Class Gtu

java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.core.gtu.Gtu
All Implemented Interfaces:
Serializable, Remote, nl.tudelft.simulation.dsol.animation.Locatable, org.djutils.base.Identifiable, org.djutils.event.EventProducer, OtsLocatable, HierarchicallyTyped<GtuType,Gtu>, Drawable, DynamicSpatialObject, SpatialObject

public class Gtu extends org.djutils.event.LocalEventProducer implements HierarchicallyTyped<GtuType,Gtu>, DynamicSpatialObject, OtsLocatable, Serializable, org.djutils.base.Identifiable, Drawable
Implements the basic functionalities of any GTU: the ability to move on 3D-space according to a plan.

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
See Also:
  • Field Details

    • ALIGNED

      public static boolean ALIGNED
      aligned or not.
    • ALIGN_COUNT

      public static int ALIGN_COUNT
      aligned schedule count.
    • MOVE_EVENT

      public static org.djutils.event.EventType MOVE_EVENT
      The event type for pub/sub indicating a move.
      Payload: [String id, DirectedPoint position, Speed speed, Acceleration acceleration, Length odometer]
    • DESTROY_EVENT

      public static org.djutils.event.EventType DESTROY_EVENT
      The event type for pub/sub indicating destruction of the GTU.
      Payload: [String id, DirectedPoint lastPosition, Length odometer]
  • Constructor Details

    • Gtu

      public Gtu(String id, GtuType gtuType, OtsSimulatorInterface simulator, PerceivableContext perceivableContext, org.djunits.value.vdouble.scalar.Length length, org.djunits.value.vdouble.scalar.Length width, org.djunits.value.vdouble.scalar.Speed maximumSpeed, org.djunits.value.vdouble.scalar.Length front, org.djunits.value.vdouble.scalar.Length centerOfGravity) throws GtuException
      Parameters:
      id - String; the id of the GTU
      gtuType - GtuType; the type of GTU, e.g. TruckType, CarType, BusType
      simulator - OtsSimulatorInterface; the simulator to schedule plan changes on
      perceivableContext - PerceivableContext; the perceivable context in which this GTU will be registered
      length - Length; the maximum length of the GTU (parallel with driving direction)
      width - Length; the maximum width of the GTU (perpendicular to driving direction)
      maximumSpeed - Speed;the maximum speed of the GTU (in the driving direction)
      front - Length; front distance relative to the reference position
      centerOfGravity - Length; distance from the center of gravity to the reference position
      Throws:
      GtuException - when the preconditions of the constructor are not met
  • Method Details

    • init

      public void init(StrategicalPlanner strategicalPlanner, org.djutils.draw.point.OrientedPoint2d initialLocation, org.djunits.value.vdouble.scalar.Speed initialSpeed) throws nl.tudelft.simulation.dsol.SimRuntimeException, GtuException
      Initialize the GTU at a location and speed, and give it a mission to fulfill through the strategical planner.
      Parameters:
      strategicalPlanner - StrategicalPlanner; the strategical planner responsible for the overall 'mission' of the GTU, usually indicating where it needs to go. It operates by instantiating tactical planners to do the work.
      initialLocation - OrientedPoint2d; the initial location (and direction) of the GTU
      initialSpeed - Speed; the initial speed of the GTU
      Throws:
      nl.tudelft.simulation.dsol.SimRuntimeException - when scheduling after the first move fails
      GtuException - when the preconditions of the parameters are not met or when the construction of the original waiting path fails
    • getFront

      public final RelativePosition getFront()
      Returns:
      the front position of the GTU, relative to its reference point.
    • getRear

      public final RelativePosition getRear()
      Returns:
      the rear position of the GTU, relative to its reference point.
    • getCenter

      public final RelativePosition getCenter()
      Returns:
      the center position of the GTU, relative to its reference point.
    • getRelativePositions

      public final org.djutils.immutablecollections.ImmutableMap<RelativePosition.Type,RelativePosition> getRelativePositions()
      Returns:
      the positions for this GTU, but not the contour points.
    • getContourPoints

      public final org.djutils.immutablecollections.ImmutableSet<RelativePosition> getContourPoints()
      Returns:
      the contour points of the GTU.
    • getLength

      public final org.djunits.value.vdouble.scalar.Length getLength()
      Returns:
      the maximum length of the GTU (parallel with driving direction).
    • getWidth

      public final org.djunits.value.vdouble.scalar.Length getWidth()
      Returns:
      the maximum width of the GTU (perpendicular to driving direction).
    • getMaximumSpeed

      public final org.djunits.value.vdouble.scalar.Speed getMaximumSpeed()
      Returns:
      the maximum speed of the GTU, in the direction of movement.
    • getBounds

      public final OtsBounds2d getBounds()
      Specified by:
      getBounds in interface nl.tudelft.simulation.dsol.animation.Locatable
      Specified by:
      getBounds in interface OtsLocatable
    • destroy

      public void destroy()
      Destructor. Don't forget to call with super.destroy() from any override to avoid memory leaks in the network.
    • move

      protected boolean move(org.djutils.draw.point.OrientedPoint2d fromLocation) throws nl.tudelft.simulation.dsol.SimRuntimeException, OperationalPlanException, GtuException, NetworkException, ParameterException
      Move from the current location according to an operational plan to a location that will bring us nearer to reaching the location provided by the strategical planner.
      This method can be overridden to carry out specific behavior during the execution of the plan (e.g., scheduling of triggers, entering or leaving lanes, etc.). Please bear in mind that the call to super.move() is essential, and that one has to take care to handle the situation that the plan gets interrupted.
      Parameters:
      fromLocation - OrientedPoint2d; the last known location (initial location, or end location of the previous operational plan)
      Returns:
      boolean; whether an exception occurred
      Throws:
      nl.tudelft.simulation.dsol.SimRuntimeException - when scheduling of the next move fails
      OperationalPlanException - when there is a problem creating a good path for the GTU
      GtuException - when there is a problem with the state of the GTU when planning a path
      NetworkException - in case of a problem with the network, e.g., a dead end where it is not expected
      ParameterException - in there is a parameter problem
    • interruptMove

      protected void interruptMove() throws nl.tudelft.simulation.dsol.SimRuntimeException, OperationalPlanException, GtuException, NetworkException, ParameterException
      Interrupt the move and ask for a new plan. This method can be overridden to carry out the bookkeeping needed when the current plan gets interrupted.
      Throws:
      OperationalPlanException - when there was a problem retrieving the location from the running plan
      nl.tudelft.simulation.dsol.SimRuntimeException - when scheduling of the next move fails
      OperationalPlanException - when there is a problem creating a good path for the GTU
      GtuException - when there is a problem with the state of the GTU when planning a path
      NetworkException - in case of a problem with the network, e.g., unreachability of a certain point
      ParameterException - when there is a problem with a parameter
    • getId

      public final String getId()
      Specified by:
      getId in interface org.djutils.base.Identifiable
      Returns:
      the id of the GTU
    • setTag

      public void setTag(String tag, String value)
      Sets a tag, these are used for specific use cases of any sort.
      Parameters:
      tag - String; name of the tag.
      value - String; value of the tag.
    • getTag

      public String getTag(String tag)
      Returns the value for the given tag, these are used for specific use cases of any sort.
      Parameters:
      tag - String; name of the tag.
      Returns:
      String; value of the tag, or null if it is not given to the GTU.
    • getType

      public GtuType getType()
      Specified by:
      getType in interface HierarchicallyTyped<GtuType,Gtu>
    • getReference

      public final RelativePosition getReference()
      Returns:
      the reference position of the GTU, by definition (0, 0, 0).
    • getSimulator

      public final OtsSimulatorInterface getSimulator()
      Returns:
      the simulator of the GTU.
    • getParameters

      public final Parameters getParameters()
      Returns:
      Parameters.
    • setParameters

      public final void setParameters(Parameters parameters)
      Parameters:
      parameters - Parameters; parameters
    • getStrategicalPlanner

      public StrategicalPlanner getStrategicalPlanner()
      Returns:
      StrategicalPlanner; the planner responsible for the overall 'mission' of the GTU, usually indicating where it needs to go. It operates by instantiating tactical planners to do the work.
    • getStrategicalPlanner

      public StrategicalPlanner getStrategicalPlanner(org.djunits.value.vdouble.scalar.Time time)
      Parameters:
      time - Time; time to obtain the strategical planner at
      Returns:
      StrategicalPlanner; the planner responsible for the overall 'mission' of the GTU, usually indicating where it needs to go. It operates by instantiating tactical planners to do the work.
    • getTacticalPlanner

      public TacticalPlanner<?,?> getTacticalPlanner()
      Returns:
      TacticalPlanner; the current tactical planner that can generate an operational plan
    • getTacticalPlanner

      public TacticalPlanner<?,?> getTacticalPlanner(org.djunits.value.vdouble.scalar.Time time)
      Parameters:
      time - Time; time to obtain the tactical planner at
      Returns:
      TacticalPlanner; the tactical planner that can generate an operational plan at the given time
    • getOperationalPlan

      public final OperationalPlan getOperationalPlan()
      Returns:
      the current operational plan for the GTU
    • getOperationalPlan

      public final OperationalPlan getOperationalPlan(org.djunits.value.vdouble.scalar.Time time)
      Parameters:
      time - Time; time to obtain the operational plan at
      Returns:
      the operational plan for the GTU at the given time.
    • setOperationalPlan

      protected void setOperationalPlan(OperationalPlan operationalPlan)
      Set the operational plan. This method is for sub classes.
      Parameters:
      operationalPlan - OperationalPlan; operational plan.
    • getOdometer

      public final org.djunits.value.vdouble.scalar.Length getOdometer()
      Returns:
      Length; the current odometer value.
    • getOdometer

      public final org.djunits.value.vdouble.scalar.Length getOdometer(org.djunits.value.vdouble.scalar.Time time)
      Parameters:
      time - Time; time to obtain the odometer at
      Returns:
      Length; the odometer value at given time.
    • getSpeed

      public final org.djunits.value.vdouble.scalar.Speed getSpeed()
      Returns:
      the current speed of the GTU, along the direction of movement.
    • getSpeed

      public final org.djunits.value.vdouble.scalar.Speed getSpeed(org.djunits.value.vdouble.scalar.Time time)
      Parameters:
      time - Time; time at which to obtain the speed
      Returns:
      the current speed of the GTU, along the direction of movement.
    • getAcceleration

      public final org.djunits.value.vdouble.scalar.Acceleration getAcceleration()
      Returns:
      the current acceleration of the GTU, along the direction of movement.
    • getAcceleration

      public final org.djunits.value.vdouble.scalar.Acceleration getAcceleration(org.djunits.value.vdouble.scalar.Time time)
      Parameters:
      time - Time; time at which to obtain the acceleration
      Returns:
      the current acceleration of the GTU, along the direction of movement.
    • getMaximumAcceleration

      public final org.djunits.value.vdouble.scalar.Acceleration getMaximumAcceleration()
      Returns:
      maximumAcceleration
    • setMaximumAcceleration

      public final void setMaximumAcceleration(org.djunits.value.vdouble.scalar.Acceleration maximumAcceleration)
      Parameters:
      maximumAcceleration - Acceleration; set maximumAcceleration
    • getMaximumDeceleration

      public final org.djunits.value.vdouble.scalar.Acceleration getMaximumDeceleration()
      Returns:
      maximumDeceleration
    • setMaximumDeceleration

      public final void setMaximumDeceleration(org.djunits.value.vdouble.scalar.Acceleration maximumDeceleration)
      Set the maximum deceleration.
      Parameters:
      maximumDeceleration - Acceleration; set maximumDeceleration, must be a negative number
    • getLocation

      public org.djutils.draw.point.OrientedPoint2d getLocation()
      Specified by:
      getLocation in interface nl.tudelft.simulation.dsol.animation.Locatable
      Specified by:
      getLocation in interface OtsLocatable
    • getShape

      public org.djutils.draw.line.Polygon2d getShape(org.djunits.value.vdouble.scalar.Time time)
      Return the shape of a dynamic object at time 'time'. Note that the getShape() method without a time returns the Minkowski sum of all shapes of the spatial object for a validity time window, e.g., a contour that describes all locations of a GTU for the next time step, i.e., the contour of the GTU belonging to the next operational plan.
      Specified by:
      getShape in interface DynamicSpatialObject
      Parameters:
      time - Time; the time for which we want the shape
      Returns:
      OtsShape; the shape of the object at time 'time'
    • getShape

      public org.djutils.draw.line.Polygon2d getShape()
      Return the shape of the GTU for the validity time of the operational plan. Note that this method without a time returns the Minkowski sum of all shapes of the spatial object for a validity time window, e.g., a contour that describes all locations of a GTU for the next time step, i.e., the contour of the GTU belonging to the next operational plan.
      Specified by:
      getShape in interface SpatialObject
      Returns:
      OtsShape; the shape of the object over the validity of the operational plan
    • isDestroyed

      public final boolean isDestroyed()
      Returns whether the GTU is destroyed.
      Returns:
      whether the GTU is destroyed
    • getPerceivableContext

      public PerceivableContext getPerceivableContext()
      Returns:
      the context to which the GTU belongs
    • addGtu

      public void addGtu(Gtu gtu) throws GtuException
      Adds the provided GTU to this GTU, meaning it moves with this GTU.
      Parameters:
      gtu - Gtu; gtu to enter this GTU
      Throws:
      GtuException - if the gtu already has a parent
    • removeGtu

      public void removeGtu(Gtu gtu)
      Removes the provided GTU from this GTU, meaning it no longer moves with this GTU.
      Parameters:
      gtu - Gtu; gtu to exit this GTU
    • setParent

      public void setParent(Gtu gtu) throws GtuException
      Set the parent GTU.
      Parameters:
      gtu - Gtu; parent GTU, may be null
      Throws:
      GtuException - if the gtu already has a parent
    • getParent

      public Gtu getParent()
      Returns the parent GTU, or null if this GTU has no parent.
      Returns:
      Gtu; parent GTU, or null if this GTU has no parent
    • getChildren

      public Set<Gtu> getChildren()
      Returns the children GTU's.
      Returns:
      Set<GTU>; children GTU's
    • getErrorHandler

      protected GtuErrorHandler getErrorHandler()
      Returns:
      errorHandler.
    • setErrorHandler

      public void setErrorHandler(GtuErrorHandler errorHandler)
      Sets the error handler.
      Parameters:
      errorHandler - GTUErrorHandler; error handler
    • getNextMoveEvent

      public final nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent<org.djunits.value.vdouble.scalar.Duration> getNextMoveEvent()
      Note that destroying the next move event of the GTU can be dangerous!
      Returns:
      nextMoveEvent the next move event of the GTU, e.g. to cancel it from outside.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object