SuggestStep#

One decision of Project::suggest_assignments that changed the working state: a slot was filled, repaired or moved to another resource. Read the steps from SuggestResult::steps, in the order they were taken. A slot that ends with no change produces no step.

Declaration#

#[derive(Clone, Debug, PartialEq)]
pub struct SuggestStep {
    pub slot: Id,
    pub task: Id,
    pub pass: u32,
    pub from_resource: Option<Id>,
    pub to_resource: Id,
    pub cost: StepCost,
}

With the serde feature, SuggestStep also implements Serialize and Deserialize, with camelCase field names.

Fields#

Field Type Description
slot Id Id of the Slot this step changed.
task Id The slot's task.
pass u32 0 for a fill or a repair; 1 and up for the rebalance pass the step was taken in.
from_resource Option<Id> The resource the slot held before the step. None when the step filled an empty slot.
to_resource Id The resource the slot holds after the step. Never empty: a step never removes an assignment.
cost StepCost State cost before and after the step.

Step kinds#

SuggestStep has no kind field. Tell the kind from from_resource and pass:

from_resource pass Kind
None 0 Fill: an empty slot got a resource.
Some(_) 0 Repair: a resource outside the slot's allowed was replaced.
Some(_) 1.. Rebalance: a valid slot moved to a cheaper resource.

Which slots are filled, repaired or rebalanced depends on SuggestOptions::targets. For how each kind picks its resource, see Suggesting assignments.

Example#

use plen_core::{SuggestResult, SuggestStep};

fn kind(step: &SuggestStep) -> &'static str {
    match (&step.from_resource, step.pass) {
        (None, _) => "fill",
        (Some(_), 0) => "repair",
        (Some(_), _) => "rebalance",
    }
}

// Print the step log of a suggest_assignments proposal.
fn print_steps(result: &SuggestResult) {
    for step in &result.steps {
        let from = step.from_resource.as_ref().map_or("-".to_string(), |r| r.to_string());
        println!(
            "pass {} {}: slot {} on task {}: {} -> {}",
            step.pass,
            kind(step),
            step.slot,
            step.task,
            from,
            step.to_resource
        );
    }
}