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.base.parameters.Parameters;
7   import org.opentrafficsim.core.gtu.GtuException;
8   import org.opentrafficsim.core.gtu.GtuType;
9   import org.opentrafficsim.core.network.route.Route;
10  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
11  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
12  
13  /**
14   * Container for a reference to information about a (lane based) GTU and a headway. The Headway can store information about GTUs
15   * or objects ahead of the reference GTU, behind the reference GTU, or (partially) parallel to the reference GTU. In addition to
16   * the (perceived) headway, several other pieces of information can be stored, such as (perceived) speed, (perceived)
17   * acceleration, (perceived) turn indicators, and (perceived) braking lights. <br>
18   * This particular version has only limited behavioral information about the observed GTU.<br>
19   * Special care must be taken in curves when perceiving headway of a GTU or object on an adjacent lane.The question is whether
20   * we perceive the parallel or ahead/behind based on a line perpendicular to the front/back of the GTU (rectangular), or
21   * perpendicular to the center line of the lane (wedge-shaped in case of a curve). The difficulty of a wedge-shaped situation is
22   * that reciprocity might be violated: in case of a clothoid, for instance, it is not sure that the point on the center line
23   * 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
24   * sharp bends. Therefore, algorithms implementing headway should only project the <i>reference point</i> of the reference GTU
25   * on the center line of the adjacent lane, and then calculate the forward position and backward position on the adjacent lane
26   * based on the reference point. Still, our human perception of what is parallel and what not, is not reflected by fractional
27   * positions. 
28   * <p>
29   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
30   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
31   * </p>
32   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
33   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
34   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
35   */
36  public class HeadwayGtuSimple extends AbstractHeadwayGtu
37  {
38      /** */
39      private static final long serialVersionUID = 20160527L;
40  
41      /**
42       * Construct a new Headway information object, for a moving GTU ahead of us or behind us.
43       * @param id String; the id of the GTU for comparison purposes, can not be null.
44       * @param gtuType GtuType; the perceived GTU Type, or null if unknown.
45       * @param distance the distance to the other object; if this constructor is used, distance cannot be null.
46       * @param length the length of the other object; if this constructor is used, length cannot be null.
47       * @param width the (perceived) width of the other object; can not be null.
48       * @param speed the (perceived) speed of the other object; can be null if unknown.
49       * @param acceleration the (perceived) acceleration of the other object; can be null if unknown.
50       * @param desiredSpeed Speed; desired speed
51       * @param gtuStatus GtuStatus...; the observable characteristics of the GTU.
52       * @throws GtuException when id is null, objectType is null, or parameters are inconsistent
53       */
54      public HeadwayGtuSimple(final String id, final GtuType gtuType, final Length distance, final Length length,
55              final Length width, final Speed speed, final Acceleration acceleration, final Speed desiredSpeed,
56              final GtuStatus... gtuStatus) throws GtuException
57      {
58          super(id, gtuType, distance, true, length, width, speed, acceleration, desiredSpeed, gtuStatus);
59      }
60  
61      /**
62       * Construct a new Headway information object, for a non-moving GTU ahead of us or behind us.
63       * @param id String; the id of the GTU for comparison purposes, can not be null.
64       * @param gtuType GtuType; the perceived GTU Type, or null if unknown.
65       * @param distance Length; the distance to the other Gtu; if this constructor is used, distance cannot be null.
66       * @param length the length of the other object; if this constructor is used, length cannot be null.
67       * @param width the (perceived) width of the other object; can not be null.
68       * @param desiredSpeed Speed; desired speed
69       * @param gtuStatus GtuStatus...; the observable characteristics of the GTU.
70       * @throws GtuException when id is null, or parameters are inconsistent
71       */
72      public HeadwayGtuSimple(final String id, final GtuType gtuType, final Length distance, final Length length,
73              final Length width, final Speed desiredSpeed, final GtuStatus... gtuStatus) throws GtuException
74      {
75          super(id, gtuType, distance, true, length, width, desiredSpeed, gtuStatus);
76      }
77  
78      /**
79       * Construct a new Headway information object, for a moving GTU parallel with us.
80       * @param id String; the id of the GTU for comparison purposes, can not be null.
81       * @param gtuType GtuType; the perceived GTU Type, or null if unknown.
82       * @param overlapFront the front-front distance to the other Gtu; if this constructor is used, this value cannot be null.
83       * @param overlap the 'center' overlap with the other Gtu; if this constructor is used, this value cannot be null.
84       * @param overlapRear the rear-rear distance to the other Gtu; if this constructor is used, this value cannot be null.
85       * @param length the length of the other object; if this constructor is used, length cannot be null.
86       * @param width the (perceived) width of the other object; can not be null.
87       * @param speed the (perceived) speed of the other Gtu; can be null if unknown.
88       * @param acceleration the (perceived) acceleration of the other Gtu; can be null if unknown.
89       * @param desiredSpeed Speed; desired speed
90       * @param gtuStatus GtuStatus...; the observable characteristics of the GTU.
91       * @throws GtuException when id is null, or parameters are inconsistent
92       */
93      @SuppressWarnings("checkstyle:parameternumber")
94      public HeadwayGtuSimple(final String id, final GtuType gtuType, final Length overlapFront, final Length overlap,
95              final Length overlapRear, final Length length, final Length width, final Speed speed,
96              final Acceleration acceleration, final Speed desiredSpeed, final GtuStatus... gtuStatus) throws GtuException
97      {
98          super(id, gtuType, overlapFront, overlap, overlapRear, true, length, width, speed, acceleration, desiredSpeed,
99                  gtuStatus);
100     }
101 
102     /**
103      * Construct a new Headway information object, for a non-moving GTU parallel with us.
104      * @param id String; the id of the GTU for comparison purposes, can not be null.
105      * @param gtuType GtuType; the perceived GTU Type, or null if unknown.
106      * @param overlapFront the front-front distance to the other Gtu; if this constructor is used, this value cannot be null.
107      * @param overlap the 'center' overlap with the other Gtu; if this constructor is used, this value cannot be null.
108      * @param overlapRear the rear-rear distance to the other Gtu; if this constructor is used, this value cannot be null.
109      * @param length the length of the other object; if this constructor is used, length cannot be null.
110      * @param width the (perceived) width of the other object; can not be null.
111      * @param desiredSpeed Speed; desired speed
112      * @param gtuStatus GtuStatus...; the observable characteristics of the GTU.
113      * @throws GtuException when id is null, or parameters are inconsistent
114      */
115     public HeadwayGtuSimple(final String id, final GtuType gtuType, final Length overlapFront, final Length overlap,
116             final Length overlapRear, final Length length, final Length width, final Speed desiredSpeed,
117             final GtuStatus... gtuStatus) throws GtuException
118     {
119         super(id, gtuType, overlapFront, overlap, overlapRear, true, length, width, desiredSpeed, gtuStatus);
120     }
121 
122     /** {@inheritDoc} */
123     @Override
124     public final CarFollowingModel getCarFollowingModel()
125     {
126         throw new UnsupportedOperationException("HeadwayGtuSimple does not support the getCarFollowingModel() method.");
127     }
128 
129     /** {@inheritDoc} */
130     @Override
131     public final Parameters getParameters()
132     {
133         throw new UnsupportedOperationException("HeadwayGtuSimple does not support the getParameters() method.");
134     }
135 
136     /** {@inheritDoc} */
137     @Override
138     public final SpeedLimitInfo getSpeedLimitInfo()
139     {
140         throw new UnsupportedOperationException("HeadwayGtuSimple does not support the getSpeedLimitInfo() method.");
141     }
142 
143     /** {@inheritDoc} */
144     @Override
145     public final Route getRoute()
146     {
147         return null;
148     }
149 
150     /** {@inheritDoc} */
151     @Override
152     public final AbstractHeadwayGtu moved(final Length headway, final Speed speed, final Acceleration acceleration)
153     {
154         try
155         {
156             return new HeadwayGtuSimple(getId(), getGtuType(), headway, getLength(), getWidth(), speed, acceleration,
157                     getDesiredSpeed(), getGtuStatus());
158         }
159         catch (GtuException exception)
160         {
161             // input should be consistent
162             throw new RuntimeException("Exception while copying Headway GTU.", exception);
163         }
164     }
165 
166     /** {@inheritDoc} */
167     @Override
168     public final String toString()
169     {
170         return "HeadwayGtuSimple [length=" + super.getLength() + "]";
171     }
172 
173 }