View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import org.djunits.unit.FrequencyUnit;
4   import org.djunits.value.vdouble.scalar.Frequency;
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 distance 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 MeanIntensity extends AbstractIndicator<Frequency>
21  {
22  
23      /** Travel distance indicator. */
24      private final TotalTravelDistance travelDistance;
25  
26      /**
27       * @param travelDistance travel distance indicator
28       */
29      public MeanIntensity(final TotalTravelDistance travelDistance)
30      {
31          this.travelDistance = travelDistance;
32      }
33      
34      /** {@inheritDoc} */
35      @Override
36      protected Frequency calculate(Query query, Time startTime, Time endTime)
37      {
38          double ttd = this.travelDistance.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 Frequency(ttd / area, FrequencyUnit.SI);
45      }
46  
47  }