Evaluating alternatives#
This guide shows how to compare several possible edits in one call and pick the best one, for example 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 value, 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. It never modifies the project, just like 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.solve(null, …)and measure the scheduled stage.- When
EvaluateOptions.levelis set,levelwith 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 one 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 (ProjectException with code NO_BASELINE), a stale baselineId in the options or in any candidate (code STALE_BASELINE), an unknown focus task or leveling options that don't fit the baseline (InputException). Everything else fails only its own candidate: the 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.
;
;
baseline: cost 2.0
stay: cost 2.0
dev2: cost 0.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.
evaluate takes a Vec<Candidate> or any Collection<Candidate>, so List.of(...) works. 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. A candidate needs a changes value; new Candidate() leaves it null. See the Candidate reference.
Options#
EvaluateOptions has four fields, all with defaults:
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. Nothing is added implicitly, so list the tasks your candidates are about.baselineId: a baseline token. The call throws aProjectExceptionwith codeSTALE_BASELINEwhen it no longer names the accepted baseline. Each candidate'schanges.baselineIdis checked the same way.clearFirst: score against a copy with the in-scopelevelingDelayandpausescleared. Defaultfalse.
Leveling changes the scores. Without it, an overloaded plan scores badly on overload. With it, the overload turns into delay, which is what the user gets after committing and leveling:
;
;
stay: project ends 2026-08-14 08:00 (+2 days), cost 2.0
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.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.
level runs with the options exactly as you pass them. LevelingOptions.clearFirst defaults to true, so each candidate is re-leveled from zero. That's a trap after an earlier 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, then solves that copy. The baseline metrics and every candidate run use the copy. The scope is level.scope.tasks when you set it, otherwise every task. The flag is independent of LevelingOptions.clearFirst, so it also works without level.
;
;
baseline overload: 2.0
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. Use clearFirst when you'll commit with level and LevelingOptions.clearFirst, which re-levels from zero, because that's the plan it scores.
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
clearFirstset tofalse.
The full field list is on the EvaluateOptions reference. For the leveling options themselves, see Leveling resources.
Metrics and cost#
Every stage reports the same Metrics:
| Field | 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, both double.
Overload is measured the way the leveler sees it. For each time bucket, it's how far a resource's load goes over its capacity, summed over the 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 to every stage of every candidate: level.basis when you set it, otherwise the one derived from config.durationUnit. The same per-resource sum is what loadProfile shows as excess 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 object: the same Metrics in its metrics field, 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 a Double holding 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:
;
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 (only the first rejection is reported), orsolveorlevelfails on the candidate's input, for example on a leveling scope id the candidate removed. The result'serrorholds 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 the 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.
;
;
missing rejected at assignments.update[0]: unknown assignment id
cycle is cyclic, leveled: false
cycle cost 1002.0
removed removes focus task B
removed cost 0.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 an InputException at path focus[i], and a stale token with a ProjectException with code STALE_BASELINE. Both are unchecked. See Handling errors.
Parallel evaluation#
Each candidate runs on its own copy, so candidates are independent. Project#evaluateWith takes an Execution and can spread them over threads:
;
;
Execution.parallel() (or Execution.parallel(null)) uses Runtime.availableProcessors() threads. Execution.parallel(0) or a negative count throws an IllegalArgumentException. Execution.sequential() is what evaluate does.
The call runs the candidates on a private fixed thread pool of min(threads, candidates) workers and shuts it down before returning. It blocks the calling thread until every candidate is done. 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.
evaluate and evaluateWith are synchronous and CPU-bound, like every call in the library. In a reactive server or on a request thread, run large evaluations on a worker executor. Don't call evaluateWith on the same Project from several threads at once: the project isn't synchronized. See the Execution reference and Call from async code.
Committing the winner#
evaluate never changes the project. To commit the chosen candidate, run its changes for real: apply the same change set, then 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.
;
;
Results come back in input order, so index i in result.candidates pairs with index i in your list. The code copies the winning change set with deepClone() before setting its baselineId, so the candidate stays as it was. With the token from the result, apply throws a ProjectException with code STALE_BASELINE when another edit landed in between. In that case, evaluate again.
If you scored with EvaluateOptions.clearFirst, commit with level and LevelingOptions.clearFirst left at true (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.