# How to fomulate the following conditional constraint in MILP?

How can I formulate the following conditional constraint to a linear constraint using indicator variables? Please note that all variables are continuous and $$c \ge 0$$

$$\text{1: if} \ c=0 \ \& \ w \geq 0 \quad \text{then} \; u=w; d=0\\ \text{2: if} \ c=0 \ \& \ w < 0 \quad \text{then} \; u=0; d=0\\ \text{3: if} \ c > 0 \ \& \ w \geq c \quad \text{then} \ u=w-c; d=0 \\ \text{4: if} \ c>0 \ \& \ w

The decision variables d and u are directly appeared with a negative and positive coefficients in the objective function. Also, the abs of coefficient d is greater than the coefficient of u $$(e.g. -40 d + 30 u)$$. Therefore, the following constraint satisfies conditions 1,3 and 4.

$$c-w - d + u = 0;\\ c, d, u \geq 0;\\$$

Nevertheless, I am still wonder how to include condition 2 as a linear constraint in my model.

• I think first you should modify the conditions a little bit, e.g., $c=0, w=0$ is common in conditions 1 and 2. Also for conditions 3 and 4 when $c>0, w=0$. Commented May 13, 2020 at 13:25
– SAH
Commented May 13, 2020 at 14:32
• You still have some overlapping cases. Maybe restrict 4 to have $c>0$? Commented May 13, 2020 at 15:14
• I restated the conditions and I think they have no overlap now. @RobPratt
– SAH
Commented May 13, 2020 at 15:32
• Yes, but you could simplify by merging 1 and 3 to $c\ge 0$. Commented May 13, 2020 at 15:35

Here's a big-M formulation that does not depend on the objective. (Minimization with positive objective coefficients for $$u$$ and $$d$$ could be exploited, but you don't have that here.) Let $$\epsilon > 0$$ be a small tolerance for positivity of $$c$$. Let $$\underline{c}$$ and $$\overline{c}$$ be bounds for $$c$$, with similar notation for $$w$$, $$u$$, and $$d$$. Let binary decision variable $$x$$ indicate whether $$c>0$$, and let binary decision variable $$y$$ indicate whether $$c>w$$. The constraints are: \begin{align} \epsilon x \le c &\le \overline{c} x \\ 0 \le d &\le \overline{d} x \\ c-w &\le (\overline{c}-\underline{w}) y \\ 0 \le u - (w-c) &\le (0-\underline{w}+\overline{c})y \\ 0 \le d &\le \overline{d} y \\ w-c &\le (\overline{w}-\underline{c})(1-y) \\ 0 \le u &\le \overline{u} (1-y) \\ (0-\overline{c}+\underline{w})(2-x-y) \le d - (c-w) &\le (0-\underline{c}+\overline{w})(2-x-y) \end{align} Just check the four cases for $$(x,y)$$.
• Yes, that constraint should have been active only when $x=y=1$. Corrected now. Commented May 13, 2020 at 19:51