Skip to main content

Emergency Response Simulation

Installing

pip install emergency_simulation

Introduction

Emergency Response Simulation is a package that helps anyone to create a simulation where you can create a city as a Graph of neighborhoods with the networkx library, and simulate emergency responses in it. The idea is to easily allow anyone to explore what is the best configuration for ambulance allocations in a given city.

Creating a simulation. Getting started with Sample Code.

Part 1. Creating a Graph with networkx

# importing packages
from emergency_simulation import *
import scipy.stats as sts
import networkx as nx

## Creating Graph
G = nx.Graph()

# creating neighborhoods with their emergency rate
G.add_node("Civic Center", emergency_distribution = sts.expon(scale=29))
G.add_node("Nob Hill", emergency_distribution = sts.expon(scale=35))
G.add_node("Downtown", emergency_distribution = sts.expon(scale=30))
G.add_node("Tenderloin", emergency_distribution = sts.expon(scale=36))
G.add_node("South of Market", emergency_distribution = sts.expon(scale=30))
G.add_node("Financial District", emergency_distribution = sts.expon(scale=20))
G.add_node("Yerba Buena", emergency_distribution = sts.expon(scale=29))
G.add_node("South Beach", emergency_distribution = sts.expon(scale=25))
G.add_node("Mission Bay", emergency_distribution = sts.expon(scale=30))
G.add_node("Potrero Hill", emergency_distribution = sts.expon(scale=33))
G.add_node("Inner Mission", emergency_distribution = sts.expon(scale=38))
G.add_node("Dogpatch", emergency_distribution = sts.expon(scale=32))


# creating edges with weight representing the distance in minutes between 2 neighborhoods
G.add_edge("Civic Center", "Nob Hill", weight=5)
G.add_edge("Civic Center", "Downtown", weight=5)
G.add_edge("Civic Center", "Tenderloin", weight=3)
G.add_edge("Civic Center", "South of Market", weight=5)

G.add_edge("Nob Hill", "Downtown", weight=5)
G.add_edge("Nob Hill", "Financial District", weight=4)

G.add_edge("Downtown", "Financial District", weight=7)
G.add_edge("Downtown", "Yerba Buena", weight=4)
G.add_edge("Downtown", "Tenderloin", weight=4)

G.add_edge("Financial District", "Yerba Buena", weight=5)
G.add_edge("Financial District", "South Beach", weight=5)

G.add_edge("Yerba Buena", "South of Market", weight=2)
G.add_edge("Yerba Buena", "South Beach", weight=3)

G.add_edge("South of Market", "Mission Bay", weight=5)
G.add_edge("South of Market", "Potrero Hill", weight=5)
G.add_edge("South of Market", "Inner Mission", weight=6)
G.add_edge("South of Market", "Tenderloin", weight=5)

G.add_edge("Mission Bay", "South Beach", weight=5)
G.add_edge("Mission Bay", "Dogpatch", weight=5)
G.add_edge("Mission Bay", "Potrero Hill", weight=5)

G.add_edge("Dogpatch", "Potrero Hill", weight=4)

G.add_edge("Potrero Hill", "Inner Mission", weight=5)

Part 2. Running the simulation

## Running the simulation with a single configuration

# neighborhoods that have ambulance stations
neighborhoods = ["Downtown", "Potrero Hill", "South Beach"]
# total ambulances available to be used
total_ambulances = 13
# ambulance stations per neighborhood
neighborhood_ambulance_allocations = neighborhood_ambulance_combinations(neighborhoods, total_ambulances)
# random value to account for ambulance time to get to the exact location and assist the person
location_and_assitance_distribution = sts.norm(loc=15, scale=5)

# running the simulation for the first "neighborhood_ambulance_allocations" and for 20 steps
simulation = run_simulation(G, neighborhood_ambulance_allocations[0], location_and_assitance_distribution, 20, log=True)

Part 3. Exploring statistics/metrics

# getting simulation statistics
wait_time = simulation.emergency_queue.wait_time_per_emergency
ambulance_stations = simulation.ambulance_stations

print("======================== RESULTS ========================")
print("Average Wait Time:", np.mean(wait_time))
print("Average Number of Ambulances left idle throughout the simulation")
for station in ambulance_stations:
    print("___________")
    mean_available_ambulances = np.mean(station.available_ambulances_evolution)
    print(station.neighborhood)
    print("Average Number of Ambulances left idle")
    print(mean_available_ambulances)
    print("Ambulance Evolution")
    print(station.available_ambulances_evolution)

Metadata

Release files for emergency_simulation 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for emergency_simulation 1.0.0
File Size Uploaded
emergency_simulation-1.0.0.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for emergency_simulation 1.0.0
File Interpreter ABI Platform
emergency_simulation-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / emergency_simulation-1.0.0.tar.gz

Download URL emergency_simulation-1.0.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a676cee5dc50c4a09aaa7a134a6dba4a5ee0dd98f2e8fb0fe4d4b5c2ab7cf59a
BLAKE2b-256 checksum
How to use checksums
c7fef27cc904f5fa9d7c7271a444adda83ea907c0f8e8ec918c3373d0f63ea7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / emergency_simulation-1.0.0-py3-none-any.whl

Download URL emergency_simulation-1.0.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f497ab43c69de100a9e9bd096437341010ac6655db97f8399264e80942178ce
BLAKE2b-256 checksum
How to use checksums
e8200d91077756740d61e3ffb89a08261cc95e4c8b5478a5cf8cb28675545baf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page