Project#solve#

Schedules a Project and accepts the scheduled dates as its baseline. Pass a ProjectData object to load a project, or null to reschedule after apply. preview, loadProfile, evaluate, slots and suggestAssignments need a solved project.

For a one-shot run without keeping state, use schedule.

Signature#

solve(data: ProjectData | null, options?: SolveOptions): ScheduleResult

Synchronous. Runs on the calling thread.

Parameters#

Name Type Description
data ProjectData | null Replacement data, or null to schedule the current state. undefined is treated as null. Never mutated.
options SolveOptions Optional. Subtree, analytics and reporting switches. Default {}.

Behavior#

  • With data, the call validates the replacement data, installs it, schedules it and accepts the result. The previous data is discarded. How data is validated or repaired depends on the project's validation option (see Project).
  • With null, the call schedules the current state when it has unsolved edits. When the project is already solved with equal options, it returns the cached result without scheduling again. The cache key is the whole options object.

Tasks touched by successful apply calls since the last solve appear in updates as direct updates, even when the planner leaves them where the edit put them. A cyclic project returns unchanged dates and keeps those tasks pending.

The result's baselineId names the accepted baseline. It changes only when the data or the dates change, so solving an unchanged state keeps it.

Returns#

A ScheduleResult. Each call returns a fresh object that shares nothing with data or the project, including a cached result. Date fields are strings, or local Date objects when the project was created with dates: "date".

Errors#

Error When
InputError data or options fails parsing or validation; kind, message and path describe the problem. Also thrown for a non-finite number or an invalid Date in the input. The previous state and cached result are kept.
ProjectError "needs-resync" data is null after an apply rejected an operation and no solve(data) followed
TypeError The input has a circular reference or a BigInt.
Error("Project has been disposed") The project was disposed with dispose.

Example#

Load a project, commit an edit and reschedule it.

import { Project } from "plen-js";

const project = new Project();
const loaded = project.solve({
  tasks: [{ id: "a", start_date: "2026-08-10 08:00", duration: 2 }],
});

// Nothing changed: the cached result comes back with the same baselineId.
const again = project.solve(null);
console.log(again.baselineId === loaded.baselineId); // true

project.apply({ tasks: { update: [{ id: "a", duration: 3 }] } });

const result = project.solve(null);
for (const update of result.updates) {
  console.log(`task ${update.id}: ${update.start_date} .. ${update.end_date}`);
  // task a: 2026-08-10 08:00 .. 2026-08-13 08:00
}