Define state, actions and reward
Specify the intersection geometry, sensor inputs (vehicle counts, queue lengths), discrete or continuous action choices and a reward that captures travel time, throughput and safety constraints.
Optimise traffic-light policy. Balance throughput and fairness.
Traffic-light control with reinforcement learning defines states (traffic queues, phases), actions (phase switches or durations) and rewards (throughput, delay, fairness). Real intersections introduce partial observability, variable demand and safety constraints that must be modelled during evaluation.
Learning concept · Not a validated service
Traffic-light control with reinforcement learning defines states (traffic queues, phases), actions (phase switches or durations) and rewards (throughput, delay, fairness). Real intersections introduce partial observability, variable demand and safety constraints that must be modelled during evaluation.
A proposed application is an adaptive intersection controller that adjusts phase timings to reduce average waiting time while preserving pedestrian crossing opportunities; a human operator should remain able to override and audit policy decisions. The supplied starter does not implement this deployment.
Specify the intersection geometry, sensor inputs (vehicle counts, queue lengths), discrete or continuous action choices and a reward that captures travel time, throughput and safety constraints.
Use a traffic simulator or Gymnasium wrapper to generate episodes with realistic arrival patterns and edge-case scenarios before training any agent.
Start with simple baselines (fixed-time, rule-based, bandit) then train value- or policy-based agents and compare average reward, queue lengths and stability across seeds.
Measure worst-case delays, pedestrian wait times and performance under demand shifts; add constraints and a manual override before any field trial.
The supplied starter simulates a 4-armed Bernoulli bandit and runs an epsilon-greedy online update: it samples actions, receives binary rewards from fixed per-arm probabilities, updates sample-average estimates, and prints counts and estimated rates. It does not instantiate an environment with states, episodes, or traffic dynamics.
for step in range(1, 2001):
if rng.random() < epsilon:
action = rng.integers(len(true_reward_rates))
else:
action = int(np.argmax(estimated_values))
reward = 1 if rng.random() < true_reward_rates[action] else 0
action_counts[action] += 1
total_reward += reward
estimated_values[action] += (reward - estimated_values[action]) / action_counts[action]The code is a stationary multi-armed bandit: it uses no environment modelling of intersections, no state or time-dependent traffic dynamics, no episodic RL loop, and no safety or pedestrian constraints required for traffic-light control.
A proposed extension is to wrap a Gymnasium-compatible traffic simulator, define state observations (lane counts, phase timers), and train a policy (PPO or DQN) that optimises average delay while enforcing safety constraints and manual overrides.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.