View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.mental.ar;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.opentrafficsim.base.parameters.ParameterException;
5   import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
6   import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
7   
8   /**
9    * Class for exponential demand.
10   * <p>
11   * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13   * </p>
14   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
15   */
16  public class ArTaskExponential extends AbstractArTask
17  {
18  
19      /** Initial level of task demand. */
20      private final double initialTaskDemand;
21  
22      /** Additional task demand. */
23      private final double additionalTaskDemand;
24  
25      /** Time scale at which task demand changes from the initial to the final value. */
26      private final Duration tau;
27  
28      /** Start time of the distraction. */
29      private final double start;
30  
31      /**
32       * Constructor.
33       * @param id id
34       * @param initialTaskDemand initial level of task demand
35       * @param finalTaskDemand final level of task demand
36       * @param tau time scale at which task demand changes from the initial to the final value
37       * @param simulator simulator
38       */
39      public ArTaskExponential(final String id, final double initialTaskDemand, final double finalTaskDemand, final Duration tau,
40              final OtsSimulatorInterface simulator)
41      {
42          super(id);
43          this.initialTaskDemand = initialTaskDemand;
44          this.additionalTaskDemand = finalTaskDemand - initialTaskDemand;
45          this.tau = tau;
46          this.start = simulator.getSimulatorTime().si;
47      }
48  
49      @Override
50      public double calculateTaskDemand(final LanePerception perception) throws ParameterException
51      {
52          double t = perception.getGtu().getSimulator().getSimulatorTime().si - this.start;
53          return this.initialTaskDemand + this.additionalTaskDemand * (1.0 - Math.exp(-t / this.tau.si));
54      }
55  
56  }