Agent-Based Modeling

Traffic, Interaction, and Congestion

This session turns the rule-based perspective from cellular automata into a simple agent-based model. Cars are individual agents with positions and speeds, and large traffic jams emerge from repeated local decisions (Nagel and Schreckenberg 1992; Wilensky and Rand 2015).

From Cellular Automata to Agents

In the previous session, every cell followed the same binary rule.

Now we keep discrete time and a one-dimensional road, but we enrich the state:

  • Occupied cells correspond to cars.
  • Each car stores a speed.
  • The update depends on the gap ahead and a stochastic slowdown rule.

This is still local. It is also more expressive, because agents now carry internal state.

Back to Cellular Automata

Case Studies

Start with the Nagel-Schreckenberg traffic model and implement the update rules carefully.

Traffic Model

Then move from one simulation to macroscopic measurements such as flow and congestion.

Flow and Congestion

When both pieces work, complete the assignment.

Assignment

Learning Goals

  • Represent traffic with occupancy and speed arrays.
  • Implement the Nagel-Schreckenberg update rules.
  • Produce space-time diagrams of traffic flow.
  • Measure density and average flow.
  • Explain how local agent behavior creates stop-and-go waves and jams.

Flow of This Session

  • Encode the road state.
  • Implement accelerate, brake, random slowdown, and move.
  • Simulate many time steps and visualize the road.
  • Measure macroscopic observables such as density and flow.
  • Compare free-flow and congested regimes.

What do we need?

numpy

Store the occupancy pattern, the speed of each car, and the experimental results.

matplotlib.pyplot

Plot space-time diagrams and flow-density curves.

Why call this agent-based if the road is still a grid?

Because each occupied site corresponds to an individual car with its own speed. The update is written from the point of view of each agent and its local environment, not as a closed-form equation for a global density field.

Scripts or notebooks?

Use a notebook for density sweeps, repeated trials, and parameter scans. Use a script if you want a faster interactive visualization or plan to add widgets later.

Note

We model a periodic road, so the first and last cells are neighbors. This removes boundary effects and makes the congestion dynamics easier to interpret.

References

Nagel, Kai, and Michael Schreckenberg. 1992. “A Cellular Automaton Model for Freeway Traffic.” Journal de Physique I 2 (12): 2221–29. https://doi.org/10.1051/jp1:1992277.
Wilensky, Uri, and William Rand. 2015. An Introduction to Agent-Based Modeling: Modeling Natural, Social, and Engineered Complex Systems with NetLogo. MIT Press.