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