View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.headway;
2   
3   import java.util.SortedSet;
4   import java.util.TreeSet;
5   
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.djunits.value.vdouble.scalar.Speed;
8   import org.opentrafficsim.core.gtu.GTUException;
9   import org.opentrafficsim.road.network.lane.CrossSectionLink;
10  import org.opentrafficsim.road.network.lane.conflict.ConflictPriority;
11  import org.opentrafficsim.road.network.lane.conflict.ConflictRule;
12  import org.opentrafficsim.road.network.lane.conflict.ConflictType;
13  
14  import nl.tudelft.simulation.language.Throw;
15  
16  /**
17   * <p>
18   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
20   * <p>
21   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Jun 2, 2016 <br>
22   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
23   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
24   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
25   */
26  public class HeadwayConflict extends AbstractHeadwayCopy
27  {
28  
29      /** */
30      private static final long serialVersionUID = 20160602L;
31  
32      /** Conflict type. */
33      private final ConflictType conflictType;
34  
35      /** Conflict priority. */
36      private final ConflictPriority conflictPriority;
37  
38      /** Length of the conflict in the conflicting directions. */
39      private final Length conflictingLength;
40  
41      /**
42       * Set of conflicting GTU's <i>completely</i> upstream of the <i>start</i> of the conflict ordered close to far from the
43       * start of the conflict. Distance and overlap info concerns the conflict.
44       */
45      private final SortedSet<HeadwayGTU> upstreamConflictingGTUs;
46  
47      /**
48       * Set of conflicting GTU's (partially) downstream of the <i>start</i> of the conflict ordered close to far from the start
49       * of conflict. Distance and overlap info concerns the conflict.
50       */
51      private final SortedSet<HeadwayGTU> downstreamConflictingGTUs;
52  
53      /** Visibility on the conflicting lane within which conflicting vehicles are visible. */
54      private final Length conflictingVisibility;
55  
56      /** Speed limit on the conflicting lane. */
57      private final Speed conflictingSpeedLimit;
58  
59      /** Link of conflicting conflict. */
60      private final CrossSectionLink conflictingLink;
61  
62      /** Stop line on the own lane. */
63      private final HeadwayStopLine stopLine;
64  
65      /** Stop line on the conflicting lane. */
66      private final HeadwayStopLine conflictingStopLine;
67  
68      /** Type of conflict rule. */
69      private final Class<? extends ConflictRule> conflictRuleType;
70  
71      /** Distance of traffic light upstream on conflicting lane. */
72      private Length conflictingTrafficLightDistance = null;
73  
74      /** Whether the conflict is permitted by the traffic light. */
75      private boolean permitted = false;
76  
77      /**
78       * Constructor.
79       * @param conflictType conflict type
80       * @param conflictPriority conflict priority
81       * @param conflictRuleType conflict rule type
82       * @param id id
83       * @param distance distance
84       * @param length length of the conflict
85       * @param conflictingLength length of the conflict on the conflicting lane
86       * @param upstreamConflictingGTUs conflicting GTU's upstream of the <i>start</i> of the conflict
87       * @param downstreamConflictingGTUs conflicting GTU's downstream of the <i>start</i> of the conflict
88       * @param conflictingVisibility visibility on the conflicting lane within which conflicting vehicles are visible
89       * @param conflictingSpeedLimit speed limit on the conflicting lane
90       * @param conflictingLink conflicting link
91       * @param stopLine stop line on the own lane
92       * @param conflictingStopLine stop line on the conflicting lane
93       * @throws GTUException when id is null, or parameters are inconsistent
94       */
95      @SuppressWarnings("checkstyle:parameternumber")
96      public HeadwayConflict(final ConflictType conflictType, final ConflictPriority conflictPriority,
97              final Class<? extends ConflictRule> conflictRuleType, final String id, final Length distance, final Length length,
98              final Length conflictingLength, final SortedSet<HeadwayGTU> upstreamConflictingGTUs,
99              final SortedSet<HeadwayGTU> downstreamConflictingGTUs, final Length conflictingVisibility,
100             final Speed conflictingSpeedLimit, final CrossSectionLink conflictingLink, final HeadwayStopLine stopLine,
101             final HeadwayStopLine conflictingStopLine) throws GTUException
102     {
103         super(ObjectType.CONFLICT, id, distance, length);
104         Throw.whenNull(conflictType, "Conflict type may not be null.");
105         Throw.whenNull(conflictPriority, "Conflict priority may not be null.");
106         Throw.whenNull(conflictRuleType, "Conflict rule type may not be null.");
107         Throw.whenNull(id, "Conflict id may not be null.");
108         Throw.whenNull(distance, "Conflict distance may not be null.");
109         Throw.whenNull(conflictingLength, "Conflict length may not be null.");
110         Throw.whenNull(upstreamConflictingGTUs, "Upstreaem conflicting GTU's may not be null.");
111         Throw.whenNull(downstreamConflictingGTUs, "Downstream conflicting GTU's may not be null.");
112         Throw.whenNull(conflictingVisibility, "Conflict visibility may not be null.");
113         Throw.whenNull(conflictingSpeedLimit, "Conflict speed limit may not be null.");
114         this.conflictType = conflictType;
115         this.conflictPriority = conflictPriority;
116         this.conflictRuleType = conflictRuleType;
117         this.conflictingLength = conflictingLength;
118         this.upstreamConflictingGTUs = upstreamConflictingGTUs;
119         this.downstreamConflictingGTUs = downstreamConflictingGTUs;
120         this.conflictingVisibility = conflictingVisibility;
121         this.conflictingSpeedLimit = conflictingSpeedLimit;
122         this.conflictingLink = conflictingLink;
123         this.stopLine = stopLine;
124         this.conflictingStopLine = conflictingStopLine;
125     }
126 
127     /**
128      * Constructor without stop lines.
129      * @param conflictType conflict type
130      * @param conflictPriority conflict priority
131      * @param conflictRuleType conflict rule type
132      * @param id id
133      * @param distance distance
134      * @param length length of the conflict
135      * @param conflictingLength length of the conflict on the conflicting lane
136      * @param upstreamConflictingGTUs conflicting GTU's upstream of the <i>start</i> of the conflict
137      * @param downstreamConflictingGTUs conflicting GTU's downstream of the <i>start</i> of the conflict
138      * @param conflictingVisibility visibility on the conflicting lane within which conflicting vehicles are visible
139      * @param conflictingSpeedLimit speed limit on the conflicting lane
140      * @param conflictingLink conflicting link
141      * @throws GTUException when id is null, or parameters are inconsistent
142      */
143     @SuppressWarnings("checkstyle:parameternumber")
144     public HeadwayConflict(final ConflictType conflictType, final ConflictPriority conflictPriority,
145             final Class<? extends ConflictRule> conflictRuleType, final String id, final Length distance, final Length length,
146             final Length conflictingLength, final SortedSet<HeadwayGTU> upstreamConflictingGTUs,
147             final SortedSet<HeadwayGTU> downstreamConflictingGTUs, final Length conflictingVisibility,
148             final Speed conflictingSpeedLimit, final CrossSectionLink conflictingLink) throws GTUException
149     {
150         this(conflictType, conflictPriority, conflictRuleType, id, distance, length, conflictingLength, upstreamConflictingGTUs,
151                 downstreamConflictingGTUs, conflictingVisibility, conflictingSpeedLimit, conflictingLink, null, null);
152     }
153 
154     /**
155      * Returns the conflict type.
156      * @return conflict type
157      */
158     public final ConflictType getConflictType()
159     {
160         return this.conflictType;
161     }
162 
163     /**
164      * Returns whether this is a crossing conflict.
165      * @return whether this is a crossing conflict
166      */
167     public final boolean isCrossing()
168     {
169         return this.conflictType.equals(ConflictType.CROSSING);
170     }
171 
172     /**
173      * Returns whether this is a merge conflict.
174      * @return whether this is a merge conflict
175      */
176     public final boolean isMerge()
177     {
178         return this.conflictType.equals(ConflictType.MERGE);
179     }
180 
181     /**
182      * Returns whether this is a split conflict.
183      * @return whether this is a split conflict
184      */
185     public final boolean isSplit()
186     {
187         return this.conflictType.equals(ConflictType.SPLIT);
188     }
189 
190     /**
191      * Returns the conflict priority.
192      * @return conflict priority
193      */
194     public final ConflictPriority getConflictPriority()
195     {
196         return this.conflictPriority;
197     }
198 
199     /**
200      * Returns the length of the conflict on the conflicting lane.
201      * @return length of the conflict on the conflicting lane
202      */
203     public final Length getConflictingLength()
204     {
205         return this.conflictingLength;
206     }
207 
208     /**
209      * Returns a set of conflicting GTU's upstream of the <i>start</i> of the conflict ordered close to far from the conflict.
210      * @return set of conflicting GTU's upstream of the <i>start</i> of the conflict ordered close to far from the conflict
211      */
212     public final SortedSet<HeadwayGTU> getUpstreamConflictingGTUs()
213     {
214         return new TreeSet<>(this.upstreamConflictingGTUs);
215     }
216 
217     /**
218      * Returns a set of conflicting GTU's downstream of the <i>start</i> of the conflict ordered close to far from the conflict.
219      * Distance is given relative to the <i>end</i> of the conflict, or null for conflicting vehicles on the conflict. In the
220      * latter case the overlap is used.
221      * @return set of conflicting GTU's downstream of the <i>start</i> of the conflict ordered close to far from the conflict
222      */
223     public final SortedSet<HeadwayGTU> getDownstreamConflictingGTUs()
224     {
225         return new TreeSet<>(this.downstreamConflictingGTUs);
226     }
227 
228     /**
229      * Returns the visibility on the conflicting lane within which conflicting vehicles are visible. All upstream conflicting
230      * GTUs have a distance smaller than the visibility. Depending on a limited visibility, a certain (lower) speed may be
231      * required while approaching the conflict.
232      * @return visibility on the conflicting lane within which conflicting vehicles are visible
233      */
234     public final Length getConflictingVisibility()
235     {
236         return this.conflictingVisibility;
237     }
238 
239     /**
240      * Returns the speed limit on the conflicting lane.
241      * @return speed limit on the conflicting lane
242      */
243     public final Speed getConflictingSpeedLimit()
244     {
245         return this.conflictingSpeedLimit;
246     }
247 
248     /**
249      * Returns the conflicting link.
250      * @return the conflicting link
251      */
252     public final CrossSectionLink getConflictingLink()
253     {
254         return this.conflictingLink;
255     }
256 
257     /**
258      * Returns the stop line.
259      * @return stop line
260      */
261     public final HeadwayStopLine getStopLine()
262     {
263         return this.stopLine;
264     }
265 
266     /**
267      * Returns the stop line on the conflicting lane.
268      * @return stop line
269      */
270     public final HeadwayStopLine getConflictingStopLine()
271     {
272         return this.conflictingStopLine;
273     }
274 
275     /**
276      * Returns the conflict rule type.
277      * @return conflict rule type
278      */
279     public Class<? extends ConflictRule> getConflictRuleType()
280     {
281         return this.conflictRuleType;
282     }
283 
284     /**
285      * Returns the distance of a traffic light upstream on the conflicting lane.
286      * @return distance of a traffic light upstream on the conflicting lane.
287      */
288     public Length getConflictingTrafficLightDistance()
289     {
290         return this.conflictingTrafficLightDistance;
291     }
292 
293     /**
294      * Whether the conflict is permitted by the traffic light.
295      * @return whether the conflict is permitted by the traffic light
296      */
297     public boolean isPermitted()
298     {
299         return this.permitted;
300     }
301 
302     /**
303      * Set the distance of a traffic light upstream on the conflicting lane.
304      * @param trafficLightDistance distance of a traffic light upstream on the conflicting lane.
305      * @param permittedConflict whether the conflict is permitted by the traffic light
306      */
307     public void setConflictingTrafficLight(final Length trafficLightDistance, final boolean permittedConflict)
308     {
309         this.conflictingTrafficLightDistance = trafficLightDistance;
310         this.permitted = permittedConflict;
311     }
312 
313     /** {@inheritDoc} */
314     public final String toString()
315     {
316         return String.format("Headway %s to object %s of type %s", getDistance(), getId(), getObjectType());
317     }
318 
319 }