1 package org.opentrafficsim.road.gtu.operational;
2
3 import org.djunits.value.vdouble.scalar.Acceleration;
4 import org.djunits.value.vdouble.scalar.Duration;
5 import org.djutils.exceptions.Throw;
6 import org.opentrafficsim.base.logger.Logger;
7 import org.opentrafficsim.core.network.LateralDirectionality;
8
9
10
11
12
13
14
15
16
17
18
19
20 public class SimpleOperationalPlan
21 {
22
23
24 private Acceleration acceleration;
25
26
27 private final Duration duration;
28
29
30 private final LateralDirectionality laneChangeDirection;
31
32
33
34
35
36
37 public SimpleOperationalPlan(final Acceleration acceleration, final Duration duration)
38 {
39 this(acceleration, duration, LateralDirectionality.NONE);
40 }
41
42
43
44
45
46
47
48 public SimpleOperationalPlan(final Acceleration acceleration, final Duration duration,
49 final LateralDirectionality laneChangeDirection)
50 {
51 Throw.whenNull(acceleration, "Acceleration may not be null.");
52 Throw.whenNull(duration, "Duration may not be null.");
53 Throw.whenNull(laneChangeDirection, "Lane change direction may not be null.");
54 checkAcceleration(acceleration);
55 this.acceleration = Acceleration.max(Acceleration.ofSI(-100.0), acceleration);
56 this.duration = duration;
57 this.laneChangeDirection = laneChangeDirection;
58 }
59
60
61
62
63
64 public final Acceleration getAcceleration()
65 {
66 return this.acceleration;
67 }
68
69
70
71
72
73 public final void setAcceleration(final Acceleration acceleration)
74 {
75 checkAcceleration(acceleration);
76 this.acceleration = acceleration;
77 }
78
79
80
81
82
83 public Duration getDuration()
84 {
85 return this.duration;
86 }
87
88
89
90
91
92 public final boolean isLaneChange()
93 {
94 return this.laneChangeDirection != LateralDirectionality.NONE;
95 }
96
97
98
99
100
101 public final LateralDirectionality getLaneChangeDirection()
102 {
103 return this.laneChangeDirection;
104 }
105
106
107
108
109
110 public final void minimizeAcceleration(final Acceleration a)
111 {
112 checkAcceleration(a);
113 this.acceleration = Acceleration.max(Acceleration.ofSI(-100.0), Acceleration.min(this.acceleration, a));
114 }
115
116
117
118
119
120 private void checkAcceleration(final Acceleration a)
121 {
122 if (a.equals(Acceleration.NEGATIVE_INFINITY) || a.equals(Acceleration.NEG_MAXVALUE))
123 {
124 Logger.ots().error("Model has calculated a negative infinite or negative max value acceleration.");
125 }
126 }
127
128 @Override
129 @SuppressWarnings("checkstyle:designforextension")
130 public String toString()
131 {
132 return "SimpleOperationalPlan [Acceleration=" + this.acceleration + ", change=" + this.laneChangeDirection + "]";
133 }
134
135 }