View Javadoc
1   package org.opentrafficsim.road.gtu.generator.headway;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.djunits.value.vdouble.scalar.Frequency;
5   import org.opentrafficsim.core.distributions.Generator;
6   
7   import nl.tudelft.simulation.jstats.streams.StreamInterface;
8   
9   /**
10   * Headway generator using independent arrivals (exponential distribution) at a fixed average rate.
11   * <p>
12   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * </p>
15   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
17   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18   */
19  public class HeadwayGenerator implements Generator<Duration>
20  {
21  
22      /** Demand level. */
23      private final Frequency demand;
24  
25      /** the stream information. */
26      private final StreamInterface stream;
27  
28      /**
29       * Constructor.
30       * @param demand demand.
31       * @param stream the stream to use for generation.
32       */
33      public HeadwayGenerator(final Frequency demand, final StreamInterface stream)
34      {
35          this.demand = demand;
36          this.stream = stream;
37      }
38  
39      @Override
40      public Duration draw()
41      {
42          return Duration.instantiateSI(-Math.log(this.stream.nextDouble()) / this.demand.si);
43      }
44  
45  }