Documentation


GRBaddgenconstrPWL

int GRBaddgenconstrPWL ( GRBmodel *model,
    const char *name,
    int xvar,
    int yvar,
    int npts,
    double *xpts,
    double *ypts )

Add a new general constraint of type GRB_GENCONSTR_PWL to a model. Note that, due to our lazy update approach, the new constraint 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).

A piecewise-linear (PWL) constraint states that the relationship <span>$</span>y =
f(x)<span>$</span> must hold between variables <span>$</span>x<span>$</span> and <span>$</span>y<span>$</span>, where <span>$</span>f<span>$</span> is a piecewise-linear function. The breakpoints for <span>$</span>f<span>$</span> are provided as arguments. Refer to the description of piecewise-linear objectives for details of how piecewise-linear functions are defined.

Return value:

A non-zero return value indicates that a problem occurred while adding the general constraint. 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 which the new general constraint should be added.

name: Name for the new general constraint. This argument can be NULL, in which case the constraint is given a default name.

xvar: The index of variable <span>$</span>x<span>$</span>.

yvar: The index of variable <span>$</span>y<span>$</span>.

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

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

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

Example usage:

  double xpts[] = {1, 3, 5};
  double ypts[] = {1, 2, 4};
  error = GRBaddgenconstr(model, "pwl", xvar, yvar, 3, x, y);