Class AbstractPerceptionIterable<H extends Headway,U,C>

java.lang.Object
org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionReiterable<H,U>
org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionIterable<H,U,C>
Type Parameters:
H - headway type
U - underlying object type
C - counter type
All Implemented Interfaces:
Iterable<H>, PerceptionCollectable<H,U>, PerceptionIterable<H>
Direct Known Subclasses:
DownstreamNeighborsIterable, LaneBasedObjectIterable, UpstreamNeighborsIterable

public abstract class AbstractPerceptionIterable<H extends Headway,U,C> extends AbstractPerceptionReiterable<H,U>
Abstract iterable that figures out how to find the next nearest object, including splits.

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, Peter Knoppers, Wouter Schakel
  • Constructor Details

    • AbstractPerceptionIterable

      public AbstractPerceptionIterable(LaneBasedGtu perceivingGtu, LaneRecordInterface<?> root, org.djunits.value.vdouble.scalar.Length initialPosition, boolean downstream, org.djunits.value.vdouble.scalar.Length maxDistance, RelativePosition relativePosition, Route route)
      Constructor.
      Parameters:
      perceivingGtu - LaneBasedGtu; perceiving GTU
      root - LaneRecord<?>; root record
      initialPosition - Length; initial position
      downstream - boolean; search downstream (or upstream)
      maxDistance - Length; max distance to search
      relativePosition - RelativePosition; position to which distance are calculated by subclasses
      route - Route; route of the GTU, may be null
  • Method Details

    • isDownstream

      public boolean isDownstream()
      Whether the iterable searches downstream.
      Returns:
      boolean; whether the iterable searches downstream
    • primaryIterator

      Returns the primary iterator. This method is called once by AbstractPerceptionReiterable.
      Specified by:
      primaryIterator in class AbstractPerceptionReiterable<H extends Headway,U>
      Returns:
      Iterator; primary iterator
    • getNext

      protected abstract AbstractPerceptionIterable<H,U,C>.Entry getNext(LaneRecordInterface<?> record, org.djunits.value.vdouble.scalar.Length position, C counter) throws GtuException
      Returns the next object(s) on the lane represented by the record. This should only consider objects on the given lane. This method should not check the distance towards objects with the maximum distance. The counter will be null for the first object(s). For following object(s) it is whatever value is given with the previous output Entry. Hence, this method maintains its own counting system.
      Parameters:
      record - LaneRecord<?>; record representing the lane and direction
      position - Length; position to look beyond
      counter - C; counter
      Returns:
      next object(s) on the lane or null if none
      Throws:
      GtuException - on any exception in the process
    • getDistance

      protected abstract org.djunits.value.vdouble.scalar.Length getDistance(U object, LaneRecordInterface<?> record, org.djunits.value.vdouble.scalar.Length position)
      Returns the distance to the object. The position fed in to this method is directly taken from an Entry returned by getNext. The two methods need to be consistent with each other.
      Parameters:
      object - U; underlying object
      record - LaneRecord<?>; record representing the lane and direction
      position - Length; position of the object on the lane
      Returns:
      Length; distance to the object
    • getDx

      protected org.djunits.value.vdouble.scalar.Length getDx()
      Returns the longitudinal length of the relevant relative position such that distances to this points can be calculated.
      Returns:
      Length; the longitudinal length of the relevant relative position such that distances to this points can be calculated
    • isOnRoute

      final boolean isOnRoute(LaneRecordInterface<?> record)
      Returns whether the record is on the route.
      Parameters:
      record - LaneRecord<?>; record
      Returns:
      boolean; whether the record is on the route