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 aLaneBasedGTU
and that use lazy evaluation.Copyright (c) 2013-2022 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 Summary
Fields Modifier and Type Field Description static Acceleration
MAX_RED_DECELERATION
Maximum deceleration that is used to determine if a vehicle will attempt to stop for a red light.static Acceleration
MAX_YELLOW_DECELERATION
Maximum deceleration that is used to determine if a vehicle will attempt to stop for a yellow light.
-
Constructor Summary
Constructors Constructor Description LaneBasedAbstractPerceptionCategory(LanePerception perception)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.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.-
Methods inherited from class org.opentrafficsim.core.gtu.perception.AbstractPerceptionCategory
getGtu, getObjectOrNull, getPerception, getTimestamp
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.opentrafficsim.core.gtu.perception.PerceptionCategory
updateAll
-
-
-
-
Field Detail
-
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 Detail
-
LaneBasedAbstractPerceptionCategory
public LaneBasedAbstractPerceptionCategory(LanePerception perception)
- Parameters:
perception
- LanePerception; perception
-
-
Method Detail
-
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 methodpublic Speed getEgoSpeed()
for the tactical planner to use, andprivate Speed computeEgoSpeed()
for internal use, then we could use the following line insidegetEgoSpeed()
:return computeIfAbsent("speedLimit", () -> computeEgoSpeed());
- Type Parameters:
T
- value type- Parameters:
key
- Object; key defining which information is requestedsupplier
- 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 methodpublic List<HeadwayGTU> getLeaders(Lane)
for the tactical planner to use, andprivate List<HeadwayGTU> computeLeaders(Lane)
for internal use, then we could use the following line insidegetLeaders(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 dependentsupplier
- 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 aSupplier<T>
is to create a method and invoke it using a lambda expression. For example, suppose we have the methodpublic List<HeadwayGTU> getNeighbors(Lane, LongiudinalDirection)
for the tactical planner to use, andprivate List<HeadwayGTU> computeNeighbors(Lane, LongiudinalDirection)
for internal use, then we could use the following line insidegetNeighbors(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 dependentsupplier
- 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
-
-