ResourceOverallocation#

The overallocated periods of one resource. You get it in ScheduleResult::overallocations, including the one in LevelingResult::schedule.

The list holds one entry per overallocated resource. A resource whose load never exceeds its capacity has no entry, so windows is never empty.

Declaration#

#[derive(Clone, Debug, PartialEq)]
pub struct ResourceOverallocation {
    pub resource: Id,
    pub windows: Vec<OverallocationWindow>,
}

With the serde feature, ResourceOverallocation implements Serialize and Deserialize. See Serialize results to JSON.

Fields#

Field Type Description
resource Id Id of the resource, as given in ResourceData::id.
windows Vec<OverallocationWindow> The resource's overallocated periods: the edges, capacity, peak load, overload and contending tasks of each.

Example#

Two one-day tasks on the same day, each booking the full capacity of one resource:

use plen_core::{
    schedule, AssignmentData, DateTime, ProjectData, ResourceData, SolveOptions, TaskData,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let monday = DateTime::from_ymd_hm(2026, 1, 5, 8, 0).ok_or("invalid date")?;

    let mut design = TaskData::new("design");
    design.start_date = Some(monday);
    design.duration = Some(1.0);

    let mut review = TaskData::new("review");
    review.start_date = Some(monday);
    review.duration = Some(1.0);

    let assign = |task: &str| AssignmentData {
        id: None,
        task: task.into(),
        resource: "anna".into(),
        value: 1.0,
        offset: None,
        duration: None,
    };

    let data = ProjectData {
        tasks: vec![design, review],
        resources: vec![ResourceData {
            id: "anna".into(),
            capacity: Some(1.0),
            calendar_id: None,
        }],
        assignments: vec![assign("design"), assign("review")],
        ..Default::default()
    };

    let result = schedule(data, &SolveOptions::default())?;

    for entry in result.overallocations.iter().flatten() {
        for window in &entry.windows {
            println!(
                "{}: {} -> {}, peak {} of {}, tasks {:?}",
                entry.resource, window.from, window.to, window.peak, window.capacity, window.tasks
            );
        }
    }
    Ok(())
}