pwlFunction
OPL keyword to create a piecewise linear function
Purpose
OPL keyword to create a piecewise linear function.
context |
---|
Model files (.mod) |
Syntax
pwlFunction F = piecewise(i in 1..n){ S[i]->T[i]; S[n+1] } (t0, v0); pwlFunction F = piecewise{ V[1]->T[1], ..., V[n]->T[n], V[n+1] }; pwlFunction F[i in ...] = piecewise (...)[ ... ];
Description
Piecewise linear functions are typically used to model a known function of time, for instance the cost incurred for completing an activity after a known date.
Note that you must ensure that the array of values T[i] is sorted.
The meanings of the S, T, and V vectors are described in Piecewise linear and stepwise functions in the Language Reference Manual.
Example
int n=2;
float objectiveforxequals0=300;
float breakpoint[1..n]=[100,200];
float slope[1..n+1]=[1,2,-3];
dvar int x;
pwlFunction obj=piecewise(i in 1..n)
{slope[i] -> breakpoint[i]; slope[n+1]}(0,objectiveforxequals0);
maximize obj(x);
subject to
{
true;
}