A real-time Emergency Room simulation built using Python and Pygame. This project models a multi-server priority queueing system using discrete-event simulation principles.
The system simulates stochastic patient arrivals, severity-based prioritization, doctor assignment, and treatment completion in a dynamic graphical environment.
- Real-time discrete-event simulation
- Multi-doctor (multi-server) system
- Severity-based priority queue (Critical > Moderate > Minor)
- Heap-based scheduling using
heapq - Adjustable number of doctors
- Adjustable patient arrival probability
- Custom simulation duration (in minutes)
- Start / Pause / Resume / Restart controls
- Scrollable hospital layout
- Live statistics panel (time, queue size, treated count)
| Severity | Priority | Service Time (seconds) |
|---|---|---|
| Critical | 1 | 20 – 30 |
| Moderate | 2 | 10 – 20 |
| Minor | 3 | 5 – 10 |
Lower numerical priority means higher urgency.
The system follows a non-preemptive priority queue discipline.
Each simulation step:
- Increments simulation time
- Generates patient arrivals probabilistically
- Updates service time for busy doctors
- Releases doctors when treatment completes
- Assigns highest-priority waiting patient
- Updates waiting time of queued patients
The simulation ends when the defined duration is reached.
The simulation tracks:
- Total patients treated
- Queue length
- Simulation time
- Throughput
- Doctor utilization
- Average waiting time
These metrics allow analysis of congestion and system stability.
Hospital-Simulation/
│
├── config.py
├── entities.py
├── simulation.py
├── ui.py
├── main.py
├── Assets/
- Python 3.x
- Pygame
pip install pygame
python main.py
Arrival Rate:
λ = p
Service Rate:
μ = 1 / Avg(Service Time)
Utilization:
ρ = λ / (cμ)
Where:
c= number of doctors- Stability condition: ρ < 1
If ρ ≥ 1, the queue grows without bound.
- Discrete Event Simulation
- Priority Queues
- Multi-Server Queueing Systems
- Stochastic Modeling
- Event-Driven Programming
- Real-Time GUI Rendering
This project serves as a dynamic experimental tool for analyzing emergency department congestion, resource allocation, and system stability under uncertainty.