View Javadoc
1   package org.opentrafficsim.road.network.control.rampmetering;
2   
3   import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
4   
5   import nl.tudelft.simulation.dsol.SimRuntimeException;
6   
7   /**
8    * Ramp metering. This consist of a {@code RampMeteringSwitch} and a {@code RampMeteringLightController}.
9    * <p>
10   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12   * </p>
13   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
14   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
15   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
16   */
17  public class RampMetering
18  {
19  
20      /** Simulator. */
21      private final OtsSimulatorInterface simulator;
22  
23      /** Ramp metering switch. */
24      private final RampMeteringSwitch rampSwitch;
25  
26      /** Ramp metering light controller. */
27      private final RampMeteringLightController rampLightController;
28  
29      /**
30       * @param simulator OtsSimulatorInterface; simulator
31       * @param rampSwitch RampMeteringSwitch; ramp metering switch
32       * @param rampLightController RampMeteringLightController; ramp metering light controller
33       */
34      public RampMetering(final OtsSimulatorInterface simulator, final RampMeteringSwitch rampSwitch,
35              final RampMeteringLightController rampLightController)
36      {
37          this.simulator = simulator;
38          this.rampSwitch = rampSwitch;
39          this.rampLightController = rampLightController;
40          control();
41      }
42  
43      /**
44       * Executes control in a cyclic manner.
45       */
46      private void control()
47      {
48          if (this.rampSwitch.isEnabled())
49          {
50              this.simulator.getLogger().always().info("Ramp-metering enabled.");
51              this.rampLightController.enable(this.rampSwitch.getCycleTime());
52          }
53          else
54          {
55              this.simulator.getLogger().always().info("Ramp-metering disabled.");
56              this.rampLightController.disable();
57          }
58          try
59          {
60              this.simulator.scheduleEventRel(this.rampSwitch.getInterval(), this, "control", null);
61          }
62          catch (SimRuntimeException exception)
63          {
64              throw new RuntimeException("Interval from ramp metering switch is not a valid positive duration.", exception);
65          }
66      }
67  
68  }