1 package org.opentrafficsim.road.network.control.rampmetering;
2
3 import org.opentrafficsim.base.OtsRuntimeException;
4 import org.opentrafficsim.base.logger.Logger;
5 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
6
7 import nl.tudelft.simulation.dsol.SimRuntimeException;
8
9
10
11
12
13
14
15
16
17
18
19 public class RampMetering
20 {
21
22
23 private final OtsSimulatorInterface simulator;
24
25
26 private final RampMeteringSwitch rampSwitch;
27
28
29 private final RampMeteringLightController rampLightController;
30
31
32
33
34
35
36
37 public RampMetering(final OtsSimulatorInterface simulator, final RampMeteringSwitch rampSwitch,
38 final RampMeteringLightController rampLightController)
39 {
40 this.simulator = simulator;
41 this.rampSwitch = rampSwitch;
42 this.rampLightController = rampLightController;
43 control();
44 }
45
46
47
48
49 private void control()
50 {
51 if (this.rampSwitch.isEnabled())
52 {
53 Logger.ots().info("Ramp-metering enabled.");
54 this.rampLightController.enable(this.rampSwitch.getCycleTime());
55 }
56 else
57 {
58 Logger.ots().info("Ramp-metering disabled.");
59 this.rampLightController.disable();
60 }
61 try
62 {
63 this.simulator.scheduleEventRel(this.rampSwitch.getInterval(), () -> control());
64 }
65 catch (SimRuntimeException exception)
66 {
67 throw new OtsRuntimeException("Interval from ramp metering switch is not a valid positive duration.", exception);
68 }
69 }
70
71 }