What is TrafficTwin?

TrafficTwin is an urban traffic simulation platform built on the Nagel-Schreckenberg cellular automata model. It provides a realistic representation of traffic flow dynamics on a configurable grid-based road network.

The simulator models individual vehicles following four fundamental rules: acceleration, gap-based slowing, random braking (to simulate human behavior), and movement. Traffic lights at intersections cycle through green, yellow, and red phases with configurable durations.

Technology Stack

  • Backend: Python / FastAPI
  • Database: SQLite / SQLAlchemy
  • Templates: Jinja2
  • Visualization: HTML5 Canvas
  • Styling: Custom CSS (urban dark theme)
  • Testing: pytest / httpx

The Nagel-Schreckenberg Model

The NaSch model is a theoretical model for highway traffic simulation. At each time step, every vehicle follows these rules:

  1. Acceleration: If the vehicle's speed is less than the maximum, increase by 1.
  2. Slowing: If the gap to the next vehicle ahead is less than the current speed, reduce speed to gap size.
  3. Random Braking: With probability p, reduce speed by 1 (simulates unpredictable driver behavior).
  4. Movement: Move forward by the current speed.

Version Info

Version: 1.0.0

License: MIT

Author: TrafficTwin Contributors