Evaluating Alternatives#
This guide shows how to compare several possible edits in one call and pick the best one, for example to decide which resource should take a task. It covers building candidates, scoring them with and without leveling, reading the metrics, handling candidates that fail, scoring on several threads and committing the winner.
How evaluation works#
Project.Evaluate takes a list of candidates. A Candidate is an Id plus a SchedulingChanges, the same change set you'd pass to Apply. Each candidate is one alternative: "give task B to dev2", "split the review between two people", "add a link". The call scores every candidate against the project's accepted baseline and returns an EvaluateResult. The project doesn't change, just as with Preview.
Every candidate goes through the same run on a disposable copy of the project:
- Copy the reference state. That's the accepted baseline, or its cleared copy with
ClearFirst(see Options). Applythe candidate's changes.- Call
Solve(null, …)and measure the scheduled stage. - If
EvaluateOptions.Levelis set, callLevelwith those options and measure the leveled stage.
You'd run the same sequence to commit the candidate for real. Each candidate starts from the reference state, never from the previous candidate, and both stages are compared with the same baseline.
The result has three parts:
Baseline: the metrics of the reference state itself. All its deltas are 0.Candidates: oneCandidateResultper candidate, in input order. It holdsScheduledmetrics,Leveledmetrics (only withLevel) and aCost.BaselineId: the token of the accepted baseline the candidates were scored against.
Each stage is described by a Metrics object: the project finish and the finish of each focus task, resource overload, conflicts, cycles and a single Cost number. Every measurement is an absolute Value plus a Delta against the baseline, so you can show either one.
Errors come in two levels. Problems with the call itself throw and fail the whole call:
- no solved baseline:
ProjectExceptionwithCode == ProjectError.NoBaseline - a stale
BaselineIdin the options or in any candidate:ProjectError.StaleBaseline - an unknown focus task, or leveling options that don't fit the baseline:
InputException
Everything else fails only its own candidate. That candidate gets an Error and no metrics, and the other candidates are scored as usual.
Evaluate reports scores, not dates. The result has no task updates and no overallocation windows. Once you've picked a candidate, commit it yourself with Apply and Level, or look at its dates with Preview.
Comparing candidates#
All examples on this page use the same small project: tasks A and B, two working days each, both starting on Monday, August 10, 2026, and both assigned to dev1. The resource dev2 is idle, and dev1 is overloaded for two days.
Candidates#
Build each alternative as a Candidate and pass them all to Evaluate. An empty change set is a useful candidate too: it scores "leave the plan as it is" next to the other options.
using Plen;
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("A") { StartDate = monday, Duration = 2.0 },
new TaskData("B") { StartDate = monday, Duration = 2.0 },
],
Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }],
Assignments =
[
new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1.0 },
new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1.0 },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
// Candidate 1: keep the plan as it is.
var stay = new Candidate { Id = "stay", Changes = new SchedulingChanges() };
// Candidate 2: give task B to dev2.
var toDev2 = new SchedulingChanges();
toDev2.Assignments.Update.Add(new AssignmentUpdate("aB") { Resource = Patch<Id>.Of("dev2") });
var dev2 = new Candidate { Id = "dev2", Changes = toDev2 };
var result = project.Evaluate([stay, dev2], new EvaluateOptions { Focus = ["B"] });
Console.WriteLine($"baseline: cost {result.Baseline.Cost}");
foreach (var candidate in result.Candidates)
Console.WriteLine($"{candidate.Id}: cost {candidate.Cost}");
baseline: cost 2
stay: cost 2
dev2: cost 0
Without leveling, only the scheduled stage is scored. stay keeps both tasks on dev1 and costs 2, two resource-days of overload. dev2 removes the overload and costs 0.
The candidate Id is echoed back so you can match results to inputs. Ids aren't checked for uniqueness, and results keep input order anyway. See the Candidate reference.
Options#
EvaluateOptions has four properties, all optional:
Level: aLevelingOptionslevels each candidate after scheduling it and adds the leveled stage.null(the default) scores the scheduled stage only.Focus: the tasks to report finish dates and focus overload for. There's no implicit "modified task", so list the tasks your candidates are about.BaselineId: a baseline token. The call throwsProjectExceptionwithProjectError.StaleBaselinewhen the token no longer names the accepted baseline. Each candidate'sChanges.BaselineIdis checked the same way.ClearFirst: score against a copy with the in-scopeLevelingDelayandPausescleared.
Leveling changes the picture. Without it, an overloaded plan looks bad on overload. With it, the overload turns into delay, which is what the user gets after committing and leveling. The rest of the examples share two helpers, SolvedProject and Reassign:
using Plen;
var project = SolvedProject();
Candidate[] candidates =
[
new() { Id = "stay", Changes = new SchedulingChanges() },
new() { Id = "dev2", Changes = Reassign("aB", "dev2") },
];
var options = new EvaluateOptions
{
Level = new LevelingOptions(),
Focus = ["A", "B"],
};
var result = project.Evaluate(candidates, options);
foreach (var candidate in result.Candidates)
{
if (candidate.Leveled is not { } leveled)
continue;
if (leveled.Metrics.Finish.Project is { } finish)
Console.WriteLine($"{candidate.Id}: project ends {finish.Date} ({finish.Delta:+0;-0;+0} days), cost {candidate.Cost}");
foreach (var task in leveled.Metrics.Finish.Tasks)
{
if (task.Finish is { } taskFinish)
Console.WriteLine($" {task.Id} ends {taskFinish.Date} ({taskFinish.Delta:+0;-0;+0})");
}
}
// Tasks A and B, two days each, both on dev1 in the same week.
static Project SolvedProject()
{
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("A") { StartDate = monday, Duration = 2.0 },
new TaskData("B") { StartDate = monday, Duration = 2.0 },
],
Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }],
Assignments =
[
new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1.0 },
new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1.0 },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
return project;
}
static SchedulingChanges Reassign(Id assignment, Id resource)
{
var changes = new SchedulingChanges();
changes.Assignments.Update.Add(new AssignmentUpdate(assignment) { Resource = resource });
return changes;
}
stay: project ends 2026-08-14 08:00 (+2 days), cost 2
A ends 2026-08-12 08:00 (+0)
B ends 2026-08-14 08:00 (+2)
dev2: project ends 2026-08-12 08:00 (+0 days), cost 0
A ends 2026-08-12 08:00 (+0)
B ends 2026-08-12 08:00 (+0)
For stay, leveling resolves the overload by pushing B two days later, so the cost is now the delay. For dev2 there's nothing to level. Inside Reassign, resource is already an Id, so it converts to Patch<Id> directly. With a string literal, write Patch<Id>.Of("dev2") as in the first example.
Level runs with the options exactly as you pass them, so LevelingOptions.ClearFirst (default true) re-levels everything from zero in each candidate. That's a pitfall after a previous Level run. The stored delays are already in the baseline finish, and they hide the overload the current assignments cause. A candidate that removes the overload then shows a negative finish delta, because leveling from zero drops the old delays.
EvaluateOptions.ClearFirst fixes this. It replaces the reference state with a copy that has the in-scope delays and pauses cleared, solved again. The baseline metrics and every candidate run then use that copy. The scope is Level.Scope.Tasks when you set it, otherwise every task. It's independent of LevelingOptions.ClearFirst, so it also works without Level.
using Plen;
var project = SolvedProject();
// The plan was leveled earlier: B carries a two-day leveling delay.
var leveled = project.Level(new LevelingOptions());
Candidate[] candidates = [new() { Id = "dev2", Changes = Reassign("aB", "dev2") }];
var options = new EvaluateOptions
{
BaselineId = leveled.Schedule.BaselineId,
Level = new LevelingOptions(),
ClearFirst = true,
};
var result = project.Evaluate(candidates, options);
// The cleared baseline shows the overload that B's delay was hiding.
Console.WriteLine($"baseline overload: {result.Baseline.Overload.Total.Value}");
foreach (var candidate in result.Candidates)
{
if (candidate.Leveled?.Metrics.Finish.Project is { } finish)
Console.WriteLine($"{candidate.Id}: finish delta {finish.Delta:+0;-0;+0}");
}
// Tasks A and B, two days each, both on dev1 in the same week.
static Project SolvedProject()
{
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("A") { StartDate = monday, Duration = 2.0 },
new TaskData("B") { StartDate = monday, Duration = 2.0 },
],
Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }],
Assignments =
[
new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1.0 },
new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1.0 },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
return project;
}
static SchedulingChanges Reassign(Id assignment, Id resource)
{
var changes = new SchedulingChanges();
changes.Assignments.Update.Add(new AssignmentUpdate(assignment) { Resource = resource });
return changes;
}
baseline overload: 2
dev2: finish delta +0
With ClearFirst, the baseline reports 2 resource-days of overload and the dev2 candidate a finish delta of 0. Without it, the baseline has no overload and the same candidate shows a finish delta of -2. Both views are valid. ClearFirst is the one that matches a commit with Level and LevelingOptions.ClearFirst, which re-levels from zero.
A few details:
BaselineId, candidate tokens,Leveloptions and focus ids are all checked against the accepted state before anything is cleared.ClearFirstadds no new errors.- A candidate's own
Changes.BaselineIdis dropped before its trial run, because the cleared copy has a different token. The result'sBaselineIdis still the accepted state's. - When there's nothing to clear in scope, the output is the same as with
ClearFirst = false.
The full property list is on the EvaluateOptions reference. For the leveling options themselves, see Leveling resources.
Metrics and cost#
Every stage reports the same Metrics:
| Property | What it measures |
|---|---|
Finish.Project |
Latest end over scheduled tasks. null when the stage has no tasks. |
Finish.Tasks |
One TaskFinish per focus task, in focus order. |
Overload.Total |
Overload over all resources. |
Overload.Resources |
Overload per resource, for every resource that's non-zero in the stage or the baseline. |
Overload.Focus |
Per focus task: the overload per resource in the buckets that intersect the task. |
Conflicts, Cycles |
How many conflicts and cycles the stage has. |
Cost |
One number for ranking, lower is better. |
Dates come as a Shift: Date plus Delta, the working time from the baseline finish in Config.DurationUnit, positive when later. A task's delta is measured on its own calendar, the project's on the global calendar. Counts and overload come as an Amount: Value plus Delta.
Overload is measured the same way the leveler sees it: for each time bucket, how far a resource's load goes over its capacity, summed over buckets. The unit is capacity × buckets, so on a day basis 2.0 means "two resource-days over". One bucket size (basis) applies to the baseline and every stage of every candidate: Level.Basis when you set it, otherwise the one derived from Config.DurationUnit. LoadProfile shows the same per-resource sum as excess load at that basis.
Focus overload shows where the trouble is. At the scheduled stage, it's the overload around the task. At the leveled stage, it's what leveling couldn't resolve there. A milestone has zero length and covers no bucket.
The leveled stage is a LeveledMetrics: the same Metrics in its Metrics property, plus Converged, Rounds and Windows, the number of overallocation windows left after leveling.
Cost is one fixed heuristic:
Cost = max(0, Finish.Project.Delta)
+ Overload.Total.Value
+ 1000 × (Conflicts.Value + Cycles.Value)
When the basis follows DurationUnit, a day of delay and a resource-day of overload weigh the same. An earlier finish doesn't earn a bonus. The 1000 penalty keeps any broken schedule, with conflicts or cycles, behind every valid one. CandidateResult.Cost is the cost of the last stage present: leveled when you level, scheduled otherwise. The baseline carries its own Cost.
If the heuristic doesn't fit your product, rank on the raw values instead. This method prints the per-resource overload change of each candidate's scheduled stage:
using Plen;
static void PrintOverload(EvaluateResult result)
{
foreach (var candidate in result.Candidates)
{
if (candidate.Scheduled is not { } scheduled)
continue;
foreach (var row in scheduled.Overload.Resources)
Console.WriteLine($"{candidate.Id}: {row.Resource} overload {row.Overload.Value} ({row.Overload.Delta:+0;-0;+0} vs baseline)");
}
}
For the project above, the dev2 candidate prints a row for dev1 with a delta of -2. The row is there because dev1 was overloaded in the baseline, even though it's zero in the stage. Resources come in stage order, then resources that exist only in the baseline. See the Metrics reference and the Overload reference.
Failed and cyclic candidates#
A candidate can fail without failing the call. Three cases need handling:
- Rejected.
Applyrejects an operation in the change set (the result reports only the first rejection), orSolveorLevelfails on the candidate's input, for example on a leveling scope id the candidate removed. The result has anError, aRejectedOperationwith aPathand aMessage.Scheduled,LeveledandCostarenull. - Cyclic. The candidate creates a dependency cycle.
Scheduledis measured on the unchanged dates the cyclic solve returns, andCycles.Valueis above 0. Leveling stops at round 0 on a cyclic plan, soLeveledisnull. The cycle penalty pushes its cost over 1000. - Focus task removed. When the candidate removes a focus task, that task's
Finishand its focus overloadResourcesarenull. The rest of the metrics are normal.
using Plen;
var project = SolvedProject();
var cycle = new SchedulingChanges();
cycle.Links.Add.Add(new LinkAdd { Id = "ab", Source = "A", Target = "B" });
cycle.Links.Add.Add(new LinkAdd { Id = "ba", Source = "B", Target = "A" });
var removed = new SchedulingChanges();
removed.Tasks.Remove.Add("B");
Candidate[] candidates =
[
new() { Id = "missing", Changes = Reassign("nope", "dev2") },
new() { Id = "cycle", Changes = cycle },
new() { Id = "removed", Changes = removed },
];
var options = new EvaluateOptions
{
Level = new LevelingOptions(),
Focus = ["B"],
};
var result = project.Evaluate(candidates, options);
foreach (var candidate in result.Candidates)
{
if (candidate.Error is { } error)
{
Console.WriteLine($"{candidate.Id} rejected at {error.Path}: {error.Message}");
continue;
}
if (candidate.Scheduled is not { } scheduled)
continue;
if (scheduled.Cycles.Value > 0)
Console.WriteLine($"{candidate.Id} is cyclic, leveled: {candidate.Leveled is not null}");
foreach (var task in scheduled.Finish.Tasks)
{
if (task.Finish is null)
Console.WriteLine($"{candidate.Id} removes focus task {task.Id}");
}
Console.WriteLine($"{candidate.Id} cost {candidate.Cost}");
}
// Tasks A and B, two days each, both on dev1 in the same week.
static Project SolvedProject()
{
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("A") { StartDate = monday, Duration = 2.0 },
new TaskData("B") { StartDate = monday, Duration = 2.0 },
],
Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }],
Assignments =
[
new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1.0 },
new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1.0 },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
return project;
}
static SchedulingChanges Reassign(Id assignment, Id resource)
{
var changes = new SchedulingChanges();
changes.Assignments.Update.Add(new AssignmentUpdate(assignment) { Resource = resource });
return changes;
}
missing rejected at assignments.update[0]: unknown assignment id
cycle is cyclic, leveled: False
cycle cost 1002
removed removes focus task B
removed cost 0
Rank only candidates that have a Cost. The cyclic candidate has one, but the penalty keeps it at the bottom. Its 1002 is the cycle penalty plus the two resource-days of overload dev1 still has.
Call-level errors still throw. An unknown focus id fails the whole call with InputException at path focus[i], and a stale token with ProjectException and ProjectError.StaleBaseline. See Error handling.
Parallel evaluation#
Each candidate runs on its own copy, so candidates are independent. On a multi-core host, Project.EvaluateWith spreads them over threads:
using Plen;
var project = SolvedProject();
// One candidate per resource that could take task B.
var candidates = new List<Candidate>();
foreach (var dev in new[] { "dev1", "dev2" })
candidates.Add(new Candidate { Id = dev, Changes = Reassign("aB", dev) });
var options = new EvaluateOptions();
var result = project.EvaluateWith(candidates, options, Execution.Parallel(4));
// Same results, same order as project.Evaluate(candidates, options).
foreach (var candidate in result.Candidates)
Console.WriteLine($"{candidate.Id}: cost {candidate.Cost}");
// Tasks A and B, two days each, both on dev1 in the same week.
static Project SolvedProject()
{
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("A") { StartDate = monday, Duration = 2.0 },
new TaskData("B") { StartDate = monday, Duration = 2.0 },
],
Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }],
Assignments =
[
new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1.0 },
new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1.0 },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
return project;
}
static SchedulingChanges Reassign(Id assignment, Id resource)
{
var changes = new SchedulingChanges();
changes.Assignments.Update.Add(new AssignmentUpdate(assignment) { Resource = resource });
return changes;
}
dev1: cost 2
dev2: cost 0
Execution.Parallel() with no argument uses Environment.ProcessorCount threads. A count of 0 or less throws ArgumentOutOfRangeException. Execution.Sequential, the default value of the struct, is what Evaluate does. The candidates run through Parallel.For with the thread count as the maximum degree of parallelism, so peak memory is one candidate copy per worker.
The results are identical to the sequential run and keep input order. If the call fails, you get the same exception as in a sequential run: the first one in input order. Later candidates may already have run.
EvaluateWith blocks the calling thread until every candidate is scored, and so does Evaluate. Every call in the library is synchronous and CPU-bound. In ASP.NET Core or another async host, run large evaluations with Task.Run or on a background worker. See Call from async code.
A Project isn't synchronized, and Evaluate with ClearFirst updates its internal copy-on-write state. Don't call it on one instance from several threads at once. EvaluateWith is the safe way to use several cores on one project. For other cases, see Share a project between threads.
Committing the winner#
Evaluate never changes the project. To commit the chosen candidate, run its changes for real: Apply the same change set, then call Level with the same LevelingOptions, Step included. With other options, the committed plan isn't the one that was scored. If you scored without Level, follow Apply with Solve(null, …) instead.
using Plen;
var project = SolvedProject();
Candidate[] candidates =
[
new() { Id = "stay", Changes = new SchedulingChanges() },
new() { Id = "dev2", Changes = Reassign("aB", "dev2") },
];
var leveling = new LevelingOptions();
var result = project.Evaluate(candidates, new EvaluateOptions { Level = leveling });
// Lowest cost wins; rejected candidates have no cost.
Candidate? winner = null;
double best = double.PositiveInfinity;
for (int i = 0; i < candidates.Length; i++)
{
if (result.Candidates[i].Cost is { } cost && cost < best)
(winner, best) = (candidates[i], cost);
}
if (winner is not null)
{
var changes = winner.Changes.DeepClone();
// Apply throws StaleBaseline if the project changed since the evaluation.
changes.BaselineId = result.BaselineId;
var report = project.Apply(changes);
if (report.Rejected.Count == 0)
{
// The same options that scored the candidate.
project.Level(leveling);
Console.WriteLine($"committed {winner.Id} (cost {best})");
}
}
// Tasks A and B, two days each, both on dev1 in the same week.
static Project SolvedProject()
{
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("A") { StartDate = monday, Duration = 2.0 },
new TaskData("B") { StartDate = monday, Duration = 2.0 },
],
Resources = [new ResourceData { Id = "dev1" }, new ResourceData { Id = "dev2" }],
Assignments =
[
new AssignmentData { Id = "aA", Task = "A", Resource = "dev1", Value = 1.0 },
new AssignmentData { Id = "aB", Task = "B", Resource = "dev1", Value = 1.0 },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
return project;
}
static SchedulingChanges Reassign(Id assignment, Id resource)
{
var changes = new SchedulingChanges();
changes.Assignments.Update.Add(new AssignmentUpdate(assignment) { Resource = resource });
return changes;
}
committed dev2 (cost 0)
Results come back in input order, so index i pairs each score with its change set. DeepClone() copies the change set before you set its token, so the candidate list stays as it was scored. Setting BaselineId to the token from the result makes Apply refuse the commit when another edit landed in between. In that case, evaluate again.
If you scored with EvaluateOptions.ClearFirst, commit with Level and LevelingOptions.ClearFirst (the default) so the commit re-levels from zero, like the scoring did.
To handle a rejected Apply, see Recover from rejected changes. To generate candidates automatically instead of writing them by hand, use SuggestAssignments, which scores its steps the same way. See Suggesting assignments.