# 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$. – Mostafa May 13 '20 at 13:25
• Applied your comment and added my try. @Mostafa – SAH May 13 '20 at 14:32
• You still have some overlapping cases. Maybe restrict 4 to have $c>0$? – RobPratt May 13 '20 at 15:14
• I restated the conditions and I think they have no overlap now. @RobPratt – SAH May 13 '20 at 15:32
• Yes, but you could simplify by merging 1 and 3 to $c\ge 0$. – RobPratt May 13 '20 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)$$.

• Thank you. But there is a problem. This set of constrains doesn't let c to be zero in any case. This is due to the left hand side of the last constraint d-c+w >= 0. let say c= 0 and w = -1. We expect to get d=0 (second condition). However d-0-1>= 0 is only satisfied by d=1 or larger (however d=1 is optimal). Therefore the value of x is equal to 1 due to the constraint 2. As a result x is always 1 and do not let c to be zero. In the optimal case c will be set to epsilon and not zero. @RobPratt – SAH May 13 '20 at 19:14
• Yes, that constraint should have been active only when $x=y=1$. Corrected now. – RobPratt May 13 '20 at 19:51
• Thank you. Would you introduce some references to learn this technique. – SAH May 13 '20 at 21:29
• H. Paul Williams, Model Building in Mathematical Programming. Also, Raman and Grossmann, Relation between MILP modelling and logical inference for chemical process synthesis – RobPratt May 13 '20 at 21:41