Critical path and slack#
This guide shows how to find the tasks that set the project's finish date and how much room every other task has. You can get these numbers from a scheduling run, or from dates you already have without scheduling anything.
How analytics work#
Analytics are off by default. Ask for them with an AnalyticsOptions value. It has two flags, CriticalPath and Slack, and you can pass it in three places:
SolveOptions.Analytics, forEngine.ScheduleandProject.Solve. The analytics describe the freshly scheduled dates.PreviewOptions.Analytics, forProject.Preview. The analytics describe the previewed dates.AnalyzeOptions.Analytics, forProject.Analyze. The analytics describe dates you supply, or the project's current dates, as they are. Nothing gets scheduled.
When you set at least one flag, ScheduleResult.Analytics holds an Analytics object. With both flags off, it's null.
The engine works from two plans. The first plan is the dates being analyzed. For the second, the engine schedules the same tasks backward from the latest finish, which gives each task its latest possible start. Slack is the gap between the two:
- Total slack is how far a task can slip before the project's finish date moves. It's the latest start minus the planned start.
- Free slack is how far a task can slip before it pushes any successor. It's the smallest margin over the task's outgoing links, and never more than the total slack. A task with no successors has free slack equal to its total slack.
A task is critical when its total slack is zero or less. A link is critical when both of its tasks are critical and the link is binding, which means its target starts exactly when the link allows. Analytics.CriticalPath is a Critical object with the critical task ids in Tasks and the link ids in Links. Analytics.Slack holds one TaskSlack per task, with Task, Total and Free.
A few rules shape the output:
- Slack is a
doublein the configuredDurationUnit(days by default) and counts working time on each task's calendar. A weekend between two tasks doesn't add slack. - Only leaf tasks and milestones get a slack entry. A summary has no slack. It's critical when any of its non-summary descendants is.
- With
UseProgress, completed tasks (Progress == 1) report zero total and free slack, but they're never critical. - A dependency cycle makes the numbers meaningless.
Statusis thenAnalyticsStatus.Invalid, andCriticalPathandSlackare bothnull.
Getting critical path and slack#
Requesting analytics#
Set the flags in SolveOptions to get analytics together with the schedule.
using Plen;
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("design") { StartDate = monday, Duration = 2.0 },
new TaskData("build") { StartDate = monday, Duration = 3.0 },
new TaskData("docs") { StartDate = monday, Duration = 1.0 },
],
Links =
[
new LinkData { Id = "l1", Source = "design", Target = "build" },
new LinkData { Id = "l2", Source = "design", Target = "docs" },
],
};
var options = new SolveOptions
{
Analytics = new AnalyticsOptions { CriticalPath = true, Slack = true },
};
var result = Engine.Schedule(data, options);
var analytics = result.Analytics ?? throw new InvalidOperationException("analytics not requested");
if (analytics.CriticalPath is { } critical)
{
foreach (var id in critical.Tasks)
Console.WriteLine($"critical task: {id}");
foreach (var id in critical.Links)
Console.WriteLine($"critical link: {id}");
}
foreach (var s in analytics.Slack ?? [])
Console.WriteLine($"{s.Task}: total {s.Total} free {s.Free}");
build and docs both wait for design. build takes three days and docs takes one, so design and build form the critical path, joined by link l1. docs reports total 2 free 2: it can slip two working days before the project end moves.
Project.Solve takes the same SolveOptions. The cache key for Solve(null, …) is the whole SolveOptions value, so turning analytics on recomputes from the accepted dates. You don't get back a cached result that lacks them.
Checking a change before you commit it#
Set the flags in PreviewOptions to see how an edit would change the critical path.
using Plen;
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("design") { StartDate = monday, Duration = 2.0 },
new TaskData("build") { StartDate = monday, Duration = 3.0 },
new TaskData("docs") { StartDate = monday, Duration = 1.0 },
],
Links =
[
new LinkData { Id = "l1", Source = "design", Target = "build" },
new LinkData { Id = "l2", Source = "design", Target = "docs" },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
// What if the docs take five days instead of one?
var changes = new SchedulingChanges();
changes.Tasks.Update.Add(new TaskUpdate("docs") { Duration = 5.0 });
var options = new PreviewOptions
{
Analytics = new AnalyticsOptions { CriticalPath = true, Slack = true },
};
var result = project.Preview(changes, options);
var analytics = result.Analytics ?? throw new InvalidOperationException("analytics not requested");
if (analytics.CriticalPath is { } critical)
Console.WriteLine($"critical: {string.Join(", ", critical.Tasks)}");
foreach (var s in analytics.Slack ?? [])
Console.WriteLine($"{s.Task}: total {s.Total} free {s.Free}");
With five days of docs, the critical path moves to design, docs, and build now has two days of slack. The project itself doesn't change. For more on previewing, see Previewing changes.
Analyzing without scheduling#
Use Project.Analyze when you already have dates, for example from your own database or a gantt chart, and want the critical path for exactly those dates.
using Plen;
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var thursday = Moment.FromYmdHm(2026, 8, 13, 8, 0) ?? throw new InvalidOperationException("invalid date");
// "build" starts a day after "design" ends. A solve would pull it back to Wednesday.
var data = new ProjectData
{
Tasks =
[
new TaskData("design") { StartDate = monday, Duration = 2.0 },
new TaskData("build") { StartDate = thursday, Duration = 3.0 },
],
Links = [new LinkData { Id = "l1", Source = "design", Target = "build" }],
};
var project = new Project();
var options = new AnalyzeOptions
{
Analytics = new AnalyticsOptions { CriticalPath = true, Slack = true },
};
var result = project.Analyze(data, options);
Console.WriteLine(result.Updates.Count); // 0
var analytics = result.Analytics ?? throw new InvalidOperationException("analytics not requested");
if (analytics.CriticalPath is { } critical)
{
foreach (var id in critical.Tasks)
Console.WriteLine($"critical task: {id}");
}
foreach (var s in analytics.Slack ?? [])
Console.WriteLine($"{s.Task}: total {s.Total} free {s.Free}");
Only build is critical. design has one day of total and free slack, because build starts a day later than the link requires. Link l1 isn't critical: it isn't binding, and design isn't critical.
Analyze never changes the project. With a non-null data it validates and reads the data but doesn't install it. Invalid data throws InputException, as described in Error handling. The result has no Updates and no planner Conflicts, and its BaselineId is null.
Analyzing the project's current dates#
Pass null to analyze the dates the project holds now, including edits that haven't been solved yet.
using Plen;
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("design") { StartDate = monday, Duration = 2.0 },
new TaskData("build") { StartDate = monday, Duration = 3.0 },
new TaskData("docs") { StartDate = monday, Duration = 1.0 },
],
Links =
[
new LinkData { Id = "l1", Source = "design", Target = "build" },
new LinkData { Id = "l2", Source = "design", Target = "docs" },
],
};
var project = new Project();
project.Solve(data, new SolveOptions());
var options = new AnalyzeOptions
{
Analytics = new AnalyticsOptions { CriticalPath = true },
};
// Solved and clean: the result names the baseline it read.
var clean = project.Analyze(null, options);
Console.WriteLine(clean.BaselineId is not null); // True
// Commit an edit without solving.
var changes = new SchedulingChanges();
changes.Tasks.Update.Add(new TaskUpdate("docs") { Duration = 5.0 });
project.Apply(changes);
var dirty = project.Analyze(null, options);
Console.WriteLine(dirty.BaselineId is null); // True
if (dirty.Analytics?.CriticalPath is { } critical)
Console.WriteLine($"critical: {string.Join(", ", critical.Tasks)}");
After the edit, the critical path is design, docs. Analyze doesn't change the project's solved status, so the project still needs Solve(null, …) before Preview works again. BaselineId is set only when the project is solved and has no unsolved edits. Check it to tell whether the analytics describe the accepted baseline.
Reading the result#
Check Status first. Then read the lists you asked for. A flag you left off gives null for its list, even when the status is Available.
using Plen;
var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
Tasks =
[
new TaskData("phase") { TaskType = TaskType.Summary },
new TaskData("spec") { Parent = "phase", StartDate = monday, Duration = 1.0, Progress = 1.0 },
new TaskData("review") { Parent = "phase", StartDate = monday, Duration = 2.0 },
new TaskData("release") { StartDate = monday, Duration = 1.0 },
],
Links = [new LinkData { Id = "l1", Source = "review", Target = "release" }],
};
data.Config.UseProgress = true;
var options = new SolveOptions
{
Analytics = new AnalyticsOptions { CriticalPath = true, Slack = true },
};
var result = Engine.Schedule(data, options);
var analytics = result.Analytics ?? throw new InvalidOperationException("analytics not requested");
if (analytics.Status == AnalyticsStatus.Invalid)
{
Console.WriteLine($"{result.Cycles.Count} dependency cycle(s), no analytics");
return;
}
if (analytics.CriticalPath is { } critical)
Console.WriteLine($"critical: {string.Join(", ", critical.Tasks)}");
foreach (var s in analytics.Slack ?? [])
Console.WriteLine($"{s.Task}: total {s.Total} free {s.Free}");
The output shows each rule from the concept section:
critical: review, phase, release
spec: total 0 free 0
review: total 0 free 0
release: total 0 free 0
phaseis critical because its childreviewis. It has no slack entry, since summaries never get one.specis complete, so it reports zero slack. It still isn't on the critical path.- The critical task list follows the scheduling graph order, not input order. Look tasks up by id instead of relying on their position.
If the links form a cycle, the solve returns unchanged dates and lists each cycle in result.Cycles. The analytics then come back as Invalid with no lists. Fix the cycle and run again. For the rest of the result, see Reading results.