J.G
J.G

Reputation: 190

Is it possible to use SUMO TraCI get the density of the edge?

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?

Upvotes: 1

Views: 1572

Answers (1)

Michael
Michael

Reputation: 3680

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.

Upvotes: 2

Related Questions