Package org.opentrafficsim.core.gtu
Class AbstractGtu
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.opentrafficsim.core.gtu.AbstractGtu
-
- All Implemented Interfaces:
Serializable,Locatable,EventProducerInterface,Identifiable,Drawable,Gtu,InternalGtu
public abstract class AbstractGtu extends EventProducer implements InternalGtu
Implements the basic functionalities of any GTU: the ability to move on 3D-space according to a plan.Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Version:
- $Revision: 6525 $, $LastChangedDate: 2020-08-03 14:36:40 +0200 (Mon, 03 Aug 2020) $, by $Author: pknoppers $,
initial version Oct 22, 2014
- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intALIGN_COUNTaligned schedule count.static booleanALIGNEDaligned or not.protected Historical<OperationalPlan>operationalPlanThe current operational plan, which provides a short-term movement over time.-
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl
-
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
Fields inherited from interface org.opentrafficsim.core.gtu.Gtu
DESTROY_EVENT, INIT_EVENT, MOVE_EVENT
-
-
Constructor Summary
Constructors Constructor Description AbstractGtu(String id, GtuType gtuType, OTSSimulatorInterface simulator, PerceivableContext perceivableContext)AbstractGtu(IdGenerator idGenerator, GtuType gtuType, OTSSimulatorInterface simulator, PerceivableContext perceivableContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGtu(Gtu gtu)Adds the provided GTU to this GTU, meaning it moves with this GTU.voiddestroy()Destructor.booleanequals(Object obj)AccelerationgetAcceleration()Retrieve the current acceleration of this GTU, along the direction of movement.AccelerationgetAcceleration(Time time)Retrieve the acceleration of this GTU at the specific time, along the direction of movement.Set<Gtu>getChildren()Retrieve the children GTUs of this GTU.protected GtuErrorHandlergetErrorHandler()GtuTypegetGTUType()TODO: expand hierarchy to include length, width, maxSpeed, maxAcceleration, maxDeceleration, referencePoints?StringgetId()OrientedPoint3dgetLocation()AccelerationgetMaximumAcceleration()AccelerationgetMaximumDeceleration()SimEvent<SimTimeDoubleUnit>getNextMoveEvent()Note that destroying the next move event of the GTU can be dangerous!LengthgetOdometer()Retrieve the current odometer value of this GTU.LengthgetOdometer(Time time)Retrieve the odometer value of this GTU at the specific time.OperationalPlangetOperationalPlan()Retrieve the current operational plan of this GTU.OperationalPlangetOperationalPlan(Time time)Retrieve the operational plan at a specific time.ParametersgetParameters()Retrieve the parameters of this GTU.GtugetParent()Retrieve the parent GTU, ornullif this GTU has no parent.PerceivableContextgetPerceivableContext()RelativePositiongetReference()OTSSimulatorInterfacegetSimulator()SerializablegetSourceId()SpeedgetSpeed()Retrieve the current speed of the GTU, along the direction of movement.SpeedgetSpeed(Time time)Retrieve the speed of this GTU at a specific time.StrategicalPlannergetStrategicalPlanner()Retrieve the strategical planner of this GTU.StrategicalPlannergetStrategicalPlanner(Time time)Retrieve the strategical planner of this GTU at a specific time.inthashCode()voidinit(StrategicalPlanner strategicalPlanner, OrientedPoint3d initialLocation, Speed initialSpeed)Initialize the GTU at a location and speed, and give it a mission to fulfill through the strategical planner.protected voidinterruptMove()Interrupt the move and ask for a new plan.booleanisDestroyed()Returns whether the GTU is destroyed.protected booleanmove(OrientedPoint3d 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.voidremoveGtu(Gtu gtu)Removes the provided GTU from this GTU, meaning it no longer moves with this GTU.voidsetErrorHandler(GtuErrorHandler errorHandler)Sets the error handler.voidsetMaximumAcceleration(Acceleration maximumAcceleration)voidsetMaximumDeceleration(Acceleration maximumDeceleration)Set the maximum deceleration.voidsetParameters(Parameters parameters)Set the parameters of this GTU.voidsetParent(Gtu gtu)Set the parent GTU.-
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, 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.djutils.event.EventProducerInterface
addListener, addListener, addListener, addListener, getEventTypesWithListeners, hasListeners, numberOfListeners, removeListener
-
Methods inherited from interface org.opentrafficsim.core.gtu.Gtu
getBounds, getCenter, getContourPoints, getFront, getLength, getMaximumSpeed, getRear, getRelativePositions, getWidth
-
Methods inherited from interface org.opentrafficsim.core.gtu.InternalGtu
getTacticalPlanner, getTacticalPlanner
-
-
-
-
Field Detail
-
operationalPlan
protected final Historical<OperationalPlan> operationalPlan
The current operational plan, which provides a short-term movement over time.
-
ALIGNED
public static boolean ALIGNED
aligned or not.
-
ALIGN_COUNT
public static int ALIGN_COUNT
aligned schedule count.
-
-
Constructor Detail
-
AbstractGtu
public AbstractGtu(String id, GtuType gtuType, OTSSimulatorInterface simulator, PerceivableContext perceivableContext) 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 registered- Throws:
GtuException- when the preconditions of the constructor are not met
-
AbstractGtu
public AbstractGtu(IdGenerator idGenerator, GtuType gtuType, OTSSimulatorInterface simulator, PerceivableContext perceivableContext) throws GtuException
- Parameters:
idGenerator- IdGenerator; the generator that will produce a unique 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 registered- Throws:
GtuException- when the preconditions of the constructor are not met
-
-
Method Detail
-
init
public void init(StrategicalPlanner strategicalPlanner, OrientedPoint3d 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- OrientedPoint3d; 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
-
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(OrientedPoint3d 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- OrientedPoint3d; 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
public final String getId()
- Specified by:
getIdin interfaceGtu- Specified by:
getIdin interfaceIdentifiable- Returns:
- the id of the GTU
-
getGTUType
public GtuType getGTUType()
TODO: expand hierarchy to include length, width, maxSpeed, maxAcceleration, maxDeceleration, referencePoints?- Specified by:
getGTUTypein interfaceGtu- Returns:
- the type of GTU, e.g. TruckType, CarType, BusType.
-
getReference
public final RelativePosition getReference()
- Specified by:
getReferencein interfaceGtu- Returns:
- the reference position of the GTU, by definition (0, 0, 0).
-
getSimulator
public final OTSSimulatorInterface getSimulator()
- Specified by:
getSimulatorin interfaceGtu- Returns:
- the simulator of the GTU.
-
getParameters
public final Parameters getParameters()
Retrieve the parameters of this GTU.- Specified by:
getParametersin interfaceInternalGtu- Returns:
- Parameters; the parameters of this GTU
-
setParameters
public final void setParameters(Parameters parameters)
Set the parameters of this GTU.- Specified by:
setParametersin interfaceInternalGtu- Parameters:
parameters- Parameters; the new parameters
-
getStrategicalPlanner
public StrategicalPlanner getStrategicalPlanner()
Retrieve the strategical planner of this GTU. This is 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.- Specified by:
getStrategicalPlannerin interfaceInternalGtu- Returns:
- StrategicalPlanner; the strategical planner
-
getStrategicalPlanner
public StrategicalPlanner getStrategicalPlanner(Time time)
Retrieve the strategical planner of this GTU at a specific time. TODO explain who might use this method.- Specified by:
getStrategicalPlannerin interfaceInternalGtu- Parameters:
time- Time; time to obtain the strategical planner at- Returns:
- StrategicalPlanner; the strategical planner
-
getOperationalPlan
public final OperationalPlan getOperationalPlan()
Retrieve the current operational plan of this GTU.- Specified by:
getOperationalPlanin interfaceInternalGtu- Returns:
- OperationalPlan; the current operational plan for the GTU
-
getOperationalPlan
public final OperationalPlan getOperationalPlan(Time time)
Retrieve the operational plan at a specific time. TODO explain who might use this method.- Specified by:
getOperationalPlanin interfaceInternalGtu- Parameters:
time- Time; time to obtain the operational plan at- Returns:
- OperationalPlan; the operational plan for the GTU at the given time
-
getOdometer
public final Length getOdometer()
Retrieve the current odometer value of this GTU.- Specified by:
getOdometerin interfaceInternalGtu- Returns:
- Length; the current odometer value
-
getOdometer
public final Length getOdometer(Time time)
Retrieve the odometer value of this GTU at the specific time. TODO explain who needs this method?- Specified by:
getOdometerin interfaceInternalGtu- Parameters:
time- Time; time to obtain the odometer at- Returns:
- Length; the odometer value at given time
-
getSpeed
public final Speed getSpeed()
Retrieve the current speed of the GTU, along the direction of movement.
-
getSpeed
public final Speed getSpeed(Time time)
Retrieve the speed of this GTU at a specific time.- Specified by:
getSpeedin interfaceInternalGtu- Parameters:
time- Time; time at which to obtain the speed- Returns:
- Time; the current speed of the GTU, along the direction of movement.
-
getAcceleration
public final Acceleration getAcceleration()
Retrieve the current acceleration of this GTU, along the direction of movement.- Specified by:
getAccelerationin interfaceGtu- Returns:
- Acceleration; the current acceleration of the GTU, along the direction of movement
-
getAcceleration
public final Acceleration getAcceleration(Time time)
Retrieve the acceleration of this GTU at the specific time, along the direction of movement.- Specified by:
getAccelerationin interfaceInternalGtu- Parameters:
time- Time; time at which to obtain the acceleration- Returns:
- Acceleration; the acceleration of the GTU at the specified time, along the direction of movement
-
getMaximumAcceleration
public final Acceleration getMaximumAcceleration()
- Specified by:
getMaximumAccelerationin interfaceGtu- Returns:
- maximumAcceleration
-
setMaximumAcceleration
public final void setMaximumAcceleration(Acceleration maximumAcceleration)
- Parameters:
maximumAcceleration- Acceleration; set maximumAcceleration
-
getMaximumDeceleration
public final Acceleration getMaximumDeceleration()
- Specified by:
getMaximumDecelerationin interfaceGtu- Returns:
- maximumDeceleration
-
setMaximumDeceleration
public final void setMaximumDeceleration(Acceleration maximumDeceleration)
Set the maximum deceleration.- Parameters:
maximumDeceleration- Acceleration; set maximumDeceleration, must be a negative number
-
getLocation
public OrientedPoint3d getLocation()
- Specified by:
getLocationin interfaceGtu- Specified by:
getLocationin interfaceLocatable
-
isDestroyed
public final boolean isDestroyed()
Returns whether the GTU is destroyed.- Specified by:
isDestroyedin interfaceGtu- Returns:
- boolean; true if this GTU is destroyed; false if this GTU is not (yet) destroyed
-
getPerceivableContext
public PerceivableContext getPerceivableContext()
- Specified by:
getPerceivableContextin interfaceGtu- 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.- Specified by:
addGtuin interfaceGtu- Parameters:
gtu- GTU; gtu to enter/board 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. TODO should throw some exception if the provided GTU is not aboard this GTU.
-
setParent
public void setParent(Gtu gtu) throws GtuException
Set the parent GTU.- Specified by:
setParentin interfaceGtu- Parameters:
gtu- GTU; parent GTU, may benull- Throws:
GtuException- if this GTU already has a parent
-
getParent
public Gtu getParent()
Retrieve the parent GTU, ornullif this GTU has no parent.
-
getChildren
public Set<Gtu> getChildren()
Retrieve the children GTUs of this GTU.- Specified by:
getChildrenin interfaceGtu- Returns:
- Set<GTU>; children GTUs
-
getErrorHandler
protected GtuErrorHandler getErrorHandler()
- Returns:
- errorHandler.
-
setErrorHandler
public void setErrorHandler(GtuErrorHandler errorHandler)
Sets the error handler.- Specified by:
setErrorHandlerin interfaceInternalGtu- Parameters:
errorHandler- GTUErrorHandler; error handler
-
getSourceId
public final Serializable getSourceId()
- Specified by:
getSourceIdin interfaceEventProducerInterface- Specified by:
getSourceIdin classEventProducer
-
getNextMoveEvent
public final SimEvent<SimTimeDoubleUnit> 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.
-
-