View Javadoc
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.base.parameters.ParameterException;
10  import org.opentrafficsim.core.gtu.GtuException;
11  import org.opentrafficsim.core.network.LateralDirectionality;
12  import org.opentrafficsim.core.network.NetworkException;
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.LaneBasedAbstractPerceptionCategory;
17  import org.opentrafficsim.road.gtu.lane.perception.categories.LaneBasedPerceptionCategory;
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 LaneBasedAbstractPerceptionCategory implements LaneBasedPerceptionCategory
34  {
35  
36      /** */
37      private static final long serialVersionUID = 20160000L;
38  
39      /** Infrastructure lane change info per relative lane. */
40      private Map<RelativeLane, TimeStampedObject<SortedSet<InfrastructureLaneChangeInfoToledo>>> infrastructureLaneChangeInfo;
41  
42      /** Wrapped regular infrastructureCategory. */
43      private final DirectInfrastructurePerception infrastructureCategory;
44  
45      /**
46       * @param perception LanePerception; perception
47       */
48      public ToledoPerception(final LanePerception perception)
49      {
50          super(perception);
51          this.infrastructureCategory = new DirectInfrastructurePerception(perception);
52      }
53  
54      /**
55       * Updates the infrastructural lane change info.
56       * @param lane RelativeLane; relative lateral lane
57       * @throws GtuException when GTU is not initialized
58       */
59      public void updateInfrastructureLaneChangeInfo(final RelativeLane lane) throws GtuException
60      {
61          //
62      }
63  
64      /**
65       * Returns infrastructure lane change info of a lane. A set is returned as multiple points may force lane changes. Which
66       * point is considered most critical is a matter of driver interpretation and may change over time. This is shown below.
67       * Suppose vehicle A needs to take the off-ramp, and that behavior is that the minimum distance per required lane change
68       * determines how critical it is. First, 400m before the lane-drop, the off-ramp is critical. 300m downstream, the lane-drop
69       * is critical. Info is sorted by distance, closest first.
70       * 
71       * <pre>
72       * _______
73       * _ _A_ _\_________
74       * _ _ _ _ _ _ _ _ _
75       * _________ _ _ ___
76       *          \_______
77       *     (-)        Lane-drop: 1 lane change  in 400m (400m per lane change)
78       *     (--------) Off-ramp:  3 lane changes in 900m (300m per lane change, critical)
79       *     
80       *     (-)        Lane-drop: 1 lane change  in 100m (100m per lane change, critical)
81       *     (--------) Off-ramp:  3 lane changes in 600m (200m per lane change)
82       * </pre>
83       * 
84       * @param lane RelativeLane; relative lateral lane
85       * @return infrastructure lane change info of a lane
86       */
87      public final SortedSet<InfrastructureLaneChangeInfoToledo> getInfrastructureLaneChangeInfo(final RelativeLane lane)
88      {
89          return new TreeSet<>();
90          // return this.infrastructureLaneChangeInfo.get(lane).getObject();
91      }
92  
93      /**
94       * Returns time stamped infrastructure lane change info of a lane. A set is returned as multiple points may force lane
95       * changes. Which point is considered most critical is a matter of driver interpretation and may change over time. This is
96       * shown below. Suppose vehicle A needs to take the off-ramp, and that behavior is that the minimum distance per required
97       * lane change determines how critical it is. First, 400m before the lane-drop, the off-ramp is critical. 300m downstream,
98       * the lane-drop is critical. Info is sorted by distance, closest first.
99       * 
100      * <pre>
101      * _______
102      * _ _A_ _\_________
103      * _ _ _ _ _ _ _ _ _
104      * _________ _ _ ___
105      *          \_______
106      *     (-)        Lane-drop: 1 lane change  in 400m (400m per lane change)
107      *     (--------) Off-ramp:  3 lane changes in 900m (300m per lane change, critical)
108      *     
109      *     (-)        Lane-drop: 1 lane change  in 100m (100m per lane change, critical)
110      *     (--------) Off-ramp:  3 lane changes in 600m (200m per lane change)
111      * </pre>
112      * 
113      * @param lane RelativeLane; relative lateral lane
114      * @return time stamped infrastructure lane change info of a lane
115      */
116     public final TimeStampedObject<SortedSet<InfrastructureLaneChangeInfoToledo>> getTimeStampedInfrastructureLaneChangeInfo(
117             final RelativeLane lane)
118     {
119         return this.infrastructureLaneChangeInfo.get(lane);
120     }
121 
122     /**
123      * Updates the speed limit prospect.
124      * @param lane RelativeLane; relative lateral lane
125      * @throws GtuException if the GTU was not initialized
126      * @throws ParameterException if a parameter is not defined
127      */
128     public final void updateSpeedLimitProspect(final RelativeLane lane) throws GtuException, ParameterException
129     {
130         this.infrastructureCategory.updateSpeedLimitProspect(lane);
131     }
132 
133     /**
134      * Updates the distance over which lane changes 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      * @throws GtuException if the GTU was not initialized
138      * @throws ParameterException if a parameter is not defined
139      */
140     public final void updateLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
141             throws GtuException, ParameterException
142     {
143         this.infrastructureCategory.updateLegalLaneChangePossibility(fromLane, lat);
144     }
145 
146     /**
147      * Updates the distance over which lane changes remains physically possible.
148      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
149      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
150      * @throws GtuException if the GTU was not initialized
151      * @throws ParameterException if a parameter is not defined
152      */
153     public final void updatePhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
154             throws GtuException, ParameterException
155     {
156         this.infrastructureCategory.updatePhysicalLaneChangePossibility(fromLane, lat);
157     }
158 
159     /**
160      * Updates a set of relative lanes representing the cross section.
161      * @throws GtuException if the GTU was not initialized
162      * @throws ParameterException if a parameter is not defined
163      */
164     public final void updateCrossSection() throws GtuException, ParameterException
165     {
166         this.infrastructureCategory.updateCrossSection();
167     }
168 
169     /**
170      * Returns the prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
171      * @param lane RelativeLane; relative lateral lane
172      * @return prospect for speed limits on a lane
173      */
174     public final SpeedLimitProspect getSpeedLimitProspect(final RelativeLane lane)
175     {
176         return this.infrastructureCategory.getSpeedLimitProspect(lane);
177     }
178 
179     /**
180      * Returns the distance over which a lane change remains legally possible.
181      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
182      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
183      * @return distance over which a lane change remains possible
184      * @throws NullPointerException if {@code lat == null}
185      */
186     public final Length getLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
187     {
188         return this.infrastructureCategory.getLegalLaneChangePossibility(fromLane, lat);
189     }
190 
191     /**
192      * Returns the distance over which a lane change remains physically possible.
193      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
194      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
195      * @return distance over which a lane change remains possible
196      * @throws NullPointerException if {@code lat == null}
197      */
198     public final Length getPhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
199     {
200         return this.infrastructureCategory.getPhysicalLaneChangePossibility(fromLane, lat);
201     }
202 
203     /**
204      * Returns a set of relative lanes representing the cross section. Lanes are sorted left to right.
205      * @return set of relative lanes representing the cross section
206      */
207     public final SortedSet<RelativeLane> getCrossSection()
208     {
209         return this.infrastructureCategory.getCrossSection();
210     }
211 
212     /**
213      * Returns the time stamped prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
214      * @param lane RelativeLane; relative lateral lane
215      * @return time stamped prospect for speed limits on a lane
216      */
217     public final TimeStampedObject<SpeedLimitProspect> getTimeStampedSpeedLimitProspect(final RelativeLane lane)
218     {
219         return this.infrastructureCategory.getTimeStampedSpeedLimitProspect(lane);
220     }
221 
222     /**
223      * Returns the time stamped distance over which a lane change remains legally possible.
224      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
225      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
226      * @return time stamped distance over which a lane change remains possible
227      * @throws NullPointerException if {@code lat == null}
228      */
229     public final TimeStampedObject<Length> getTimeStampedLegalLaneChangePossibility(final RelativeLane fromLane,
230             final LateralDirectionality lat)
231     {
232         return this.infrastructureCategory.getTimeStampedLegalLaneChangePossibility(fromLane, lat);
233     }
234 
235     /**
236      * Returns the time stamped distance over which a lane change remains physically possible.
237      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
238      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
239      * @return time stamped distance over which a lane change remains possible
240      * @throws NullPointerException if {@code lat == null}
241      */
242     public final TimeStampedObject<Length> getTimeStampedPhysicalLaneChangePossibility(final RelativeLane fromLane,
243             final LateralDirectionality lat)
244     {
245         return this.infrastructureCategory.getTimeStampedPhysicalLaneChangePossibility(fromLane, lat);
246     }
247 
248     /**
249      * Returns a time stamped set of relative lanes representing the cross section. Lanes are sorted left to right.
250      * @return time stamped set of relative lanes representing the cross section
251      */
252     public final TimeStampedObject<SortedSet<RelativeLane>> getTimeStampedCrossSection()
253     {
254         return this.infrastructureCategory.getTimeStampedCrossSection();
255     }
256 
257     /** {@inheritDoc} */
258     @Override
259     public final void updateAll() throws GtuException, NetworkException, ParameterException
260     {
261         this.infrastructureCategory.updateAll();
262     }
263 
264     /** {@inheritDoc} */
265     @Override
266     public final String toString()
267     {
268         return "ToledoPerceptionCategory";
269     }
270 
271 }