# Mixed Integer Linear Programming Conditional Constraints

I have a set of variables: $x_1,x_2,x_3,x_4$

$x_1$ is a binary integer variable while the rest are real numbers all between $0$ and $1$.

I want a constraint such that:

if $x_2+x_3+x_4>0$ then $x_1=1$,

and

if $x_2+x_3+x_4=0$ then $x_1=0$.

You can write $$x_1=-\left\lfloor -{x_2+x_3+x_4\over 3}\right\rfloor$$which is equivalent to the following linear constraints:$$-x_1\le -{x_2+x_3+x_4\over 3}<-x_1+1$$or equivalently$$-3x_1+x_2+x_3+x_4\le 0\\-3x_1+x_2+x_3+x_4>-3$$

This looks like a fixed cost problem, and it is easy to model if you have an objective function such as $$Min \quad x_1$$ If so, all you have to do is add the following constraint: $$x_2+x_3+x_4\le x_1 \\ x_1 \in \{0,1\}$$

Indeed, if $x_2+x_3+x_4>0$, then necessarily you will have $x_1=1$. Otherwise, the objective function will "pull down" $x_1$ to $0$.

• What about my answer? Also, what's up with the last line? I think your constraint applies only to the first statement ($x_2+x_3+x_4 > 0 \to x_1=1$)?
– BCLC
May 11, 2016 at 17:45

You can think about it logically:

If $x_2 + x_3 + x_4 > 0$, then $x_1 = 1$

$\iff$

$x_2 + x_3 + x_4 = 0$ if $x_1 = 0$

$\iff$

$x_2 + x_3 + x_4 = 0$ or $x_1 = 1$

$\iff$

$x_2 = x_3 = x_4 = 0$ or $x_1 = 1$

$\iff$

$x_2 = x_3 = x_4 = 0$ or $x_1 = 1$

$\iff$

$[x_2 = 0 \ and \ x_3 = 0 \ and \ x_4 = 0]$ or $x_1 = 1$

$\iff$

$x_2 = 0 \ or \ x_1 = 1$

and

$x_3 = 0 \ or \ x_1 = 1$

and

$x_4 = 0 \ or \ x_1 = 1$

$\iff$

$1-x_2 = 1 \ or \ x_1 = 1$

and

$1-x_3 = 1 \ or \ x_1 = 1$

and

$1-x_4 = 1 \ or \ x_1 = 1$

$\iff$

$1-x_2 + x_1 \ge 1$

and

$1-x_3 + x_1 \ge 1$

and

$1-x_4 + x_1 \ge 1$

$$x_2+x_3+x_4 \le M(x_1)$$

What Kuifje said.

If $x_2 + x_3 + x_4 = 0$, then $x_1 = 0$

$\iff$

$x_2 + x_3 + x_4 > 0$ if $x_1 = 1$

$\iff$

$x_2 > 0 \ or \ x_3 > 0 \ or \ x_4 > 0$ if $x_1 = 1$

$\iff$

$x_2 > 0 \ or \ x_3 > 0 \ or \ x_4 > 0 \ or \ 1 - x_1 = 1$

$\iff$

$x_2 > 0 \ or \ x_3 > 0 \ or \ x_4 > 0 \ or \ 1 - x_1 > 0$

$\iff$

$x_2 + x_3 + x_4 + 1 - x_1 > 0$

$\iff$

$x_2 + x_3 + x_4 > x_1 - 1$

$$-(x_2+x_3+x_4) < M(1-x_1)$$

Don't forget

$$x_1 \in \{0,1\}$$

$$1 \ge x_2, x_3, x_4 \ge 0$$

According to you $x_1$ is a binary decision variable. So the constraints will look like this

[ $x_1$= \begin{cases} 1,& \text{if } x_2+x_3+x_4>0\\ 0, & \text{if } x_2+x_3+x_4 =0 \end{cases} ]

I think this constraint suitable for MILP.

Here is my suggestion. Let $$0 be a constant \begin{align} x_2+x_3+x_4 \leq 3 x_1\\ x_2+x_3+x_4 \geq a x_1 \end{align}

This will work because:

• if $$x_2+x_3+x_4=0$$ then $$a x_1 \leq 0$$. For $$x_1 =1$$, we have $$a<0$$ (contradiction due to $$0), thus $$x_1 =0$$.

• if $$x_2+x_3+x_4 \geq 1$$ then $$x_2 + x_3 + x_4\leq 3 x_1$$. For $$x_1 =0$$, $$x_2 +x_3 + x_4 \leq 0$$, (contradiction due to $$x_2+x_3+x_4 \geq 1$$), thus $$x_1=1$$

• What about my answer? Also, your answer seems to exclude certain possibilities like $x_2 = x_3 = x_4 = 0.0000000001$?
– BCLC
May 11, 2016 at 17:48
• which part is wrong?
– BCLC
May 12, 2016 at 13:45
• you've gotta be kidding me. Contrapositive? I triple checked
– BCLC
May 12, 2016 at 15:00