This guide shows how to let Planning Engine pick who works on a task: filling open positions, fixing assignments that no longer fit, and moving work off overloaded people. It also covers how to read the proposal and commit it.
A slot is one position on one task: "task C needs one person, and dev1 or dev2 can do it". It holds the task, the list of eligible resources (allowed) and, when someone already fills it, the assignment that does. Core doesn't know about skills. If you model skills, the plen-assign crate turns workers and requirements into slots for you (see Skills and requirements).
Every slot is in one of three states, judged from its current resource:
moves it only if another resource is strictly cheaper
SuggestOptions.targets says which states to act on. The default is [Empty]: fill open positions, leave the rest alone.
The call is greedy. It visits slots one at a time and tries every eligible resource on a working copy of the project. Each try is scheduled and scored the same way evaluate scores a candidate: finish delay plus overload plus a heavy penalty for conflicts. The cheapest resource wins, and later slots build on the earlier picks.
The result has two parts. changes is a SchedulingChanges value you can pass straight to apply. steps is a log of every decision, with the cost before and after, so a UI can explain each pick.
suggest_assignments never removes an assignment. It can add one (fill) or change the resource of one (repair, rebalance). A slot it can't fix is reported, and you decide what to do with it.
Build a slot with Slot::new(id, task, allowed). The order of allowed is the tie-break: when two resources cost the same, the earlier one wins. A new assignment gets value units, 1.0 by default.
The slot id becomes the id of the assignment that fills it. On the next run, pass that id back in slot.assignment, so the slot is filled and isn't filled twice.
useplen_core::{
AssignmentData, DateTime, Project, ProjectData, ResourceData, Slot, SolveOptions,
SuggestOptions, TaskData,};fntask(id:&str, start: DateTime, duration:f64)-> TaskData{letmut task =TaskData::new(id);
task.start_date =Some(start);
task.duration =Some(duration);
task
}fnresource(id:&str)-> ResourceData{
ResourceData { id: id.into(), capacity:None, calendar_id:None}}fnassignment(id:&str, task:&str, resource:&str)-> AssignmentData{
AssignmentData {
id:Some(id.into()),
task: task.into(),
resource: resource.into(),
value:1.0,
offset:None,
duration:None,}}fnmain()->Result<(), Box<dyn std::error::Error>>{let start =DateTime::from_ymd_hm(2026,8,10,0,0).ok_or("invalid date")?;letmut data = ProjectData {
tasks:vec![task("A", start,2.0),task("B", start,2.0),task("C", start,2.0)],
resources:vec![resource("dev1"),resource("dev2"),resource("dev3")],// dev1 works on A and B at the same time.
assignments:vec![assignment("aA","A","dev1"),assignment("aB","B","dev1")],..Default::default()};
data.config.use_calendars =false;letmut project =Project::default();
project.solve(Some(data),&SolveOptions::default())?;// Task C needs one person: dev1 or dev2.
let slots =vec![Slot::new("sC","C",vec!["dev1".into(),"dev2".into()])];let result = project.suggest_assignments(&slots,&SuggestOptions::default())?;for add in&result.changes.assignments.add {println!("{} on {}: {}", add.id.as_ref().ok_or("no id")?, add.task, add.resource);}Ok(())}
This prints sC on C: dev2. dev1 is already double-booked on A and B, so putting C on dev1 adds two more days of overload. dev2 is free.
To describe a filled slot, set assignment. The assignment must be active and on the slot's task:
The call checks every slot before it does any work. It fails with Error::Input on a duplicate slot id, an unknown or summary task, an unknown resource in allowed, a value that isn't a finite number above 0, or a bad assignment. The error path points at the slot (slots[1].allowed[0]). The full list is on the Slot reference.
If you model skills, don't build slots by hand. plen_assign::slots builds them from a pool of workers and task requirements and binds existing assignments to their slots:
useplen_assign::{slots, Pool, Requirement, Skill, SkillMatch, Worker};useplen_core::{DateTime, Project, ProjectData, ResourceData, SolveOptions, SuggestOptions, TaskData};fnmain()->Result<(), Box<dyn std::error::Error>>{let start =DateTime::from_ymd_hm(2026,8,10,0,0).ok_or("invalid date")?;letmut c =TaskData::new("C");
c.start_date =Some(start);
c.duration =Some(2.0);letmut data = ProjectData {
tasks:vec![c],
resources:vec![
ResourceData { id:"dev1".into(), capacity:None, calendar_id:None},
ResourceData { id:"dev2".into(), capacity:None, calendar_id:None},],..Default::default()};
data.config.use_calendars =false;letmut project =Project::default();
project.solve(Some(data),&SolveOptions::default())?;let pool = Pool {
workers:vec![
Worker { resource:"dev1".into(), skills:vec![Skill { id:"qa".into(), value:1.0}]},
Worker { resource:"dev2".into(), skills:vec![]},],};let requirements =vec![Requirement::new("qa","C",vec![SkillMatch::at_least("qa",1.0)])];// One slot "qa#1" on C, with dev1 as the only eligible resource.
let slots =slots(&project,&pool,&requirements)?;let result = project.suggest_assignments(&slots,&SuggestOptions::default())?;println!("{} step(s)", result.steps.len());Ok(())}
Add AssignTarget::Valid to move work off overloaded people. Rebalancing runs after filling and repairing, so it also sees the slots that were just filled.
The call fills sC with dev2, then moves aB from dev1 to dev3. dev2 isn't a good pick for B anymore, because it now works on C. The proposal holds one add (sC) and one update (aB โ dev3).
A valid slot moves only on strict improvement: on a tie, the current resource stays. With new_resource_penalty at 0.0, a valid slot is skipped when its current resource isn't overloaded during the task. One pass is often enough. When a later move makes an earlier pick worse, raise passes. The loop stops early after a pass that moves nothing.
sC is still filled with dev2, but aB stays on dev1. A fixed resource still counts as being on its task, and a fixed slot that is broken is still listed in invalid. An id in fixed must name an active assignment; it doesn't have to be bound to a slot.
A slot breaks when its resource drops out of allowed, for example after a requirement or a skill grade changed. Run with targets: vec![] first to only check, then with AssignTarget::Broken to fix:
A repair always moves the slot. It takes the cheapest eligible resource, even if keeping the current one would cost less. A broken slot is visited once, with no retry. If no eligible resource can take it, it keeps its assignment and stays in invalid.
By default each candidate is only scheduled, so overload shows up as cost. With level, each candidate is also leveled with those options and scored on the leveled plan, where overload turns into delay. The score then tells you how much later the project would finish with each pick.
sC goes to dev2. The leveled finish is two days later than the accepted plan, because leveling still has to separate A and B on dev1.
Each pick builds on the scheduled copy, not the leveled one, so leveling delays don't add up across picks. Every candidate runs a full level, so keep leveled scoring for small sets of slots.
If the project holds delays from an earlier level run, those delays can hide overload: the rebalance skip rule then sees nothing to fix. Set clear_first: true to score against a copy with the delays and pauses cleared. changes then starts with a tasks.update for each cleared task, so committing it reproduces the cleared state.
Slots are visited in a fixed order, set once from the accepted plan: task start, then task order in the model, then the order of the slots you passed. Picks that move dates don't change the order. The order matters, because the result is greedy: an early slot takes the best resource, and later slots work around it.
The call runs in passes:
Pass 0 fills empty slots and repairs broken ones, if those states are targeted.
Passes 1 to passes rebalance every valid slot, if Valid is targeted.
For each slot it tries every resource in allowed, except resources already on the task (a task never gets the same person twice) and duplicates. It schedules each try on a copy of the working state and computes its cost:
cost = evaluate cost against the accepted plan
+ new_resource_penalty ร (people in use now โ people in use in the accepted plan)
The evaluate cost is finish delay plus overload plus 1000 per conflict or cycle; see Evaluating alternatives. It's always measured against the accepted plan, never against the previous pick.
"People in use" counts the resources in any slot's allowed, plus the current holders of filled slots, that have at least one active assignment. Once someone is brought in, later slots can use them for free. Moving someone's last assignment away lowers the cost.
new_resource_penalty is the one lever between balance and headcount. At 0.0 the call spreads work to idle people. A large value keeps work on the people already busy, as long as their extra overload costs less than the penalty:
penalty 0: 3 in use, cost 0
penalty 0.5: 3 in use, cost 1
penalty 5: 1 in use, cost 4
At 0.5, two new people cost 1, and removing four days of overload is worth more. At 5, one new person would cost more than the two extra days of overload on dev1, so C goes to dev1 and nobody else is brought in. With a penalty above 0.0, valid slots aren't skipped when their holder isn't overloaded: freeing a person is a gain on its own.
A candidate that can't be applied or scheduled is dropped. An empty slot with no candidate left goes to unfilled.
SuggestResult has everything a UI needs to show and explain the proposal:
changes - the net edit: one add per filled slot, one update per moved assignment (even after several passes), and the clear_first clears. Its baseline_id is set.
steps - every decision that changed the working state, in order.
unfilled - targeted empty slots left empty.
invalid - slots whose resource is outside allowed at the end, whatever targets was.
baseline and proposed - cost and people in use before and after. proposed also carries the scheduled Metrics and, with level, the leveled ones.
A SuggestStep has no kind field. Read the kind from from_resource and pass:
cost 2 -> 0
sC on C: fill to dev2, cost 2 -> 2
sB on B: rebalance from dev1 (pass 1) to dev3, cost 2 -> 0
The step costs form a chain: the first before is baseline.cost, and each before is the previous step's after. The baseline costs 2 because dev1 is already overloaded for two days. Filling C doesn't make that worse, and moving B to dev3 removes it.
proposed.scheduled is the full Metrics of the final state, with finish, overload per resource, conflicts and cycles. See SuggestResult and Metrics.
Pass result.changes to apply, then reschedule. If you scored with level, run level with the same options instead of solve(None).
useplen_core::{
AssignTarget, AssignmentData, DateTime, Project, ProjectData, ResourceData, Slot,
SolveOptions, SuggestOptions, TaskData,};fntask(id:&str, start: DateTime, duration:f64)-> TaskData{letmut task =TaskData::new(id);
task.start_date =Some(start);
task.duration =Some(duration);
task
}fnresource(id:&str)-> ResourceData{
ResourceData { id: id.into(), capacity:None, calendar_id:None}}fnassignment(id:&str, task:&str, resource:&str)-> AssignmentData{
AssignmentData {
id:Some(id.into()),
task: task.into(),
resource: resource.into(),
value:1.0,
offset:None,
duration:None,}}fnmain()->Result<(), Box<dyn std::error::Error>>{let start =DateTime::from_ymd_hm(2026,8,10,0,0).ok_or("invalid date")?;letmut data = ProjectData {
tasks:vec![task("A", start,2.0),task("B", start,2.0),task("C", start,2.0)],
resources:vec![resource("dev1"),resource("dev2"),resource("dev3")],
assignments:vec![assignment("aA","A","dev1"),assignment("aB","B","dev1")],..Default::default()};
data.config.use_calendars =false;letmut project =Project::default();
project.solve(Some(data),&SolveOptions::default())?;letmut b =Slot::new("sB","B",vec!["dev1".into(),"dev2".into(),"dev3".into()]);
b.assignment =Some("aB".into());let slots =vec![Slot::new("sC","C",vec!["dev1".into(),"dev2".into()]), b];let options = SuggestOptions {
targets:vec![AssignTarget::Empty,AssignTarget::Valid],..Default::default()};let result = project.suggest_assignments(&slots,&options)?;let report = project.apply(&result.changes)?;if!report.rejected.is_empty(){returnErr("proposal rejected, resync the project".into());}
project.solve(None,&SolveOptions::default())?;// Next run: sC is now the id of the assignment on C.
letmut c =Slot::new("sC","C",vec!["dev1".into(),"dev2".into()]);
c.assignment =Some("sC".into());letmut b =Slot::new("sB","B",vec!["dev1".into(),"dev2".into(),"dev3".into()]);
b.assignment =Some("aB".into());let again = project.suggest_assignments(&[c, b],&options)?;println!("{} step(s)", again.steps.len());// 0: nothing left to improve
Ok(())}
changes.baseline_id names the plan the proposal was built on. If the project changed in between, apply fails with ProjectError::StaleBaseline instead of committing an outdated proposal. A rejected operation sets needs_resync; see Recovering from rejected changes.
The new assignment takes the slot id, so the slot keeps its binding after the commit. On the next run, pass that id in slot.assignment, as above. plen_assign::slots binds slots this way for you. A slot id that is already the id of another assignment fails the call with Error::Input at slots[i].id. If the slot isn't bound, every add for it would be rejected as a duplicate id, and the slot would stay unfilled without a reason.
You can also commit part of a proposal. changes is a plain SchedulingChanges, so drop the adds or updates the user declines before you call apply.
The committed plan matches proposed when config.gap_behavior is GapBehavior::Compress. With the default Preserve, it can differ slightly. The call reschedules after each pick, while the commit reschedules once, and preserved dates depend on the path taken. Treat proposed as an estimate in that mode.
suggest_assignments runs one schedule (and one level, with level) per slot and candidate, all on the calling thread. On large projects, run it on a worker thread or in spawn_blocking in an async server.