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