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