Skip to main content

Class: CumulExpr

Cumulative expression.

Cumulative expression represents a resource usage over time. The resource could be a machine, a group of workers, a material, 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 to model the resource usage and constrain it.

Basic cumulative expressions are:

  • Pulse: the resource is used over an interval of time. For example, pulse can be used to represent a task that requires 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: given amount of resource is consumed or produced at a specified time (e.g. at a start of an interval variable). Steps can be used to 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 together using Model.cumulPlus, Model.cumulMinus, cumulNeg and Model.cumulSum. The resulting cumulative expression represents a sum of the resource usage of the combined expressions.

Cumulative expressions can be constrained by Model.cumulGe and Model.cumulLe constraints to specify the minimum and maximum allowed resource usage.

See Model.cumulLe and Model.cumulGe for examples.

Extends

Methods

cumulGe()

cumulGe(minCapacity: number): void

Constraints the cumulative function to be everywhere greater or equal to minCapacity.

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 cumulGe.

Parameters

ParameterType
minCapacitynumber

Returns

void

See


cumulLe()

cumulLe(maxCapacity: number): void

Constraints the cumulative function to be everywhere less or equal to maxCapacity.

This function can be used to specify the maximum limit of resource usage at any time. For example to limit number of workers working simultaneously, limit the maximum amount of material on stock etc. See Model.pulse for an example with cumulLe.

Parameters

ParameterType
maxCapacitynumber

Returns

void

See


cumulMinus()

cumulMinus(rhs: CumulExpr): CumulExpr

Subtraction of two cumulative expressions.

Parameters

ParameterType
rhsCumulExpr

Returns

CumulExpr

Remarks

This function is the same as Model.minus.


cumulNeg()

cumulNeg(): CumulExpr

Negation of a cumulative expression.

Returns

CumulExpr

Remarks

This function is the same as Model.neg.


cumulPlus()

cumulPlus(rhs: CumulExpr): CumulExpr

Addition of two cumulative expressions.

Parameters

ParameterType
rhsCumulExpr

Returns

CumulExpr

Remarks

This function is the same as Model.plus.


getName()

getName(): undefined | string

Returns the name assigned to the node.

Returns

undefined | string

Inherited from

ModelNode.getName


setName()

setName(name: string): this

Assigns a name to the node.

Parameters

ParameterTypeDescription
namestringNamed to be assigned.

Returns

this

The node itself so it can be used in chained expression.

Remarks

Assigning a name is optional. However is useful for debugging because variable names appear in the development traces. It is also useful for exporting the model to a file (see problem2json).

Example

let model = new CP.Model();
let x = model.intervalVar({ length: 10 }).setName("x");
// The line above is equivalent to:
// let x = model.intervalVar({ length: 10, name:"x" });
let endOfX = model.endOf(x).setName("endOfX");
let result = await CP.solve(model);

Inherited from

ModelNode.setName