View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.headway;
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.opentrafficsim.core.perception.PerceivedObject;
7   
8   /**
9    * Interface for a reference to information about a (lane based) GTU and a headway. The Headway can store information about GTUs
10   * or objects ahead of the reference GTU, behind the reference GTU, or (partially) parallel to the reference GTU. In addition to
11   * the (perceived) headway, several other pieces of information can be stored, such as (perceived) speed, (perceived)
12   * acceleration, (perceived) turn indicators, and (perceived) braking lights. <br>
13   * Special care must be taken in curves when perceiving headway of a GTU or object on an adjacent lane.The question is whether
14   * we perceive the parallel or ahead/behind based on a line perpendicular to the front/back of the GTU (rectangular), or
15   * perpendicular to the center line of the lane (wedge-shaped in case of a curve). The difficulty of a wedge-shaped situation is
16   * that reciprocity might be violated: in case of a clothoid, for instance, it is not sure that the point on the center line
17   * when projected from lane 1 to lane 2 is the same as the projection from lane 2 to lane 1. The same holds for shapes with
18   * sharp bends. Therefore, algorithms implementing headway should only project the <i>reference point</i> of the reference GTU
19   * on the center line of the adjacent lane, and then calculate the forward position and backward position on the adjacent lane
20   * based on the reference point. Still, our human perception of what is parallel and what not, is not reflected by fractional
21   * positions.
22   * <p>
23   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * </p>
26   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
28   */
29  public interface Headway extends PerceivedObject, Comparable<Headway>
30  {
31      /** the object types that can be distinguished for headway. */
32      enum ObjectType
33      {
34          /** the observed object for headway is a GTU. */
35          GTU,
36  
37          /** the observed object for headway is a traffic light. */
38          TRAFFICLIGHT,
39  
40          /** the observed object for headway is a generic object. */
41          OBJECT,
42  
43          /** there is no observed object, just a distance. */
44          DISTANCEONLY,
45  
46          /** intersection conflict. */
47          CONFLICT,
48  
49          /** stop line. */
50          STOPLINE,
51  
52          /** bus stop. */
53          BUSSTOP;
54  
55          /** @return whether this object is a GTU or not. */
56          public boolean isGtu()
57          {
58              return this.equals(GTU);
59          }
60  
61          /** @return whether this object is a GTU or not. */
62          public boolean isTrafficLight()
63          {
64              return this.equals(TRAFFICLIGHT);
65          }
66  
67          /** @return whether this object is an object or not. */
68          public boolean isObject()
69          {
70              return this.equals(OBJECT);
71          }
72  
73          /** @return whether no object was observed and only a distance was stored. */
74          public boolean isDistanceOnly()
75          {
76              return this.equals(DISTANCEONLY);
77          }
78  
79          /** @return whether this object is a conflict or not. */
80          public boolean isConflict()
81          {
82              return this.equals(CONFLICT);
83          }
84  
85          /** @return whether this object is a stop line or not. */
86          public boolean isStopLine()
87          {
88              return this.equals(STOPLINE);
89          }
90  
91          /** @return whether this object is a bus stop or not. */
92          public boolean isBusStop()
93          {
94              return this.equals(BUSSTOP);
95          }
96  
97      }
98  
99      /**
100      * @return the id of the other object for comparison purposes, cannot be null.
101      */
102     @Override
103     String getId();
104 
105     /**
106      * @return the length of the other object; can be null if unknown.
107      */
108     Length getLength();
109 
110     /**
111      * @return the (perceived) speed of the other object; can be null if unknown.
112      */
113     Speed getSpeed();
114 
115     /**
116      * Retrieve the strongly typed distance to the other object.
117      * @return the distance to the object, return value null indicates that the other object is parallel to the reference object
118      */
119     Length getDistance();
120 
121     /**
122      * @return the (perceived) object Type, can be null if no object type unknown.
123      */
124     ObjectType getObjectType();
125 
126     /**
127      * @return acceleration the (perceived) acceleration of the other object; can be null if unknown.
128      */
129     Acceleration getAcceleration();
130 
131     /**
132      * Return the (perceived) front overlap to the other object. This value should be null if there is no overlap. In the figure
133      * for two GTUs below, it is distance c, positive for GTU1, negative for GTU2.
134      * 
135      * <pre>
136      * ----------
137      * |  GTU 1 |          -----&gt;
138      * ----------
139      *      ---------------
140      *      |    GTU 2    |          -----&gt;
141      *      ---------------
142      * | a  | b |     c   |
143      * </pre>
144      * 
145      * @return the (perceived) front overlap to the other object or null if there is no overlap.
146      */
147     Length getOverlapFront();
148 
149     /**
150      * Return the (perceived) rear overlap to the other object. This value should be null if there is no overlap.In the figure
151      * below for two GTUs, it is distance a, positive for GTU1, negative for GTU2.
152      * 
153      * <pre>
154      * ----------
155      * |  GTU 1 |          -----&gt;
156      * ----------
157      *      ---------------
158      *      |    GTU 2    |          -----&gt;
159      *      ---------------
160      * | a  | b |     c   |
161      * </pre>
162      * 
163      * @return the (perceived) rear overlap to the other object or null if there is no overlap.
164      */
165     Length getOverlapRear();
166 
167     /**
168      * Return the (perceived) overlap with the other object. This value should be null if there is no overlap. In the figure
169      * below for two GTUs, it is distance b, positive for GTU1 and GTU2.
170      * 
171      * <pre>
172      * ----------
173      * |  GTU 1 |          -----&gt;
174      * ----------
175      *      ---------------
176      *      |    GTU 2    |          -----&gt;
177      *      ---------------
178      * | a  | b |     c   |
179      * </pre>
180      * 
181      * @return Length, the (perceived) overlap with the other object or null if there is no overlap.
182      */
183     Length getOverlap();
184 
185     /**
186      * @return whether the other object is in front of the reference object.
187      */
188     boolean isAhead();
189 
190     /**
191      * @return whether the other object is behind the reference object.
192      */
193     boolean isBehind();
194 
195     /**
196      * @return whether the other object is parallel the reference object.
197      */
198     boolean isParallel();
199 
200     @Override
201     default int compareTo(final Headway headway)
202     {
203         if (getDistance() != null)
204         {
205             if (headway.getDistance() != null)
206             {
207                 return getDistance().compareTo(headway.getDistance());
208             }
209             return 1;
210         }
211         else if (headway.getDistance() != null)
212         {
213             return -1;
214         }
215         return getOverlapFront().compareTo(headway.getOverlapFront());
216     }
217 }