Class: IntStepFunction
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:
- Function Model.eval evaluates the function at the given point (given as IntExpr).
- Function Model.integral computes a sum (integral) of the function over an IntervalVar.
- Constraints Model.forbidStart and Model.forbidEnd forbid the start/end of an IntervalVar to be in a zero-value interval of the function.
- Constraint Model.forbidExtent forbids the extent of an IntervalVar to be in a zero-value interval of the function.
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 IntStepFunction()
new IntStepFunction():
IntStepFunction
Returns
Inherited from
Methods
eval()
Evaluates the step function at a given point.
Parameters
| Parameter | Type | Description |
|---|---|---|
arg | number | IntExpr | The point at which to evaluate the step function. |
Returns
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
- Model.eval for the equivalent function on Model.
- Model.forbidStart, Model.forbidEnd are convenience functions built on top of
eval.
integral()
integral(
interval:IntervalVar):IntExpr
Computes sum of values of the step function over the interval interval.
Parameters
| Parameter | Type | Description |
|---|---|---|
interval | IntervalVar | The interval variable. |
Returns
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.
Properties
| Property | Modifier | Type |
|---|---|---|
__brand | readonly | "IntStepFunction" |