View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import java.util.List;
4   
5   import org.djunits.value.vdouble.scalar.Speed;
6   import org.djunits.value.vdouble.scalar.Time;
7   import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
8   import org.opentrafficsim.kpi.sampling.Query;
9   import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
10  
11  /**
12   * Sum of trajectory lengths divided by sum of trajectory durations.
13   * <p>
14   * Copyright (c) 2013-2019 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 Sep 22, 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  public class MeanSpeed extends AbstractIndicator<Speed>
23  {
24  
25      /** Travel distance indicator. */
26      private final TotalTravelDistance travelDistance;
27  
28      /** Travel time indicator. */
29      private final TotalTravelTime travelTime;
30  
31      /**
32       * @param travelDistance TotalTravelDistance; travel distance indicator
33       * @param travelTime TotalTravelTime; travel time indicator
34       */
35      public MeanSpeed(final TotalTravelDistance travelDistance, final TotalTravelTime travelTime)
36      {
37          this.travelDistance = travelDistance;
38          this.travelTime = travelTime;
39      }
40  
41      /** {@inheritDoc} */
42      @Override
43      protected <G extends GtuDataInterface> Speed calculate(final Query<G> query, final Time startTime, final Time endTime,
44              final List<TrajectoryGroup<G>> trajectoryGroups)
45      {
46          return this.travelDistance.getValue(query, startTime, endTime, trajectoryGroups)
47                  .divideBy(this.travelTime.getValue(query, startTime, endTime, trajectoryGroups));
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      @SuppressWarnings("checkstyle:designforextension")
53      public String toString()
54      {
55          return "MeanSpeed [travelDistance=" + this.travelDistance + ", travelTime=" + this.travelTime + "]";
56      }
57  
58  }