An intelligent traffic management system that dynamically adjusts highway lane configurations using AI-powered congestion detection and a movable median barrier. This project addresses the Engineering Grand Challenge of urban infrastructure optimization and traffic congestion mitigation.
Real-time traffic simulation in CARLA showing the dynamic median traffic management system
Traditional highway infrastructure suffers from directional traffic imbalances—morning rush hours congest one direction while the opposite remains empty, and vice versa in the evening. This system solves that problem by:
- Intelligent Congestion Detection: Monitors vehicle speeds and counts in real-time
- Adaptive Lane Allocation: Shifts median barrier to create 4 lanes in congested direction
- Computer Vision: YOLOv8-based vehicle detection and tracking
- BPR Function Analysis: Bureau of Public Roads trip time calculations
- Real-time Dashboard: Web-based monitoring and control interface
- Simulates 6-lane highways (3 lanes each direction)
- Handles 100+ vehicles simultaneously
- Dynamic median movement with collision avoidance
- Traffic flow metrics and performance analysis
- Export data to JSON/CSV for further analysis
Python 3.8+
CARLA Simulator 0.9.15
carla==0.9.15
pygame==2.5.2
flask==3.0.0
numpy (optional, for advanced analysis)
Download CARLA 0.9.15 from official website
# Extract CARLA
# Windows: Extract to C:\CARLA
# Linux: Extract to ~/CARLAgit clone https://github.com/hitX/dynamic-median-traffic.git
cd dynamic-median-traffic# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
# Install dependencies
pip install carla==0.9.15 pygame==2.5.2 flask==3.0.0# Windows
cd C:\CARLA
.\CarlaUE4.exe
# Linux
cd ~/CARLA
./CarlaUE4.sh# In project directory
python test_carla.py# In a separate terminal
python dashboard_server.pyThen open http://localhost:5000 in your browser.
The simulation runs automatically and will:
- Spawn 100+ vehicles on a 6-lane highway
- Monitor traffic conditions in real-time
- Detect congestion (>15 slow vehicles)
- Shift median to create 4-2 lane configuration
- Return to 3-3 when congestion clears
- Shift Median: Manually trigger lane configuration changes
- Spawn Vehicles: Add more traffic to test scenarios
- Speed Control: Adjust traffic flow speed
- Weather: Change environmental conditions
- Create Congestion: Simulate rush hour traffic
Ctrl+C: Stop simulation and save metricsESC: Emergency stop
The system calculates and tracks:
Uses BPR (Bureau of Public Roads) function:
T = T₀ × [1 + 0.15 × (V/C)⁴]
Where:
- T₀ = Free-flow time (10-60 minutes, random)
- V = Traffic volume (220-250 vehicles/hour)
- C = Capacity (200 baseline, 267 improved)
median_3d/
│
├── test_carla.py # Main simulation script
├── dashboard_server.py # Web dashboard backend
├── templates/
│ └── metrics_dashboard.html # Dashboard UI
│
├── ANALYSIS.md # Performance analysis
├── METHODS.md # Methodology documentation
├── METRICS_EQUATIONS.md # Formula reference
├── QUICK_START.md # User guide
│
├── simulation_results.json # Historical test data
└── simulation_state.json # Real-time state
The Bureau of Public Roads function calculates trip time based on traffic volume and capacity:
Baseline (3-3 lanes):
- Capacity: 200 veh/h per direction
Improved (4-2 lanes):
- Capacity: 267 veh/h (forward)
Detailed documentation available:
- ANALYSIS.md - Complete performance analysis with graphs and tables
- METHODS.md - Materials, construction, and test methodology
- METRICS_EQUATIONS.md - All formulas and calculations
- QUICK_START.md - Step-by-step user guide