View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import java.util.List;
4   
5   import org.djunits.unit.FrequencyUnit;
6   import org.djunits.value.vdouble.scalar.Frequency;
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 distance 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 MeanIntensity extends AbstractIndicator<Frequency>
23  {
24  
25      /** Travel distance indicator. */
26      private final TotalTravelDistance travelDistance;
27  
28      /**
29       * @param travelDistance travel distance indicator
30       */
31      public MeanIntensity(final TotalTravelDistance travelDistance)
32      {
33          this.travelDistance = travelDistance;
34      }
35  
36      /** {@inheritDoc} */
37      @Override
38      protected Frequency calculate(Query query, Time startTime, Time endTime, final List<TrajectoryGroup> trajectoryGroups)
39      {
40          double ttd = this.travelDistance.getValue(query, startTime, endTime, trajectoryGroups).si;
41          double area = 0;
42          for (TrajectoryGroup trajectoryGroup : trajectoryGroups)
43          {
44              area += trajectoryGroup.getLength().si * (endTime.si - startTime.si);
45          }
46          return new Frequency(ttd / area, FrequencyUnit.SI);
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public final String toString()
52      {
53          return "MeanIntensity [travelDistance=" + this.travelDistance + "]";
54      }
55  
56  }