View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.mental;
2   
3   import static org.opentrafficsim.base.parameters.constraint.NumericConstraint.POSITIVEZERO;
4   
5   import org.djunits.value.vdouble.scalar.Duration;
6   import org.opentrafficsim.base.parameters.ParameterException;
7   import org.opentrafficsim.base.parameters.ParameterTypeDouble;
8   import org.opentrafficsim.base.parameters.ParameterTypes;
9   import org.opentrafficsim.base.parameters.Parameters;
10  import org.opentrafficsim.road.gtu.lane.perception.mental.Fuller.BehavioralAdaptation;
11  
12  /**
13   * Behavioral adaptation which increases the desired headway to reduce task-demand.
14   * <p>
15   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17   * </p>
18   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
20   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
21   */
22  public class AdaptationHeadway implements BehavioralAdaptation
23  {
24  
25      /** Parameter for desired headway scaling. */
26      public static final ParameterTypeDouble BETA_T =
27              new ParameterTypeDouble("Beta_T", "max headway scaling", 1.0, POSITIVEZERO);
28  
29      /** Base value for the minimum desired headway. */
30      private Duration t0Min;
31  
32      /** Base value for the maximum desired headway. */
33      private Duration t0Max;
34  
35      /** {@inheritDoc} */
36      @Override
37      public void adapt(final Parameters parameters, final double taskSaturation) throws ParameterException
38      {
39          if (this.t0Min == null)
40          {
41              this.t0Min = parameters.getParameterOrNull(ParameterTypes.TMIN);
42              this.t0Max = parameters.getParameterOrNull(ParameterTypes.TMAX);
43          }
44          double eps = parameters.getParameter(Fuller.TS) - parameters.getParameter(Fuller.TS_CRIT);
45          eps = eps < 0.0 ? 0.0 : (eps > 1.0 ? 1.0 : eps);
46          double factor = 1.0 + parameters.getParameter(BETA_T) * eps;
47          Duration tMin = this.t0Min.times(factor);
48          Duration tMax = this.t0Max.times(factor);
49          if (tMax.si <= parameters.getParameter(ParameterTypes.TMIN).si)
50          {
51              parameters.setParameter(ParameterTypes.TMIN, tMin);
52              parameters.setParameter(ParameterTypes.TMAX, tMax);
53          }
54          else
55          {
56              parameters.setParameter(ParameterTypes.TMAX, tMax);
57              parameters.setParameter(ParameterTypes.TMIN, tMin);
58          }
59      }
60  
61  }