There are four variables: $x_1, x_2, x_3, x_4$.

If you choose either $x_3$ or $x_4$ or both — then you should choose exactly one of $x_1$ or $x_2$.

If you choose neither $x_3$ or $x_4$ — then there is no restriction in choosing $x_1$ or $x_2$.

I have come up with the following if else logic for this, but cannot proceed from there.

If $x_3+x_4 = 0$ then $x_1 + x_2 \ge 0$

If $x_3 + x_4 \ge 1$ then $x_1 + x_2 = 1$

Can you let me know how to come up with an integer linear program with this understanding?


1 Answer 1


Every logical formula can be converted to conjunctive normal form (CNF), that is, into a conjunction (AND) of clauses (OR). In turn, a clause $\ell_1 \lor \cdots \lor \ell_m$ can be expressed as the constraint $\ell_1 + \cdots + \ell_m \geq 1$. In this way, you can express any logical condition in an integer program.

As an example, consider the logical formula $x \oplus y$, that is, exactly one of $x,y$ is true. While it can be expressed directly as $x + y = 1$, let's see how to do it using CNF. Putting it into CNF, we get $(x \lor y) \land (\lnot x \lor \lnot y)$. Therefore we add the following constraints: $x + y \geq 1$ and $(1-x) + (1-y) \geq 1$, i.e., $-x-y \geq -1$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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