Preview leveling#
Show the user what leveling would change before it touches the project, then keep the leveled plan or throw it away.
Project::level takes &mut self and commits: it writes leveling_delay and pauses into the project and accepts the leveled dates as the new baseline. To get a proposal instead, level a clone. Project::clone is O(1), because the data stays shared until one copy is edited.
Prerequisites#
- A solved
Project:solve(Some(data), ...)has run. - The data has
resourcesandassignments, so there's overallocation to level. - The project is forward-scheduled.
levelrefusesconfig.schedule_from_end: truewithError::Input.
Steps#
-
Clone the solved project:
let mut draft = project.clone; -
Level the clone. The original keeps its dates, its baseline and its overallocation:
let proposal = draft.level?; -
Show the proposal.
proposal.schedule.updateslists the tasks leveling moved, with their new dates,leveling_delayandpauses. The diff is relative to the state the call started from. That state matches the original, so you can apply the entries to the model you already hold.for update in &proposal.schedule.updates -
Show what leveling couldn't fix.
proposal.schedule.overallocationsholds the windows left after leveling, and each window has areason, such asfixed-taskorpriority-1000:for over in proposal.schedule.overallocations.iter.flatten -
Apply the user's choice:
- Accept: replace the original with the clone,
project = draft;. The project now holds the leveled baseline. - Reject: drop
draft. Nothing else needs undoing.
Replace the original only if it hasn't been edited since you cloned it. Otherwise the proposal was computed from an older state, so level a new clone.
- Accept: replace the original with the clone,
The full example levels two tasks that book the same developer full time on Monday and Tuesday:
use ;
Result#
The example prints the one task leveling moved, and nothing is left overallocated:
B: 2026-08-12 08:00 .. 2026-08-14 08:00, delay Some(2.0)
overallocated resources left: 0
B waits two days for A, so its leveling_delay is 2.0. Until you replace project with draft, project still reports the Monday-Tuesday window on dev1, and a solve(None) on it returns no updates. After the swap, baseline_id is the token from the leveling result.
The clone is a full solved project, so you can also call draft.load_profile on it to draw the leveled load. See Resource load. To compare leveling across several alternative change sets with scores, use evaluate with EvaluateOptions.level instead. See Evaluating alternatives. For options, reasons and splits, see Leveling resources.