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.Speed;
8 import org.djunits.value.vdouble.scalar.Time;
9 import org.opentrafficsim.core.geometry.OTSLine3D;
10 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
11 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
12 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
13 import org.opentrafficsim.road.network.lane.Lane;
14
15 import nl.tudelft.simulation.language.d3.DirectedPoint;
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-2017 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> secondLaneList;
40
41 private final int lastLaneIndex;
42
43 private final double lastFractionalPosition;
44
45 /**
46 * Construct an operational plan without a lane change.
47 * @param gtu the GTU for debugging purposes
48 * @param path the path to follow from a certain time till a certain time. The path should have <i>at least</i> the length
49 * @param startTime the absolute start time when we start executing the path
50 * @param startSpeed the GTU speed when we start executing the path
51 * @param operationalPlanSegmentList the segments that make up the path with an acceleration, constant speed or deceleration
52 * profile
53 * @param referenceLaneList the list of lanes that are part of this plan
54 * @throws OperationalPlanException when the path is too short for the operation
55 */
56 public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final OTSLine3D path, final Time startTime, final Speed startSpeed,
57 final List<Segment> operationalPlanSegmentList, final List<Lane> referenceLaneList) throws OperationalPlanException
58 {
59 super(gtu, path, startTime, startSpeed, operationalPlanSegmentList);
60 this.referenceLaneList = referenceLaneList;
61 this.secondLaneList = null;
62 this.lastLaneIndex = 0;
63 this.lastFractionalPosition = 0;
64 }
65
66 /**
67 * Construct an operational plan with a lane change.
68 * @param gtu the GTU for debugging purposes
69 * @param path the path to follow from a certain time till a certain time. The path should have <i>at least</i> the length
70 * @param startTime the absolute start time when we start executing the path
71 * @param startSpeed the GTU speed when we start executing the path
72 * @param operationalPlanSegmentList the segments that make up the path with an acceleration, constant speed or deceleration
73 * profile
74 * @param fromLaneList the list of lanes that the gtu comes from
75 * @param toLaneList the list of lanes that the gtu goes towards
76 * @param lastLaneIndex index in lane arrays of last position in plan
77 * @param lastFractionalPosition fractional position of last postition in plan
78 * @throws OperationalPlanException when the path is too short for the operation
79 */
80 @SuppressWarnings("checkstyle:parameternumber")
81 public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final OTSLine3D path, final Time startTime, final Speed startSpeed,
82 final List<Segment> operationalPlanSegmentList, final List<Lane> fromLaneList, final List<Lane> toLaneList,
83 final int lastLaneIndex, final double lastFractionalPosition) throws OperationalPlanException
84 {
85 super(gtu, path, startTime, startSpeed, operationalPlanSegmentList);
86 this.referenceLaneList = fromLaneList;
87 this.secondLaneList = toLaneList;
88 this.lastLaneIndex = lastLaneIndex;
89 this.lastFractionalPosition = lastFractionalPosition;
90 }
91
92 /**
93 * Build a plan where the GTU will wait for a certain time. Of course no lane change takes place.
94 * @param gtu the GTU for debugging purposes
95 * @param waitPoint the point at which the GTU will wait
96 * @param startTime the current time or a time in the future when the plan should start
97 * @param duration the waiting time
98 * @param referenceLane the reference lane where the halting takes place
99 * @throws OperationalPlanException when construction of a waiting path fails
100 */
101 public LaneBasedOperationalPlan(final LaneBasedGTU gtu, final DirectedPoint waitPoint, final Time startTime,
102 final Duration duration, final Lane referenceLane) throws OperationalPlanException
103 {
104 super(gtu, waitPoint, startTime, duration);
105 this.referenceLaneList = new ArrayList<>();
106 this.referenceLaneList.add(referenceLane);
107 this.secondLaneList = null;
108 this.lastLaneIndex = 0;
109 this.lastFractionalPosition = 0;
110 }
111
112 /**
113 * Check if we deviate from the center line.
114 * @return whether this maneuver involves deviation from the center line.
115 */
116 public final boolean isDeviative()
117 {
118 return this.secondLaneList != null;
119 }
120
121 /**
122 * @return referenceLane
123 */
124 public final Lane getReferenceLane()
125 {
126 return this.referenceLaneList.get(0);
127 }
128
129 /**
130 * @return referenceLaneList
131 */
132 public final List<Lane> getReferenceLaneList()
133 {
134 return this.referenceLaneList;
135 }
136
137 /**
138 * @return secondLaneList
139 */
140 public final List<Lane> getSecondLaneList()
141 {
142 return this.secondLaneList;
143 }
144
145 /**
146 * @return lastLaneIndex.
147 */
148 public final int getLastLaneIndex()
149 {
150 return this.lastLaneIndex;
151 }
152
153 /**
154 * @return lastFractionalPosition.
155 */
156 public final double getLastFractionalPosition()
157 {
158 return this.lastFractionalPosition;
159 }
160
161 /** {@inheritDoc} */
162 @Override
163 public final String toString()
164 {
165 return "LaneBasedOperationalPlan [referenceLaneList=" + this.referenceLaneList + ", secondLaneList="
166 + this.secondLaneList + "]";
167 }
168 }