Skip to main content

Class: IntStepFunction

Piecewise-constant function mapping time to integers, used for costs and availability windows.

Remarks​

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

Step functions can be used in the following ways:

Extends​

Accessors​

name​

Get Signature​

get name(): string | undefined

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​

string | undefined

Set Signature​

set name(value: string): void

Parameters​
ParameterType
valuestring
Returns​

void

Inherited from​

ModelElement.name

Constructors​

Constructor​

new IntStepFunction(): IntStepFunction

Returns​

IntStepFunction

Inherited from​

ModelElement.constructor

Methods​

eval()​

eval(arg: number | IntExpr): IntExpr

Evaluates the step function at a given point.

Parameters​

ParameterTypeDescription
argnumber | IntExprThe point at which to evaluate the step function.

Returns​

IntExpr

The resulting integer expression

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​


integral()​

integral(interval: IntervalVar): IntExpr

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

Parameters​

ParameterTypeDescription
intervalIntervalVarThe interval variable.

Returns​

IntExpr

The resulting integer expression

Remarks​

The sum is computed over all integer time points from interval.start() to interval.end()-1 inclusive. In other words, the sum includes the function value at the start time but excludes the value at the end time (half-open interval). 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.integral for the equivalent function on Model.