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