View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import java.util.HashSet;
4   import java.util.List;
5   import java.util.Set;
6   
7   import org.djunits.value.vdouble.scalar.Length;
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 lengths divided by number of GTU's.
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  public class MeanTripLength extends AbstractIndicator<Length>
26  {
27  
28      /** {@inheritDoc} */
29      @Override
30      protected <G extends GtuDataInterface> Length calculate(final Query<G> query, final Time startTime, final Time endTime,
31              final List<TrajectoryGroup<G>> trajectoryGroups)
32      {
33          Length sum = Length.ZERO;
34          Set<String> gtuIds = new HashSet<>();
35          for (TrajectoryGroup<?> trajectoryGroup : trajectoryGroups)
36          {
37              for (Trajectory<?> trajectory : trajectoryGroup.getTrajectories())
38              {
39                  sum = sum.plus(trajectory.getTotalLength());
40                  gtuIds.add(trajectory.getGtuId());
41              }
42          }
43          return sum.divideBy(gtuIds.size());
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      @SuppressWarnings("checkstyle:designforextension")
49      public String toString()
50      {
51          return "MeanTripLength []";
52      }
53  
54  }