ToledoPerception.java

  1. package org.opentrafficsim.road.gtu.lane.tactical.toledo;

  2. import java.util.Map;
  3. import java.util.SortedSet;
  4. import java.util.TreeSet;

  5. import org.djunits.value.vdouble.scalar.Length;
  6. import org.opentrafficsim.base.TimeStampedObject;
  7. import org.opentrafficsim.base.parameters.ParameterException;
  8. import org.opentrafficsim.core.gtu.GTUException;
  9. import org.opentrafficsim.core.network.LateralDirectionality;
  10. import org.opentrafficsim.core.network.NetworkException;
  11. import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
  12. import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
  13. import org.opentrafficsim.road.gtu.lane.perception.categories.DirectInfrastructurePerception;
  14. import org.opentrafficsim.road.gtu.lane.perception.categories.LaneBasedAbstractPerceptionCategory;
  15. import org.opentrafficsim.road.gtu.lane.perception.categories.LaneBasedPerceptionCategory;
  16. import org.opentrafficsim.road.network.speed.SpeedLimitProspect;

  17. /**
  18.  * Wrapper class around {@code InfrastructureCategory} that forwards all methods except for infrastructure lane change info.
  19.  * These methods determine and return infrastructure information of type {@code InfrastructureLaneChangeInfoToledo}, which
  20.  * includes split number.
  21.  * <p>
  22.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  23.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  24.  * <p>
  25.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Jul 28, 2016 <br>
  26.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  27.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  28.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  29.  */
  30. // TODO updateInfrastructureLaneChangeInfo with split number
  31. public class ToledoPerception extends LaneBasedAbstractPerceptionCategory implements LaneBasedPerceptionCategory
  32. {

  33.     /** */
  34.     private static final long serialVersionUID = 20160000L;

  35.     /** Infrastructure lane change info per relative lane. */
  36.     private Map<RelativeLane, TimeStampedObject<SortedSet<InfrastructureLaneChangeInfoToledo>>> infrastructureLaneChangeInfo;

  37.     /** Wrapped regular infrastructureCategory. */
  38.     private final DirectInfrastructurePerception infrastructureCategory;

  39.     /**
  40.      * @param perception LanePerception; perception
  41.      */
  42.     public ToledoPerception(final LanePerception perception)
  43.     {
  44.         super(perception);
  45.         this.infrastructureCategory = new DirectInfrastructurePerception(perception);
  46.     }

  47.     /**
  48.      * Updates the infrastructural lane change info.
  49.      * @param lane RelativeLane; relative lateral lane
  50.      * @throws GTUException when GTU is not initialized
  51.      */
  52.     public void updateInfrastructureLaneChangeInfo(final RelativeLane lane) throws GTUException
  53.     {
  54.         //
  55.     }

  56.     /**
  57.      * Returns infrastructure lane change info of a lane. A set is returned as multiple points may force lane changes. Which
  58.      * point is considered most critical is a matter of driver interpretation and may change over time. This is shown below.
  59.      * Suppose vehicle A needs to take the off-ramp, and that behavior is that the minimum distance per required lane change
  60.      * determines how critical it is. First, 400m before the lane-drop, the off-ramp is critical. 300m downstream, the lane-drop
  61.      * is critical. Info is sorted by distance, closest first.
  62.      *
  63.      * <pre>
  64.      * _______
  65.      * _ _A_ _\_________
  66.      * _ _ _ _ _ _ _ _ _
  67.      * _________ _ _ ___
  68.      *          \_______
  69.      *     (-)        Lane-drop: 1 lane change  in 400m (400m per lane change)
  70.      *     (--------) Off-ramp:  3 lane changes in 900m (300m per lane change, critical)
  71.      *    
  72.      *     (-)        Lane-drop: 1 lane change  in 100m (100m per lane change, critical)
  73.      *     (--------) Off-ramp:  3 lane changes in 600m (200m per lane change)
  74.      * </pre>
  75.      *
  76.      * @param lane RelativeLane; relative lateral lane
  77.      * @return infrastructure lane change info of a lane
  78.      */
  79.     public final SortedSet<InfrastructureLaneChangeInfoToledo> getInfrastructureLaneChangeInfo(final RelativeLane lane)
  80.     {
  81.         return new TreeSet<>();
  82.         // return this.infrastructureLaneChangeInfo.get(lane).getObject();
  83.     }

  84.     /**
  85.      * Returns time stamped infrastructure lane change info of a lane. A set is returned as multiple points may force lane
  86.      * changes. Which point is considered most critical is a matter of driver interpretation and may change over time. This is
  87.      * shown below. Suppose vehicle A needs to take the off-ramp, and that behavior is that the minimum distance per required
  88.      * lane change determines how critical it is. First, 400m before the lane-drop, the off-ramp is critical. 300m downstream,
  89.      * the lane-drop is critical. Info is sorted by distance, closest first.
  90.      *
  91.      * <pre>
  92.      * _______
  93.      * _ _A_ _\_________
  94.      * _ _ _ _ _ _ _ _ _
  95.      * _________ _ _ ___
  96.      *          \_______
  97.      *     (-)        Lane-drop: 1 lane change  in 400m (400m per lane change)
  98.      *     (--------) Off-ramp:  3 lane changes in 900m (300m per lane change, critical)
  99.      *    
  100.      *     (-)        Lane-drop: 1 lane change  in 100m (100m per lane change, critical)
  101.      *     (--------) Off-ramp:  3 lane changes in 600m (200m per lane change)
  102.      * </pre>
  103.      *
  104.      * @param lane RelativeLane; relative lateral lane
  105.      * @return time stamped infrastructure lane change info of a lane
  106.      */
  107.     public final TimeStampedObject<SortedSet<InfrastructureLaneChangeInfoToledo>> getTimeStampedInfrastructureLaneChangeInfo(
  108.             final RelativeLane lane)
  109.     {
  110.         return this.infrastructureLaneChangeInfo.get(lane);
  111.     }

  112.     /**
  113.      * Updates the speed limit prospect.
  114.      * @param lane RelativeLane; relative lateral lane
  115.      * @throws GTUException if the GTU was not initialized
  116.      * @throws ParameterException if a parameter is not defined
  117.      */
  118.     public final void updateSpeedLimitProspect(final RelativeLane lane) throws GTUException, ParameterException
  119.     {
  120.         this.infrastructureCategory.updateSpeedLimitProspect(lane);
  121.     }

  122.     /**
  123.      * Updates the distance over which lane changes remains legally possible.
  124.      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
  125.      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
  126.      * @throws GTUException if the GTU was not initialized
  127.      * @throws ParameterException if a parameter is not defined
  128.      */
  129.     public final void updateLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
  130.             throws GTUException, ParameterException
  131.     {
  132.         this.infrastructureCategory.updateLegalLaneChangePossibility(fromLane, lat);
  133.     }

  134.     /**
  135.      * Updates the distance over which lane changes remains physically possible.
  136.      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
  137.      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
  138.      * @throws GTUException if the GTU was not initialized
  139.      * @throws ParameterException if a parameter is not defined
  140.      */
  141.     public final void updatePhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
  142.             throws GTUException, ParameterException
  143.     {
  144.         this.infrastructureCategory.updatePhysicalLaneChangePossibility(fromLane, lat);
  145.     }

  146.     /**
  147.      * Updates a set of relative lanes representing the cross section.
  148.      * @throws GTUException if the GTU was not initialized
  149.      * @throws ParameterException if a parameter is not defined
  150.      */
  151.     public final void updateCrossSection() throws GTUException, ParameterException
  152.     {
  153.         this.infrastructureCategory.updateCrossSection();
  154.     }

  155.     /**
  156.      * Returns the prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
  157.      * @param lane RelativeLane; relative lateral lane
  158.      * @return prospect for speed limits on a lane
  159.      */
  160.     public final SpeedLimitProspect getSpeedLimitProspect(final RelativeLane lane)
  161.     {
  162.         return this.infrastructureCategory.getSpeedLimitProspect(lane);
  163.     }

  164.     /**
  165.      * Returns the distance over which a lane change remains legally possible.
  166.      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
  167.      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
  168.      * @return distance over which a lane change remains possible
  169.      * @throws NullPointerException if {@code lat == null}
  170.      */
  171.     public final Length getLegalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
  172.     {
  173.         return this.infrastructureCategory.getLegalLaneChangePossibility(fromLane, lat);
  174.     }

  175.     /**
  176.      * Returns the distance over which a lane change remains physically possible.
  177.      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
  178.      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
  179.      * @return distance over which a lane change remains possible
  180.      * @throws NullPointerException if {@code lat == null}
  181.      */
  182.     public final Length getPhysicalLaneChangePossibility(final RelativeLane fromLane, final LateralDirectionality lat)
  183.     {
  184.         return this.infrastructureCategory.getPhysicalLaneChangePossibility(fromLane, lat);
  185.     }

  186.     /**
  187.      * Returns a set of relative lanes representing the cross section. Lanes are sorted left to right.
  188.      * @return set of relative lanes representing the cross section
  189.      */
  190.     public final SortedSet<RelativeLane> getCrossSection()
  191.     {
  192.         return this.infrastructureCategory.getCrossSection();
  193.     }

  194.     /**
  195.      * Returns the time stamped prospect for speed limits on a lane (dynamic speed limits may vary between lanes).
  196.      * @param lane RelativeLane; relative lateral lane
  197.      * @return time stamped prospect for speed limits on a lane
  198.      */
  199.     public final TimeStampedObject<SpeedLimitProspect> getTimeStampedSpeedLimitProspect(final RelativeLane lane)
  200.     {
  201.         return this.infrastructureCategory.getTimeStampedSpeedLimitProspect(lane);
  202.     }

  203.     /**
  204.      * Returns the time stamped distance over which a lane change remains legally possible.
  205.      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
  206.      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
  207.      * @return time stamped distance over which a lane change remains possible
  208.      * @throws NullPointerException if {@code lat == null}
  209.      */
  210.     public final TimeStampedObject<Length> getTimeStampedLegalLaneChangePossibility(final RelativeLane fromLane,
  211.             final LateralDirectionality lat)
  212.     {
  213.         return this.infrastructureCategory.getTimeStampedLegalLaneChangePossibility(fromLane, lat);
  214.     }

  215.     /**
  216.      * Returns the time stamped distance over which a lane change remains physically possible.
  217.      * @param fromLane RelativeLane; lane from which the lane change possibility is requested
  218.      * @param lat LateralDirectionality; LEFT or RIGHT, null not allowed
  219.      * @return time stamped distance over which a lane change remains possible
  220.      * @throws NullPointerException if {@code lat == null}
  221.      */
  222.     public final TimeStampedObject<Length> getTimeStampedPhysicalLaneChangePossibility(final RelativeLane fromLane,
  223.             final LateralDirectionality lat)
  224.     {
  225.         return this.infrastructureCategory.getTimeStampedPhysicalLaneChangePossibility(fromLane, lat);
  226.     }

  227.     /**
  228.      * Returns a time stamped set of relative lanes representing the cross section. Lanes are sorted left to right.
  229.      * @return time stamped set of relative lanes representing the cross section
  230.      */
  231.     public final TimeStampedObject<SortedSet<RelativeLane>> getTimeStampedCrossSection()
  232.     {
  233.         return this.infrastructureCategory.getTimeStampedCrossSection();
  234.     }

  235.     /** {@inheritDoc} */
  236.     @Override
  237.     public final void updateAll() throws GTUException, NetworkException, ParameterException
  238.     {
  239.         this.infrastructureCategory.updateAll();
  240.     }

  241.     /** {@inheritDoc} */
  242.     @Override
  243.     public final String toString()
  244.     {
  245.         return "ToledoPerceptionCategory";
  246.     }

  247. }