View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.util.LinkedHashMap;
4   import java.util.Set;
5   
6   import org.djunits.value.vdouble.scalar.Speed;
7   import org.opentrafficsim.core.gtu.GtuType;
8   import org.opentrafficsim.core.network.LateralDirectionality;
9   import org.opentrafficsim.core.network.NetworkException;
10  import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
11  
12  /**
13   * This class is mostly the same as a Lane. But as a shoulder it can be recognized by algorithms and models to be responded to
14   * differently.
15   * <p>
16   * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * </p>
19   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
20   */
21  public class Shoulder extends Lane
22  {
23  
24      /** */
25      private static final long serialVersionUID = 20240507L;
26  
27      /**
28       * Constructor specifying geometry.
29       * @param link link
30       * @param id the id of this lane within the link; should be unique within the link
31       * @param geometry geometry
32       * @param laneType lane type
33       * @throws NetworkException when no cross-section slice is defined
34       */
35      public Shoulder(final CrossSectionLink link, final String id, final CrossSectionGeometry geometry, final LaneType laneType)
36              throws NetworkException
37      {
38          super(link, id, geometry, laneType, new LinkedHashMap<>());
39      }
40  
41      /**
42       * Returns one adjacent lane.
43       * @param laneChangeDirection lane change direction
44       * @param gtuType GTU type.
45       * @return adjacent lane, {@code null} if none
46       */
47      @Override
48      public Lane getAdjacentLane(final LateralDirectionality laneChangeDirection, final GtuType gtuType)
49      {
50          Set<Lane> adjLanes = accessibleAdjacentLanesPhysical(laneChangeDirection, gtuType);
51          if (!adjLanes.isEmpty())
52          {
53              return adjLanes.iterator().next();
54          }
55          return null;
56      }
57  
58      @Override
59      public double getZ()
60      {
61          return -0.00005;
62      }
63  
64      @Override
65      public Speed getSpeedLimit(final GtuType gtuType) throws NetworkException
66      {
67          LateralDirectionality[] lats = getLink().getLaneKeepingPolicy().equals(LaneKeepingPolicy.KEEPRIGHT)
68                  ? new LateralDirectionality[] {LateralDirectionality.RIGHT, LateralDirectionality.LEFT}
69                  : new LateralDirectionality[] {LateralDirectionality.LEFT, LateralDirectionality.RIGHT};
70          for (LateralDirectionality lat : lats)
71          {
72              Lane adjacentLane = getAdjacentLane(lat, gtuType);
73              if (adjacentLane != null)
74              {
75                  return adjacentLane.getSpeedLimit(gtuType);
76              }
77          }
78          return Speed.ZERO;
79      }
80  }