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.gtu.perception.AbstractPerceptionCategory;
12  import org.opentrafficsim.core.gtu.perception.PerceptionCategory;
13  import org.opentrafficsim.core.network.LateralDirectionality;
14  import org.opentrafficsim.core.network.NetworkException;
15  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
16  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
17  import org.opentrafficsim.road.gtu.lane.perception.categories.DirectInfrastructurePerception;
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-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
26   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
27   * <p>
28   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Jul 28, 2016 <br>
29   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
30   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
31   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
32   */
33  // TODO updateInfrastructureLaneChangeInfo with split number
34  public class ToledoPerception extends AbstractPerceptionCategory implements PerceptionCategory
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<InfrastructureLaneChangeInfoToledo>>> infrastructureLaneChangeInfo;
42  
43      /** Wrapped regular infrastructureCategory. */
44      private final DirectInfrastructurePerception infrastructureCategory;
45  
46      /**
47       * @param perception 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 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 relative lateral lane
86       * @return infrastructure lane change info of a lane
87       */
88      public final SortedSet<InfrastructureLaneChangeInfoToledo> 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 relative lateral lane
115      * @return time stamped infrastructure lane change info of a lane
116      */
117     public final TimeStampedObject<SortedSet<InfrastructureLaneChangeInfoToledo>> getTimeStampedInfrastructureLaneChangeInfo(
118             final RelativeLane lane)
119     {
120         return this.infrastructureLaneChangeInfo.get(lane);
121     }
122 
123     /**
124      * Updates the speed limit prospect.
125      * @param lane relative lateral lane
126      * @throws GTUException if the GTU was not initialized
127      * @throws ParameterException if a parameter is not defined
128      */
129     public final void updateSpeedLimitProspect(final RelativeLane lane) throws GTUException, ParameterException
130     {
131         this.infrastructureCategory.updateSpeedLimitProspect(lane);
132     }
133 
134     /**
135      * Updates the distance over which lane changes remains legally possible.
136      * @param fromLane lane from which the lane change possibility is requested
137      * @param lat LEFT or RIGHT, null not allowed
138      * @throws GTUException if the GTU was not initialized
139      * @throws ParameterException if a parameter is not defined
140      */
141     public final void updateLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
142             throws GTUException, ParameterException
143     {
144         this.infrastructureCategory.updateLegalLaneChangePossibility(fromLane, lat);
145     }
146 
147     /**
148      * Updates the distance over which lane changes remains physically possible.
149      * @param fromLane lane from which the lane change possibility is requested
150      * @param lat LEFT or RIGHT, null not allowed
151      * @throws GTUException if the GTU was not initialized
152      * @throws ParameterException if a parameter is not defined
153      */
154     public final void updatePhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
155             throws GTUException, ParameterException
156     {
157         this.infrastructureCategory.updatePhysicalLaneChangePossibility(fromLane, lat);
158     }
159 
160     /**
161      * Updates a set of relative lanes representing the cross section.
162      * @throws GTUException if the GTU was not initialized
163      * @throws ParameterException if a parameter is not defined
164      */
165     public final void updateCrossSection() throws GTUException, ParameterException
166     {
167         this.infrastructureCategory.updateCrossSection();
168     }
169 
170     /**
171      * Returns the prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
172      * @param lane relative lateral lane
173      * @return prospect for speed limits on a lane
174      */
175     public final SpeedLimitProspect getSpeedLimitProspect(final RelativeLane lane)
176     {
177         return this.infrastructureCategory.getSpeedLimitProspect(lane);
178     }
179 
180     /**
181      * Returns the distance over which a lane change remains legally possible.
182      * @param fromLane lane from which the lane change possibility is requested
183      * @param lat LEFT or RIGHT, null not allowed
184      * @return distance over which a lane change remains possible
185      * @throws NullPointerException if {@code lat == null}
186      */
187     public final Length getLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
188     {
189         return this.infrastructureCategory.getLegalLaneChangePossibility(fromLane, lat);
190     }
191 
192     /**
193      * Returns the distance over which a lane change remains physically possible.
194      * @param fromLane lane from which the lane change possibility is requested
195      * @param lat LEFT or RIGHT, null not allowed
196      * @return distance over which a lane change remains possible
197      * @throws NullPointerException if {@code lat == null}
198      */
199     public final Length getPhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
200     {
201         return this.infrastructureCategory.getPhysicalLaneChangePossibility(fromLane, lat);
202     }
203 
204     /**
205      * Returns a set of relative lanes representing the cross section. Lanes are sorted left to right.
206      * @return set of relative lanes representing the cross section
207      */
208     public final SortedSet<RelativeLane> getCrossSection()
209     {
210         return this.infrastructureCategory.getCrossSection();
211     }
212 
213     /**
214      * Returns the time stamped prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
215      * @param lane relative lateral lane
216      * @return time stamped prospect for speed limits on a lane
217      */
218     public final TimeStampedObject<SpeedLimitProspect> getTimeStampedSpeedLimitProspect(final RelativeLane lane)
219     {
220         return this.infrastructureCategory.getTimeStampedSpeedLimitProspect(lane);
221     }
222 
223     /**
224      * Returns the time stamped distance over which a lane change remains legally possible.
225      * @param fromLane lane from which the lane change possibility is requested
226      * @param lat LEFT or RIGHT, null not allowed
227      * @return time stamped distance over which a lane change remains possible
228      * @throws NullPointerException if {@code lat == null}
229      */
230     public final TimeStampedObject<Length> getTimeStampedLegalLaneChangePossibility(final RelativeLane fromLane,
231             final LateralDirectionality lat)
232     {
233         return this.infrastructureCategory.getTimeStampedLegalLaneChangePossibility(fromLane, lat);
234     }
235 
236     /**
237      * Returns the time stamped distance over which a lane change remains physically possible.
238      * @param fromLane lane from which the lane change possibility is requested
239      * @param lat LEFT or RIGHT, null not allowed
240      * @return time stamped distance over which a lane change remains possible
241      * @throws NullPointerException if {@code lat == null}
242      */
243     public final TimeStampedObject<Length> getTimeStampedPhysicalLaneChangePossibility(final RelativeLane fromLane,
244             final LateralDirectionality lat)
245     {
246         return this.infrastructureCategory.getTimeStampedPhysicalLaneChangePossibility(fromLane, lat);
247     }
248 
249     /**
250      * Returns a time stamped set of relative lanes representing the cross section. Lanes are sorted left to right.
251      * @return time stamped set of relative lanes representing the cross section
252      */
253     public final TimeStampedObject<SortedSet<RelativeLane>> getTimeStampedCrossSection()
254     {
255         return this.infrastructureCategory.getTimeStampedCrossSection();
256     }
257 
258     /** {@inheritDoc} */
259     @Override
260     public final void updateAll() throws GTUException, NetworkException, ParameterException
261     {
262         this.infrastructureCategory.updateAll();
263     }
264 
265     /** {@inheritDoc} */
266     @Override
267     public final String toString()
268     {
269         return "ToledoPerceptionCategory";
270     }
271 
272 }