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