Package org.opentrafficsim.core.gtu
Class AbstractGTU
java.lang.Object
org.djutils.event.EventProducer
org.opentrafficsim.core.gtu.AbstractGTU
- All Implemented Interfaces:
java.io.Serializable,Locatable,EventProducerInterface,Identifiable,Drawable,GTU
- Direct Known Subclasses:
AbstractLinkBasedGTU
public abstract class AbstractGTU extends EventProducer implements GTU
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: 6119 $, $LastChangedDate: 2020-01-24 02:44:57 +0100 (Fri, 24 Jan 2020) $, by $Author: averbraeck $,
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 interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITIONFields inherited from interface org.opentrafficsim.core.gtu.GTU
DESTROY_EVENT, INIT_EVENT, MOVE_EVENT -
Constructor Summary
Constructors Constructor Description AbstractGTU(java.lang.String id, GTUType gtuType, OTSSimulatorInterface simulator, PerceivableContext perceivableContext)AbstractGTU(IdGenerator idGenerator, GTUType gtuType, OTSSimulatorInterface simulator, PerceivableContext perceivableContext) -
Method Summary
Modifier and Type Method Description voidaddGtu(GTU gtu)Adds the provided GTU to this GTU, meaning it moves with this GTU.voiddestroy()Destructor.booleanequals(java.lang.Object obj)AccelerationgetAcceleration()AccelerationgetAcceleration(Time time)java.util.Set<GTU>getChildren()Returns the children GTU's.protected GTUErrorHandlergetErrorHandler()GTUTypegetGTUType()java.lang.StringgetId()DirectedPointgetLocation()AccelerationgetMaximumAcceleration()AccelerationgetMaximumDeceleration()SimEvent<SimTimeDoubleUnit>getNextMoveEvent()Note that destroying the next move event of the GTU can be dangerous!LengthgetOdometer()LengthgetOdometer(Time time)OperationalPlangetOperationalPlan()OperationalPlangetOperationalPlan(Time time)ParametersgetParameters()GTUgetParent()Returns the parent GTU, ornullif this GTU has no parent.PerceivableContextgetPerceivableContext()RelativePositiongetReference()OTSSimulatorInterfacegetSimulator()java.io.SerializablegetSourceId()SpeedgetSpeed()SpeedgetSpeed(Time time)StrategicalPlannergetStrategicalPlanner()StrategicalPlannergetStrategicalPlanner(Time time)inthashCode()voidinit(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 voidinterruptMove()Interrupt the move and ask for a new plan.booleanisDestroyed()Returns whether the GTU is destroyed.protected booleanmove(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.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)voidsetParameters(Parameters parameters)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, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, getEventTypesWithListeners, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListenerMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.djutils.event.EventProducerInterface
addListener, addListener, addListener, addListener, getEventTypesWithListeners, hasListeners, numberOfListeners, removeListenerMethods inherited from interface org.opentrafficsim.core.gtu.GTU
getCenter, getContourPoints, getFront, getLength, getMaximumSpeed, getRear, getRelativePositions, getTacticalPlanner, getTacticalPlanner, getWidth
-
Field Details
-
operationalPlan
The current operational plan, which provides a short-term movement over time. -
ALIGNED
public static boolean ALIGNEDaligned or not. -
ALIGN_COUNT
public static int ALIGN_COUNTaligned schedule count.
-
-
Constructor Details
-
AbstractGTU
public AbstractGTU(java.lang.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 Details
-
init
public void init(StrategicalPlanner strategicalPlanner, DirectedPoint initialLocation, Speed initialSpeed) throws SimRuntimeException, GTUExceptionInitialize 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
-
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, ParameterExceptionMove 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
public final java.lang.String getId()- Specified by:
getIdin interfaceGTU- Specified by:
getIdin interfaceIdentifiable- Returns:
- the id of the GTU
-
getGTUType
- Specified by:
getGTUTypein interfaceGTU- Returns:
- the type of GTU, e.g. TruckType, CarType, BusType.
-
getReference
- Specified by:
getReferencein interfaceGTU- Returns:
- the reference position of the GTU, by definition (0, 0, 0).
-
getSimulator
- Specified by:
getSimulatorin interfaceGTU- Returns:
- the simulator of the GTU.
-
getParameters
- Specified by:
getParametersin interfaceGTU- Returns:
- Parameters.
-
setParameters
- Specified by:
setParametersin interfaceGTU- Parameters:
parameters- Parameters; parameters
-
getStrategicalPlanner
- Specified by:
getStrategicalPlannerin interfaceGTU- 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
- Specified by:
getStrategicalPlannerin interfaceGTU- 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.
-
getOperationalPlan
- Specified by:
getOperationalPlanin interfaceGTU- Returns:
- the current operational plan for the GTU
-
getOperationalPlan
- Specified by:
getOperationalPlanin interfaceGTU- Parameters:
time- Time; time to obtain the operational plan at- Returns:
- the operational plan for the GTU at the given time.
-
getOdometer
- Specified by:
getOdometerin interfaceGTU- Returns:
- Length; the current odometer value.
-
getOdometer
- Specified by:
getOdometerin interfaceGTU- Parameters:
time- Time; time to obtain the odometer at- Returns:
- Length; the odometer value at given time.
-
getSpeed
-
getSpeed
-
getAcceleration
- Specified by:
getAccelerationin interfaceGTU- Returns:
- the current acceleration of the GTU, along the direction of movement.
-
getAcceleration
- Specified by:
getAccelerationin interfaceGTU- Parameters:
time- Time; time at which to obtain the acceleration- Returns:
- the current acceleration of the GTU, along the direction of movement.
-
getMaximumAcceleration
- Specified by:
getMaximumAccelerationin interfaceGTU- Returns:
- maximumAcceleration
-
setMaximumAcceleration
- Parameters:
maximumAcceleration- Acceleration; set maximumAcceleration
-
getMaximumDeceleration
- Specified by:
getMaximumDecelerationin interfaceGTU- Returns:
- maximumDeceleration
-
setMaximumDeceleration
- Parameters:
maximumDeceleration- Acceleration; set maximumDeceleration, stored as a negative number
-
getLocation
- Specified by:
getLocationin interfaceLocatable
-
isDestroyed
public final boolean isDestroyed()Returns whether the GTU is destroyed.- Specified by:
isDestroyedin interfaceGTU- Returns:
- whether the GTU is destroyed
-
getPerceivableContext
- Specified by:
getPerceivableContextin interfaceGTU- Returns:
- the context to which the GTU belongs
-
addGtu
Adds the provided GTU to this GTU, meaning it moves with this GTU.- Specified by:
addGtuin interfaceGTU- 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. -
setParent
Set the parent GTU.- Specified by:
setParentin interfaceGTU- Parameters:
gtu- GTU; parent GTU, may benull- Throws:
GTUException- if the gtu already has a parent
-
getParent
Returns the parent GTU, ornullif this GTU has no parent. -
getChildren
Returns the children GTU's.- Specified by:
getChildrenin interfaceGTU- Returns:
- Set<GTU>; children GTU's
-
getErrorHandler
- Returns:
- errorHandler.
-
setErrorHandler
Sets the error handler.- Specified by:
setErrorHandlerin interfaceGTU- Parameters:
errorHandler- GTUErrorHandler; error handler
-
getSourceId
public final java.io.Serializable getSourceId()- Specified by:
getSourceIdin interfaceEventProducerInterface- Specified by:
getSourceIdin classEventProducer
-
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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-