I have a traffic simulation and I don't understand how I can plot the fundamental diagram (flow rate vs density). I simulate the traffic as follows:
I have a matrix that has as many columns as the the road length, and rows as time steps. Every car is represented by 1 in the matrix. I have lists to keep track of the index and speed of a car. I loop over N time steps so that the traffic evolves over time according to some rules.
I have looked at wikipedia and tried to find something online to help me but no luck so far in understanding it. How do I derive the data in order to plot the fundamental diagram?
My nested list where the first index is the position of the car and the second is its speed:
carIS[[0, 2], [1, 0], [2, 0], [3, 0], [4, 0], [6, 1], [7, 0], [9, 1], [10, 0], [11, 0], [12, 0], [13, 0], [16, 2], [19, 0], [20, 0], [22, 1], [24, 0], [26, 1], [28, 0], [30, 1], [31, 0], [32, 0], [33, 0], [34, 0], [35, 0], [36, 0], [39, 2], [40, 0], [41, 0], [42, 0], [43, 0], [44, 0], [45, 0], [46, 0], [47, 0]]
This list is produced with every time step. What should I do in order to generate the fundamental plot?