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