GRBModel.SetPWLObj()
GRBModel.SetPWLObj()
Set a piecewise-linear objective function for a variable.
The arguments to this method specify a list of points that define a piecewise-linear objective function for a single variable. Specifically, theandarguments give coordinates for the vertices of the function.
For example, suppose we want to define the functionshown below:
More formally, a set ofpoints
define the following piecewise-linear function:
Theentries must appear in non-decreasing order. Two points can have the samecoordinate -- this can be useful for specifying a discrete jump in the objective function.
Note that a piecewise-linear objective can change the type of a model. Specifically, including a non-convex piecewise linear objective function in a continuous model will transform that model into a MIP. This can significantly increase the cost of solving the model.
Setting a piecewise-linear objective for a variable will set theObj attributeon that variable to 0. Similarly, setting theObj
attribute will delete the piecewise-linear objective on that variable.
Each variable can have its own piecewise-linear objective function. They must be specified individually, even if multiple variables share the same function.
void | SetPWLObj( | GRBvar | var, |
double[] | x, | ||
double[] | y ) |
-
Set the piecewise-linear objective function for a variable.
Arguments:
var: The variable whose objective function is being set.
x: Thevalues for the points that define the piecewise-linear function. Must be in non-decreasing order.
y: Thevalues for the points that define the piecewise-linear function.