Imagine sitting in traffic, watching the light turn red just as you pull up—frustrating, right? As an engineering student fascinated by how cities work, I wanted to tackle this everyday problem using Monte Carlo simulation, a cool statistical method that uses random sampling to predict uncertain outcomes. In this experiment, I simulated traffic at a single intersection to find the best light timing that reduces wait times and keeps cars moving smoothly.
By modeling random car arrivals (like how traffic ebbs and flows unpredictably), I tested different light cycles over a one-hour period. This isn't just theory—it's a practical way to make roads more efficient, cutting down on wasted time and fuel. Drawing from basic queue theory and real traffic data, my goal was to see if computer simulations could beat traditional fixed timings, and the results were eye-opening!
I built the simulation in Google Colab using Python—it's free and easy to share. The setup mimics a four-way intersection with east-west (EW) and north-south (NS) directions. Cars arrive randomly following a Poisson process (think of it as bursts of traffic with quiet spells), at rates of 0.8 cars per minute EW and 0.6 NS—realistic for a suburban spot.
The key was a TrafficLightSimulator class that cycles through green (cars go) and yellow (caution) phases for each direction. I tested four simple scenarios, changing how long each side gets green:
Short Cycle: 30s EW green, 25s NS green (total 61s cycle)
Medium Cycle: 45s EW green, 40s NS green (total 93s)
Long Cycle: 60s EW green, 55s NS green (total 125s)
Rush Hour Setup: 70s EW green, 30s NS green (total 110s, favoring busier EW)
For reliability, I ran each scenario 100 times (Monte Carlo magic!), tracking metrics like average wait time, queue length, cars processed per hour (throughput), and an efficiency score (throughput divided by wait time). I also compared results to Webster's formula, a classic equation for ideal cycle time:
(where 8s is "lost time" for changes, and 0.047 is the traffic flow ratio). Plus, I analyzed car arrival patterns over 10,000 quick simulations to spot probabilities like "how often does traffic spike?"
This hands-on approach let me experiment with randomness in a controlled way, much like testing city plans on a computer before real-world trials.
The simulations painted a clear picture: shorter cycles win for everyday traffic! The Short Cycle topped the charts with an efficiency score of 9.183, meaning more cars moved with less waiting (just 9.2 seconds on average). Longer cycles built up bigger queues, even if they seemed logical for "clearing" traffic.
Webster’s Formula:
Theoretical optimal cycle time: 17.8 seconds
Theoretical green (EW): 5.6 seconds
Theoretical green (NS): 4.2 seconds
Critical flow ratio: 0.047
These theoretical values favor shorter cycles under moderate flows, consistent with the simulation’s preference for the Short Cycle configuration.
Average vehicles per minute: 0.69
Standard deviation: 0.83
Probability of high traffic (> ~1.5 vehicles/min): 0.150
Probability of zero arrivals per minute: 0.506
This variability explains why shorter cycles reduce excessive waiting during random lulls and spikes.
Shorter cycles are advantageous under moderate, variable traffic—reducing average waits and preventing long queues.
Longer cycles may feel intuitive but can increase maximum waits due to stochastic bunching during red phases.
The close alignment between simulation outcomes and Webster’s theoretical predictions boosts confidence in the model.
Practical implication: Adaptive signal control should lean toward shorter cycles during typical conditions and adjust only when sustained heavy flows are detected.
The Monte Carlo approach successfully identified the Short Cycle as the optimal timing for the tested conditions.
Average waits were minimized without sacrificing throughput, achieving the highest efficiency score.
Randomness in arrivals is a critical factor in signal optimization; simulation-based evaluation provides robust guidance beyond fixed heuristics.
Interact with the full code, run the simulation, and explore the graphs directly within the site.