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!
Optional. Stays on this device only โ not sent to WhizzStep.
๐ฆ WhizzStep AI Lab
Activity completion card for
Student Name
has built an Adaptive Traffic Light AI using RL
This records completion of a browser activity only. It is not an accredited certificate or proof of mastery.
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.
About this lab
AI-16How AI and Machine Learning WorkClasses 7-915 minFoundation
Learning objective: Adjust a simplified traffic-signal controller and see how it responds to changing traffic conditions.
What this simplifies: A small simulated intersection is used; real traffic-control systems integrate many more sensors and constraints.
Privacy: No learner input leaves the device.
Teacher prompt: Ask the class why this simulation might mislead someone who takes it too literally.
Reflect: What is one thing this activity showed you that you did not expect?