1 package org.opentrafficsim.road.network.control.rampmetering;
2
3 import java.util.List;
4
5 import org.djunits.unit.FrequencyUnit;
6 import org.djunits.unit.SpeedUnit;
7 import org.djunits.value.vdouble.scalar.Duration;
8 import org.djunits.value.vdouble.scalar.Frequency;
9 import org.djunits.value.vdouble.scalar.Speed;
10 import org.opentrafficsim.road.network.lane.object.detector.LoopDetector;
11
12
13
14
15
16
17
18
19
20
21
22 public class AlineaSwitch extends SingleCrossSectionSwitch
23 {
24
25
26 private static final Duration MAX_CYCLE_TIME = Duration.instantiateSI(15);
27
28
29 private final Frequency capacity;
30
31
32 private final Frequency flowThreshold;
33
34
35 private final Speed speedThreshold = new Speed(70, SpeedUnit.KM_PER_HOUR);
36
37
38 private Duration cycleTime;
39
40
41 private Frequency lastFlow;
42
43
44
45
46 public AlineaSwitch(final List<LoopDetector> detectors)
47 {
48 super(Duration.instantiateSI(60.0), detectors);
49 this.capacity = new Frequency(2000, FrequencyUnit.PER_HOUR).times(detectors.size());
50 this.flowThreshold = new Frequency(1500, FrequencyUnit.PER_HOUR).times(detectors.size());
51 }
52
53 @Override
54 public boolean isEnabled()
55 {
56 Frequency flow = totalFlow();
57 if (meanSpeed().le(this.speedThreshold)
58 || (this.lastFlow != null && flow.lt(this.lastFlow) && flow.gt(this.flowThreshold)))
59 {
60 this.cycleTime = Duration.instantiateSI(1.0 / this.capacity.minus(flow).si);
61 this.cycleTime = Duration.min(this.cycleTime, MAX_CYCLE_TIME);
62 this.lastFlow = flow;
63 return true;
64 }
65 this.lastFlow = flow;
66 return false;
67 }
68
69 @Override
70 public Duration getCycleTime()
71 {
72 return this.cycleTime;
73 }
74
75 }