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-2019 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 String; id 61 * @param gtuType GTUType; GTU type 62 * @param distance Length; distance 63 * @param length Length; length 64 * @param width Length; width 65 * @param speed Speed; speed 66 * @param acceleration Acceleration; acceleration 67 * @param carFollowingModel CarFollowingModel; car-following model 68 * @param parameters Parameters; parameters 69 * @param speedLimitInfo SpeedLimitInfo; speed limit info 70 * @param route Route; route 71 * @param desiredSpeed Speed; desired speed 72 * @param gtuStatus 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 String; id 91 * @param gtuType 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; length 96 * @param width Length; width 97 * @param speed Speed; speed 98 * @param acceleration Acceleration; acceleration 99 * @param carFollowingModel CarFollowingModel; car-following model 100 * @param parameters Parameters; parameters 101 * @param speedLimitInfo SpeedLimitInfo; speed limit info 102 * @param route Route; route 103 * @param desiredSpeed Speed; desired speed 104 * @param gtuStatus 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 LaneBasedGTU; 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(), getGTUStatuses(gtu, gtu.getSimulator().getSimulatorTime())); 132 this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel(); 133 this.parameters = new ParameterSet(gtu.getParameters()); 134 this.speedLimitInfo = getSpeedLimitInfo(gtu); 135 this.route = gtu.getStrategicalPlanner().getRoute(); 136 } 137 138 /** 139 * Construct a new Headway information object, for a GTU parallel with us. 140 * @param gtu LaneBasedGTU; the observed GTU, can not be null. 141 * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null. 142 * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null. 143 * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null. 144 * @throws GTUException when id is null, or parameters are inconsistent 145 */ 146 public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap, final Length overlapRear) 147 throws GTUException 148 { 149 super(gtu.getId(), gtu.getGTUType(), overlapFront, overlap, overlapRear, true, gtu.getLength(), gtu.getWidth(), 150 gtu.getSpeed(), gtu.getAcceleration(), gtu.getDesiredSpeed(), 151 getGTUStatuses(gtu, gtu.getSimulator().getSimulatorTime())); 152 this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel(); 153 this.parameters = new ParameterSet(gtu.getParameters()); 154 this.speedLimitInfo = getSpeedLimitInfo(gtu); 155 this.route = gtu.getStrategicalPlanner().getRoute(); 156 } 157 158 /** {@inheritDoc} */ 159 @Override 160 public final CarFollowingModel getCarFollowingModel() 161 { 162 return this.carFollowingModel; 163 } 164 165 /** {@inheritDoc} */ 166 @Override 167 public final Parameters getParameters() 168 { 169 return this.parameters; 170 } 171 172 /** {@inheritDoc} */ 173 @Override 174 public final SpeedLimitInfo getSpeedLimitInfo() 175 { 176 return this.speedLimitInfo; 177 } 178 179 /** {@inheritDoc} */ 180 @Override 181 public final Route getRoute() 182 { 183 return this.route; 184 } 185 186 /** {@inheritDoc} */ 187 @Override 188 public final AbstractHeadwayGTU moved(final Length headway, final Speed speed, final Acceleration acceleration) 189 { 190 try 191 { 192 return new HeadwayGTURealCopy(getId(), getGtuType(), headway, getLength(), getWidth(), speed, acceleration, 193 getCarFollowingModel(), getParameters(), getSpeedLimitInfo(), getRoute(), getDesiredSpeed(), 194 getGtuStatus()); 195 } 196 catch (GTUException exception) 197 { 198 // input should be consistent 199 throw new RuntimeException("Exception while copying Headway GTU.", exception); 200 } 201 } 202 203 /** {@inheritDoc} */ 204 @Override 205 public final String toString() 206 { 207 return "HeadwayGTURealCopy [carFollowingModel=" + this.carFollowingModel + ", parameters=" + this.parameters 208 + ", speedLimitInfo=" + this.speedLimitInfo + ", route=" + this.route + "]"; 209 } 210 211 }