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-2023 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://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
36 * @author <a href="https://dittlab.tudelft.nl">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 String; id
58 * @param gtuType GtuType; GTU type
59 * @param distance Length; distance
60 * @param length Length; length
61 * @param width Length; width
62 * @param speed Speed; speed
63 * @param acceleration Acceleration; acceleration
64 * @param carFollowingModel CarFollowingModel; car-following model
65 * @param parameters Parameters; parameters
66 * @param speedLimitInfo SpeedLimitInfo; speed limit info
67 * @param route Route; route
68 * @param desiredSpeed Speed; desired speed
69 * @param gtuStatus 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 String; id
88 * @param gtuType 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; length
93 * @param width Length; width
94 * @param speed Speed; speed
95 * @param acceleration Acceleration; acceleration
96 * @param carFollowingModel CarFollowingModel; car-following model
97 * @param parameters Parameters; parameters
98 * @param speedLimitInfo SpeedLimitInfo; speed limit info
99 * @param route Route; route
100 * @param desiredSpeed Speed; desired speed
101 * @param gtuStatus 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 LaneBasedGtu; the observed GTU, can not be null.
122 * @param distance the distance to the other object; 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 LaneBasedGtu; 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 /** {@inheritDoc} */
156 @Override
157 public final CarFollowingModel getCarFollowingModel()
158 {
159 return this.carFollowingModel;
160 }
161
162 /** {@inheritDoc} */
163 @Override
164 public final Parameters getParameters()
165 {
166 return this.parameters;
167 }
168
169 /** {@inheritDoc} */
170 @Override
171 public final SpeedLimitInfo getSpeedLimitInfo()
172 {
173 return this.speedLimitInfo;
174 }
175
176 /** {@inheritDoc} */
177 @Override
178 public final Route getRoute()
179 {
180 return this.route;
181 }
182
183 /** {@inheritDoc} */
184 @Override
185 public final AbstractHeadwayGtu moved(final Length headway, final Speed speed, final Acceleration acceleration)
186 {
187 try
188 {
189 return new HeadwayGtuRealCopy(getId(), getGtuType(), headway, getLength(), getWidth(), speed, acceleration,
190 getCarFollowingModel(), getParameters(), getSpeedLimitInfo(), getRoute(), getDesiredSpeed(),
191 getGtuStatus());
192 }
193 catch (GtuException exception)
194 {
195 // input should be consistent
196 throw new RuntimeException("Exception while copying Headway GTU.", exception);
197 }
198 }
199
200 /** {@inheritDoc} */
201 @Override
202 public final String toString()
203 {
204 return "HeadwayGtuRealCopy [carFollowingModel=" + this.carFollowingModel + ", parameters=" + this.parameters
205 + ", speedLimitInfo=" + this.speedLimitInfo + ", route=" + this.route + "]";
206 }
207
208 }