HeadwayGTURealCopy.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.base.parameters.ParameterSet;
  6. import org.opentrafficsim.base.parameters.Parameters;
  7. import org.opentrafficsim.core.gtu.GTUException;
  8. import org.opentrafficsim.core.gtu.GTUType;
  9. import org.opentrafficsim.core.network.route.Route;
  10. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  11. import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
  12. import org.opentrafficsim.road.network.speed.SpeedLimitInfo;

  13. /**
  14.  * Container for a reference to information about a (lane based) GTU and a headway. The Headway can store information about GTUs
  15.  * or objects ahead of the reference GTU, behind the reference GTU, or (partially) parallel to the reference GTU. In addition to
  16.  * the (perceived) headway, several other pieces of information can be stored, such as (perceived) speed, (perceived)
  17.  * acceleration, (perceived) turn indicators, and (perceived) braking lights. <br>
  18.  * This particular version returns behavioral information about the observed GTU objects based on their real state.<br>
  19.  * Special care must be taken in curves when perceiving headway of a GTU or object on an adjacent lane.The question is whether
  20.  * we perceive the parallel or ahead/behind based on a line perpendicular to the front/back of the GTU (rectangular), or
  21.  * perpendicular to the center line of the lane (wedge-shaped in case of a curve). The difficulty of a wedge-shaped situation is
  22.  * that reciprocity might be violated: in case of a clothoid, for instance, it is not sure that the point on the center line
  23.  * 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
  24.  * sharp bends. Therefore, algorithms implementing headway should only project the <i>reference point</i> of the reference GTU
  25.  * on the center line of the adjacent lane, and then calculate the forward position and backward position on the adjacent lane
  26.  * based on the reference point. Still, our human perception of what is parallel and what not, is not reflected by fractional
  27.  * positions. See examples in
  28.  * <a href= "http://simulation.tudelft.nl:8085/browse/OTS-113">http://simulation.tudelft.nl:8085/browse/OTS-113</a>.
  29.  * <p>
  30.  * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  31.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  32.  * </p>
  33.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  34.  * initial version May 27, 2016 <br>
  35.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  36.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  37.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  38.  */
  39. public class HeadwayGTURealCopy extends AbstractHeadwayGTU
  40. {
  41.     /** */
  42.     private static final long serialVersionUID = 20160527L;

  43.     /** stored car following model of the observed GTU. */
  44.     private final CarFollowingModel carFollowingModel;

  45.     /** stored parameters of the observed GTU. */
  46.     private final Parameters parameters;

  47.     /** stored speed limit info of the observed GTU. */
  48.     private final SpeedLimitInfo speedLimitInfo;

  49.     /** stored route of the observed GTU. */
  50.     private final Route route;

  51.     /**
  52.      * Protected constructor for moved copies or subclasses.
  53.      * @param id id
  54.      * @param gtuType GTU type
  55.      * @param distance distance
  56.      * @param length length
  57.      * @param width width
  58.      * @param speed speed
  59.      * @param acceleration acceleration
  60.      * @param carFollowingModel car-following model
  61.      * @param parameters parameters
  62.      * @param speedLimitInfo speed limit info
  63.      * @param route route
  64.      * @param desiredSpeed desired speed
  65.      * @param gtuStatus gtu status
  66.      * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
  67.      */
  68.     @SuppressWarnings("checkstyle:parameternumber")
  69.     HeadwayGTURealCopy(final String id, final GTUType gtuType, final Length distance, final Length length, final Length width,
  70.             final Speed speed, final Acceleration acceleration, final CarFollowingModel carFollowingModel,
  71.             final Parameters parameters, final SpeedLimitInfo speedLimitInfo, final Route route, final Speed desiredSpeed,
  72.             final GTUStatus... gtuStatus) throws GTUException
  73.     {
  74.         super(id, gtuType, distance, true, length, width, speed, acceleration, desiredSpeed, gtuStatus);
  75.         this.carFollowingModel = carFollowingModel;
  76.         this.parameters = parameters;
  77.         this.speedLimitInfo = speedLimitInfo;
  78.         this.route = route;
  79.     }

  80.     /**
  81.      * Protected constructor for moved copies or subclasses.
  82.      * @param id id
  83.      * @param gtuType GTU type
  84.      * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
  85.      * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
  86.      * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
  87.      * @param length length
  88.      * @param width width
  89.      * @param speed speed
  90.      * @param acceleration acceleration
  91.      * @param carFollowingModel car-following model
  92.      * @param parameters parameters
  93.      * @param speedLimitInfo speed limit info
  94.      * @param route route
  95.      * @param desiredSpeed desired speed
  96.      * @param gtuStatus gtu status
  97.      * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
  98.      */
  99.     @SuppressWarnings("checkstyle:parameternumber")
  100.     HeadwayGTURealCopy(final String id, final GTUType gtuType, final Length overlapFront, final Length overlap,
  101.             final Length overlapRear, final Length length, final Length width, final Speed speed,
  102.             final Acceleration acceleration, final CarFollowingModel carFollowingModel, final Parameters parameters,
  103.             final SpeedLimitInfo speedLimitInfo, final Route route, final Speed desiredSpeed, final GTUStatus... gtuStatus)
  104.             throws GTUException
  105.     {
  106.         super(id, gtuType, overlapFront, overlap, overlapRear, true, length, width, speed, acceleration, desiredSpeed,
  107.                 gtuStatus);
  108.         this.carFollowingModel = carFollowingModel;
  109.         this.parameters = parameters;
  110.         this.speedLimitInfo = speedLimitInfo;
  111.         this.route = route;
  112.     }

  113.     /**
  114.      * Construct a new Headway information object, for a GTU ahead of us or behind us.
  115.      * @param gtu the observed GTU, can not be null.
  116.      * @param distance the distance to the other object; if this constructor is used, distance cannot be null.
  117.      * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
  118.      */
  119.     public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length distance) throws GTUException
  120.     {
  121.         super(gtu.getId(), gtu.getGTUType(), distance, true, gtu.getLength(), gtu.getWidth(), gtu.getSpeed(),
  122.                 gtu.getAcceleration(), gtu.getDesiredSpeed(),
  123.                 getGTUStatuses(gtu, gtu.getSimulator().getSimulatorTime()));
  124.         this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
  125.         this.parameters = new ParameterSet(gtu.getParameters());
  126.         this.speedLimitInfo = getSpeedLimitInfo(gtu);
  127.         this.route = gtu.getStrategicalPlanner().getRoute();
  128.     }

  129.     /**
  130.      * Construct a new Headway information object, for a GTU parallel with us.
  131.      * @param gtu the observed GTU, can not be null.
  132.      * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
  133.      * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
  134.      * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
  135.      * @throws GTUException when id is null, or parameters are inconsistent
  136.      */
  137.     public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap, final Length overlapRear)
  138.             throws GTUException
  139.     {
  140.         super(gtu.getId(), gtu.getGTUType(), overlapFront, overlap, overlapRear, true, gtu.getLength(), gtu.getWidth(),
  141.                 gtu.getSpeed(), gtu.getAcceleration(), gtu.getDesiredSpeed(),
  142.                 getGTUStatuses(gtu, gtu.getSimulator().getSimulatorTime()));
  143.         this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
  144.         this.parameters = new ParameterSet(gtu.getParameters());
  145.         this.speedLimitInfo = getSpeedLimitInfo(gtu);
  146.         this.route = gtu.getStrategicalPlanner().getRoute();
  147.     }

  148.     /** {@inheritDoc} */
  149.     @Override
  150.     public final CarFollowingModel getCarFollowingModel()
  151.     {
  152.         return this.carFollowingModel;
  153.     }

  154.     /** {@inheritDoc} */
  155.     @Override
  156.     public final Parameters getParameters()
  157.     {
  158.         return this.parameters;
  159.     }

  160.     /** {@inheritDoc} */
  161.     @Override
  162.     public final SpeedLimitInfo getSpeedLimitInfo()
  163.     {
  164.         return this.speedLimitInfo;
  165.     }

  166.     /** {@inheritDoc} */
  167.     @Override
  168.     public final Route getRoute()
  169.     {
  170.         return this.route;
  171.     }

  172.     /** {@inheritDoc} */
  173.     @Override
  174.     public final AbstractHeadwayGTU moved(final Length headway, final Speed speed, final Acceleration acceleration)
  175.     {
  176.         try
  177.         {
  178.             return new HeadwayGTURealCopy(getId(), getGtuType(), headway, getLength(), getWidth(), speed, acceleration,
  179.                     getCarFollowingModel(), getParameters(), getSpeedLimitInfo(), getRoute(), getDesiredSpeed(),
  180.                     getGtuStatus());
  181.         }
  182.         catch (GTUException exception)
  183.         {
  184.             // input should be consistent
  185.             throw new RuntimeException("Exception while copying Headway GTU.", exception);
  186.         }
  187.     }

  188.     /** {@inheritDoc} */
  189.     @Override
  190.     public final String toString()
  191.     {
  192.         return "HeadwayGTURealCopy [carFollowingModel=" + this.carFollowingModel + ", parameters=" + this.parameters
  193.                 + ", speedLimitInfo=" + this.speedLimitInfo + ", route=" + this.route + "]";
  194.     }

  195. }