View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import java.util.List;
4   
5   import org.djunits.unit.DimensionlessUnit;
6   import org.djunits.value.vdouble.scalar.Dimensionless;
7   import org.djunits.value.vdouble.scalar.Time;
8   import org.opentrafficsim.kpi.sampling.Query;
9   import org.opentrafficsim.kpi.sampling.Trajectory;
10  import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
11  
12  /**
13   * Sum of measurements with zero speed, preceded by a non-zero speed.
14   * <p>
15   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 1 okt. 2016 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
22   */
23  public class TotalNumberOfStops extends AbstractIndicator<Dimensionless>
24  {
25  
26      /** {@inheritDoc} */
27      @Override
28      protected Dimensionless calculate(final Query query, final Time startTime, final Time endTime,
29              final List<TrajectoryGroup> trajectoryGroups)
30      {
31          int sum = 0;
32          for (TrajectoryGroup trajectoryGroup : trajectoryGroups)
33          {
34              for (Trajectory<?> trajectory : trajectoryGroup.getTrajectories())
35              {
36                  float[] v = trajectory.getV();
37                  for (int i = 1; i < v.length; i++)
38                  {
39                      if (v[i] == 0 && v[i - 1] > 0)
40                      {
41                          sum++;
42                      }
43                  }
44              }
45          }
46          return new Dimensionless(sum, DimensionlessUnit.SI);
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      @SuppressWarnings("checkstyle:designforextension")
52      public String toString()
53      {
54          return "TotalNumberOfStops []";
55      }
56  
57  }