Project#

A stateful project. It holds one accepted baseline (the last solved dates), takes incremental edits and answers read-only questions about them: previews, analytics, load, candidate scoring and assignment proposals. Create one with new Project(), then load data with solve.

For a one-shot run over a snapshot, use Engine.schedule instead.

Declaration#

package org.dhtmlx.plen;

public class Project extends ValueRecord

Project has no public fields. It isn't AutoCloseable and needs no explicit release; the garbage collector reclaims it.

solve, apply and level change the project. Every other method leaves its state unchanged. All methods are synchronous and CPU-only. Each one throws NullPointerException for a null argument that isn't documented as nullable. All engine exceptions are unchecked; no method declares throws.

Project isn't synchronized, and that includes the read-only methods and copy(), which updates internal sharing flags on the source. Serialize access to one instance. To work from several threads, make one copy() per thread on a single thread first, or score candidates with evaluateWith and Execution.parallel(). See Share a project between threads.

Constructors#

Project()#

public Project()

Creates an empty, unsolved project with strict validation. Same as new Project((ProjectOptions) null).

Project(ProjectOptions)#

public Project(ProjectOptions options)

Creates an empty, unsolved project. The constructor deep-copies options, so later changes to the caller's object don't reach the project.

Parameters

Name Type Description
options ProjectOptions Project-wide settings, such as the validation mode. Nullable; null uses the defaults (strict validation).

Returns an empty Project with no baseline.

Project(Project)#

public Project(Project other)

Creates a copy of other. Same as other.copy().

Parameters

Name Type Description
other Project The project to copy

Methods#

Each method below except copy, equals and hashCode has its own page with the full contract.

solve#

public ScheduleResult solve(ProjectData data, SolveOptions options)

Schedules the project and accepts the scheduled dates as the baseline. A ProjectData replaces the project's data. null reschedules the current state after apply, or returns the cached result when nothing changed since a solve with equal options.

Returns a ScheduleResult that the project keeps as its baseline.

Errors: InputException for invalid data, ProjectException NEEDS_RESYNC for null after a rejected apply. See Project#solve.

preview#

public ScheduleResult preview(SchedulingChanges changes, PreviewOptions options)

Schedules hypothetical changes on a copy of the solved baseline. The project isn't modified.

Returns a ScheduleResult for the previewed state.

Errors: ProjectException NO_BASELINE / STALE_BASELINE, InputException for a rejected operation. See Project#preview.

analyze#

public ScheduleResult analyze(ProjectData data, AnalyzeOptions options)

Computes analytics, cycles and overallocations over supplied dates, or over the current dates when data is null. It doesn't schedule and never installs data.

Returns a ScheduleResult with empty updates.

Errors: InputException for invalid supplied data. See Project#analyze.

apply#

public ApplyReport apply(SchedulingChanges changes)

Commits edits to the accepted state and marks it unsolved. Rejected operations go into the report, not into an exception, and leave the project needing a full solve(data, …).

Returns an ApplyReport.

Errors: ProjectException NEEDS_RESYNC / STALE_BASELINE. See Project#apply.

level#

public LevelingResult level(LevelingOptions options)

Solves the current state, resolves resource overallocation with persistent levelingDelay / pauses edits and accepts the leveled state as the baseline. To see leveling without committing it, call level on a copy().

Returns a LevelingResult.

Errors: InputException for invalid options, ProjectException NEEDS_RESYNC. See Project#level.

loadProfile#

public LoadProfile loadProfile(LoadProfileOptions options)

Reads per-bucket load and capacity of resources on the solved baseline. Wrap a ProfileQuery in new LoadProfileOptions(query).

Returns a LoadProfile.

Errors: ProjectException NO_BASELINE / STALE_BASELINE, InputException for an invalid range or resource. See Project#loadProfile.

evaluate#

public EvaluateResult evaluate(Vec<Candidate> candidates, EvaluateOptions options)
public EvaluateResult evaluate(Collection<Candidate> candidates, EvaluateOptions options)

Scores alternative change sets against the solved baseline, each on a disposable copy. The project is never modified. A failure inside one candidate goes into that candidate's result.

Returns an EvaluateResult.

Errors: ProjectException NO_BASELINE / STALE_BASELINE, InputException for invalid options. See Project#evaluate.

evaluateWith#

public EvaluateResult evaluateWith(
    Vec<Candidate> candidates, EvaluateOptions options, Execution execution)
public EvaluateResult evaluateWith(
    Collection<Candidate> candidates, EvaluateOptions options, Execution execution)

evaluate with a choice of Execution. Execution.parallel(...) scores candidates on a thread pool and blocks until all finish. Results are identical to evaluate and keep input order.

Returns an EvaluateResult.

Errors: same as evaluate. See Project#evaluate.

suggestAssignments#

public SuggestResult suggestAssignments(Vec<Slot> slots, SuggestOptions options)
public SuggestResult suggestAssignments(Collection<Slot> slots, SuggestOptions options)

Proposes resources for requirement slots and returns the proposal as a change set. The project is never modified; commit the proposal with apply(result.changes).

Returns a SuggestResult.

Errors: ProjectException NO_BASELINE / STALE_BASELINE, InputException for invalid options or slots. See Project#suggestAssignments.

roster#

public Roster roster()

Reads the accepted state without skills: scheduled leaf tasks, resources and active assignments, in model order.

Returns a Roster.

Errors: ProjectException NO_BASELINE when the project is unsolved or has unsolved edits. See Project#roster.

copy#

public Project copy()

Returns an independent copy. Both projects share their state, including the cached solve result, until one of them changes it, so copying is cheap. Edits to one copy never affect the other.

Shared results are the same objects in both projects. Treat them as read-only, or call deepClone() on one before modifying it.

Returns a new Project with the same state, baseline and validation mode.

equals / hashCode#

public boolean equals(Object other)
public int hashCode()

Identity-based: a project equals only itself, and a copy never equals its source.

Example#

Load a project, commit an edit and reschedule it, falling back to a full reload when the edit is rejected.

import java.util.List;
import org.dhtmlx.plen.*;

public class ProjectExample {
  public static void main(String[] args) throws Exception {
    Moment monday = Moment.fromYmdHm(2026, 8, 10, 8, 0);
    ProjectData data = new ProjectData()
        .withTasks(List.of(new TaskData(Id.num(1)).withStartDate(monday).withDuration(2.0)));

    SolveOptions options = new SolveOptions();
    Project project = new Project();
    project.solve(data, options);

    SchedulingChanges changes = new SchedulingChanges();
    changes.tasks.update.add(new TaskUpdate(Id.num(1)).withDuration(Patch.of(3.0)));

    ApplyReport report = project.apply(changes);
    ScheduleResult result = report.needsResync
        ? project.solve(data, options)
        : project.solve(null, options);

    for (Mutation update : result.updates) {
      System.out.println("task " + update.id + ": " + update.startDate + " .. " + update.endDate);
    }
  }
}