Documentation


GRBsetpwlobj

int GRBsetpwlobj ( GRBmodel *model,
    int var,
    int npoints,
    double *x,
    double *y )

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, the <span>$</span>x<span>$</span> and <span>$</span>y<span>$</span> arguments give coordinates for the vertices of the function.

For additional details on piecewise-linear objective functions, refer to this discussion.

Note that, due to our lazy update approach, the new piecewise-linear objective won't actually be added until you update the model (using GRBupdatemodel), optimize the model (using GRBoptimize), or write the model to disk (using GRBwrite).

Return value:

A non-zero return value indicates that a problem occurred while setting the piecewise-linear objective. Refer to the Error Code table for a list of possible return values. Details on the error can be obtained by calling GRBgeterrormsg.

Arguments:

model: The model to modify.

var: The variable whose objective function is being changed.

npoints: The number of points that define the piecewise-linear function.

x: The <span>$</span>x<span>$</span> values for the points that define the piecewise-linear function. Must be in non-decreasing order.

y: The <span>$</span>y<span>$</span> values for the points that define the piecewise-linear function.

Example usage:

  double x[] = {1, 3, 5};
  double y[] = {1, 2, 4};
  error = GRBsetpwlobj(model, var, 3, x, y);