๐Ÿšฆ Reinforcement Learning ยท Real World

Traffic Light AI

Watch a fixed timer create gridlock, then design the AI's observation space and train it to dramatically cut average waiting times โ€” just like smart city traffic systems!

๐Ÿšฆ Fixed Timer Mode
๐Ÿ“Š Design State Space
๐Ÿง  Train AI
๐Ÿ†š Compare Results
๐Ÿ† Badge

How Traffic AI Works

๐Ÿ“ก

Observe

The AI reads queue lengths, waiting times, and traffic flow rates at each approach to the intersection.

๐ŸŽฏ

Decide

Every few seconds: which direction gets the green light? The AI picks the action that minimises total waiting time.

๐Ÿ“Š

Reward

Reward = negative total waiting time. Lower wait = higher reward. The AI learns to keep queues short.

๐Ÿ™๏ธ

Real World

Google's DeepMind worked with Transport for London to use RL for traffic signals, cutting waiting times by 10โ€“20%.

๐Ÿšฆ
Wizzy the AI Tutor
Watch the fixed timer in action! The light switches every 30 seconds regardless of traffic. See what happens at rush hour โ€” cars pile up on one side while the other road is empty! This is how most traffic lights in the world still work today.

Step 1 โ€” Fixed Timer Mode

N-S: Green
30s
Medium

๐Ÿšฆ Fixed Timer Stats

Time elapsed0s
N-S queue0
E-W queue0
Avg wait time0s
Max queue0
Cars passed0

๐Ÿ“Š Queue Length Over Time

Start the simulation to see traffic flow!
๐Ÿšฆ
Wizzy the AI Tutor
Before training, we need to decide what the AI can observe! This is called the state space design. More information = better decisions, but also a bigger Q-table and slower learning. Pick the features you think matter most and see how they affect performance!

Step 2 โ€” Design the State Space

Select which features the AI can observe (choose 3โ€“5):
๐Ÿ“Š N-S Queue Length

How many cars are waiting on the North-South road (0โ€“10+)

States added: ร—10
๐Ÿ“Š E-W Queue Length

How many cars waiting on the East-West road (0โ€“10+)

States added: ร—10
โฑ๏ธ N-S Max Wait

How long the oldest car on N-S has been waiting

States added: ร—5
โฑ๏ธ E-W Max Wait

How long the oldest car on E-W has been waiting

States added: ร—5
๐Ÿšฆ Current Phase

Which direction currently has green (N-S or E-W)

States added: ร—2
โฐ Time in Phase

How long the current phase has been running (0โ€“60s)

States added: ร—6
Select 3โ€“5 features for best results. More features = more powerful AI but slower to train!
๐Ÿšฆ
Wizzy the AI Tutor
Now train the adaptive AI! ๐Ÿง  It starts with random decisions โ€” sometimes extending a green light when the other road is empty. But as it learns, watch the average wait time drop. The AI discovers that it should extend green when the queue is long and switch when the road is clear!

Step 3 โ€” Train Adaptive Traffic AI

AI decision log will appear here during training...

๐Ÿง  AI Training Stats

Episode0
Avg wait (current)โ€”
Best avg waitโ€”
Fixed timer waitโ€”
Improvementโ€”
Q-states learned0

๐Ÿ“‰ Avg Wait Time Over Episodes

Start training to see the AI learn!
๐Ÿšฆ
Wizzy the AI Tutor
The full comparison! ๐Ÿ†š Fixed timer vs AI-controlled โ€” same traffic, same conditions. The improvement % shows how much the AI reduced average waiting time. Real smart city traffic systems achieve 10โ€“30% improvement. How does yours compare?

Step 4 โ€” Fixed Timer vs AI

โŒ Fixed Timer (30s)

Avg wait timeโ€”
Max queue everโ€”
Cars passed/minโ€”
Fixed lights waste green time on empty roads and create unnecessary queues.

โœ… AI Adaptive

Avg wait timeโ€”
Max queue everโ€”
Cars passed/minโ€”
AI extends green when queues are long and switches quickly when roads are clear.
โ€”
improvement in average wait time
Run the simulations in Phases 1 and 3 to populate this comparison!
๐Ÿšฆ
Wizzy the AI Tutor
๐ŸŽŠ You've built a real adaptive traffic controller! You designed the state space, trained a Q-learning agent, and measured the improvement. Google's DeepMind applied this exact approach to 70 intersections in London, saving fuel and cutting emissions!
๐Ÿšฆ

Smart City AI Badge!

You built and trained an adaptive traffic light AI!

๐Ÿšฆ WhizzStep AI Lab
This certifies that
Student Name
has built an Adaptive Traffic Light AI using RL
Smart City Engineer
State Space Designer
Traffic AI Expert
whizzstep.in

Key Concepts Mastered

State Space Design

๐Ÿ“ก What to Observe

Choosing what the agent observes is as important as the learning algorithm. Too little = can't make good decisions. Too much = Q-table explodes.

Multi-Agent RL

๐Ÿ™๏ธ Multiple Intersections

Real cities have thousands of traffic lights that affect each other. Multi-agent RL coordinates them simultaneously.

Reward Function

๐ŸŽฏ Minimise Wait

We reward the AI with the negative of total waiting time. Minimising waiting = maximising the reward.

Throughput vs Fairness

โš–๏ธ The Trade-off

Maximum throughput might starve one direction. Fairness constraints ensure no car waits more than a maximum time.

DeepMind TfL

๐Ÿ™๏ธ Real Deployment

Google DeepMind applied RL to 70 London intersections, reducing stops by 10โ€“20% and cutting emissions.

Sim-to-Real Gap

๐Ÿ”„ Transfer Learning

Training in simulation doesn't always transfer to real intersections. Real traffic has pedestrians, emergencies, and unpredictable drivers.