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.Duration;
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.djunits.value.vdouble.scalar.Speed;
7   
8   /**
9    * Form of anticipation.
10   * <p>
11   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
13   * <p>
14   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 24 feb. 2017 <br>
15   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
18   */
19  public interface Anticipation
20  {
21  
22      /** Assume no anticipation. */
23      Anticipation NONE = new Anticipation()
24      {
25          @Override
26          public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
27                  final Length traveledDistance, final boolean downstream)
28          {
29              return neighborTriplet;
30          }
31  
32          @Override
33          public Length egoAnticipation(final Speed speed, final Acceleration acceleration, final Duration duration)
34          {
35              return Length.ZERO;
36          }
37      };
38  
39      /** Assume constant speed. */
40      Anticipation CONSTANT_SPEED = new Anticipation()
41      {
42          @Override
43          public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
44                  final Length traveledDistance, final boolean downstream)
45          {
46              // upstream neighbor approaches when faster
47              Length distance = downstream
48                      ? neighborTriplet.getHeadway().plus(neighborTriplet.getSpeed().multiplyBy(duration)).minus(traveledDistance)
49                      : neighborTriplet.getHeadway().minus(neighborTriplet.getSpeed().multiplyBy(duration))
50                              .plus(traveledDistance);
51              return new NeighborTriplet(distance, neighborTriplet.getSpeed(), neighborTriplet.getAcceleration());
52          }
53  
54          @Override
55          public Length egoAnticipation(final Speed speed, final Acceleration acceleration, final Duration duration)
56          {
57              return speed.multiplyBy(duration);
58          }
59      };
60  
61      /** Assume constant acceleration. */
62      Anticipation CONSTANT_ACCELERATION = new Anticipation()
63      {
64          @Override
65          public NeighborTriplet anticipate(final NeighborTriplet neighborTriplet, final Duration duration,
66                  final Length traveledDistance, final boolean downstream)
67          {
68              if (neighborTriplet.getSpeed().si < -neighborTriplet.getAcceleration().si * duration.si)
69              {
70                  // to stand still
71                  double t = neighborTriplet.getSpeed().si / -neighborTriplet.getAcceleration().si;
72                  double dx = neighborTriplet.getSpeed().si * t + .5 * neighborTriplet.getAcceleration().si * t * t;
73                  dx = downstream ? dx : -dx; // upstream neighbor approaches when faster
74                  return new NeighborTriplet(Length.createSI(neighborTriplet.getHeadway().si + dx - traveledDistance.si),
75                          Speed.ZERO, Acceleration.ZERO);
76              }
77              double dx = neighborTriplet.getSpeed().si * duration.si
78                      + .5 * neighborTriplet.getAcceleration().si * duration.si * duration.si;
79              double dv = neighborTriplet.getAcceleration().si * duration.si;
80              return new NeighborTriplet(Length.createSI(neighborTriplet.getHeadway().si + dx - traveledDistance.si),
81                      Speed.createSI(neighborTriplet.getSpeed().si + dv), neighborTriplet.getAcceleration());
82          }
83  
84          @Override
85          public Length egoAnticipation(final Speed speed, final Acceleration acceleration, final Duration duration)
86          {
87              return speed.multiplyBy(duration);
88          }
89      };
90  
91      /**
92       * Anticipate movement.
93       * @param neighborTriplet NeighborTriplet; headway, speed and acceleration
94       * @param duration Duration; duration
95       * @param traveledDistance Length; distance the subject vehicle traveled during the anticipation time
96       * @param downstream boolean; whether the perceived GTU is downstream
97       * @return anticipated info
98       */
99      NeighborTriplet anticipate(NeighborTriplet neighborTriplet, Duration duration, Length traveledDistance, boolean downstream);
100 
101     /**
102      * Anticipate own movement.
103      * @param speed Speed; current speed
104      * @param acceleration Acceleration; current acceleration
105      * @param duration Duration; anticipation time
106      * @return anticipated distance traveled
107      */
108     Length egoAnticipation(Speed speed, Acceleration acceleration, Duration duration);
109 }