Set covering problem: an integer programming example, solved and checked
The set covering problem is a classic integer programming problem. Here it is solved by a real solver (HIGHS) and checked: every constraint, the dual, and the optimality certificate. Change the numbers below and solve your own.
Solve your own version free, no account needed
The problem
Six candidate stations (costs in $ millions) cover districts: S1 {1,2,3} cost 3; S2 {2,4} cost 2; S3 {3,4,5} cost 3; S4 {1,5} cost 2; S5 {4,5,6} cost 3; S6 {6} cost 1. Cover all districts 1-6 at minimum cost.
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- sj = 1 if station Sj is built. The objective adds the costs of the stations built, in $ millions.
- Each line says one district is covered by at least one station built. District 1 is covered by S1 or S4, so s1 + s4 ≥ 1.
The model
Each line has a plain-language note on the right.
| make as small as possible: total cost of built stations ($ millions) | |
| limit 1: left side must reach at least 1 | |
| limit 2: left side must reach at least 1 | |
| limit 3: left side must reach at least 1 | |
| limit 4: left side must reach at least 1 | |
| limit 5: left side must reach at least 1 | |
| limit 6: left side must reach at least 1 | |
| yes (1) or no (0) |
In matrix form
With its numbers:
What is being decided
There are 6 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| s1 | binary (0 or 1) | 1 if station S1 is built, 0 otherwise |
| s4 | binary (0 or 1) | 1 if station S4 is built, 0 otherwise |
| s2 | binary (0 or 1) | 1 if station S2 is built, 0 otherwise |
| s3 | binary (0 or 1) | 1 if station S3 is built, 0 otherwise |
| s5 | binary (0 or 1) | 1 if station S5 is built, 0 otherwise |
| s6 | binary (0 or 1) | 1 if station S6 is built, 0 otherwise |
Goal and limits
Minimize total cost of built stations ($ millions) subject to 6 constraints.
Problem type
ILP, complexity level 5: integer variables with linear objective and constraints. Solved with HIGHS at the Medium solver tier.
The answer at a glance
The optimal value of each decision, as the solver returned it.
Which constraints hold the answer in place
Binding (no slack left): (1) s1 + s4 >= 1; (2) s1 + s2 >= 1; (3) s1 + s3 >= 1; (4) s2 + s3 + s5 >= 1; (5) s3 + s4 + s5 >= 1; (6) s5 + s6 >= 1. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | s1 + s4 >= 1 | 1 | 1 | 0 | yes |
| 2 | s1 + s2 >= 1 | 1 | 1 | 0 | yes |
| 3 | s1 + s3 >= 1 | 1 | 1 | 0 | yes |
| 4 | s2 + s3 + s5 >= 1 | 1 | 1 | 0 | yes |
| 5 | s3 + s4 + s5 >= 1 | 1 | 1 | 0 | yes |
| 6 | s5 + s6 >= 1 | 1 | 1 | 0 | yes |
Algebraic model (low level)
Decision variables, objective and every constraint written out; this is exactly what the solver receives.
Standard form
As a linear program: minimize cᵀx subject to A x ≤ b (the inequality rows) and A_eq x = b_eq (the equations); a maximization is written as minimizing the negative.
Model code (cvxpy)
The same model in cvxpy, ready to run.
import cvxpy as cp
s1 = cp.Variable(name='s1', boolean=True) # 1 if station S1 is built, 0 otherwise
s4 = cp.Variable(name='s4', boolean=True) # 1 if station S4 is built, 0 otherwise
s2 = cp.Variable(name='s2', boolean=True) # 1 if station S2 is built, 0 otherwise
s3 = cp.Variable(name='s3', boolean=True) # 1 if station S3 is built, 0 otherwise
s5 = cp.Variable(name='s5', boolean=True) # 1 if station S5 is built, 0 otherwise
s6 = cp.Variable(name='s6', boolean=True) # 1 if station S6 is built, 0 otherwise
objective = cp.Minimize(3*s1 + 2*s2 + 3*s3 + 2*s4 + 3*s5 + s6)
constraints = [
s1 + s4 >= 1,
s1 + s2 >= 1,
s1 + s3 >= 1,
s2 + s3 + s5 >= 1,
s3 + s4 + s5 >= 1,
s5 + s6 >= 1,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('s1 =', s1.value)
print('s4 =', s4.value)
print('s2 =', s2.value)
print('s3 =', s3.value)
print('s5 =', s5.value)
print('s6 =', s6.value)The dual problem
Every constraint of the original (primal) problem gets a price, and every primal variable becomes a constraint on those prices. Integer variables are relaxed: this is the dual of the continuous (LP) relaxation, which gives a bound on the integer optimum, not its exact value. Only weak duality: the dual of the continuous relaxation gives an lower bound of 6 on the integer optimum 6, a duality gap of 0. Integer problems generally have a gap.
| Dual variable | Prices | Value |
|---|---|---|
| y1 | price of constraint 's1 + s4 >= 1' (objective change per extra unit of its right-hand side) | 0 |
| y2 | price of constraint 's1 + s2 >= 1' (objective change per extra unit of its right-hand side) | 2 |
| y3 | price of constraint 's1 + s3 >= 1' (objective change per extra unit of its right-hand side) | 1 |
| y4 | price of constraint 's2 + s3 + s5 >= 1' (objective change per extra unit of its right-hand side) | 0 |
| y5 | price of constraint 's3 + s4 + s5 >= 1' (objective change per extra unit of its right-hand side) | 2 |
| y6 | price of constraint 's5 + s6 >= 1' (objective change per extra unit of its right-hand side) | 1 |
| y7 | price of constraint 's1 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y8 | price of constraint 's4 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y9 | price of constraint 's2 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y10 | price of constraint 's3 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y11 | price of constraint 's5 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y12 | price of constraint 's6 <= 1' (objective change per extra unit of its right-hand side) | 0 |
Solve your own
This is the model as the app reads it. Change any number and solve it in the free box on the front page (no account needed).
minimize 3*s1 + 2*s2 + 3*s3 + 2*s4 + 3*s5 + 1*s6
subject to
s1 + s4 >= 1
s1 + s2 >= 1
s1 + s3 >= 1
s2 + s3 + s5 >= 1
s3 + s4 + s5 >= 1
s5 + s6 >= 1
binary: s1, s2, s3, s4, s5, s6
# s1 = 1 if station S1 is built, 0 otherwise
# s2 = 1 if station S2 is built, 0 otherwise
# s3 = 1 if station S3 is built, 0 otherwise
# s4 = 1 if station S4 is built, 0 otherwise
# s5 = 1 if station S5 is built, 0 otherwise
# s6 = 1 if station S6 is built, 0 otherwise
# objective = total cost of built stations ($ millions)Checked: the app's answer matches the reference answer in our test set, which two solvers (HIGHS, SCIP) agree on. Built 2026-11-10.
Related examples
Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.