1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import java.util.List;
4
5 import org.djunits.unit.FrequencyUnit;
6 import org.djunits.value.vdouble.scalar.Frequency;
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 MeanIntensity extends AbstractIndicator<Frequency>
23 {
24
25
26 private final TotalTravelDistance travelDistance;
27
28
29
30
31 public MeanIntensity(final TotalTravelDistance travelDistance)
32 {
33 this.travelDistance = travelDistance;
34 }
35
36
37 @Override
38 protected Frequency calculate(Query query, Time startTime, Time endTime, final List<TrajectoryGroup> trajectoryGroups)
39 {
40 double ttd = this.travelDistance.getValue(query, startTime, endTime, trajectoryGroups).si;
41 double area = 0;
42 for (TrajectoryGroup trajectoryGroup : trajectoryGroups)
43 {
44 area += trajectoryGroup.getLength().si * (endTime.si - startTime.si);
45 }
46 return new Frequency(ttd / area, FrequencyUnit.SI);
47 }
48
49
50 @Override
51 public final String toString()
52 {
53 return "MeanIntensity [travelDistance=" + this.travelDistance + "]";
54 }
55
56 }