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