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