# Re: [sumo-user] Can you clarify how density is computed for lanes and edges

```Hello Jakob,
thanks a lot, now it is more clear.
The problem is that I was assuming that sampledSecond is just the number of
seconds there were vehicles on the lane, not the sum of the number of seconds
of every vehicle on the lane. I was assuming that if your measure interval is,
say 10 s, then sampledSeconds<=10 always.  Even though it is on the wiki, I
think it is not clear enough.```
```
Best regards,
Esteban

Sent with [ProtonMail](https://protonmail.com) Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On 7 March 2018 10:10 AM, Jakob Erdmann <namdre.s...@googlemail.com> wrote:

> Hello,
> I admit the formula is a bit hard to read.
>
> Consider an aggregation period of 1s. In that case each vehicle on the lane
> results in 1 sampled second so sampleSeconds gives the number of vehicles on
> the lane.
> Since the length of the lane is in m we get the density #veh/m by dividing by
> myLaneLength.
> To get #veh/km we multiply by 1000
>
> For longer periods, if the number of vehicle on the lane stays constant, it
> should be obvious that the sampleSeconds is a multiple of the number and the
> period and the formula is correct as well.
>
> If the number of vehicles changes during the aggregation period, the formula
> gives the appropriate average.
> regards,
> Jakob
>
> 2018-03-06 18:59 GMT+01:00 eegea <ee...@protonmail.com>:
>
>> According to the wiki
>> (http://sumo.dlr.de/wiki/Simulation/Output/Lane-_or_Edge-based_Traffic_Measures)
>> density is given as "#veh/km"
>> However, looking at the source in MSMeanData_Net line 179 and 208 it is
>> computed as
>>
>> dev.writeAttr("density", sampleSeconds / STEPS2TIME(period) * (SUMOReal)
>> 1000 / myLaneLength)
>>
>> I cannot see why the above gives the number of vehicles per Km in the lane
>> during the period. As far as I see, sampleSeconds is updated as expected
>> sampleSeconds += timeOnLane
>> so it seems to be what the wiki says "Number seconds vehicles were measured
>> on the edge/lane".
>> It seems that we have the fraction of time the lane has been occupied
>> multiplied by 1000  and divided by the lane length.
>> Is this an error or is this coming from some formula I do not know of?
>>
>> _______________________________________________
>> sumo-user mailing list
>> sumo-user@eclipse.org
>> To change your delivery options, retrieve your password, or unsubscribe from
>> this list, visit
>> https://dev.eclipse.org/mailman/listinfo/sumo-user```
```_______________________________________________
sumo-user mailing list
sumo-user@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user
```