Table of Contents

Class CumulExpr

Namespace
OptalCP
Assembly
OptalCP.dll

Tracks cumulative resource usage over time for capacity constraints.

public class CumulExpr : ModelElement
Inheritance
CumulExpr
Inherited Members

Remarks

Cumulative expression.

Cumulative expression represents resource usage over time. The resource could be a machine, a group of workers, a material, or anything of a limited capacity. The resource usage is not known in advance as it depends on the variables of the problem. Cumulative expressions allow us to model the resource usage and constrain it.

Basic cumulative expressions are:

  • Pulse: the resource is used over an interval of time. For example, a pulse can represent a task requiring a certain number of workers during its execution. At the beginning of the interval, the resource usage increases by a given amount, and at the end of the interval, the resource usage decreases by the same amount. Pulse can be created by function Model.Pulse or IntervalVar.Pulse.
  • Step: a given amount of resource is consumed or produced at a specified time (e.g., at the start of an interval variable). Steps may represent an inventory of a material that is consumed or produced by some tasks (a reservoir). Steps can be created by functions Model.StepAtStart, IntervalVar.StepAtStart, Model.StepAtEnd, IntervalVar.StepAtEnd. and Model.StepAt.

Cumulative expressions can be combined using operators (+, -, unary -) and Model.Sum. The resulting cumulative expression represents a sum of the resource usage of the combined expressions.

Cumulative expressions can be constrained using comparison operators (<=, >=) to specify the minimum and maximum allowed resource usage.

Limitations:

  • Pulse-based and step-based cumulative expressions cannot be mixed.
  • Pulses cannot have negative height. Use - and unary - only with step-based expressions.

See Model.Pulse for examples.

Operators

operator +(CumulExpr, CumulExpr)

Add two cumulative expressions using the + operator.

public static CumulExpr operator +(CumulExpr lhs, CumulExpr rhs)

Parameters

lhs CumulExpr
rhs CumulExpr

Returns

CumulExpr

A new cumulative expression representing the sum.

Remarks

Returns a new CumulExpr representing the combined resource usage of two cumulative expressions.

Use this to combine resource usages from different sources. For example, combining the cumulative usage of two different task types on the same resource.

Limitation: Currently, pulse-based and step-based cumulative expressions cannot be mixed. You can add pulses to pulses and steps to steps, but not pulses to steps.

var total = workers + machines;
model.Enforce(total <= 10);

See also:

  • Model.Sum — for summing multiple cumulative expressions.

operator >=(CumulExpr, IntExpr)

Constrain a cumulative expression to be at least a bound using >=.

public static Constraint operator >=(CumulExpr lhs, IntExpr rhs)

Parameters

lhs CumulExpr
rhs IntExpr

Returns

Constraint

A constraint that the cumulative expression meets or exceeds the bound.

Remarks

Returns a Constraint enforcing that the cumulative expression is at least the given bound at every point in time. The bound can be an int constant or an IntExpr.

Limitation: This constraint can only be used with step-based cumulative expressions, not with pulses.

Important: The constraint requires the minimum level to be maintained everywhere, including at the beginning of time. If the required level is greater than 0, you must include a step at Model.IntervalMin (not at 0) to establish the initial level.

All equivalent forms are supported: cumul >= bound and bound <= cumul.

// Require at least 2 workers active at any time
model.Enforce(workerUsage >= 2);

// With an integer expression bound
model.Enforce(workerUsage >= minRequired);

See also the <= operator for the maximum capacity constraint.

operator >=(CumulExpr, int)

Constrain a cumulative expression to be at least a bound using >=.

public static Constraint operator >=(CumulExpr lhs, int rhs)

Parameters

lhs CumulExpr
rhs int

Returns

Constraint

A constraint that the cumulative expression meets or exceeds the bound.

Remarks

Returns a Constraint enforcing that the cumulative expression is at least the given bound at every point in time. The bound can be an int constant or an IntExpr.

Limitation: This constraint can only be used with step-based cumulative expressions, not with pulses.

Important: The constraint requires the minimum level to be maintained everywhere, including at the beginning of time. If the required level is greater than 0, you must include a step at Model.IntervalMin (not at 0) to establish the initial level.

All equivalent forms are supported: cumul >= bound and bound <= cumul.

// Require at least 2 workers active at any time
model.Enforce(workerUsage >= 2);

// With an integer expression bound
model.Enforce(workerUsage >= minRequired);

See also the <= operator for the maximum capacity constraint.

operator >=(IntExpr, CumulExpr)

Constrain a cumulative expression to be at most a bound using <=.

public static Constraint operator >=(IntExpr lhs, CumulExpr rhs)

Parameters

lhs IntExpr
rhs CumulExpr

Returns

Constraint

A constraint that the cumulative expression does not exceed the bound.

Remarks

Returns a Constraint enforcing that the cumulative expression is at most the given bound at every point in time. The bound can be an int constant or an IntExpr.

Limitations:

  • Variable capacity (using IntExpr) is only supported for discrete resources (pulses). Reservoir resources (steps) require a constant capacity.
  • The capacity expression must not be optional or absent.

All equivalent forms are supported: cumul <= bound and bound >= cumul.

// Limit resource usage to 5 workers at any time
model.Enforce(workerUsage <= 5);

// With an integer expression bound
model.Enforce(workerUsage <= capacity);

See also the >= operator for the minimum capacity constraint.

operator >=(int, CumulExpr)

Constrain a cumulative expression to be at most a bound using <=.

public static Constraint operator >=(int lhs, CumulExpr rhs)

Parameters

lhs int
rhs CumulExpr

Returns

Constraint

A constraint that the cumulative expression does not exceed the bound.

Remarks

Returns a Constraint enforcing that the cumulative expression is at most the given bound at every point in time. The bound can be an int constant or an IntExpr.

Limitations:

  • Variable capacity (using IntExpr) is only supported for discrete resources (pulses). Reservoir resources (steps) require a constant capacity.
  • The capacity expression must not be optional or absent.

All equivalent forms are supported: cumul <= bound and bound >= cumul.

// Limit resource usage to 5 workers at any time
model.Enforce(workerUsage <= 5);

// With an integer expression bound
model.Enforce(workerUsage <= capacity);

See also the >= operator for the minimum capacity constraint.

operator <=(CumulExpr, IntExpr)

Constrain a cumulative expression to be at most a bound using <=.

public static Constraint operator <=(CumulExpr lhs, IntExpr rhs)

Parameters

lhs CumulExpr
rhs IntExpr

Returns

Constraint

A constraint that the cumulative expression does not exceed the bound.

Remarks

Returns a Constraint enforcing that the cumulative expression is at most the given bound at every point in time. The bound can be an int constant or an IntExpr.

Limitations:

  • Variable capacity (using IntExpr) is only supported for discrete resources (pulses). Reservoir resources (steps) require a constant capacity.
  • The capacity expression must not be optional or absent.

All equivalent forms are supported: cumul <= bound and bound >= cumul.

// Limit resource usage to 5 workers at any time
model.Enforce(workerUsage <= 5);

// With an integer expression bound
model.Enforce(workerUsage <= capacity);

See also the >= operator for the minimum capacity constraint.

operator <=(CumulExpr, int)

Constrain a cumulative expression to be at most a bound using <=.

public static Constraint operator <=(CumulExpr lhs, int rhs)

Parameters

lhs CumulExpr
rhs int

Returns

Constraint

A constraint that the cumulative expression does not exceed the bound.

Remarks

Returns a Constraint enforcing that the cumulative expression is at most the given bound at every point in time. The bound can be an int constant or an IntExpr.

Limitations:

  • Variable capacity (using IntExpr) is only supported for discrete resources (pulses). Reservoir resources (steps) require a constant capacity.
  • The capacity expression must not be optional or absent.

All equivalent forms are supported: cumul <= bound and bound >= cumul.

// Limit resource usage to 5 workers at any time
model.Enforce(workerUsage <= 5);

// With an integer expression bound
model.Enforce(workerUsage <= capacity);

See also the >= operator for the minimum capacity constraint.

operator <=(IntExpr, CumulExpr)

Constrain a cumulative expression to be at least a bound using >=.

public static Constraint operator <=(IntExpr lhs, CumulExpr rhs)

Parameters

lhs IntExpr
rhs CumulExpr

Returns

Constraint

A constraint that the cumulative expression meets or exceeds the bound.

Remarks

Returns a Constraint enforcing that the cumulative expression is at least the given bound at every point in time. The bound can be an int constant or an IntExpr.

Limitation: This constraint can only be used with step-based cumulative expressions, not with pulses.

Important: The constraint requires the minimum level to be maintained everywhere, including at the beginning of time. If the required level is greater than 0, you must include a step at Model.IntervalMin (not at 0) to establish the initial level.

All equivalent forms are supported: cumul >= bound and bound <= cumul.

// Require at least 2 workers active at any time
model.Enforce(workerUsage >= 2);

// With an integer expression bound
model.Enforce(workerUsage >= minRequired);

See also the <= operator for the maximum capacity constraint.

operator <=(int, CumulExpr)

Constrain a cumulative expression to be at least a bound using >=.

public static Constraint operator <=(int lhs, CumulExpr rhs)

Parameters

lhs int
rhs CumulExpr

Returns

Constraint

A constraint that the cumulative expression meets or exceeds the bound.

Remarks

Returns a Constraint enforcing that the cumulative expression is at least the given bound at every point in time. The bound can be an int constant or an IntExpr.

Limitation: This constraint can only be used with step-based cumulative expressions, not with pulses.

Important: The constraint requires the minimum level to be maintained everywhere, including at the beginning of time. If the required level is greater than 0, you must include a step at Model.IntervalMin (not at 0) to establish the initial level.

All equivalent forms are supported: cumul >= bound and bound <= cumul.

// Require at least 2 workers active at any time
model.Enforce(workerUsage >= 2);

// With an integer expression bound
model.Enforce(workerUsage >= minRequired);

See also the <= operator for the maximum capacity constraint.

operator -(CumulExpr, CumulExpr)

Subtract two cumulative expressions using the - operator.

public static CumulExpr operator -(CumulExpr lhs, CumulExpr rhs)

Parameters

lhs CumulExpr
rhs CumulExpr

Returns

CumulExpr

A new cumulative expression representing the difference.

Remarks

Returns a new CumulExpr representing the difference of two cumulative expressions.

Limitation: This operator can only be used with step-based cumulative expressions, not with pulses. Pulses cannot have negative height.

Use this to compute the net effect of additions and removals. For example, tracking inventory where items are added and removed over time.

var net = produced - consumed;
model.Enforce(net >= 0);

operator -(CumulExpr)

Negate a cumulative expression using the unary - operator.

public static CumulExpr operator -(CumulExpr expr)

Parameters

expr CumulExpr

Returns

CumulExpr

A new cumulative expression representing the negation.

Remarks

Returns a new CumulExpr representing -expr.

Limitation: This operator should only be used with step-based cumulative expressions, not with pulses. Pulses cannot have negative height.

Negating a cumulative expression flips the sign of all its values over time. Useful for modeling resource production as the negation of consumption.

var production = -consumption;