Here’s a explanation of a disaster evacuation and resource allocation optimization problem using Python.
This example is designed to run in Google Colaboratory.
🆘 Optimizing Evacuation Routes and Resource Allocation During Disasters with Python
In the face of natural disasters like earthquakes or floods, efficient evacuation and proper distribution of limited emergency resources are critical to saving lives.
In this blog post, we’ll walk through a practical example where we optimize:
- Evacuation routes to shelters
- Distribution of limited supplies (like food, water, and medicine)
We’ll solve this as a Linear Programming (LP) problem using Python’s PuLP library and visualize the results with matplotlib and networkx.
🧠 The Problem: Evacuation and Supply Allocation
Let’s consider a simplified city model with:
- 3 danger zones (where people need evacuation)
- 2 shelters (safe zones)
- Limited roads connecting them
- Each shelter has a capacity
- A limited number of supplies that must be distributed optimally based on the number of evacuees
We’ll optimize for:
- Minimum total travel distance
- Feasible distribution of evacuees and resources
🧮 Mathematical Formulation
Let:
- $( D = {d_1, d_2, d_3} )$ be danger zones
- $( S = {s_1, s_2} )$ be shelters
- $( x_{ij} )$: number of people evacuated from danger zone $( d_i )$ to shelter $( s_j )$
- $( c_{ij} )$: cost (distance) from $( d_i )$ to $( s_j )$
Objective:
Minimize total cost:
$$
\min \sum_{i \in D} \sum_{j \in S} c_{ij} \cdot x_{ij}
$$
Subject to:
All people in each danger zone must be evacuated:
$$
\sum_{j \in S} x_{ij} = p_i \quad \forall i \in D
$$Shelter capacity must not be exceeded:
$$
\sum_{i \in D} x_{ij} \leq C_j \quad \forall j \in S
$$
Where $( p_i )$ is the population in $( d_i )$ and $( C_j )$ is the capacity of $( s_j )$.
🧪 Let’s Code!
✅ Install PuLP
1 | !pip install pulp |
🧮 Python Code (Evacuation Optimization)
1 | import pulp |
📊 Visualization
1 | # Create graph for visualization |
🔍 Results and Analysis
Evacuate from D1 to S1: 100.0 people Evacuate from D1 to S2: 0.0 people Evacuate from D2 to S1: 0.0 people Evacuate from D2 to S2: 150.0 people Evacuate from D3 to S1: 80.0 people Evacuate from D3 to S2: 0.0 people Total evacuation cost: 4100.0

The solver calculates the optimal evacuation plan minimizing total travel distance while respecting shelter capacities.
The graph clearly shows:
- Which danger zones send evacuees to which shelters
- The number of evacuees per route
- How capacity constraints affect distribution
For example, if S1 is closer to D1 and D3, but its capacity is limited, the algorithm automatically diverts D2‘s population to S2 even if it’s farther, because that’s the optimal feasible plan.
🧯 Next Steps
- Add resource distribution (food, medicine) using multi-objective optimization
- Consider road congestion as dynamic costs
- Extend to real geospatial data using libraries like
geopandas
This example is just the tip of the iceberg.
Python and linear programming give us powerful tools to make life-saving decisions smarter and faster.












