Interactive Graph Theory Learning
Interactive Graph Theory Learning
Guest User
Using app without sign in
Facility location solver
Finds optimal central hub minimizing average distance
Select an algorithm and generate steps to begin visualization
The facility location problem chooses where to open facilities, such as warehouses or clinics, to serve a set of demand points at minimum total cost, balancing facility opening costs against customer service distances. Most variants, including k-median and k-center, are NP-hard.
Practical solvers combine several ideas. Greedy algorithms open the facility with the best cost-per-covered-demand ratio and achieve provable approximation guarantees. Local search swaps open and closed facilities while improvement is possible. Exact solutions for moderate sizes use mixed integer programming, and large instances use Lagrangian relaxation or clustering-based heuristics such as k-means to seed candidate sites.
Facility location decides warehouse and distribution center placement in supply chains, cell tower and EV charging coverage, hospital and fire station siting for emergency response, and content delivery server placement. It is a flagship problem of operations research and logistics analytics.
The uncapacitated facility location problem trades off the fixed cost of opening a site against the transport cost of serving customers from it. Greedy opens whichever site most improves the total.
GreedyFacilityLocation(sites, customers):
open = {}
cost[c] = infinity for every customer c
repeat:
best = null
for each unopened site s:
// saving = reduction in service cost, minus
// the fixed cost of opening s
saving = sum over c of max(0, cost[c] - d(c,s))
- openCost[s]
if saving > best.saving: best = s
if best is null or best.saving <= 0: stop
open.add(best)
cost[c] = min(cost[c], d(c, best)) for every cThe greedy rule is submodular: each additional facility helps less than the one before, because customers already served cheaply cannot be improved much. That structure is what gives greedy its provable guarantee, a factor of 1 + ln n for the uncapacitated version, and it is why the stopping rule is simply "no site has positive saving left".
Decide which of two candidate depots to open when serving four customers, weighing fixed cost against travel.
Example graph: Customers at positions 0, 2, 8 and 10 on a line. Candidate sites at position 1 and position 9, each costing 10 to open. Service cost is the distance.
The optimal solution opens both depots for a total of 24, beating either single depot at 28. The instructive part is the second evaluation: the saving from adding a facility is measured only against what customers currently pay, not against serving them from nothing. That is why the marginal value of each new facility falls as more are opened, and why greedy stops when the next one would cost more than it saves.
Time: NP-hard; O(n·m^2) greedy · Space: O(n + m)
With n customers and m candidate sites, each greedy round evaluates every unopened site against every customer at O(n·m), and there are at most m rounds, giving O(n·m squared). The problem itself is NP-hard, reducing from set cover, and that reduction also transfers the hardness of approximation: no polynomial algorithm can beat a factor of 1 + ln n unless P equals NP. Greedy achieves exactly that bound for the uncapacitated case, so it is not merely a reasonable heuristic but provably the best possible ratio in general. The metric version, where distances obey the triangle inequality, admits better constant-factor approximations, currently around 1.488.
The right model depends on whether facilities have capacity and whether you are minimising total cost or worst-case distance.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Capacitated facility location | Each site can serve only so much demand, so assignment becomes a transportation problem in its own right. | NP-hard |
| k-median | You must open exactly k facilities and there is no fixed opening cost to trade off. | NP-hard, 2.675-approx |
| k-center | You care about the worst-served customer rather than the total, as with emergency response times. | NP-hard, 2-approx |
| Integer programming | The instance is modest and you need a provable optimum. Modern solvers handle thousands of sites. | exponential worst case |
| k-means clustering | Sites can go anywhere in continuous space rather than being chosen from a candidate list. | O(n·k·d·i) |
Read the full article: Operations Research and Graph Theory
Related algorithms: K-Means Logistics Clustering, Fleet Dispatching (mTSP), Capacitated Vehicle Routing (CVRP)