1 package org.opentrafficsim.road.gtu.lane.perception.headway;
2
3 import org.djunits.value.vdouble.scalar.Acceleration;
4 import org.djunits.value.vdouble.scalar.Length;
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.opentrafficsim.core.gtu.GTUException;
7 import org.opentrafficsim.core.gtu.GTUType;
8 import org.opentrafficsim.core.gtu.behavioralcharacteristics.BehavioralCharacteristics;
9 import org.opentrafficsim.core.network.NetworkException;
10 import org.opentrafficsim.core.network.route.Route;
11 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
12 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
13 import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
14 import org.opentrafficsim.road.network.speed.SpeedLimitTypes;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class HeadwayGTURealCopy extends AbstractHeadwayGTU
43 {
44
45 private static final long serialVersionUID = 20160527L;
46
47
48 private final CarFollowingModel carFollowingModel;
49
50
51 private final BehavioralCharacteristics behavioralCharacteristics;
52
53
54 private final SpeedLimitInfo speedLimitInfo;
55
56
57 private final Route route;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 @SuppressWarnings("checkstyle:parameternumber")
75 HeadwayGTURealCopy(final String id, final GTUType gtuType, final Length distance, final Length length, final Speed speed,
76 final Acceleration acceleration, final CarFollowingModel carFollowingModel,
77 final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedLimitInfo, final Route route,
78 final GTUStatus... gtuStatus) throws GTUException
79 {
80 super(id, gtuType, distance, true, length, speed, acceleration, gtuStatus);
81 this.carFollowingModel = carFollowingModel;
82 this.behavioralCharacteristics = behavioralCharacteristics;
83 this.speedLimitInfo = speedLimitInfo;
84 this.route = route;
85 }
86
87
88
89
90
91
92
93
94 public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length distance, final GTUStatus... gtuStatus) throws GTUException
95 {
96 super(gtu.getId(), gtu.getGTUType(), distance, true, gtu.getLength(), gtu.getSpeed(), gtu.getAcceleration(), gtuStatus);
97 this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
98 this.behavioralCharacteristics = new BehavioralCharacteristics(gtu.getBehavioralCharacteristics());
99 this.speedLimitInfo = getSpeedLimitInfo(gtu);
100 this.route = gtu.getStrategicalPlanner().getRoute();
101 }
102
103
104
105
106
107
108
109
110
111 public HeadwayGTURealCopy(final LaneBasedGTU gtu, final Length overlapFront, final Length overlap, final Length overlapRear)
112 throws GTUException
113 {
114 super(gtu.getId(), gtu.getGTUType(), overlapFront, overlap, overlapRear, true, gtu.getLength(), gtu.getSpeed(),
115 gtu.getAcceleration());
116 this.carFollowingModel = gtu.getTacticalPlanner().getCarFollowingModel();
117 this.behavioralCharacteristics = new BehavioralCharacteristics(gtu.getBehavioralCharacteristics());
118 this.speedLimitInfo = getSpeedLimitInfo(gtu);
119 this.route = gtu.getStrategicalPlanner().getRoute();
120 }
121
122
123
124
125
126
127
128 private SpeedLimitInfo getSpeedLimitInfo(final LaneBasedGTU gtu)
129 {
130 SpeedLimitInfo sli = new SpeedLimitInfo();
131 sli.addSpeedInfo(SpeedLimitTypes.MAX_VEHICLE_SPEED, gtu.getMaximumSpeed());
132 try
133 {
134 sli.addSpeedInfo(SpeedLimitTypes.FIXED_SIGN, gtu.getReferencePosition().getLane().getSpeedLimit(gtu.getGTUType()));
135 }
136 catch (NetworkException | GTUException exception)
137 {
138 throw new RuntimeException("Could not obtain speed limit from lane for perception.", exception);
139 }
140 return sli;
141 }
142
143
144 @Override
145 public final CarFollowingModel getCarFollowingModel()
146 {
147 return this.carFollowingModel;
148 }
149
150
151 @Override
152 public final BehavioralCharacteristics getBehavioralCharacteristics()
153 {
154 return this.behavioralCharacteristics;
155 }
156
157
158 @Override
159 public final SpeedLimitInfo getSpeedLimitInfo()
160 {
161 return this.speedLimitInfo;
162 }
163
164
165 @Override
166 public final Route getRoute()
167 {
168 return this.route;
169 }
170
171
172 @Override
173 public AbstractHeadwayGTU moved(final Length headway, final Speed speed, final Acceleration acceleration)
174 {
175 try
176 {
177 return new HeadwayGTURealCopy(getId(), getGtuType(), headway, getLength(), speed, acceleration,
178 getCarFollowingModel(), getBehavioralCharacteristics(), getSpeedLimitInfo(), getRoute(), getGtuStatus());
179 }
180 catch (GTUException exception)
181 {
182
183 throw new RuntimeException("Exception while copying Headway GTU.", exception);
184 }
185 }
186
187 }