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