Stepwise functions

Describes stepwise functions (stepFunction) in OPL.

Shows how to declare stepwise functions in the OPL language.

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.

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 (...)[ ... ];

Example

A declaration of the form


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

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

declares a stepwise function, f.

Example

Another example, declaring the stepwise function F2:


stepFunction F2 = stepwise{ 0->0; 100->20; 60->30; 100 }; 
int ii= F2( 10 ); 

execute { 
        writeln( ii ); 
        writeln( F2( 25 ) ); 
} 

Stepwise functions are covered in detail in Piecewise linear and stepwise functions.