Class: CumulExpr
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 CumulExpr.plus, CumulExpr.minus, CumulExpr.neg and Model.sum. The resulting cumulative expression represents a sum of the resource usage of the combined expressions.
Cumulative expressions can be constrained by CumulExpr.ge and CumulExpr.le 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 CumulExpr.le and CumulExpr.ge for examples.
Extends
Accessors
name
Get Signature
get name():
undefined|string
The name assigned to this model element.
Remarks
The name is optional and primarily useful for debugging purposes. When set, it helps identify the element in solver logs, error messages, and when inspecting solutions.
Names can be assigned to any model element including variables, expressions, and constraints.
Example
import * as CP from "optalcp";
const model = new CP.Model();
// Name a variable at creation
const task = model.intervalVar({ length: 10, name: "assembly" });
// Or set name later
const x = model.intVar({ min: 0, max: 100 });
x.name = "quantity";
console.log(task.name); // "assembly"
console.log(x.name); // "quantity"
Returns
undefined | string
Set Signature
set name(
value:string):void
Parameters
| Parameter | Type |
|---|---|
value | string |
Returns
void
Inherited from
Constructors
new CumulExpr()
new CumulExpr():
CumulExpr
Returns
Inherited from
Methods
ge()
ge(
minCapacity:number):Constraint
This function can be used to specify the minimum limit of resource usage at any time. minCapacity.
Parameters
| Parameter | Type | Description |
|---|---|---|
minCapacity | number | The minimum capacity value. |
Returns
Constraint
The constraint object
Remarks
This function can be used to specify the minimum limit of resource usage at any time. For example to make sure that there is never less than zero material on stock.
See Model.stepAtStart for an example with ge.
See
le()
le(
maxCapacity:number):Constraint
Constrains the cumulative function to be everywhere less or equal to maxCapacity.
Parameters
| Parameter | Type | Description |
|---|---|---|
maxCapacity | number | The maximum capacity value. |
Returns
Constraint
The constraint object
Remarks
This function can be used to specify the maximum limit of resource usage at any time. For example, to limit the number of workers working simultaneously, limit the maximum amount of material on stock, etc.
See Model.pulse for an example with le.
See
minus()
Subtraction of two cumulative expressions.
Parameters
| Parameter | Type | Description |
|---|---|---|
rhs | CumulExpr | The right-hand side cumulative expression. |
Returns
The resulting cumulative expression
Remarks
This function is the same as Model.minus.
neg()
neg():
CumulExpr
Negation of a cumulative expression.
Returns
The resulting cumulative expression
Remarks
This function is the same as Model.neg.
plus()
Addition of two cumulative expressions.
Parameters
| Parameter | Type | Description |
|---|---|---|
rhs | CumulExpr | The right-hand side cumulative expression. |
Returns
The resulting cumulative expression
Remarks
This function is the same as Model.plus.
Properties
| Property | Modifier | Type |
|---|---|---|
__brand | readonly | "CumulExpr" |