Modeling At-Most-K and Exactly-K Constraints
How to use sums of binary variables to enforce that at most K, at least K, or exactly K items in a set are selected, and how to combine these cardinality constraints on subsets of variables.
Step 1 of 157%
Tutorial
At-Most-K Constraints
Suppose we have binary decision variables , where means item is selected and means it is not.
The at-most-K constraint restricts the number of selected items to at most . Since each selected item contributes to the sum and each unselected item contributes , the total count of selected items is exactly . We therefore write
For example, with five binaries , the requirement "at most of them equal " becomes
The assignment has sum and is feasible. The assignment has sum and is infeasible.