LaneBasedGTU.java

  1. package org.opentrafficsim.road.gtu.lane;

  2. import java.util.Map;

  3. import org.djunits.value.vdouble.scalar.Length;
  4. import org.djunits.value.vdouble.scalar.Time;
  5. import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
  6. import org.opentrafficsim.core.gtu.GTU;
  7. import org.opentrafficsim.core.gtu.GTUDirectionality;
  8. import org.opentrafficsim.core.gtu.GTUException;
  9. import org.opentrafficsim.core.gtu.RelativePosition;
  10. import org.opentrafficsim.core.network.LateralDirectionality;
  11. import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlanner;
  12. import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner;
  13. import org.opentrafficsim.road.network.lane.DirectedLanePosition;
  14. import org.opentrafficsim.road.network.lane.Lane;

  15. import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent;
  16. import nl.tudelft.simulation.event.EventType;
  17. import nl.tudelft.simulation.language.d3.DirectedPoint;

  18. /**
  19.  * This interface defines a lane based GTU.
  20.  * <p>
  21.  * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  22.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  23.  * <p>
  24.  * @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $,
  25.  *          initial version Oct 22, 2014 <br>
  26.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  27.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  28.  */
  29. public interface LaneBasedGTU extends GTU
  30. {
  31.     /** {@inheritDoc} */
  32.     @Override
  33.     LaneBasedStrategicalPlanner getStrategicalPlanner();

  34.     /** {@inheritDoc} */
  35.     @Override
  36.     LaneBasedTacticalPlanner getTacticalPlanner();

  37.     /**
  38.      * Return the location without a RemoteException.
  39.      * {@inheritDoc}
  40.      */
  41.     @Override
  42.     DirectedPoint getLocation();
  43.    
  44.     /**
  45.      * insert GTU at a certain position. This can happen at setup (first initialization), and after a lane change of the GTU.
  46.      * The relative position that will be registered is the referencePosition (dx, dy, dz) = (0, 0, 0). Front and rear positions
  47.      * are relative towards this position.
  48.      * @param lane the lane to add to the list of lanes on which the GTU is registered.
  49.      * @param gtuDirection the direction of the GTU on the lane (which can be bidirectional). If the GTU has a positive speed,
  50.      *            it is moving in this direction.
  51.      * @param position the position on the lane.
  52.      * @throws GTUException when positioning the GTU on the lane causes a problem
  53.      */
  54.     void enterLane(Lane lane, Length position, GTUDirectionality gtuDirection) throws GTUException;

  55.     /**
  56.      * Unregister the GTU from a lane.
  57.      * @param lane the lane to remove from the list of lanes on which the GTU is registered.
  58.      * @throws GTUException when leaveLane should not be called
  59.      */
  60.     void leaveLane(Lane lane) throws GTUException;

  61.     /**
  62.      * Change lanes instantaneously.
  63.      * @param laneChangeDirection the direction to change to
  64.      * @throws GTUException in case lane change fails
  65.      */
  66.     void changeLaneInstantaneously(LateralDirectionality laneChangeDirection) throws GTUException;

  67.     /**
  68.      * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the
  69.      * vehicle is registered. <br>
  70.      * <b>Note:</b> If a GTU is registered in multiple parallel lanes, the lateralLaneChangeModel is used to determine the
  71.      * center line of the vehicle at this point in time. Otherwise, the average of the center positions of the lines will be
  72.      * taken.
  73.      * @param relativePosition the position on the vehicle relative to the reference point.
  74.      * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU.
  75.      * @throws GTUException when the vehicle is not on one of the lanes on which it is registered.
  76.      */
  77.     Map<Lane, Length> positions(RelativePosition relativePosition) throws GTUException;

  78.     /**
  79.      * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the
  80.      * vehicle is registered.
  81.      * @param relativePosition the position on the vehicle relative to the reference point.
  82.      * @param when the future time for which to calculate the positions.
  83.      * @return the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of
  84.      *         the GTU.
  85.      * @throws GTUException when the vehicle is not on one of the lanes on which it is registered.
  86.      */
  87.     Map<Lane, Length> positions(RelativePosition relativePosition, Time when) throws GTUException;

  88.     /**
  89.      * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane at the current
  90.      * simulation time. <br>
  91.      * @param lane the position on this lane will be returned.
  92.      * @param relativePosition the position on the vehicle relative to the reference point.
  93.      * @return DoubleScalarAbs&lt;LengthUnit&gt;; the position, relative to the center line of the Lane.
  94.      * @throws GTUException when the vehicle is not on the given lane.
  95.      */
  96.     Length position(Lane lane, RelativePosition relativePosition) throws GTUException;

  97.     /**
  98.      * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane.
  99.      * @param lane the position on this lane will be returned.
  100.      * @param relativePosition the position on the vehicle relative to the reference point.
  101.      * @param when the future time for which to calculate the positions.
  102.      * @return DoubleScalarAbs&lt;LengthUnit&gt;; the position, relative to the center line of the Lane.
  103.      * @throws GTUException when the vehicle is not on the given lane.
  104.      */
  105.     Length position(Lane lane, RelativePosition relativePosition, Time when) throws GTUException;

  106.     /**
  107.      * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the
  108.      * vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are
  109.      * next to each other and we compare an 'inner' and 'outer' curve.<br>
  110.      * @param relativePosition the position on the vehicle relative to the reference point.
  111.      * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU.
  112.      * @throws GTUException when the vehicle is not on one of the lanes on which it is registered.
  113.      */
  114.     Map<Lane, Double> fractionalPositions(RelativePosition relativePosition) throws GTUException;

  115.     /**
  116.      * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the
  117.      * vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are
  118.      * next to each other and we compare an 'inner' and 'outer' curve.
  119.      * @param relativePosition the position on the vehicle relative to the reference point.
  120.      * @param when the future time for which to calculate the positions.
  121.      * @return the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of
  122.      *         the GTU.
  123.      * @throws GTUException when the vehicle is not on one of the lanes on which it is registered.
  124.      */
  125.     Map<Lane, Double> fractionalPositions(RelativePosition relativePosition, Time when) throws GTUException;

  126.     /**
  127.      * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction
  128.      * 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
  129.      * 'inner' and 'outer' curve.
  130.      * @param lane the position on this lane will be returned.
  131.      * @param relativePosition the position on the vehicle relative to the reference point.
  132.      * @param when the future time for which to calculate the positions.
  133.      * @return the fractional relative position on the lane at the given time.
  134.      * @throws GTUException when the vehicle is not on the given lane.
  135.      */
  136.     double fractionalPosition(Lane lane, RelativePosition relativePosition, Time when) throws GTUException;

  137.     /**
  138.      * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction
  139.      * 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
  140.      * 'inner' and 'outer' curve.<br>
  141.      * @param lane the position on this lane will be returned.
  142.      * @param relativePosition the position on the vehicle relative to the reference point.
  143.      * @return the fractional relative position on the lane at the given time.
  144.      * @throws GTUException when the vehicle is not on the given lane.
  145.      */
  146.     double fractionalPosition(Lane lane, RelativePosition relativePosition) throws GTUException;

  147.     /**
  148.      * Return the longitudinal position that this GTU would have if it were to change to another Lane with a / the current
  149.      * CrossSectionLink.
  150.      * @param projectionLane Lane; the lane onto which the position of this GTU must be projected
  151.      * @param relativePosition RelativePosition; the point on this GTU that must be projected
  152.      * @param when Time; the time for which to project the position of this GTU
  153.      * @return Length; the position of this GTU in the projectionLane
  154.      * @throws GTUException when projectionLane it not in any of the CrossSectionLink that the GTU is on
  155.      */
  156.     Length projectedPosition(Lane projectionLane, RelativePosition relativePosition, Time when) throws GTUException;

  157.     /**
  158.      * Return the current Lane, position and directionality of the GTU.
  159.      * @return DirectedLanePosition; the current Lane, position and directionality of the GTU
  160.      * @throws GTUException in case the reference position of the GTU cannot be found on the lanes in its current path
  161.      */
  162.     DirectedLanePosition getReferencePosition() throws GTUException;
  163.    
  164.     /**
  165.      * Return the directionality of a lane on which the GTU is registered for its current operational plan.
  166.      * @param lane Lane; the lane for which we want to know the direction
  167.      * @return GTUDirectionality; the direction on the given lane
  168.      * @throws GTUException in case the GTU is not registered on the Lane
  169.      */
  170.     GTUDirectionality getDirection(Lane lane) throws GTUException;
  171.    
  172.     /**
  173.      * Add an event to the list of lane triggers scheduled for this GTU.
  174.      * @param lane Lane; the lane on which the event occurs
  175.      * @param event SimeEvent&lt;OTSSimTimeDouble&gt; the event
  176.      */
  177.     void addTrigger(Lane lane, SimEvent<OTSSimTimeDouble> event);

  178.     /**
  179.      * The lane-based event type for pub/sub indicating the initialization of a new GTU. <br>
  180.      * Payload: [String gtuId, DirectedPoint initialPosition, Length length, Length width, Color gtuBaseColor, Lane
  181.      * referenceLane, Length positionOnReferenceLane, GTUDirectionality direction, GTUType gtuType]
  182.      */
  183.     EventType LANEBASED_INIT_EVENT = new EventType("LANEBASEDGTU.INIT");

  184.     /**
  185.      * The lane-based event type for pub/sub indicating a move. <br>
  186.      * Payload: [String gtuId, DirectedPoint position, Speed speed, Acceleration acceleration, TurnIndicatorStatus
  187.      * turnIndicatorStatus, Length odometer, Lane referenceLane, Length positionOnReferenceLane, GTUDirectionality direction]
  188.      */
  189.     EventType LANEBASED_MOVE_EVENT = new EventType("LANEBASEDGTU.MOVE");

  190.     /**
  191.      * The lane-based event type for pub/sub indicating destruction of the GTU. <br>
  192.      * Payload: [String gtuId, DirectedPoint lastPosition, Length odometer, Lane referenceLane, Length positionOnReferenceLane,
  193.      * GTUDirectionality direction]
  194.      */
  195.     EventType LANEBASED_DESTROY_EVENT = new EventType("LANEBASEDGTU.DESTROY");

  196.     /**
  197.      * The event type for pub/sub indicating that the GTU entered a new link (with the FRONT position if driving forward; REAR
  198.      * if driving backward). <br>
  199.      * Payload: [String gtuId, Link link]
  200.      */
  201.     EventType LINK_ENTER_EVENT = new EventType("LINK.ENTER");

  202.     /**
  203.      * The event type for pub/sub indicating that the GTU exited a link (with the REAR position if driving forward; FRONT if
  204.      * driving backward). <br>
  205.      * Payload: [String gtuId, Link link]
  206.      */
  207.     EventType LINK_EXIT_EVENT = new EventType("LINK.EXIT");

  208.     /**
  209.      * The event type for pub/sub indicating that the GTU entered a new lane (with the FRONT position if driving forward; REAR
  210.      * if driving backward). <br>
  211.      * Payload: [String gtuId, Lane lane]
  212.      */
  213.     EventType LANE_ENTER_EVENT = new EventType("LANE.ENTER");

  214.     /**
  215.      * The event type for pub/sub indicating that the GTU exited a lane (with the REAR position if driving forward; FRONT if
  216.      * driving backward). <br>
  217.      * Payload: [String gtuId, Lane lane]
  218.      */
  219.     EventType LANE_EXIT_EVENT = new EventType("LANE.EXIT");

  220. }