ResourceUpdate#

An edit to one existing resource of a live project. It goes in the Update list of SchedulingChanges.Resources, which Project.Apply and Project.Preview take. Create it with new ResourceUpdate(id) and set the fields to change in an object initializer. To add a resource, put a ResourceData in SchedulingChanges.Resources.Add instead.

Declaration#

namespace Plen;

public sealed class ResourceUpdate : IDeepCloneable<ResourceUpdate>

Constructors#

ResourceUpdate(Id)#

public ResourceUpdate(Id id)

Creates an update for the resource with the given id. Capacity and CalendarId start as Patch<T>.Missing, so the update changes nothing until one of them is set.

Name Type Description
id Id Id of the resource to edit. A string, int or double converts implicitly.

Properties#

Capacity and CalendarId are Patch<T> values. Missing (the default) keeps the stored value, a value sets it, and Null clears it. The On Null column shows what Null leaves behind. For the meaning of each value, see the property of the same name on ResourceData.

A plain double converts implicitly, so Capacity = 2.0 works. CalendarId needs Patch<Id>.Of(...) when the value is a string or a number, because C# doesn't chain the two implicit conversions.

Property Type On Null Description
Id Id required Id of the resource to edit.
Capacity Patch<double> null, so SchedulingConfig.DefaultResourceCapacity applies New capacity, in the same scale as assignment Value (1 = 100 %).
CalendarId Patch<Id> null, no calendar of its own New working calendar of the resource.

Dates after an update#

In CalendarMode.Resource with UseCalendars on, a CalendarId change can change the calendars that a leaf task's assignments work on. Each leaf task whose set of working calendars changes keeps its start and duration and gets its end derived again. In the Task and TaskInherited modes, the update doesn't move any dates. How a resource calendar combines with a task calendar is covered in Resource calendars.

Methods#

DeepClone#

public ResourceUpdate DeepClone()

Returns a copy with the same Id, Capacity and CalendarId.

ToString#

public override string ToString()

Returns a readable rendering of Id, Capacity and CalendarId, for logging. Each patch shows its state: Missing, Null or the carried value.

Errors#

An update is rejected as a single operation, at path resources.update[i]. Project.Apply and Project.Preview describe how a rejection is reported.

Message When it occurs
unknown resource id No resource has Id.
a validation message The edited resource breaks a ResourceData rule: Capacity is negative, NaN or infinite, or, in CalendarMode.Resource, CalendarId names no calendar.

Example#

Double a resource's capacity and drop its own calendar:

using Plen;

var monday = Moment.FromYmdHm(2026, 4, 6, 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 = 2.0 },
    ],
    Resources = [new ResourceData { Id = "dev1", Capacity = 1.0 }],
    Assignments =
    [
        new AssignmentData { Task = "design", Resource = "dev1", Value = 1.0 },
        new AssignmentData { Task = "build", Resource = "dev1", Value = 1.0 },
    ],
};

var project = new Project();
project.Solve(data, new SolveOptions());

var changes = new SchedulingChanges();
changes.Resources.Update.Add(new ResourceUpdate("dev1")
{
    Capacity = 2.0,
    CalendarId = Patch<Id>.Null,
});

var report = project.Apply(changes);
if (report.Rejected.Count == 0)
{
    var result = project.Solve(null, new SolveOptions());
    Console.WriteLine($"Overallocated resources: {result.Overallocations?.Count ?? 0}");
}