public abstract class LaneBasedAbstractPerceptionCategory extends AbstractPerceptionCategory<LaneBasedGTU,LanePerception>
LaneBasedGTU
and that use lazy evaluation.
Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
Modifier and Type | Field and 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 and Description |
---|
LaneBasedAbstractPerceptionCategory(LanePerception perception) |
Modifier and Type | Method and 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.
|
getGtu, getObjectOrNull, getPerception, getTimestamp
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
updateAll
public static final Acceleration MAX_YELLOW_DECELERATION
public static final Acceleration MAX_RED_DECELERATION
public LaneBasedAbstractPerceptionCategory(LanePerception perception)
perception
- LanePerception; perceptionprotected <T> T computeIfAbsent(Object key, Supplier<T> supplier)
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());
T
- value typekey
- Object; key defining which information is requestedsupplier
- Supplier<T>;protected <T> T computeIfAbsent(Object key, Supplier<T> supplier, Object context)
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))
T
- value typekey
- 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 requestedprotected <T> T computeIfAbsent(Object key, Supplier<T> supplier, Object... context)
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))
T
- value typekey
- 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
requestedCopyright © 2014–2019 Delft University of Technology. All rights reserved.