Event-driven traffic simulation implementing priority-based vehicle scheduling, dynamic rerouting, and real-time intersection management using custom data structures in C++.
| Name | |
|---|---|
| Zeyad Mohamed Fathy | [email protected] |
| Omar Ahmed Fathy | [email protected] |
| Shaza Kazem Mahmoud | [email protected] |
| Ganna Allah Walid Helmy | [email protected] |
A sophisticated traffic control center simulation that manages multiple intersections, handles dynamic events (accidents, road closures, vehicle arrivals), and prioritizes emergency vehicles while ensuring fairness across all vehicle types. Built entirely from scratch using custom data structuresβno STL containers.
- Priority-Based Scheduling: Emergency vehicles (EV) preempt normal traffic using urgency-weighted priority queues
- Dynamic Event Handling: Real-time processing of arrivals, cancellations, promotions, accidents (ACC), and road closures (RC)
- Adaptive Rerouting: Automatic vehicle rerouting during lane blockages using adjacency-based pathfinding
- Auto-Promotion System: Public transport (PT) automatically promoted to EV status after waiting threshold
- Fair Cancellation: Normal cars (NC) auto-cancel after exceeding wait limits to prevent indefinite blocking
- Multi-Lane Management: Each intersection supports 4 lanes with independent queuing and switching cost optimization
- Comprehensive Statistics: Detailed performance metrics including wait times, completion times, and intersection utilization
TrafficControlCenter (Orchestrator)
βββ Event Queue (Priority Queue)
β βββ Arrival Events
β βββ Cancellation Events
β βββ Promotion Events
β βββ Accident Events
β βββ Road Closure Events
β
βββ Intersections (Array)
β βββ Lanes (Per Intersection)
β βββ EV Queue (Priority Queue)
β βββ PT Queue (FIFO Queue)
β βββ NC Queue (FIFO Queue)
β βββ FV Queue (FIFO Queue)
β
βββ Vehicle Registry (Queue)
βββ All Vehicles
βββ Completed Vehicles
βββ Canceled Vehicles
| Type | Priority | Behavior |
|---|---|---|
| EV (Emergency) | Highest | Can interrupt green signals; Priority = (Urgency Γ 2) - WT |
| PT (Public Transport) | Medium | FIFO within lane; Auto-promotes to EV if WT β₯ AP threshold |
| FV (Freight) | Medium-Low | Locks lane during crossing; Cannot be interrupted |
| NC (Normal Cars) | Lowest | FIFO; Auto-cancels if WT β₯ CancelT threshold |
- Priority Queue: Max-heap implementation for event scheduling and EV prioritization
- Queue: FIFO implementation for PT, NC, FV vehicle management
- Node-based Linked Lists: Memory-efficient pointer sharing (no copying)
- Adjacency Matrix: Intersection connectivity for rerouting pathfinding
Events processed in strict order per timestep:
- Cancellations (highest priority)
- Promotions
- Accidents & Road Closures
- Arrivals (lowest priority)
- Lane assignment and green signal updates
// EV Priority Calculation
priority = (urgency * 2) - waiting_time;
// Lane Selection Logic
for each lane:
if (has_EV):
select_lane_with_highest_EV_priority()
else if (has_PT):
select_lane_with_oldest_PT()
else if (has_FV):
select_lane_with_oldest_FV()
else:
select_lane_with_oldest_NC()| Mode | Description | Use Case |
|---|---|---|
| Interactive | Manual step-through with console output | Debugging, demonstrations |
| Step-by-Step | Auto-advances with delay | Presentations, live monitoring |
| Silent | No console output, file-only | Performance testing, batch processing |
- C++11 or higher
- Any standard C++ compiler (GCC, Clang, MSVC)
# Using g++
g++ -std=c++11 src/*.cpp -o traffic_sim
# Using Visual Studio (already configured via .vcxproj)
# Open in VS and build solution./traffic_simThe program will prompt you to:
- Select simulation mode (1-3)
- Choose input test file (1-6)
- Specify output filename
<num_intersections>
<switching_cost>
<auto_promote_threshold>
<cancel_threshold>
<rerouting_flag: ON/OFF>
Connections:
<intersection_id>: <connected_intersection_ids>
<num_events>
<event_lines>
| Event Type | Format | Example |
|---|---|---|
| Arrival | A TYPE AT ID INT LN XD [PR] |
A EV 3 301 1 2 2 5 |
| Cancellation | X AT ID |
X 6 101 |
| Promotion | P AT ID |
P 5 201 |
| Accident | ACC AT INT LN DUR |
ACC 4 1 1 3 |
| Road Closure | RC AT INT DUR |
RC 8 2 2 |
The system generates comprehensive metrics:
- Vehicle Counts: Total and per-type breakdown (EV, PT, NC, FV)
- Average Wait Times: Overall and per vehicle type
- Average Crossing Duration: System-wide XD analysis
- Auto-Promotion Rate: % of PT vehicles promoted to EV
- Signal Switches: Total lane changes across all intersections
- Cancellation Rate: % of vehicles that timed out
- Most Delayed Vehicle: ID and wait time of longest-waiting vehicle
- Intersection Blockage: % of time each intersection was blocked (ACC/RC)
Six comprehensive test files included:
| Test File | Vehicles | Intersections | Events | Focus Area |
|---|---|---|---|---|
TestFile1.txt |
20-30 | 2-4 | 8-10 | Basic arrivals, promotions |
TestFile2.txt |
40-60 | 4-6 | 15-20 | Cancellations, accidents |
TestFile3.txt |
80-100 | 6-8 | 25-30 | Road closures, rerouting |
TestFile4.txt |
100+ | 8-10 | 35+ | Heavy load, EV priority |
TestFile5.txt |
150+ | 10+ | 50+ | Stress test, edge cases |
TestFile6.txt |
200+ | 12+ | 75+ | Max capacity, all features |
Course: CSAI 201 - Data Structures and Algorithms
Institution: Zewail City University
Semester: Fall 2025
β
Custom data structures (Queue, Priority Queue, Linked Lists)
β
No global variables, no STL, no friendship
β
Pointer-based memory sharing (zero-copy architecture)
β
Object-oriented design with clear separation of concerns
β
Event-driven simulation with discrete timestep advancement
β
Comprehensive statistics and output file generation
β
Multiple simulation modes for different use cases
This project is licensed under the MIT License - see the LICENSE file for details.
This project deliberately avoids STL containers to demonstrate:
- Deep understanding of data structure internals
- Memory management expertise (manual allocation, pointer manipulation)
- Performance optimization (cache locality, minimal allocations)
- Academic integrity (no black-box dependencies)
- Facade Pattern:
TrafficControlCenterabstracts complexity from UI - Strategy Pattern: Different vehicle types implement varying priority logic
- Observer Pattern: Events trigger state changes across intersections
- State Pattern: Vehicle status transitions (WAITING β PASSING β FINISHED)
Note: This is an academic project. The simulation logic is designed for educational purposes and does not reflect real-world traffic control systems.