Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file Vehicle.cpp
15 : /// @author Jakob Erdmann
16 : /// @author Michael Behrisch
17 : /// @author Mirko Barthauer
18 : /// @date 30.05.2012
19 : ///
20 : // C++ TraCI client API implementation
21 : /****************************************************************************/
22 : #include <config.h>
23 : #include <sstream>
24 :
25 : #define LIBTRACI 1
26 : #include <libsumo/StorageHelper.h>
27 : #include <libsumo/Vehicle.h>
28 : #include "Domain.h"
29 :
30 : namespace libtraci {
31 :
32 : typedef Domain<libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::CMD_SET_VEHICLE_VARIABLE> Dom;
33 :
34 :
35 : // ===========================================================================
36 : // static member definitions
37 : // ===========================================================================
38 : std::vector<std::string>
39 42371 : Vehicle::getIDList() {
40 84741 : return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
41 : }
42 :
43 :
44 : int
45 31 : Vehicle::getIDCount() {
46 62 : return Dom::getInt(libsumo::ID_COUNT, "");
47 : }
48 :
49 :
50 32962 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Vehicle, VEHICLE)
51 1209 : LIBTRACI_PARAMETER_IMPLEMENTATION(Vehicle, VEHICLE)
52 :
53 : double
54 5157 : Vehicle::getSpeed(const std::string& vehID) {
55 5157 : return Dom::getDouble(libsumo::VAR_SPEED, vehID);
56 : }
57 :
58 : double
59 18 : Vehicle::getLateralSpeed(const std::string& vehID) {
60 18 : return Dom::getDouble(libsumo::VAR_SPEED_LAT, vehID);
61 : }
62 :
63 : double
64 1176 : Vehicle::getAcceleration(const std::string& vehID) {
65 1176 : return Dom::getDouble(libsumo::VAR_ACCELERATION, vehID);
66 : }
67 :
68 :
69 : double
70 1028 : Vehicle::getSpeedWithoutTraCI(const std::string& vehID) {
71 1028 : return Dom::getDouble(libsumo::VAR_SPEED_WITHOUT_TRACI, vehID);
72 : }
73 :
74 :
75 : libsumo::TraCIPosition
76 331143 : Vehicle::getPosition(const std::string& vehID, const bool includeZ) {
77 331143 : return includeZ ? getPosition3D(vehID) : Dom::getPos(libsumo::VAR_POSITION, vehID);
78 : }
79 :
80 :
81 : libsumo::TraCIPosition
82 399 : Vehicle::getPosition3D(const std::string& vehID) {
83 399 : return Dom::getPos3D(libsumo::VAR_POSITION3D, vehID);
84 : }
85 :
86 :
87 : double
88 102 : Vehicle::getAngle(const std::string& vehID) {
89 102 : return Dom::getDouble(libsumo::VAR_ANGLE, vehID);
90 : }
91 :
92 :
93 : double
94 2 : Vehicle::getSlope(const std::string& vehID) {
95 2 : return Dom::getDouble(libsumo::VAR_SLOPE, vehID);
96 : }
97 :
98 :
99 : std::string
100 1019 : Vehicle::getRoadID(const std::string& vehID) {
101 1019 : return Dom::getString(libsumo::VAR_ROAD_ID, vehID);
102 : }
103 :
104 :
105 : double
106 18 : Vehicle::getDeparture(const std::string& vehID) {
107 18 : return Dom::getDouble(libsumo::VAR_DEPARTURE, vehID);
108 : }
109 :
110 :
111 : double
112 18 : Vehicle::getDepartDelay(const std::string& vehID) {
113 18 : return Dom::getDouble(libsumo::VAR_DEPART_DELAY, vehID);
114 : }
115 :
116 :
117 : std::string
118 3357 : Vehicle::getLaneID(const std::string& vehID) {
119 3357 : return Dom::getString(libsumo::VAR_LANE_ID, vehID);
120 : }
121 :
122 :
123 : int
124 1258 : Vehicle::getLaneIndex(const std::string& vehID) {
125 1258 : return Dom::getInt(libsumo::VAR_LANE_INDEX, vehID);
126 : }
127 :
128 :
129 : std::string
130 24 : Vehicle::getSegmentID(const std::string& vehID) {
131 24 : return Dom::getString(libsumo::VAR_SEGMENT_ID, vehID);
132 : }
133 :
134 :
135 : int
136 23 : Vehicle::getSegmentIndex(const std::string& vehID) {
137 23 : return Dom::getInt(libsumo::VAR_SEGMENT_INDEX, vehID);
138 : }
139 :
140 :
141 : std::string
142 83 : Vehicle::getTypeID(const std::string& vehID) {
143 83 : return Dom::getString(libsumo::VAR_TYPE, vehID);
144 : }
145 :
146 :
147 : std::string
148 26 : Vehicle::getRouteID(const std::string& vehID) {
149 26 : return Dom::getString(libsumo::VAR_ROUTE_ID, vehID);
150 : }
151 :
152 :
153 : int
154 992 : Vehicle::getRouteIndex(const std::string& vehID) {
155 992 : return Dom::getInt(libsumo::VAR_ROUTE_INDEX, vehID);
156 : }
157 :
158 :
159 : libsumo::TraCIColor
160 40 : Vehicle::getColor(const std::string& vehID) {
161 40 : return Dom::getCol(libsumo::VAR_COLOR, vehID);
162 : }
163 :
164 : double
165 4745 : Vehicle::getLanePosition(const std::string& vehID) {
166 4745 : return Dom::getDouble(libsumo::VAR_LANEPOSITION, vehID);
167 : }
168 :
169 : double
170 798 : Vehicle::getLateralLanePosition(const std::string& vehID) {
171 798 : return Dom::getDouble(libsumo::VAR_LANEPOSITION_LAT, vehID);
172 : }
173 :
174 : double
175 98 : Vehicle::getCO2Emission(const std::string& vehID) {
176 98 : return Dom::getDouble(libsumo::VAR_CO2EMISSION, vehID);
177 : }
178 :
179 : double
180 18 : Vehicle::getCOEmission(const std::string& vehID) {
181 18 : return Dom::getDouble(libsumo::VAR_COEMISSION, vehID);
182 : }
183 :
184 : double
185 18 : Vehicle::getHCEmission(const std::string& vehID) {
186 18 : return Dom::getDouble(libsumo::VAR_HCEMISSION, vehID);
187 : }
188 :
189 : double
190 18 : Vehicle::getPMxEmission(const std::string& vehID) {
191 18 : return Dom::getDouble(libsumo::VAR_PMXEMISSION, vehID);
192 : }
193 :
194 : double
195 18 : Vehicle::getNOxEmission(const std::string& vehID) {
196 18 : return Dom::getDouble(libsumo::VAR_NOXEMISSION, vehID);
197 : }
198 :
199 : double
200 88 : Vehicle::getFuelConsumption(const std::string& vehID) {
201 88 : return Dom::getDouble(libsumo::VAR_FUELCONSUMPTION, vehID);
202 : }
203 :
204 : double
205 18 : Vehicle::getNoiseEmission(const std::string& vehID) {
206 18 : return Dom::getDouble(libsumo::VAR_NOISEEMISSION, vehID);
207 : }
208 :
209 : double
210 38 : Vehicle::getElectricityConsumption(const std::string& vehID) {
211 38 : return Dom::getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, vehID);
212 : }
213 :
214 : int
215 18 : Vehicle::getPersonNumber(const std::string& vehID) {
216 18 : return Dom::getInt(libsumo::VAR_PERSON_NUMBER, vehID);
217 : }
218 :
219 : int
220 18 : Vehicle::getPersonCapacity(const std::string& vehID) {
221 18 : return Dom::getInt(libsumo::VAR_PERSON_CAPACITY, vehID);
222 : }
223 :
224 :
225 : double
226 18 : Vehicle::getBoardingDuration(const std::string& vehID) {
227 18 : return Dom::getDouble(libsumo::VAR_BOARDING_DURATION, vehID);
228 : }
229 :
230 :
231 : double
232 24 : Vehicle::getImpatience(const std::string& vehID) {
233 24 : return Dom::getDouble(libsumo::VAR_IMPATIENCE, vehID);
234 : }
235 :
236 :
237 : std::vector<std::string>
238 40 : Vehicle::getPersonIDList(const std::string& vehID) {
239 40 : return Dom::getStringVector(libsumo::LAST_STEP_PERSON_ID_LIST, vehID);
240 : }
241 :
242 : std::pair<std::string, double>
243 6177 : Vehicle::getLeader(const std::string& vehID, double dist) {
244 6177 : tcpip::Storage content;
245 : StoHelp::writeTypedDouble(content, dist);
246 6177 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
247 : tcpip::Storage& ret = Dom::get(libsumo::VAR_LEADER, vehID, &content);
248 6177 : ret.readInt(); // components
249 6177 : ret.readUnsignedByte();
250 6177 : const std::string leaderID = ret.readString();
251 6177 : ret.readUnsignedByte();
252 6177 : const double gap = ret.readDouble();
253 6177 : return std::make_pair(leaderID, gap);
254 6177 : }
255 :
256 :
257 : std::pair<std::string, double>
258 59 : Vehicle::getFollower(const std::string& vehID, double dist) {
259 59 : tcpip::Storage content;
260 : StoHelp::writeTypedDouble(content, dist);
261 59 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
262 : tcpip::Storage& ret = Dom::get(libsumo::VAR_FOLLOWER, vehID, &content);
263 58 : ret.readInt(); // components
264 59 : const std::string leaderID = StoHelp::readTypedString(ret);
265 174 : return std::make_pair(leaderID, StoHelp::readTypedDouble(ret));
266 59 : }
267 :
268 :
269 : std::vector<libsumo::TraCIJunctionFoe>
270 30 : Vehicle::getJunctionFoes(const std::string& vehID, double dist) {
271 : std::vector<libsumo::TraCIJunctionFoe> result;
272 30 : tcpip::Storage content;
273 : StoHelp::writeTypedDouble(content, dist);
274 30 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
275 : tcpip::Storage& ret = Dom::get(libsumo::VAR_FOES, vehID, &content);
276 30 : ret.readInt(); // compound size
277 60 : StoHelp::readJunctionFoeVector(ret, result);
278 30 : return result;
279 30 : }
280 :
281 :
282 : double
283 50 : Vehicle::getWaitingTime(const std::string& vehID) {
284 50 : return Dom::getDouble(libsumo::VAR_WAITING_TIME, vehID);
285 : }
286 :
287 :
288 : double
289 25 : Vehicle::getAccumulatedWaitingTime(const std::string& vehID) {
290 25 : return Dom::getDouble(libsumo::VAR_ACCUMULATED_WAITING_TIME, vehID);
291 : }
292 :
293 :
294 : double
295 23 : Vehicle::getAdaptedTraveltime(const std::string& vehID, double time, const std::string& edgeID) {
296 23 : tcpip::Storage content;
297 : StoHelp::writeCompound(content, 2);
298 : StoHelp::writeTypedDouble(content, time);
299 : StoHelp::writeTypedString(content, edgeID);
300 46 : return Dom::getDouble(libsumo::VAR_EDGE_TRAVELTIME, vehID, &content);
301 23 : }
302 :
303 :
304 : double
305 22 : Vehicle::getEffort(const std::string& vehID, double time, const std::string& edgeID) {
306 22 : tcpip::Storage content;
307 : StoHelp::writeCompound(content, 2);
308 : StoHelp::writeTypedDouble(content, time);
309 : StoHelp::writeTypedString(content, edgeID);
310 44 : return Dom::getDouble(libsumo::VAR_EDGE_EFFORT, vehID, &content);
311 22 : }
312 :
313 :
314 : bool
315 18 : Vehicle::isRouteValid(const std::string& vehID) {
316 18 : return Dom::getInt(libsumo::VAR_ROUTE_VALID, vehID) != 0;
317 : }
318 :
319 :
320 : std::vector<std::string>
321 1045 : Vehicle::getRoute(const std::string& vehID) {
322 1045 : return Dom::getStringVector(libsumo::VAR_EDGES, vehID);
323 : }
324 :
325 :
326 : int
327 18 : Vehicle::getSignals(const std::string& vehID) {
328 18 : return Dom::getInt(libsumo::VAR_SIGNALS, vehID);
329 : }
330 :
331 :
332 : std::vector<libsumo::TraCIBestLanesData>
333 18 : Vehicle::getBestLanes(const std::string& vehID) {
334 18 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
335 : std::vector<libsumo::TraCIBestLanesData> result;
336 : tcpip::Storage& ret = Dom::get(libsumo::VAR_BEST_LANES, vehID);
337 18 : ret.readInt();
338 36 : StoHelp::readBestLanesVector(ret, result);
339 18 : return result;
340 0 : }
341 :
342 :
343 : std::vector<libsumo::TraCINextTLSData>
344 276 : Vehicle::getNextTLS(const std::string& vehID) {
345 276 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
346 : std::vector<libsumo::TraCINextTLSData> result;
347 : tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_TLS, vehID);
348 273 : ret.readInt(); // components
349 546 : StoHelp::readTLSDataVector(ret, result);
350 273 : return result;
351 3 : }
352 :
353 : std::vector<libsumo::TraCINextStopData>
354 26 : Vehicle::getNextStops(const std::string& vehID) {
355 26 : return getStops(vehID, 0);
356 : }
357 :
358 : std::vector<libsumo::TraCIConnection>
359 1 : Vehicle::getNextLinks(const std::string& vehID) {
360 1 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
361 : std::vector<libsumo::TraCIConnection> result;
362 : tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_LINKS, vehID);
363 1 : ret.readInt(); // components
364 : // number of items
365 1 : const int linkNo = StoHelp::readTypedInt(ret);
366 3 : for (int i = 0; i < linkNo; ++i) {
367 : libsumo::TraCIConnection con;
368 2 : StoHelp::readConnection(ret, con);
369 2 : result.emplace_back(con);
370 2 : }
371 1 : return result;
372 0 : }
373 :
374 : std::vector<libsumo::TraCINextStopData>
375 734 : Vehicle::getStops(const std::string& vehID, int limit) {
376 : std::vector<libsumo::TraCINextStopData> result;
377 734 : tcpip::Storage content;
378 : StoHelp::writeTypedInt(content, limit);
379 734 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
380 : tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_STOPS2, vehID, &content);
381 733 : ret.readInt(); // components
382 1467 : StoHelp::readStopVector(ret, result);
383 733 : return result;
384 735 : }
385 :
386 : std::string
387 91 : Vehicle::getStopParameter(const std::string& vehID, int nextStopIndex, const std::string& param, bool customParam) {
388 91 : tcpip::Storage content;
389 : StoHelp::writeCompound(content, 3);
390 : StoHelp::writeTypedInt(content, nextStopIndex);
391 : StoHelp::writeTypedString(content, param);
392 91 : StoHelp::writeTypedByte(content, customParam);
393 182 : return Dom::getString(libsumo::VAR_STOP_PARAMETER, vehID, &content);
394 91 : }
395 :
396 : int
397 346 : Vehicle::getStopState(const std::string& vehID) {
398 346 : return Dom::getInt(libsumo::VAR_STOPSTATE, vehID);
399 : }
400 :
401 :
402 : double
403 128 : Vehicle::getDistance(const std::string& vehID) {
404 128 : return Dom::getDouble(libsumo::VAR_DISTANCE, vehID);
405 : }
406 :
407 :
408 : double
409 683 : Vehicle::getDrivingDistance(const std::string& vehID, const std::string& edgeID, double pos, int laneIndex) {
410 683 : tcpip::Storage content;
411 : StoHelp::writeCompound(content, 2);
412 683 : content.writeUnsignedByte(libsumo::POSITION_ROADMAP);
413 683 : content.writeString(edgeID);
414 683 : content.writeDouble(pos);
415 683 : content.writeUnsignedByte(laneIndex);
416 683 : content.writeUnsignedByte(libsumo::REQUEST_DRIVINGDIST);
417 1366 : return Dom::getDouble(libsumo::DISTANCE_REQUEST, vehID, &content);
418 683 : }
419 :
420 :
421 : double
422 18 : Vehicle::getDrivingDistance2D(const std::string& vehID, double x, double y) {
423 18 : tcpip::Storage content;
424 : StoHelp::writeCompound(content, 2);
425 18 : content.writeUnsignedByte(libsumo::POSITION_2D);
426 18 : content.writeDouble(x);
427 18 : content.writeDouble(y);
428 18 : content.writeUnsignedByte(libsumo::REQUEST_DRIVINGDIST);
429 36 : return Dom::getDouble(libsumo::DISTANCE_REQUEST, vehID, &content);
430 18 : }
431 :
432 :
433 : double
434 18 : Vehicle::getAllowedSpeed(const std::string& vehID) {
435 18 : return Dom::getDouble(libsumo::VAR_ALLOWED_SPEED, vehID);
436 : }
437 :
438 :
439 : double
440 49 : Vehicle::getSpeedFactor(const std::string& vehID) {
441 49 : return Dom::getDouble(libsumo::VAR_SPEED_FACTOR, vehID);
442 : }
443 :
444 :
445 : int
446 15 : Vehicle::getSpeedMode(const std::string& vehID) {
447 15 : return Dom::getInt(libsumo::VAR_SPEEDSETMODE, vehID);
448 : }
449 :
450 :
451 : int
452 15 : Vehicle::getLaneChangeMode(const std::string& vehID) {
453 15 : return Dom::getInt(libsumo::VAR_LANECHANGE_MODE, vehID);
454 : }
455 :
456 :
457 : int
458 18 : Vehicle::getRoutingMode(const std::string& vehID) {
459 18 : return Dom::getInt(libsumo::VAR_ROUTING_MODE, vehID);
460 : }
461 :
462 :
463 : std::string
464 18 : Vehicle::getLine(const std::string& vehID) {
465 18 : return Dom::getString(libsumo::VAR_LINE, vehID);
466 : }
467 :
468 :
469 :
470 : std::vector<std::string>
471 18 : Vehicle::getVia(const std::string& vehID) {
472 18 : return Dom::getStringVector(libsumo::VAR_VIA, vehID);
473 : }
474 :
475 :
476 : std::pair<int, int>
477 3493 : Vehicle::getLaneChangeState(const std::string& vehID, int direction) {
478 3493 : tcpip::Storage content;
479 : StoHelp::writeTypedInt(content, direction);
480 3493 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
481 : tcpip::Storage& ret = Dom::get(libsumo::CMD_CHANGELANE, vehID, &content);
482 3493 : ret.readInt(); // components
483 3493 : const int stateWithoutTraCI = StoHelp::readTypedInt(ret);
484 6986 : const int state = StoHelp::readTypedInt(ret);
485 3493 : return std::make_pair(stateWithoutTraCI, state);
486 3493 : }
487 :
488 :
489 : std::vector<std::pair<std::string, double> >
490 856 : Vehicle::getNeighbors(const std::string& vehID, const int mode) {
491 : std::vector<std::pair<std::string, double> > neighs;
492 856 : tcpip::Storage content;
493 856 : content.writeUnsignedByte(libsumo::TYPE_UBYTE);
494 856 : content.writeUnsignedByte(mode);
495 856 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
496 : tcpip::Storage& ret = Dom::get(libsumo::VAR_NEIGHBORS, vehID, &content);
497 856 : const int items = ret.readInt(); // components
498 1328 : for (int i = 0; i < items; i++) {
499 472 : const std::string neighID = ret.readString();
500 472 : neighs.emplace_back(neighID, ret.readDouble());
501 : }
502 856 : return neighs;
503 856 : }
504 :
505 :
506 : double
507 177 : Vehicle::getFollowSpeed(const std::string& vehID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
508 177 : tcpip::Storage content;
509 : StoHelp::writeCompound(content, 5);
510 : StoHelp::writeTypedDouble(content, speed);
511 : StoHelp::writeTypedDouble(content, gap);
512 : StoHelp::writeTypedDouble(content, leaderSpeed);
513 : StoHelp::writeTypedDouble(content, leaderMaxDecel);
514 : StoHelp::writeTypedString(content, leaderID);
515 354 : return Dom::getDouble(libsumo::VAR_FOLLOW_SPEED, vehID, &content);
516 177 : }
517 :
518 :
519 : double
520 2 : Vehicle::getSecureGap(const std::string& vehID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
521 2 : tcpip::Storage content;
522 : StoHelp::writeCompound(content, 4);
523 : StoHelp::writeTypedDouble(content, speed);
524 : StoHelp::writeTypedDouble(content, leaderSpeed);
525 : StoHelp::writeTypedDouble(content, leaderMaxDecel);
526 : StoHelp::writeTypedString(content, leaderID);
527 4 : return Dom::getDouble(libsumo::VAR_SECURE_GAP, vehID, &content);
528 2 : }
529 :
530 :
531 : double
532 2 : Vehicle::getStopSpeed(const std::string& vehID, const double speed, double gap) {
533 2 : tcpip::Storage content;
534 : StoHelp::writeCompound(content, 2);
535 : StoHelp::writeTypedDouble(content, speed);
536 : StoHelp::writeTypedDouble(content, gap);
537 4 : return Dom::getDouble(libsumo::VAR_STOP_SPEED, vehID, &content);
538 2 : }
539 :
540 : double
541 125 : Vehicle::getStopDelay(const std::string& vehID) {
542 125 : return Dom::getDouble(libsumo::VAR_STOP_DELAY, vehID);
543 : }
544 :
545 : double
546 125 : Vehicle::getStopArrivalDelay(const std::string& vehID) {
547 125 : return Dom::getDouble(libsumo::VAR_STOP_ARRIVALDELAY, vehID);
548 : }
549 :
550 : double
551 18 : Vehicle::getTimeLoss(const std::string& vehID) {
552 18 : return Dom::getDouble(libsumo::VAR_TIMELOSS, vehID);
553 : }
554 :
555 : std::vector<std::string>
556 1962 : Vehicle::getTaxiFleet(int taxiState) {
557 1962 : tcpip::Storage content;
558 : StoHelp::writeTypedInt(content, taxiState);
559 3924 : return Dom::getStringVector(libsumo::VAR_TAXI_FLEET, "", &content);
560 1962 : }
561 :
562 : std::vector<std::string>
563 46 : Vehicle::getLoadedIDList() {
564 92 : return Dom::getStringVector(libsumo::VAR_LOADED_LIST, "");
565 : }
566 :
567 : std::vector<std::string>
568 36 : Vehicle::getTeleportingIDList() {
569 72 : return Dom::getStringVector(libsumo::VAR_TELEPORTING_LIST, "");
570 : }
571 :
572 : std::string
573 38 : Vehicle::getEmissionClass(const std::string& vehID) {
574 38 : return Dom::getString(libsumo::VAR_EMISSIONCLASS, vehID);
575 : }
576 :
577 : std::string
578 18 : Vehicle::getShapeClass(const std::string& vehID) {
579 18 : return Dom::getString(libsumo::VAR_SHAPECLASS, vehID);
580 : }
581 :
582 :
583 : double
584 20 : Vehicle::getLength(const std::string& vehID) {
585 20 : return Dom::getDouble(libsumo::VAR_LENGTH, vehID);
586 : }
587 :
588 :
589 : double
590 20 : Vehicle::getAccel(const std::string& vehID) {
591 20 : return Dom::getDouble(libsumo::VAR_ACCEL, vehID);
592 : }
593 :
594 :
595 : double
596 201 : Vehicle::getDecel(const std::string& vehID) {
597 201 : return Dom::getDouble(libsumo::VAR_DECEL, vehID);
598 : }
599 :
600 :
601 22 : double Vehicle::getEmergencyDecel(const std::string& vehID) {
602 22 : return Dom::getDouble(libsumo::VAR_EMERGENCY_DECEL, vehID);
603 : }
604 :
605 :
606 20 : double Vehicle::getApparentDecel(const std::string& vehID) {
607 20 : return Dom::getDouble(libsumo::VAR_APPARENT_DECEL, vehID);
608 : }
609 :
610 :
611 20 : double Vehicle::getActionStepLength(const std::string& vehID) {
612 20 : return Dom::getDouble(libsumo::VAR_ACTIONSTEPLENGTH, vehID);
613 : }
614 :
615 :
616 18 : double Vehicle::getLastActionTime(const std::string& vehID) {
617 18 : return Dom::getDouble(libsumo::VAR_LASTACTIONTIME, vehID);
618 : }
619 :
620 :
621 : double
622 20 : Vehicle::getTau(const std::string& vehID) {
623 20 : return Dom::getDouble(libsumo::VAR_TAU, vehID);
624 : }
625 :
626 :
627 : double
628 22 : Vehicle::getImperfection(const std::string& vehID) {
629 22 : return Dom::getDouble(libsumo::VAR_IMPERFECTION, vehID);
630 : }
631 :
632 :
633 : double
634 18 : Vehicle::getSpeedDeviation(const std::string& vehID) {
635 18 : return Dom::getDouble(libsumo::VAR_SPEED_DEVIATION, vehID);
636 : }
637 :
638 :
639 : std::string
640 18 : Vehicle::getVehicleClass(const std::string& vehID) {
641 18 : return Dom::getString(libsumo::VAR_VEHICLECLASS, vehID);
642 : }
643 :
644 :
645 : double
646 59 : Vehicle::getMinGap(const std::string& vehID) {
647 59 : return Dom::getDouble(libsumo::VAR_MINGAP, vehID);
648 : }
649 :
650 :
651 : double
652 18 : Vehicle::getMinGapLat(const std::string& vehID) {
653 18 : return Dom::getDouble(libsumo::VAR_MINGAP_LAT, vehID);
654 : }
655 :
656 :
657 : double
658 20 : Vehicle::getMaxSpeed(const std::string& vehID) {
659 20 : return Dom::getDouble(libsumo::VAR_MAXSPEED, vehID);
660 : }
661 :
662 :
663 : double
664 18 : Vehicle::getMaxSpeedLat(const std::string& vehID) {
665 18 : return Dom::getDouble(libsumo::VAR_MAXSPEED_LAT, vehID);
666 : }
667 :
668 :
669 : std::string
670 18 : Vehicle::getLateralAlignment(const std::string& vehID) {
671 18 : return Dom::getString(libsumo::VAR_LATALIGNMENT, vehID);
672 : }
673 :
674 :
675 : double
676 20 : Vehicle::getWidth(const std::string& vehID) {
677 20 : return Dom::getDouble(libsumo::VAR_WIDTH, vehID);
678 : }
679 :
680 :
681 : double
682 18 : Vehicle::getHeight(const std::string& vehID) {
683 18 : return Dom::getDouble(libsumo::VAR_HEIGHT, vehID);
684 : }
685 :
686 :
687 : double
688 22 : Vehicle::getMass(const std::string& vehID) {
689 22 : return Dom::getDouble(libsumo::VAR_MASS, vehID);
690 : }
691 :
692 :
693 : void
694 43 : Vehicle::setStop(const std::string& vehID,
695 : const std::string& edgeID,
696 : double pos,
697 : int laneIndex,
698 : double duration,
699 : int flags,
700 : double startPos,
701 : double until) {
702 43 : tcpip::Storage content;
703 : StoHelp::writeCompound(content, 7);
704 : StoHelp::writeTypedString(content, edgeID);
705 : StoHelp::writeTypedDouble(content, pos);
706 : StoHelp::writeTypedByte(content, laneIndex);
707 : StoHelp::writeTypedDouble(content, duration);
708 : StoHelp::writeTypedByte(content, flags);
709 : StoHelp::writeTypedDouble(content, startPos);
710 : StoHelp::writeTypedDouble(content, until);
711 43 : Dom::set(libsumo::CMD_STOP, vehID, &content);
712 43 : }
713 :
714 :
715 : void
716 43 : Vehicle::replaceStop(const std::string& vehID,
717 : int nextStopIndex,
718 : const std::string& edgeID,
719 : double pos,
720 : int laneIndex,
721 : double duration,
722 : int flags,
723 : double startPos,
724 : double until,
725 : int teleport) {
726 43 : tcpip::Storage content;
727 : StoHelp::writeCompound(content, 9);
728 : StoHelp::writeTypedString(content, edgeID);
729 : StoHelp::writeTypedDouble(content, pos);
730 : StoHelp::writeTypedByte(content, laneIndex);
731 : StoHelp::writeTypedDouble(content, duration);
732 : StoHelp::writeTypedInt(content, flags);
733 : StoHelp::writeTypedDouble(content, startPos);
734 : StoHelp::writeTypedDouble(content, until);
735 : StoHelp::writeTypedInt(content, nextStopIndex);
736 : StoHelp::writeTypedByte(content, teleport);
737 43 : Dom::set(libsumo::CMD_REPLACE_STOP, vehID, &content);
738 43 : }
739 :
740 :
741 : void
742 28 : Vehicle::insertStop(const std::string& vehID,
743 : int nextStopIndex,
744 : const std::string& edgeID,
745 : double pos,
746 : int laneIndex,
747 : double duration,
748 : int flags,
749 : double startPos,
750 : double until,
751 : int teleport) {
752 28 : tcpip::Storage content;
753 : StoHelp::writeCompound(content, 9);
754 : StoHelp::writeTypedString(content, edgeID);
755 : StoHelp::writeTypedDouble(content, pos);
756 : StoHelp::writeTypedByte(content, laneIndex);
757 : StoHelp::writeTypedDouble(content, duration);
758 : StoHelp::writeTypedInt(content, flags);
759 : StoHelp::writeTypedDouble(content, startPos);
760 : StoHelp::writeTypedDouble(content, until);
761 : StoHelp::writeTypedInt(content, nextStopIndex);
762 : StoHelp::writeTypedByte(content, teleport);
763 28 : Dom::set(libsumo::CMD_INSERT_STOP, vehID, &content);
764 28 : }
765 :
766 :
767 : void
768 35 : Vehicle::setStopParameter(const std::string& vehID, int nextStopIndex,
769 : const std::string& param, const std::string& value,
770 : bool customParam) {
771 35 : tcpip::Storage content;
772 : StoHelp::writeCompound(content, 4);
773 : StoHelp::writeTypedInt(content, nextStopIndex);
774 : StoHelp::writeTypedString(content, param);
775 : StoHelp::writeTypedString(content, value);
776 35 : StoHelp::writeTypedByte(content, customParam);
777 35 : Dom::set(libsumo::VAR_STOP_PARAMETER, vehID, &content);
778 35 : }
779 :
780 :
781 : void
782 3 : Vehicle::rerouteParkingArea(const std::string& vehID, const std::string& parkingAreaID) {
783 3 : tcpip::Storage content;
784 : StoHelp::writeCompound(content, 1);
785 : StoHelp::writeTypedString(content, parkingAreaID);
786 3 : Dom::set(libsumo::CMD_REROUTE_TO_PARKING, vehID, &content);
787 3 : }
788 :
789 :
790 : void
791 2 : Vehicle::resume(const std::string& vehID) {
792 2 : tcpip::Storage content;
793 : StoHelp::writeCompound(content, 0);
794 2 : Dom::set(libsumo::CMD_RESUME, vehID, &content);
795 2 : }
796 :
797 :
798 : void
799 9 : Vehicle::changeTarget(const std::string& vehID, const std::string& edgeID) {
800 9 : Dom::setString(libsumo::CMD_CHANGETARGET, vehID, edgeID);
801 7 : }
802 :
803 :
804 : void
805 2222 : Vehicle::changeLane(const std::string& vehID, int laneIndex, double duration) {
806 2222 : tcpip::Storage content;
807 : StoHelp::writeCompound(content, 2);
808 : StoHelp::writeTypedByte(content, laneIndex);
809 : StoHelp::writeTypedDouble(content, duration);
810 2222 : Dom::set(libsumo::CMD_CHANGELANE, vehID, &content);
811 2222 : }
812 :
813 : void
814 55 : Vehicle::changeLaneRelative(const std::string& vehID, int indexOffset, double duration) {
815 55 : tcpip::Storage content;
816 : StoHelp::writeCompound(content, 3);
817 : StoHelp::writeTypedByte(content, indexOffset);
818 : StoHelp::writeTypedDouble(content, duration);
819 : StoHelp::writeTypedByte(content, 1);
820 55 : Dom::set(libsumo::CMD_CHANGELANE, vehID, &content);
821 55 : }
822 :
823 :
824 : void
825 75 : Vehicle::changeSublane(const std::string& vehID, double latDist) {
826 75 : Dom::setDouble(libsumo::CMD_CHANGESUBLANE, vehID, latDist);
827 75 : }
828 :
829 :
830 : void
831 7479 : Vehicle::add(const std::string& vehID,
832 : const std::string& routeID,
833 : const std::string& typeID,
834 : const std::string& depart,
835 : const std::string& departLane,
836 : const std::string& departPos,
837 : const std::string& departSpeed,
838 : const std::string& arrivalLane,
839 : const std::string& arrivalPos,
840 : const std::string& arrivalSpeed,
841 : const std::string& fromTaz,
842 : const std::string& toTaz,
843 : const std::string& line,
844 : int personCapacity,
845 : int personNumber) {
846 7479 : tcpip::Storage content;
847 : StoHelp::writeCompound(content, 14);
848 : StoHelp::writeTypedString(content, routeID);
849 : StoHelp::writeTypedString(content, typeID);
850 : StoHelp::writeTypedString(content, depart);
851 : StoHelp::writeTypedString(content, departLane);
852 : StoHelp::writeTypedString(content, departPos);
853 : StoHelp::writeTypedString(content, departSpeed);
854 :
855 : StoHelp::writeTypedString(content, arrivalLane);
856 : StoHelp::writeTypedString(content, arrivalPos);
857 : StoHelp::writeTypedString(content, arrivalSpeed);
858 :
859 : StoHelp::writeTypedString(content, fromTaz);
860 : StoHelp::writeTypedString(content, toTaz);
861 : StoHelp::writeTypedString(content, line);
862 :
863 : StoHelp::writeTypedInt(content, personCapacity);
864 : StoHelp::writeTypedInt(content, personNumber);
865 :
866 7479 : Dom::set(libsumo::ADD_FULL, vehID, &content);
867 7479 : }
868 :
869 :
870 : void
871 1015 : Vehicle::moveToXY(const std::string& vehID, const std::string& edgeID, const int laneIndex,
872 : const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
873 1015 : tcpip::Storage content;
874 : StoHelp::writeCompound(content, 7);
875 : StoHelp::writeTypedString(content, edgeID);
876 : StoHelp::writeTypedInt(content, laneIndex);
877 : StoHelp::writeTypedDouble(content, x);
878 : StoHelp::writeTypedDouble(content, y);
879 : StoHelp::writeTypedDouble(content, angle);
880 : StoHelp::writeTypedByte(content, keepRoute);
881 : StoHelp::writeTypedDouble(content, matchThreshold);
882 1015 : Dom::set(libsumo::MOVE_TO_XY, vehID, &content);
883 1015 : }
884 :
885 : void
886 8 : Vehicle::slowDown(const std::string& vehID, double speed, double duration) {
887 8 : tcpip::Storage content;
888 : StoHelp::writeCompound(content, 2);
889 : StoHelp::writeTypedDouble(content, speed);
890 : StoHelp::writeTypedDouble(content, duration);
891 8 : Dom::set(libsumo::CMD_SLOWDOWN, vehID, &content);
892 8 : }
893 :
894 : void
895 17 : Vehicle::openGap(const std::string& vehID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, const std::string& referenceVehID) {
896 17 : tcpip::Storage content;
897 17 : StoHelp::writeCompound(content, referenceVehID != "" ? 6 : 5);
898 : StoHelp::writeTypedDouble(content, newTimeHeadway);
899 : StoHelp::writeTypedDouble(content, newSpaceHeadway);
900 : StoHelp::writeTypedDouble(content, duration);
901 : StoHelp::writeTypedDouble(content, changeRate);
902 : StoHelp::writeTypedDouble(content, maxDecel);
903 17 : if (referenceVehID != "") {
904 : StoHelp::writeTypedString(content, referenceVehID);
905 : }
906 17 : Dom::set(libsumo::CMD_OPENGAP, vehID, &content);
907 17 : }
908 :
909 : void
910 2 : Vehicle::deactivateGapControl(const std::string& vehID) {
911 2 : openGap(vehID, -1, -1, -1, -1);
912 2 : }
913 :
914 : void
915 0 : Vehicle::requestToC(const std::string& vehID, double leadTime) {
916 0 : std::ostringstream oss;
917 : oss.setf(std::ios::fixed, std::ios::floatfield);
918 : oss << std::setprecision(2);
919 : oss << leadTime;
920 0 : setParameter(vehID, "device.toc.requestToC", oss.str());
921 0 : }
922 :
923 : void
924 974 : Vehicle::setSpeed(const std::string& vehID, double speed) {
925 974 : Dom::setDouble(libsumo::VAR_SPEED, vehID, speed);
926 974 : }
927 :
928 : void
929 3 : Vehicle::setAcceleration(const std::string& vehID, double acceleration, double duration) {
930 3 : tcpip::Storage content;
931 : StoHelp::writeCompound(content, 2);
932 : StoHelp::writeTypedDouble(content, acceleration);
933 : StoHelp::writeTypedDouble(content, duration);
934 3 : Dom::set(libsumo::VAR_ACCELERATION, vehID, &content);
935 3 : }
936 :
937 : void
938 49 : Vehicle::setPreviousSpeed(const std::string& vehID, double prevSpeed, double prevAcceleration) {
939 49 : tcpip::Storage content;
940 : StoHelp::writeCompound(content, 2);
941 : StoHelp::writeTypedDouble(content, prevSpeed);
942 : StoHelp::writeTypedDouble(content, prevAcceleration);
943 49 : Dom::set(libsumo::VAR_PREV_SPEED, vehID, &content);
944 49 : }
945 :
946 : void
947 760 : Vehicle::setSpeedMode(const std::string& vehID, int speedMode) {
948 760 : Dom::setInt(libsumo::VAR_SPEEDSETMODE, vehID, speedMode);
949 760 : }
950 :
951 : void
952 108 : Vehicle::setLaneChangeMode(const std::string& vehID, int laneChangeMode) {
953 108 : Dom::setInt(libsumo::VAR_LANECHANGE_MODE, vehID, laneChangeMode);
954 108 : }
955 :
956 : void
957 23 : Vehicle::setRoutingMode(const std::string& vehID, int routingMode) {
958 23 : Dom::setInt(libsumo::VAR_ROUTING_MODE, vehID, routingMode);
959 23 : }
960 :
961 : void
962 74 : Vehicle::setType(const std::string& vehID, const std::string& typeID) {
963 74 : Dom::setString(libsumo::VAR_TYPE, vehID, typeID);
964 74 : }
965 :
966 : void
967 5 : Vehicle::setRouteID(const std::string& vehID, const std::string& routeID) {
968 5 : Dom::setString(libsumo::VAR_ROUTE_ID, vehID, routeID);
969 5 : }
970 :
971 : void
972 1 : Vehicle::setRoute(const std::string& vehID, const std::string& edgeID) {
973 3 : setRoute(vehID, std::vector<std::string>({edgeID}));
974 0 : }
975 :
976 : void
977 7 : Vehicle::setRoute(const std::string& vehID, const std::vector<std::string>& edgeIDs) {
978 7 : Dom::setStringVector(libsumo::VAR_ROUTE, vehID, edgeIDs);
979 6 : }
980 :
981 : void
982 2 : Vehicle::setLateralLanePosition(const std::string& vehID, double posLat) {
983 2 : Dom::setDouble(libsumo::VAR_LANEPOSITION_LAT, vehID, posLat);
984 2 : }
985 :
986 : void
987 56 : Vehicle::updateBestLanes(const std::string& vehID) {
988 56 : tcpip::Storage content;
989 56 : Dom::set(libsumo::VAR_UPDATE_BESTLANES, vehID, &content);
990 56 : }
991 :
992 :
993 : void
994 39 : Vehicle::setAdaptedTraveltime(const std::string& vehID, const std::string& edgeID,
995 : double time, double begSeconds, double endSeconds) {
996 39 : tcpip::Storage content;
997 39 : if (time == libsumo::INVALID_DOUBLE_VALUE) {
998 : // reset
999 : StoHelp::writeCompound(content, 1);
1000 : StoHelp::writeTypedString(content, edgeID);
1001 37 : } else if (begSeconds == libsumo::INVALID_DOUBLE_VALUE) {
1002 : // set value for the whole simulation
1003 : StoHelp::writeCompound(content, 2);
1004 : StoHelp::writeTypedString(content, edgeID);
1005 : StoHelp::writeTypedDouble(content, time);
1006 : } else {
1007 : StoHelp::writeCompound(content, 4);
1008 : StoHelp::writeTypedDouble(content, begSeconds);
1009 : StoHelp::writeTypedDouble(content, endSeconds);
1010 : StoHelp::writeTypedString(content, edgeID);
1011 : StoHelp::writeTypedDouble(content, time);
1012 : }
1013 39 : Dom::set(libsumo::VAR_EDGE_TRAVELTIME, vehID, &content);
1014 39 : }
1015 :
1016 :
1017 : void
1018 6 : Vehicle::setEffort(const std::string& vehID, const std::string& edgeID,
1019 : double effort, double begSeconds, double endSeconds) {
1020 6 : tcpip::Storage content;
1021 6 : if (effort == libsumo::INVALID_DOUBLE_VALUE) {
1022 : // reset
1023 : StoHelp::writeCompound(content, 1);
1024 : StoHelp::writeTypedString(content, edgeID);
1025 4 : } else if (begSeconds == libsumo::INVALID_DOUBLE_VALUE) {
1026 : // set value for the whole simulation
1027 : StoHelp::writeCompound(content, 2);
1028 : StoHelp::writeTypedString(content, edgeID);
1029 : StoHelp::writeTypedDouble(content, effort);
1030 : } else {
1031 : StoHelp::writeCompound(content, 4);
1032 : StoHelp::writeTypedDouble(content, begSeconds);
1033 : StoHelp::writeTypedDouble(content, endSeconds);
1034 : StoHelp::writeTypedString(content, edgeID);
1035 : StoHelp::writeTypedDouble(content, effort);
1036 : }
1037 6 : Dom::set(libsumo::VAR_EDGE_EFFORT, vehID, &content);
1038 6 : }
1039 :
1040 :
1041 : void
1042 73 : Vehicle::rerouteTraveltime(const std::string& vehID, const bool /* currentTravelTimes */) {
1043 73 : tcpip::Storage content;
1044 : StoHelp::writeCompound(content, 0);
1045 73 : Dom::set(libsumo::CMD_REROUTE_TRAVELTIME, vehID, &content);
1046 73 : }
1047 :
1048 :
1049 : void
1050 2 : Vehicle::rerouteEffort(const std::string& vehID) {
1051 2 : tcpip::Storage content;
1052 : StoHelp::writeCompound(content, 0);
1053 2 : Dom::set(libsumo::CMD_REROUTE_EFFORT, vehID, &content);
1054 2 : }
1055 :
1056 :
1057 : void
1058 4 : Vehicle::setSignals(const std::string& vehID, int signals) {
1059 4 : Dom::setInt(libsumo::VAR_SIGNALS, vehID, signals);
1060 4 : }
1061 :
1062 :
1063 : void
1064 102 : Vehicle::moveTo(const std::string& vehID, const std::string& laneID, double pos, int reason) {
1065 102 : tcpip::Storage content;
1066 : StoHelp::writeCompound(content, 3);
1067 : StoHelp::writeTypedString(content, laneID);
1068 : StoHelp::writeTypedDouble(content, pos);
1069 : StoHelp::writeTypedInt(content, reason);
1070 102 : Dom::set(libsumo::VAR_MOVE_TO, vehID, &content);
1071 102 : }
1072 :
1073 :
1074 : void
1075 4 : Vehicle::setActionStepLength(const std::string& vehID, double actionStepLength, bool resetActionOffset) {
1076 : //if (actionStepLength < 0) {
1077 : // raise TraCIException("Invalid value for actionStepLength. Given value must be non-negative.")
1078 : //{
1079 : // Use negative value to indicate resetActionOffset == False
1080 4 : if (!resetActionOffset) {
1081 2 : actionStepLength *= -1;
1082 : }
1083 4 : Dom::setDouble(libsumo::VAR_ACTIONSTEPLENGTH, vehID, actionStepLength);
1084 4 : }
1085 :
1086 :
1087 : void
1088 4 : Vehicle::remove(const std::string& vehID, char reason) {
1089 4 : tcpip::Storage content;
1090 4 : content.writeUnsignedByte(libsumo::TYPE_BYTE);
1091 4 : content.writeUnsignedByte(reason);
1092 4 : Dom::set(libsumo::REMOVE, vehID, &content);
1093 4 : }
1094 :
1095 :
1096 : void
1097 44 : Vehicle::setColor(const std::string& vehID, const libsumo::TraCIColor& color) {
1098 44 : Dom::setCol(libsumo::VAR_COLOR, vehID, color);
1099 44 : }
1100 :
1101 :
1102 : void
1103 2048 : Vehicle::setSpeedFactor(const std::string& vehID, double factor) {
1104 2048 : Dom::setDouble(libsumo::VAR_SPEED_FACTOR, vehID, factor);
1105 2048 : }
1106 :
1107 :
1108 : void
1109 3 : Vehicle::setLine(const std::string& vehID, const std::string& line) {
1110 3 : Dom::setString(libsumo::VAR_LINE, vehID, line);
1111 3 : }
1112 :
1113 :
1114 : void
1115 4 : Vehicle::setVia(const std::string& vehID, const std::vector<std::string>& edgeList) {
1116 4 : Dom::setStringVector(libsumo::VAR_VIA, vehID, edgeList);
1117 4 : }
1118 :
1119 :
1120 : void
1121 23 : Vehicle::setLength(const std::string& vehID, double length) {
1122 23 : Dom::setDouble(libsumo::VAR_LENGTH, vehID, length);
1123 23 : }
1124 :
1125 :
1126 : void
1127 9 : Vehicle::setMaxSpeed(const std::string& vehID, double speed) {
1128 9 : Dom::setDouble(libsumo::VAR_MAXSPEED, vehID, speed);
1129 9 : }
1130 :
1131 :
1132 : void
1133 2 : Vehicle::setVehicleClass(const std::string& vehID, const std::string& clazz) {
1134 2 : Dom::setString(libsumo::VAR_VEHICLECLASS, vehID, clazz);
1135 2 : }
1136 :
1137 :
1138 : void
1139 2 : Vehicle::setShapeClass(const std::string& vehID, const std::string& clazz) {
1140 2 : Dom::setString(libsumo::VAR_SHAPECLASS, vehID, clazz);
1141 2 : }
1142 :
1143 :
1144 : void
1145 5 : Vehicle::setEmissionClass(const std::string& vehID, const std::string& clazz) {
1146 5 : Dom::setString(libsumo::VAR_EMISSIONCLASS, vehID, clazz);
1147 5 : }
1148 :
1149 :
1150 : void
1151 3 : Vehicle::setWidth(const std::string& vehID, double width) {
1152 3 : Dom::setDouble(libsumo::VAR_WIDTH, vehID, width);
1153 3 : }
1154 :
1155 :
1156 : void
1157 2 : Vehicle::setHeight(const std::string& vehID, double height) {
1158 2 : Dom::setDouble(libsumo::VAR_HEIGHT, vehID, height);
1159 2 : }
1160 :
1161 :
1162 : void
1163 2 : Vehicle::setMass(const std::string& vehID, double mass) {
1164 2 : Dom::setDouble(libsumo::VAR_MASS, vehID, mass);
1165 2 : }
1166 :
1167 :
1168 : void
1169 3 : Vehicle::setMinGap(const std::string& vehID, double minGap) {
1170 3 : Dom::setDouble(libsumo::VAR_MINGAP, vehID, minGap);
1171 3 : }
1172 :
1173 :
1174 : void
1175 5 : Vehicle::setAccel(const std::string& vehID, double accel) {
1176 5 : Dom::setDouble(libsumo::VAR_ACCEL, vehID, accel);
1177 5 : }
1178 :
1179 :
1180 : void
1181 3 : Vehicle::setDecel(const std::string& vehID, double decel) {
1182 3 : Dom::setDouble(libsumo::VAR_DECEL, vehID, decel);
1183 3 : }
1184 :
1185 :
1186 : void
1187 5 : Vehicle::setEmergencyDecel(const std::string& vehID, double decel) {
1188 5 : Dom::setDouble(libsumo::VAR_EMERGENCY_DECEL, vehID, decel);
1189 5 : }
1190 :
1191 :
1192 : void
1193 3 : Vehicle::setApparentDecel(const std::string& vehID, double decel) {
1194 3 : Dom::setDouble(libsumo::VAR_APPARENT_DECEL, vehID, decel);
1195 3 : }
1196 :
1197 :
1198 : void
1199 5 : Vehicle::setImperfection(const std::string& vehID, double imperfection) {
1200 5 : Dom::setDouble(libsumo::VAR_IMPERFECTION, vehID, imperfection);
1201 5 : }
1202 :
1203 :
1204 : void
1205 3 : Vehicle::setTau(const std::string& vehID, double tau) {
1206 3 : Dom::setDouble(libsumo::VAR_TAU, vehID, tau);
1207 3 : }
1208 :
1209 :
1210 : void
1211 2 : Vehicle::setMinGapLat(const std::string& vehID, double minGapLat) {
1212 2 : Dom::setDouble(libsumo::VAR_MINGAP_LAT, vehID, minGapLat);
1213 2 : }
1214 :
1215 :
1216 : void
1217 2 : Vehicle::setMaxSpeedLat(const std::string& vehID, double speed) {
1218 2 : Dom::setDouble(libsumo::VAR_MAXSPEED_LAT, vehID, speed);
1219 2 : }
1220 :
1221 :
1222 : void
1223 2 : Vehicle::setLateralAlignment(const std::string& vehID, const std::string& latAlignment) {
1224 2 : Dom::setString(libsumo::VAR_LATALIGNMENT, vehID, latAlignment);
1225 2 : }
1226 :
1227 :
1228 : void
1229 6 : Vehicle::setImpatience(const std::string& vehID, double impatience) {
1230 6 : Dom::setDouble(libsumo::VAR_IMPATIENCE, vehID, impatience);
1231 6 : }
1232 :
1233 : void
1234 2 : Vehicle::setBoardingDuration(const std::string& vehID, double boardingDuration) {
1235 2 : Dom::setDouble(libsumo::VAR_BOARDING_DURATION, vehID, boardingDuration);
1236 2 : }
1237 :
1238 :
1239 : void
1240 10 : Vehicle::highlight(const std::string& vehID, const libsumo::TraCIColor& col, double size, const int alphaMax, const double duration, const int type) {
1241 10 : tcpip::Storage content;
1242 10 : StoHelp::writeCompound(content, alphaMax > 0 ? 5 : 2);
1243 10 : content.writeUnsignedByte(libsumo::TYPE_COLOR);
1244 10 : content.writeUnsignedByte(col.r);
1245 10 : content.writeUnsignedByte(col.g);
1246 10 : content.writeUnsignedByte(col.b);
1247 10 : content.writeUnsignedByte(col.a);
1248 : StoHelp::writeTypedDouble(content, size);
1249 10 : if (alphaMax > 0) {
1250 6 : content.writeUnsignedByte(libsumo::TYPE_UBYTE);
1251 6 : content.writeUnsignedByte(alphaMax);
1252 : StoHelp::writeTypedDouble(content, duration);
1253 6 : content.writeUnsignedByte(libsumo::TYPE_UBYTE);
1254 6 : content.writeUnsignedByte(type);
1255 : }
1256 10 : Dom::set(libsumo::VAR_HIGHLIGHT, vehID, &content);
1257 10 : }
1258 :
1259 : void
1260 36 : Vehicle::dispatchTaxi(const std::string& vehID, const std::vector<std::string>& reservations) {
1261 36 : Dom::setStringVector(libsumo::CMD_TAXI_DISPATCH, vehID, reservations);
1262 31 : }
1263 :
1264 :
1265 : void
1266 17 : Vehicle::subscribeLeader(const std::string& vehID, double dist, double begin, double end) {
1267 17 : subscribe(vehID, std::vector<int>({ libsumo::VAR_LEADER }), begin, end,
1268 51 : libsumo::TraCIResults({ {libsumo::VAR_LEADER, std::make_shared<libsumo::TraCIDouble>(dist)} }));
1269 17 : }
1270 :
1271 :
1272 : void
1273 43 : Vehicle::addSubscriptionFilterLanes(const std::vector<int>& lanes, bool noOpposite, double downstreamDist, double upstreamDist) {
1274 43 : tcpip::Storage content;
1275 43 : content.writeUnsignedByte((int)lanes.size());
1276 115 : for (int lane : lanes) {
1277 72 : content.writeUnsignedByte(lane < 0 ? lane + 256 : lane);
1278 : }
1279 43 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LANES, &content);
1280 43 : if (noOpposite) {
1281 1 : addSubscriptionFilterNoOpposite();
1282 : }
1283 43 : if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1284 2 : addSubscriptionFilterDownstreamDistance(downstreamDist);
1285 : }
1286 43 : if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1287 2 : addSubscriptionFilterUpstreamDistance(upstreamDist);
1288 : }
1289 43 : }
1290 :
1291 :
1292 : void
1293 14 : Vehicle::addSubscriptionFilterNoOpposite() {
1294 14 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_NOOPPOSITE);
1295 14 : }
1296 :
1297 :
1298 : void
1299 51 : Vehicle::addSubscriptionFilterDownstreamDistance(double dist) {
1300 51 : tcpip::Storage content;
1301 : StoHelp::writeTypedDouble(content, dist);
1302 51 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_DOWNSTREAM_DIST, &content);
1303 51 : }
1304 :
1305 :
1306 : void
1307 43 : Vehicle::addSubscriptionFilterUpstreamDistance(double dist) {
1308 43 : tcpip::Storage content;
1309 : StoHelp::writeTypedDouble(content, dist);
1310 43 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_UPSTREAM_DIST, &content);
1311 43 : }
1312 :
1313 :
1314 : void
1315 1 : Vehicle::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) {
1316 1 : addSubscriptionFilterLeadFollow(std::vector<int>(1));
1317 1 : if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1318 0 : addSubscriptionFilterDownstreamDistance(downstreamDist);
1319 : }
1320 1 : if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1321 0 : addSubscriptionFilterUpstreamDistance(upstreamDist);
1322 : }
1323 1 : }
1324 :
1325 :
1326 : void
1327 4 : Vehicle::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) {
1328 4 : if (direction == libsumo::INVALID_INT_VALUE) {
1329 1 : addSubscriptionFilterLeadFollow({ -1, 0, 1 });
1330 3 : } else if (direction != -1 && direction != 1) {
1331 : // warnings.warn("Ignoring lane change subscription filter with non-neighboring lane offset direction=%s." % direction)
1332 : return;
1333 : } else {
1334 3 : addSubscriptionFilterLeadFollow({ 0, direction });
1335 : }
1336 4 : if (noOpposite) {
1337 0 : addSubscriptionFilterNoOpposite();
1338 : }
1339 4 : if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1340 0 : addSubscriptionFilterDownstreamDistance(downstreamDist);
1341 : }
1342 4 : if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1343 0 : addSubscriptionFilterUpstreamDistance(upstreamDist);
1344 : }
1345 : }
1346 :
1347 :
1348 : void
1349 5 : Vehicle::addSubscriptionFilterLeadFollow(const std::vector<int>& lanes) {
1350 5 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LEAD_FOLLOW);
1351 5 : addSubscriptionFilterLanes(lanes);
1352 5 : }
1353 :
1354 :
1355 : void
1356 8 : Vehicle::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) {
1357 8 : tcpip::Storage content;
1358 : StoHelp::writeTypedDouble(content, foeDistToJunction);
1359 8 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_TURN, &content);
1360 8 : if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1361 8 : addSubscriptionFilterDownstreamDistance(downstreamDist);
1362 : }
1363 8 : }
1364 :
1365 :
1366 : void
1367 3 : Vehicle::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) {
1368 3 : tcpip::Storage content;
1369 : StoHelp::writeTypedStringList(content, vClasses);
1370 3 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_VCLASS, &content);
1371 3 : }
1372 :
1373 :
1374 : void
1375 3 : Vehicle::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) {
1376 3 : tcpip::Storage content;
1377 : StoHelp::writeTypedStringList(content, vTypes);
1378 3 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_VTYPE, &content);
1379 3 : }
1380 :
1381 :
1382 : void
1383 8 : Vehicle::addSubscriptionFilterFieldOfVision(double openingAngle) {
1384 8 : tcpip::Storage content;
1385 : StoHelp::writeTypedDouble(content, openingAngle);
1386 8 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_FIELD_OF_VISION, &content);
1387 8 : }
1388 :
1389 :
1390 : void
1391 8 : Vehicle::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) {
1392 8 : tcpip::Storage content;
1393 : StoHelp::writeTypedDouble(content, lateralDist);
1394 8 : libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LATERAL_DIST, &content);
1395 7 : if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1396 7 : addSubscriptionFilterDownstreamDistance(downstreamDist);
1397 : }
1398 7 : if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
1399 7 : addSubscriptionFilterUpstreamDistance(upstreamDist);
1400 : }
1401 8 : }
1402 :
1403 :
1404 : }
1405 :
1406 :
1407 : /****************************************************************************/
|