View Javadoc
1   package org.opentrafficsim.road.network.sampling.data;
2   
3   import org.djunits.unit.SpeedUnit;
4   import org.djunits.value.vfloat.scalar.FloatSpeed;
5   import org.opentrafficsim.core.gtu.GTUException;
6   import org.opentrafficsim.core.network.NetworkException;
7   import org.opentrafficsim.kpi.sampling.data.ExtendedDataTypeSpeed;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
9   import org.opentrafficsim.road.network.sampling.GtuData;
10  
11  /**
12   * Reference speed for trajectories.
13   * <p>
14   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 21 nov. 2016 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
21   */
22  public class ReferenceSpeed extends ExtendedDataTypeSpeed<GtuData>
23  {
24  
25      /**
26       * 
27       */
28      public ReferenceSpeed()
29      {
30          super("referenceSpeed");
31      }
32  
33      /** {@inheritDoc} */
34      @Override
35      public final FloatSpeed getValue(final GtuData gtu)
36      {
37          LaneBasedGTU gtuObj = gtu.getGtu();
38          try
39          {
40              double v1 = gtuObj.getReferencePosition().getLane().getSpeedLimit(gtuObj.getGTUType()).si;
41              double v2 = gtuObj.getMaximumSpeed().si;
42              return new FloatSpeed(v1 < v2 ? v1 : v2, SpeedUnit.SI);
43          }
44          catch (@SuppressWarnings("unused") GTUException exception)
45          {
46              // GTU was destroyed and is without a reference location
47              return new FloatSpeed(Double.NaN, SpeedUnit.SI);
48          }
49          catch (NetworkException exception)
50          {
51              throw new RuntimeException("Could not obtain reference speed from GTU " + gtuObj, exception);
52          }
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public final String toString()
58      {
59          return "Reference Speed";
60      }
61  
62  }