Skip to content

Python implementation of the cellular automaton model for freeway traffic discussed in the paper by Kai Nagel and Michael Schreckenberg (HAL Id: jpa-00246697).

Notifications You must be signed in to change notification settings

piotrczech/cellular-automaton-freeway-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A cellular automation model for freeway traffic

About

Implementation of the cellular automaton model for freeway traffic discussed in the paper by Kai Nagel and Michael Schreckenberg (HAL Id: jpa-00246697).

Usage

python main.py [-h] [-L SITES] [-v V_MAX] [-d DENSITY] [-p PROBABILITY] [-s STEPS] [-m DISPLAY_MODE {console,scatter,line}]

where options are:

  • -h, --help - show help message and exit
  • -L, --sites - number of sites on the road (default: 70)
  • -v, --v_max - maximum velocity of vehicles (default: 5)
  • -d, --density - density of vehicles on the road (default: 0.25)
  • -p, --probability - probability of randomization (default: 0.4)
  • -s, --steps - number of simulation steps (default: 50)
  • -m, --display-mode - display mode for simulation data (default: console) (enum of: console, scatter, line)

Additional information you can get by providing

python main.py --help

Basic run

To simply run basic model implementation provide

python main.py

Examples

Console

The default display mode is the console, as it is fast and presents numerical values compared to other types of plots. However, it is important to note that the console is efficient only when one row of the road containing L sites can be displayed in a single console row. Otherwise, this implementation loses its purpose, so we suggest adjusting smaller values for the --sites and --steps parameters.

Examples of console usage on a 1920x1080 resolution:

python main.py --sites 80 --steps 40
python main.py --sites 80 --steps 40 --v_max 7 --density 0.4
Plots

Displaying data as a plot is more computationally complex, but at the same time requires a much larger amount of data to achieve nice results. The data points must be so close together that they almost overlap. This approach is recommended for patient users.

Examples of plotting without resizing the plot window:

python main.py --display-mode scatter --sites 350 --steps 600
python main.py --display-mode line --sites 250 --steps 600 --density 0.4
python main.py --display-mode scatter --sites 350 --steps 600 --v_max 15 --probability 0.7
Note

At the moment, the scatter implementation performs significantly better than the line plot, so we recommend using it.

Testing

Unit tests can be conducted using pytest. To run the tests, make sure you have pytest installed in your environment. You can install it using pip:

pip install pytest

Once pytest is installed, you can run the tests by navigating to the project directory and executing:

pytest --verbosity=1 .

About

Python implementation of the cellular automaton model for freeway traffic discussed in the paper by Kai Nagel and Michael Schreckenberg (HAL Id: jpa-00246697).

Topics

Resources

Stars

Watchers

Forks

Languages