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.sampling.Query;
9   import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
10  
11  /**
12   * Total travel time divided by the sum of areas (X * T).
13   * <p>
14   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 16 okt. 2016 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
21   */
22  public class MeanDensity extends AbstractIndicator<LinearDensity>
23  {
24  
25      /** Travel time indicator. */
26      private final TotalTravelTime travelTime;
27  
28      /**
29       * @param travelTime travel time indicator
30       */
31      public MeanDensity(final TotalTravelTime travelTime)
32      {
33          this.travelTime = travelTime;
34      }
35  
36      /** {@inheritDoc} */
37      @Override
38      protected LinearDensity calculate(final Query query, final Time startTime, final Time endTime,
39              final List<TrajectoryGroup> trajectoryGroups)
40      {
41          double ttt = this.travelTime.getValue(query, startTime, endTime, trajectoryGroups).si;
42          double area = 0;
43          for (TrajectoryGroup trajectoryGroup : trajectoryGroups)
44          {
45              area += trajectoryGroup.getLength().si * (endTime.si - startTime.si);
46          }
47          return new LinearDensity(ttt / area, LinearDensityUnit.SI);
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public final String toString()
53      {
54          return "MeanDensity [travelTime=" + this.travelTime + "]";
55      }
56  
57  }