Facility location problem: an integer programming example, solved and checked
The facility location 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
Say it or snap it
You can give ProvenDecisions this problem out loud or as a photo. The app wrote down both, solved them, and got the same checked answer as the typed version.
What the app heard: “three warehouses cost $30, $25 and $35 to open. Five customers need 10, 15, 12, 8 and 10 units. Delivering one unit to customer one costs $4 from warehouse one, $6 from warehouse two and $9 from warehouse three. Four customer two the costs per unit are five, four and seven dollars. For customer three, six, three and four dollars. For customer four, eight, five and three dollars. For customer five, 10, eight and four, $10, which warehouses should open and which warehouse serves each customer to minimize the total cost in dollars.”

The problem
Three warehouses have fixed opening costs of $30, $25 and $35. Five customers with demands of 10, 15, 12, 8 and 10 units pay delivery costs in dollars per unit (rows customers, columns warehouses): [4,6,9], [5,4,7], [6,3,4], [8,5,3], [10,8,4]. Which warehouses should open, and who serves whom, to minimize the total cost in dollars?
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
Assumptions:
- warehouses have unlimited capacity, so each customer's demand cost is demand times the per-unit delivery cost
The model
Each line has a plain-language note on the right.
| make as small as possible: total cost: warehouse opening costs plus demand-weighted delivery costs (dollars) | |
| limit 1: left side must equal 1 | |
| limit 2: left side must equal 1 | |
| limit 3: left side must equal 1 | |
| limit 4: left side must equal 1 | |
| limit 5: left side must equal 1 | |
| limit 6: left side cannot exceed the right side | |
| limit 7: left side cannot exceed the right side | |
| limit 8: left side cannot exceed the right side | |
| limit 9: left side cannot exceed the right side | |
| limit 10: left side cannot exceed the right side | |
| limit 11: left side cannot exceed the right side | |
| limit 12: left side cannot exceed the right side | |
| limit 13: left side cannot exceed the right side | |
| limit 14: left side cannot exceed the right side | |
| limit 15: left side cannot exceed the right side | |
| limit 16: left side cannot exceed the right side | |
| limit 17: left side cannot exceed the right side | |
| limit 18: left side cannot exceed the right side | |
| limit 19: left side cannot exceed the right side | |
| limit 20: left side cannot exceed the right side | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 1) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 2) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 3) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 1) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 2) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 3) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 1) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 2) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 3) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 1) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 2) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 3) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 1) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 2) cannot be negative | |
| fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 3) cannot be negative | |
| yes (1) or no (0) |
What is being decided
There are 18 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| x11 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 1) |
| x12 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 2) |
| x13 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 3) |
| x21 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 1) |
| x22 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 2) |
| x23 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 3) |
| x31 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 1) |
| x32 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 2) |
| x33 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 3) |
| x41 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 1) |
| x42 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 2) |
| x43 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 3) |
| x51 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 1) |
| x52 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 2) |
| x53 | real number | fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 3) |
| y1 | binary (0 or 1) | 1 if warehouse 1, 2, 3 is opened (yes/no) |
| y2 | binary (0 or 1) | 1 if warehouse 1, 2, 3 is opened (yes/no) |
| y3 | binary (0 or 1) | 1 if warehouse 1, 2, 3 is opened (yes/no) |
Goal and limits
Minimize total cost: warehouse opening costs plus demand-weighted delivery costs (dollars) subject to 35 constraints, of which 15 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): constraints 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 19, 20, 21, 23, 24, 26, 27, 29, 30, 31, 33, 34 (see the table). 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 = 1 | 1 | 1 | 0 | yes |
| 2 | x21 + x22 + x23 = 1 | 1 | 1 | 0 | yes |
| 3 | x31 + x32 + x33 = 1 | 1 | 1 | 0 | yes |
| 4 | x41 + x42 + x43 = 1 | 1 | 1 | 0 | yes |
| 5 | x51 + x52 + x53 = 1 | 1 | 1 | 0 | yes |
| 6 | x11 <= y1 | 0 | 0 | 0 | yes |
| 7 | x21 <= y1 | 0 | 0 | 0 | yes |
| 8 | x31 <= y1 | 0 | 0 | 0 | yes |
| 9 | x41 <= y1 | 0 | 0 | 0 | yes |
| 10 | x51 <= y1 | 0 | 0 | 0 | yes |
| 11 | x12 <= y2 | 1 | 1 | 0 | yes |
| 12 | x22 <= y2 | 1 | 1 | 0 | yes |
| 13 | x32 <= y2 | 1 | 1 | 0 | yes |
| 14 | x42 <= y2 | 0 | 1 | 1 | |
| 15 | x52 <= y2 | 0 | 1 | 1 | |
| 16 | x13 <= y3 | 0 | 1 | 1 | |
| 17 | x23 <= y3 | 0 | 1 | 1 | |
| 18 | x33 <= y3 | 0 | 1 | 1 | |
| 19 | x43 <= y3 | 1 | 1 | 0 | yes |
| 20 | x53 <= y3 | 1 | 1 | 0 | yes |
| 21 | x11 >= 0 | 0 | 0 | 0 | yes |
| 22 | x12 >= 0 | 1 | 0 | 1 | |
| 23 | x13 >= 0 | 0 | 0 | 0 | yes |
| 24 | x21 >= 0 | 0 | 0 | 0 | yes |
| 25 | x22 >= 0 | 1 | 0 | 1 | |
| 26 | x23 >= 0 | 0 | 0 | 0 | yes |
| 27 | x31 >= 0 | 0 | 0 | 0 | yes |
| 28 | x32 >= 0 | 1 | 0 | 1 | |
| 29 | x33 >= 0 | 0 | 0 | 0 | yes |
| 30 | x41 >= 0 | 0 | 0 | 0 | yes |
| 31 | x42 >= 0 | 0 | 0 | 0 | yes |
| 32 | x43 >= 0 | 1 | 0 | 1 | |
| 33 | x51 >= 0 | 0 | 0 | 0 | yes |
| 34 | x52 >= 0 | 0 | 0 | 0 | yes |
| 35 | x53 >= 0 | 1 | 0 | 1 |
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') # fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 1)
x12 = cp.Variable(name='x12') # fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 2)
x13 = cp.Variable(name='x13') # fraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 3)
x21 = cp.Variable(name='x21') # fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 1)
x22 = cp.Variable(name='x22') # fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 2)
x23 = cp.Variable(name='x23') # fraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 3)
x31 = cp.Variable(name='x31') # fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 1)
x32 = cp.Variable(name='x32') # fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 2)
x33 = cp.Variable(name='x33') # fraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 3)
x41 = cp.Variable(name='x41') # fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 1)
x42 = cp.Variable(name='x42') # fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 2)
x43 = cp.Variable(name='x43') # fraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 3)
x51 = cp.Variable(name='x51') # fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 1)
x52 = cp.Variable(name='x52') # fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 2)
x53 = cp.Variable(name='x53') # fraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 3)
y1 = cp.Variable(name='y1', boolean=True) # 1 if warehouse 1, 2, 3 is opened (yes/no)
y2 = cp.Variable(name='y2', boolean=True) # 1 if warehouse 1, 2, 3 is opened (yes/no)
y3 = cp.Variable(name='y3', boolean=True) # 1 if warehouse 1, 2, 3 is opened (yes/no)
objective = cp.Minimize(40*x11 + 60*x12 + 90*x13 + 75*x21 + 60*x22 + 105*x23 + 72*x31 + 36*x32 + 48*x33 + 64*x41 + 40*x42 + 24*x43 + 100*x51 + 80*x52 + 40*x53 + 30*y1 + 25*y2 + 35*y3)
constraints = [
x11 + x12 + x13 == 1,
x21 + x22 + x23 == 1,
x31 + x32 + x33 == 1,
x41 + x42 + x43 == 1,
x51 + x52 + x53 == 1,
x11 <= y1,
x21 <= y1,
x31 <= y1,
x41 <= y1,
x51 <= y1,
x12 <= y2,
x22 <= y2,
x32 <= y2,
x42 <= y2,
x52 <= y2,
x13 <= y3,
x23 <= y3,
x33 <= y3,
x43 <= y3,
x53 <= y3,
x11 >= 0,
x12 >= 0,
x13 >= 0,
x21 >= 0,
x22 >= 0,
x23 >= 0,
x31 >= 0,
x32 >= 0,
x33 >= 0,
x41 >= 0,
x42 >= 0,
x43 >= 0,
x51 >= 0,
x52 >= 0,
x53 >= 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('x21 =', x21.value)
print('x22 =', x22.value)
print('x23 =', x23.value)
print('x31 =', x31.value)
print('x32 =', x32.value)
print('x33 =', x33.value)
print('x41 =', x41.value)
print('x42 =', x42.value)
print('x43 =', x43.value)
print('x51 =', x51.value)
print('x52 =', x52.value)
print('x53 =', x53.value)
print('y1 =', y1.value)
print('y2 =', y2.value)
print('y3 =', y3.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 280 on the integer optimum 280, a duality gap of 0. Integer problems generally have a gap.
| Dual variable | Prices | Value |
|---|---|---|
| y1 | price of constraint 'x11 + x12 + x13 = 1' (objective change per extra unit of its right-hand side) | 60 |
| y2 | price of constraint 'x21 + x22 + x23 = 1' (objective change per extra unit of its right-hand side) | 75 |
| y3 | price of constraint 'x31 + x32 + x33 = 1' (objective change per extra unit of its right-hand side) | 46 |
| y4 | price of constraint 'x41 + x42 + x43 = 1' (objective change per extra unit of its right-hand side) | 24 |
| y5 | price of constraint 'x51 + x52 + x53 = 1' (objective change per extra unit of its right-hand side) | 75 |
| y6 | price of constraint 'x11 <= y1' (objective change per extra unit of its right-hand side) | -20 |
| y7 | price of constraint 'x21 <= y1' (objective change per extra unit of its right-hand side) | 0 |
| y8 | price of constraint 'x31 <= y1' (objective change per extra unit of its right-hand side) | 0 |
| y9 | price of constraint 'x41 <= y1' (objective change per extra unit of its right-hand side) | 0 |
| y10 | price of constraint 'x51 <= y1' (objective change per extra unit of its right-hand side) | 0 |
| y11 | price of constraint 'x12 <= y2' (objective change per extra unit of its right-hand side) | 0 |
| y12 | price of constraint 'x22 <= y2' (objective change per extra unit of its right-hand side) | -15 |
| y13 | price of constraint 'x32 <= y2' (objective change per extra unit of its right-hand side) | -10 |
| y14 | price of constraint 'x42 <= y2' (objective change per extra unit of its right-hand side) | 0 |
| y15 | price of constraint 'x52 <= y2' (objective change per extra unit of its right-hand side) | 0 |
| y16 | price of constraint 'x13 <= y3' (objective change per extra unit of its right-hand side) | 0 |
| y17 | price of constraint 'x23 <= y3' (objective change per extra unit of its right-hand side) | 0 |
| y18 | price of constraint 'x33 <= y3' (objective change per extra unit of its right-hand side) | 0 |
| y19 | price of constraint 'x43 <= y3' (objective change per extra unit of its right-hand side) | 0 |
| y20 | price of constraint 'x53 <= y3' (objective change per extra unit of its right-hand side) | -35 |
| y21 | price of constraint 'y1 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y22 | price of constraint 'y2 <= 1' (objective change per extra unit of its right-hand side) | 0 |
| y23 | price of constraint 'y3 <= 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 30*y1 + 25*y2 + 35*y3 + 40*x11 + 60*x12 + 90*x13 + 75*x21 + 60*x22 + 105*x23 + 72*x31 + 36*x32 + 48*x33 + 64*x41 + 40*x42 + 24*x43 + 100*x51 + 80*x52 + 40*x53
subject to
x11 + x12 + x13 = 1
x21 + x22 + x23 = 1
x31 + x32 + x33 = 1
x41 + x42 + x43 = 1
x51 + x52 + x53 = 1
x11 <= y1
x21 <= y1
x31 <= y1
x41 <= y1
x51 <= y1
x12 <= y2
x22 <= y2
x32 <= y2
x42 <= y2
x52 <= y2
x13 <= y3
x23 <= y3
x33 <= y3
x43 <= y3
x53 <= y3
x11, x12, x13, x21, x22, x23, x31, x32, x33, x41, x42, x43, x51, x52, x53 >= 0
binary: y1, y2, y3
# y1, y2, y3 = 1 if warehouse 1, 2, 3 is opened (yes/no)
# xij = fraction of customer i's demand served from warehouse j (fraction)
# objective = total cost: warehouse opening costs plus demand-weighted delivery costs (dollars)
# assume: warehouses have unlimited capacity, so each customer's demand cost is demand times the per-unit delivery costChecked: 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.