5

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.

RobPratt
  • 32,006
  • 1
  • 44
  • 84
J. Dionisio
  • 534
  • 2
  • 14
  • 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. – J. Dionisio Jun 23 '21 at 11:07

1 Answers1

7

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 $$

RobPratt
  • 32,006
  • 1
  • 44
  • 84
  • 1
    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? – J. Dionisio Jun 22 '21 at 13:01
  • 2
    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. – RobPratt Jun 22 '21 at 14:42