ReferenceSpeed.java

  1. package org.opentrafficsim.road.network.sampling.data;

  2. import org.djunits.unit.SpeedUnit;
  3. import org.djunits.value.vfloat.scalar.FloatSpeed;
  4. import org.opentrafficsim.core.gtu.GTUException;
  5. import org.opentrafficsim.core.network.NetworkException;
  6. import org.opentrafficsim.kpi.sampling.data.ExtendedDataTypeSpeed;
  7. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  8. import org.opentrafficsim.road.network.sampling.GtuData;

  9. /**
  10.  * Reference speed for trajectories.
  11.  * <p>
  12.  * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  13.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  14.  * <p>
  15.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 21 nov. 2016 <br>
  16.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  17.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  18.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  19.  */
  20. public class ReferenceSpeed extends ExtendedDataTypeSpeed<GtuData>
  21. {

  22.     /**
  23.      *
  24.      */
  25.     public ReferenceSpeed()
  26.     {
  27.         super("referenceSpeed");
  28.     }

  29.     /** {@inheritDoc} */
  30.     @Override
  31.     public final FloatSpeed getValue(final GtuData gtu)
  32.     {
  33.         LaneBasedGTU gtuObj = gtu.getGtu();
  34.         try
  35.         {
  36.             double v1 = gtuObj.getReferencePosition().getLane().getSpeedLimit(gtuObj.getGTUType()).si;
  37.             double v2 = gtuObj.getMaximumSpeed().si;
  38.             return new FloatSpeed(v1 < v2 ? v1 : v2, SpeedUnit.SI);
  39.         }
  40.         catch (@SuppressWarnings("unused") GTUException exception)
  41.         {
  42.             // GTU was destroyed and is without a reference location
  43.             return new FloatSpeed(Double.NaN, SpeedUnit.SI);
  44.         }
  45.         catch (NetworkException exception)
  46.         {
  47.             throw new RuntimeException("Could not obtain reference speed from GTU " + gtuObj, exception);
  48.         }
  49.     }

  50.     /** {@inheritDoc} */
  51.     @Override
  52.     public final String toString()
  53.     {
  54.         return "Reference Speed";
  55.     }

  56. }