Class RollingLaneStructure

java.lang.Object
org.opentrafficsim.road.gtu.lane.perception.RollingLaneStructure
All Implemented Interfaces:
Serializable, Remote, EventListener, org.djutils.event.EventListener, LaneStructure

public class RollingLaneStructure extends Object implements LaneStructure, Serializable, org.djutils.event.EventListener
This data structure can clearly indicate the lane structure ahead of us, e.g. in the following situation:
     (---- a ----)(---- b ----)(---- c ----)(---- d ----)(---- e ----)(---- f ----)(---- g ----)  
                                             __________                             __________
                                            / _________ 1                          / _________ 2
                                           / /                                    / /
                                __________/ /             _______________________/ /
  1  ____________ ____________ /_ _ _ _ _ _/____________ /_ _ _ _ _ _ _ _ _ _ _ _ /      
  0 |_ _X_ _ _ _ |_ _ _ _ _ _ |_ _ _ _ _ _ |_ _ _ _ _ _ |_ _ _ _ _ _ |_ _ _ _ _ _ \____________
 -1 |____________|_ _ _ _ _ _ |____________|____________|  __________|____________|____________| 3
 -2              / __________/                           \ \  
        ________/ /                                       \ \___________  
      5 _________/                                         \____________  4
 
When the GTU is looking ahead, it needs to know that when it continues to destination 3, it needs to shift one lane to the right at some point, but not two lanes to the right in link b, and not later than at the end of link f. When it needs to go to destination 1, it needs to shift to the left in link c. When it has to go to destination 2, it has to shift to the left, but not earlier than at link e. At node [de], it is possible to leave the rightmost lane of link e, and go to destination 4. The rightmost lane just splits into two lanes at the end of link d, and the GTU can either continue driving to destination 3, turn right to destination 4. This means that the right lane of link d has two successor lanes.

In the data structures, lanes are numbered laterally. Suppose that the lane where vehicle X resides would be number 0. Consistent with "left is positive" for angles, the lane right of X would have number -1, and entry 5 would have number -2.

In the data structure, this can be indicated as follows (N = next, P = previous, L = left, R = right, D = lane drop, . = continued but not in this structure). The merge lane in b is considered "off limits" for the GTUs on the "main" lane -1; the "main" lane 0 is considered off limits from the exit lanes on c, e, and f. Still, we need to maintain pointers to these lanes, as we are interested in the GTUs potentially driving next to us, feeding into our lane, etc.

       1                0               -1               -2
       
                       ROOT 
                   _____|_____      ___________      ___________            
                  |_-_|_._|_R_|----|_L_|_._|_-_|    |_-_|_._|_-_|  a           
                        |                |                |
                   _____V_____      _____V_____      _____V_____            
                  |_-_|_N_|_R_|----|_L_|_N_|_R_|<---|_L_|_D_|_-_|  b           
                        |                |                 
  ___________      _____V_____      _____V_____                 
 |_-_|_N_|_R_|<---|_L_|_N_|_R_|----|_L_|_N_|_-_|                   c
       |                |                |                 
  _____V_____      _____V_____      _____V_____                 
 |_-_|_._|_-_|    |_-_|_N_|_R_|----|_L_|_NN|_-_|                   d          
                        |                ||_______________ 
  ___________      _____V_____      _____V_____      _____V_____            
 |_-_|_N_|_R_|<---|_L_|_N_|_R_|----|_L_|_N_|_-_|    |_-_|_N_|_-_|  e          
       |                |                |                |
  _____V_____      _____V_____      _____V_____      _____V_____            
 |_-_|_N_|_R_|<---|_L_|_D_|_R_|----|_L_|_N_|_-_|    |_-_|_._|_-_|  f          
       |                                 |                 
  _____V_____                       _____V_____                             
 |_-_|_._|_-_|                     |_-_|_._|_-_|                   g
 

Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck
See Also:
  • Field Details

  • Constructor Details

    • RollingLaneStructure

      public RollingLaneStructure(org.djunits.value.vdouble.scalar.Length lookAhead, org.djunits.value.vdouble.scalar.Length down, org.djunits.value.vdouble.scalar.Length up, org.djunits.value.vdouble.scalar.Length downSplit, org.djunits.value.vdouble.scalar.Length upMerge, LaneBasedGtu gtu)
      Constructor.
      Parameters:
      lookAhead - Length; distance over which visual objects are included
      down - Length; downstream distance over which the structure is made
      up - Length; upstream distance over which the structure is made, should include a margin for reaction time
      downSplit - Length; downstream distance at splits (links not on route) included in the structure
      upMerge - Length; upstream distance at downstream merges (links not on route) included in the structure
      gtu - LaneBasedGtu; GTU
  • Method Details

    • update

      public final void update(LanePosition pos, Route route, GtuType gtuType) throws GtuException
      Updates the underlying structure shifting the root position to the input.
      Specified by:
      update in interface LaneStructure
      Parameters:
      pos - LanePosition; current position of the GTU
      route - Route; current route of the GTU
      gtuType - GtuType; GTU type
      Throws:
      GtuException - on a problem while updating the structure
    • getRootRecord

      public final LaneStructureRecord getRootRecord()
      Returns the root record.
      Specified by:
      getRootRecord in interface LaneStructure
      Returns:
      LaneRecord; root record
    • getRootRecord

      public final LaneStructureRecord getRootRecord(org.djunits.value.vdouble.scalar.Time time)
      Parameters:
      time - Time; time to obtain the root at
      Returns:
      rootRecord
    • getExtendedCrossSection

      public final SortedSet<RelativeLane> getExtendedCrossSection()
      Returns the extended cross-section, which includes all lanes for which a first record is present.
      Specified by:
      getExtendedCrossSection in interface LaneStructure
      Returns:
      SortedSet; the cross-section
    • getFirstRecord

      public final RollingLaneStructureRecord getFirstRecord(RelativeLane lane)
      Returns the first record on the given lane. This is often a record in the current cross section, but it may be one downstream for a lane that starts further downstream.
      Specified by:
      getFirstRecord in interface LaneStructure
      Parameters:
      lane - RelativeLane; lane
      Returns:
      first record on the given lane, or null if no such record
    • getDownstreamObjects

      public final <T extends LaneBasedObject> Map<RelativeLane,SortedSet<LaneStructure.Entry<T>>> getDownstreamObjects(Class<T> clazz, LaneBasedGtu gtu, RelativePosition.Type pos) throws GtuException
      Retrieve objects of a specific type. Returns objects over a maximum length of the look ahead distance downstream from the relative position, or as far as the lane map goes.
      Specified by:
      getDownstreamObjects in interface LaneStructure
      Type Parameters:
      T - type of objects to find
      Parameters:
      clazz - Class<T>; class of objects to find
      gtu - LaneBasedGtu; gtu
      pos - RelativePosition.TYPE; relative position to start search from
      Returns:
      Sorted set of objects of requested type per lane
      Throws:
      GtuException - if lane is not in current set
    • getDownstreamObjects

      public final <T extends LaneBasedObject> SortedSet<LaneStructure.Entry<T>> getDownstreamObjects(RelativeLane lane, Class<T> clazz, LaneBasedGtu gtu, RelativePosition.Type pos) throws GtuException
      Retrieve objects on a lane of a specific type. Returns objects over a maximum length of the look ahead distance downstream from the relative position, or as far as the lane map goes.
      Specified by:
      getDownstreamObjects in interface LaneStructure
      Type Parameters:
      T - type of objects to find
      Parameters:
      lane - RelativeLane; lane
      clazz - Class<T>; class of objects to find
      gtu - LaneBasedGtu; gtu
      pos - RelativePosition.TYPE; relative position to start search from
      Returns:
      Sorted set of objects of requested type
      Throws:
      GtuException - if lane is not in current set
    • getDownstreamObjectsOnRoute

      public final <T extends LaneBasedObject> SortedSet<LaneStructure.Entry<T>> getDownstreamObjectsOnRoute(RelativeLane lane, Class<T> clazz, LaneBasedGtu gtu, RelativePosition.Type pos, Route route) throws GtuException
      Retrieve objects on a lane of a specific type. Returns objects over a maximum length of the look ahead distance downstream from the relative position, or as far as the lane map goes. Objects on links not on the route are ignored.
      Specified by:
      getDownstreamObjectsOnRoute in interface LaneStructure
      Type Parameters:
      T - type of objects to find
      Parameters:
      lane - RelativeLane; lane
      clazz - Class<T>; class of objects to find
      gtu - LaneBasedGtu; gtu
      pos - RelativePosition.TYPE; relative position to start search from
      route - Route; the route
      Returns:
      Sorted set of objects of requested type
      Throws:
      GtuException - if lane is not in current set
    • getDownstreamObjectsOnRoute

      public final <T extends LaneBasedObject> Map<RelativeLane,SortedSet<LaneStructure.Entry<T>>> getDownstreamObjectsOnRoute(Class<T> clazz, LaneBasedGtu gtu, RelativePosition.Type pos, Route route) throws GtuException
      Retrieve objects of a specific type. Returns objects over a maximum length of the look ahead distance downstream from the relative position, or as far as the lane map goes. Objects on links not on the route are ignored.
      Specified by:
      getDownstreamObjectsOnRoute in interface LaneStructure
      Type Parameters:
      T - type of objects to find
      Parameters:
      clazz - Class<T>; class of objects to find
      gtu - LaneBasedGtu; gtu
      pos - RelativePosition.TYPE; relative position to start search from
      route - Route; the route
      Returns:
      Sorted set of objects of requested type per lane
      Throws:
      GtuException - if lane is not in current set
    • getUpstreamObjects

      public final <T extends LaneBasedObject> SortedSet<LaneStructure.Entry<T>> getUpstreamObjects(RelativeLane lane, Class<T> clazz, LaneBasedGtu gtu, RelativePosition.Type pos) throws GtuException
      Retrieve objects on a lane of a specific type. Returns upstream objects from the relative position for as far as the lane map goes. Distances to upstream objects are given as positive values.
      Specified by:
      getUpstreamObjects in interface LaneStructure
      Type Parameters:
      T - type of objects to find
      Parameters:
      lane - RelativeLane; lane
      clazz - Class<T>; class of objects to find
      gtu - LaneBasedGtu; gtu
      pos - RelativePosition.TYPE; relative position to start search from
      Returns:
      Sorted set of objects of requested type
      Throws:
      GtuException - if lane is not in current set
    • print

      public static String print(RollingLaneStructure ls, LaneBasedGtu gtu)
      Print the lane structure as a number of lines in a String.
      Parameters:
      ls - RollingLaneStructure; the lane structure to print
      gtu - LaneBasedGtu; the GTTU for which the lane structure is printed
      Returns:
      a String with information about the RollingLaneStructire
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • notify

      public void notify(org.djutils.event.Event event) throws RemoteException
      Specified by:
      notify in interface org.djutils.event.EventListener
      Throws:
      RemoteException