StepCost#

The state cost before and after one step of Project::suggest_assignments. Each SuggestStep carries one in its cost field. StepCost isn't built by hand.

Declaration#

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct StepCost {
    pub before: f64,
    pub after: f64,
}

With the serde feature (cargo add plen-core --features serde), StepCost also implements Serialize and Deserialize, with fields before and after.

Fields#

Field Type Description
before f64 State cost before the step. Equals the previous step's after. For the first step, equals SuggestResult::baseline.cost.
after f64 State cost after the step. The next step's before.

Both values include the new_resource_penalty and are measured on the scoring stage, against the reference state the call started from. SuggestOptions::level selects the scoring stage. For how a state's cost is computed, see Suggesting assignments.

Example#

use plen_core::SuggestResult;

// Print how much each step changed the state cost.
fn print_step_costs(result: &SuggestResult) {
    for step in &result.steps {
        let delta = step.cost.after - step.cost.before;
        println!(
            "slot {}: {} -> {} ({:+})",
            step.slot, step.cost.before, step.cost.after, delta
        );
    }
}