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. See examples in
30 * <a href= "http://simulation.tudelft.nl:8085/browse/OTS-113">http://simulation.tudelft.nl:8085/browse/OTS-113</a>.
31 * <p>
32 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
33 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
34 * </p>
35 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
36 * initial version May 27, 2016 <br>
37 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
38 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
39 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
40 */
41 public class HeadwayGTURealCopy extends AbstractHeadwayGTU
42 {
43 /** */
44 private static final long serialVersionUID = 20160527L;
45
46 /** stored car following model of the observed GTU. */
47 private final CarFollowingModel carFollowingModel;
48
49 /** stored parameters of the observed GTU. */
50 private final Parameters parameters;
51
52 /** stored speed limit info of the observed GTU. */
53 private final SpeedLimitInfo speedLimitInfo;
54
55 /** stored route of the observed GTU. */
56 private final Route route;
57
58 /**
59 * Protected constructor for moved copies or subclasses.
60 * @param id id
61 * @param gtuType GTU type
62 * @param distance distance
63 * @param length length
64 * @param width width
65 * @param speed speed
66 * @param acceleration acceleration
67 * @param carFollowingModel car-following model
68 * @param parameters parameters
69 * @param speedLimitInfo speed limit info
70 * @param route route
71 * @param desiredSpeed desired speed
72 * @param gtuStatus gtu status
73 * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
74 */
75 @SuppressWarnings("checkstyle:parameternumber")
76 HeadwayGTURealCopy(final String id, final GTUType gtuType, final Length distance, final Length length, final Length width,
77 final Speed speed, final Acceleration acceleration, final CarFollowingModel carFollowingModel,
78 final Parameters parameters, final SpeedLimitInfo speedLimitInfo, final Route route, final Speed desiredSpeed,
79 final GTUStatus... gtuStatus) throws GTUException
80 {
81 super(id, gtuType, distance, true, length, width, speed, acceleration, desiredSpeed, gtuStatus);
82 this.carFollowingModel = carFollowingModel;
83 this.parameters = parameters;
84 this.speedLimitInfo = speedLimitInfo;
85 this.route = route;
86 }
87
88 /**
89 * Protected constructor for moved copies or subclasses.
90 * @param id id
91 * @param gtuType GTU type
92 * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
93 * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
94 * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
95 * @param length length
96 * @param width width
97 * @param speed speed
98 * @param acceleration acceleration
99 * @param carFollowingModel car-following model
100 * @param parameters parameters
101 * @param speedLimitInfo speed limit info
102 * @param route route
103 * @param desiredSpeed desired speed
104 * @param gtuStatus gtu status
105 * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
106 */
107 @SuppressWarnings("checkstyle:parameternumber")
108 HeadwayGTURealCopy(final String id, final GTUType gtuType, final Length overlapFront, final Length overlap,
109 final Length overlapRear, final Length length, final Length width, final Speed speed,
110 final Acceleration acceleration, final CarFollowingModel carFollowingModel, final Parameters parameters,
111 final SpeedLimitInfo speedLimitInfo, final Route route, final Speed desiredSpeed, final GTUStatus... gtuStatus)
112 throws GTUException
113 {
114 super(id, gtuType, overlapFront, overlap, overlapRear, true, length, width, speed, acceleration, desiredSpeed,
115 gtuStatus);
116 this.carFollowingModel = carFollowingModel;
117 this.parameters = parameters;
118 this.speedLimitInfo = speedLimitInfo;
119 this.route = route;
120 }
121
122 /**
123 * Construct a new Headway information object, for a GTU ahead of us or behind us.
124 * @param gtu the observed GTU, can not be null.
125 * @param distance the distance to the other object; if this constructor is used, distance cannot be null.
126 * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
127 */
128 public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length distance) throws GTUException
129 {
130 super(gtu.getId(), gtu.getGTUType(), distance, true, gtu.getLength(), gtu.getWidth(), gtu.getSpeed(),
131 gtu.getAcceleration(), gtu.getDesiredSpeed(),
132 getGTUStatuses(gtu, gtu.getSimulator().getSimulatorTime()));
133 this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
134 this.parameters = new ParameterSet(gtu.getParameters());
135 this.speedLimitInfo = getSpeedLimitInfo(gtu);
136 this.route = gtu.getStrategicalPlanner().getRoute();
137 }
138
139 /**
140 * Construct a new Headway information object, for a GTU parallel with us.
141 * @param gtu the observed GTU, can not be null.
142 * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
143 * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
144 * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
145 * @throws GTUException when id is null, or parameters are inconsistent
146 */
147 public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap, final Length overlapRear)
148 throws GTUException
149 {
150 super(gtu.getId(), gtu.getGTUType(), overlapFront, overlap, overlapRear, true, gtu.getLength(), gtu.getWidth(),
151 gtu.getSpeed(), gtu.getAcceleration(), gtu.getDesiredSpeed(),
152 getGTUStatuses(gtu, gtu.getSimulator().getSimulatorTime()));
153 this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
154 this.parameters = new ParameterSet(gtu.getParameters());
155 this.speedLimitInfo = getSpeedLimitInfo(gtu);
156 this.route = gtu.getStrategicalPlanner().getRoute();
157 }
158
159 /** {@inheritDoc} */
160 @Override
161 public final CarFollowingModel getCarFollowingModel()
162 {
163 return this.carFollowingModel;
164 }
165
166 /** {@inheritDoc} */
167 @Override
168 public final Parameters getParameters()
169 {
170 return this.parameters;
171 }
172
173 /** {@inheritDoc} */
174 @Override
175 public final SpeedLimitInfo getSpeedLimitInfo()
176 {
177 return this.speedLimitInfo;
178 }
179
180 /** {@inheritDoc} */
181 @Override
182 public final Route getRoute()
183 {
184 return this.route;
185 }
186
187 /** {@inheritDoc} */
188 @Override
189 public final AbstractHeadwayGTU moved(final Length headway, final Speed speed, final Acceleration acceleration)
190 {
191 try
192 {
193 return new HeadwayGTURealCopy(getId(), getGtuType(), headway, getLength(), getWidth(), speed, acceleration,
194 getCarFollowingModel(), getParameters(), getSpeedLimitInfo(), getRoute(), getDesiredSpeed(),
195 getGtuStatus());
196 }
197 catch (GTUException exception)
198 {
199 // input should be consistent
200 throw new RuntimeException("Exception while copying Headway GTU.", exception);
201 }
202 }
203
204 /** {@inheritDoc} */
205 @Override
206 public final String toString()
207 {
208 return "HeadwayGTURealCopy [carFollowingModel=" + this.carFollowingModel + ", parameters=" + this.parameters
209 + ", speedLimitInfo=" + this.speedLimitInfo + ", route=" + this.route + "]";
210 }
211
212 }