View Javadoc
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   * Switch implementing the ALINEA algorithm.
14   * <p>
15   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17   * </p>
18   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
20   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
21   */
22  public class AlineaSwitch extends SingleCrossSectionSwitch
23  {
24  
25      /** Maximum cycle time. */
26      private static final Duration MAX_CYCLE_TIME = Duration.instantiateSI(15);
27  
28      /** Capacity. */
29      private final Frequency capacity;
30  
31      /** Flow threshold. */
32      private final Frequency flowThreshold;
33  
34      /** Speed threshold. */
35      private final Speed speedThreshold = new Speed(70, SpeedUnit.KM_PER_HOUR);
36  
37      /** Cycle time. */
38      private Duration cycleTime;
39  
40      /** Flow in previous time step. */
41      private Frequency lastFlow;
42  
43      /**
44       * @param detectors List&lt;Detector&gt;; detectors
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      /** {@inheritDoc} */
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      /** {@inheritDoc} */
71      @Override
72      public Duration getCycleTime()
73      {
74          return this.cycleTime;
75      }
76  
77  }