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