Apologies if this question has been asked, but I haven't been able to find it. I'm modelling something with Gurobi and want to do the following:

\begin{align}\text{cond} < \dfrac{1}{3} &\iff x = 1,\\\dfrac{1}{3} \leq \text{cond} \leq \dfrac{2}{3} &\iff y = 1,\\\dfrac{2}{3} <\text{cond}\leq 1 &\iff z = 1\end{align} $$ (x,y,z) \in \{0,1\}^{3}, 0\leq \text{cond}\leq 1$$

So, three indicator variables depending on $\text{cond}$. I managed to model the left implications (e.g. $\text{cond}\leq \dfrac{1}{3} + 2(1-x)$), but I'm having a bit of trouble with the right side and making sure it all ties together.

  • $\begingroup$ It is substantially more complicated than what I was thinking, but I found a paper "Nonconvex piecewise linear functions: Advanced formulations and simple modeling tools" that also answers this question. $\endgroup$ Commented Jun 23, 2021 at 11:07

1 Answer 1


Without using a small epsilon, you can’t enforce strict inequality. Here’s one approach that allows ambiguity at the endpoints of each interval, as your proposed constraint does: $$ x+y+z=1\\ 0x+\frac{1}{3}y+\frac{2}{3}z \le \text{cond} \le \frac{1}{3}x+\frac{2}{3}y+1z $$

  • 1
    $\begingroup$ Thank you very much! I tried quite a bit and got nowhere, do you mind telling me how you reached this solution? How does one generally approach this? $\endgroup$ Commented Jun 22, 2021 at 13:01
  • 2
    $\begingroup$ Glad to help. Not sure where I first learned this approach, but I suggested it here for a very similar situation. I also recommend watching the linearization and modeling tags, for which some posts link to additional resources. $\endgroup$
    – RobPratt
    Commented Jun 22, 2021 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.