# Converting if else condition to MIP constraints - validation

I have an if else condition as follows: If $$g \ge 0$$ then $$e=1$$, else $$e=b$$.

I formulated MIP constraints using big-M as follows where I am setting $$\delta=1$$ if $$g \ge 0$$:

\begin{alignat}2g &\ge -M(1-\delta)\tag1\\g &\le M\delta\tag2\\1-M(1-\delta) &\le e \le 1+M(1-\delta)\tag3\\b-M\delta &\le e \le b+M\delta\tag4\end{alignat}

My question is if the formulation is correct, especially the first equation.

Looks correct, but there is the usual ambiguity at the boundary: $$g=0$$ allows either $$e$$ value. Also, if $$b$$ is a constant, you can simplify by replacing (3) and (4) with a single equality: $$e=1\delta+b(1-\delta)$$ Note that the best values of $$M$$ in (3) and (4) yield this equality. Explicitly: \begin{align} 1-(1-b)(1-\delta) &\le e \le 1+(b-1)(1-\delta) \tag3\\ b-(b-1)\delta &\le e \le b+(1-b)\delta &&\tag4 \end{align}
• If $g$ and $b$ are constants, you do not need to introduce $\delta$, impose big-M constraints, or call any solver. The value of $e$ is already completely determined once you know $g$ and $b$. Mar 17 '20 at 22:24