1 package org.opentrafficsim.road.gtu.lane.tactical.toledo;
2
3 import java.util.Map;
4 import java.util.SortedSet;
5 import java.util.TreeSet;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.opentrafficsim.base.TimeStampedObject;
9 import org.opentrafficsim.core.gtu.GtuException;
10 import org.opentrafficsim.core.gtu.perception.AbstractPerceptionCategory;
11 import org.opentrafficsim.core.network.LateralDirectionality;
12 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
13 import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
14 import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
15 import org.opentrafficsim.road.gtu.lane.perception.categories.DirectInfrastructurePerception;
16 import org.opentrafficsim.road.gtu.lane.perception.categories.LaneBasedPerceptionCategory;
17 import org.opentrafficsim.road.network.LaneChangeInfo;
18 import org.opentrafficsim.road.network.speed.SpeedLimitProspect;
19
20 /**
21 * Wrapper class around {@code InfrastructureCategory} that forwards all methods except for infrastructure lane change info.
22 * These methods determine and return infrastructure information of type {@code InfrastructureLaneChangeInfoToledo}, which
23 * includes split number.
24 * <p>
25 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
26 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
27 * </p>
28 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
29 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
30 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
31 */
32 // TODO updateInfrastructureLaneChangeInfo with split number
33 public class ToledoPerception extends AbstractPerceptionCategory<LaneBasedGtu, LanePerception>
34 implements LaneBasedPerceptionCategory
35 {
36
37 /** */
38 private static final long serialVersionUID = 20160000L;
39
40 /** Infrastructure lane change info per relative lane. */
41 private Map<RelativeLane, TimeStampedObject<SortedSet<LaneChangeInfo>>> infrastructureLaneChangeInfo;
42
43 /** Wrapped regular infrastructureCategory. */
44 private final DirectInfrastructurePerception infrastructureCategory;
45
46 /**
47 * @param perception LanePerception; perception
48 */
49 public ToledoPerception(final LanePerception perception)
50 {
51 super(perception);
52 this.infrastructureCategory = new DirectInfrastructurePerception(perception);
53 }
54
55 /**
56 * Updates the infrastructural lane change info.
57 * @param lane RelativeLane; relative lateral lane
58 * @throws GtuException when GTU is not initialized
59 */
60 public void updateInfrastructureLaneChangeInfo(final RelativeLane lane) throws GtuException
61 {
62 //
63 }
64
65 /**
66 * Returns infrastructure lane change info of a lane. A set is returned as multiple points may force lane changes. Which
67 * point is considered most critical is a matter of driver interpretation and may change over time. This is shown below.
68 * Suppose vehicle A needs to take the off-ramp, and that behavior is that the minimum distance per required lane change
69 * determines how critical it is. First, 400m before the lane-drop, the off-ramp is critical. 300m downstream, the lane-drop
70 * is critical. Info is sorted by distance, closest first.
71 *
72 * <pre>
73 * _______
74 * _ _A_ _\_________
75 * _ _ _ _ _ _ _ _ _
76 * _________ _ _ ___
77 * \_______
78 * (-) Lane-drop: 1 lane change in 400m (400m per lane change)
79 * (--------) Off-ramp: 3 lane changes in 900m (300m per lane change, critical)
80 *
81 * (-) Lane-drop: 1 lane change in 100m (100m per lane change, critical)
82 * (--------) Off-ramp: 3 lane changes in 600m (200m per lane change)
83 * </pre>
84 *
85 * @param lane RelativeLane; relative lateral lane
86 * @return infrastructure lane change info of a lane
87 */
88 public final SortedSet<LaneChangeInfo> getInfrastructureLaneChangeInfo(final RelativeLane lane)
89 {
90 return new TreeSet<>();
91 // return this.infrastructureLaneChangeInfo.get(lane).getObject();
92 }
93
94 /**
95 * Returns time stamped infrastructure lane change info of a lane. A set is returned as multiple points may force lane
96 * changes. Which point is considered most critical is a matter of driver interpretation and may change over time. This is
97 * shown below. Suppose vehicle A needs to take the off-ramp, and that behavior is that the minimum distance per required
98 * lane change determines how critical it is. First, 400m before the lane-drop, the off-ramp is critical. 300m downstream,
99 * the lane-drop is critical. Info is sorted by distance, closest first.
100 *
101 * <pre>
102 * _______
103 * _ _A_ _\_________
104 * _ _ _ _ _ _ _ _ _
105 * _________ _ _ ___
106 * \_______
107 * (-) Lane-drop: 1 lane change in 400m (400m per lane change)
108 * (--------) Off-ramp: 3 lane changes in 900m (300m per lane change, critical)
109 *
110 * (-) Lane-drop: 1 lane change in 100m (100m per lane change, critical)
111 * (--------) Off-ramp: 3 lane changes in 600m (200m per lane change)
112 * </pre>
113 *
114 * @param lane RelativeLane; relative lateral lane
115 * @return time stamped infrastructure lane change info of a lane
116 */
117 public final TimeStampedObject<SortedSet<LaneChangeInfo>> getTimeStampedInfrastructureLaneChangeInfo(
118 final RelativeLane lane)
119 {
120 return this.infrastructureLaneChangeInfo.get(lane);
121 }
122
123 /**
124 * Returns the prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
125 * @param lane RelativeLane; relative lateral lane
126 * @return prospect for speed limits on a lane
127 */
128 public final SpeedLimitProspect getSpeedLimitProspect(final RelativeLane lane)
129 {
130 return this.infrastructureCategory.getSpeedLimitProspect(lane);
131 }
132
133 /**
134 * Returns the distance over which a lane change remains legally possible.
135 * @param fromLane RelativeLane; lane from which the lane change possibility is requested
136 * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
137 * @return distance over which a lane change remains possible
138 * @throws NullPointerException if {@code lat == null}
139 */
140 public final Length getLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
141 {
142 return this.infrastructureCategory.getLegalLaneChangePossibility(fromLane, lat);
143 }
144
145 /**
146 * Returns the distance over which a lane change remains physically possible.
147 * @param fromLane RelativeLane; lane from which the lane change possibility is requested
148 * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
149 * @return distance over which a lane change remains possible
150 * @throws NullPointerException if {@code lat == null}
151 */
152 public final Length getPhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
153 {
154 return this.infrastructureCategory.getPhysicalLaneChangePossibility(fromLane, lat);
155 }
156
157 /**
158 * Returns a set of relative lanes representing the cross section. Lanes are sorted left to right.
159 * @return set of relative lanes representing the cross section
160 */
161 public final SortedSet<RelativeLane> getCrossSection()
162 {
163 return this.infrastructureCategory.getCrossSection();
164 }
165
166 /** {@inheritDoc} */
167 @Override
168 public final String toString()
169 {
170 return "ToledoPerceptionCategory";
171 }
172
173 }