Capacitated facility location: an integer programming example, solved and checked
The capacitated facility location 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
Two depots cost $20 and $25 to open and can ship 30 and 25 units. Three stores need 15, 20 and 10 units. Shipping one unit costs $2, $4 and $5 from depot 1 to stores 1, 2 and 3, and $5, $3 and $2 from depot 2. Minimize opening plus shipping cost.
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- yi = 1 if depot i opens; xij is the number of units shipped from depot i to store j.
- x11 + x12 + x13 ≤ 30 y1: a closed depot (y1 = 0) ships nothing, and an open one ships at most 30 units.
- x11 + x21 = 15: store 1 gets its 15 units. The next two lines are stores 2 and 3.
The model
Each line has a plain-language note on the right.
| make as small as possible: total depot opening cost plus shipping cost ($) | |
| limit 1: left side cannot exceed the right side | |
| limit 2: left side cannot exceed the right side | |
| limit 3: left side must equal 15 | |
| limit 4: left side must equal 20 | |
| limit 5: left side must equal 10 | |
| units shipped from depot 1 to store 1 (units) cannot be negative | |
| units shipped from depot 1 to store 2 (units) cannot be negative | |
| units shipped from depot 1 to store 3 (units) cannot be negative | |
| units shipped from depot 2 to store 1 (units) cannot be negative | |
| units shipped from depot 2 to store 2 (units) cannot be negative | |
| units shipped from depot 2 to store 3 (units) cannot be negative | |
| yes (1) or no (0) |
In matrix form
With its numbers:
What is being decided
There are 8 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| x11 | real number | units shipped from depot 1 to store 1 (units) |
| x12 | real number | units shipped from depot 1 to store 2 (units) |
| x13 | real number | units shipped from depot 1 to store 3 (units) |
| y1 | binary (0 or 1) | 1 if depot 1 is opened, else 0 (yes/no) |
| x21 | real number | units shipped from depot 2 to store 1 (units) |
| x22 | real number | units shipped from depot 2 to store 2 (units) |
| x23 | real number | units shipped from depot 2 to store 3 (units) |
| y2 | binary (0 or 1) | 1 if depot 2 is opened, else 0 (yes/no) |
Goal and limits
Minimize total depot opening cost plus shipping cost ($) subject to 11 constraints, of which 6 are simple bounds on a single variable.
Problem type
MILP, 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): (2) x21 + x22 + x23 <= 25*y2; (3) x11 + x21 = 15; (4) x12 + x22 = 20; (5) x13 + x23 = 10; (8) x13 >= 0; (9) x21 >= 0. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | x11 + x12 + x13 <= 30*y1 | 20 | 30 | 10 | |
| 2 | x21 + x22 + x23 <= 25*y2 | 25 | 25 | 0 | yes |
| 3 | x11 + x21 = 15 | 15 | 15 | 0 | yes |
| 4 | x12 + x22 = 20 | 20 | 20 | 0 | yes |
| 5 | x13 + x23 = 10 | 10 | 10 | 0 | yes |
| 6 | x11 >= 0 | 15 | 0 | 15 | |
| 7 | x12 >= 0 | 5 | 0 | 5 | |
| 8 | x13 >= 0 | 0 | 0 | 0 | yes |
| 9 | x21 >= 0 | 0 | 0 | 0 | yes |
| 10 | x22 >= 0 | 15 | 0 | 15 | |
| 11 | x23 >= 0 | 10 | 0 | 10 |
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
x11 = cp.Variable(name='x11') # units shipped from depot 1 to store 1 (units)
x12 = cp.Variable(name='x12') # units shipped from depot 1 to store 2 (units)
x13 = cp.Variable(name='x13') # units shipped from depot 1 to store 3 (units)
y1 = cp.Variable(name='y1', boolean=True) # 1 if depot 1 is opened, else 0 (yes/no)
x21 = cp.Variable(name='x21') # units shipped from depot 2 to store 1 (units)
x22 = cp.Variable(name='x22') # units shipped from depot 2 to store 2 (units)
x23 = cp.Variable(name='x23') # units shipped from depot 2 to store 3 (units)
y2 = cp.Variable(name='y2', boolean=True) # 1 if depot 2 is opened, else 0 (yes/no)
objective = cp.Minimize(2*x11 + 4*x12 + 5*x13 + 5*x21 + 3*x22 + 2*x23 + 20*y1 + 25*y2)
constraints = [
x11 + x12 + x13 <= 30*y1,
x21 + x22 + x23 <= 25*y2,
x11 + x21 == 15,
x12 + x22 == 20,
x13 + x23 == 10,
x11 >= 0,
x12 >= 0,
x13 >= 0,
x21 >= 0,
x22 >= 0,
x23 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('x11 =', x11.value)
print('x12 =', x12.value)
print('x13 =', x13.value)
print('y1 =', y1.value)
print('x21 =', x21.value)
print('x22 =', x22.value)
print('x23 =', x23.value)
print('y2 =', y2.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 153.333 on the integer optimum 160, a duality gap of 6.66667. Integer problems generally have a gap.
| Dual variable | Prices | Value |
|---|---|---|
| y1 | price of constraint 'x11 + x12 + x13 <= 30*y1' (objective change per extra unit of its right-hand side) | -0.666667 |
| y2 | price of constraint 'x21 + x22 + x23 <= 25*y2' (objective change per extra unit of its right-hand side) | -1.66667 |
| y3 | price of constraint 'x11 + x21 = 15' (objective change per extra unit of its right-hand side) | 2.66667 |
| y4 | price of constraint 'x12 + x22 = 20' (objective change per extra unit of its right-hand side) | 4.66667 |
| y5 | price of constraint 'x13 + x23 = 10' (objective change per extra unit of its right-hand side) | 3.66667 |
| y6 | price of constraint 'y1 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y7 | price of constraint 'y2 <= 1' (objective change per extra unit of its right-hand side) | -16.6667 |
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 20*y1 + 25*y2 + 2*x11 + 4*x12 + 5*x13 + 5*x21 + 3*x22 + 2*x23
subject to
x11 + x12 + x13 <= 30*y1
x21 + x22 + x23 <= 25*y2
x11 + x21 = 15
x12 + x22 = 20
x13 + x23 = 10
x11, x12, x13, x21, x22, x23 >= 0
binary: y1, y2
# y1 = 1 if depot 1 is opened, else 0 (yes/no)
# y2 = 1 if depot 2 is opened, else 0 (yes/no)
# x11 = units shipped from depot 1 to store 1 (units)
# x12 = units shipped from depot 1 to store 2 (units)
# x13 = units shipped from depot 1 to store 3 (units)
# x21 = units shipped from depot 2 to store 1 (units)
# x22 = units shipped from depot 2 to store 2 (units)
# x23 = units shipped from depot 2 to store 3 (units)
# objective = total depot opening cost plus shipping cost ($)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.