Headway.java

  1. package org.opentrafficsim.road.gtu.lane.perception.headway;

  2. import org.djunits.value.vdouble.scalar.Acceleration;
  3. import org.djunits.value.vdouble.scalar.Length;
  4. import org.djunits.value.vdouble.scalar.Speed;
  5. import org.opentrafficsim.core.perception.PerceivedObject;

  6. /**
  7.  * Interface for a reference to information about a (lane based) GTU and a headway. The Headway can store information about GTUs
  8.  * or objects ahead of the reference GTU, behind the reference GTU, or (partially) parallel to the reference GTU. In addition to
  9.  * the (perceived) headway, several other pieces of information can be stored, such as (perceived) speed, (perceived)
  10.  * acceleration, (perceived) turn indicators, and (perceived) braking lights. <br>
  11.  * Special care must be taken in curves when perceiving headway of a GTU or object on an adjacent lane.The question is whether
  12.  * we perceive the parallel or ahead/behind based on a line perpendicular to the front/back of the GTU (rectangular), or
  13.  * perpendicular to the center line of the lane (wedge-shaped in case of a curve). The difficulty of a wedge-shaped situation is
  14.  * that reciprocity might be violated: in case of a clothoid, for instance, it is not sure that the point on the center line
  15.  * when projected from lane 1 to lane 2 is the same as the projection from lane 2 to lane 1. The same holds for shapes with
  16.  * sharp bends. Therefore, algorithms implementing headway should only project the <i>reference point</i> of the reference GTU
  17.  * on the center line of the adjacent lane, and then calculate the forward position and backward position on the adjacent lane
  18.  * based on the reference point. Still, our human perception of what is parallel and what not, is not reflected by fractional
  19.  * positions. See examples in
  20.  * <a href= "http://simulation.tudelft.nl:8085/browse/OTS-113">http://simulation.tudelft.nl:8085/browse/OTS-113</a>.
  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/license.html">OpenTrafficSim License</a>.
  24.  * <p>
  25.  * @version $Revision: 1368 $, $LastChangedDate: 2015-09-02 00:20:20 +0200 (Wed, 02 Sep 2015) $, by $Author: averbraeck $,
  26.  *          initial version 11 feb. 2015 <br>
  27.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  28.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  29.  */
  30. public interface Headway extends PerceivedObject, Comparable<Headway>
  31. {
  32.     /** the object types that can be distinguished for headway. */
  33.     enum ObjectType
  34.     {
  35.         /** the observed object for headway is a GTU. */
  36.         GTU,

  37.         /** the observed object for headway is a traffic light. */
  38.         TRAFFICLIGHT,

  39.         /** the observed object for headway is a generic object. */
  40.         OBJECT,

  41.         /** there is no observed object, just a distance. */
  42.         DISTANCEONLY,

  43.         /** intersection conflict. */
  44.         CONFLICT,

  45.         /** stop line. */
  46.         STOPLINE,

  47.         /** bus stop. */
  48.         BUSSTOP;

  49.         /** @return whether this object is a GTU or not. */
  50.         public boolean isGtu()
  51.         {
  52.             return this.equals(GTU);
  53.         }

  54.         /** @return whether this object is a GTU or not. */
  55.         public boolean isTrafficLight()
  56.         {
  57.             return this.equals(TRAFFICLIGHT);
  58.         }

  59.         /** @return whether this object is an object or not. */
  60.         public boolean isObject()
  61.         {
  62.             return this.equals(OBJECT);
  63.         }

  64.         /** @return whether no object was observed and only a distance was stored. */
  65.         public boolean isDistanceOnly()
  66.         {
  67.             return this.equals(DISTANCEONLY);
  68.         }

  69.         /** @return whether this object is a conflict or not. */
  70.         public boolean isConflict()
  71.         {
  72.             return this.equals(CONFLICT);
  73.         }

  74.         /** @return whether this object is a stop line or not. */
  75.         public boolean isStopLine()
  76.         {
  77.             return this.equals(STOPLINE);
  78.         }

  79.         /** @return whether this object is a bus stop or not. */
  80.         public boolean isBusStop()
  81.         {
  82.             return this.equals(BUSSTOP);
  83.         }

  84.     }

  85.     /**
  86.      * @return String; the id of the other object for comparison purposes, cannot be null.
  87.      */
  88.     @Override
  89.     String getId();

  90.     /**
  91.      * @return Length; the length of the other object; can be null if unknown.
  92.      */
  93.     Length getLength();

  94.     /**
  95.      * @return Speed; the (perceived) speed of the other object; can be null if unknown.
  96.      */
  97.     Speed getSpeed();

  98.     /**
  99.      * Retrieve the strongly typed distance to the other object.
  100.      * @return Length; the distance to the object, return value null indicates that the other object is parallel to the
  101.      *         reference object
  102.      */
  103.     Length getDistance();

  104.     /**
  105.      * @return Length; the (perceived) object Type, can be null if no object type unknown.
  106.      */
  107.     ObjectType getObjectType();

  108.     /**
  109.      * @return Acceleration; acceleration the (perceived) acceleration of the other object; can be null if unknown.
  110.      */
  111.     Acceleration getAcceleration();

  112.     /**
  113.      * Return the (perceived) front overlap to the other object. This value should be null if there is no overlap. In the figure
  114.      * for two GTUs below, it is distance c, positive for GTU1, negative for GTU2.
  115.      *
  116.      * <pre>
  117.      * ----------
  118.      * |  GTU 1 |          -----&gt;
  119.      * ----------
  120.      *      ---------------
  121.      *      |    GTU 2    |          -----&gt;
  122.      *      ---------------
  123.      * | a  | b |     c   |
  124.      * </pre>
  125.      *
  126.      * @return Length; the (perceived) front overlap to the other object or null if there is no overlap.
  127.      */
  128.     Length getOverlapFront();

  129.     /**
  130.      * Return the (perceived) rear overlap to the other object. This value should be null if there is no overlap.In the figure
  131.      * below for two GTUs, it is distance a, positive for GTU1, negative for GTU2.
  132.      *
  133.      * <pre>
  134.      * ----------
  135.      * |  GTU 1 |          -----&gt;
  136.      * ----------
  137.      *      ---------------
  138.      *      |    GTU 2    |          -----&gt;
  139.      *      ---------------
  140.      * | a  | b |     c   |
  141.      * </pre>
  142.      *
  143.      * @return Length; the (perceived) rear overlap to the other object or null if there is no overlap.
  144.      */
  145.     Length getOverlapRear();

  146.     /**
  147.      * Return the (perceived) overlap with the other object. This value should be null if there is no overlap. In the figure
  148.      * below for two GTUs, it is distance b, positive for GTU1 and GTU2.
  149.      *
  150.      * <pre>
  151.      * ----------
  152.      * |  GTU 1 |          -----&gt;
  153.      * ----------
  154.      *      ---------------
  155.      *      |    GTU 2    |          -----&gt;
  156.      *      ---------------
  157.      * | a  | b |     c   |
  158.      * </pre>
  159.      *
  160.      * @return Length, the (perceived) overlap with the other object or null if there is no overlap.
  161.      */
  162.     Length getOverlap();

  163.     /**
  164.      * @return whether the other object is in front of the reference object.
  165.      */
  166.     boolean isAhead();

  167.     /**
  168.      * @return whether the other object is behind the reference object.
  169.      */
  170.     boolean isBehind();

  171.     /**
  172.      * @return whether the other object is parallel the reference object.
  173.      */
  174.     boolean isParallel();

  175.     /** {@inheritDoc} */
  176.     @Override
  177.     default int compareTo(final Headway headway)
  178.     {
  179.         if (getDistance() != null)
  180.         {
  181.             if (headway.getDistance() != null)
  182.             {
  183.                 return getDistance().compareTo(headway.getDistance());
  184.             }
  185.             return 1;
  186.         }
  187.         else if (headway.getDistance() != null)
  188.         {
  189.             return -1;
  190.         }
  191.         return getOverlapFront().compareTo(headway.getOverlapFront());
  192.     }
  193. }