Skip to main content

Class: IntStepFunction

Integer step function.

Integer step function is a piecewise constant function defined on integer values in range IntVarMin to IntVarMax. The function can be created by Model.intStepFunction.

Step functions can be used following ways:

Extends

Methods

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


stepFunctionEval()

stepFunctionEval(arg: number | IntExpr): IntExpr

Evaluates the step function at a given point.

Parameters

ParameterType
argnumber | IntExpr

Returns

IntExpr

Remarks

The result is the value of the step function at the point arg. If the value of arg is absent then the result is also absent.

By constraining the returned value, it is possible to limit arg to be only within certain segments of the segmented function. In particular, functions Model.forbidStart and Model.forbidEnd work that way.

See


stepFunctionSum()

stepFunctionSum(interval: IntervalVar): IntExpr

Computes sum of values of the step function over the interval interval.

Parameters

ParameterType
intervalIntervalVar

Returns

IntExpr

Remarks

The sum is computed over all points in range interval.start() .. interval.end()-1. That is, the sum includes the function value at the start time, but not the value at the end time. If the interval variable has zero length then the result is 0. If the interval variable is absent then the result is absent.

Requirement: The step function func must be non-negative.

See

Model.stepFunctionSum for the equivalent function on Model.