Skip to content

Location-Allocation (P-Median)

The location-allocation problem answers the question: given N potential sites, where should I place P facilities to minimize total customer travel? It’s the mathematical core of network planning for retail chains, hospitals, fire stations, and any service with physical locations.

Minimize Z = Σᵢ Σⱼ (wᵢ × dᵢⱼ × xᵢⱼ)

Subject to:

  • Each demand point i is assigned to exactly one facility j
  • Exactly P facilities are open
  • A demand point can only be assigned to an open facility

Where:

  • wᵢ = demand (population, spending power) at point i
  • dᵢⱼ = distance/travel time from demand point i to facility j
  • xᵢⱼ = 1 if point i is served by facility j, 0 otherwise
  • P = number of facilities to locate

“Facility location problems involve flows… the p-median problem minimizes total weighted distance.” — de Smith, Goodchild & Longley, Geospatial Analysis, §7.4

ModelObjectiveUse Case
P-medianMinimize average distanceRetail chains, post offices
P-centreMinimize maximum distanceEmergency services, hospitals
CoverageMaximize population within threshold distanceAmbulance stations, cell towers
Maximal coverageCover max demand with budget constraintAny service with fixed budget
  1. Define demand points — census blocks, residential areas, each with a population weight
  2. Define candidate sites — all possible locations you’d consider opening
  3. Calculate distance matrix — travel time or distance from every demand point to every candidate
  4. Run optimization — find the P sites that minimize total weighted distance
  5. Assign customers — each demand point goes to its nearest open facility

de Smith et al. describe three practical approaches:

Start with no facilities. Add the one that reduces total distance the most. Repeat P times. Fast but can get stuck in local optima.

Start with P random facilities. Try swapping each one with a non-selected candidate. Accept swaps that reduce total distance. Repeat until no improvement. Better solutions, slower convergence.

Relax the assignment constraint, solve a simpler problem, then iteratively tighten. Provides bounds on how close your solution is to optimal.

For a restaurant chain evaluating 14 Wa In Fong East among multiple candidates:

InputHK Open Data SourceNotes
Demand pointsCensus TPUs (Tertiary Planning Units)~450 units across HK Island
Population weightsCensus 2021 population by TPUResident + working population
Candidate sitesFEHD-licensed restaurant locations208 in C&W, 17,154 across HK
Distance matrixGoogle/OSM network distanceWalking + MTR time

Example: “Where should we open 3 branches on HK Island?”

Section titled “Example: “Where should we open 3 branches on HK Island?””

The p-median solver would evaluate all possible combinations of 3 sites from hundreds of candidates, selecting the trio that minimizes total weighted travel time for the entire Island population.

~450
Demand Points (TPUs)
17,154
Candidate Locations

For evaluating one specific site (14 Wa In Fong East), location-allocation isn’t the right tool directly. But it answers a critical question:

“Is this site in the optimal set?”

If you run p-median for P=5 branches in Central & Western, and 14 Wa In Fong East doesn’t appear in any solution, that’s a strong signal. If it consistently appears, that validates the location.

Strengths:

  • Mathematically rigorous optimization
  • Considers the entire network simultaneously (not just one catchment)
  • Answers “where” not just “how good”
  • Scales to regional and national planning

Limitations:

  • Requires complete distance matrix (expensive to compute)
  • NP-hard — heuristics needed for real-world size
  • Assumes customers always go to nearest facility (ignores brand preference, quality)
  • Static — doesn’t account for time-varying demand

The p-median model pairs naturally with the Huff Model and Spatial Interaction Model:

  1. P-median → identifies where to locate
  2. Huff/SIM → predicts how much revenue each location captures
  3. Agent simulation → tests what happens when consumers make complex choices

📖 de Smith, M.J., Goodchild, M.F. & Longley, P.A. (2024). Geospatial Analysis: A Comprehensive Guide. §7.4: Facility Location — P-Median and P-Centre Problems.