1 package org.opentrafficsim.core.gtu.lane; 2 3 import java.rmi.RemoteException; 4 import java.util.Map; 5 import java.util.Set; 6 7 import org.opentrafficsim.core.gtu.GTU; 8 import org.opentrafficsim.core.gtu.RelativePosition; 9 import org.opentrafficsim.core.gtu.following.GTUFollowingModel; 10 import org.opentrafficsim.core.gtu.following.HeadwayGTU; 11 import org.opentrafficsim.core.network.LateralDirectionality; 12 import org.opentrafficsim.core.network.NetworkException; 13 import org.opentrafficsim.core.network.lane.Lane; 14 import org.opentrafficsim.core.unit.AccelerationUnit; 15 import org.opentrafficsim.core.unit.LengthUnit; 16 import org.opentrafficsim.core.unit.SpeedUnit; 17 import org.opentrafficsim.core.unit.TimeUnit; 18 import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar; 19 20 /** 21 * The starting point of a LaneBasedTU is that it can be in <b>multiple lanes</b> at the same time. This can be due to a lane 22 * change (lateral), or due to crossing a link (front of the GTU is on another Lane than rear of the GTU). If a Lane is shorter 23 * than the length of the GTU (e.g. when we do node expansion on a crossing, this is very well possible), a GTU could occupy 24 * dozens of Lanes at the same time. 25 * <p> 26 * When calculating a headway, the GTU has to look in successive lanes. When Lanes (or underlying CrossSectionLinks) diverge, 27 * the headway algorithms have to look at multiple Lanes and return the minimum headway in each of the Lanes. When the Lanes (or 28 * underlying CrossSectionLinks) converge, "parallel" traffic is not taken into account in the headway calculation. Instead, gap 29 * acceptance algorithms or their equivalent should guide the merging behavior. 30 * <p> 31 * Copyright (c) 2013-2014 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/node/13">OpenTrafficSim License</a>. 33 * <p> 34 * @version Oct 22, 2014 <br> 35 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 36 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 37 * @param <ID> The type of ID, e.g., String or Integer 38 */ 39 public interface LaneBasedGTU<ID> extends GTU<ID> 40 { 41 /** 42 * v(t) = v0 + (t - t0) * a. 43 * @return the velocity of the GTU, in the direction of the lane 44 * @throws RemoteException in case of problems getting the simulation time. 45 */ 46 DoubleScalar.Abs<SpeedUnit> getLongitudinalVelocity() throws RemoteException; 47 48 /** 49 * Return the speed of this GTU at the specified time. <br> 50 * v(t) = v0 + (t - t0) * a 51 * @param when time for which the speed must be returned 52 * @return DoubleScalarAbs<SpeedUnit>; the speed at the specified time 53 */ 54 DoubleScalar.Abs<SpeedUnit> getLongitudinalVelocity(DoubleScalar.Abs<TimeUnit> when); 55 56 /** 57 * @return the acceleration (or deceleration) of the GTU, in the direction of the lane 58 * @throws RemoteException in case of problems getting the simulation time. 59 */ 60 DoubleScalar.Abs<AccelerationUnit> getAcceleration() throws RemoteException; 61 62 /** 63 * @param when time for which the speed must be returned 64 * @return the acceleration (or deceleration) of the GTU, in the direction of the lane. 65 */ 66 DoubleScalar.Abs<AccelerationUnit> getAcceleration(DoubleScalar.Abs<TimeUnit> when); 67 68 /** 69 * @return the velocity of the GTU, perpendicular to the direction of the lane. Positive lateral velocity is "left" compared 70 * to the driving direction. 71 */ 72 DoubleScalar.Abs<SpeedUnit> getLateralVelocity(); 73 74 /** @return DoubleScalarAbs<TimeUnit>; the time of last evaluation. */ 75 DoubleScalar.Abs<TimeUnit> getLastEvaluationTime(); 76 77 /** @return DoubleScalarAbs<TimeUnit>; the time of next evaluation. */ 78 DoubleScalar.Abs<TimeUnit> getNextEvaluationTime(); 79 80 /** 81 * Register the lane with a GTU, at the start of the lane. The reference point will be registered at the time and relative 82 * position of the last evaluation of the GTU to keep calculations consistent. 83 * @param lane the lane to add to the list of lanes on which the GTU is registered. 84 * @throws NetworkException 85 * @throws RemoteException 86 */ 87 void addFrontToSubsequentLane(Lane lane) throws RemoteException, NetworkException; 88 89 /** 90 * insert GTU at a certain position. This can happen at setup (first initialization), and after a lane change of the GTU. 91 * The relative position that will be registered is the referencePosition (dx, dy, dz) = (0, 0, 0). Front and rear positions 92 * are relative towards this position. 93 * @param lane the lane to add to the list of lanes on which the GTU is registered. 94 * @param position the position on the lane. 95 * @throws NetworkException 96 */ 97 void addLane(Lane lane, DoubleScalar.Rel<LengthUnit> position) throws NetworkException; 98 99 /** 100 * Unregister the GTU from a lane. 101 * @param lane the lane to remove from the list of lanes on which the GTU is registered. 102 */ 103 void removeLane(Lane lane); 104 105 /** 106 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the 107 * vehicle is registered. <br> 108 * <b>Note:</b> If a GTU is registered in multiple parallel lanes, the lateralLaneChangeModel is used to determine the 109 * center line of the vehicle at this point in time. Otherwise, the average of the center positions of the lines will be 110 * taken. 111 * @param relativePosition the position on the vehicle relative to the reference point. 112 * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU. 113 * @throws RemoteException when simulator time cannot be retrieved. 114 * @throws NetworkException when the vehicle is not on one of the lanes on which it is registered. 115 */ 116 Map<Lane, DoubleScalar.Rel<LengthUnit>> positions(RelativePosition relativePosition) throws NetworkException, 117 RemoteException; 118 119 /** 120 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the 121 * vehicle is registered. 122 * @param relativePosition the position on the vehicle relative to the reference point. 123 * @param when the future time for which to calculate the positions. 124 * @return the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of 125 * the GTU. 126 * @throws NetworkException when the vehicle is not on one of the lanes on which it is registered. 127 */ 128 Map<Lane, DoubleScalar.Rel<LengthUnit>> positions(RelativePosition relativePosition, DoubleScalar.Abs<TimeUnit> when) 129 throws NetworkException; 130 131 /** 132 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane at the current 133 * simulation time. <br> 134 * @param lane the position on this lane will be returned. 135 * @param relativePosition the position on the vehicle relative to the reference point. 136 * @return DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane. 137 * @throws NetworkException when the vehicle is not on the given lane. 138 * @throws RemoteException when simulator time cannot be retrieved. 139 */ 140 DoubleScalar.Rel<LengthUnit> position(Lane lane, RelativePosition relativePosition) throws NetworkException, 141 RemoteException; 142 143 /** 144 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane. 145 * @param lane the position on this lane will be returned. 146 * @param relativePosition the position on the vehicle relative to the reference point. 147 * @param when the future time for which to calculate the positions. 148 * @return DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane. 149 * @throws NetworkException when the vehicle is not on the given lane. 150 */ 151 DoubleScalar.Rel<LengthUnit> position(Lane lane, RelativePosition relativePosition, DoubleScalar.Abs<TimeUnit> when) 152 throws NetworkException; 153 154 /** 155 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the 156 * vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are 157 * next to each other and we compare an 'inner' and 'outer' curve.<br> 158 * @param relativePosition the position on the vehicle relative to the reference point. 159 * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU. 160 * @throws RemoteException when simulator time cannot be retrieved. 161 * @throws NetworkException when the vehicle is not on one of the lanes on which it is registered. 162 */ 163 Map<Lane, Double> fractionalPositions(RelativePosition relativePosition) throws NetworkException, RemoteException; 164 165 /** 166 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the 167 * vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are 168 * next to each other and we compare an 'inner' and 'outer' curve. 169 * @param relativePosition the position on the vehicle relative to the reference point. 170 * @param when the future time for which to calculate the positions. 171 * @return the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of 172 * the GTU. 173 * @throws NetworkException when the vehicle is not on one of the lanes on which it is registered. 174 */ 175 Map<Lane, Double> fractionalPositions(RelativePosition relativePosition, DoubleScalar.Abs<TimeUnit> when) 176 throws NetworkException; 177 178 /** 179 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction 180 * of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an 181 * 'inner' and 'outer' curve. 182 * @param lane the position on this lane will be returned. 183 * @param relativePosition the position on the vehicle relative to the reference point. 184 * @param when the future time for which to calculate the positions. 185 * @return the fractional relative position on the lane at the given time. 186 * @throws NetworkException when the vehicle is not on the given lane. 187 */ 188 double fractionalPosition(Lane lane, RelativePosition relativePosition, DoubleScalar.Abs<TimeUnit> when) 189 throws NetworkException; 190 191 /** 192 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction 193 * of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an 194 * 'inner' and 'outer' curve.<br> 195 * @param lane the position on this lane will be returned. 196 * @param relativePosition the position on the vehicle relative to the reference point. 197 * @return the fractional relative position on the lane at the given time. 198 * @throws NetworkException when the vehicle is not on the given lane. 199 * @throws RemoteException when simulator time cannot be retrieved. 200 */ 201 double fractionalPosition(Lane lane, RelativePosition relativePosition) throws NetworkException, RemoteException; 202 203 /** 204 * Return the longitudinal position that this GTU would have if it were to change to another Lane with a/the current 205 * CrossSectionLink. 206 * @param projectionLane Lane; the lane onto which the position of this GTU must be projected 207 * @param relativePosition RelativePosition; the point on this GTU that must be projected 208 * @param when DoubleScalar.Abs<TimeUnit>; the time for which to project the position of this GTU 209 * @return DoubleScalar.Rel<LengthUnit>; the position of this GTU in the projectionLane 210 * @throws NetworkException when projectionLane it not in any of the CrossSectionLink that the GTU is on 211 */ 212 DoubleScalar.Rel<LengthUnit> projectedPosition(Lane projectionLane, RelativePosition relativePosition, 213 DoubleScalar.Abs<TimeUnit> when) throws NetworkException; 214 215 /** 216 * Determine which GTU in front of this GTU, or behind this GTU. This method looks in all lanes where this GTU is 217 * registered, and not further than the absolute value of the given maxDistance. The minimum headway is returned of all 218 * Lanes where the GTU is registered. When no GTU is found within the given maxDistance, <b>null</b> is returned. The search 219 * will extend into successive lanes if the maxDistance is larger than the remaining length on the lane. When Lanes (or 220 * underlying CrossSectionLinks) diverge, the headway algorithms have to look at multiple Lanes and return the minimum 221 * headway in each of the Lanes. When the Lanes (or underlying CrossSectionLinks) converge, "parallel" traffic is not taken 222 * into account in the headway calculation. Instead, gap acceptance algorithms or their equivalent should guide the merging 223 * behavior.<br> 224 * <b>Note:</b> Headway is the net headway and calculated on a front-to-back basis. 225 * @param maxDistance the maximum distance to look for the nearest GTU; positive values search forwards; negative values 226 * search backwards 227 * @return HeadwayGTU; the headway and the GTU 228 * @throws RemoteException when simulator time cannot be retrieved. 229 * @throws NetworkException when there is an error with the next lanes in the network. 230 */ 231 HeadwayGTU headway(DoubleScalar.Rel<LengthUnit> maxDistance) throws RemoteException, NetworkException; 232 233 /** 234 * Determine by what distance the front of this GTU is behind the rear an other GTU, or the rear of this GTU is ahead of the 235 * front of an other GTU. Only positive values are returned. This method only looks in the given lane, and not further than 236 * the given maxDistance. When no vehicle is found within the given maxDistance, 237 * <code>new DoubleScalar.Rel<LengthUnit>(Double.MAX_VALUE, LengthUnit.METER)</code> is returned. The search will extend 238 * into successive lanes if the maxDistance is larger than the length of the lane.<br> 239 * <b>Note:</b> Headway is the net headway and calculated on a front-to-back basis. 240 * @param lane the lane to look for another GTU 241 * @param maxDistance the maximum distance to look for; if positive, the search is forwards; if negative, the search is 242 * backwards 243 * @return HeadwayGTU; the headway and the GTU 244 * @throws RemoteException when simulator time cannot be retrieved 245 * @throws NetworkException when the vehicle's route is inconclusive or vehicles are not registered correctly on their lanes 246 */ 247 HeadwayGTU headway(Lane lane, DoubleScalar.Rel<LengthUnit> maxDistance) throws RemoteException, NetworkException; 248 249 /** 250 * Determine which GTUs are parallel with us on another lane, based on fractional positions. <br> 251 * Note: When the GTU that calls the method is also registered on the given lane, it is excluded from the return set. 252 * @param lane the lane to look for parallel (partial or full overlapping) GTUs. 253 * @param when the future time for which to calculate the headway 254 * @return the set of GTUs parallel to us on the other lane (partial overlap counts as parallel), based on fractional 255 * positions, or an empty set when no GTUs were found. 256 * @throws RemoteException when simulator time cannot be retrieved. 257 * @throws NetworkException when the vehicle's route is inconclusive, when vehicles are not registered correctly on their 258 * lanes, or when the given lane is not parallel to one of the lanes where we are registered. 259 */ 260 Set<LaneBasedGTU<?>> parallel(Lane lane, DoubleScalar.Abs<TimeUnit> when) throws RemoteException, NetworkException; 261 262 /** 263 * Determine which GTUs are parallel with us in a certain lateral direction, based on fractional positions. <br> 264 * Note 1: This method will look to the adjacent lanes of all lanes where the vehicle has been registered.<br> 265 * Note 2: When the GTU that calls the method is also registered on the given lane, it is excluded from the return set. 266 * @param lateralDirection the direction of the adjacent lane(s) to look for parallel (partial or full overlapping) GTUs. 267 * @param when the future time for which to calculate the headway 268 * @return the set of GTUs parallel to us on other lane(s) in the given direction (partial overlap counts as parallel), 269 * based on fractional positions, or an empty set when no GTUs were found. 270 * @throws RemoteException when simulator time cannot be retrieved. 271 * @throws NetworkException when the vehicle's route is inconclusive, when vehicles are not registered correctly on their 272 * lanes, or when there are no lanes parallel to one of the lanes where we are registered in the given 273 * direction. 274 */ 275 Set<LaneBasedGTU<?>> parallel(LateralDirectionality lateralDirection, DoubleScalar.Abs<TimeUnit> when) 276 throws RemoteException, NetworkException; 277 278 /** 279 * Determine the time when this GTU will have covered the specified distance from the position of the last evaluation time. 280 * @param distance DoubleScalar.Rel<LengthUnit>; the distance 281 * @return DoubleScalar.Rel<TimeUnit>; the time, or null if this GTU stops before covering the specified distance 282 */ 283 DoubleScalar.Abs<TimeUnit> timeAtDistance(DoubleScalar.Rel<LengthUnit> distance); 284 285 /** 286 * Determine the time since last evaluation when this GTU has covered the specified distance from the position of the last 287 * evaluation time. 288 * @param distance DoubleScalar.Rel<LengthUnit>; the distance 289 * @return DoubleScalar.Rel<TimeUnit>; the time difference from last evaluation or null if this GTU stops before 290 * covering the specified distance 291 */ 292 DoubleScalar.Rel<TimeUnit> deltaTimeForDistance(DoubleScalar.Rel<LengthUnit> distance); 293 294 /** 295 * Retrieve the GTU following model of this LaneBasedGTU. 296 * @return GTUFollowingModel 297 */ 298 GTUFollowingModel getGTUFollowingModel(); 299 300 }