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