Skip to content
Β 
Β 

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Smart Traffic Lights System (SmartTLS)

Our Team

TomΓ‘s Santos
TomΓ‘s Santos
Pedro Pinto
Pedro Pinto
Danilo Silva
Danilo Silva
JoΓ£o Pinto
JoΓ£o Pinto
Guilherme Santos
Guilherme Santos

Project Abstract

The Smart Traffic Light System (SmartTLS) was developed as part of the Aveiro Tech City Hackathon 2024 to address urban traffic challenges using cutting-edge Artificial Intelligence (AI). This project focuses on optimizing traffic flow at signalized intersections in the city center of Aveiro by leveraging the existing infrastructure of the Aveiro Tech City Living Lab, including smart lamp posts and sensors.

The solution integrates Multi-Agent Reinforcement Learning (MARL) to dynamically adapt traffic light behavior based on real-time data from radars and cameras. Each traffic light acts as an autonomous agent, cooperating with neighboring lights to prioritize public transportation, reduce waiting times for all vehicles, and minimize COβ‚‚ emissions. The system also supports scalability, allowing seamless integration of additional intersections and sensors without modifying the core algorithm.

Key features of the project include:

  • Optimization Goals: Reduction of COβ‚‚ emissions, improved punctuality of public transport, and minimized delays for general traffic.
  • Real-Time Adaptation: Dynamic decision-making based on live traffic data, including vehicle counts, wait times, and speeds.
  • Comparison and Validation: Evaluated against traditional fixed-timing systems and advanced gap-based models, the SmartTLS consistently demonstrated superior performance in reducing emissions and wait times.

This innovative approach represents a sustainable and efficient solution for urban traffic management, aligning with the goals of smart city development and enhancing the quality of urban living.

For more details, please refer to the project documentation files: Proposed Challenge, Project Presentation, Executive Summary, and Technical Report.


How to Use

1. Setup

1.1 Create a Python Virtual Environment

python3 -m venv env

1.2 Activate the Virtual Environment

source env/bin/activate

1.3 Install Required Packages

pip install -r requirements.txt

2. Model Training and Testing

2.1 Train the Model

python3 train.py --save_model="data/<trained_model>" --simulation="cross/cross" --num_timesteps=100000

2.2 Test the Model

python3 test.py --load_model="data/<trained_model>" --simulation="cross/cross" --traffic_scale=1

2.3 Example Commands

python3 train.py --save_model="data/trained_model_ppo_aveiro_traffic" --simulation="aveiro_traffic/osm" --timesteps=200000
python3 test.py --load_model="data/trained_model_ppo_aveiro_traffic" --simulation="aveiro_traffic/osm" --traffic_scale=1

3. Visualization

3.1 Show TensorBoard

python3 -m tensorboard.main --logdir="./data/logs/"

3.2 Statistics Visualization

python3 $SUMO_HOME/tools/visualization/plotXMLAttributes.py teste.xml teste2.xml -x maxJamLengthInMeters -y @COUNT -i @NONE --legend --barplot --xbin 1 --xclamp :3000

4. Data Download

4.1 Download from osmWebWizard

Select the area in the opened website page and download the files:

python3 $SUMO_HOME/tools/osmWebWizard.py

5. Simulation Setup

5.1 Create a Simulation

  1. Copy files to sumo_config/<simulation_name>.
  2. Add osm.det.xml in the created folder:
    • In this file, you can add the detectors with the corresponding lanes (see in netedit).
  3. Change the traffic light id in netedit in the file osm.net.xml.gz to TLS.
  4. Start a test with the corresponding simulation parameters.

5.2 Run the Simulation (When No Simulation is Running)

Arguments:

  • data/trained_model_ppo_aveiro_traffic_1M_new - The trained model.
  • 2.75 - The traffic scale.
./stats.sh data/trained_model_ppo_aveiro_traffic_1M_new 2.75 

6. Simulation Data Generation (Without Shell)

6.1 Smart Traffic Light Model (Our Model)

Change data/emissions.xml to data/emissions-smart.xml and data/waitingTime.xml to data/waitingTime-smart.xml.

python3 test.py --load_model="data/trained_model_ppo_aveiro_traffic_1M_new" --simulation="aveiro_traffic/osm" --traffic_scale=2.75

6.2 Normal Traffic Light Model (No Model Used In Aveiro Yet)

Change data/emissions.xml to data/emissions-normal.xml and data/waitingTime.xml to data/waitingTime-normal.xml.

sumo -c sumo_config/aveiro_traffic/osm.sumocfg --tripinfo-output.write-unfinished="true" --duration-log.statistics="true" --device.emissions.probability="0.10" --no-step-log="true" --no-warnings="true" --end="2250" --scale="2.75" --start="true"

6.3 Actuated Traffic Light Model (Model Implemtented In Germany, "Gap-Based")

Change data/emissions.xml to data/emissions-actuated.xml and data/waitingTime.xml to data/waitingTime-actuated.xml.

sumo -c sumo_config/aveiro_traffic/osm.actuated.sumocfg --tripinfo-output.write-unfinished="true" --duration-log.statistics="true" --device.emissions.probability="0.10" --no-step-log="true" --no-warnings="true" --end="2250" --scale="2.75" --start="true"

6.4 Generate Graphs

python3 $SUMO_HOME/tools/visualization/plotXMLAttributes.py -x begin -y CO2_abs -i @NONE data/emissions-smart.xml data/emissions-normal.xml data/emissions-actuated.xml --ylabel="CO2 mg/m" --title="CO2 Emission in Traffic Lights" --legend --barplot --xbin=60
python3 $SUMO_HOME/tools/visualization/plotXMLAttributes.py -x begin -y waitingTime -i @NONE data/waitingTime-smart.xml data/waitingTime-normal.xml data/waitingTime-actuated.xml --ylabel="Time s/m" --title="Waiting Time in Traffic Lights" --legend --barplot --xbin=60

Add a Simulation

1. Create the Simulation

Use the following command to create a simulation using the osmWebWizard:

python3 $SUMO_HOME/tools/osmWebWizard.py

2. Select the Desired City

  • In the web interface, choose the region of interest by selecting the desired city or area for the simulation.

3. Modify Traffic Lights

  1. Open the file osm.net.xml.gz in NetEdit.
  2. Change the traffic light ID for each intersection to a sequential naming format:
    • TLS1, TLS2, ..., TLSn.

4. Add Detectors to the Simulation

  1. Add detectors to the simulation by creating an osm.det.xml file in the same folder where the simulation files are located.

    • This file should define detectors and associate them with the corresponding lanes. You can look on /sumo_config/aveiro_traffic/osm.det.xml
  2. Connect the detectors to the simulation configuration file osm.sumocfg.

    • This ensures the detectors are recognized and functional within the simulation.

5. Test the Simulation

Once the setup is complete, run the simulation using sumo-gui to visually verify the traffic flow and detector operations:

sumo-gui -c sumo_config/<simulation_name>/osm.sumocfg 

About

πŸ† Winning solution for the Aveiro Tech City Hackathon 2024 - 5000€ πŸ† | Multi-Agent Reinforcement Learning for Traffic Lights in Aveiro

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages