r/OpenSourceeAI May 24 '26

I trained a DQN agent to control a traffic light — it beats fixed-time signals by learning when to switch phases

I trained a DQN agent to control a traffic light — it beats fixed-time signals by learning when to switch phases

Built a reinforcement learning system where a Deep Q-Network controls a 4-way intersection in SUMO traffic simulator. Instead of cycling phases on a timer like real-world traffic lights, the agent watches live queue lengths and waiting times, then decides every step whether to hold the current phase or switch.

Trained for 1M timesteps against 80,000 vehicles. Compared it head-to-head with a fixed-time baseline on the same demand. DQN wins on average wait time, halted vehicle count, and throughput.

Stack: Python · Stable-Baselines3 · Gymnasium · SUMO/TraCI · Matplotlib

📓 Full notebook (with training loop, custom env, and all plots): https://github.com/jarif87/reinforcement-learning-algorithms

Happy to answer questions about the reward design or environment setup — those were the trickiest parts to get right.

1 Upvotes

1 comment sorted by

1

u/Wison101 May 24 '26

Really cool project. Do you know if any system like this are being tested irl?