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