Warehouse location (Fermat-Weber point): a convex optimization example, solved and checked
The warehouse location (Fermat-Weber point) is a classic convex optimization problem. Here it is solved by a real solver (CLARABEL) and checked: every constraint, and the optimality certificate. Change the numbers below and solve your own.
Solve your own version free, no account needed
The problem
Towns sit at (0, 0), (4, 0) and (1, 3) on a map in km. Where should a warehouse go to minimize the total straight-line distance to the three towns, and what is that total?
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- √(x2 + y2) is the straight-line distance in km from the warehouse at (x, y) to the town at (0, 0), by Pythagoras. The other two terms are the distances to (4, 0) and (1, 3).
Assumptions:
- the warehouse may be placed anywhere on the plane
The model
Each line has a plain-language note on the right.
| make as small as possible: total straight-line distance from the warehouse to the three towns (km) | |
| warehouse east-west coordinate (km) is at least -1000 | |
| warehouse north-south coordinate (km) is at least -1000 |
What is being decided
There are 2 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| x | real number | warehouse east-west coordinate (km) |
| y | real number | warehouse north-south coordinate (km) |
Goal and limits
Minimize total straight-line distance from the warehouse to the three towns (km) subject to 2 constraints, of which 2 are simple bounds on a single variable.
Problem type
Conic (convex), complexity level 4: convex nonlinear functions such as log, exp, square roots or powers. Solved with CLARABEL at the Medium solver tier.
Picture
Shaded: every point that satisfies all the constraints. Dot: the optimum. Dashed: the objective's level line through it.
The answer at a glance
The optimal value of each decision, as the solver returned it.
Which constraints hold the answer in place
No constraint is binding. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | x >= -1000 | 1.30224 | -1000 | 1001.3 | |
| 2 | y >= -1000 | 1.04678 | -1000 | 1001.05 |
Algebraic model (low level)
Decision variables, objective and every constraint written out; this is exactly what the solver receives.
Model code (cvxpy)
The same model in cvxpy, ready to run.
import cvxpy as cp
x = cp.Variable(name='x') # warehouse east-west coordinate (km)
y = cp.Variable(name='y') # warehouse north-south coordinate (km)
objective = cp.Minimize(cp.sqrt(x**2 + y**2) + cp.sqrt(y**2 + (x - 4)**2) + cp.sqrt((x - 1)**2 + (y - 3)**2))
constraints = [
x >= -1000,
y >= -1000,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='CLARABEL')
print(problem.status, problem.value)
print('x =', x.value)
print('y =', y.value)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 sqrt((x-0)^2 + (y-0)^2) + sqrt((x-4)^2 + (y-0)^2) + sqrt((x-1)^2 + (y-3)^2)
subject to
x >= -1000
y >= -1000
# x = warehouse east-west coordinate (km)
# y = warehouse north-south coordinate (km)
# objective = total straight-line distance from the warehouse to the three towns (km)
# assume: the warehouse may be placed anywhere on the planeChecked: the app's answer matches the reference answer in our test set, which two solvers (CLARABEL, SCS) 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.