View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import java.util.List;
4   
5   import org.djunits.value.vdouble.scalar.Duration;
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.djunits.value.vdouble.scalar.Speed;
8   import org.djunits.value.vdouble.scalar.Time;
9   import org.opentrafficsim.kpi.sampling.Query;
10  import org.opentrafficsim.kpi.sampling.Trajectory;
11  import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
12  
13  /**
14   * Sum of trajectory durations minus the sum of trajectory lengths divided by a reference speed.
15   * <p>
16   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
18   * <p>
19   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 1 okt. 2016 <br>
20   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
22   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
23   */
24  // TODO something better than a global reference speed defined at the indicator
25  public class TotalDelay extends AbstractIndicator<Duration>
26  {
27  
28      /** Reference speed for delay. */
29      private final Speed referenceSpeed;
30  
31      /**
32       * @param referenceSpeed reference speed for delay
33       */
34      public TotalDelay(final Speed referenceSpeed)
35      {
36          this.referenceSpeed = referenceSpeed;
37      }
38  
39      /** {@inheritDoc} */
40      @Override
41      protected Duration calculate(final Query query, final Time startTime, final Time endTime,
42              final List<TrajectoryGroup> trajectoryGroups)
43      {
44          Duration sumTime = Duration.ZERO;
45          Length sumDist = Length.ZERO;
46          for (TrajectoryGroup trajectoryGroup : trajectoryGroups)
47          {
48              // TODO: use data points and limit speed per interval
49              for (Trajectory<?> trajectory : trajectoryGroup.getTrajectories())
50              {
51                  sumTime = sumTime.plus(trajectory.getTotalDuration());
52                  sumDist = sumDist.plus(trajectory.getTotalLength());
53              }
54          }
55          return sumTime.minus(sumDist.divideBy(this.referenceSpeed));
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      @SuppressWarnings("checkstyle:designforextension")
61      public String toString()
62      {
63          return "TotalDelay [referenceSpeed=" + this.referenceSpeed + "]";
64      }
65  
66  }