stepFunction

Creates a new step function (a function that remains constant within each of a series of adjacent intervals but changes in value from one interval to the next).

Syntax

Parameters

Comma separated list of pairs (start, value) sorted by start. Each pair corresponds with an interval where the function is constant (a step of the function). The function has constant value value from start until the next step. Parameter start is sint (allowed range intervalmin..intervalmax), parameter value is uint (allowed range 0..intmax).

To simplify code generation, a trailing comma at the end of non-empty list is allowed.

Description

The function stepFunction creates a new function with the specified steps. Each step starts at the specified start time and ends just before the start of the next step.

The function is always defined on interval intervalmin..intervalmax. If the first step does not start at intervalmin then the function is 0 from intervalmin until the start of the first step. The last step ends at intervalmax, that is, the function is defined for intervalmax.

Use stepFunction to express intensity of a work during intervalVar, or to forbid intervalVar to start/stop or extent certain intervals using constraints forbidStart, forbidEnd and forbidExtent.

Example

The following two functions are equivalent because the function is always zero from intervalmin until the first step:


function = stepFunction((intervalmin, 0), (3, 100), (10, 60), (15, 80));
g = stepFunction(                  (3, 100), (10, 60), (15, 80));

Here is a graph of the both functions:

Example

The following function represents working days during three weeks. Its value is 0 during weekends and 100 during working days.


workingDays = stepFunction((0, 100), (5, 0), (7, 100), (12, 0), (14, 100), (19, 0));

Here is graphical representation of the function:

Such function can be used as intensity to express that a task takes (for example) 5 days however weekends do not count:


d = intervalVar(size=5, end=0..21, intensity=workingDays);

Possible solution then can be that the work starts on Thursday and ends on Wednesday next week:

However another possible solution is that the work starts (suspended) on Sunday and ends on next Sunday (again suspended):

Such a solution is usually not desired. In this case it is also necessary to forbid the interval to start or end during a weekend using constraints forbidStart and forbidEnd:


forbidStart(d, workingDays);
forbidEnd(d, workingDays);

Requirements

  • The segments must be sorted in ascending order by start.
  • Two segments with the same start value are not allowed.

Notes

  • When no step is specified then the function has value 0 over the whole range intervalmin..intervalmax.
  • If the function is used as an intensity of an interval variable then its value must be within range 0..granularity (granularity is 100 by default).
  • There is no expression to actually evaluate the step function. The step function is meant to be passed as an argument to constraints forbidStart, forbidEnd, forbidExtent or as an intensity argument to function {intervalVar}.