1 package org.opentrafficsim.road.gtu.lane.tactical;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.opentrafficsim.core.geometry.OTSLine3D;
9 import org.opentrafficsim.road.network.lane.Lane;
10 import org.opentrafficsim.road.network.lane.LaneDirection;
11
12 /**
13 * This class provides the following information for an operational plan:
14 * <ul>
15 * <li>the lanes to follow, with the direction to drive on them</li>
16 * <li>the starting point on the first lane</li>
17 * <li>the path to follow when staying on the same lane</li>
18 * </ul>
19 * <p>
20 * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22 * </p>
23 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
24 * initial version Dec 31, 2015 <br>
25 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
27 */
28 public class LanePathInfo implements Serializable
29 {
30 /** */
31 private static final long serialVersionUID = 20151231L;
32
33 /**
34 * The path it the GTU keeps driving in the same lane, and follows the route if possible in the same lane. The path stops
35 * when the lane or a continuation lane does not lead in the direction of the route provided by the strategical planner.
36 */
37 private final OTSLine3D path;
38
39 /**
40 * The current lane on which the reference point of the GTU is registered (if the GTU is registered on multiple lanes with
41 * the reference point, one lane is chosen where the reference point has a fractional lane position between 0.0 and 1.0),
42 * and consecutive lanes that follow the route if possible in the same lane. The list of lanes stops when a continuation
43 * lane does not lead in the direction of the route provided by the strategical planner. For each lane, the direction to
44 * drive is provided.
45 */
46 private final List<LaneDirection> laneDirectionList;
47
48 /**
49 * The start point on the first lane in the laneDirectionList. When this is a point that represents a GTU position, it
50 * should represent the reference point of the GTU.
51 */
52 private final Length referencePosition;
53
54 /**
55 * @param path OTSLine3D; the path it the GTU keeps driving in the same lane, and follows the route if possible in the same
56 * lane. The path stops when the lane or a continuation lane does not lead in the direction of the route provided
57 * by the strategical planner.
58 * @param laneDirectionList List<LaneDirection>; the current lane on which the reference point of the GTU is
59 * registered (if the GTU is registered on multiple lanes with the reference point, one lane is chosen where the
60 * reference point has a fractional lane position between 0.0 and 1.0), and consecutive lanes that follow the
61 * route if possible in the same lane. The list of lanes stops when a continuation lane does not lead in the
62 * direction of the route provided by the strategical planner. For each lane, the direction to drive is provided.
63 * @param referencePosition Length; the start point on the first lane in the laneDirectionList. When this is a point that
64 * represents a GTU position, it should represent the reference point of the GTU.
65 */
66 public LanePathInfo(final OTSLine3D path, final List<LaneDirection> laneDirectionList, final Length referencePosition)
67 {
68 this.path = path;
69 this.laneDirectionList = laneDirectionList;
70 this.referencePosition = referencePosition;
71 }
72
73 /**
74 * @return path the path it the GTU keeps driving in the same lane, and follows the route if possible in the same lane. The
75 * path stops when the lane or a continuation lane does not lead in the direction of the route provided by the
76 * strategical planner.
77 */
78 public final OTSLine3D getPath()
79 {
80 return this.path;
81 }
82
83 /**
84 * @return laneList the current lane on which the reference point of the GTU is registered (if the GTU is registered on
85 * multiple lanes with the reference point, one lane is chosen where the reference point has a fractional lane
86 * position between 0.0 and 1.0), and consecutive lanes that follow the route if possible in the same lane. The list
87 * of lanes stops when a continuation lane does not lead in the direction of the route provided by the strategical
88 * planner. For each lane, the direction to drive is provided.
89 */
90 public final List<LaneDirection> getLaneDirectionList()
91 {
92 return this.laneDirectionList;
93 }
94
95 /**
96 * @return list of lanes
97 */
98 public final List<Lane> getLanes()
99 {
100 List<Lane> lanes = new ArrayList<>();
101 for (LaneDirection ld : this.laneDirectionList)
102 {
103 lanes.add(ld.getLane());
104 }
105 return lanes;
106 }
107
108 /**
109 * The reference lane is the widest lane on which the reference point of the GTU is fully registered.
110 * @return the reference lane on which the GTU is registered, plus the driving direction on this lane, or null if the GTU is
111 * not registered on any lane.
112 */
113 public final LaneDirection getReferenceLaneDirection()
114 {
115 return this.laneDirectionList.isEmpty() ? null : this.laneDirectionList.get(0);
116 }
117
118 /**
119 * The reference lane is the widest lane on which the reference point of the GTU is fully registered.
120 * @return the reference lane on which the GTU is registered, or null if the GTU is not registered on any lane.
121 */
122 public final Lane getReferenceLane()
123 {
124 return this.laneDirectionList.isEmpty() ? null : this.laneDirectionList.get(0).getLane();
125 }
126
127 /**
128 * @return the start point on the first lane in the laneDirectionList. When this is a point that represents a GTU position,
129 * it should represent the reference point of the GTU.
130 */
131 public final Length getReferencePosition()
132 {
133 return this.referencePosition;
134 }
135
136 /** {@inheritDoc} */
137 @Override
138 public final String toString()
139 {
140 return "LanePathInfo [path=" + this.path + ", laneDirectionList=" + this.laneDirectionList + ", referencePosition="
141 + this.referencePosition + "]";
142 }
143
144 }