View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception.mental;
2   
3   import org.opentrafficsim.base.parameters.ParameterException;
4   import org.opentrafficsim.road.gtu.lane.perception.LanePerception;
5   
6   /**
7    * Has task demand as internal variable.
8    * <p>
9    * Copyright (c) 2025-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
11   * </p>
12   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
13   */
14  public abstract class AbstractTask implements Task
15  {
16  
17      /** Id. */
18      private final String id;
19  
20      /** Task demand. */
21      private double taskDemand;
22  
23      /**
24       * Constructor.
25       * @param id id
26       */
27      public AbstractTask(final String id)
28      {
29          this.id = id;
30      }
31  
32      @Override
33      public double getTaskDemand(final LanePerception perception) throws ParameterException
34      {
35          this.taskDemand = calculateTaskDemand(perception);
36          return this.taskDemand;
37      }
38  
39      /**
40       * Calculates the task demand.
41       * @param perception perception
42       * @return task demand
43       * @throws ParameterException if a parameter is missing or out of bounds
44       */
45      protected abstract double calculateTaskDemand(LanePerception perception) throws ParameterException;
46  
47      @Override
48      public double getTaskDemand()
49      {
50          return this.taskDemand;
51      }
52  
53      @Override
54      public String getId()
55      {
56          return this.id;
57      }
58  
59  }