View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.headway;
2   
3   import org.djunits.value.vdouble.scalar.Acceleration;
4   import org.djunits.value.vdouble.scalar.Length;
5   import org.djunits.value.vdouble.scalar.Speed;
6   import org.opentrafficsim.core.gtu.GTUException;
7   import org.opentrafficsim.core.gtu.GTUType;
8   import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
9   import org.opentrafficsim.core.network.NetworkException;
10  import org.opentrafficsim.core.network.route.Route;
11  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
12  import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
13  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
14  import org.opentrafficsim.road.network.speed.SpeedLimitTypes;
15  
16  /**
17   * Container for a reference to information about a (lane based) GTU and a headway. The Headway can store information about GTUs
18   * or objects ahead of the reference GTU, behind the reference GTU, or (partially) parallel to the reference GTU. In addition to
19   * the (perceived) headway, several other pieces of information can be stored, such as (perceived) speed, (perceived)
20   * acceleration, (perceived) turn indicators, and (perceived) braking lights. <br>
21   * This particular version returns behavioral information about the observed GTU objects based on their real state.<br>
22   * Special care must be taken in curves when perceiving headway of a GTU or object on an adjacent lane.The question is whether
23   * we perceive the parallel or ahead/behind based on a line perpendicular to the front/back of the GTU (rectangular), or
24   * perpendicular to the center line of the lane (wedge-shaped in case of a curve). The difficulty of a wedge-shaped situation is
25   * that reciprocity might be violated: in case of a clothoid, for instance, it is not sure that the point on the center line
26   * 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
27   * sharp bends. Therefore, algorithms implementing headway should only project the <i>reference point</i> of the reference GTU
28   * on the center line of the adjacent lane, and then calculate the forward position and backward position on the adjacent lane
29   * based on the reference point. Still, our human perception of what is parallel and what not, is not reflected by fractional
30   * positions. See examples in
31   * <a href= "http://simulation.tudelft.nl:8085/browse/OTS-113">http://simulation.tudelft.nl:8085/browse/OTS-113</a>.
32   * <p>
33   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
34   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
35   * </p>
36   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
37   * initial version May 27, 2016 <br>
38   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
39   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
40   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
41   */
42  public class HeadwayGTURealCopy extends AbstractHeadwayGTU
43  {
44      /** */
45      private static final long serialVersionUID = 20160527L;
46  
47      /** stored car following model of the observed GTU. */
48      private final CarFollowingModel carFollowingModel;
49  
50      /** stored behavioral characteristics of the observed GTU. */
51      private final BehavioralCharacteristics behavioralCharacteristics;
52  
53      /** stored speed limit info of the observed GTU. */
54      private final SpeedLimitInfo speedLimitInfo;
55  
56      /** stored route of the observed GTU. */
57      private final Route route;
58  
59      /**
60       * Private constructor for copies.
61       * @param id id
62       * @param gtuType GTU type
63       * @param distance distance
64       * @param length length
65       * @param speed speed
66       * @param acceleration acceleration
67       * @param carFollowingModel car-following model
68       * @param behavioralCharacteristics behavioral characteristics
69       * @param speedLimitInfo speed limit info
70       * @param route route
71       * @param gtuStatus gtu status
72       * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
73       */
74      @SuppressWarnings("checkstyle:parameternumber")
75      HeadwayGTURealCopy(final String id, final GTUType gtuType, final Length distance, final Length length, final Speed speed,
76              final Acceleration acceleration, final CarFollowingModel carFollowingModel,
77              final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedLimitInfo, final Route route,
78              final GTUStatus... gtuStatus) throws GTUException
79      {
80          super(id, gtuType, distance, true, length, speed, acceleration, gtuStatus);
81          this.carFollowingModel = carFollowingModel;
82          this.behavioralCharacteristics = behavioralCharacteristics;
83          this.speedLimitInfo = speedLimitInfo;
84          this.route = route;
85      }
86  
87      /**
88       * Construct a new Headway information object, for a GTU ahead of us or behind us.
89       * @param gtu the observed GTU, can not be null.
90       * @param distance the distance to the other object; if this constructor is used, distance cannot be null.
91       * @param gtuStatus the observable characteristics of the GTU.
92       * @throws GTUException when id is null, objectType is null, or parameters are inconsistent
93       */
94      public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length distance, final GTUStatus... gtuStatus) throws GTUException
95      {
96          super(gtu.getId(), gtu.getGTUType(), distance, true, gtu.getLength(), gtu.getSpeed(), gtu.getAcceleration(), gtuStatus);
97          this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
98          this.behavioralCharacteristics = new BehavioralCharacteristics(gtu.getBehavioralCharacteristics());
99          this.speedLimitInfo = getSpeedLimitInfo(gtu);
100         this.route = gtu.getStrategicalPlanner().getRoute();
101     }
102 
103     /**
104      * Construct a new Headway information object, for a GTU parallel with us.
105      * @param gtu the observed GTU, can not be null.
106      * @param overlapFront the front-front distance to the other GTU; if this constructor is used, this value cannot be null.
107      * @param overlap the 'center' overlap with the other GTU; if this constructor is used, this value cannot be null.
108      * @param overlapRear the rear-rear distance to the other GTU; if this constructor is used, this value cannot be null.
109      * @throws GTUException when id is null, or parameters are inconsistent
110      */
111     public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap, final Length overlapRear)
112             throws GTUException
113     {
114         super(gtu.getId(), gtu.getGTUType(), overlapFront, overlap, overlapRear, true, gtu.getLength(), gtu.getSpeed(),
115                 gtu.getAcceleration());
116         this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
117         this.behavioralCharacteristics = new BehavioralCharacteristics(gtu.getBehavioralCharacteristics());
118         this.speedLimitInfo = getSpeedLimitInfo(gtu);
119         this.route = gtu.getStrategicalPlanner().getRoute();
120     }
121 
122     /**
123      * Creates speed limit prospect for given GTU.
124      * @param gtu gtu to the the speed limit prospect for
125      * @return speed limit prospect for given GTU
126      */
127     // TODO this is a simple fix
128     private SpeedLimitInfo getSpeedLimitInfo(final LaneBasedGTU gtu)
129     {
130         SpeedLimitInfo sli = new SpeedLimitInfo();
131         sli.addSpeedInfo(SpeedLimitTypes.MAX_VEHICLE_SPEED, gtu.getMaximumSpeed());
132         try
133         {
134             sli.addSpeedInfo(SpeedLimitTypes.FIXED_SIGN, gtu.getReferencePosition().getLane().getSpeedLimit(gtu.getGTUType()));
135         }
136         catch (NetworkException | GTUException exception)
137         {
138             throw new RuntimeException("Could not obtain speed limit from lane for perception.", exception);
139         }
140         return sli;
141     }
142 
143     /** {@inheritDoc} */
144     @Override
145     public final CarFollowingModel getCarFollowingModel()
146     {
147         return this.carFollowingModel;
148     }
149 
150     /** {@inheritDoc} */
151     @Override
152     public final BehavioralCharacteristics getBehavioralCharacteristics()
153     {
154         return this.behavioralCharacteristics;
155     }
156 
157     /** {@inheritDoc} */
158     @Override
159     public final SpeedLimitInfo getSpeedLimitInfo()
160     {
161         return this.speedLimitInfo;
162     }
163 
164     /** {@inheritDoc} */
165     @Override
166     public final Route getRoute()
167     {
168         return this.route;
169     }
170 
171     /** {@inheritDoc} */
172     @Override
173     public AbstractHeadwayGTU moved(final Length headway, final Speed speed, final Acceleration acceleration)
174     {
175         try
176         {
177             return new HeadwayGTURealCopy(getId(), getGtuType(), headway, getLength(), speed, acceleration,
178                     getCarFollowingModel(), getBehavioralCharacteristics(), getSpeedLimitInfo(), getRoute(), getGtuStatus());
179         }
180         catch (GTUException exception)
181         {
182             // input should be consistent
183             throw new RuntimeException("Exception while copying Headway GTU.", exception);
184         }
185     }
186 
187 }