Model.addGenConstrPWL()

addGenConstrPWL ( xvar, yvar, xpts, ypts, name="" )

Add a new general constraint of type GRB.GENCONSTR_PWL to a model.

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

Arguments:

xvar (Var): The $x$ variable.

yvar (Var): The $y$ variable.

xpts (list of float): The $x$ values for the points that define the piecewise-linear function. Must be in non-decreasing order.

ypts (list of float): The $y$ values for the points that define the piecewise-linear function.

name (string, optional): Name for the new general constraint.

Return value:

New general constraint.

Example usage:

  gc = model.addGenConstrPWL(x, y, [0, 1, 2], [1.5, 0, 3], "myPWLConstr")