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.base.parameters.ParameterException;
6 import org.opentrafficsim.core.distributions.Generator;
7 import org.opentrafficsim.core.distributions.ProbabilityException;
8
9 import nl.tudelft.simulation.jstats.streams.StreamInterface;
10
11
12
13
14
15
16
17
18
19
20
21 public class HeadwayGenerator implements Generator<Duration>
22 {
23
24
25 private final Frequency demand;
26
27
28 private final StreamInterface stream;
29
30
31
32
33
34
35 public HeadwayGenerator(final Frequency demand, final StreamInterface stream)
36 {
37 this.demand = demand;
38 this.stream = stream;
39 }
40
41
42 @Override
43 public Duration draw() throws ProbabilityException, ParameterException
44 {
45 return Duration.instantiateSI(-Math.log(this.stream.nextDouble()) / this.demand.si);
46 }
47
48 }