How to create conditional constraint for two binary variables?

146 Views Asked by At

I need to include the following conditional constraint in my MIP formulation. I have the following situation in a Mixed Integer Program: A1,…,An and B are binary variables. If two or more variables $A_i$ are set to $1$, then I need to have $B=1$.

That is: $$\sum_{i=1}^n A_i \geq2 \Longrightarrow B=1$$

Do I need to introduce a new variable here? Thanks in Advance!

1

There are 1 best solutions below

0
On BEST ANSWER

You can do it with one "big-M" constraint as follows: $$\sum_{i=1}^n A_i - 1 \le (n-1)B.$$

Alternatively, you can obtain $\binom{n}{2}$ linear constraints via conjunctive normal form: \begin{equation} \bigvee_{i<j} \left(A_i \land A_j\right) \implies B \\ \neg\bigvee_{i<j} (A_i \land A_j) \lor B \\ \bigwedge_{i<j} \neg(A_i \land A_j) \lor B \\ \bigwedge_{i<j} (\neg A_i \lor \neg A_j) \lor B \\ \bigwedge_{i<j} (\neg A_i \lor \neg A_j \lor B) \\ 1- A_i + 1- A_j + B \ge 1 \text{ for all $i<j$} \\ A_i + A_j - 1 \le B \text{ for all $i<j$} \end{equation}