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.interfaces.GtuDataInterface;
9 import org.opentrafficsim.kpi.sampling.Query;
10 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
11
12
13
14
15
16
17
18
19
20
21
22
23 public class MeanIntensity extends AbstractIndicator<Frequency>
24 {
25
26
27 private final TotalTravelDistance travelDistance;
28
29
30
31
32 public MeanIntensity(final TotalTravelDistance travelDistance)
33 {
34 this.travelDistance = travelDistance;
35 }
36
37
38 @Override
39 protected <G extends GtuDataInterface> Frequency calculate(final Query<G> query, final Time startTime, final Time endTime,
40 final List<TrajectoryGroup<G>> trajectoryGroups)
41 {
42 double ttd = this.travelDistance.getValue(query, startTime, endTime, trajectoryGroups).si;
43 double area = 0;
44 for (TrajectoryGroup<?> trajectoryGroup : trajectoryGroups)
45 {
46 area += trajectoryGroup.getLength().si * (endTime.si - startTime.si);
47 }
48 return new Frequency(ttd / area, FrequencyUnit.SI);
49 }
50
51
52 @Override
53 public final String toString()
54 {
55 return "MeanIntensity [travelDistance=" + this.travelDistance + "]";
56 }
57
58 }