# 8. Nagel-Schreckenberg traffic model

**Ouvert le :**vendredi 12 février 2021, 00:00

**À rendre :**vendredi 19 février 2021, 23:55

In this assignment, you will implement the *Nagel-Schreckenberg Traffic Model* presented in class (lecture #15, slide 23).

We will use *dimensionless quantities*, meaning that [x]=[v]=[t], ie. position, velocity and time, all have the same "units".

In the model, each car has a position x and a velocity v which evolve in time as follows:

v ← min(v + 1, vmax )v ← min(v, max(d − 1,0))

v ← v − 1 if v > 0, with probability p

x ← x + v

where d was the distance to the next car.

Your code should be able to simulate the dynamics of Nagel-Schreckenberg traffic model for a set of cars that start from random positions on a road with periodic boundary conditions. The code should take its simulation parameters from a parameter file.

For the assignment, it is required that

- You use a git repository for your code
- you use a modular implementation with modules for the different main elements in the model; e.g. reading initial parameters, setting the initial conditions, single time step (including randomness), output, etc.
- the code reads the parameter file of the simulation from a file called
`params.ini`

, a plain-text file containing the following parameters:

- L = number of positions in the road (e.g. 500) T = total number of time steps (e.g. 500) N = number of cars in the road (e.g. 300) p = probability of slowing down (e.g. 0.2) vmax = maximum velocity (e.g. 2) seed = random number seed (e.g. 13) outputfilename = name of the file to save the data (e.g. "trafficMC.ext", where "ext" will match the file format of your choice)

- the code should use the Mersenne Twister random number generator either from the C++ random library or the GSL.
- the code should save the data generated for the model in either
a text file or netcdf file (your choice), but such that it can be used
for generating an image similar to the one presented in lecture #15
(slide 24). E.g. you could construct an
`rmatrix`that hold a space-time diagram with positions as rows and time as columns, such that the matrix has a value of 1 if a car is present at that time, and 0 otherwise. - you should include a visualization (plot) of the case run by your parameter file, using any tools you wish, e.g. python, gnuplot, ncview (depending, of course, on what format you used to store the data).

Submit the git repo as in previous assignments, i.e., by using the `git2zip` command on the Teach cluster, and uploading the resulting zip file to the website.

The due date for submission is Friday March 19th, 2021 by midnight (EST)