View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import java.util.List;
4   
5   import org.djunits.unit.LinearDensityUnit;
6   import org.djunits.value.vdouble.scalar.LinearDensity;
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.TrajectoryGroup;
11  
12  /**
13   * Total travel time divided by the sum of areas (X * T).
14   * <p>
15   * Copyright (c) 2013-2019 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 16 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 MeanDensity extends AbstractIndicator<LinearDensity>
24  {
25  
26      /** Travel time indicator. */
27      private final TotalTravelTime travelTime;
28  
29      /**
30       * @param travelTime TotalTravelTime; travel time indicator
31       */
32      public MeanDensity(final TotalTravelTime travelTime)
33      {
34          this.travelTime = travelTime;
35      }
36  
37      /** {@inheritDoc} */
38      @Override
39      protected <G extends GtuDataInterface> LinearDensity calculate(final Query<G> query, final Time startTime,
40              final Time endTime, final List<TrajectoryGroup<G>> trajectoryGroups)
41      {
42          double ttt = this.travelTime.getValue(query, startTime, endTime, trajectoryGroups).si;
43          double area = 0;
44          for (TrajectoryGroup<?> trajectoryGroup : trajectoryGroups)
45          {
46              area += trajectoryGroup.getLength().si * (endTime.si - startTime.si);
47          }
48          return new LinearDensity(ttt / area, LinearDensityUnit.SI);
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public final String toString()
54      {
55          return "MeanDensity [travelTime=" + this.travelTime + "]";
56      }
57  
58  }