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
9
10
11
12
13
14
15
16
17 public class RampMetering
18 {
19
20
21 private final OtsSimulatorInterface simulator;
22
23
24 private final RampMeteringSwitch rampSwitch;
25
26
27 private final RampMeteringLightController rampLightController;
28
29
30
31
32
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
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 }