1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
6 import org.djunits.value.vdouble.scalar.Duration;
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Time;
9 import org.opentrafficsim.kpi.interfaces.LinkDataInterface;
10 import org.opentrafficsim.kpi.sampling.Query;
11 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
12
13
14
15
16
17
18
19
20
21
22
23
24 public class MeanTravelTime extends AbstractIndicator<Duration>
25 {
26
27
28 private final MeanSpeed meanSpeed;
29
30
31
32
33 public MeanTravelTime(final MeanSpeed meanSpeed)
34 {
35 this.meanSpeed = meanSpeed;
36 }
37
38
39 @Override
40 public final Duration calculate(final Query query, final Time startTime, final Time endTime)
41 {
42 Length cumulLength = Length.ZERO;
43 Set<LinkDataInterface> links = new HashSet<>();
44 for (TrajectoryGroup trajectoryGroup : query.getTrajectoryGroups(startTime, endTime))
45 {
46 if (!links.contains(trajectoryGroup.getLaneDirection().getLaneData().getLinkData()))
47 {
48 cumulLength = cumulLength.plus(trajectoryGroup.getLength());
49 links.add(trajectoryGroup.getLaneDirection().getLaneData().getLinkData());
50 }
51 }
52 return cumulLength.divideBy(this.meanSpeed.getValue(query, startTime, endTime));
53 }
54
55
56 @Override
57 @SuppressWarnings("checkstyle:designforextension")
58 public String toString()
59 {
60 return "MeanTravelTime [meanSpeed=" + this.meanSpeed + "]";
61 }
62
63 }