View Javadoc
1   package org.opentrafficsim.road.gtu.lane.plan.operational;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import nl.tudelft.simulation.language.d3.DirectedPoint;
7   
8   import org.djunits.value.vdouble.scalar.Speed;
9   import org.djunits.value.vdouble.scalar.Time;
10  import org.opentrafficsim.core.geometry.OTSLine3D;
11  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
12  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
13  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
14  import org.opentrafficsim.road.network.lane.Lane;
15  
16  /**
17   * An operational plan with some extra information about the lanes and lane changes so this information does not have to be
18   * recalculated multiple times. Furthermore, it is quite expensive to check whether a lane change is part of the oprtational
19   * plan based on geographical data.
20   * <p>
21   * Copyright (c) 2013-2015 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   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
25   * initial version Jan 20, 2016 <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 class LaneBasedOperationalPlan extends OperationalPlan
30  {
31      /** */
32      private static final long serialVersionUID = 20160120L;
33  
34      /** The list of lanes that are part of this plan; these will be deregistered in case of lane change. */
35      private final List<Lane> referenceLaneList;
36      
37      /** The list of new lanes to which the GTU is driving, parallel to the referenceLaneList. */
38      private final List<Lane> targetLaneList;
39  
40      /**
41       * Construct an operational plan without a lane change.
42       * @param gtu the GTU for debugging purposes
43       * @param path the path to follow from a certain time till a certain time. The path should have <i>at least</i> the length
44       * @param startTime the absolute start time when we start executing the path
45       * @param startSpeed the GTU speed when we start executing the path
46       * @param operationalPlanSegmentList the segments that make up the path with an acceleration, constant speed or deceleration
47       *            profile
48       * @param referenceLaneList the list of lanes that are part of this plan
49       * @throws OperationalPlanException when the path is too short for the operation
50       */
51      public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final OTSLine3D path, final Time.Abs startTime, final Speed startSpeed,
52          List<Segment> operationalPlanSegmentList, final List<Lane> referenceLaneList) throws OperationalPlanException
53      {
54          super(gtu, path, startTime, startSpeed, operationalPlanSegmentList);
55          this.referenceLaneList = referenceLaneList;
56          this.targetLaneList = null;
57      }
58  
59      /**
60       * Build a plan where the GTU will wait for a certain time. Of course no lane change takes place.
61       * @param gtu the GTU for debugging purposes
62       * @param waitPoint the point at which the GTU will wait
63       * @param startTime the current time or a time in the future when the plan should start
64       * @param duration the waiting time
65       * @param referenceLane the reference lane where the halting takes place
66       * @throws OperationalPlanException when construction of a waiting path fails
67       */
68      public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final DirectedPoint waitPoint, final Time.Abs startTime, final Time.Rel duration,
69          final Lane referenceLane) throws OperationalPlanException
70      {
71          super(gtu, waitPoint, startTime, duration);
72          this.referenceLaneList = new ArrayList<>();
73          this.referenceLaneList.add(referenceLane);
74          this.targetLaneList = null;
75      }
76  
77      /**
78       * Check if we make a lane change.
79       * @return whether this maneuver involves a lane change.
80       */
81      public boolean isLaneChange()
82      {
83          return this.targetLaneList != null;
84      }
85  
86      /**
87       * @return referenceLane
88       */
89      public final Lane getReferenceLane()
90      {
91          return this.referenceLaneList.get(0);
92      }
93  
94      /**
95       * @return referenceLaneList
96       */
97      public final List<Lane> getReferenceLaneList()
98      {
99          return this.referenceLaneList;
100     }
101 
102     /**
103      * @return targetLaneList
104      */
105     public final List<Lane> getTargetLaneList()
106     {
107         return this.targetLaneList;
108     }
109 }