Class LaneBasedAbstractPerceptionCategory

java.lang.Object
org.opentrafficsim.base.Type<AbstractPerceptionCategory<G,​P>>
org.opentrafficsim.core.gtu.perception.AbstractPerceptionCategory<LaneBasedGTU,​LanePerception>
org.opentrafficsim.road.gtu.lane.perception.categories.LaneBasedAbstractPerceptionCategory
All Implemented Interfaces:
Serializable, PerceptionCategory<LaneBasedGTU,​LanePerception>
Direct Known Subclasses:
AccPerception, AnticipationTrafficPerception, CaccPerception, DirectBusStopPerception, DirectDefaultSimplePerception, DirectInfrastructurePerception, DirectIntersectionPerception, DirectNeighborsPerception, ToledoPerception

public abstract class LaneBasedAbstractPerceptionCategory
extends AbstractPerceptionCategory<LaneBasedGTU,​LanePerception>
Super class for perception categories that use a LaneBasedGTU and that use lazy evaluation.

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

Version:
$Revision$, $LastChangedDate$, by $Author$, initial version Jul 29, 2016
Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
See Also:
Serialized Form
  • Field Details

    • MAX_YELLOW_DECELERATION

      public static final Acceleration MAX_YELLOW_DECELERATION
      Maximum deceleration that is used to determine if a vehicle will attempt to stop for a yellow light.
      Derived from the report Onderzoek geeltijden by Goudappel Coffeng.
    • MAX_RED_DECELERATION

      public static final Acceleration MAX_RED_DECELERATION
      Maximum deceleration that is used to determine if a vehicle will attempt to stop for a red light.
      Not based on any scientific source; sorry.
  • Constructor Details

  • Method Details

    • computeIfAbsent

      protected <T> T computeIfAbsent​(Object key, Supplier<T> supplier)
      Returns the cached value for the given key, or computes it if it's absent or not from the current simulation time. The key represents a type of information, e.g. 'ego speed'.

      This method will compute the information if required. A simple manner to define a Supplier<T> is to create a method and invoke it using a lambda expression. For example, suppose we have the method public Speed getEgoSpeed() for the tactical planner to use, and private Speed computeEgoSpeed() for internal use, then we could use the following line inside getEgoSpeed():

       return computeIfAbsent("speedLimit", () -> computeEgoSpeed());
       
      Type Parameters:
      T - value type
      Parameters:
      key - Object; key defining which information is requested
      supplier - Supplier<T>;
      Returns:
      T; cached or computed value
    • computeIfAbsent

      protected <T> T computeIfAbsent​(Object key, Supplier<T> supplier, Object context)
      Returns the cached value for the given key, or computes it if it's absent or not from the current simulation time. The key represents a type of information, e.g. 'leading GTUs'. This information is context specific, namely the lane for which 'leading GTUs' are requested.

      This method will compute the information if required. A simple manner to define a Supplier<T> is to create a method and invoke it using a lambda expression. For example, suppose we have the method public List<HeadwayGTU> getLeaders(Lane) for the tactical planner to use, and private List<HeadwayGTU> computeLeaders(Lane) for internal use, then we could use the following line inside getLeaders(Lane):

       return computeIfAbsent("leaders", () -> computeLeaders(lane))
       
      Type Parameters:
      T - value type
      Parameters:
      key - Object; key defining which information is requested, it may be contextual if it's context dependent
      supplier - Supplier<T>;
      context - Object; object defining the context, e.g. the lane for which the information is requested
      Returns:
      T; cached or computed value
    • computeIfAbsent

      protected <T> T computeIfAbsent​(Object key, Supplier<T> supplier, Object... context)
      Returns the cached value for the given key, or computes it if it's absent or not from the current simulation time. The key represents a type of information, e.g. 'neighboring GTUs'. This information is context specific, namely the lane for which 'neighboring GTUs' are requested, as well as the longitudinal direction.

      It is not advised to use this method at high frequency as it contains slight overhead. Instead, consider defining keys directly for various contexts. For example:

       private final Object leftLaneLeadersKey = new Object();
       
       private final Object leftLaneFollowersKey = new Object();
       
       private final Object righttLaneLeadersKey = new Object();
       
       private final Object rightLaneFollowersKey = new Object();
       
      This method will compute the information if required. A simple manner to define a Supplier<T> is to create a method and invoke it using a lambda expression. For example, suppose we have the method public List<HeadwayGTU> getNeighbors(Lane, LongiudinalDirection) for the tactical planner to use, and private List<HeadwayGTU> computeNeighbors(Lane, LongiudinalDirection) for internal use, then we could use the following line inside getNeighbors(Lane, LongiudinalDirection):
       return computeIfAbsent("neighbors", () -> computeNeighbors(lane, longDir))
       
      Type Parameters:
      T - value type
      Parameters:
      key - Object; key defining which information is requested, it may be contextual if it's context dependent
      supplier - Supplier<T>;
      context - Object...; objects defining the context, e.g. the lane and direction for which the information is requested
      Returns:
      T; cached or computed value