0
$\begingroup$

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

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

I have figured out the answer to this. The constraints:

  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

can also be formulated as:

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

Hence the constraints can be written as such:

  1. $y_1$<=$M(1-x_1)$
  2. $y_1+y_2$<=$M(1-x_2)$
  3. $y_1+y_2+y_3$<=$M(1-x_3)$

Where $M$ is a very large integer.

$\endgroup$
  • $\begingroup$ That looks correct. You can choose $M=1$ for constraint 1., $M=2$ for constraint 2. and $M=3$ for constraint 3. $\endgroup$ – Kuifje Nov 22 '15 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.