View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import org.djunits.value.vdouble.scalar.Speed;
4   import org.djunits.value.vdouble.scalar.Time;
5   import org.opentrafficsim.kpi.sampling.Query;
6   
7   /**
8    * Sum of trajectory lengths divided by sum of trajectory durations.
9    * <p>
10   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
12   * <p>
13   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Sep 22, 2016 <br>
14   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
17   */
18  public class MeanSpeed extends AbstractIndicator<Speed>
19  {
20  
21      /** Travel distance indicator. */
22      private final TotalTravelDistance travelDistance;
23  
24      /** Travel time indicator. */
25      private final TotalTravelTime travelTime;
26  
27      /**
28       * @param travelDistance travel distance indicator
29       * @param travelTime travel time indicator
30       */
31      public MeanSpeed(final TotalTravelDistance travelDistance, final TotalTravelTime travelTime)
32      {
33          this.travelDistance = travelDistance;
34          this.travelTime = travelTime;
35      }
36  
37      /** {@inheritDoc} */
38      @Override
39      public final Speed calculate(final Query query, final Time startTime, final Time endTime)
40      {
41          return this.travelDistance.getValue(query, startTime, endTime).divideBy(
42              this.travelTime.getValue(query, startTime, endTime));
43      }
44  
45      /** {@inheritDoc} */
46      @Override
47      @SuppressWarnings("checkstyle:designforextension")
48      public String toString()
49      {
50          return "MeanSpeed [travelDistance=" + this.travelDistance + ", travelTime=" + this.travelTime + "]";
51      }
52  
53  }