An intelligent traffic management system that uses reinforcement learning to optimize traffic light timing based on real-time traffic conditions. The system integrates with the TomTom API to fetch live traffic data and simulates vehicle movement through a city's road network.
- Enhanced Simulation: Improved vehicle movement and traffic signal control
- Robust Error Handling: Added comprehensive error handling and logging
- Compatibility Fixes: Resolved OSMnx version compatibility issues
- Performance Optimizations: Improved simulation performance and stability
- Detailed Logging: Added timestamped logging for better debugging
- Real-time Traffic Monitoring: Displays live traffic data through a city's road network
- AI-Powered Traffic Signals: Uses Q-learning to optimize traffic light timing
- Interactive Dashboard: Streamlit-based web interface for monitoring and control
- Detailed Simulation: Realistic vehicle movement and traffic flow modeling
- Comprehensive Logging: Timestamped logs for debugging and analysis
- Error Resilience: Robust error handling and recovery mechanisms
- Modular Architecture: Easy to extend and customize
- Python 3.8 or higher
- Internet connection (for fetching real-time traffic data)
- TomTom API Key (free tier available)
- Git (for version control)
-
Clone the repository:
git clone https://github.com/06navdeep06/realtime-traffic-sensor.git cd realtime-traffic-sensor
-
Create and activate a virtual environment (recommended):
# On Windows python -m venv venv .\venv\Scripts\activate # On macOS/Linux python3 -m venv venv source venv/bin/activate
-
Install the required packages:
pip install -r requirements.txt
For development, also install:
pip install -r requirements-dev.txt
-
Install pre-commit hooks for code quality:
pre-commit install
-
Run tests:
python -m pytest tests/
-
Run the debug script to test the simulation:
python debug_simulation.py
-
Copy the example environment file and update with your API key:
copy .env.example .env
-
Edit the
.env
file and add your TomTom API key:TOMTOM_API_KEY=your_api_key_here DEBUG=False
Note: Make sure to add
.env
to your.gitignore
to keep your API key secure.
-
Start the Streamlit dashboard:
streamlit run dashboard.py
-
Open your browser and navigate to the URL shown in the terminal (usually http://localhost:8501)
-
In the sidebar:
- Specify the city to monitor (e.g., "Patan, Nepal")
- Adjust the number of vehicles to display (10-500)
- Click "Start Real-time Traffic Monitoring"
-
For a quick test of the simulation:
python simple_simulation_test.py
-
For detailed debugging:
python debug_simulation.py
This will generate a timestamped log file with detailed simulation information.
dashboard.py
: Streamlit web interface for the traffic simulationsimulation.py
: Core simulation logic and vehicle managementtraffic_signal.py
: Traffic signal controller with Q-learning agentrl_agent.py
: Implementation of the Q-learning algorithmroad_network.py
: Handles road network data and real-time traffic updatesvisualization.py
: Visualization utilities for the road network and trafficdebug_simulation.py
: Debugging tool for the simulation enginesimple_simulation_test.py
: Basic test script for the simulationtest_*.py
: Unit tests for various components
The system provides real-time traffic monitoring and analysis:
- Road Network Modeling: Uses OSMnx to fetch and model real-world road networks
- Real-time Data Processing: Continuously fetches and processes live traffic data
- Traffic Analysis: Uses machine learning to analyze traffic patterns and congestion
- Interactive Visualization: Provides real-time visualization of traffic flow and conditions
The dashboard displays several key metrics:
- Simulation step count
- Number of active vehicles
- Average trip time (in simulation steps)
- Current state of each traffic signal
This project is licensed under the MIT License - see the LICENSE file for details.
- TomTom for their excellent mapping and traffic APIs
- OSMnx for powerful street network analysis
- Streamlit for the intuitive web interface
- The open-source community for invaluable tools and libraries
For questions or feedback, please contact [email protected]