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