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.
python3 -m venv envsource env/bin/activatepip install -r requirements.txtpython3 train.py --save_model="data/<trained_model>" --simulation="cross/cross" --num_timesteps=100000python3 test.py --load_model="data/<trained_model>" --simulation="cross/cross" --traffic_scale=1python3 train.py --save_model="data/trained_model_ppo_aveiro_traffic" --simulation="aveiro_traffic/osm" --timesteps=200000python3 test.py --load_model="data/trained_model_ppo_aveiro_traffic" --simulation="aveiro_traffic/osm" --traffic_scale=1python3 -m tensorboard.main --logdir="./data/logs/"python3 $SUMO_HOME/tools/visualization/plotXMLAttributes.py teste.xml teste2.xml -x maxJamLengthInMeters -y @COUNT -i @NONE --legend --barplot --xbin 1 --xclamp :3000Select the area in the opened website page and download the files:
python3 $SUMO_HOME/tools/osmWebWizard.py- Copy files to
sumo_config/<simulation_name>. - Add
osm.det.xmlin the created folder:- In this file, you can add the detectors with the corresponding lanes (see in
netedit).
- In this file, you can add the detectors with the corresponding lanes (see in
- Change the traffic light id in
neteditin the fileosm.net.xml.gzto TLS. - Start a test with the corresponding simulation parameters.
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 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.75Change 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"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"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=60python3 $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=60Use the following command to create a simulation using the osmWebWizard:
python3 $SUMO_HOME/tools/osmWebWizard.py- In the web interface, choose the region of interest by selecting the desired city or area for the simulation.
- Open the file
osm.net.xml.gzin NetEdit. - Change the traffic light ID for each intersection to a sequential naming format:
- TLS1, TLS2, ..., TLSn.
-
Add detectors to the simulation by creating an
osm.det.xmlfile 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
- This file should define detectors and associate them with the corresponding lanes. You can look on
-
Connect the detectors to the simulation configuration file
osm.sumocfg.- This ensures the detectors are recognized and functional within 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