1

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?

Lebowski
  • 145
  • 1
  • 12
  • Is it a question of how you technically display the plots or how you derive the data for the plots? Please be more precise. – jhoepken Mar 01 '16 at 18:15
  • @JensHöpken I have a problem with deriving the data for the plots – Lebowski Mar 01 '16 at 18:27
  • If you could give an example for the data, that would be of great help as well. – jhoepken Mar 01 '16 at 18:34
  • @JensHöpken I have updated my question. I have seen the wikipedia page but I still don't understand it – Lebowski Mar 01 '16 at 18:47
  • As long as you don't know what data you have stored inside your list, you won't be able to plot anything. Understand the problem first, go back the literature and get a solid understanding of what you have simulated. You see where I am going with this? – jhoepken Mar 02 '16 at 10:04

1 Answers1

0

If by fundamental plot of traffic flow you mean this diagram: Fundamental Diagram from Wikipedia

You can create these easily using Matplotlib.

jhoepken
  • 1,842
  • 3
  • 17
  • 24