∇ProvenDecisions
Ctrl K

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.

Answer. Assumed: warehouses have unlimited capacity, so each customer's demand cost is demand times the per-unit delivery cost. The smallest objective value is 280, at x11 = 0, x12 = 1, x13 = 0, x21 = 0, x22 = 1, x23 = 0, x31 = 0, x32 = 1, x33 = 0, x41 = 0, x42 = 0, x43 = 1, x51 = 0, x52 = 0, x53 = 1, y1 = 0, y2 = 1, y3 = 1. All 35 constraints are satisfied exactly. Optimal within gap tolerance.

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.

🎙️ Spoken (36 seconds)

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.”

📷 Photographed
Photo of the facility location problem written on a note

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:

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.

VariableTypeMeaning
x11real numberfraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 1)
x12real numberfraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 2)
x13real numberfraction of customer i's demand served from warehouse j (fraction) (i = 1, j = 3)
x21real numberfraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 1)
x22real numberfraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 2)
x23real numberfraction of customer i's demand served from warehouse j (fraction) (i = 2, j = 3)
x31real numberfraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 1)
x32real numberfraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 2)
x33real numberfraction of customer i's demand served from warehouse j (fraction) (i = 3, j = 3)
x41real numberfraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 1)
x42real numberfraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 2)
x43real numberfraction of customer i's demand served from warehouse j (fraction) (i = 4, j = 3)
x51real numberfraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 1)
x52real numberfraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 2)
x53real numberfraction of customer i's demand served from warehouse j (fraction) (i = 5, j = 3)
y1binary (0 or 1)1 if warehouse 1, 2, 3 is opened (yes/no)
y2binary (0 or 1)1 if warehouse 1, 2, 3 is opened (yes/no)
y3binary (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.

x110x121x130x210x221x230x310x321x330x410x420x431x510x520x531y10y21y31

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.

#ConstraintValueLimitSlackBinding
1x11 + x12 + x13 = 1110yes
2x21 + x22 + x23 = 1110yes
3x31 + x32 + x33 = 1110yes
4x41 + x42 + x43 = 1110yes
5x51 + x52 + x53 = 1110yes
6x11 <= y1000yes
7x21 <= y1000yes
8x31 <= y1000yes
9x41 <= y1000yes
10x51 <= y1000yes
11x12 <= y2110yes
12x22 <= y2110yes
13x32 <= y2110yes
14x42 <= y2011
15x52 <= y2011
16x13 <= y3011
17x23 <= y3011
18x33 <= y3011
19x43 <= y3110yes
20x53 <= y3110yes
21x11 >= 0000yes
22x12 >= 0101
23x13 >= 0000yes
24x21 >= 0000yes
25x22 >= 0101
26x23 >= 0000yes
27x31 >= 0000yes
28x32 >= 0101
29x33 >= 0000yes
30x41 >= 0000yes
31x42 >= 0000yes
32x43 >= 0101
33x51 >= 0000yes
34x52 >= 0000yes
35x53 >= 0101

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 variablePricesValue
y1price of constraint 'x11 + x12 + x13 = 1' (objective change per extra unit of its right-hand side)60
y2price of constraint 'x21 + x22 + x23 = 1' (objective change per extra unit of its right-hand side)75
y3price of constraint 'x31 + x32 + x33 = 1' (objective change per extra unit of its right-hand side)46
y4price of constraint 'x41 + x42 + x43 = 1' (objective change per extra unit of its right-hand side)24
y5price of constraint 'x51 + x52 + x53 = 1' (objective change per extra unit of its right-hand side)75
y6price of constraint 'x11 <= y1' (objective change per extra unit of its right-hand side)-20
y7price of constraint 'x21 <= y1' (objective change per extra unit of its right-hand side)0
y8price of constraint 'x31 <= y1' (objective change per extra unit of its right-hand side)0
y9price of constraint 'x41 <= y1' (objective change per extra unit of its right-hand side)0
y10price of constraint 'x51 <= y1' (objective change per extra unit of its right-hand side)0
y11price of constraint 'x12 <= y2' (objective change per extra unit of its right-hand side)0
y12price of constraint 'x22 <= y2' (objective change per extra unit of its right-hand side)-15
y13price of constraint 'x32 <= y2' (objective change per extra unit of its right-hand side)-10
y14price of constraint 'x42 <= y2' (objective change per extra unit of its right-hand side)0
y15price of constraint 'x52 <= y2' (objective change per extra unit of its right-hand side)0
y16price of constraint 'x13 <= y3' (objective change per extra unit of its right-hand side)0
y17price of constraint 'x23 <= y3' (objective change per extra unit of its right-hand side)0
y18price of constraint 'x33 <= y3' (objective change per extra unit of its right-hand side)0
y19price of constraint 'x43 <= y3' (objective change per extra unit of its right-hand side)0
y20price of constraint 'x53 <= y3' (objective change per extra unit of its right-hand side)-35
y21price of constraint 'y1 <= 1' (objective change per extra unit of its right-hand side)0
y22price of constraint 'y2 <= 1' (objective change per extra unit of its right-hand side)0
y23price 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 cost

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: