∇ProvenDecisions
Ctrl K

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.

Answer. The smallest objective value is 6, at s1 = 1, s4 = 0, s2 = 0, s3 = 0, s5 = 1, s6 = 0. All 6 constraints are satisfied exactly. Optimal within gap tolerance.

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:

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.

VariableTypeMeaning
s1binary (0 or 1)1 if station S1 is built, 0 otherwise
s4binary (0 or 1)1 if station S4 is built, 0 otherwise
s2binary (0 or 1)1 if station S2 is built, 0 otherwise
s3binary (0 or 1)1 if station S3 is built, 0 otherwise
s5binary (0 or 1)1 if station S5 is built, 0 otherwise
s6binary (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.

s11s40s20s30s51s60

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.

#ConstraintValueLimitSlackBinding
1s1 + s4 >= 1110yes
2s1 + s2 >= 1110yes
3s1 + s3 >= 1110yes
4s2 + s3 + s5 >= 1110yes
5s3 + s4 + s5 >= 1110yes
6s5 + s6 >= 1110yes

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 variablePricesValue
y1price of constraint 's1 + s4 >= 1' (objective change per extra unit of its right-hand side)0
y2price of constraint 's1 + s2 >= 1' (objective change per extra unit of its right-hand side)2
y3price of constraint 's1 + s3 >= 1' (objective change per extra unit of its right-hand side)1
y4price of constraint 's2 + s3 + s5 >= 1' (objective change per extra unit of its right-hand side)0
y5price of constraint 's3 + s4 + s5 >= 1' (objective change per extra unit of its right-hand side)2
y6price of constraint 's5 + s6 >= 1' (objective change per extra unit of its right-hand side)1
y7price of constraint 's1 <= 1' (objective change per extra unit of its right-hand side)0
y8price of constraint 's4 <= 1' (objective change per extra unit of its right-hand side)0
y9price of constraint 's2 <= 1' (objective change per extra unit of its right-hand side)0
y10price of constraint 's3 <= 1' (objective change per extra unit of its right-hand side)0
y11price of constraint 's5 <= 1' (objective change per extra unit of its right-hand side)0
y12price 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)

Change the numbers and solve it

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

All 50 solved examples

Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.

What do you want to optimize?

Type the math, describe it in words, snap a photo or say it. ProvenDecisions builds the model, solves it, checks it and walks you through it.

One constraint per line, or separated by commas. Add integer: x, y or binary: z for whole-number decisions. LaTeX works too.

Try: