Class AbstractGTU

    • 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 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
        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 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
        Throws:
        GTUException - when the preconditions of the constructor are not met
    • Method Detail

      • 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 GTU
        initialSpeed - Speed; the initial speed of the GTU
        Throws:
        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
      • destroy

        public void destroy()
        Destructor. Don't forget to call with super.destroy() from any override to avoid memory leaks in the network.
        Specified by:
        destroy in interface GTU
      • 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 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
      • getGTUType

        public GTUType getGTUType()
        Specified by:
        getGTUType in interface GTU
        Returns:
        the type of GTU, e.g. TruckType, CarType, BusType.
      • getReference

        public final RelativePosition getReference()
        Specified by:
        getReference in interface GTU
        Returns:
        the reference position of the GTU, by definition (0, 0, 0).
      • setParameters

        public final void setParameters​(Parameters parameters)
        Specified by:
        setParameters in interface GTU
        Parameters:
        parameters - Parameters; parameters
      • getStrategicalPlanner

        public StrategicalPlanner getStrategicalPlanner()
        Specified by:
        getStrategicalPlanner in interface GTU
        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​(Time time)
        Specified by:
        getStrategicalPlanner in interface GTU
        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

        public final OperationalPlan getOperationalPlan​(Time time)
        Specified by:
        getOperationalPlan in interface GTU
        Parameters:
        time - Time; time to obtain the operational plan at
        Returns:
        the operational plan for the GTU at the given time.
      • getOdometer

        public final Length getOdometer()
        Specified by:
        getOdometer in interface GTU
        Returns:
        Length; the current odometer value.
      • getOdometer

        public final Length getOdometer​(Time time)
        Specified by:
        getOdometer in interface GTU
        Parameters:
        time - Time; time to obtain the odometer at
        Returns:
        Length; the odometer value at given time.
      • getSpeed

        public final Speed getSpeed()
        Specified by:
        getSpeed in interface GTU
        Returns:
        the current speed of the GTU, along the direction of movement.
      • getSpeed

        public final Speed getSpeed​(Time time)
        Specified by:
        getSpeed in interface GTU
        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 Acceleration getAcceleration()
        Specified by:
        getAcceleration in interface GTU
        Returns:
        the current acceleration of the GTU, along the direction of movement.
      • getAcceleration

        public final Acceleration getAcceleration​(Time time)
        Specified by:
        getAcceleration in interface GTU
        Parameters:
        time - Time; time at which to obtain the acceleration
        Returns:
        the current acceleration of the GTU, along the direction of movement.
      • setMaximumAcceleration

        public final void setMaximumAcceleration​(Acceleration maximumAcceleration)
        Parameters:
        maximumAcceleration - Acceleration; set maximumAcceleration
      • setMaximumDeceleration

        public final void setMaximumDeceleration​(Acceleration maximumDeceleration)
        Set the maximum deceleration.
        Parameters:
        maximumDeceleration - Acceleration; set maximumDeceleration, must be a negative number
      • isDestroyed

        public final boolean isDestroyed()
        Returns whether the GTU is destroyed.
        Specified by:
        isDestroyed in interface GTU
        Returns:
        whether the GTU is destroyed
      • addGtu

        public void addGtu​(GTU gtu)
                    throws GTUException
        Adds the provided GTU to this GTU, meaning it moves with this GTU.
        Specified by:
        addGtu in interface 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.
        Specified by:
        removeGtu in interface GTU
        Parameters:
        gtu - GTU; gtu to exit this GTU
      • setParent

        public void setParent​(GTU gtu)
                       throws GTUException
        Set the parent GTU.
        Specified by:
        setParent in interface 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.
        Specified by:
        getParent in interface GTU
        Returns:
        GTU; parent GTU, or null if this GTU has no parent
      • getChildren

        public Set<GTU> getChildren()
        Returns the children GTU's.
        Specified by:
        getChildren in interface GTU
        Returns:
        Set<GTU>; children GTU's
      • getErrorHandler

        protected GTUErrorHandler getErrorHandler()
        Returns:
        errorHandler.
      • setErrorHandler

        public void setErrorHandler​(GTUErrorHandler errorHandler)
        Sets the error handler.
        Specified by:
        setErrorHandler in interface GTU
        Parameters:
        errorHandler - GTUErrorHandler; error handler
      • getNextMoveEvent

        public final SimEvent<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