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. It is defined by an array of points [[x0,y0],[x1,y1],,[xn,yn]][[x_0, y_0], [x_1, y_1],\dots , [x_n, y_n]] where xix_i and yiy_i are integer values. The array must be sorted by xix_i in ascending order and values xix_i must be unique. The function is defined as follows:

  • f(x)=0f(x) = 0 for x<x0x < x_0,
  • f(x)=yif(x) = y_i for xix<xi+1x_i \leq x < x_{i+1}
  • f(x)=ynf(x) = y_n for xxnx \geq x_n.

Step functions can be used the following ways:

Hierarchy

Constructors

constructor

new IntStepFunction(cp, values)

Parameters

NameType
cpModel
valuesnumber[][]

Overrides

ModelNode.constructor

Methods

getName

getName(): undefined | string

Returns the name assigned to the node.

Returns

undefined | string

Inherited from

ModelNode.getName


setName

setName(name): IntStepFunction

Assigns a name to the node.

Parameters

NameTypeDescription
namestringNamed to be assigned.

Returns

IntStepFunction

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): IntExpr

Evaluates the step function at a given point.

Parameters

NameType
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 forbidStart and forbidEnd work that way.

See


stepFunctionSum

stepFunctionSum(interval): IntExpr

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

Parameters

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