View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.categories;
2   
3   import org.djunits.value.vdouble.scalar.Acceleration;
4   import org.djunits.value.vdouble.scalar.Length;
5   import org.djunits.value.vdouble.scalar.Speed;
6   import org.djunits.value.vdouble.scalar.Time;
7   import org.opentrafficsim.base.parameters.ParameterException;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9   import org.opentrafficsim.road.gtu.lane.perception.categories.Anticipation.NeighborTriplet;
10  import org.opentrafficsim.road.gtu.lane.perception.mental.AdaptationSituationalAwareness;
11  
12  /**
13   * Estimation of neighbor headway, speed and acceleration.
14   * <p>
15   * Copyright (c) 2013-2018 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 6 apr. 2018 <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 interface Estimation
24  {
25      /** No estimation errors. */
26      public static final Estimation NONE = new Estimation()
27      {
28          @Override
29          public NeighborTriplet estimate(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
30                  final Length distance, final boolean downstream, final Time when) throws ParameterException
31          {
32              return new NeighborTriplet(distance, perceivedGtu.getSpeed(), perceivedGtu.getAcceleration());
33          }
34      };
35  
36      /** Underestimation based on situational awareness. */
37      public static final Estimation UNDERESTIMATION = new Estimation()
38      {
39          @Override
40          public NeighborTriplet estimate(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
41                  final Length distance, final boolean downstream, final Time when) throws ParameterException
42          {
43              double factor = 1.0 - (perceivingGtu.getParameters().getParameter(AdaptationSituationalAwareness.SA_MAX)
44                      - perceivingGtu.getParameters().getParameter(AdaptationSituationalAwareness.SA));
45              double delta = (perceivedGtu.getOdometer().si - perceivedGtu.getOdometer(when).si)
46                      - (perceivingGtu.getOdometer().si - perceivingGtu.getOdometer(when).si);
47              if (!downstream)
48              {
49                  delta = -delta; // faster leader increases the headway, faster follower reduces the headway
50              }
51              Length headway = Length.createSI((distance.si + delta) * factor);
52              double egoSpeed = perceivingGtu.getSpeed(when).si;
53              Speed speed = Speed.createSI(egoSpeed + factor * (perceivedGtu.getSpeed(when).si - egoSpeed));
54              Acceleration acceleration = perceivedGtu.getAcceleration(when);
55              return new NeighborTriplet(headway, speed, acceleration);
56          }
57      };
58  
59      /**
60       * Estimate headway, speed and acceleration.
61       * @param perceivingGtu LaneBasedGTU; perceiving GTU
62       * @param perceivedGtu LaneBasedGTU; perceived GTU
63       * @param distance Length; actual headway at 'now' (i.e. not at 'when' if there is a reaction time)
64       * @param downstream boolean; downstream (or upstream) neighbor
65       * @param when Time; moment of perception, reaction time included
66       * @return NeighborTriplet; perceived headway, speed and acceleration
67       * @throws ParameterException on invalid parameter value or if parameter is not available
68       */
69      NeighborTriplet estimate(LaneBasedGTU perceivingGtu, LaneBasedGTU perceivedGtu, Length distance, boolean downstream,
70              Time when) throws ParameterException;
71  }