# Deep Q-Learning Agent for Traffic Signal Control in SUMO

> Andrea Vidali’s training pipeline lets you inspect how a PyTorch agent controls one SUMO junction and compare its behavior across simulated traffic conditions.

**AndreaVidali/Deep-QLearning-Agent-for-Traffic-Signal-Control** — A framework where a deep Q-Learning Reinforcement Learning agent tries to choose the correct traffic light phase at an intersection to maximize traffic efficiency.

- Repository: https://github.com/AndreaVidali/Deep-QLearning-Agent-for-Traffic-Signal-Control
- Stars: 508 · Forks: 157
- Language: Python
- License: MIT
- Published: 2026-11-30 · Updated: 2026-11-30 · Language: en
- Canonical page: https://hysenlabs.com/projects/andreavidali-deep-qlearning-agent-for-traffic-signal-control

## One junction as a controlled experiment

Andrea Vidali’s Deep Q-Learning Agent for Traffic Signal Control puts a PyTorch policy in charge of one simulated junction. The bundled SUMO network sets the geometry and the available movements. That makes the repository practical for a reinforcement learning exercise where the learner needs to trace how a decision affects a queue. A junction model with linked signals or a different set of permitted movements would require changes to the environment. Start with the supplied network so that geometry stays fixed while you change the traffic demand or the learning settings. This also makes it easier to identify which changes came from the experiment design.

## What the policy sees when a lane fills

The environment encodes the approaching lanes as 80 binary occupancy cells. Two traffic situations can look identical to the policy if their vehicles occupy the same cells. This representation is easy to inspect in the environment code and gives the network a fixed input size. The action is an index into four traffic signal choices. When the selected green differs from the current one, the SUMO wrapper applies the outgoing yellow phase before switching to the next green. The green and yellow durations come from the settings. Treat those durations as part of the experimental setup because they determine when the controller can act again and how much simulated time elapses during a switch.

## Exploration and demand change on different schedules

The training session sets epsilon at the beginning of each episode. The policy uses this setting to balance exploration and greedy action selection. Experience replay supplies the network with stored transitions, and the training YAML controls how much experience the buffer can hold and when it has enough samples to train. The training session also uses the episode number as the route-generation seed. For a comparison between two training configurations, retain a copy of each YAML file and check the demand settings first. A different number of cars or turn probability changes the problem seen by the agent, even when both runs use the same SUMO network and share the same episode count.

## Train a checkpoint and open a named test

The repository uses the MIT license. Its Python package declares Python 3.13, and the README requires SUMO and the SUMO_HOME environment variable. Clone the repository and open a shell in its root. After installing SUMO and uv, the README’s CLI commands can be run in the uv environment. The help command is a useful first check that the package entry point resolves. Use a fresh output directory name when repeating the exercise because the CLI checks for an existing directory before writing.

```bash
uv sync
uv run tlcs --help
uv run tlcs train --out-path model/run-01
uv run tlcs test --model-path model/run-01 --test-name sample
```

The test command reads the saved training settings for the model and takes simulation settings from the test YAML. It writes the named test directory directly under the model directory, so this example places it at model/run-01/sample. The test uses epsilon zero and a route-generation seed set by episode_seed in the test settings.

## Read the reward trace beside the queue trace

The training output contains a PyTorch model, a copy of the training configuration, plots and text series. In the training loop, the reward series sums the negative reward records in each episode. The test loop writes the sequence of rewards recorded during its episode. The two series therefore have different units of observation. A training point summarizes an episode, while a test point describes a recorded decision within one episode. Read the delay and queue series alongside reward when examining a change to green duration. A shorter queue at one stage of an episode can coexist with a later build-up, and an episode-level training reward alone gives little information about the time at which the queue accumulated.

## Use a fixed signal plan as a comparison

The bundled assets and outputs are useful for comparing settings in the same simulated network. A larger claim about traffic efficiency would call for a baseline such as a fixed signal plan run against the same route seeds. Keep the traffic settings and episode horizon aligned so that the two controllers face equivalent traffic and the same time window. The repository’s last recorded push was on 2026-05-24, and the project record lists no tagged GitHub releases. Pin the repository commit for a reproducible exercise, since the README also points to a pre-refactor version with a different layout. The relevant primary references are the [repository and README](https://github.com/AndreaVidali/Deep-QLearning-Agent-for-Traffic-Signal-Control), the source under src/tlcs, and [SUMO installation documentation](https://sumo.dlr.de/docs/Installing/).

## Conclusion

Use the project to study a simulated intersection and evaluate saved checkpoints under defined demand. Verify SUMO setup and choose matching route seeds before comparing policies.

## FAQ

### Does Deep Q-Learning Agent for Traffic Signal Control need a GPU?

The README describes a CPU default, with a GPU optional.

### What Python version does Deep Q-Learning Agent for Traffic Signal Control require?

The package declares Python 3.13.

### Can Deep Q-Learning Agent for Traffic Signal Control replay the same test demand?

Its test configuration sets a route-generation seed through episode_seed.

## Sources

- [AndreaVidali/Deep-QLearning-Agent-for-Traffic-Signal-Control on GitHub](https://github.com/AndreaVidali/Deep-QLearning-Agent-for-Traffic-Signal-Control)
- [Issues](https://github.com/AndreaVidali/Deep-QLearning-Agent-for-Traffic-Signal-Control/issues)
- [License: MIT](https://github.com/AndreaVidali/Deep-QLearning-Agent-for-Traffic-Signal-Control/blob/master/LICENSE)
- [README](https://github.com/AndreaVidali/Deep-QLearning-Agent-for-Traffic-Signal-Control/blob/master/README.md)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/andreavidali-deep-qlearning-agent-for-traffic-signal-control
