View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.headway;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.opentrafficsim.core.gtu.GTUException;
5   import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
6   import org.opentrafficsim.core.network.NetworkException;
7   import org.opentrafficsim.core.network.route.Route;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9   import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
10  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
11  import org.opentrafficsim.road.network.speed.SpeedLimitTypes;
12  
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 <a href=
28   * "http://simulation.tudelft.nl:8085/browse/OTS-113">http://simulation.tudelft.nl:8085/browse/OTS-113</a>.
29   * <p>
30   * Copyright (c) 2013-2016 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 HeadwayGTUReal extends AbstractHeadwayGTU
40  {
41      /** */
42      private static final long serialVersionUID = 20160527L;
43  
44      /** stored car following model of the observed GTU. */
45      private final CarFollowingModel carFollowingModel;
46  
47      /** stored behavioral characteristics of the observed GTU. */
48      private final BehavioralCharacteristics behavioralCharacteristics;
49  
50      /** stored speed limit info of the observed GTU. */
51      private final SpeedLimitInfo speedLimitInfo;
52      
53      /** stored route of the observed GTU. */
54      private final Route route;
55  
56      /**
57       * Construct a new Headway information object, for a GTU ahead of us or behind us.
58       * @param gtu the observed GTU, can not be null.
59       * @param distance the distance to the other object; if this constructor is used, distance cannot be null.
60       * @param gtuStatus the observable characteristics of the GTU.
61       * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
62       */
63      public HeadwayGTUReal(final LaneBasedGTU gtu, final Length distance, final GTUStatus... gtuStatus) throws GTUException
64      {
65          super(gtu.getId(), gtu.getGTUType(), distance, true, gtu.getLength(), gtu.getSpeed(), gtu.getAcceleration(), gtuStatus);
66          this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
67          this.behavioralCharacteristics = new BehavioralCharacteristics(gtu.getBehavioralCharacteristics());
68          this.speedLimitInfo = getSpeedLimitInfo(gtu);
69          this.route = gtu.getStrategicalPlanner().getRoute();
70      }
71  
72      /**
73       * Construct a new Headway information object, for a GTU parallel with us.
74       * @param gtu the observed GTU, can not be null.
75       * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
76       * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
77       * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
78       * @throws GTUException when id is null, or parameters are inconsistent
79       */
80      public HeadwayGTUReal(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap, final Length overlapRear)
81          throws GTUException
82      {
83          super(gtu.getId(), gtu.getGTUType(), overlapFront, overlap, overlapRear, true, gtu.getLength(), gtu.getSpeed(), gtu
84              .getAcceleration());
85          this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
86          this.behavioralCharacteristics = new BehavioralCharacteristics(gtu.getBehavioralCharacteristics());
87          this.speedLimitInfo = getSpeedLimitInfo(gtu);
88          this.route = gtu.getStrategicalPlanner().getRoute();
89      }
90      
91      /**
92       * Creates speed limit prospect for given GTU.
93       * @param gtu gtu to the the speed limit prospect for
94       * @return speed limit prospect for given GTU
95       */
96      // TODO this is a simple fix, and getReferenceLane()
97      private SpeedLimitInfo getSpeedLimitInfo(final LaneBasedGTU gtu)
98      {
99          SpeedLimitInfo sli = new SpeedLimitInfo();
100         sli.addSpeedInfo(SpeedLimitTypes.MAX_VEHICLE_SPEED, gtu.getMaximumSpeed());
101         try
102         {
103             sli.addSpeedInfo(SpeedLimitTypes.FIXED_SIGN,
104                     gtu.getReferencePosition().getLane().getSpeedLimit(gtu.getGTUType()));
105         }
106         catch (NetworkException | GTUException exception)
107         {
108             throw new RuntimeException("Could not obtain speed limit from lane for perception.", exception);
109         }
110         return sli;
111     }
112 
113     /** {@inheritDoc} */
114     @Override
115     public final CarFollowingModel getCarFollowingModel()
116     {
117         return this.carFollowingModel;
118     }
119 
120     /** {@inheritDoc} */
121     @Override
122     public final BehavioralCharacteristics getBehavioralCharacteristics()
123     {
124         return this.behavioralCharacteristics;
125     }
126 
127     /** {@inheritDoc} */
128     @Override
129     public final SpeedLimitInfo getSpeedLimitInfo()
130     {
131         return this.speedLimitInfo;
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     public final Route getRoute()
137     {
138         return this.route;
139     }
140     
141 }