AdaptationHeadway.java

  1. package org.opentrafficsim.road.gtu.lane.perception.mental;

  2. import static org.opentrafficsim.base.parameters.constraint.NumericConstraint.POSITIVEZERO;

  3. import org.djunits.value.vdouble.scalar.Duration;
  4. import org.opentrafficsim.base.parameters.ParameterException;
  5. import org.opentrafficsim.base.parameters.ParameterTypeDouble;
  6. import org.opentrafficsim.base.parameters.ParameterTypes;
  7. import org.opentrafficsim.base.parameters.Parameters;
  8. import org.opentrafficsim.road.gtu.lane.perception.mental.Fuller.BehavioralAdaptation;

  9. /**
  10.  * Behavioral adaptation which increases the desired headway to reduce task-demand.
  11.  * <p>
  12.  * Copyright (c) 2013-2019 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 3 apr. 2018 <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 AdaptationHeadway implements BehavioralAdaptation
  21. {

  22.     /** Parameter for desired headway scaling. */
  23.     public static final ParameterTypeDouble BETA_T =
  24.             new ParameterTypeDouble("Beta_T", "max headway scaling", 1.0, POSITIVEZERO);

  25.     /** Base value for the minimum desired headway. */
  26.     private Duration t0Min;

  27.     /** Base value for the maximum desired headway. */
  28.     private Duration t0Max;

  29.     /** {@inheritDoc} */
  30.     @Override
  31.     public void adapt(final Parameters parameters, final double taskSaturation) throws ParameterException
  32.     {
  33.         if (this.t0Min == null)
  34.         {
  35.             this.t0Min = parameters.getParameterOrNull(ParameterTypes.TMIN);
  36.             this.t0Max = parameters.getParameterOrNull(ParameterTypes.TMAX);
  37.         }
  38.         double eps = parameters.getParameter(Fuller.TS) - parameters.getParameter(Fuller.TS_CRIT);
  39.         eps = eps < 0.0 ? 0.0 : (eps > 1.0 ? 1.0 : eps);
  40.         double factor = 1.0 + parameters.getParameter(BETA_T) * eps;
  41.         Duration tMin = this.t0Min.multiplyBy(factor);
  42.         Duration tMax = this.t0Max.multiplyBy(factor);
  43.         if (tMax.si <= parameters.getParameter(ParameterTypes.TMIN).si)
  44.         {
  45.             parameters.setParameter(ParameterTypes.TMIN, tMin);
  46.             parameters.setParameter(ParameterTypes.TMAX, tMax);
  47.         }
  48.         else
  49.         {
  50.             parameters.setParameter(ParameterTypes.TMAX, tMax);
  51.             parameters.setParameter(ParameterTypes.TMIN, tMin);
  52.         }
  53.     }

  54. }