Shoulder.java

  1. package org.opentrafficsim.road.network.lane;

  2. import java.util.LinkedHashMap;
  3. import java.util.Set;

  4. import org.djunits.value.vdouble.scalar.Speed;
  5. import org.opentrafficsim.core.gtu.GtuType;
  6. import org.opentrafficsim.core.network.LateralDirectionality;
  7. import org.opentrafficsim.core.network.NetworkException;
  8. import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;

  9. /**
  10.  * 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
  11.  * differently.
  12.  * <p>
  13.  * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  14.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  15.  * </p>
  16.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  17.  */
  18. public class Shoulder extends Lane
  19. {

  20.     /** */
  21.     private static final long serialVersionUID = 20240507L;

  22.     /**
  23.      * Constructor specifying geometry.
  24.      * @param link link
  25.      * @param id the id of this lane within the link; should be unique within the link
  26.      * @param geometry geometry
  27.      * @param laneType lane type
  28.      * @throws NetworkException when no cross-section slice is defined
  29.      */
  30.     public Shoulder(final CrossSectionLink link, final String id, final CrossSectionGeometry geometry, final LaneType laneType)
  31.             throws NetworkException
  32.     {
  33.         super(link, id, geometry, laneType, new LinkedHashMap<>());
  34.     }

  35.     /**
  36.      * Returns one adjacent lane.
  37.      * @param laneChangeDirection lane change direction
  38.      * @param gtuType GTU type.
  39.      * @return adjacent lane, {@code null} if none
  40.      */
  41.     @Override
  42.     public Lane getAdjacentLane(final LateralDirectionality laneChangeDirection, final GtuType gtuType)
  43.     {
  44.         Set<Lane> adjLanes = accessibleAdjacentLanesPhysical(laneChangeDirection, gtuType);
  45.         if (!adjLanes.isEmpty())
  46.         {
  47.             return adjLanes.iterator().next();
  48.         }
  49.         return null;
  50.     }

  51.     @Override
  52.     public double getZ()
  53.     {
  54.         return -0.00005;
  55.     }

  56.     @Override
  57.     public Speed getSpeedLimit(final GtuType gtuType) throws NetworkException
  58.     {
  59.         LateralDirectionality[] lats = getLink().getLaneKeepingPolicy().equals(LaneKeepingPolicy.KEEPRIGHT)
  60.                 ? new LateralDirectionality[] {LateralDirectionality.RIGHT, LateralDirectionality.LEFT}
  61.                 : new LateralDirectionality[] {LateralDirectionality.LEFT, LateralDirectionality.RIGHT};
  62.         for (LateralDirectionality lat : lats)
  63.         {
  64.             Lane adjacentLane = getAdjacentLane(lat, gtuType);
  65.             if (adjacentLane != null)
  66.             {
  67.                 return adjacentLane.getSpeedLimit(gtuType);
  68.             }
  69.         }
  70.         return Speed.ZERO;
  71.     }
  72. }