Split assignment work#

Hand one task's work to several people, for example one developer for the first two days and another for the rest, without changing the task's dates.

Use the offset and duration fields of AssignmentData to do this. Each assignment books only its own part of the task, called a slice. For how slices affect load, see Resources and assignments.

Steps#

  1. Book each person on their part of the task. Both fields are worked time in the task's duration_unit, counted from the task start:

    • offset: where the slice starts. None means the task start.
    • duration: how much work the slice books. None means up to the task end.
    use plen_core::AssignmentData;
    
    // Anna works the first 2 days of `build`.
    let anna = AssignmentData {
        id: Some("build:anna".into()),
        task: "build".into(),
        resource: "anna".into(),
        value: 1.0,
        offset: None,
        duration: Some(2.0),
    };
    // Ben starts after 2 days of work and finishes the task.
    let ben = AssignmentData {
        id: Some("build:ben".into()),
        task: "build".into(),
        resource: "ben".into(),
        value: 1.0,
        offset: Some(2.0),
        duration: None,
    };
    
  2. Pass the assignments to solve(Some(data), ...) as usual. Then check the booked load with Project::load_profile:

    use plen_core::{Basis, LoadProfileOptions, ProfileQuery};
    
    let mut query = ProfileQuery::new(from, to);
    query.basis = Some(Basis::Day);
    let profile = project.load_profile(&LoadProfileOptions::from(query))?;
    
  3. To move the handover in a live project, send an AssignmentUpdate for each slice, then call solve(None, ...):

    use plen_core::{AssignmentUpdate, Patch, SchedulingChanges};
    
    let mut anna = AssignmentUpdate::new("build:anna");
    anna.duration = Patch::Value(3.0);
    let mut ben = AssignmentUpdate::new("build:ben");
    ben.offset = Patch::Value(3.0);
    
    let mut changes = SchedulingChanges::default();
    changes.assignments.update.extend([anna, ben]);
    
  4. To book the whole task again, set the field to Patch::Null. offset: Patch::Null goes back to the task start, and duration: Patch::Null goes up to the task end.

The full example splits the 4-day build task between Anna and Ben, prints their daily load, then moves the handover one day later:

use plen_core::{
    AssignmentData, AssignmentUpdate, Basis, DateTime, LoadProfileOptions, Patch, Project,
    ProfileQuery, ProjectData, ResourceData, SchedulingChanges, SolveOptions, TaskData,
};

fn person(id: &str) -> ResourceData {
    ResourceData { id: id.into(), capacity: None, calendar_id: None }
}

fn print_load(project: &Project) -> Result<(), Box<dyn std::error::Error>> {
    // Daily load from Monday 2026-08-10 to Friday 2026-08-14.
    let from = DateTime::from_ymd_hm(2026, 8, 10, 0, 0).ok_or("invalid date")?;
    let to = DateTime::from_ymd_hm(2026, 8, 15, 0, 0).ok_or("invalid date")?;
    let mut query = ProfileQuery::new(from, to);
    query.basis = Some(Basis::Day);
    let profile = project.load_profile(&LoadProfileOptions::from(query))?;
    for resource in &profile.resources {
        let loads: Vec<f64> = resource.buckets.iter().map(|b| b.load).collect();
        println!("  {}: {:?}", resource.resource, loads);
    }
    Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // `build`: 4 working days, Monday to Thursday.
    let mut build = TaskData::new("build");
    build.start_date = DateTime::from_ymd_hm(2026, 8, 10, 8, 0);
    build.duration = Some(4.0);

    let data = ProjectData {
        tasks: vec![build],
        resources: vec![person("anna"), person("ben")],
        assignments: vec![
            // Anna works the first 2 days of `build`.
            AssignmentData {
                id: Some("build:anna".into()),
                task: "build".into(),
                resource: "anna".into(),
                value: 1.0,
                offset: None,
                duration: Some(2.0),
            },
            // Ben starts after 2 days of work and finishes the task.
            AssignmentData {
                id: Some("build:ben".into()),
                task: "build".into(),
                resource: "ben".into(),
                value: 1.0,
                offset: Some(2.0),
                duration: None,
            },
        ],
        ..Default::default()
    };

    let mut project = Project::default();
    let first = project.solve(Some(data), &SolveOptions::default())?;
    println!("handover after day 2");
    print_load(&project)?;

    // Move the handover one day later: Anna works 3 days, Ben the last one.
    let mut anna = AssignmentUpdate::new("build:anna");
    anna.duration = Patch::Value(3.0);
    let mut ben = AssignmentUpdate::new("build:ben");
    ben.offset = Patch::Value(3.0);
    let mut changes = SchedulingChanges::default();
    changes.baseline_id = first.baseline_id.clone();
    changes.assignments.update.extend([anna, ben]);

    let report = project.apply(&changes)?;
    if !report.rejected.is_empty() {
        return Err(format!("rejected: {:?}", report.rejected).into());
    }
    let result = project.solve(None, &SolveOptions::default())?;
    println!("handover after day 3, moved tasks: {}", result.updates.len());
    print_load(&project)?;
    Ok(())
}

load_profile needs a solved project, so call solve(None, ...) after apply and before you read the load again.

Things to check#

  • Slices never move tasks. A slice edit leaves every task date as it was, but it changes the baseline_id, so a SchedulingChanges that still carries the old token fails with Error::Project(ProjectError::StaleBaseline).
  • The engine clips the slice to the task's work when it books load. A slice that runs past the task end books only up to the end. An offset at or past the task's duration books nothing. If the task gets shorter later, the slice follows it.
  • Non-working time and leveling pauses don't count as worked time. A pause or a leveling_delay moves the slice together with the work.
  • Two slices of the same resource on the same task add up where they overlap.
  • Strict validation rejects an offset below 0 or not finite, and a duration of 0 or less or not finite. solve(Some(data)) returns Error::Input at assignments[i].offset or assignments[i].duration. In apply, the same values show up as rejected operations in ApplyReport.rejected, at paths like assignments.update[0]. See Recover from rejected changes.
  • With Validation::Repair, the engine clears an invalid value and adds a Note::Repaired, so the assignment books the whole task. See Accept messy input.
  • An assignment on an unscheduled task keeps its slice and books it again when the task is scheduled.

Result#

The example prints each person's load for Monday to Friday, before and after the handover moves:

handover after day 2
  anna: [1.0, 1.0, 0.0, 0.0, 0.0]
  ben: [0.0, 0.0, 1.0, 1.0, 0.0]
handover after day 3, moved tasks: 0
  anna: [1.0, 1.0, 1.0, 0.0, 0.0]
  ben: [0.0, 0.0, 0.0, 1.0, 0.0]

The load moves from Ben to Anna on Wednesday. build keeps its dates, so solve(None, ...) reports no moved tasks.