View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.categories.neighbors;
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.mental.AdaptationSituationalAwareness;
10  
11  /**
12   * Estimation of neighbor headway, speed and acceleration.
13   * <p>
14   * Copyright (c) 2013-2019 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 6 apr. 2018 <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 interface Estimation
23  {
24      /** No estimation errors. */
25      Estimation NONE = new Estimation()
26      {
27          @Override
28          public NeighborTriplet estimate(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
29                  final Length distance, final boolean downstream, final Time when) throws ParameterException
30          {
31              return new NeighborTriplet(distance, perceivedGtu.getSpeed(), perceivedGtu.getAcceleration());
32          }
33      };
34  
35      /** Underestimation based on situational awareness. */
36      Estimation UNDERESTIMATION = new FactorEstimation()
37      {
38          /** {@inheritDoc} */
39          @Override
40          boolean overEstimation()
41          {
42              return false;
43          }
44      };
45  
46      /** OVerestimation based on situational awareness. */
47      Estimation OVERESTIMATION = new FactorEstimation()
48      {
49          /** {@inheritDoc} */
50          @Override
51          boolean overEstimation()
52          {
53              return true;
54          }
55      };
56  
57      /**
58       * Estimate headway, speed and acceleration.
59       * @param perceivingGtu LaneBasedGTU; perceiving GTU
60       * @param perceivedGtu LaneBasedGTU; perceived GTU
61       * @param distance Length; actual headway at 'now' (i.e. not at 'when' if there is a reaction time)
62       * @param downstream boolean; downstream (or upstream) neighbor
63       * @param when Time; moment of perception, reaction time included
64       * @return NeighborTriplet; perceived headway, speed and acceleration
65       * @throws ParameterException on invalid parameter value or if parameter is not available
66       */
67      NeighborTriplet estimate(LaneBasedGTU perceivingGtu, LaneBasedGTU perceivedGtu, Length distance, boolean downstream,
68              Time when) throws ParameterException;
69  
70      /**
71       * Estimation based on a factor.
72       * <p>
73       * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
74       * <br>
75       * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
76       * <p>
77       * @version $Revision$, $LastChangedDate$, by $Author$, initial version 31 jan. 2019 <br>
78       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
79       * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
80       * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
81       */
82      abstract class FactorEstimation implements Estimation
83      {
84  
85          /** Sign. */
86          private final double sign;
87  
88          /**
89           * Constructor.
90           */
91          FactorEstimation()
92          {
93              this.sign = overEstimation() ? 1.0 : -1.0;
94          }
95  
96          /** {@inheritDoc} */
97          @Override
98          public NeighborTriplet estimate(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
99                  final Length distance, final boolean downstream, final Time when) throws ParameterException
100         {
101             double factor = 1.0 + this.sign * (perceivingGtu.getParameters().getParameter(AdaptationSituationalAwareness.SA_MAX)
102                     - perceivingGtu.getParameters().getParameter(AdaptationSituationalAwareness.SA));
103             double delta = (perceivedGtu.getOdometer().si - perceivedGtu.getOdometer(when).si)
104                     - (perceivingGtu.getOdometer().si - perceivingGtu.getOdometer(when).si);
105             if (downstream)
106             {
107                 delta = -delta; // faster leader increases the headway, faster follower reduces the headway
108             }
109             Length headway = Length.createSI((distance.si + delta) * factor);
110             double egoSpeed = perceivingGtu.getSpeed(when).si;
111             Speed speed = Speed.createSI(egoSpeed + factor * (perceivedGtu.getSpeed(when).si - egoSpeed));
112             Acceleration acceleration = perceivedGtu.getAcceleration(when);
113             return new NeighborTriplet(headway, speed, acceleration);
114         }
115 
116         /**
117          * Returns whether this is over-estimation.
118          * @return boolean; whether this is over-estimation
119          */
120         abstract boolean overEstimation();
121     }
122 
123 }