Class AbstractLaneBasedGTU2

  • All Implemented Interfaces:
    Serializable, Locatable, EventProducerInterface, Identifiable, Drawable, GTU, LaneBasedGTU
    Direct Known Subclasses:
    AbstractLaneBasedIndividualGTU

    public abstract class AbstractLaneBasedGTU2
    extends AbstractGTU
    implements LaneBasedGTU
    This class contains most of the code that is needed to run a lane based GTU.
    The starting point of a LaneBasedTU is that it can be in multiple lanes at the same time. This can be due to a lane change (lateral), or due to crossing a link (front of the GTU is on another Lane than rear of the GTU). If a Lane is shorter than the length of the GTU (e.g. when we do node expansion on a crossing, this is very well possible), a GTU could occupy dozens of Lanes at the same time.

    When calculating a headway, the GTU has to look in successive lanes. When Lanes (or underlying CrossSectionLinks) diverge, the headway algorithms have to look at multiple Lanes and return the minimum headway in each of the Lanes. When the Lanes (or underlying CrossSectionLinks) converge, "parallel" traffic is not taken into account in the headway calculation. Instead, gap acceptance algorithms or their equivalent should guide the merging behavior.

    To decide its movement, an AbstractLaneBasedGTU applies its car following algorithm and lane change algorithm to set the acceleration and any lane change operation to perform. It then schedules the triggers that will add it to subsequent lanes and remove it from current lanes as needed during the time step that is has committed to. Finally, it re-schedules its next movement evaluation with the simulator.

    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: 1408 $, $LastChangedDate: 2015-09-24 15:17:25 +0200 (Thu, 24 Sep 2015) $, by $Author: pknoppers $, initial version Oct 22, 2014
    Author:
    Alexander Verbraeck, Peter Knoppers
    See Also:
    Serialized Form
    • Field Detail

      • initialLocationThresholdDifference

        public static Length initialLocationThresholdDifference
        The threshold distance for differences between initial locations of the GTU on different lanes.
      • eventMargin

        public static Length eventMargin
        Margin to add to plan to check of the path will enter the next section.
      • CACHING

        public static boolean CACHING
        Caching on or off.
      • CACHED_POSITION

        public static int CACHED_POSITION
        cached position count.
      • NON_CACHED_POSITION

        public static int NON_CACHED_POSITION
        cached position count.
    • Constructor Detail

      • AbstractLaneBasedGTU2

        public AbstractLaneBasedGTU2​(String id,
                                     GTUType gtuType,
                                     OTSRoadNetwork network)
                              throws GTUException
        Construct a Lane Based GTU.
        Parameters:
        id - String; the id of the GTU
        gtuType - GTUType; the type of GTU, e.g. TruckType, CarType, BusType
        network - OTSRoadNetwork; the network that the GTU is initially registered in
        Throws:
        GTUException - when initial values are not correct
    • Method Detail

      • finalizeLaneChange

        protected void finalizeLaneChange​(LateralDirectionality laneChangeDirection)
                                   throws GTUException
        Performs the finalization of a lane change by leaving the from lanes.
        Parameters:
        laneChangeDirection - LateralDirectionality; direction of lane change
        Throws:
        GTUException - if position or direction could not be obtained
      • getDirection

        public final GTUDirectionality getDirection​(Lane lane)
                                             throws GTUException
        Return the directionality of a lane on which the GTU is registered for its current operational plan.
        Specified by:
        getDirection in interface LaneBasedGTU
        Parameters:
        lane - Lane; the lane for which we want to know the direction
        Returns:
        GTUDirectionality; the direction on the given lane
        Throws:
        GTUException - in case the GTU is not registered on the Lane
      • positions

        public final Map<Lane,​Length> positions​(RelativePosition relativePosition)
                                               throws GTUException
        Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the vehicle is registered.
        Note: If a GTU is registered in multiple parallel lanes, the lateralLaneChangeModel is used to determine the center line of the vehicle at this point in time. Otherwise, the average of the center positions of the lines will be taken.
        Specified by:
        positions in interface LaneBasedGTU
        Parameters:
        relativePosition - RelativePosition; the position on the vehicle relative to the reference point.
        Returns:
        the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU.
        Throws:
        GTUException - when the vehicle is not on one of the lanes on which it is registered.
      • positions

        public final Map<Lane,​Length> positions​(RelativePosition relativePosition,
                                                      Time when)
                                               throws GTUException
        Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the vehicle is registered.
        Specified by:
        positions in interface LaneBasedGTU
        Parameters:
        relativePosition - RelativePosition; the position on the vehicle relative to the reference point.
        when - Time; the future time for which to calculate the positions.
        Returns:
        the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of the GTU.
        Throws:
        GTUException - when the vehicle is not on one of the lanes on which it is registered.
      • position

        public final Length position​(Lane lane,
                                     RelativePosition relativePosition)
                              throws GTUException
        Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane at the current simulation time.
        Specified by:
        position in interface LaneBasedGTU
        Parameters:
        lane - Lane; the position on this lane will be returned.
        relativePosition - RelativePosition; the position on the vehicle relative to the reference point.
        Returns:
        DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane.
        Throws:
        GTUException - when the vehicle is not on the given lane.
      • position

        public Length position​(Lane lane,
                               RelativePosition relativePosition,
                               Time when)
                        throws GTUException
        Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane.
        Specified by:
        position in interface LaneBasedGTU
        Parameters:
        lane - Lane; the position on this lane will be returned.
        relativePosition - RelativePosition; the position on the vehicle relative to the reference point.
        when - Time; the future time for which to calculate the positions.
        Returns:
        DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane.
        Throws:
        GTUException - when the vehicle is not on the given lane.
      • getReferencePosition

        public DirectedLanePosition getReferencePosition()
                                                  throws GTUException
        Return the current Lane, position and directionality of the GTU.
        Specified by:
        getReferencePosition in interface LaneBasedGTU
        Returns:
        DirectedLanePosition; the current Lane, position and directionality of the GTU
        Throws:
        GTUException - in case the reference position of the GTU cannot be found on the lanes in its current path
      • fractionalPositions

        public final Map<Lane,​Double> fractionalPositions​(RelativePosition relativePosition)
                                                         throws GTUException
        Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an 'inner' and 'outer' curve.
        Specified by:
        fractionalPositions in interface LaneBasedGTU
        Parameters:
        relativePosition - RelativePosition; the position on the vehicle relative to the reference point.
        Returns:
        the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU.
        Throws:
        GTUException - when the vehicle is not on one of the lanes on which it is registered.
      • fractionalPositions

        public final Map<Lane,​Double> fractionalPositions​(RelativePosition relativePosition,
                                                                Time when)
                                                         throws GTUException
        Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an 'inner' and 'outer' curve.
        Specified by:
        fractionalPositions in interface LaneBasedGTU
        Parameters:
        relativePosition - RelativePosition; the position on the vehicle relative to the reference point.
        when - Time; the future time for which to calculate the positions.
        Returns:
        the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of the GTU.
        Throws:
        GTUException - when the vehicle is not on one of the lanes on which it is registered.
      • fractionalPosition

        public final double fractionalPosition​(Lane lane,
                                               RelativePosition relativePosition,
                                               Time when)
                                        throws GTUException
        Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an 'inner' and 'outer' curve.
        Specified by:
        fractionalPosition in interface LaneBasedGTU
        Parameters:
        lane - Lane; the position on this lane will be returned.
        relativePosition - RelativePosition; the position on the vehicle relative to the reference point.
        when - Time; the future time for which to calculate the positions.
        Returns:
        the fractional relative position on the lane at the given time.
        Throws:
        GTUException - when the vehicle is not on the given lane.
      • fractionalPosition

        public final double fractionalPosition​(Lane lane,
                                               RelativePosition relativePosition)
                                        throws GTUException
        Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an 'inner' and 'outer' curve.
        Specified by:
        fractionalPosition in interface LaneBasedGTU
        Parameters:
        lane - Lane; the position on this lane will be returned.
        relativePosition - RelativePosition; the position on the vehicle relative to the reference point.
        Returns:
        the fractional relative position on the lane at the given time.
        Throws:
        GTUException - when the vehicle is not on the given lane.
      • addTrigger

        public final void addTrigger​(Lane lane,
                                     SimEventInterface<SimTimeDoubleUnit> event)
        Add an event to the list of lane triggers scheduled for this GTU.
        Specified by:
        addTrigger in interface LaneBasedGTU
        Parameters:
        lane - Lane; the lane on which the event occurs
        event - SimEventInterface<SimTimeDoubleUnit>; SimeEvent<SimTimeDoubleUnit> the event
      • setVehicleModel

        public void setVehicleModel​(VehicleModel vehicleModel)
        Sets a vehicle model.
        Parameters:
        vehicleModel - VehicleModel; vehicle model
      • getBounds

        public final javax.media.j3d.Bounds getBounds()
        Specified by:
        getBounds in interface Locatable
      • getDesiredSpeed

        public Speed getDesiredSpeed()
        This method returns the current desired speed of the GTU. This value is required often, so implementations can cache it.
        Specified by:
        getDesiredSpeed in interface LaneBasedGTU
        Returns:
        Speed; current desired speed
      • getCarFollowingAcceleration

        public Acceleration getCarFollowingAcceleration()
        This method returns the current car-following acceleration of the GTU. This value is required often, so implementations can cache it.
        Specified by:
        getCarFollowingAcceleration in interface LaneBasedGTU
        Returns:
        Acceleration; current car-following acceleration
      • getTurnIndicatorStatus

        public final TurnIndicatorStatus getTurnIndicatorStatus​(Time time)
        Specified by:
        getTurnIndicatorStatus in interface LaneBasedGTU
        Parameters:
        time - Time; time to obtain the turn indicator status at
        Returns:
        the status of the turn indicator at the given time
      • setTurnIndicatorStatus

        public final void setTurnIndicatorStatus​(TurnIndicatorStatus turnIndicatorStatus)
        Set the status of the turn indicator.
        Specified by:
        setTurnIndicatorStatus in interface LaneBasedGTU
        Parameters:
        turnIndicatorStatus - TurnIndicatorStatus; the new status of the turn indicator.
      • getLateralPosition

        public Length getLateralPosition​(Lane lane)
                                  throws GTUException
        Returns the lateral position of the GTU relative to the lane center line. Negative values are towards the right.
        Specified by:
        getLateralPosition in interface LaneBasedGTU
        Parameters:
        lane - Lane; lane to consider (most important regarding left/right, not upstream downstream)
        Returns:
        Length; lateral position of the GTU relative to the lane center line
        Throws:
        GTUException - when the vehicle is not on the given lane.
      • setInstantaneousLaneChange

        public void setInstantaneousLaneChange​(boolean instantaneous)
        Sets whether the GTU perform lane changes instantaneously or not.
        Specified by:
        setInstantaneousLaneChange in interface LaneBasedGTU
        Parameters:
        instantaneous - boolean; whether the GTU perform lane changes instantaneously or not
      • isInstantaneousLaneChange

        public boolean isInstantaneousLaneChange()
        Returns whether the GTU perform lane changes instantaneously or not.
        Specified by:
        isInstantaneousLaneChange in interface LaneBasedGTU
        Returns:
        boolean; whether the GTU perform lane changes instantaneously or not