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.sensor.Detector;
11
12
13
14
15
16
17
18
19
20
21
22
23 public class AlineaSwitch extends SingleCrossSectionSwitch
24 {
25
26
27 private static final Duration MAX_CYCLE_TIME = Duration.instantiateSI(15);
28
29
30 private final Frequency capacity;
31
32
33 private final Frequency flowThreshold;
34
35
36 private final Speed speedThreshold = new Speed(70, SpeedUnit.KM_PER_HOUR);
37
38
39 private Duration cycleTime;
40
41
42 private Frequency lastFlow;
43
44
45
46
47 public AlineaSwitch(final List<Detector> detectors)
48 {
49 super(Duration.instantiateSI(60.0), detectors);
50 this.capacity = new Frequency(2000, FrequencyUnit.PER_HOUR).times(detectors.size());
51 this.flowThreshold = new Frequency(1500, FrequencyUnit.PER_HOUR).times(detectors.size());
52 }
53
54
55 @Override
56 public boolean isEnabled()
57 {
58 Frequency flow = totalFlow();
59 if (meanSpeed().le(this.speedThreshold)
60 || (this.lastFlow != null && flow.lt(this.lastFlow) && flow.gt(this.flowThreshold)))
61 {
62 this.cycleTime = Duration.instantiateSI(1.0 / this.capacity.minus(flow).si);
63 this.cycleTime = Duration.min(this.cycleTime, MAX_CYCLE_TIME);
64 this.lastFlow = flow;
65 return true;
66 }
67 this.lastFlow = flow;
68 return false;
69 }
70
71
72 @Override
73 public Duration getCycleTime()
74 {
75 return this.cycleTime;
76 }
77
78 }