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
54 @Override
55 public boolean isEnabled()
56 {
57 Frequency flow = totalFlow();
58 if (meanSpeed().le(this.speedThreshold)
59 || (this.lastFlow != null && flow.lt(this.lastFlow) && flow.gt(this.flowThreshold)))
60 {
61 this.cycleTime = Duration.instantiateSI(1.0 / this.capacity.minus(flow).si);
62 this.cycleTime = Duration.min(this.cycleTime, MAX_CYCLE_TIME);
63 this.lastFlow = flow;
64 return true;
65 }
66 this.lastFlow = flow;
67 return false;
68 }
69
70
71 @Override
72 public Duration getCycleTime()
73 {
74 return this.cycleTime;
75 }
76
77 }