1

In order to monitor the LOS (Level of Service) of the edge, I need to know the density of the edge/road. I know the SUMO Edge-based Traffic Measure Output contains the attribute density. But I need to get it during the simulation. So, is it possible to use SUMO TraCI to get the density of the edge? Otherwise, how is the density in the output calculated?

J.G
  • 190
  • 3
  • 13
  • 1
    According to `http://sumo.dlr.de/wiki/TraCI/Edge_Value_Retrieval` you can request for the amount of vehicles driving on an edge in the last time stamp. If you need the length of the edge, you can probably get these information from the length of the lanes of the edge. – Ventu Apr 13 '18 at 08:50

1 Answers1

2

The comment by Ventu basically says it: Density is number of vehicles per km. So in Python you can use

num = traci.edge.getLastStepVehicleNumber(edgeID)
density = num / traci.lane.getLength(edgeID + "_0") / 1000.

The last line is a little hack because it simply derives the id of the first lane from the edge id and assumes that all lanes of an edge have the same length, but currently this is true for all networks in sumo.

Michael
  • 3,510
  • 1
  • 11
  • 23
  • Just to confirm if the density need to take the length of vehicle into account. For example, if the road has only trucks, the number of vehicles may be smaller, which leads to a smaller density. But if the road has only compact vehicles, the number of vehicles may be greater, which leads to a greater density. – J.G Apr 15 '18 at 17:13
  • 1
    There are different definitions of density but yes the one sumo uses is exactly as you stated. A road full of trucks will have a smaller density than a road full of small cars. – Michael Apr 15 '18 at 18:33
  • Also, based on the given formula above, the density is for the edge. In that case, if I need the density for the lane, I can do the further calculation by: `laneDensity = edgeDensity / numOfLane`. Is this correct? – J.G Apr 17 '18 at 05:30
  • This would be the average density for all lanes. If you want it specific for one lane just call `traci.lane.getLastStepVehicleNumber(laneID)` instead of the edge counterpart – Michael Apr 17 '18 at 12:23