A comprehensive simulation environment for comparing wired and wireless AI-controlled traffic management systems.
This project investigates whether artificial intelligence can effectively control traffic systems wirelessly compared to traditional wired implementations. Through a Pygame-based simulation, the environment allows AI controllers to manage traffic flow across multiple intersections, with the ability to toggle between wired and wireless communication models for direct performance comparison.
The central research question guiding this project is:
How effective is AI in controlling traffic systems wirelessly compared to traditional wired traffic systems?
- Realistic Traffic Simulation: Multi-lane roads, intersections with traffic lights, and vehicles with realistic movement characteristics
- Advanced Vehicle Behavior: Cars, buses, and trucks with accurate acceleration, deceleration, and lane-changing behaviors
- Configurable Traffic Patterns: Support for various traffic scenarios including rush hour, normal flow, and special events
- Communication Models: Accurate simulation of both wired (fixed latency, high reliability) and wireless (variable latency, interference-prone) communication
- AI Controller: Reinforcement learning-based traffic signal control with network-wide coordination
- Performance Metrics: Comprehensive collection of traffic efficiency, environmental impact, and system reliability metrics
- Visual Analysis: Real-time visualization of traffic flow and performance indicators
The system is divided into several modules, each responsible for different aspects of the simulation:
- SimulationManager: Central coordinator that initializes and orchestrates all subsystems
- SimulationClock: Controls simulation time progression and speed
- RoadNetwork: Represents the physical road infrastructure and connectivity
- Intersection: Manages traffic signals and vehicle interactions at junction points
- Vehicle: Simulates individual vehicles with realistic physics and behavior
- TrafficGenerator: Creates traffic flows based on configurable patterns
- WiredModel: Simulates fixed-latency, high-reliability communication
- WirelessModel: Simulates variable-latency, interference-prone wireless communication
- ActiveChannelManagement: Models wireless interference avoidance techniques
- DeepQNetwork: Reinforcement learning model for signal timing decisions
- WiredAI: Centralized decision-making optimized for reliable communication
- WirelessAI: More distributed decision-making robust to communication issues
- Renderer: Visualizes the simulation environment and traffic elements
- Dashboard: Displays real-time performance metrics and comparative analysis
- Controls: User interaction elements for simulation management
- MetricsCollector: Gathers performance data across multiple dimensions
- ComparativeAnalyzer: Tools for analyzing differences between wired and wireless implementations
- Visualizer: Graphical representation of performance metrics
- Python 3.8 or higher
- Pygame 2.0.0 or higher
- NumPy
- TensorFlow 2.x (for AI controllers)
- Matplotlib (for data visualization)
-
Clone the repository
git clone https://github.com/yourusername/ai-traffic-control.git cd ai-traffic-control -
Create a virtual environment (optional but recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Start the basic simulation
python main.py
-
Keyboard controls
- Space: Pause/Resume simulation
- +/-: Increase/Decrease simulation speed
- W: Toggle between wired and wireless communication
- D: Toggle debug visualization
- R: Reset simulation
- ESC: Exit
The simulation behavior can be customized by modifying parameters in config.py:
- Display Settings: Screen dimensions, colors, and debug mode
- Simulation Parameters: Time scale, pixel-to-meter ratio
- Road Network: Lane width, intersection size, road types
- Vehicle Types: Properties for cars, buses, and trucks
- Traffic Patterns: Vehicle spawn rates for different scenarios
- Communication Models: Latency and reliability parameters
- AI Settings: Learning rates, exploration parameters, neural network architecture
ai_traffic_control/
│
├── main.py # Main entry point for the simulation
├── config.py # Configuration parameters
│
├── simulation/
│ ├── __init__.py
│ ├── manager.py # Simulation Manager
│ └── clock.py # Simulation Clock
│
├── traffic/
│ ├── __init__.py
│ ├── environment.py # Traffic Environment
│ ├── road_network.py # Road Network representation
│ ├── intersection.py # Intersection with traffic lights
│ ├── vehicle.py # Vehicle class and behaviors
│ ├── vehicle_factory.py # Factory for creating vehicles
│ └── traffic_generator.py # Traffic pattern generator
│
├── communication/
│ ├── __init__.py
│ ├── base_model.py # Base communication model
│ ├── wired_model.py # Wired communication implementation
│ └── wireless_model.py # Wireless communication implementation
│
├── ai/
│ ├── __init__.py
│ ├── controller.py # Base AI controller
│ ├── wired_ai.py # Wired AI implementation
│ └── wireless_ai.py # Wireless AI implementation
│
├── ui/
│ ├── __init__.py
│ ├── renderer.py # Main rendering engine
│ ├── dashboard.py # Performance metrics display
│ └── controls.py # User interface controls
│
└── analysis/
├── __init__.py
├── metrics.py # Performance metrics collection
├── data_storage.py # Data storage and retrieval
└── visualizer.py # Data visualization tools
The road network is represented as a collection of interconnected roads and intersections. Each road has bidirectional traffic with multiple lanes, and each intersection manages traffic lights and vehicle movements.
# Create a basic road network with 4 intersections in a grid
road_network = RoadNetwork()
# Add intersections
for i, pos in enumerate(grid_positions):
road_network.add_intersection(i, pos)
# Connect intersections with roads
road_network.add_road(0, 1) # Horizontal connection
road_network.add_road(0, 2) # Vertical connectionVehicles in the simulation exhibit realistic behaviors including acceleration, deceleration, lane following, and traffic signal response. Different vehicle types (cars, buses, trucks) have distinct characteristics affecting their movement.
# Vehicle update logic (simplified)
def update(self, dt):
# Calculate desired speed based on traffic conditions
self._calculate_desired_speed()
# Update speed with realistic acceleration/deceleration
if self.speed < self.desired_speed:
self.speed = min(self.speed + self.acceleration * dt, self.desired_speed)
elif self.speed > self.desired_speed:
self.speed = max(self.speed - self.deceleration * dt, self.desired_speed)
# Update position
self.position += self.speed * dt * self.directionIntersections manage traffic signals with configurable phase timing. In the full implementation, these signals will be controlled by AI systems.
# Traffic light phases for a 4-way intersection
def _create_default_phases(self):
# Phase 1: North-South green
ns_roads = self._get_north_south_roads()
# Phase 2: East-West green
ew_roads = self._get_east_west_roads()
self.phases = [ns_roads, ew_roads]The simulation models both wired and wireless communication systems with different latency and reliability characteristics:
- Wired: Fixed latency (1-5ms), near-perfect reliability (99.9%+)
- Wireless: Variable latency (7-20ms + fluctuations), moderate reliability (95-99%)
The AI controllers use Deep Q-Networks to learn optimal traffic signal timing strategies. Two variants are implemented:
- Wired AI: Centralized decision-making with access to complete network information
- Wireless AI: More distributed decision-making that's robust to communication issues
The system evaluates the performance of both wired and wireless implementations across multiple dimensions:
-
Traffic Efficiency
- Average vehicle delay
- Throughput (vehicles per hour)
- Queue lengths
- System response time
-
Communication System Performance
- Signal latency
- Packet loss rate
- Recovery time
-
Environmental Impact
- Estimated fuel consumption
- CO2 emissions
- Idle time
-
AI Controller Performance
- Learning efficiency
- Decision quality
- Adaptation rate
The project follows a phased development approach:
- Literature review
- System design framework
- Detailed simulation requirements
- Set up Pygame environment and basic traffic simulation ✓
- Develop AI controller system
- Implement wired and wireless communication models
- Fine-tune the AI decision-making algorithms
- Design and implement test scenarios
- Run experiments across various traffic conditions
- Collect and organize performance data
- Refine algorithms based on initial results
- Develop comprehensive project report
- Create professionalism companion report
- Review and finalize all deliverables
Contributions to this project are welcome. Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- The project builds on research in reinforcement learning for traffic signal control
- Pygame community for the graphics and simulation framework
- Traffic engineering principles from established literature
For questions or collaboration inquiries, please contact [your-email@example.com].