View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.toledo;
2   
3   import java.util.Map;
4   import java.util.SortedSet;
5   
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.opentrafficsim.base.TimeStampedObject;
8   import org.opentrafficsim.core.gtu.GTUException;
9   import org.opentrafficsim.core.gtu.behavioralcharacteristics.ParameterException;
10  import org.opentrafficsim.core.gtu.perception.AbstractPerceptionCategory;
11  import org.opentrafficsim.core.gtu.perception.PerceptionCategory;
12  import org.opentrafficsim.core.network.LateralDirectionality;
13  import org.opentrafficsim.core.network.NetworkException;
14  import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
15  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
16  import org.opentrafficsim.road.gtu.lane.perception.categories.DirectInfrastructurePerception;
17  import org.opentrafficsim.road.network.speed.SpeedLimitProspect;
18  
19  /**
20   * Wrapper class around {@code InfrastructureCategory} that forwards all methods except for infrastructure lane change info.
21   * These methods determine and return infrastructure information of type {@code InfrastructureLaneChangeInfoToledo}, which
22   * includes split number.
23   * <p>
24   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
26   * <p>
27   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Jul 28, 2016 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
31   */
32  // TODO updateInfrastructureLaneChangeInfo with split number
33  public class ToledoPerception extends AbstractPerceptionCategory implements PerceptionCategory
34  {
35  
36      /** Infrastructure lane change info per relative lane. */
37      private Map<RelativeLane, TimeStampedObject<SortedSet<InfrastructureLaneChangeInfoToledo>>> infrastructureLaneChangeInfo;
38  
39      /** Wrapped regular infrastructureCategory. */
40      private final DirectInfrastructurePerception infrastructureCategory;
41  
42      /**
43       * @param perception perception
44       */
45      public ToledoPerception(final LanePerception perception)
46      {
47          super(perception);
48          this.infrastructureCategory = new DirectInfrastructurePerception(perception);
49      }
50  
51      /**
52       * Updates the infrastructural lane change info.
53       * @param lane relative lateral lane
54       */
55      public void updateInfrastructureLaneChangeInfo(final RelativeLane lane)
56      {
57          //
58      }
59  
60      /**
61       * Returns infrastructure lane change info of a lane. A set is returned as multiple points may force lane changes. Which
62       * point is considered most critical is a matter of driver interpretation and may change over time. This is shown below.
63       * Suppose vehicle A needs to take the off-ramp, and that behavior is that the minimum distance per required lane change
64       * determines how critical it is. First, 400m before the lane-drop, the off-ramp is critical. 300m downstream, the lane-drop
65       * is critical. Info is sorted by distance, closest first.
66       * 
67       * <pre>
68       * _______
69       * _ _A_ _\_________
70       * _ _ _ _ _ _ _ _ _
71       * _________ _ _ ___
72       *          \_______
73       *     (-)        Lane-drop: 1 lane change  in 400m (400m per lane change)
74       *     (--------) Off-ramp:  3 lane changes in 900m (300m per lane change, critical)
75       *     
76       *     (-)        Lane-drop: 1 lane change  in 100m (100m per lane change, critical)
77       *     (--------) Off-ramp:  3 lane changes in 600m (200m per lane change)
78       * </pre>
79       * @param lane relative lateral lane
80       * @return infrastructure lane change info of a lane
81       */
82      public final SortedSet<InfrastructureLaneChangeInfoToledo> getInfrastructureLaneChangeInfo(final RelativeLane lane)
83      {
84          return this.infrastructureLaneChangeInfo.get(lane).getObject();
85      }
86  
87      /**
88       * Returns time stamped infrastructure lane change info of a lane. A set is returned as multiple points may force lane
89       * changes. Which point is considered most critical is a matter of driver interpretation and may change over time. This is
90       * shown below. Suppose vehicle A needs to take the off-ramp, and that behavior is that the minimum distance per required
91       * lane change determines how critical it is. First, 400m before the lane-drop, the off-ramp is critical. 300m downstream,
92       * the lane-drop is critical. Info is sorted by distance, closest first.
93       * 
94       * <pre>
95       * _______
96       * _ _A_ _\_________
97       * _ _ _ _ _ _ _ _ _
98       * _________ _ _ ___
99       *          \_______
100      *     (-)        Lane-drop: 1 lane change  in 400m (400m per lane change)
101      *     (--------) Off-ramp:  3 lane changes in 900m (300m per lane change, critical)
102      *     
103      *     (-)        Lane-drop: 1 lane change  in 100m (100m per lane change, critical)
104      *     (--------) Off-ramp:  3 lane changes in 600m (200m per lane change)
105      * </pre>
106      * @param lane relative lateral lane
107      * @return time stamped infrastructure lane change info of a lane
108      */
109     public final TimeStampedObject<SortedSet<InfrastructureLaneChangeInfoToledo>>
110         getTimeStampedInfrastructureLaneChangeInfo(final RelativeLane lane)
111     {
112         return this.infrastructureLaneChangeInfo.get(lane);
113     }
114 
115     /**
116      * Updates the speed limit prospect.
117      * @param lane relative lateral lane
118      * @throws GTUException if the GTU was not initialized
119      * @throws ParameterException if a parameter is not defined
120      */
121     public final void updateSpeedLimitProspect(final RelativeLane lane) throws GTUException, ParameterException
122     {
123         this.infrastructureCategory.updateSpeedLimitProspect(lane);
124     }
125 
126     /**
127      * Updates the distance over which lane changes remains legally possible.
128      * @param fromLane lane from which the lane change possibility is requested
129      * @param lat LEFT or RIGHT, null not allowed
130      * @throws GTUException if the GTU was not initialized
131      * @throws ParameterException if a parameter is not defined
132      */
133     public final void updateLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
134         throws GTUException, ParameterException
135     {
136         this.infrastructureCategory.updateLegalLaneChangePossibility(fromLane, lat);
137     }
138 
139     /**
140      * Updates the distance over which lane changes remains physically possible.
141      * @param fromLane lane from which the lane change possibility is requested
142      * @param lat LEFT or RIGHT, null not allowed
143      * @throws GTUException if the GTU was not initialized
144      * @throws ParameterException if a parameter is not defined
145      */
146     public final void updatePhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
147         throws GTUException, ParameterException
148     {
149         this.infrastructureCategory.updatePhysicalLaneChangePossibility(fromLane, lat);
150     }
151 
152     /**
153      * Updates a set of relative lanes representing the cross section.
154      * @throws GTUException if the GTU was not initialized
155      * @throws ParameterException if a parameter is not defined
156      */
157     public final void updateCrossSection() throws GTUException, ParameterException
158     {
159         this.infrastructureCategory.updateCrossSection();
160     }
161 
162     /**
163      * Returns the prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
164      * @param lane relative lateral lane
165      * @return prospect for speed limits on a lane
166      */
167     public final SpeedLimitProspect getSpeedLimitProspect(final RelativeLane lane)
168     {
169         return this.infrastructureCategory.getSpeedLimitProspect(lane);
170     }
171 
172     /**
173      * Returns the distance over which a lane change remains legally possible.
174      * @param fromLane lane from which the lane change possibility is requested
175      * @param lat LEFT or RIGHT, null not allowed
176      * @return distance over which a lane change remains possible
177      * @throws NullPointerException if {@code lat == null}
178      */
179     public final Length getLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
180     {
181         return this.infrastructureCategory.getLegalLaneChangePossibility(fromLane, lat);
182     }
183 
184     /**
185      * Returns the distance over which a lane change remains physically possible.
186      * @param fromLane lane from which the lane change possibility is requested
187      * @param lat LEFT or RIGHT, null not allowed
188      * @return distance over which a lane change remains possible
189      * @throws NullPointerException if {@code lat == null}
190      */
191     public final Length getPhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
192     {
193         return this.infrastructureCategory.getPhysicalLaneChangePossibility(fromLane, lat);
194     }
195 
196     /**
197      * Returns a set of relative lanes representing the cross section. Lanes are sorted left to right.
198      * @return set of relative lanes representing the cross section
199      */
200     public final SortedSet<RelativeLane> getCrossSection()
201     {
202         return this.infrastructureCategory.getCrossSection();
203     }
204 
205     /**
206      * Returns the time stamped prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
207      * @param lane relative lateral lane
208      * @return time stamped prospect for speed limits on a lane
209      */
210     public final TimeStampedObject<SpeedLimitProspect> getTimeStampedSpeedLimitProspect(final RelativeLane lane)
211     {
212         return this.infrastructureCategory.getTimeStampedSpeedLimitProspect(lane);
213     }
214 
215     /**
216      * Returns the time stamped distance over which a lane change remains legally possible.
217      * @param fromLane lane from which the lane change possibility is requested
218      * @param lat LEFT or RIGHT, null not allowed
219      * @return time stamped distance over which a lane change remains possible
220      * @throws NullPointerException if {@code lat == null}
221      */
222     public final TimeStampedObject<Length> getTimeStampedLegalLaneChangePossibility(final RelativeLane fromLane,
223         final LateralDirectionality lat)
224     {
225         return this.infrastructureCategory.getTimeStampedLegalLaneChangePossibility(fromLane, lat);
226     }
227 
228     /**
229      * Returns the time stamped distance over which a lane change remains physically possible.
230      * @param fromLane lane from which the lane change possibility is requested
231      * @param lat LEFT or RIGHT, null not allowed
232      * @return time stamped distance over which a lane change remains possible
233      * @throws NullPointerException if {@code lat == null}
234      */
235     public final TimeStampedObject<Length> getTimeStampedPhysicalLaneChangePossibility(final RelativeLane fromLane,
236         final LateralDirectionality lat)
237     {
238         return this.infrastructureCategory.getTimeStampedPhysicalLaneChangePossibility(fromLane, lat);
239     }
240 
241     /**
242      * Returns a time stamped set of relative lanes representing the cross section. Lanes are sorted left to right.
243      * @return time stamped set of relative lanes representing the cross section
244      */
245     public final TimeStampedObject<SortedSet<RelativeLane>> getTimeStampedCrossSection()
246     {
247         return this.infrastructureCategory.getTimeStampedCrossSection();
248     }
249 
250     /** {@inheritDoc} */
251     @Override
252     public final void updateAll() throws GTUException, NetworkException, ParameterException
253     {
254         this.infrastructureCategory.updateAll();
255     }
256     
257     /** {@inheritDoc} */
258     @Override
259     public final String toString()
260     {
261         return "ToledoPerceptionCategory";
262     }
263 
264 }