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.GtuData;
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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
19   * </p>
20   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
22   * @author <a href="https://github.com/wjschakel">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 Speed; reference speed for delay
33       */
34      public TotalDelay(final Speed referenceSpeed)
35      {
36          this.referenceSpeed = referenceSpeed;
37      }
38  
39      /** {@inheritDoc} */
40      @Override
41      protected <G extends GtuData> Duration calculate(final Query<G, ?> query, final Time startTime, final Time endTime,
42              final List<TrajectoryGroup<G>> 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.divide(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  }