Suppose we have the following piecewise linear function $f(x)$:

$3x + 8, x\in [0,5]$

$33 - 2x, x\in [5,10]$

$3 + x, x\in [10,20]$

How to model the relations between $f(x)$ and $x$ using integer variables and linear constraints. How to specify the values of M if we model it using big-M method.

  • 1
    $\begingroup$ As a somewhat tangential comment (for posterity), some MIP solvers include the ability to specify a piecewise-linear function directly (without requiring the user to introduce binary variables and large constants). $\endgroup$
    – prubin
    Mar 18, 2021 at 15:56

1 Answer 1


Introduce a binary variable $z_i$ for each segment and impose the following linear constraints: \begin{align} z_1 + z_2 + z_3 &= 1 \\ 0z_1 + 5z_2 + 10z_3 \le x &\le 5z_1 + 10z_2 + 20z_3 \\ L_1(1-z_1) \le y - (3x+8) &\le U_1(1-z_1) \\ L_2(1-z_2) \le y - (33-2x) &\le U_2(1-z_2) \\ L_3(1-z_3) \le y - (3+x) &\le U_3(1-z_3) \end{align} I'll leave the computations of the big-M values $L_i$ and $U_i$ to you.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .