Package org.opentrafficsim.core.gtu
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 Summary
Modifier and TypeFieldDescriptionstatic int
aligned schedule count.static boolean
aligned or not.static org.djutils.event.EventType
The event type for pub/sub indicating destruction of the GTU.static org.djutils.event.EventType
The event type for pub/sub indicating a move.Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION
-
Constructor Summary
ConstructorDescriptionGtu
(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) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the provided GTU to this GTU, meaning it moves with this GTU.void
destroy()
Destructor.boolean
final org.djunits.value.vdouble.scalar.Acceleration
final org.djunits.value.vdouble.scalar.Acceleration
getAcceleration
(org.djunits.value.vdouble.scalar.Time time) final OtsBounds2d
final RelativePosition
Returns the children GTU's.final org.djutils.immutablecollections.ImmutableSet<RelativePosition>
protected GtuErrorHandler
final RelativePosition
getFront()
final String
getId()
final org.djunits.value.vdouble.scalar.Length
org.djutils.draw.point.OrientedPoint2d
final org.djunits.value.vdouble.scalar.Acceleration
final org.djunits.value.vdouble.scalar.Acceleration
final org.djunits.value.vdouble.scalar.Speed
final nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent<org.djunits.value.vdouble.scalar.Duration>
Note that destroying the next move event of the GTU can be dangerous!final org.djunits.value.vdouble.scalar.Length
final org.djunits.value.vdouble.scalar.Length
getOdometer
(org.djunits.value.vdouble.scalar.Time time) final OperationalPlan
final OperationalPlan
getOperationalPlan
(org.djunits.value.vdouble.scalar.Time time) final Parameters
Returns the parent GTU, ornull
if this GTU has no parent.final RelativePosition
getRear()
final RelativePosition
final org.djutils.immutablecollections.ImmutableMap<RelativePosition.Type,
RelativePosition> org.djutils.draw.line.Polygon2d
getShape()
Return the shape of the GTU for the validity time of the operational plan.org.djutils.draw.line.Polygon2d
getShape
(org.djunits.value.vdouble.scalar.Time time) Return the shape of a dynamic object at time 'time'.final OtsSimulatorInterface
final org.djunits.value.vdouble.scalar.Speed
getSpeed()
final org.djunits.value.vdouble.scalar.Speed
getSpeed
(org.djunits.value.vdouble.scalar.Time time) getStrategicalPlanner
(org.djunits.value.vdouble.scalar.Time time) TacticalPlanner<?,
?> TacticalPlanner<?,
?> getTacticalPlanner
(org.djunits.value.vdouble.scalar.Time time) Returns the value for the given tag, these are used for specific use cases of any sort.getType()
final org.djunits.value.vdouble.scalar.Length
getWidth()
int
hashCode()
void
init
(StrategicalPlanner strategicalPlanner, org.djutils.draw.point.OrientedPoint2d initialLocation, org.djunits.value.vdouble.scalar.Speed initialSpeed) Initialize the GTU at a location and speed, and give it a mission to fulfill through the strategical planner.protected void
Interrupt the move and ask for a new plan.final boolean
Returns whether the GTU is destroyed.protected boolean
move
(org.djutils.draw.point.OrientedPoint2d fromLocation) 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.void
Removes the provided GTU from this GTU, meaning it no longer moves with this GTU.void
setErrorHandler
(GtuErrorHandler errorHandler) Sets the error handler.final void
setMaximumAcceleration
(org.djunits.value.vdouble.scalar.Acceleration maximumAcceleration) final void
setMaximumDeceleration
(org.djunits.value.vdouble.scalar.Acceleration maximumDeceleration) Set the maximum deceleration.protected void
setOperationalPlan
(OperationalPlan operationalPlan) Set the operational plan.final void
setParameters
(Parameters parameters) void
Set the parent GTU.void
Sets a tag, these are used for specific use cases of any sort.Methods inherited from class org.djutils.event.LocalEventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opentrafficsim.core.DynamicSpatialObject
transformShape
Methods inherited from interface org.opentrafficsim.base.HierarchicallyTyped
isOfType
Methods inherited from interface nl.tudelft.simulation.dsol.animation.Locatable
getDirZ, getZ
-
Field Details
-
ALIGNED
public static boolean ALIGNEDaligned or not. -
ALIGN_COUNT
public static int ALIGN_COUNTaligned schedule count. -
MOVE_EVENT
public static org.djutils.event.EventType MOVE_EVENTThe 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_EVENTThe 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 GTUgtuType
- GtuType; the type of GTU, e.g. TruckType, CarType, BusTypesimulator
- OtsSimulatorInterface; the simulator to schedule plan changes onperceivableContext
- PerceivableContext; the perceivable context in which this GTU will be registeredlength
- 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 positioncenterOfGravity
- 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 GTUinitialSpeed
- Speed; the initial speed of the GTU- Throws:
nl.tudelft.simulation.dsol.SimRuntimeException
- when scheduling after the first move failsGtuException
- when the preconditions of the parameters are not met or when the construction of the original waiting path fails
-
getFront
- Returns:
- the front position of the GTU, relative to its reference point.
-
getRear
- Returns:
- the rear position of the GTU, relative to its reference point.
-
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
- 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
- Specified by:
getBounds
in interfacenl.tudelft.simulation.dsol.animation.Locatable
- Specified by:
getBounds
in interfaceOtsLocatable
-
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 failsOperationalPlanException
- when there is a problem creating a good path for the GTUGtuException
- when there is a problem with the state of the GTU when planning a pathNetworkException
- in case of a problem with the network, e.g., a dead end where it is not expectedParameterException
- in there is a parameter problem
-
interruptMove
protected void interruptMove() throws nl.tudelft.simulation.dsol.SimRuntimeException, OperationalPlanException, GtuException, NetworkException, ParameterExceptionInterrupt 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 plannl.tudelft.simulation.dsol.SimRuntimeException
- when scheduling of the next move failsOperationalPlanException
- when there is a problem creating a good path for the GTUGtuException
- when there is a problem with the state of the GTU when planning a pathNetworkException
- in case of a problem with the network, e.g., unreachability of a certain pointParameterException
- when there is a problem with a parameter
-
getId
- Specified by:
getId
in interfaceorg.djutils.base.Identifiable
- Returns:
- the id of the GTU
-
setTag
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
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
- Specified by:
getType
in interfaceHierarchicallyTyped<GtuType,
Gtu>
-
getReference
- Returns:
- the reference position of the GTU, by definition (0, 0, 0).
-
getSimulator
- Returns:
- the simulator of the GTU.
-
getParameters
- Returns:
- Parameters.
-
setParameters
- Parameters:
parameters
- Parameters; parameters
-
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
- 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
- Returns:
- TacticalPlanner; the current tactical planner that can generate an operational plan
-
getTacticalPlanner
- 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
- Returns:
- the current operational plan for the GTU
-
getOperationalPlan
- Parameters:
time
- Time; time to obtain the operational plan at- Returns:
- the operational plan for the GTU at the given time.
-
setOperationalPlan
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 interfacenl.tudelft.simulation.dsol.animation.Locatable
- Specified by:
getLocation
in interfaceOtsLocatable
-
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 interfaceDynamicSpatialObject
- 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 interfaceSpatialObject
- 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
- Returns:
- the context to which the GTU belongs
-
addGtu
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
Removes the provided GTU from this GTU, meaning it no longer moves with this GTU.- Parameters:
gtu
- Gtu; gtu to exit this GTU
-
setParent
Set the parent GTU.- Parameters:
gtu
- Gtu; parent GTU, may benull
- Throws:
GtuException
- if the gtu already has a parent
-
getParent
Returns the parent GTU, ornull
if this GTU has no parent.- Returns:
- Gtu; parent GTU, or
null
if this GTU has no parent
-
getChildren
Returns the children GTU's.- Returns:
- Set<GTU>; children GTU's
-
getErrorHandler
- Returns:
- errorHandler.
-
setErrorHandler
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() -
equals
-