1 package org.opentrafficsim.road.gtu.generator.headway;
2
3 import org.djunits.value.vdouble.scalar.Frequency;
4 import org.djunits.value.vdouble.scalar.Time;
5 import org.djunits.value.vdouble.vector.FrequencyVector;
6 import org.djunits.value.vdouble.vector.TimeVector;
7 import org.opentrafficsim.road.od.Interpolation;
8
9 /**
10 * Demand pattern defined by a frequency vector, time vector and interpolation.
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://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
17 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18 * @param demandVector FrequencyVector; demand vector
19 * @param timeVector TimeVector; time vector
20 * @param interpolation Interpolation; interpolation
21 */
22 public record DemandPattern(FrequencyVector demandVector, TimeVector timeVector, Interpolation interpolation)
23 implements Arrivals
24 {
25
26 /** {@inheritDoc} */
27 @Override
28 public Frequency getFrequency(final Time time, final boolean sliceStart)
29 {
30 return this.interpolation.interpolateVector(time, this.demandVector, this.timeVector, sliceStart);
31 }
32
33 /** {@inheritDoc} */
34 @Override
35 public Time nextTimeSlice(final Time time)
36 {
37 for (Time d : this.timeVector)
38 {
39 if (d.gt(time))
40 {
41 return d;
42 }
43 }
44 return null;
45 }
46
47 }