Package org.opentrafficsim.core.gtu
Class Gtu
java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.core.gtu.Gtu
- All Implemented Interfaces:
Serializable
,Remote
,Locatable
,org.djutils.event.EventProducer
,HierarchicallyTyped<GtuType,
,Gtu> Identifiable
,Drawable
,DynamicSpatialObject
,SpatialObject
public class Gtu
extends org.djutils.event.LocalEventProducer
implements HierarchicallyTyped<GtuType,Gtu>, DynamicSpatialObject, Locatable, Serializable, Identifiable, Drawable
Implements the basic functionalities of any GTU: the ability to move on 3D-space according to a plan.
Copyright (c) 2013-2023 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
FieldsModifier 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
ConstructorsConstructorDescriptionGtu
(String id, GtuType gtuType, OtsSimulatorInterface simulator, PerceivableContext perceivableContext, Length length, Length width, Speed maximumSpeed, Length front, 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 Acceleration
final Acceleration
getAcceleration
(Time time) final Bounds
final RelativePosition
Returns the children GTU's.final org.djutils.immutablecollections.ImmutableSet<RelativePosition>
protected GtuErrorHandler
final RelativePosition
getFront()
final String
getId()
final Length
final Acceleration
final Acceleration
final Speed
Note that destroying the next move event of the GTU can be dangerous!final Length
final Length
getOdometer
(Time time) final OperationalPlan
final OperationalPlan
getOperationalPlan
(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> getShape()
Return the shape of the GTU for the validity time of the operational plan.Return the shape of a dynamic object at time 'time'.final OtsSimulatorInterface
final Speed
getSpeed()
final Speed
getStrategicalPlanner
(Time time) TacticalPlanner<?,
?> TacticalPlanner<?,
?> getTacticalPlanner
(Time time) Returns the value for the given tag, these are used for specific use cases of any sort.getType()
final Length
getWidth()
int
hashCode()
void
init
(StrategicalPlanner strategicalPlanner, DirectedPoint initialLocation, 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
(DirectedPoint 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
(Acceleration maximumAcceleration) final void
setMaximumDeceleration
(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
-
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, Length length, Length width, Speed maximumSpeed, Length front, 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, DirectedPoint initialLocation, Speed initialSpeed) throws 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
- DirectedPoint; the initial location (and direction) of the GTUinitialSpeed
- Speed; the initial speed of the GTU- Throws:
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
- Returns:
- the maximum length of the GTU (parallel with driving direction).
-
getWidth
- Returns:
- the maximum width of the GTU (perpendicular to driving direction).
-
getMaximumSpeed
- Returns:
- the maximum speed of the GTU, in the direction of movement.
-
getBounds
-
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(DirectedPoint fromLocation) throws 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
- DirectedPoint; the last known location (initial location, or end location of the previous operational plan)- Returns:
- boolean; whether an exception occurred
- Throws:
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 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 planSimRuntimeException
- 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 interfaceIdentifiable
- 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
- Returns:
- Length; the current odometer value.
-
getOdometer
- Parameters:
time
- Time; time to obtain the odometer at- Returns:
- Length; the odometer value at given time.
-
getSpeed
- Returns:
- the current speed of the GTU, along the direction of movement.
-
getSpeed
- Parameters:
time
- Time; time at which to obtain the speed- Returns:
- the current speed of the GTU, along the direction of movement.
-
getAcceleration
- Returns:
- the current acceleration of the GTU, along the direction of movement.
-
getAcceleration
- Parameters:
time
- Time; time at which to obtain the acceleration- Returns:
- the current acceleration of the GTU, along the direction of movement.
-
getMaximumAcceleration
- Returns:
- maximumAcceleration
-
setMaximumAcceleration
- Parameters:
maximumAcceleration
- Acceleration; set maximumAcceleration
-
getMaximumDeceleration
- Returns:
- maximumDeceleration
-
setMaximumDeceleration
Set the maximum deceleration.- Parameters:
maximumDeceleration
- Acceleration; set maximumDeceleration, must be a negative number
-
getLocation
- Specified by:
getLocation
in interfaceLocatable
-
getShape
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
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
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
-