1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import org.djunits.unit.LinearDensityUnit;
4 import org.djunits.value.vdouble.scalar.LinearDensity;
5 import org.djunits.value.vdouble.scalar.Time;
6 import org.opentrafficsim.kpi.sampling.Query;
7 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
8
9
10
11
12
13
14
15
16
17
18
19
20 public class MeanDensity extends AbstractIndicator<LinearDensity>
21 {
22
23
24 private final TotalTravelTime travelTime;
25
26
27
28
29 public MeanDensity(final TotalTravelTime travelTime)
30 {
31 this.travelTime = travelTime;
32 }
33
34
35 @Override
36 protected LinearDensity calculate(Query query, Time startTime, Time endTime)
37 {
38 double ttt = this.travelTime.getValue(query, startTime, endTime).si;
39 double area = 0;
40 for (TrajectoryGroup trajectoryGroup : query.getTrajectoryGroups(startTime, endTime))
41 {
42 area += trajectoryGroup.getLength().si * (endTime.si - startTime.si);
43 }
44 return new LinearDensity(ttt / area, LinearDensityUnit.SI);
45 }
46
47 }