[Math] Integer Programming Conditional Constraints

integer programminglinear programming

I have a set of integer [0,1]variables
$x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4$

I want a conditional constraint such that if any of the $x$ variables is equal to 1, I want the sum of the subsequent $y$ variables to be 2.

For example

  1. if $x_1$==1 then $y_2+y_3+y_4$=2,
  2. if $x_2$==1 then $y_3+y_4$=2
  3. if $x_3$==1 then $y_4$==2

The objective function is just the sum of all the variables. There are additional constraints such as:
$x_1+x_2+x_3+x_4=2$ and $y_1+y_2+y_3+y_4=2$

The solution here would be:
1 0 1 0 0 1 0 1

Best Answer

Such constraints are called disjunctive constraints. You can proceed as follows (for your constraint 1.):

$$ y_2+y_3+y_4\le2+(1-x_1)\quad y_2+y_3+y_4\ge2-2(1-x_1), $$

This way, if $x_1=1$, you have

$$ y_2+y_3+y_4\le2 \quad y_2+y_3+y_4\ge2, $$

which is equivalent to $y_2+y_3+y_4=2$. And if $x_1=0$, you have

$$ y_2+y_3+y_4\le2+1=3\quad y_2+y_3+y_4\ge2-2=0, $$

which will always be satisfied since variables are boolean.