stepFunction

OPL keyword to create a stepwise linear function

Purpose

OPL keyword to create a stepwise linear function.

context
Model files (.mod)

Syntax

stepFunction F = stepwise(i in 1..n){ V[i]->T[i]; V[n+1] };

stepFunction F = stepwise{ V[1]->T[1], ..., V[n]->T[n], V[n+1] };

stepFunction F[i in ...] = stepwise (...)[ ... ];

Description

Stepwise linear functions are typically used to model the efficiency of a resource over time. A stepwise function is a special case of piecewise linear function where all slopes are equal to 0 and the domain and image of F are integer.

Note that you must ensure that the array of values T[i] is sorted.

Example

stepFunction f=stepwise {0->3; 2};

assert f(-1)==0;
assert f(3)==2;
assert f(3.1)==2;