[Canonical page](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/step-cost/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# StepCost

The state cost before and after one step of [`Project::suggest_assignments`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/project.md#suggest_assignments>). Each [`SuggestStep`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/suggest-step.md>) carries one in its `cost` field. `StepCost` isn't built by hand.

## Declaration

```rust
#[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`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/suggest-result.md>)`.cost`. |
| `after` | `f64` | State cost after the step. The next step's `before`. |

Both values include the [`new_resource_penalty`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/suggest-options.md>) and are measured on the scoring stage, against the reference state the call started from. [`SuggestOptions::level`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/suggest-options.md>) selects the scoring stage. For how a state's cost is computed, see [Suggesting assignments](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/suggesting-assignments.md>).

## Example

```rust
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
        );
    }
}
```

## Related

- [`SuggestStep`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/suggest-step.md>) - carries this value in its `cost` field
- [`AssignTotal`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/assign-total.md>) - the reference cost the first step starts from
- [`SuggestProposal`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/suggest-proposal.md>) - the final cost the last step ends at
- [Suggesting assignments](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/suggesting-assignments.md#reading-the-proposal>) - shows reading per-step costs from a proposal
