Skip to main content

cumulative

Function cumulative 

Source
pub fn cumulative<StartTimes, Durations, ResourceRequirements>(
    start_times: StartTimes,
    durations: Durations,
    resource_requirements: ResourceRequirements,
    resource_capacity: i32,
    constraint_tag: ConstraintTag,
) -> impl Constraint
where StartTimes: IntoIterator, <StartTimes as IntoIterator>::Item: IntegerVariable + Debug + 'static, <StartTimes as IntoIterator>::IntoIter: ExactSizeIterator, Durations: IntoIterator<Item = i32>, <Durations as IntoIterator>::IntoIter: ExactSizeIterator, ResourceRequirements: IntoIterator<Item = i32>, <ResourceRequirements as IntoIterator>::IntoIter: ExactSizeIterator,
Expand description

Creates the Cumulative Constraint.

This constraint ensures that at no point in time, the cumulative resource usage of the tasks exceeds bound.

The implementation uses a form of time-table reasoning (for an example of this type of reasoning, see [1], note that it does not implement the specific algorithm in the paper but that the reasoning used is the same).

The length of start_times, durations and resource_requirements should be the same; if this is not the case then this method will panic.

It is possible to specify certain options for the cumulative (such as whether to allow holes in the domain or the type of explanation) using cumulative_with_options.

§Example

// We construct three tasks for a resource with capacity 2:
// - Task 0: Start times: [0, 5], Processing time: 4, Resource usage: 1
// - Task 1: Start times: [0, 5], Processing time: 2, Resource usage: 1
// - Task 2: Start times: [0, 5], Processing time: 4, Resource usage: 2
// We can infer that Task 0 and Task 1 execute at the same time
// while Task 2 will start after them
let solver = Solver::default();

let mut solver = Solver::default();

let start_0 = solver.new_bounded_integer(0, 4);
let start_1 = solver.new_bounded_integer(0, 4);
let start_2 = solver.new_bounded_integer(0, 5);

let constraint_tag = solver.new_constraint_tag();

let start_times = [start_0, start_1, start_2];
let durations = [5, 2, 5];
let resource_requirements = [1, 1, 2];
let resource_capacity = 2;

solver
    .add_constraint(pumpkin_constraints::cumulative(
        start_times.clone(),
        durations.clone(),
        resource_requirements.clone(),
        resource_capacity,
        constraint_tag,
    ))
    .post();

// ...

§Bibliography

[1] S. Gay, R. Hartert, and P. Schaus, ‘Simple and scalable time-table filtering for the cumulative constraint’, in Principles and Practice of Constraint Programming: 21st International Conference, CP 2015, Cork, Ireland, August 31–September 4, 2015, Proceedings 21, 2015, pp. 149–157.