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
10
11
12
13
14
15
16
17
18
19 public enum Interpolation
20 {
21
22
23 STEPWISE
24 {
25
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
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
43 LINEAR
44 {
45
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
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
64
65
66
67
68
69
70
71 abstract Frequency
72 interpolate(Frequency frequency0, Duration time0, Frequency frequency1, Duration time1, Duration time);
73
74
75
76
77
78
79
80
81
82 abstract int integrate(Frequency frequency0, Duration time0, Frequency frequency1, Duration time1);
83
84 }