Class TacticalContextEgo

java.lang.Object
org.opentrafficsim.road.gtu.tactical.TacticalContextEgo
All Implemented Interfaces:
Identifiable, TacticalContext

public class TacticalContextEgo extends Object implements TacticalContext
Wraps a LaneBasedGtu and provides bundled and easy-access information that tactical models and their components need regarding the ego-vehicle. This information may be cached, such that different components do not need to repeat expensive steps to obtain certain information. Because of the caching, this is a throw-away class that should only have a lifetime equal to a single model execution.

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

Author:
Wouter Schakel
  • Constructor Details

    • TacticalContextEgo

      public TacticalContextEgo(LaneBasedGtu gtu)
      Constructor.
      Parameters:
      gtu - GTU
  • Method Details

    • getUnsafeGtu

      public LaneBasedGtu getUnsafeGtu()
      Returns the GTU. This is tagged as unsafe because models should not typically interfere with the simulation structure. Still, sometimes information or commands are required outside of the tactical context. This should only be done with care and full understanding of what is being done.
      Returns:
      GTU
    • getPerception

      public LanePerception getPerception()
      Returns the perception.
      Returns:
      perception
    • getTime

      public org.djunits.value.vdouble.scalar.Duration getTime()
      Returns the current time.
      Returns:
      current time
    • getCarFollowingAcceleration

      public org.djunits.value.vdouble.scalar.Acceleration getCarFollowingAcceleration() throws ParameterException
      Returns the car-following acceleration from the car-following model and leaders perceived by the neighbor category.
      Returns:
      car-following acceleration from the car-following model
      Throws:
      NoSuchElementException - when neighbors perception is not present
      ParameterException - if a parameter is not present
    • getPosition

      public LanePosition getPosition()
      Returns the current position.
      Returns:
      current position
    • addIntent

      public void addIntent(Object intent, org.djunits.value.vdouble.scalar.Length distance)
      Add value for intent. The type (class) of the value determines the type of intent.
      Parameters:
      intent - intent value
      distance - distance at which the intent applies
    • getIntent

      public <T> Optional<DistancedObject<T>> getIntent(Class<T> clazz)
      Returns the nearest value of intent of type given by the class.
      Type Parameters:
      T - value type
      Parameters:
      clazz - class of type
      Returns:
      nearest value of intent of type given by the class, empty if no such intent
      Throws:
      NullPointerException - when any input is null
    • getIntent

      public <T> Optional<DistancedObject<T>> getIntent(Class<T> clazz, org.djunits.value.vdouble.scalar.Length horizon)
      Returns the nearest value of intent of type given by the class, if within a distance.
      Type Parameters:
      T - value type
      Parameters:
      clazz - class of type
      horizon - obtain intent only within this distance
      Returns:
      nearest value of intent of type given by the class, empty if no such intent
      Throws:
      NullPointerException - when any input is null
    • getId

      public String getId()
      Specified by:
      getId in interface Identifiable
    • getGtuType

      public GtuType getGtuType()
      Description copied from interface: TacticalContext
      Returns the GTU type.
      Specified by:
      getGtuType in interface TacticalContext
      Returns:
      GTU type
    • getParameters

      public Parameters getParameters()
      Description copied from interface: TacticalContext
      Returns the parameters.
      Specified by:
      getParameters in interface TacticalContext
      Returns:
      parameters
    • getCarFollowingModel

      public CarFollowingModel getCarFollowingModel()
      Description copied from interface: TacticalContext
      Returns the car-following model.
      Specified by:
      getCarFollowingModel in interface TacticalContext
      Returns:
      car-following model
    • getSpeedLimits

      public SpeedLimits getSpeedLimits()
      Description copied from interface: TacticalContext
      Returns the speed limits at the current location.
      Specified by:
      getSpeedLimits in interface TacticalContext
      Returns:
      speed limits
    • getDesiredSpeed

      public org.djunits.value.vdouble.scalar.Speed getDesiredSpeed() throws ParameterException
      Description copied from interface: TacticalContext
      Returns the desired speed from the car-following model.
      Specified by:
      getDesiredSpeed in interface TacticalContext
      Returns:
      desired speed from the car-following model
      Throws:
      ParameterException - if a parameter is not present
    • getRoute

      public Optional<Route> getRoute()
      Description copied from interface: TacticalContext
      Returns the route.
      Specified by:
      getRoute in interface TacticalContext
      Returns:
      route
    • getLaneChangeDirection

      public LateralDirectionality getLaneChangeDirection()
      Description copied from interface: TacticalContext
      Returns the lane change direction.
      Specified by:
      getLaneChangeDirection in interface TacticalContext
      Returns:
      lane change direction
    • getLength

      public org.djunits.value.vdouble.scalar.Length getLength()
      Description copied from interface: TacticalContext
      Return ego length.
      Specified by:
      getLength in interface TacticalContext
      Returns:
      ego length
    • getWidth

      public org.djunits.value.vdouble.scalar.Length getWidth()
      Description copied from interface: TacticalContext
      Return ego width.
      Specified by:
      getWidth in interface TacticalContext
      Returns:
      ego width
    • getSpeed

      public org.djunits.value.vdouble.scalar.Speed getSpeed()
      Description copied from interface: TacticalContext
      Return ego speed.
      Specified by:
      getSpeed in interface TacticalContext
      Returns:
      ego speed
    • getMaximumSpeed

      public org.djunits.value.vdouble.scalar.Speed getMaximumSpeed()
      Description copied from interface: TacticalContext
      Returns the maximum seed.
      Specified by:
      getMaximumSpeed in interface TacticalContext
      Returns:
      maximum speed
    • getAcceleration

      public org.djunits.value.vdouble.scalar.Acceleration getAcceleration()
      Description copied from interface: TacticalContext
      Return ego acceleration.
      Specified by:
      getAcceleration in interface TacticalContext
      Returns:
      ego acceleration
    • toString

      public String toString()
      Overrides:
      toString in class Object