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
14
15
16
17
18
19
20
21
22 public class AdaptationHeadway implements BehavioralAdaptation
23 {
24
25
26 public static final ParameterTypeDouble BETA_T =
27 new ParameterTypeDouble("Beta_T", "max headway scaling", 1.0, POSITIVEZERO);
28
29
30 private Duration t0Min;
31
32
33 private Duration t0Max;
34
35
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 }