View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.io.Serializable;
4   import java.util.ArrayList;
5   import java.util.HashMap;
6   import java.util.List;
7   import java.util.Map;
8   
9   import org.opentrafficsim.core.geometry.OTSLine3D;
10  import org.opentrafficsim.core.gtu.GTUType;
11  import org.opentrafficsim.core.network.LinkType;
12  import org.opentrafficsim.core.network.LongitudinalDirectionality;
13  import org.opentrafficsim.core.network.OTSLink;
14  import org.opentrafficsim.core.network.OTSNode;
15  import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
16  
17  /**
18   * A CrossSectionLink is a link with lanes where GTUs can possibly switch between lanes.
19   * <p>
20   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22   * <p>
23   * $LastChangedDate: 2015-09-16 19:20:07 +0200 (Wed, 16 Sep 2015) $, @version $Revision: 1405 $, by $Author: averbraeck $,
24   * initial version Aug 19, 2014 <br>
25   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
27   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
28   */
29  public class CrossSectionLink extends OTSLink implements Serializable
30  {
31      /** */
32      private static final long serialVersionUID = 20141015L;
33  
34      /** list of cross-section elements. */
35      private final List<CrossSectionElement> crossSectionElementList = new ArrayList<>();
36  
37      /** the policy to generally keep left, keep right, or keep lane. */
38      private final LaneKeepingPolicy laneKeepingPolicy;
39  
40      /**
41       * Construction of a cross section link.
42       * @param id the link id.
43       * @param startNode start node (directional).
44       * @param endNode end node (directional).
45       * @param linkType the linktype
46       * @param designLine the OTSLine3D design line of the Link
47       * @param directionalityMap the directions (FORWARD, BACKWARD, BOTH, NONE) that GTUtypes can traverse this link
48       * @param laneKeepingPolicy the policy to generally keep left, keep right, or keep lane
49       */
50      public CrossSectionLink(final String id, final OTSNode startNode, final OTSNode endNode, final LinkType linkType,
51          final OTSLine3D designLine, final Map<GTUType, LongitudinalDirectionality> directionalityMap,
52          final LaneKeepingPolicy laneKeepingPolicy)
53      {
54          super(id, startNode, endNode, linkType, designLine, directionalityMap);
55          this.laneKeepingPolicy = laneKeepingPolicy;
56      }
57  
58      /**
59       * Construction of a link, with a general directionality for GTUType.ALL. Other directionalities can be added with the
60       * method addDirectionality(...) later.
61       * @param id the link id.
62       * @param startNode start node (directional).
63       * @param endNode end node (directional).
64       * @param linkType the linktype
65       * @param designLine the OTSLine3D design line of the Link
66       * @param directionality the default directionality for all GTUs
67       * @param laneKeepingPolicy the policy to generally keep left, keep right, or keep lane
68       */
69      public CrossSectionLink(final String id, final OTSNode startNode, final OTSNode endNode, final LinkType linkType,
70          final OTSLine3D designLine, final LongitudinalDirectionality directionality,
71          final LaneKeepingPolicy laneKeepingPolicy)
72      {
73          super(id, startNode, endNode, linkType, designLine, directionality);
74          this.laneKeepingPolicy = laneKeepingPolicy;
75      }
76  
77      /**
78       * Construction of a link, on which no traffic is allowed after construction of the link. Directionality for GTUTypes can be
79       * added with the method addDirectionality(...) later.
80       * @param id the link id.
81       * @param startNode start node (directional).
82       * @param endNode end node (directional).
83       * @param linkType the linktype
84       * @param designLine the OTSLine3D design line of the Link
85       * @param laneKeepingPolicy the policy to generally keep left, keep right, or keep lane
86       */
87      public CrossSectionLink(final String id, final OTSNode startNode, final OTSNode endNode, final LinkType linkType,
88          final OTSLine3D designLine, final LaneKeepingPolicy laneKeepingPolicy)
89      {
90          this(id, startNode, endNode, linkType, designLine, new HashMap<GTUType, LongitudinalDirectionality>(),
91              laneKeepingPolicy);
92      }
93  
94      /**
95       * Add a cross section element at the end of the list. <br>
96       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction.
97       * @param cse the cross section element to add.
98       */
99      protected final void addCrossSectionElement(final CrossSectionElement cse)
100     {
101         this.crossSectionElementList.add(cse);
102     }
103 
104     /**
105      * Add a cross section element at specified index in the list.<br>
106      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction.
107      * @param index the location to insert the element.
108      * @param cse the cross section element to add.
109      */
110     protected final void addCrossSectionElement(final CrossSectionElement cse, final int index)
111     {
112         this.crossSectionElementList.add(index, cse);
113     }
114 
115     /**
116      * @return crossSectionElementList.
117      */
118     public final List<CrossSectionElement> getCrossSectionElementList()
119     {
120         return this.crossSectionElementList;
121     }
122 
123     /**
124      * @return laneKeepingPolicy
125      */
126     public final LaneKeepingPolicy getLaneKeepingPolicy()
127     {
128         return this.laneKeepingPolicy;
129     }
130     
131     /**
132      * @param id the cse.id to search for
133      * @return the cross section element with the given id, or null if not found
134      */
135     public final CrossSectionElement getCrossSectionElement(final String id)
136     {
137         for (CrossSectionElement cse : this.crossSectionElementList)
138         {
139             if (cse.getId().equals(id))
140             {
141                 return cse;
142             }
143         }
144         return null;
145     }
146 }