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
11
12
13
14
15
16
17
18
19 public class HeadwayGenerator implements Generator<Duration>
20 {
21
22
23 private final Frequency demand;
24
25
26 private final StreamInterface stream;
27
28
29
30
31
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 }