# If-Then-Else modeling in MILP using the Big M method

I have trouble finding a solution to the following problem. I have a decision variable $$x$$. If the value of $$x$$ is between 0 and a constant $$A$$, then the binary variable $$y_1$$ must be equal to 1. If $$x$$ is greater than $$A$$ but lower than another constant $$B$$, then the binary variable $$y_2$$ must be equal to 1 while the $$y_1$$ must be equal to 0. If $$x$$ goes above $$B$$, the binary variable $$y_3$$ must be equal to 1 while $$y_1$$ and $$y_2$$ must be equal to 0.

I tried using the Big $$M$$ method as follows:

$$x \le Ay_1 \tag{1}$$

The problem here is that if $$x$$ goes above $$A$$ then $$x$$ is infeasible. Then I created three new decision variables $$x_1$$, $$x_2$$, and $$x_3$$ that could "follow" $$x$$ for a certain amount:

$$x = (x_1 y_1)+(x_2 y_2)+(x_3 y_3) \tag{2}$$

$$x_1 \le A y_1 \tag{1}$$

$$x_2 \ge A y_2 \tag{3}$$

$$x_2 \le B y_2 \tag{4}$$

$$x_3 \ge B y_3 \tag{5}$$

This does not work: the solver tells me it is infeasible. I'm using OpenSolver in Excel. How can I resolve this?

There is some ambiguity about the strictness of above/beneath, but does the following do what you want? $$0y_1 + Ay_2 + By_3 \le x \le Ay_1 + By_2 + Cy_3 \\ y_1 + y_2 + y_3 = 1$$ Checking, we have: \begin{align} y_1 = 1 &\implies x \in [0,A] \\ y_2 = 1 &\implies x \in [A,B] \\ y_3 = 1 &\implies x \in [B,C] \\ \end{align}