View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.mental;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.opentrafficsim.base.parameters.ParameterException;
5   import org.opentrafficsim.base.parameters.Parameters;
6   import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
7   import org.opentrafficsim.core.gtu.GtuException;
8   import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
9   import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
10  
11  /**
12   * Class for exponential demand.
13   */
14  public class ExponentialTask extends AbstractTask
15  {
16      /** Initial level of task demand. */
17      private final double initialTaskDemand;
18  
19      /** Additional task demand. */
20      private final double additionalTaskDemand;
21  
22      /** Time scale at which task demand changes from the initial to the final value. */
23      private final Duration tau;
24  
25      /** Start time of the distraction. */
26      private final double start;
27  
28      /**
29       * Constructor.
30       * @param id String; id
31       * @param initialTaskDemand double; initial level of task demand
32       * @param finalTaskDemand double; final level of task demand
33       * @param tau Duration; time scale at which task demand changes from the initial to the final value
34       * @param simulator OtsSimulatorInterface; simulator
35       */
36      public ExponentialTask(final String id, final double initialTaskDemand, final double finalTaskDemand, final Duration tau,
37              final OtsSimulatorInterface simulator)
38      {
39          super(id);
40          this.initialTaskDemand = initialTaskDemand;
41          this.additionalTaskDemand = finalTaskDemand - initialTaskDemand;
42          this.tau = tau;
43          this.start = simulator.getSimulatorTime().si;
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public double calculateTaskDemand(final LanePerception perception, final LaneBasedGtu gtu, final Parameters parameters)
49              throws ParameterException, GtuException
50      {
51          double t = gtu.getSimulator().getSimulatorTime().si - this.start;
52          return this.initialTaskDemand + this.additionalTaskDemand * (1.0 - Math.exp(-t / this.tau.si));
53      }
54  
55  }