Suggesting assignments#

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.

How auto-assignment works#

Project.SuggestAssignments(slots, options) takes a list of slots and returns a proposal. It never changes the project. You decide what to commit.

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. The core package doesn't know about skills. If you model skills, the Plen.Assign package 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:

State Meaning AssignTarget What the call does
empty no assignment Empty fills it with the cheapest eligible resource
broken held by a resource outside Allowed Broken moves it to the cheapest eligible resource
valid held by a resource in Allowed Valid moves it only if another resource is strictly cheaper

SuggestOptions.Targets says which states to act on. The default is [AssignTarget.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 object 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.

SuggestAssignments 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.

Slots#

Build a slot with new Slot(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 counts as filled and isn't filled twice.

The examples on this page share one small project: three 2-day tasks that start on the same day, three developers, and dev1 booked on both A and B.

using Plen;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("A") { StartDate = start, Duration = 2 },
        new TaskData("B") { StartDate = start, Duration = 2 },
        new TaskData("C") { StartDate = start, Duration = 2 },
    ],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }, new ResourceData { Id = "dev3" }],
    // dev1 works on A and B at the same time.
    Assignments =
    [
        new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1 },
        new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1 },
    ],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

// Task C needs one person: dev1 or dev2.
List<Slot> slots = [new Slot("sC", "C", ["dev1", "dev2"])];
var result = project.SuggestAssignments(slots, new SuggestOptions());

foreach (var add in result.Changes.Assignments.Add)
    Console.WriteLine($"{add.Id} on {add.Task}: {add.Resource}");

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:

using Plen;

var slot = new Slot("sB", "B", ["dev1", "dev2"]) { Assignment = "aB" };
Console.WriteLine(slot);

The call checks every slot before it does any work. It throws an InputException on a duplicate slot id, an unknown, unscheduled or summary task, an unknown resource in Allowed, a Value that isn't a finite number above 0, or a bad Assignment. Path points at the slot, for example slots[1].allowed[0]. The full list is on the Slot reference.

If you model skills, don't build slots by hand. SkillLayer.Slots builds them from a pool of workers and task requirements and binds existing assignments to their slots:

using Plen;
using Plen.Assign;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks = [new TaskData("C") { StartDate = start, Duration = 2 }],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

var pool = new Pool
{
    Workers =
    [
        new Worker { Resource = "dev1", Skills = [new Skill { Id = "qa", Value = 1 }] },
        new Worker { Resource = "dev2" },
    ],
};
List<Requirement> requirements = [new Requirement("qa", "C", [SkillMatch.AtLeast("qa", 1)])];

// One slot "qa#1" on C, with dev1 as the only eligible resource.
var slots = SkillLayer.Slots(project, pool, requirements);
var result = project.SuggestAssignments(slots, new SuggestOptions());
Console.WriteLine($"{slots[0].Id}: [{string.Join(", ", slots[0].Allowed)}], {result.Steps.Count} step(s)");

This prints qa#1: [dev1], 1 step(s). Slot ids are "<requirement id>#<n>", and only dev1 has the qa skill.

Options#

Create SuggestOptions with an object initializer and set only the properties you need.

Property Default Use it to
Targets [Empty] choose which slot states to act on; [] only reports broken slots
Fixed empty keep listed assignments where they are
NewResourcePenalty 0.0 trade balance against headcount (see How picks are made)
Passes 1 rebalance valid slots more than once
Level null score each candidate after leveling
ClearFirst false score against a copy with stored leveling delays cleared
BaselineId null throw StaleBaseline if the project changed

All properties are on the SuggestOptions reference.

Rebalancing filled slots#

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.

using Plen;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("A") { StartDate = start, Duration = 2 },
        new TaskData("B") { StartDate = start, Duration = 2 },
        new TaskData("C") { StartDate = start, Duration = 2 },
    ],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }, new ResourceData { Id = "dev3" }],
    // dev1 works on A and B at the same time.
    Assignments =
    [
        new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1 },
        new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1 },
    ],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

var b = new Slot("sB", "B", ["dev1", "dev2", "dev3"]) { Assignment = "aB" };
List<Slot> slots = [new Slot("sC", "C", ["dev1", "dev2"]), b];

var options = new SuggestOptions { Targets = [AssignTarget.Empty, AssignTarget.Valid] };
var result = project.SuggestAssignments(slots, options);

foreach (var add in result.Changes.Assignments.Add)
    Console.WriteLine($"add {add.Id}: {add.Resource}");
foreach (var update in result.Changes.Assignments.Update)
    Console.WriteLine($"update {update.Id}: {update.Resource.Value}");
add sC: dev2
update aB: dev3

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 NewResourcePenalty 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.

Keeping people in place#

List assignment ids in Fixed to keep them out of every pass, whatever the load:

using Plen;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("A") { StartDate = start, Duration = 2 },
        new TaskData("B") { StartDate = start, Duration = 2 },
        new TaskData("C") { StartDate = start, Duration = 2 },
    ],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }, new ResourceData { Id = "dev3" }],
    // dev1 works on A and B at the same time.
    Assignments =
    [
        new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1 },
        new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1 },
    ],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

var b = new Slot("sB", "B", ["dev1", "dev2", "dev3"]) { Assignment = "aB" };
List<Slot> slots = [new Slot("sC", "C", ["dev1", "dev2"]), b];

var options = new SuggestOptions
{
    Targets = [AssignTarget.Empty, AssignTarget.Valid],
    Fixed = ["aB"], // dev1 stays on B
};
var result = project.SuggestAssignments(slots, options);
Console.WriteLine($"{result.Changes.Assignments.Add.Count} add(s), {result.Changes.Assignments.Update.Count} update(s)");

This prints 1 add(s), 0 update(s). 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, but it doesn't have to be bound to a slot.

Repairing broken slots#

A slot breaks when its resource drops out of Allowed, for example after a requirement or a skill grade changed. Run with Targets = [] first to only check, then with AssignTarget.Broken to fix:

using Plen;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("A") { StartDate = start, Duration = 2 },
        new TaskData("B") { StartDate = start, Duration = 2 },
        new TaskData("C") { StartDate = start, Duration = 2 },
    ],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }, new ResourceData { Id = "dev3" }],
    // dev1 works on A and B at the same time.
    Assignments =
    [
        new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1 },
        new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1 },
    ],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

// B now needs dev2 or dev3, but dev1 holds it.
List<Slot> slots = [new Slot("sB", "B", ["dev2", "dev3"]) { Assignment = "aB" }];

var check = project.SuggestAssignments(slots, new SuggestOptions { Targets = [] });
Console.WriteLine($"broken: {string.Join(", ", check.Invalid)}");

var repair = project.SuggestAssignments(slots, new SuggestOptions { Targets = [AssignTarget.Broken] });
foreach (var step in repair.Steps)
    Console.WriteLine($"{step.Slot}: {step.FromResource} -> {step.ToResource}");
broken: sB
sB: dev1 -> dev2

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.

Scoring after leveling#

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.

using Plen;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("A") { StartDate = start, Duration = 2 },
        new TaskData("B") { StartDate = start, Duration = 2 },
        new TaskData("C") { StartDate = start, Duration = 2 },
    ],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }, new ResourceData { Id = "dev3" }],
    // dev1 works on A and B at the same time.
    Assignments =
    [
        new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1 },
        new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1 },
    ],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

List<Slot> slots = [new Slot("sC", "C", ["dev1", "dev2"])];
var options = new SuggestOptions { Level = new LevelingOptions() };
var result = project.SuggestAssignments(slots, options);

if (result.Proposed.Leveled?.Metrics.Finish.Project is { } finish)
    Console.WriteLine($"leveled finish: {finish.Date} ({finish.Delta} days later)");

This prints leveled finish: 2026-08-14 00:00 (2 days later). 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, and the rebalance skip rule then sees nothing to fix. Set ClearFirst = true to score against a copy with the delays and pauses cleared. Changes then starts with a Tasks.Update entry for each cleared task, so committing it reproduces the cleared state.

How picks are made#

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:

  1. Pass 0 fills empty slots and repairs broken ones, if those states are targeted.
  2. 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
     + NewResourcePenalty × (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.

NewResourcePenalty is the one setting that trades balance against 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:

using Plen;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("A") { StartDate = start, Duration = 2 },
        new TaskData("B") { StartDate = start, Duration = 2 },
        new TaskData("C") { StartDate = start, Duration = 2 },
    ],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }, new ResourceData { Id = "dev3" }],
    // dev1 works on A and B at the same time.
    Assignments =
    [
        new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1 },
        new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1 },
    ],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

var b = new Slot("sB", "B", ["dev1", "dev2", "dev3"]) { Assignment = "aB" };
List<Slot> slots = [new Slot("sC", "C", ["dev1", "dev2"]), b];

foreach (var penalty in new[] { 0.0, 0.5, 5.0 })
{
    var options = new SuggestOptions
    {
        Targets = [AssignTarget.Empty, AssignTarget.Valid],
        NewResourcePenalty = penalty,
    };
    var result = project.SuggestAssignments(slots, options);
    Console.WriteLine($"penalty {penalty}: {result.Proposed.Resources} in use, cost {result.Proposed.Cost}");
}
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.

Reading the proposal#

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 ClearFirst clears. Its BaselineId 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 property. Read the kind from FromResource and Pass:

using Plen;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("A") { StartDate = start, Duration = 2 },
        new TaskData("B") { StartDate = start, Duration = 2 },
        new TaskData("C") { StartDate = start, Duration = 2 },
    ],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }, new ResourceData { Id = "dev3" }],
    // dev1 works on A and B at the same time.
    Assignments =
    [
        new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1 },
        new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1 },
    ],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

var b = new Slot("sB", "B", ["dev1", "dev2", "dev3"]) { Assignment = "aB" };
List<Slot> slots = [new Slot("sC", "C", ["dev1", "dev2"]), b];
var options = new SuggestOptions { Targets = [AssignTarget.Empty, AssignTarget.Valid] };
var result = project.SuggestAssignments(slots, options);

Console.WriteLine($"cost {result.Baseline.Cost} -> {result.Proposed.Cost}");
foreach (var step in result.Steps)
{
    var action = (step.FromResource, step.Pass) switch
    {
        (null, _) => "fill",
        (var from, 0) => $"repair from {from}",
        (var from, var pass) => $"rebalance from {from} (pass {pass})",
    };
    Console.WriteLine($"{step.Slot} on {step.Task}: {action} to {step.ToResource}, cost {step.Cost.Before} -> {step.Cost.After}");
}
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.

Committing#

Pass result.Changes to Apply, then reschedule. If you scored with Level, run Level with the same options instead of Solve(null, …).

using Plen;

var start = Moment.FromYmdHm(2026, 8, 10, 0, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("A") { StartDate = start, Duration = 2 },
        new TaskData("B") { StartDate = start, Duration = 2 },
        new TaskData("C") { StartDate = start, Duration = 2 },
    ],
    Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }, new ResourceData { Id = "dev3" }],
    // dev1 works on A and B at the same time.
    Assignments =
    [
        new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1 },
        new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1 },
    ],
};
data.Config.UseCalendars = false;

var project = new Project();
project.Solve(data, new SolveOptions());

var options = new SuggestOptions { Targets = [AssignTarget.Empty, AssignTarget.Valid] };
List<Slot> slots =
[
    new Slot("sC", "C", ["dev1", "dev2"]),
    new Slot("sB", "B", ["dev1", "dev2", "dev3"]) { Assignment = "aB" },
];
var result = project.SuggestAssignments(slots, options);

var report = project.Apply(result.Changes);
if (report.Rejected.Count > 0)
    throw new InvalidOperationException("proposal rejected, resync the project");
project.Solve(null, new SolveOptions());

// Next run: sC is now the id of the assignment on C.
List<Slot> next =
[
    new Slot("sC", "C", ["dev1", "dev2"]) { Assignment = "sC" },
    new Slot("sB", "B", ["dev1", "dev2", "dev3"]) { Assignment = "aB" },
];
var again = project.SuggestAssignments(next, options);
Console.WriteLine($"{again.Steps.Count} step(s)"); // 0: nothing left to improve

Changes.BaselineId names the plan the proposal was built on. If the project changed in between, Apply throws a ProjectException with Code == ProjectError.StaleBaseline instead of committing an outdated proposal. A rejected operation sets NeedsResync; 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. SkillLayer.Slots binds slots this way for you. A slot id that is already the id of another assignment throws an InputException at slots[i].id. Without that check, every add for the slot 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 remove the adds or updates the user declines before you call Apply.

The committed plan matches Proposed when Config.GapBehavior is GapBehavior.Compress (see SchedulingConfig). 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.

SuggestAssignments runs one schedule (and one level, with Level) per slot and candidate, synchronously on the calling thread. On large projects in an ASP.NET Core or other async host, run it with Task.Run or on a background worker; see Calling from async code.