LanePathInfo.java

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

  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import java.util.List;

  5. import org.djunits.value.vdouble.scalar.Length;
  6. import org.opentrafficsim.core.geometry.OTSLine3D;
  7. import org.opentrafficsim.road.network.lane.Lane;
  8. import org.opentrafficsim.road.network.lane.LaneDirection;

  9. /**
  10.  * This class provides the following information for an operational plan:
  11.  * <ul>
  12.  * <li>the lanes to follow, with the direction to drive on them</li>
  13.  * <li>the starting point on the first lane</li>
  14.  * <li>the path to follow when staying on the same lane</li>
  15.  * </ul>
  16.  * <p>
  17.  * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  18.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  19.  * </p>
  20.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  21.  * initial version Dec 31, 2015 <br>
  22.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  23.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  24.  */
  25. public class LanePathInfo implements Serializable
  26. {
  27.     /** */
  28.     private static final long serialVersionUID = 20151231L;

  29.     /**
  30.      * The path it the GTU keeps driving in the same lane, and follows the route if possible in the same lane. The path stops
  31.      * when the lane or a continuation lane does not lead in the direction of the route provided by the strategical planner.
  32.      */
  33.     private final OTSLine3D path;

  34.     /**
  35.      * The current lane on which the reference point of the GTU is registered (if the GTU is registered on multiple lanes with
  36.      * the reference point, one lane is chosen where the reference point has a fractional lane position between 0.0 and 1.0),
  37.      * and consecutive lanes that follow the route if possible in the same lane. The list of lanes stops when a continuation
  38.      * lane does not lead in the direction of the route provided by the strategical planner. For each lane, the direction to
  39.      * drive is provided.
  40.      */
  41.     private final List<LaneDirection> laneDirectionList;

  42.     /**
  43.      * The start point on the first lane in the laneDirectionList. When this is a point that represents a GTU position, it
  44.      * should represent the reference point of the GTU.
  45.      */
  46.     private final Length referencePosition;

  47.     /**
  48.      * @param path the path it the GTU keeps driving in the same lane, and follows the route if possible in the same lane. The
  49.      *            path stops when the lane or a continuation lane does not lead in the direction of the route provided by the
  50.      *            strategical planner.
  51.      * @param laneDirectionList the current lane on which the reference point of the GTU is registered (if the GTU is registered
  52.      *            on multiple lanes with the reference point, one lane is chosen where the reference point has a fractional lane
  53.      *            position between 0.0 and 1.0), and consecutive lanes that follow the route if possible in the same lane. The
  54.      *            list of lanes stops when a continuation lane does not lead in the direction of the route provided by the
  55.      *            strategical planner. For each lane, the direction to drive is provided.
  56.      * @param referencePosition the start point on the first lane in the laneDirectionList. When this is a point that represents
  57.      *            a GTU position, it should represent the reference point of the GTU.
  58.      */
  59.     public LanePathInfo(final OTSLine3D path, final List<LaneDirection> laneDirectionList, final Length referencePosition)
  60.     {
  61.         super();
  62.         this.path = path;
  63.         this.laneDirectionList = laneDirectionList;
  64.         this.referencePosition = referencePosition;
  65.     }

  66.     /**
  67.      * @return path the path it the GTU keeps driving in the same lane, and follows the route if possible in the same lane. The
  68.      *         path stops when the lane or a continuation lane does not lead in the direction of the route provided by the
  69.      *         strategical planner.
  70.      */
  71.     public final OTSLine3D getPath()
  72.     {
  73.         return this.path;
  74.     }

  75.     /**
  76.      * @return laneList the current lane on which the reference point of the GTU is registered (if the GTU is registered on
  77.      *         multiple lanes with the reference point, one lane is chosen where the reference point has a fractional lane
  78.      *         position between 0.0 and 1.0), and consecutive lanes that follow the route if possible in the same lane. The list
  79.      *         of lanes stops when a continuation lane does not lead in the direction of the route provided by the strategical
  80.      *         planner. For each lane, the direction to drive is provided.
  81.      */
  82.     public final List<LaneDirection> getLaneDirectionList()
  83.     {
  84.         return this.laneDirectionList;
  85.     }

  86.     /**
  87.      * @return list of lanes
  88.      */
  89.     public final List<Lane> getLanes()
  90.     {
  91.         List<Lane> lanes = new ArrayList<>();
  92.         for (LaneDirection ld : this.laneDirectionList)
  93.         {
  94.             lanes.add(ld.getLane());
  95.         }
  96.         return lanes;
  97.     }

  98.     /**
  99.      * The reference lane is the widest lane on which the reference point of the GTU is fully registered.
  100.      * @return the reference lane on which the GTU is registered, plus the driving direction on this lane, or null if the GTU is
  101.      *         not registered on any lane.
  102.      */
  103.     public final LaneDirection getReferenceLaneDirection()
  104.     {
  105.         return this.laneDirectionList.isEmpty() ? null : this.laneDirectionList.get(0);
  106.     }

  107.     /**
  108.      * The reference lane is the widest lane on which the reference point of the GTU is fully registered.
  109.      * @return the reference lane on which the GTU is registered, or null if the GTU is not registered on any lane.
  110.      */
  111.     public final Lane getReferenceLane()
  112.     {
  113.         return this.laneDirectionList.isEmpty() ? null : this.laneDirectionList.get(0).getLane();
  114.     }

  115.     /**
  116.      * @return the start point on the first lane in the laneDirectionList. When this is a point that represents a GTU position,
  117.      *         it should represent the reference point of the GTU.
  118.      */
  119.     public final Length getReferencePosition()
  120.     {
  121.         return this.referencePosition;
  122.     }

  123.     /** {@inheritDoc} */
  124.     @Override
  125.     public final String toString()
  126.     {
  127.         return "LanePathInfo [path=" + this.path + ", laneDirectionList=" + this.laneDirectionList + ", referencePosition="
  128.                 + this.referencePosition + "]";
  129.     }

  130. }