View Javadoc
1   package org.opentrafficsim.road.gtu.generator.headway;
2   
3   import java.util.Optional;
4   
5   import org.djunits.value.vdouble.scalar.Duration;
6   import org.djunits.value.vdouble.scalar.Frequency;
7   import org.djunits.value.vdouble.vector.DurationVector;
8   import org.djunits.value.vdouble.vector.FrequencyVector;
9   import org.opentrafficsim.road.od.Interpolation;
10  
11  /**
12   * Demand pattern defined by a frequency vector, time vector and interpolation.
13   * <p>
14   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * </p>
17   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
19   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
20   * @param demandVector demand vector
21   * @param timeVector time vector
22   * @param interpolation interpolation
23   */
24  public record DemandPattern(FrequencyVector demandVector, DurationVector timeVector, Interpolation interpolation)
25          implements Arrivals
26  {
27  
28      @Override
29      public Frequency getFrequency(final Duration time, final boolean sliceStart)
30      {
31          return this.interpolation.interpolateVector(time, this.demandVector, this.timeVector, sliceStart);
32      }
33  
34      @Override
35      public Optional<Duration> nextTimeSlice(final Duration time)
36      {
37          for (Duration d : this.timeVector)
38          {
39              if (d.gt(time))
40              {
41                  return Optional.of(d);
42              }
43          }
44          return Optional.empty();
45      }
46  
47  }