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:
- Function Model.stepFunctionEval evaluates the function at the given point (given as IntExpr).
- Function Model.stepFunctionSum 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
Methods
getName()
getName():
undefined
|string
Returns the name assigned to the node.
Returns
undefined
| string
Inherited from
setName()
setName(
name
:string
):this
Assigns a name to the node.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | Named 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
stepFunctionEval()
Evaluates the step function at a given point.
Parameters
Parameter | Type |
---|---|
arg | number | IntExpr |
Returns
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.stepFunctionEval for the equivalent function on Model.
- Model.forbidStart, Model.forbidEnd are convenience functions built on top of
stepFunctionEval
.
stepFunctionSum()
stepFunctionSum(
interval
:IntervalVar
):IntExpr
Computes sum of values of the step function over the interval interval
.
Parameters
Parameter | Type |
---|---|
interval | IntervalVar |
Returns
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.