# Model "if and only if" indicator constraints in Linear programming

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.

• 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. Jun 23 at 11:07

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