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 org.djunits.value.vdouble.scalar.Duration;
7   import org.djunits.value.vdouble.scalar.Length;
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  import nl.tudelft.simulation.language.d3.DirectedPoint;
17  
18  /**
19   * An operational plan with some extra information about the lanes and lane changes so this information does not have to be
20   * recalculated multiple times. Furthermore, it is quite expensive to check whether a lane change is part of the oprtational
21   * plan based on geographical data.
22   * <p>
23   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * </p>
26   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
27   * initial version Jan 20, 2016 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   */
31  public class LaneBasedOperationalPlan extends OperationalPlan
32  {
33      /** */
34      private static final long serialVersionUID = 20160120L;
35  
36      /** The list of lanes that are part of this plan; these will be deregistered in case of lane change. */
37      private final List<Lane> referenceLaneList;
38  
39      /** The list of new lanes to which the GTU is driving, parallel to the referenceLaneList. */
40      private final List<Lane> secondLaneList;
41  
42      private final int lastLaneIndex;
43  
44      private final double lastFractionalPosition;
45  
46      /**
47       * Construct an operational plan without a lane change.
48       * @param gtu the GTU for debugging purposes
49       * @param path the path to follow from a certain time till a certain time. The path should have <i>at least</i> the length
50       * @param startTime the absolute start time when we start executing the path
51       * @param startSpeed the GTU speed when we start executing the path
52       * @param operationalPlanSegmentList the segments that make up the path with an acceleration, constant speed or deceleration
53       *            profile
54       * @param referenceLaneList the list of lanes that are part of this plan
55       * @throws OperationalPlanException when the path is too short for the operation
56       */
57      public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final OTSLine3D path, final Time startTime, final Speed startSpeed,
58              final List<Segment> operationalPlanSegmentList, final List<Lane> referenceLaneList) throws OperationalPlanException
59      {
60          super(gtu, path, startTime, startSpeed, operationalPlanSegmentList);
61          this.referenceLaneList = referenceLaneList;
62          this.secondLaneList = null;
63          this.lastLaneIndex = 0;
64          this.lastFractionalPosition = 0;
65      }
66  
67      /**
68       * Construct an operational plan with a lane change.
69       * @param gtu the GTU for debugging purposes
70       * @param path the path to follow from a certain time till a certain time. The path should have <i>at least</i> the length
71       * @param startTime the absolute start time when we start executing the path
72       * @param startSpeed the GTU speed when we start executing the path
73       * @param operationalPlanSegmentList the segments that make up the path with an acceleration, constant speed or deceleration
74       *            profile
75       * @param fromLaneList the list of lanes that the gtu comes from
76       * @param toLaneList the list of lanes that the gtu goes towards
77       * @param lastLaneIndex index in lane arrays of last position in plan
78       * @param lastFractionalPosition fractional position of last postition in plan
79       * @throws OperationalPlanException when the path is too short for the operation
80       */
81      @SuppressWarnings("checkstyle:parameternumber")
82      public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final OTSLine3D path, final Time startTime, final Speed startSpeed,
83              final List<Segment> operationalPlanSegmentList, final List<Lane> fromLaneList, final List<Lane> toLaneList,
84              final int lastLaneIndex, final double lastFractionalPosition) throws OperationalPlanException
85      {
86          super(gtu, path, startTime, startSpeed, operationalPlanSegmentList);
87          this.referenceLaneList = fromLaneList;
88          this.secondLaneList = toLaneList;
89          this.lastLaneIndex = lastLaneIndex;
90          this.lastFractionalPosition = lastFractionalPosition;
91      }
92  
93      /**
94       * Build a plan where the GTU will wait for a certain time. Of course no lane change takes place.
95       * @param gtu the GTU for debugging purposes
96       * @param waitPoint the point at which the GTU will wait
97       * @param startTime the current time or a time in the future when the plan should start
98       * @param duration the waiting time
99       * @param referenceLane the reference lane where the halting takes place
100      * @throws OperationalPlanException when construction of a waiting path fails
101      */
102     public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final DirectedPoint waitPoint, final Time startTime,
103             final Duration duration, final Lane referenceLane) throws OperationalPlanException
104     {
105         super(gtu, waitPoint, startTime, duration);
106         this.referenceLaneList = new ArrayList<>();
107         this.referenceLaneList.add(referenceLane);
108         this.secondLaneList = null;
109         this.lastLaneIndex = 0;
110         this.lastFractionalPosition = 0;
111     }
112 
113     /**
114      * Check if we deviate from the center line.
115      * @return whether this maneuver involves deviation from the center line.
116      */
117     public final boolean isDeviative()
118     {
119         return this.secondLaneList != null;
120     }
121 
122     /**
123      * @return referenceLane
124      */
125     public final Lane getReferenceLane()
126     {
127         return this.referenceLaneList.get(0);
128     }
129 
130     /**
131      * @return referenceLaneList
132      */
133     public final List<Lane> getReferenceLaneList()
134     {
135         return this.referenceLaneList;
136     }
137 
138     /**
139      * @return secondLaneList
140      */
141     public final List<Lane> getSecondLaneList()
142     {
143         return this.secondLaneList;
144     }
145     
146     /**
147      * @return lastLaneIndex.
148      */
149     public final int getLastLaneIndex()
150     {
151         return this.lastLaneIndex;
152     }
153 
154     /**
155      * @return lastFractionalPosition.
156      */
157     public final double getLastFractionalPosition()
158     {
159         return this.lastFractionalPosition;
160     }
161 
162     /** {@inheritDoc} */
163     @Override
164     public final String toString()
165     {
166         return "LaneBasedOperationalPlan [referenceLaneList=" + this.referenceLaneList + ", secondLaneList="
167                 + this.secondLaneList + "]";
168     }
169 }