LaneBasedOperationalPlan.java

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

  2. import java.util.ArrayList;
  3. import java.util.List;

  4. import org.djunits.value.vdouble.scalar.Duration;
  5. import org.djunits.value.vdouble.scalar.Length;
  6. import org.djunits.value.vdouble.scalar.Speed;
  7. import org.djunits.value.vdouble.scalar.Time;
  8. import org.opentrafficsim.core.geometry.OTSLine3D;
  9. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
  10. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
  11. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  12. import org.opentrafficsim.road.network.lane.Lane;

  13. import nl.tudelft.simulation.language.d3.DirectedPoint;

  14. /**
  15.  * An operational plan with some extra information about the lanes and lane changes so this information does not have to be
  16.  * recalculated multiple times. Furthermore, it is quite expensive to check whether a lane change is part of the oprtational
  17.  * plan based on geographical data.
  18.  * <p>
  19.  * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  20.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  21.  * </p>
  22.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  23.  * initial version Jan 20, 2016 <br>
  24.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  25.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  26.  */
  27. public class LaneBasedOperationalPlan extends OperationalPlan
  28. {
  29.     /** */
  30.     private static final long serialVersionUID = 20160120L;

  31.     /** The list of lanes that are part of this plan; these will be deregistered in case of lane change. */
  32.     private final List<Lane> referenceLaneList;

  33.     /** The list of new lanes to which the GTU is driving, parallel to the referenceLaneList. */
  34.     private final List<Lane> secondLaneList;

  35.     private final int lastLaneIndex;

  36.     private final double lastFractionalPosition;

  37.     /**
  38.      * Construct an operational plan without a lane change.
  39.      * @param gtu the GTU for debugging purposes
  40.      * @param path the path to follow from a certain time till a certain time. The path should have <i>at least</i> the length
  41.      * @param startTime the absolute start time when we start executing the path
  42.      * @param startSpeed the GTU speed when we start executing the path
  43.      * @param operationalPlanSegmentList the segments that make up the path with an acceleration, constant speed or deceleration
  44.      *            profile
  45.      * @param referenceLaneList the list of lanes that are part of this plan
  46.      * @throws OperationalPlanException when the path is too short for the operation
  47.      */
  48.     public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final OTSLine3D path, final Time startTime, final Speed startSpeed,
  49.             final List<Segment> operationalPlanSegmentList, final List<Lane> referenceLaneList) throws OperationalPlanException
  50.     {
  51.         super(gtu, path, startTime, startSpeed, operationalPlanSegmentList);
  52.         this.referenceLaneList = referenceLaneList;
  53.         this.secondLaneList = null;
  54.         this.lastLaneIndex = 0;
  55.         this.lastFractionalPosition = 0;
  56.     }

  57.     /**
  58.      * Construct an operational plan with a lane change.
  59.      * @param gtu the GTU for debugging purposes
  60.      * @param path the path to follow from a certain time till a certain time. The path should have <i>at least</i> the length
  61.      * @param startTime the absolute start time when we start executing the path
  62.      * @param startSpeed the GTU speed when we start executing the path
  63.      * @param operationalPlanSegmentList the segments that make up the path with an acceleration, constant speed or deceleration
  64.      *            profile
  65.      * @param fromLaneList the list of lanes that the gtu comes from
  66.      * @param toLaneList the list of lanes that the gtu goes towards
  67.      * @param lastLaneIndex index in lane arrays of last position in plan
  68.      * @param lastFractionalPosition fractional position of last postition in plan
  69.      * @throws OperationalPlanException when the path is too short for the operation
  70.      */
  71.     @SuppressWarnings("checkstyle:parameternumber")
  72.     public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final OTSLine3D path, final Time startTime, final Speed startSpeed,
  73.             final List<Segment> operationalPlanSegmentList, final List<Lane> fromLaneList, final List<Lane> toLaneList,
  74.             final int lastLaneIndex, final double lastFractionalPosition) throws OperationalPlanException
  75.     {
  76.         super(gtu, path, startTime, startSpeed, operationalPlanSegmentList);
  77.         this.referenceLaneList = fromLaneList;
  78.         this.secondLaneList = toLaneList;
  79.         this.lastLaneIndex = lastLaneIndex;
  80.         this.lastFractionalPosition = lastFractionalPosition;
  81.     }

  82.     /**
  83.      * Build a plan where the GTU will wait for a certain time. Of course no lane change takes place.
  84.      * @param gtu the GTU for debugging purposes
  85.      * @param waitPoint the point at which the GTU will wait
  86.      * @param startTime the current time or a time in the future when the plan should start
  87.      * @param duration the waiting time
  88.      * @param referenceLane the reference lane where the halting takes place
  89.      * @throws OperationalPlanException when construction of a waiting path fails
  90.      */
  91.     public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final DirectedPoint waitPoint, final Time startTime,
  92.             final Duration duration, final Lane referenceLane) throws OperationalPlanException
  93.     {
  94.         super(gtu, waitPoint, startTime, duration);
  95.         this.referenceLaneList = new ArrayList<>();
  96.         this.referenceLaneList.add(referenceLane);
  97.         this.secondLaneList = null;
  98.         this.lastLaneIndex = 0;
  99.         this.lastFractionalPosition = 0;
  100.     }

  101.     /**
  102.      * Check if we deviate from the center line.
  103.      * @return whether this maneuver involves deviation from the center line.
  104.      */
  105.     public final boolean isDeviative()
  106.     {
  107.         return this.secondLaneList != null;
  108.     }

  109.     /**
  110.      * @return referenceLane
  111.      */
  112.     public final Lane getReferenceLane()
  113.     {
  114.         return this.referenceLaneList.get(0);
  115.     }

  116.     /**
  117.      * @return referenceLaneList
  118.      */
  119.     public final List<Lane> getReferenceLaneList()
  120.     {
  121.         return this.referenceLaneList;
  122.     }

  123.     /**
  124.      * @return secondLaneList
  125.      */
  126.     public final List<Lane> getSecondLaneList()
  127.     {
  128.         return this.secondLaneList;
  129.     }
  130.    
  131.     /**
  132.      * @return lastLaneIndex.
  133.      */
  134.     public final int getLastLaneIndex()
  135.     {
  136.         return this.lastLaneIndex;
  137.     }

  138.     /**
  139.      * @return lastFractionalPosition.
  140.      */
  141.     public final double getLastFractionalPosition()
  142.     {
  143.         return this.lastFractionalPosition;
  144.     }

  145.     /** {@inheritDoc} */
  146.     @Override
  147.     public final String toString()
  148.     {
  149.         return "LaneBasedOperationalPlan [referenceLaneList=" + this.referenceLaneList + ", secondLaneList="
  150.                 + this.secondLaneList + "]";
  151.     }
  152. }