Class LaneBasedGtu
- All Implemented Interfaces:
nl.tudelft.simulation.dsol.animation.Locatable,Identifiable,EventProducer,OtsShape,HierarchicallyTyped<GtuType,,Gtu> LocatedObject,LaneBasedObject
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-2024 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, Wouter Schakel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EventTypeThe event type for pub/sub indicating that the GTU changed lane, laterally only.
Payload: [String gtuId, LateralDirectionality direction, String linkId, String fromLaneId, Length position]static final EventTypeThe event type for pub/sub indicating that the GTU entered a lane in either the lateral or longitudinal direction.
Payload: [String gtuId, String link id, String lane id]static final EventTypeThe event type for pub/sub indicating that the GTU exited a lane in either the lateral or longitudinal direction.
Payload: [String gtuId, String link id, String lane id]static final EventTypeThe lane-based event type for pub/sub indicating destruction of the GTU.
Payload: [String gtuId, PositionVector finalPosition, Direction finalDirection, Length finalOdometer, String linkId, String laneId, Length positionOnLane]static final EventTypeThe lane-based event type for pub/sub indicating a move.
Payload: [String gtuId, PositionVector currentPosition, Direction currentDirection, Speed speed, Acceleration acceleration, TurnIndicatorStatus turnIndicatorStatus, Length odometer, String linkId, String laneId, Length positionOnLane]Fields inherited from class org.opentrafficsim.core.gtu.Gtu
DESTROY_EVENT, MOVE_EVENTFields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITIONFields inherited from interface org.opentrafficsim.base.geometry.OtsShape
DEFAULT_POLYGON_SEGMENTS, WORLD_MARGIN_LINE -
Constructor Summary
ConstructorsConstructorDescriptionLaneBasedGtu(String id, GtuType gtuType, Length length, Length width, Speed maximumSpeed, Length front, RoadNetwork network) Construct a Lane Based GTU. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCancels all future events.voidchangeLaneInstantaneously(LateralDirectionality laneChangeDirection) Change lanes instantaneously.voiddestroy()protected voidendRoaming(LanePosition roamingPosition) Ends roaming if the roaming position is sufficiently close to enter the network.protected voidEnters a new lane, and removes the GTU from the previous lane.protected voidexitLane()Removes the registration between this GTU and the lane.protected voidfindDetectorTriggers(boolean schedule) This method applies a detector finding algorithm that guarantees that detectors at the same location, triggered for different relative positions, are all always triggered in combination.Returns how lane bookkeeping at lane changes is done.This method returns the current car-following acceleration of the GTU.This method returns the current desired speed of the GTU.Deviation from lane center.getDeviation(Duration time) Deviation from lane center at time.protected LengthgetDeviation(Lane lane, Point2d location) Returns the deviation from the center line of the given lane, using extension if the GTU is not on the lane.getLane()Returns the lane.Returns the lane at the given time.Returns the lane change direction.Returns the lane change direction at the given time.Returns the longitudinal position.Returns the network.getNextLaneForRoute(Lane lane) Returns the next lane for a given lane to stay on the route.Returns the lane and reference position on the lane of the GTU.getPosition(Duration time) Returns the lane and reference position on the lane of the GTU.getPosition(RelativePosition relativePosition) Returns the lane and relative position on the lane of the GTU.getPosition(RelativePosition relativePosition, Duration time) Returns the lane and relative position on the lane of the GTU.getPosition(Lane lane) Returns the projected position of the GTU on the given lane, which should be on the same link.getPosition(Lane lane, Duration time) Returns the projected position of the GTU on the given lane, which should be on the same link.getPosition(Lane lane, RelativePosition relativePosition) Returns the projected position of the GTU on the given lane, which should be on the same link.getPosition(Lane lane, RelativePosition relativePosition, Duration time) Returns the projected position of the GTU on the given lane, which should be on the same link.Returns the position when the GTU is on a lane, or the roaming position otherwise.getProjectedLength(Lane lane) Get projected length on the lane.Returns the nearest lane position on the route / network.protected LanePositiongetRoamingPosition(Point2d location) Returns the nearest lane position on the route / network.getTacticalPlanner(Duration time) protected DurationgetTimeOfLateralCrossing(Duration fromTime, Duration toTime, boolean roam) Estimates when the path crosses a lateral lane boundary assuming the GTU is within the boundary.Returns the turn indicator status.Returns the turn indicator status at time.Returns the vehicle model.voidinit(LaneBasedStrategicalPlanner strategicalPlanner, DirectedPoint2d initialLocation, Speed initialSpeed) Initializes the GTU.booleanReturns whether the braking lights are on.booleanisBrakingLightsOn(Duration time) Returns whether the braking lights are on.booleanReturns whether the GTU is roaming (i.e. not on a lane).booleanReturns whether the GTU is roaming (i.e. not on a lane).booleanReturns whether a lane change is allowed.protected LengthlaneLateralOvershoot(Duration time) Returns the lateral overshoot at give time.protected booleanmove(DirectedPoint2d fromLocation) protected voidSchedules when a lane is entered (and a previous one is left).voidsetBookkeeping(LaneBookkeeping bookkeeping) Sets how lane bookkeeping at lane changes is done.voidsetLaneChangeDirection(LateralDirectionality direction) Set lane change direction.voidsetNoLaneChangeDistance(Length distance) Set distance over which the GTU should not change lane after being created.voidThe lane the GTU is on will be left.voidsetTurnIndicatorStatus(TurnIndicatorStatus turnIndicatorStatus) Set the status of the turn indicator.voidsetVehicleModel(VehicleModel vehicleModel) Sets a vehicle model.voidstop()Stops the GTU using a permanent stand-still operational plan.toString()protected voidtriggerDetector(LaneDetector detector) Trigger detector and remove it from detectors that need to be triggered.Methods inherited from class org.opentrafficsim.core.gtu.Gtu
addGtu, equals, getAbsoluteContour, getAbsoluteContour, getAcceleration, getAcceleration, getAlignStep, getCenter, getChildren, getErrorHandler, getFront, getId, getLength, getLocation, getLocation, getMaximumAcceleration, getMaximumDeceleration, getMaximumSpeed, getNextMoveEvent, getOdometer, getOdometer, getOperationalPlan, getOperationalPlan, getParameters, getParent, getPerceivableContext, getRear, getReference, getRelativeBounds, getRelativeContour, getRelativePositions, getSimulator, getSpeed, getSpeed, getTag, getType, getWidth, hashCode, init, interruptMove, isDestroyed, removeGtu, setAlignStep, setErrorHandler, setMaximumAcceleration, setMaximumDeceleration, setOperationalPlan, setParameters, setTag, signedDistanceMethods inherited from class org.djutils.event.LocalEventProducer
getEventListenerMapMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListenerMethods inherited from interface org.opentrafficsim.base.HierarchicallyTyped
isOfTypeMethods inherited from interface org.djutils.base.Identifiable
getIdMethods inherited from interface org.opentrafficsim.road.network.lane.object.LaneBasedObject
getLength, getLine, getLocation, getSimulatorMethods inherited from interface nl.tudelft.simulation.dsol.animation.Locatable
getZMethods inherited from interface org.opentrafficsim.base.geometry.OtsShape
contains, contains, getAbsoluteBounds, getAbsoluteContour, getAbsoluteContour, getDirZ, getRelativeBounds, getRelativeContour, signedDistance, signedDistance
-
Field Details
-
LANEBASED_MOVE_EVENT
The lane-based event type for pub/sub indicating a move.
Payload: [String gtuId, PositionVector currentPosition, Direction currentDirection, Speed speed, Acceleration acceleration, TurnIndicatorStatus turnIndicatorStatus, Length odometer, String linkId, String laneId, Length positionOnLane] -
LANEBASED_DESTROY_EVENT
The lane-based event type for pub/sub indicating destruction of the GTU.
Payload: [String gtuId, PositionVector finalPosition, Direction finalDirection, Length finalOdometer, String linkId, String laneId, Length positionOnLane] -
LANE_ENTER_EVENT
The event type for pub/sub indicating that the GTU entered a lane in either the lateral or longitudinal direction.
Payload: [String gtuId, String link id, String lane id] -
LANE_EXIT_EVENT
The event type for pub/sub indicating that the GTU exited a lane in either the lateral or longitudinal direction.
Payload: [String gtuId, String link id, String lane id] -
LANE_CHANGE_EVENT
The event type for pub/sub indicating that the GTU changed lane, laterally only.
Payload: [String gtuId, LateralDirectionality direction, String linkId, String fromLaneId, Length position]
-
-
Constructor Details
-
LaneBasedGtu
public LaneBasedGtu(String id, GtuType gtuType, Length length, Length width, Speed maximumSpeed, Length front, RoadNetwork network) throws GtuException Construct a Lane Based GTU.- Parameters:
id- the id of the GTUgtuType- the type of GTU, e.g. TruckType, CarType, BusTypelength- the maximum length of the GTU (parallel with driving direction)width- the maximum width of the GTU (perpendicular to driving direction)maximumSpeed- the maximum speed of the GTU (in the driving direction)front- front distance relative to the reference positionnetwork- the network that the GTU is initially registered in- Throws:
GtuException- when initial values are not correct
-
-
Method Details
-
init
public void init(LaneBasedStrategicalPlanner strategicalPlanner, DirectedPoint2d initialLocation, Speed initialSpeed) throws NetworkException, nl.tudelft.simulation.dsol.SimRuntimeException, GtuException Initializes the GTU.- Parameters:
strategicalPlanner- the strategical planner (e.g., route determination) to useinitialLocation- initial locationinitialSpeed- the initial speed of the car on the lane- Throws:
NetworkException- when the GTU cannot be placed on the given lanenl.tudelft.simulation.dsol.SimRuntimeException- when the move method cannot be scheduledGtuException- when initial values are not correct
-
setParent
The lane the GTU is on will be left.- Overrides:
setParentin classGtu- Throws:
GtuException
-
exitLane
protected void exitLane()Removes the registration between this GTU and the lane. -
enterLane
Enters a new lane, and removes the GTU from the previous lane.- Parameters:
lane- lanefraction- fractional position
-
isRoaming
public boolean isRoaming()Returns whether the GTU is roaming (i.e. not on a lane). In this case all methods on lane and position should not be called as they will returnnull.- Returns:
- whether the GTU is roaming
-
isRoaming
Returns whether the GTU is roaming (i.e. not on a lane). In this case all methods on lane and position should not be called as they will returnnull.- Parameters:
time- simulation time to get the lane for- Returns:
- whether the GTU is roaming
-
getPositionOrRoaming
Returns the position when the GTU is on a lane, or the roaming position otherwise.- Returns:
- position when the GTU is on a lane, or the roaming position otherwise
-
getLane
Description copied from interface:LaneBasedObjectReturns the lane.- Specified by:
getLanein interfaceLaneBasedObject- Returns:
- lane
-
getLane
Returns the lane at the given time. This may be in the future during the plan, in which case it is a prospective lane.- Parameters:
time- simulation time to get the lane for- Returns:
- lane at given time
-
getPosition
Returns the lane and reference position on the lane of the GTU.- Returns:
- lane position at time
-
getPosition
Returns the lane and reference position on the lane of the GTU.- Parameters:
time- simulation time to get the position for- Returns:
- lane position at time
-
getPosition
Returns the lane and relative position on the lane of the GTU. The relative position is calculated by shifting the position of the reference bydxof the relative position.- Parameters:
relativePosition- relative position- Returns:
- lane position
-
getPosition
Returns the lane and relative position on the lane of the GTU. The relative position is calculated by shifting the position of the reference bydxof the relative position.- Parameters:
relativePosition- relative positiontime- simulation time to get the position for- Returns:
- lane position at time
-
getPosition
Returns the projected position of the GTU on the given lane, which should be on the same link.- Parameters:
lane- lane- Returns:
- projected position of the GTU on the given lane
- Throws:
IllegalStateException- when the GTU is not on a laneIllegalArgumentException- when the lane is not in the link the GTU is on
-
getPosition
Returns the projected position of the GTU on the given lane, which should be on the same link.- Parameters:
lane- lanetime- simulation time- Returns:
- projected position of the GTU on the given lane
- Throws:
IllegalStateException- when the GTU is not on a laneIllegalArgumentException- when the lane is not in the link the GTU is on
-
getPosition
Returns the projected position of the GTU on the given lane, which should be on the same link. The relative position is calculated by shifting the position of the reference bydxof the relative position.- Parameters:
lane- lanerelativePosition- relative position- Returns:
- projected position of the GTU on the given lane
- Throws:
IllegalStateException- when the GTU is not on a laneIllegalArgumentException- when the lane is not in the link the GTU is on
-
getLongitudinalPosition
Description copied from interface:LaneBasedObjectReturns the longitudinal position.- Specified by:
getLongitudinalPositionin interfaceLaneBasedObject- Returns:
- position (between 0.0 and the length of the lane)
-
getPosition
Returns the projected position of the GTU on the given lane, which should be on the same link. The relative position is calculated by shifting the position of the reference bydxof the relative position.- Parameters:
lane- lanerelativePosition- relative positiontime- simulation time- Returns:
- projected position of the GTU on the given lane
- Throws:
IllegalStateException- when the GTU is not on a laneIllegalArgumentException- when the lane is not in the link the GTU is on
-
getRoamingPosition
Returns the nearest lane position on the route / network. It is not strictly guaranteed that the position is closest, as this method will only search on links where either of the nodes is the closest node.- Returns:
- nearest lane position on the route / network
-
getRoamingPosition
Returns the nearest lane position on the route / network. It is not strictly guaranteed that the position is closest, as this method will only search on links where either of the nodes is the closest node.- Parameters:
location- location to find the nearest lane position for- Returns:
- nearest lane position on the route / network
-
getDeviation
Deviation from lane center. Positive values are left, negative values are right.- Returns:
- deviation from lane center line, positive values are left, negative values are right
-
getDeviation
Deviation from lane center at time. Positive values are left, negative values are right.- Parameters:
time- simulation time- Returns:
- deviation from lane center line, positive values are left, negative values are right
-
getDeviation
Returns the deviation from the center line of the given lane, using extension if the GTU is not on the lane. Positive values are left, negative values are right.- Parameters:
lane- lanelocation- location- Returns:
- deviation from lane center line, positive values are left, negative values are right
-
changeLaneInstantaneously
Change lanes instantaneously.- Parameters:
laneChangeDirection- the direction to change to
-
move
protected boolean move(DirectedPoint2d fromLocation) throws nl.tudelft.simulation.dsol.SimRuntimeException, GtuException, NetworkException, ParameterException - Overrides:
movein classGtu- Throws:
nl.tudelft.simulation.dsol.SimRuntimeExceptionGtuExceptionNetworkExceptionParameterException
-
cancelAllEvents
protected void cancelAllEvents()Cancels all future events. -
scheduleLaneEvents
protected void scheduleLaneEvents()Schedules when a lane is entered (and a previous one is left). Also schedules start of roaming (GTU not having a lane), or ends roaming if the GTU is on a lane. -
getTimeOfLateralCrossing
Estimates when the path crosses a lateral lane boundary assuming the GTU is within the boundary. This is estimated through linear interpolation between the start and end deviation values of a line segment of the path. The line segment is found through a binary search.- Parameters:
fromTime- first time to consider on the lanetoTime- last time to consider on the laneroam- whentruethe full width of the GTU is considered, whenfalseonly the reference position- Returns:
- when the path crosses a lateral lane boundary
-
endRoaming
Ends roaming if the roaming position is sufficiently close to enter the network.- Parameters:
roamingPosition- roaming position
-
findDetectorTriggers
protected void findDetectorTriggers(boolean schedule) This method applies a detector finding algorithm that guarantees that detectors at the same location, triggered for different relative positions, are all always triggered in combination. As detectors might be triggered by the front, detectors beyond the current plan path may need to be triggered in the current plan duration. To achieve this, all detectors are found between the path start position + dx, up to the path end position + dx, where dx is the distance the front is before the reference point. Start and end position and dx are applied along the lane center lines. In case of a lane change dx is also applied on both lanes, meaning that all detectors overlapping the vehicle on the from lane are found, but at the target lane only detectors downstream of the front are found.
This method stores all found detectors as detector triggers. This includes for each detector the odometer value of the reference point at which the detector should be triggered. The odometer value is adjusted for the relative position that should trigger the detector, along the lane center lines.
Finally, this method schedules trigger events for all stored detector triggers when the reference point reaches the relevant odometer value in the current plan. This may include detector triggers that were stored in a previous time step as the front reached the detector, but no event was scheduled in a previous time step as the relevant relative position of the detector, e.g. the rear, did not reach the detector.
Alternatively whenschedule = falsethis method finds all detector triggers downstream of the current front location during the current plan using the same search algorithm, and removes them from the stored detector triggers. No events will be scheduled (nor removed by this method). Removing detector triggers is relevant when a plan is cancelled. Any downstream detectors may be found again and rescheduled depending on a new plan by a new move.- Parameters:
schedule-trueadds downstream triggers and schedules them,falseremoves downstream triggers
-
triggerDetector
Trigger detector and remove it from detectors that need to be triggered.- Parameters:
detector- detector
-
laneLateralOvershoot
Returns the lateral overshoot at give time. This is the lateral distance by which the reference point exceeds either the left or right edge of the lane. Negative values indicate the reference point is still on the lane.- Parameters:
time- simulation time- Returns:
- lateral overshoot
-
getNextLaneForRoute
Returns the next lane for a given lane to stay on the route.- Parameters:
lane- the lane for which we want to know the next Lane- Returns:
- next lane, empty if none
-
setVehicleModel
Sets a vehicle model.- Parameters:
vehicleModel- vehicle model
-
getVehicleModel
Returns the vehicle model.- Returns:
- vehicle model
-
getStrategicalPlanner
- Overrides:
getStrategicalPlannerin classGtu
-
getStrategicalPlanner
- Overrides:
getStrategicalPlannerin classGtu
-
getNetwork
Returns the network.- Returns:
- the road network to which the LaneBasedGtu belongs
-
getDesiredSpeed
This method returns the current desired speed of the GTU. This value is required often, so implementations can cache it.- Returns:
- current desired speed
-
getCarFollowingAcceleration
This method returns the current car-following acceleration of the GTU. This value is required often, so implementations can cache it.- Returns:
- current car-following acceleration
-
getTurnIndicatorStatus
Returns the turn indicator status.- Returns:
- the status of the turn indicator
-
getTurnIndicatorStatus
Returns the turn indicator status at time.- Parameters:
time- simulation time to obtain the turn indicator status at- Returns:
- the status of the turn indicator at the given time
-
setTurnIndicatorStatus
Set the status of the turn indicator.- Parameters:
turnIndicatorStatus- the new status of the turn indicator.
-
getHeight
- Specified by:
getHeightin interfaceLocatedObject
-
getFullId
- Specified by:
getFullIdin interfaceLocatedObject
-
setBookkeeping
Sets how lane bookkeeping at lane changes is done.- Parameters:
bookkeeping- how lane bookkeeping at lane changes is done
-
getBookkeeping
Returns how lane bookkeeping at lane changes is done.- Returns:
- how lane bookkeeping at lane changes is done
-
getTacticalPlanner
- Overrides:
getTacticalPlannerin classGtu
-
getTacticalPlanner
- Overrides:
getTacticalPlannerin classGtu
-
setNoLaneChangeDistance
Set distance over which the GTU should not change lane after being created.- Parameters:
distance- distance over which the GTU should not change lane after being created
-
laneChangeAllowed
public boolean laneChangeAllowed()Returns whether a lane change is allowed.- Returns:
- whether a lane change is allowed
-
setLaneChangeDirection
Set lane change direction. This should only be set by a controller of the GTU, e.g. the tactical planner.- Parameters:
direction- lane change direction
-
getLaneChangeDirection
Returns the lane change direction.- Returns:
- lane change direction
-
getLaneChangeDirection
Returns the lane change direction at the given time.- Parameters:
time- simulation time- Returns:
- lane change direction at the given time
-
isBrakingLightsOn
public boolean isBrakingLightsOn()Returns whether the braking lights are on.- Returns:
- whether the braking lights are on
-
isBrakingLightsOn
Returns whether the braking lights are on.- Parameters:
time- simulation time- Returns:
- whether the braking lights are on
-
getProjectedLength
Get projected length on the lane.- Parameters:
lane- lane to project the vehicle on- Returns:
- the length on the lane, which is different from the actual length during deviative tactical plans
-
stop
public void stop()Stops the GTU using a permanent stand-still operational plan. -
destroy
public void destroy() -
toString
-