1 package org.opentrafficsim.road.gtu.strategical.od;
2
3 import org.djunits.unit.FrequencyUnit;
4 import org.djunits.unit.TimeUnit;
5 import org.djunits.value.vdouble.scalar.Duration;
6 import org.djunits.value.vdouble.scalar.Frequency;
7
8 /**
9 * Interpolation of demand.
10 * <p>
11 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12 * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
13 * <p>
14 * @version $Revision$, $LastChangedDate$, by $Author$, initial version Sep 15, 2016 <br>
15 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
18 */
19 public enum Interpolation
20 {
21
22 /** Stepwise interpolation of demand. */
23 STEPWISE
24 {
25 /** {@inheritDoc} */
26 @Override
27 Frequency interpolate(final Frequency frequency0, final Duration time0, final Frequency frequency1,
28 final Duration time1, final Duration time)
29 {
30 return frequency0;
31 }
32
33 /** {@inheritDoc} */
34 @Override
35 int integrate(final Frequency frequency0, final Duration time0, final Frequency frequency1, final Duration time1)
36 {
37 return (int) (frequency0.getInUnit(FrequencyUnit.PER_HOUR) * (time1.getInUnit(TimeUnit.HOUR) - time0
38 .getInUnit(TimeUnit.HOUR)));
39 }
40 },
41
42 /** Linear interpolation of demand. */
43 LINEAR
44 {
45 /** {@inheritDoc} */
46 @Override
47 Frequency interpolate(final Frequency frequency0, final Duration time0, final Frequency frequency1,
48 final Duration time1, final Duration time)
49 {
50 return Frequency.interpolate(frequency0, frequency1, (time.si - time0.si) / (time1.si - time0.si));
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 int integrate(final Frequency frequency0, final Duration time0, final Frequency frequency1, final Duration time1)
56 {
57 return (int) (0.5 * (frequency0.getInUnit(FrequencyUnit.PER_HOUR) + frequency1.getInUnit(FrequencyUnit.PER_HOUR)) * (time1
58 .getInUnit(TimeUnit.HOUR) - time0.getInUnit(TimeUnit.HOUR)));
59 }
60 };
61
62 /**
63 * Interpolate between given frequencies.
64 * @param frequency0 frequency at {@code time0}
65 * @param time0 time of {@code frequency0} (≤ {@code time})
66 * @param frequency1 frequency at {@code time1}
67 * @param time1 time of {@code frequency1} (> {@code time})
68 * @param time {@code time0} ≤ {@code time} < {@code time1}
69 * @return interpolated frequency
70 */
71 abstract Frequency
72 interpolate(Frequency frequency0, Duration time0, Frequency frequency1, Duration time1, Duration time);
73
74 /**
75 * Integrates to the number of trips in given period.
76 * @param frequency0 frequency at {@code time0}
77 * @param time0 time of {@code frequency0} (≤ {@code time})
78 * @param frequency1 frequency at {@code time1}
79 * @param time1 time of {@code frequency1} (> {@code time})
80 * @return number of trips in given period
81 */
82 abstract int integrate(Frequency frequency0, Duration time0, Frequency frequency1, Duration time1);
83
84 }