# Modeling the sum of binary variables

Suppose $$x_{1},x_{2}, \cdots ,x_{n}$$ are binaries.

I would like to model the following:

IF $$x_{1} + x_{2}+ \cdots +x_{n} \ge 2$$ THEN $$x_{1} + x_{2} = 2$$

IF $$x_{1} + x_{2}+ \cdots +x_{n} \ge 3$$ THEN $$x_{1} + x_{2} + x_{3}= 3$$

and so on.

Is there a better way than asking for the following

$$(x_{1} \ge 1) \lor (x_{1} + x_{2} \ge 2) \lor (x_{1} + x_{2} + x_{3} \ge 3) \cdots$$, which then requires the introduction of additional binaries?

• I think you need another clause in the disjunction: $\sum_{i=1}^n x_i = 0$. Otherwise, $x_1=1$ is forced. – RobPratt May 12 '20 at 20:35
• Yes, you are right! – Clement May 12 '20 at 21:01

## 1 Answer

Does $$x_i \ge x_{i+1}$$ do what you want?

• That's genius... – Oguz Toragay May 12 '20 at 19:58
• Thank you Rob. This is what I already have implemented. I hoped, that is the purpose of the question, I can do something without having to wait for the end of the optimisation run. I mean, if I have the constraint x1 + x2 + x3 => 2 then in a relaxation it can be satisfied as (x1,x2,x3) = (0.8,0.7,0.5), which satisfies the requirement x(i) => x(i+1) but not x1+x2=2. – Clement May 12 '20 at 20:18
• Looks like the simple formulation already yields the integer hull, so you will not get anything stronger unless you consider the other constraints in your model. – RobPratt May 12 '20 at 20:32
• Then I can stop looking for something better. Thank you again Rob. – Clement May 12 '20 at 21:00