Gurobi versions 9.0 and later include an interface for piecewise-linear constraints. See the General Constraints section of the reference manual for more information. An interface for piecewise-linear objective functions has been included in Gurobi since version 6.0.

Gurobi versions 8.1 and earlier do not include a dedicated interface for piecewise-linear constraints. However, these can be modeled using special ordered sets of type 2 (SOS2). For example, to add the constraint \( y = f(x) \) where \( f \) is the piecewise-linear function defined by the points \( (x_1, y_1), \ldots, (x_n, y_n), \) add the variables \( \lambda_i\ (i = 1, \ldots, n) \) to the problem, then add the following constraints:

$$\begin{alignat}{2} \sum_{i = 1}^n \lambda_i x_i &= x && \\ \sum_{i = 1}^n \lambda_i y_i &= y && \\ \sum_{i = 1}^n \lambda_i &= 1 && \\ \lambda_i &\geq 0 && i = 1, \ldots, n \\ \lambda_i &\in \textrm{SOS2} \quad && i = 1, \ldots, n. \end{alignat}$$

### Further information