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