Modeling Logical Constraints with Binaries (AND, OR, NOT)

Translate logical conditions on yes/no decisions — AND, OR, NOT, implications, and compound rules — into linear constraints on binary variables.

Step 1 of 157%

Tutorial

Logical Conditions as Linear Constraints

Recall that a binary variable x{0,1}x \in \{0,1\} encodes a yes/no decision. Once decisions are represented this way, we can translate logical conditions into linear constraints.

Let x1,x2,,xn{0,1}x_1, x_2, \ldots, x_n \in \{0,1\}.

  • AND (both selected): xi=1x_i = 1 and xj=1x_j = 1 becomes
xi+xj=2.x_i + x_j = 2.
  • OR (at least one selected): xi=1x_i = 1 or xj=1x_j = 1 becomes
xi+xj1.x_i + x_j \geq 1.
  • NOT (xix_i is not selected):
xi=0.x_i = 0.

More generally,

  • 'at least kk of x1,,xnx_1, \ldots, x_n are selected': i=1nxik,\sum\limits_{i=1}^n x_i \geq k,
  • 'at most kk are selected': i=1nxik,\sum\limits_{i=1}^n x_i \leq k,
  • 'exactly kk are selected': i=1nxi=k,\sum\limits_{i=1}^n x_i = k,
  • 'xix_i and xjx_j cannot both be selected': xi+xj1.x_i + x_j \leq 1.

For instance, a factory must run at least two of three machines A,B,CA, B, C. With binaries xA,xB,xC,x_A, x_B, x_C, the rule becomes

xA+xB+xC2.x_A + x_B + x_C \geq 2.
navigate · Enter open · Esc close · ⌘K/Ctrl K toggle