Skip to content

Facility location and capacity (quakecascade.allocate)

What it computes

All functions take a cost matrix \(d_{ji}\) from sites \(j\) (rows) to demand points \(i\) (columns) and demand weights \(w_i\). A network matrix from RoadNetwork.travel_time_matrix(demand, sites) is demand × sites, so pass its transpose .T. inf marks an unreachable pair.

  • Maximal coverage (Church & ReVelle 1974), greedy: pick up to \(p\) sites maximising the demand within radius \(r\).
  • p-median (Hakimi 1964; ReVelle & Swain 1970):
\[ \min_{S,\ |S| = p}\ \sum_i w_i\, \min_{j \in S} d_{ji}, \]

solved by greedy construction then Teitz & Bart (1968) vertex substitution: each chosen site is swapped for any unchosen one while the objective falls. The result is never worse than the greedy start (tested over random cases, and against exact_location_audit, which enumerates every set on small problems). * Capacitated assignment: cheapest eligible pairs first, a whole demand point goes to the nearest site that still has room, spilling to the next one when it is full. * Capacitated siting: greedy + Teitz–Bart over the lexicographic objective (served demand first, then weighted cost). * Capacity from area: \(C = \lfloor A / a \rfloor\), area \(A\) in m² and \(a\) m² per person. * Capacity balance: two readings of one supply and demand. 1. Nearest-site load without a capacity limit, and the overload ratio \(\rho_j = \sum_{i \to j} w_i / C_j\) (where people would crowd if each goes to the nearest site). 2. A capacity-respecting allocation: pairs are filled cheapest first up to each site's capacity, so demand spills from full sites to the next nearest one with room within max_cost. split=True lets a point's people use several sites; split=False keeps whole points.

Outputs and missing data

capacity_balance returns CapacityBalance(sites, demand, summary):

Table Columns
sites capacity, nearest_demand, overload_ratio (inf when capacity is 0 and demand > 0), served, utilisation, site_status (computed; partial when the site also receives demand whose strictly nearest site has unknown capacity, so its load may be overstated; no_capacity)
demand demand, nearest_site (-1 none reachable), nearest_cost, served, unserved, demand_status (computed; partial when a nearer site has unknown capacity or an unknown cost, so the demand was diverted; no_capacity, with NaN served and unserved, when every site it may reach has unknown capacity; no_demand)
summary total_demand, total_capacity, served, unserved, unreachable_demand, unknown_capacity_demand, n_sites_overloaded, n_sites_no_capacity, n_demand_missing, split; total_demand = served + unserved + unknown_capacity_demand

A site with unknown capacity receives nobody; it is never given an assumed capacity. A demand point with unknown population is left out and counted. assign_to_nearest and capacitated_assign report an unreachable point with site -1 and cost inf (PlanX used -1.0).

Parameters

Parameter Unit Default Source / note
p sites required –
radius cost unit required (coverage) –
penalty cost unit required when D has inf cost of an unreachable pair; no published default (PlanX used 1.5 × the largest finite cost). State it in the report
max_iter rounds 100 substitution stops earlier when no swap improves
max_cost cost unit none catchment limit
m2_per_person \(a\) m²/person required depends on purpose: e.g. Sphere (2018) shelter standard 3 gives ≥ 3.5 m² covered living space per person; open assembly areas follow national guidance with much smaller values
split – True divisible vs whole-point allocation

Caveats

  • Greedy + Teitz–Bart is a heuristic; use exact_location_audit on small cases to measure the gap.
  • The capacitated rules are explainable greedy fills, not min-cost-flow optima; whole-point assignment can strand capacity smaller than one point.
  • Capacity from area is only as good as the usable-area estimate.

Example

import numpy as np
from quakecascade import allocate

cost = np.array([[1.0, 2.0, 9.0],      # site 0 -> demand points
                 [5.0, 1.0, 1.0]])     # site 1
capacity = allocate.capacity_from_area([52.5, 105.0], m2_per_person=3.5)  # [15, 30]
res = allocate.capacity_balance([10, 20, 30], capacity, cost)
print(res.sites[["nearest_demand", "overload_ratio", "served"]].round(2))
print(res.summary["unserved"])         # 15.0

trap = np.abs(np.subtract.outer([0.0, 10.0, 20.0], [0.0, 10.0, 20.0]))
pm = allocate.p_median(trap, [5, 4, 5], p=2)
print(sorted(pm["selected"]), pm["greedy_objective"], pm["objective"])  # [0, 2] 50.0 40.0

Provenance

coverage_weights, greedy_max_coverage, p_median, assign_to_nearest, exact_location_audit, capacitated_assign and capacitated_siting are ported from the PlanX engine (engine/optimize.py, same author); changes: the unreachable penalty is a required argument, unreachable costs are inf instead of -1.0, NaN costs are rejected (by every function here, including capacity_balance: give a demand point whose costs are unknown NaN demand). capacity_from_area and capacity_balance re-implement the method of the DİRİ evacuation and logistics engines (nearest-site load, overload ratio, spill to sites with room), with the area per person and the walking radius as caller inputs.

References

  • Church, R., & ReVelle, C. (1974). The maximal covering location problem. Papers of the Regional Science Association 32, 101–118. doi:10.1007/BF01942293
  • Hakimi, S. L. (1964). Optimum locations of switching centers and the absolute centers and medians of a graph. Operations Research 12(3), 450–459. doi:10.1287/opre.12.3.450
  • ReVelle, C. S., & Swain, R. W. (1970). Central facilities location. Geographical Analysis 2(1), 30–42. doi:10.1111/j.1538-4632.1970.tb00142.x
  • Sphere Association (2018). The Sphere Handbook: Humanitarian Charter and Minimum Standards in Humanitarian Response, 4th ed. Geneva. doi:10.3362/9781908176707
  • Teitz, M. B., & Bart, P. (1968). Heuristic methods for estimating the generalized vertex median of a weighted graph. Operations Research 16(5), 955–961. doi:10.1287/opre.16.5.955