View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.headway;
2   
3   import java.util.EnumSet;
4   
5   import org.djunits.value.vdouble.scalar.Acceleration;
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.djunits.value.vdouble.scalar.Speed;
8   import org.opentrafficsim.core.Throw;
9   import org.opentrafficsim.core.gtu.GTUException;
10  import org.opentrafficsim.core.gtu.GTUType;
11  import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
12  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
13  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
14  
15  /**
16   * Container for a reference to information about a (lane based) GTU and a headway. The Headway can store information about GTUs
17   * or objects ahead of the reference GTU, behind the reference GTU, or (partially) parallel to the reference GTU. In addition to
18   * the (perceived) headway, several other pieces of information can be stored, such as (perceived) speed, (perceived)
19   * acceleration, (perceived) turn indicators, and (perceived) braking lights. <br>
20   * Special care must be taken in curves when perceiving headway of a GTU or object on an adjacent lane.The question is whether
21   * we perceive the parallel or ahead/behind based on a line perpendicular to the front/back of the GTU (rectangular), or
22   * perpendicular to the center line of the lane (wedge-shaped in case of a curve). The difficulty of a wedge-shaped situation is
23   * that reciprocity might be violated: in case of a clothoid, for instance, it is not sure that the point on the center line
24   * 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
25   * sharp bends. Therefore, algorithms implementing headway should only project the <i>reference point</i> of the reference GTU
26   * on the center line of the adjacent lane, and then calculate the forward position and backward position on the adjacent lane
27   * based on the reference point. Still, our human perception of what is parallel and what not, is not reflected by fractional
28   * positions. See examples in <a href=
29   * "http://simulation.tudelft.nl:8085/browse/OTS-113">http://simulation.tudelft.nl:8085/browse/OTS-113</a>.
30   * <p>
31   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
32   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
33   * <p>
34   * @version $Revision: 1368 $, $LastChangedDate: 2015-09-02 00:20:20 +0200 (Wed, 02 Sep 2015) $, by $Author: averbraeck $,
35   *          initial version 11 feb. 2015 <br>
36   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
37   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
38   */
39  public abstract class AbstractHeadwayGTU extends AbstractHeadway
40  {
41      /** */
42      private static final long serialVersionUID = 20160410L;
43  
44      /** The perceived GTU Type, or null if unknown. */
45      private final GTUType gtuType;
46  
47      /** Observable characteristics of a GTU. */
48      public enum GTUStatus
49      {
50          /** Braking lights are on when observing the headway. */
51          BRAKING_LIGHTS,
52  
53          /** Left turn indicator was on when observing the headway. */
54          LEFT_TURNINDICATOR,
55  
56          /** Right turn indicator was on when observing the headway. */
57          RIGHT_TURNINDICATOR,
58  
59          /** Alarm lights are on. */
60          EMERGENCY_LIGHTS,
61  
62          /** GTU was honking (car) or ringing a bell (cyclist) when observing the headway. */
63          HONK;
64      }
65  
66      /** The observable characteristics of the GTU. */
67      private final EnumSet<GTUStatus> gtuStatus = EnumSet.noneOf(GTUStatus.class);
68  
69      /**
70       * Construct a new Headway information object, for a moving GTU ahead of us or behind us.
71       * @param id the id of the GTU for comparison purposes, can not be null.
72       * @param gtuType the perceived GTU Type, or null if unknown.
73       * @param distance the distance to the other object; if this constructor is used, distance cannot be null.
74       * @param length the (perceived) length of the other object; can not be null.
75       * @param speed the (perceived) speed of the other object; can be null if unknown.
76       * @param acceleration the (perceived) acceleration of the other object; can be null if unknown.
77       * @param gtuStatus the observable characteristics of the GTU.
78       * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
79       */
80      public AbstractHeadwayGTU(final String id, final GTUType gtuType, final Length distance, final Length length,
81          final Speed speed, final Acceleration acceleration, final GTUStatus... gtuStatus) throws GTUException
82      {
83          super(ObjectType.GTU, id, distance, length, speed, acceleration);
84          this.gtuType = gtuType;
85          for (GTUStatus status : gtuStatus)
86          {
87              this.gtuStatus.add(status);
88          }
89      }
90  
91      /**
92       * Construct a new Headway information object, for a non-moving GTU ahead of us or behind us.
93       * @param id String; the id of the GTU for comparison purposes, can not be null.
94       * @param gtuType GTUType; the perceived GTU Type, or null if unknown.
95       * @param distance Length; the distance to the other GTU; if this constructor is used, distance cannot be null.
96       * @param length the (perceived) length of the other object; can not be null.
97       * @throws GTUException when id is null, or parameters are inconsistent
98       */
99      public AbstractHeadwayGTU(final String id, final GTUType gtuType, final Length distance, final Length length)
100         throws GTUException
101     {
102         super(ObjectType.GTU, id, distance, length);
103         this.gtuType = gtuType;
104     }
105 
106     /**
107      * Construct a new Headway information object, for a moving GTU parallel with us.
108      * @param id the id of the GTU for comparison purposes, can not be null.
109      * @param gtuType the perceived GTU Type, or null if unknown.
110      * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
111      * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
112      * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
113      * @param length the (perceived) length of the other object; can not be null.
114      * @param speed the (perceived) speed of the other GTU; can be null if unknown.
115      * @param acceleration the (perceived) acceleration of the other GTU; can be null if unknown.
116      * @throws GTUException when id is null, or parameters are inconsistent
117      */
118     @SuppressWarnings("checkstyle:parameternumber")
119     public AbstractHeadwayGTU(final String id, final GTUType gtuType, final Length overlapFront, final Length overlap,
120         final Length overlapRear, final Length length, final Speed speed, final Acceleration acceleration)
121         throws GTUException
122     {
123         super(ObjectType.GTU, id, overlapFront, overlap, overlapRear, length, speed, acceleration);
124         this.gtuType = gtuType;
125     }
126 
127     /**
128      * Construct a new Headway information object, for a non-moving GTU parallel with us.
129      * @param id the id of the GTU for comparison purposes, can not be null.
130      * @param gtuType the perceived GTU Type, or null if unknown.
131      * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
132      * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
133      * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
134      * @param length the (perceived) length of the other object; can not be null.
135      * @throws GTUException when id is null, or parameters are inconsistent
136      */
137     public AbstractHeadwayGTU(final String id, final GTUType gtuType, final Length overlapFront, final Length overlap,
138         final Length overlapRear, final Length length) throws GTUException
139     {
140         super(ObjectType.GTU, id, overlapFront, overlap, overlapRear, length);
141         this.gtuType = gtuType;
142     }
143 
144     /**
145      * @return gtuType
146      */
147     public final GTUType getGtuType()
148     {
149         return this.gtuType;
150     }
151 
152     /** @return were the braking lights on? */
153     public final boolean isBrakingLightsOn()
154     {
155         return this.gtuStatus.contains(GTUStatus.BRAKING_LIGHTS);
156     }
157 
158     /** @return was the left turn indicator on? */
159     public final boolean isLeftTurnIndicatorOn()
160     {
161         return this.gtuStatus.contains(GTUStatus.LEFT_TURNINDICATOR);
162     }
163 
164     /** @return was the right turn indicator on? */
165     public final boolean isRightTurnIndicatorOn()
166     {
167         return this.gtuStatus.contains(GTUStatus.RIGHT_TURNINDICATOR);
168     }
169 
170     /** @return were the emergency lights on? */
171     public final boolean isEmergencyLightsOn()
172     {
173         return this.gtuStatus.contains(GTUStatus.EMERGENCY_LIGHTS);
174     }
175 
176     /** @return was the vehicle honking or ringing its bell when being observed for the headway? */
177     public final boolean isHonking()
178     {
179         return this.gtuStatus.contains(GTUStatus.HONK);
180     }
181 
182     /**
183      * Many models that observe a GTU need to predict the imminent behavior of that GTU. Having a car following model of the
184      * observed GTU can help with that. The car following model that is returned can be on a continuum between the actual car
185      * following model of the observed GTU and the own car following model of the observing GTU, not making any assumptions
186      * about the observed GTU. When successive observations of the GTU take place, parameters about its behavior can be
187      * estimated more accurately. Another interesting easy-to-implement solution is to return a car following model per GTU
188      * type, where the following model of a truck can differ from that of a car.
189      * @return a car following model that represents the expected behavior of the observed GTU
190      */
191     public abstract CarFollowingModel getCarFollowingModel();
192 
193     /**
194      * Many models that observe a GTU need to predict the imminent behavior of that GTU. Having an estimate of the behavioral
195      * characteristics of the observed GTU can help with that. The behavioral characteristics that are returned can be on a
196      * continuum between the actual behavioral characteristics of the observed GTU and the own behavioral characteristics of the
197      * observing GTU, not making any assumptions about the observed GTU. When successive observations of the GTU take place,
198      * parameters about its behavior can be estimated more accurately. Another interesting easy-to-implement solution is to
199      * return a set of behavioral characteristics per GTU type, where the behavioral characteristics of a truck can differ from
200      * that of a car.
201      * @return the behavioral characteristics that represent the expected behavior of the observed GTU
202      */
203     public abstract BehavioralCharacteristics getBehavioralCharacteristics();
204 
205     /**
206      * Many models that observe a GTU need to predict the imminent behavior of that GTU. Having a model of the speed info
207      * profile for the observed GTU can help with predicting its future behavior. The speed limit info that is returned can be
208      * on a continuum between the actual speed limit model of the observed GTU and the own speed limit model of the observing
209      * GTU, not making any assumptions about the observed GTU. When successive observations of the GTU take place, parameters
210      * about its behavior, such as the maximum speed it accepts, can be estimated more accurately. Another interesting
211      * easy-to-implement solution is to return a speed limit info object per GTU type, where the returned information of a truck
212      * -- with a maximum allowed speed on 80 km/h -- can differ from that of a car -- which can have a maximum allowed speed of
213      * 100 km/h on the same road.
214      * @return a speed limit model that helps in determining the expected behavior of the observed GTU
215      */
216     public abstract SpeedLimitInfo getSpeedLimitInfo();
217 
218     /** {@inheritDoc} */
219     @Override
220     public final String toString()
221     {
222         return "HeadwayGTU [gtuType=" + this.gtuType + ", gtuStatus=" + this.gtuStatus + "]";
223     }
224 
225 }