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