Ambulance Station Placement
P-Median Problem
A city must position p ambulance stations among candidate sites to minimize the population-weighted distance to the nearest station. Every second counts in emergency response — optimal placement can mean the difference between life and death. This is the p-Median Problem, a cornerstone of facility location theory.
The Problem
Minimizing emergency response times across Quebec City
Quebec City’s emergency medical services must decide where to place ambulance stations to serve a population spread across diverse neighborhoods — from the dense historic core of Vieux-Québec to the sprawling suburbs of Charlesbourg and Cap-Rouge. Each neighborhood has a population that generates emergency calls proportional to its size, and the goal is to ensure that the total population-weighted distance from every demand zone to its nearest station is minimized.
Given m candidate sites, n demand zones with population weights wj, and pairwise distances d(j, i), the objective is to select exactly p stations to open so as to minimize Σ wj · mini ∈ S d(j, i), where S is the set of opened stations. This is the p-Median Problem — NP-hard for general p (Kariv & Hakimi, 1979).
With 8 demand zones and 5 candidate sites choosing p = 3, there are C(5,3) = 10 possible configurations. But real cities have hundreds of zones and dozens of candidate sites, making exhaustive enumeration infeasible and heuristic methods essential.
The Model
Mathematical formulation of the p-Median Problem
subject to
Σi xji = 1 ∀ j // each demand zone assigned to exactly one station
xji ≤ yi ∀ j, i // can only assign to open stations
Σi yi = p // exactly p stations opened
xji, yi ∈ {0, 1} // binary decision variables
Where wj is the population of demand zone j, dji is the distance from zone j to candidate site i, yi indicates whether station i is opened, and xji assigns zone j to station i.
See full p-Median theory and all algorithmsTry It Yourself
Edit demand zones and candidate sites, then solve with all algorithms
Station Placement Solver
8 Zones · 5 Candidates · p = 3| Name | Lat | Lng | Population |
|---|
| Name | Lat | Lng |
|---|
The Algorithms
Two heuristic approaches for the p-Median Problem
Greedy Add Heuristic
A constructive heuristic that builds the solution incrementally.
- Start with no facilities open.
- Evaluate each closed candidate: compute the total weighted distance if it were added to the current set.
- Open the facility that reduces total weighted distance the most.
- Repeat until p facilities are open.
Complexity: O(p · m · n) — fast but may miss global optimum.
Teitz-Bart Interchange Heuristic
An improvement heuristic that refines the greedy solution by swapping facilities.
- Start with the greedy solution (p open facilities).
- For each open facility, try swapping it with each closed facility.
- Accept the swap if total weighted distance improves.
- Repeat until no improving swap exists.
Complexity: O(iterations · p · (m−p) · n) — converges to local optimum.
Why It’s More Complex
Real-world ambulance placement goes beyond the p-Median model
Real-World Considerations
- Time-varying demand — call volumes shift between day and night, weekdays and weekends, requiring dynamic repositioning strategies.
- Traffic congestion — travel times vary by time of day and route; Euclidean distance is a poor proxy for actual response time in urban areas.
- Coverage constraints — regulations may require that every zone has a station within a maximum response time (the Set Covering variant).
- Multiple vehicle types — basic life support vs. advanced life support units have different capabilities and deployment considerations.
- Relocation during calls — when an ambulance is dispatched, remaining units must be repositioned to maintain coverage across the city.
- Backup coverage — ensuring that zones have access to a second-nearest station in case the primary unit is unavailable.
Key References
- (1964). "Optimum Locations of Switching Centers and the Absolute Centers and Medians of a Graph." Operations Research, 12(3), 450–459.
- (2005). "Location Analysis: A Synthesis and Survey." European Journal of Operational Research, 165(1), 1–19.
- (1979). "An Algorithmic Approach to Network Location Problems." SIAM Journal on Applied Mathematics, 37(3), 539–560.
- (1968). "Heuristic Methods for Estimating the Generalized Vertex Median of a Weighted Graph." Operations Research, 16(5), 955–961.
- Application context and algorithm implementations from this repository’s p-Median module.
Need to Optimize Facility Placement?
Every emergency services system has unique constraints — terrain, traffic patterns, population density, regulatory requirements. This demo shows the fundamentals, but real-world solutions require tailored modeling and implementation.