Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
TraCIAPI.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2026 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/****************************************************************************/
21// C++ TraCI client API implementation
22/****************************************************************************/
23#include "TraCIAPI.h"
24
25
26// ===========================================================================
27// member definitions
28// ===========================================================================
29
30// ---------------------------------------------------------------------------
31// TraCIAPI-methods
32// ---------------------------------------------------------------------------
33#ifdef _MSC_VER
34#pragma warning(push)
35#pragma warning(disable: 4355) // mask warning about "this" in initializers
36#endif
38 edge(*this), gui(*this), inductionloop(*this),
39 junction(*this), lane(*this), lanearea(*this), multientryexit(*this),
40 person(*this), poi(*this), polygon(*this),
41 rerouter(*this), route(*this), routeprobe(*this),
42 simulation(*this), trafficlights(*this),
43 vehicle(*this), vehicletype(*this),
44 mySocket(nullptr) {
45 std::cerr << "TraCIAPI is deprecated. Please use libtraci instead, see https://sumo.dlr.de/docs/Libtraci.html.\n";
62}
63#ifdef _MSC_VER
64#pragma warning(pop)
65#endif
66
68 delete mySocket;
69}
70
71
72void
73TraCIAPI::connect(const std::string& host, int port) {
74 mySocket = new tcpip::Socket(host, port);
75 try {
77 } catch (tcpip::SocketException&) {
78 delete mySocket;
79 mySocket = nullptr;
80 throw;
81 }
82}
83
84
85void
87 tcpip::Storage outMsg;
88 // command length
89 outMsg.writeUnsignedByte(1 + 1 + 4);
90 // command id
92 outMsg.writeInt(order);
93 // send request message
94 mySocket->sendExact(outMsg);
95 tcpip::Storage inMsg;
97}
98
99
100void
103 tcpip::Storage inMsg;
104 std::string acknowledgement;
105 check_resultState(inMsg, libsumo::CMD_CLOSE, false, &acknowledgement);
106 closeSocket();
107}
108
109
110void
112 if (mySocket == nullptr) {
113 return;
114 }
115 mySocket->close();
116 delete mySocket;
117 mySocket = nullptr;
118}
119
120
121void
123 tcpip::Storage outMsg;
124 // command length
125 outMsg.writeUnsignedByte(1 + 1 + 8);
126 // command id
128 outMsg.writeDouble(time);
129 // send request message
130 mySocket->sendExact(outMsg);
131}
132
133
134void
136 tcpip::Storage outMsg;
137 // command length
138 outMsg.writeUnsignedByte(1 + 1);
139 // command id
141 mySocket->sendExact(outMsg);
142}
143
144
145void
147 tcpip::Storage outMsg;
148 // command length
149 outMsg.writeUnsignedByte(1 + 1 + 4);
150 // command id
152 // client index
153 outMsg.writeInt(order);
154 mySocket->sendExact(outMsg);
155}
156
157
158void
159TraCIAPI::createCommand(int cmdID, int varID, const std::string& objID, tcpip::Storage* add) const {
160 myOutput.reset();
161 // command length
162 int length = 1 + 1 + 1 + 4 + (int) objID.length();
163 if (add != nullptr) {
164 length += (int)add->size();
165 }
166 if (length <= 255) {
168 } else {
170 myOutput.writeInt(length + 4);
171 }
174 myOutput.writeString(objID);
175 // additional values
176 if (add != nullptr) {
178 }
179}
180
181
182void
183TraCIAPI::createFilterCommand(int cmdID, int varID, tcpip::Storage* add) const {
184 myOutput.reset();
185 // command length
186 int length = 1 + 1 + 1;
187 if (add != nullptr) {
188 length += (int)add->size();
189 }
190 if (length <= 255) {
192 } else {
194 myOutput.writeInt(length + 4);
195 }
198 // additional values
199 if (add != nullptr) {
201 }
202}
203
204
205void
206TraCIAPI::send_commandSubscribeObjectVariable(int domID, const std::string& objID, double beginTime, double endTime,
207 const std::vector<int>& vars) const {
208 if (mySocket == nullptr) {
209 throw tcpip::SocketException("Socket is not initialised");
210 }
211 tcpip::Storage outMsg;
212 // command length (domID, objID, beginTime, endTime, length, vars)
213 int varNo = (int) vars.size();
214 outMsg.writeUnsignedByte(0);
215 outMsg.writeInt(5 + 1 + 8 + 8 + 4 + (int) objID.length() + 1 + varNo);
216 // command id
217 outMsg.writeUnsignedByte(domID);
218 // time
219 outMsg.writeDouble(beginTime);
220 outMsg.writeDouble(endTime);
221 // object id
222 outMsg.writeString(objID);
223 // command id
224 outMsg.writeUnsignedByte((int)vars.size());
225 for (int i = 0; i < varNo; ++i) {
226 outMsg.writeUnsignedByte(vars[i]);
227 }
228 // send message
229 mySocket->sendExact(outMsg);
230}
231
232
233void
234TraCIAPI::send_commandSubscribeObjectContext(int domID, const std::string& objID, double beginTime, double endTime,
235 int domain, double range, const std::vector<int>& vars) const {
236 if (mySocket == nullptr) {
237 throw tcpip::SocketException("Socket is not initialised");
238 }
239 tcpip::Storage outMsg;
240 // command length (domID, objID, beginTime, endTime, length, vars)
241 int varNo = (int) vars.size();
242 outMsg.writeUnsignedByte(0);
243 outMsg.writeInt(5 + 1 + 8 + 8 + 4 + (int) objID.length() + 1 + 8 + 1 + varNo);
244 // command id
245 outMsg.writeUnsignedByte(domID);
246 // time
247 outMsg.writeDouble(beginTime);
248 outMsg.writeDouble(endTime);
249 // object id
250 outMsg.writeString(objID);
251 // domain and range
252 outMsg.writeUnsignedByte(domain);
253 outMsg.writeDouble(range);
254 // command id
255 outMsg.writeUnsignedByte((int)vars.size());
256 for (int i = 0; i < varNo; ++i) {
257 outMsg.writeUnsignedByte(vars[i]);
258 }
259 // send message
260 mySocket->sendExact(outMsg);
261}
262
263
264void
265TraCIAPI::check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId, std::string* acknowledgement) const {
266 mySocket->receiveExact(inMsg);
267 int cmdLength;
268 int cmdId;
269 int resultType;
270 int cmdStart;
271 std::string msg;
272 try {
273 cmdStart = inMsg.position();
274 cmdLength = inMsg.readUnsignedByte();
275 cmdId = inMsg.readUnsignedByte();
276 if (command != cmdId && !ignoreCommandId) {
277 throw libsumo::TraCIException("#Error: received status response to command: " + toString(cmdId) + " but expected: " + toString(command));
278 }
279 resultType = inMsg.readUnsignedByte();
280 msg = inMsg.readString();
281 } catch (std::invalid_argument&) {
282 throw libsumo::TraCIException("#Error: an exception was thrown while reading result state message");
283 }
284 switch (resultType) {
286 throw libsumo::TraCIException(".. Answered with error to command (" + toString(command) + "), [description: " + msg + "]");
288 throw libsumo::TraCIException(".. Sent command is not implemented (" + toString(command) + "), [description: " + msg + "]");
290 if (acknowledgement != nullptr) {
291 (*acknowledgement) = ".. Command acknowledged (" + toString(command) + "), [description: " + msg + "]";
292 }
293 break;
294 default:
295 throw libsumo::TraCIException(".. Answered with unknown result code(" + toString(resultType) + ") to command(" + toString(command) + "), [description: " + msg + "]");
296 }
297 if ((cmdStart + cmdLength) != (int) inMsg.position()) {
298 throw libsumo::TraCIException("#Error: command at position " + toString(cmdStart) + " has wrong length");
299 }
300}
301
302
303int
304TraCIAPI::check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId) const {
305 inMsg.position(); // respStart
306 int length = inMsg.readUnsignedByte();
307 if (length == 0) {
308 length = inMsg.readInt();
309 }
310 int cmdId = inMsg.readUnsignedByte();
311 if (!ignoreCommandId && cmdId != (command + 0x10)) {
312 throw libsumo::TraCIException("#Error: received response with command id: " + toString(cmdId) + "but expected: " + toString(command + 0x10));
313 }
314 if (expectedType >= 0) {
315 // not called from the TraCITestClient but from within the TraCIAPI
316 inMsg.readUnsignedByte(); // variableID
317 inMsg.readString(); // objectID
318 int valueDataType = inMsg.readUnsignedByte();
319 if (valueDataType != expectedType) {
320 throw libsumo::TraCIException("Expected " + toString(expectedType) + " but got " + toString(valueDataType));
321 }
322 }
323 return cmdId;
324}
325
326
327bool
328TraCIAPI::processGet(int command, int expectedType, bool ignoreCommandId) {
329 if (mySocket != nullptr) {
331 myInput.reset();
332 check_resultState(myInput, command, ignoreCommandId);
333 check_commandGetResult(myInput, command, expectedType, ignoreCommandId);
334 return true;
335 }
336 return false;
337}
338
339
340bool
342 if (mySocket != nullptr) {
344 myInput.reset();
345 check_resultState(myInput, command);
346 return true;
347 }
348 return false;
349}
350
351
352void
353TraCIAPI::readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, libsumo::SubscriptionResults& into) {
354 while (variableCount > 0) {
355
356 const int variableID = inMsg.readUnsignedByte();
357 const int status = inMsg.readUnsignedByte();
358 const int type = inMsg.readUnsignedByte();
359
360 if (status == libsumo::RTYPE_OK) {
361 switch (type) {
363 into[objectID][variableID] = std::make_shared<libsumo::TraCIDouble>(inMsg.readDouble());
364 break;
366 into[objectID][variableID] = std::make_shared<libsumo::TraCIString>(inMsg.readString());
367 break;
369 auto p = std::make_shared<libsumo::TraCIPosition>();
370 p->x = inMsg.readDouble();
371 p->y = inMsg.readDouble();
372 p->z = 0.;
373 into[objectID][variableID] = p;
374 break;
375 }
377 auto p = std::make_shared<libsumo::TraCIPosition>();
378 p->x = inMsg.readDouble();
379 p->y = inMsg.readDouble();
380 p->z = inMsg.readDouble();
381 into[objectID][variableID] = p;
382 break;
383 }
384 case libsumo::TYPE_COLOR: {
385 auto c = std::make_shared<libsumo::TraCIColor>();
386 c->r = (unsigned char)inMsg.readUnsignedByte();
387 c->g = (unsigned char)inMsg.readUnsignedByte();
388 c->b = (unsigned char)inMsg.readUnsignedByte();
389 c->a = (unsigned char)inMsg.readUnsignedByte();
390 into[objectID][variableID] = c;
391 break;
392 }
394 into[objectID][variableID] = std::make_shared<libsumo::TraCIInt>(inMsg.readInt());
395 break;
397 auto sl = std::make_shared<libsumo::TraCIStringList>();
398 int n = inMsg.readInt();
399 for (int i = 0; i < n; ++i) {
400 sl->value.push_back(inMsg.readString());
401 }
402 into[objectID][variableID] = sl;
403 }
404 break;
405
406 // TODO Other data types
407
408 default:
409 throw libsumo::TraCIException("Unimplemented subscription type: " + toString(type));
410 }
411 } else {
412 throw libsumo::TraCIException("Subscription response error: variableID=" + toString(variableID) + " status=" + toString(status));
413 }
414
415 variableCount--;
416 }
417}
418
419
420void
422 const std::string objectID = inMsg.readString();
423 const int variableCount = inMsg.readUnsignedByte();
424 readVariables(inMsg, objectID, variableCount, myDomains[cmdId]->getModifiableSubscriptionResults());
425}
426
427
428void
430 const std::string contextID = inMsg.readString();
431 inMsg.readUnsignedByte(); // context domain
432 const int variableCount = inMsg.readUnsignedByte();
433 int numObjects = inMsg.readInt();
434
435 while (numObjects > 0) {
436 std::string objectID = inMsg.readString();
437 readVariables(inMsg, objectID, variableCount, myDomains[cmdId]->getModifiableContextSubscriptionResults(contextID));
438 numObjects--;
439 }
440}
441
442
443void
446 tcpip::Storage inMsg;
448
449 for (auto it : myDomains) {
450 it.second->clearSubscriptionResults();
451 }
452 int numSubs = inMsg.readInt();
453 while (numSubs > 0) {
454 int cmdId = check_commandGetResult(inMsg, 0, -1, true);
456 readVariableSubscription(cmdId, inMsg);
457 } else {
458 readContextSubscription(cmdId + 0x50, inMsg);
459 }
460 numSubs--;
461 }
462}
463
464
465void
466TraCIAPI::load(const std::vector<std::string>& args) {
467 int numChars = 0;
468 for (int i = 0; i < (int)args.size(); ++i) {
469 numChars += (int)args[i].size();
470 }
471 tcpip::Storage content;
472 content.writeUnsignedByte(0);
473 content.writeInt(1 + 4 + 1 + 1 + 4 + numChars + 4 * (int)args.size());
476 content.writeStringList(args);
477 mySocket->sendExact(content);
478 tcpip::Storage inMsg;
480}
481
482
483std::pair<int, std::string>
485 tcpip::Storage content;
486 content.writeUnsignedByte(2);
488 mySocket->sendExact(content);
489 tcpip::Storage inMsg;
491 inMsg.readUnsignedByte(); // msg length
492 inMsg.readUnsignedByte(); // libsumo::CMD_GETVERSION again, see #7284
493 const int traciVersion = inMsg.readInt(); // to fix evaluation order
494 return std::make_pair(traciVersion, inMsg.readString());
495}
496
497
498// ---------------------------------------------------------------------------
499// TraCIAPI::EdgeScope-methods
500// ---------------------------------------------------------------------------
501double
502TraCIAPI::EdgeScope::getAdaptedTraveltime(const std::string& edgeID, double time) const {
503 tcpip::Storage content;
505 content.writeDouble(time);
506 return getDouble(libsumo::VAR_EDGE_TRAVELTIME, edgeID, &content);
507}
508
509double
510TraCIAPI::EdgeScope::getEffort(const std::string& edgeID, double time) const {
511 tcpip::Storage content;
513 content.writeDouble(time);
514 return getDouble(libsumo::VAR_EDGE_EFFORT, edgeID, &content);
515}
516
517double
518TraCIAPI::EdgeScope::getCO2Emission(const std::string& edgeID) const {
519 return getDouble(libsumo::VAR_CO2EMISSION, edgeID);
520}
521
522
523double
524TraCIAPI::EdgeScope::getCOEmission(const std::string& edgeID) const {
525 return getDouble(libsumo::VAR_COEMISSION, edgeID);
526}
527
528double
529TraCIAPI::EdgeScope::getHCEmission(const std::string& edgeID) const {
530 return getDouble(libsumo::VAR_HCEMISSION, edgeID);
531}
532
533double
534TraCIAPI::EdgeScope::getPMxEmission(const std::string& edgeID) const {
535 return getDouble(libsumo::VAR_PMXEMISSION, edgeID);
536}
537
538double
539TraCIAPI::EdgeScope::getNOxEmission(const std::string& edgeID) const {
540 return getDouble(libsumo::VAR_NOXEMISSION, edgeID);
541}
542
543double
544TraCIAPI::EdgeScope::getFuelConsumption(const std::string& edgeID) const {
545 return getDouble(libsumo::VAR_FUELCONSUMPTION, edgeID);
546}
547
548double
549TraCIAPI::EdgeScope::getNoiseEmission(const std::string& edgeID) const {
550 return getDouble(libsumo::VAR_NOISEEMISSION, edgeID);
551}
552
553double
554TraCIAPI::EdgeScope::getElectricityConsumption(const std::string& edgeID) const {
555 return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, edgeID);
556}
557
558double
559TraCIAPI::EdgeScope::getLastStepMeanSpeed(const std::string& edgeID) const {
560 return getDouble(libsumo::LAST_STEP_MEAN_SPEED, edgeID);
561}
562
563double
564TraCIAPI::EdgeScope::getMaxSpeed(const std::string& edgeID) const {
565 return getDouble(libsumo::VAR_MAXSPEED, edgeID);
566}
567
568double
569TraCIAPI::EdgeScope::getLastStepOccupancy(const std::string& edgeID) const {
570 return getDouble(libsumo::LAST_STEP_OCCUPANCY, edgeID);
571}
572
573double
574TraCIAPI::EdgeScope::getLastStepLength(const std::string& edgeID) const {
575 return getDouble(libsumo::LAST_STEP_LENGTH, edgeID);
576}
577
578double
579TraCIAPI::EdgeScope::getTraveltime(const std::string& edgeID) const {
580 return getDouble(libsumo::VAR_CURRENT_TRAVELTIME, edgeID);
581}
582
583int
584TraCIAPI::EdgeScope::getLastStepVehicleNumber(const std::string& edgeID) const {
585 return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, edgeID);
586}
587
588double
589TraCIAPI::EdgeScope::getLastStepHaltingNumber(const std::string& edgeID) const {
590 return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, edgeID);
591}
592
593std::vector<std::string>
594TraCIAPI::EdgeScope::getLastStepVehicleIDs(const std::string& edgeID) const {
595 return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, edgeID);
596}
597
598
599int
600TraCIAPI::EdgeScope::getLaneNumber(const std::string& edgeID) const {
601 return getInt(libsumo::VAR_LANE_INDEX, edgeID);
602}
603
604
605std::string
606TraCIAPI::EdgeScope::getStreetName(const std::string& edgeID) const {
607 return getString(libsumo::VAR_NAME, edgeID);
608}
609
610
611void
612TraCIAPI::EdgeScope::adaptTraveltime(const std::string& edgeID, double time, double beginSeconds, double endSeconds) const {
613 tcpip::Storage content;
615 if (endSeconds != std::numeric_limits<double>::max()) {
616 content.writeInt(3);
618 content.writeDouble(beginSeconds);
620 content.writeDouble(endSeconds);
621 } else {
622 content.writeInt(1);
623 }
625 content.writeDouble(time);
626 myParent.createCommand(libsumo::CMD_SET_EDGE_VARIABLE, libsumo::VAR_EDGE_TRAVELTIME, edgeID, &content);
627 myParent.processSet(libsumo::CMD_SET_EDGE_VARIABLE);
628}
629
630
631void
632TraCIAPI::EdgeScope::setEffort(const std::string& edgeID, double effort, double beginSeconds, double endSeconds) const {
633 tcpip::Storage content;
635 if (endSeconds != std::numeric_limits<double>::max()) {
636 content.writeInt(3);
638 content.writeDouble(beginSeconds);
640 content.writeDouble(endSeconds);
641 } else {
642 content.writeInt(1);
643 }
645 content.writeDouble(effort);
646 myParent.createCommand(libsumo::CMD_SET_EDGE_VARIABLE, libsumo::VAR_EDGE_EFFORT, edgeID, &content);
647 myParent.processSet(libsumo::CMD_SET_EDGE_VARIABLE);
648}
649
650void
651TraCIAPI::EdgeScope::setMaxSpeed(const std::string& edgeID, double speed) const {
652 setDouble(libsumo::VAR_MAXSPEED, edgeID, speed);
653}
654
655
656// ---------------------------------------------------------------------------
657// TraCIAPI::GUIScope-methods
658// ---------------------------------------------------------------------------
659double
660TraCIAPI::GUIScope::getZoom(const std::string& viewID) const {
661 return getDouble(libsumo::VAR_VIEW_ZOOM, viewID);
662}
663
665TraCIAPI::GUIScope::getOffset(const std::string& viewID) const {
666 return getPos(libsumo::VAR_VIEW_OFFSET, viewID);
667}
668
669std::string
670TraCIAPI::GUIScope::getSchema(const std::string& viewID) const {
671 return getString(libsumo::VAR_VIEW_SCHEMA, viewID);
672}
673
675TraCIAPI::GUIScope::getBoundary(const std::string& viewID) const {
676 return getPolygon(libsumo::VAR_VIEW_BOUNDARY, viewID);
677}
678
679
680void
681TraCIAPI::GUIScope::setZoom(const std::string& viewID, double zoom) const {
682 setDouble(libsumo::VAR_VIEW_ZOOM, viewID, zoom);
683}
684
685void
686TraCIAPI::GUIScope::setOffset(const std::string& viewID, double x, double y) const {
687 tcpip::Storage content;
689 content.writeDouble(x);
690 content.writeDouble(y);
691 myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_VIEW_OFFSET, viewID, &content);
692 myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
693}
694
695void
696TraCIAPI::GUIScope::setSchema(const std::string& viewID, const std::string& schemeName) const {
697 setString(libsumo::VAR_VIEW_SCHEMA, viewID, schemeName);
698}
699
700void
701TraCIAPI::GUIScope::setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const {
702 tcpip::Storage content;
704 content.writeByte(2);
705 content.writeDouble(xmin);
706 content.writeDouble(ymin);
707 content.writeDouble(xmax);
708 content.writeDouble(ymax);
709 myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_VIEW_BOUNDARY, viewID, &content);
710 myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
711}
712
713void
714TraCIAPI::GUIScope::screenshot(const std::string& viewID, const std::string& filename, const int width, const int height) const {
715 tcpip::Storage content;
717 content.writeInt(3);
719 content.writeString(filename);
721 content.writeInt(width);
723 content.writeInt(height);
724 myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_SCREENSHOT, viewID, &content);
725 myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
726}
727
728void
729TraCIAPI::GUIScope::trackVehicle(const std::string& viewID, const std::string& vehID) const {
730 setString(libsumo::VAR_VIEW_SCHEMA, viewID, vehID);
731}
732
733
734// ---------------------------------------------------------------------------
735// TraCIAPI::InductionLoopScope-methods
736// ---------------------------------------------------------------------------
737
738int TraCIAPI::InductionLoopScope::getIntervalVehicleNumber(const std::string& loopID) const {
739 return getInt(libsumo::VAR_LAST_INTERVAL_NUMBER, loopID);
740}
741
742double
743TraCIAPI::InductionLoopScope::getPosition(const std::string& loopID) const {
744 return getDouble(libsumo::VAR_POSITION, loopID);
745}
746
747std::string
748TraCIAPI::InductionLoopScope::getLaneID(const std::string& loopID) const {
749 return getString(libsumo::VAR_LANE_ID, loopID);
750}
751
752int
754 return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, loopID);
755}
756
757double
759 return getDouble(libsumo::LAST_STEP_MEAN_SPEED, loopID);
760}
761
762std::vector<std::string>
764 return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, loopID);
765}
766
767double
769 return getDouble(libsumo::LAST_STEP_OCCUPANCY, loopID);
770}
771
772double
774 return getDouble(libsumo::LAST_STEP_LENGTH, loopID);
775}
776
777double
779 return getDouble(libsumo::LAST_STEP_TIME_SINCE_DETECTION, loopID);
780}
781
782
783std::vector<libsumo::TraCIVehicleData>
784TraCIAPI::InductionLoopScope::getVehicleData(const std::string& loopID) const {
785 std::vector<libsumo::TraCIVehicleData> result;
788 myParent.myInput.readInt(); // components
789 // number of items
790 myParent.myInput.readUnsignedByte();
791 const int n = myParent.myInput.readInt();
792 for (int i = 0; i < n; ++i) {
794
795 myParent.myInput.readUnsignedByte();
796 vd.id = myParent.myInput.readString();
797
798 myParent.myInput.readUnsignedByte();
799 vd.length = myParent.myInput.readDouble();
800
801 myParent.myInput.readUnsignedByte();
802 vd.entryTime = myParent.myInput.readDouble();
803
804 myParent.myInput.readUnsignedByte();
805 vd.leaveTime = myParent.myInput.readDouble();
806
807 myParent.myInput.readUnsignedByte();
808 vd.typeID = myParent.myInput.readString();
809
810 result.push_back(vd);
811 }
812 }
813 return result;
814}
815
816
817// ---------------------------------------------------------------------------
818// TraCIAPI::JunctionScope-methods
819// ---------------------------------------------------------------------------
821TraCIAPI::JunctionScope::getPosition(const std::string& junctionID) const {
822 return getPos(libsumo::VAR_POSITION, junctionID);
823}
824
826TraCIAPI::JunctionScope::getShape(const std::string& junctionID) const {
827 return getPolygon(libsumo::VAR_SHAPE, junctionID);
828}
829
830
831// ---------------------------------------------------------------------------
832// TraCIAPI::LaneScope-methods
833// ---------------------------------------------------------------------------
834double
835TraCIAPI::LaneScope::getLength(const std::string& laneID) const {
836 return getDouble(libsumo::VAR_LENGTH, laneID);
837}
838
839double
840TraCIAPI::LaneScope::getMaxSpeed(const std::string& laneID) const {
841 return getDouble(libsumo::VAR_MAXSPEED, laneID);
842}
843
844double
845TraCIAPI::LaneScope::getWidth(const std::string& laneID) const {
846 return getDouble(libsumo::VAR_WIDTH, laneID);
847}
848
849std::vector<std::string>
850TraCIAPI::LaneScope::getAllowed(const std::string& laneID) const {
851 return getStringVector(libsumo::LANE_ALLOWED, laneID);
852}
853
854std::vector<std::string>
855TraCIAPI::LaneScope::getDisallowed(const std::string& laneID) const {
856 return getStringVector(libsumo::LANE_DISALLOWED, laneID);
857}
858
859int
860TraCIAPI::LaneScope::getLinkNumber(const std::string& laneID) const {
861 return getInt(libsumo::LANE_LINK_NUMBER, laneID);
862}
863
864std::vector<libsumo::TraCIConnection>
865TraCIAPI::LaneScope::getLinks(const std::string& laneID) const {
866 std::vector<libsumo::TraCIConnection> ret;
867 myParent.createCommand(libsumo::CMD_GET_LANE_VARIABLE, libsumo::LANE_LINKS, laneID);
868 if (myParent.processGet(libsumo::CMD_GET_LANE_VARIABLE, libsumo::TYPE_COMPOUND)) {
869 myParent.myInput.readUnsignedByte();
870 myParent.myInput.readInt();
871
872 int linkNo = myParent.myInput.readInt();
873 for (int i = 0; i < linkNo; ++i) {
874
875 myParent.myInput.readUnsignedByte();
876 std::string approachedLane = myParent.myInput.readString();
877
878 myParent.myInput.readUnsignedByte();
879 std::string approachedLaneInternal = myParent.myInput.readString();
880
881 myParent.myInput.readUnsignedByte();
882 bool hasPrio = myParent.myInput.readUnsignedByte() != 0;
883
884 myParent.myInput.readUnsignedByte();
885 bool isOpen = myParent.myInput.readUnsignedByte() != 0;
886
887 myParent.myInput.readUnsignedByte();
888 bool hasFoe = myParent.myInput.readUnsignedByte() != 0;
889
890 myParent.myInput.readUnsignedByte();
891 std::string state = myParent.myInput.readString();
892
893 myParent.myInput.readUnsignedByte();
894 std::string direction = myParent.myInput.readString();
895
896 myParent.myInput.readUnsignedByte();
897 double length = myParent.myInput.readDouble();
898
899 ret.push_back(libsumo::TraCIConnection(approachedLane,
900 hasPrio,
901 isOpen,
902 hasFoe,
903 approachedLaneInternal,
904 state,
905 direction,
906 length));
907
908 }
909
910 }
911 return ret;
912}
913
915TraCIAPI::LaneScope::getShape(const std::string& laneID) const {
916 return getPolygon(libsumo::VAR_SHAPE, laneID);
917}
918
919std::string
920TraCIAPI::LaneScope::getEdgeID(const std::string& laneID) const {
921 return getString(libsumo::LANE_EDGE_ID, laneID);
922}
923
924double
925TraCIAPI::LaneScope::getCO2Emission(const std::string& laneID) const {
926 return getDouble(libsumo::VAR_CO2EMISSION, laneID);
927}
928
929double
930TraCIAPI::LaneScope::getCOEmission(const std::string& laneID) const {
931 return getDouble(libsumo::VAR_COEMISSION, laneID);
932}
933
934double
935TraCIAPI::LaneScope::getHCEmission(const std::string& laneID) const {
936 return getDouble(libsumo::VAR_HCEMISSION, laneID);
937}
938
939double
940TraCIAPI::LaneScope::getPMxEmission(const std::string& laneID) const {
941 return getDouble(libsumo::VAR_PMXEMISSION, laneID);
942}
943
944double
945TraCIAPI::LaneScope::getNOxEmission(const std::string& laneID) const {
946 return getDouble(libsumo::VAR_NOXEMISSION, laneID);
947}
948
949double
950TraCIAPI::LaneScope::getFuelConsumption(const std::string& laneID) const {
951 return getDouble(libsumo::VAR_FUELCONSUMPTION, laneID);
952}
953
954double
955TraCIAPI::LaneScope::getNoiseEmission(const std::string& laneID) const {
956 return getDouble(libsumo::VAR_NOISEEMISSION, laneID);
957}
958
959double
960TraCIAPI::LaneScope::getElectricityConsumption(const std::string& laneID) const {
961 return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, laneID);
962}
963
964double
965TraCIAPI::LaneScope::getLastStepMeanSpeed(const std::string& laneID) const {
966 return getDouble(libsumo::LAST_STEP_MEAN_SPEED, laneID);
967}
968
969double
970TraCIAPI::LaneScope::getLastStepOccupancy(const std::string& laneID) const {
971 return getDouble(libsumo::LAST_STEP_OCCUPANCY, laneID);
972}
973
974double
975TraCIAPI::LaneScope::getLastStepLength(const std::string& laneID) const {
976 return getDouble(libsumo::LAST_STEP_LENGTH, laneID);
977}
978
979double
980TraCIAPI::LaneScope::getTraveltime(const std::string& laneID) const {
981 return getDouble(libsumo::VAR_CURRENT_TRAVELTIME, laneID);
982}
983
984int
985TraCIAPI::LaneScope::getLastStepVehicleNumber(const std::string& laneID) const {
986 return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, laneID);
987}
988
989int
990TraCIAPI::LaneScope::getLastStepHaltingNumber(const std::string& laneID) const {
991 return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, laneID);
992}
993
994std::vector<std::string>
995TraCIAPI::LaneScope::getLastStepVehicleIDs(const std::string& laneID) const {
996 return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, laneID);
997}
998
999
1000std::vector<std::string>
1001TraCIAPI::LaneScope::getFoes(const std::string& laneID, const std::string& toLaneID) const {
1002 std::vector<std::string> r;
1003 tcpip::Storage content;
1005 content.writeString(toLaneID);
1006 myParent.createCommand(libsumo::CMD_GET_LANE_VARIABLE, libsumo::VAR_FOES, laneID, &content);
1007 if (myParent.processGet(libsumo::CMD_GET_LANE_VARIABLE, libsumo::TYPE_STRINGLIST)) {
1008 const int size = myParent.myInput.readInt();
1009 for (int i = 0; i < size; ++i) {
1010 r.push_back(myParent.myInput.readString());
1011 }
1012 }
1013 return r;
1014}
1015
1016std::vector<std::string>
1017TraCIAPI::LaneScope::getInternalFoes(const std::string& laneID) const {
1018 return getFoes(laneID, "");
1019}
1020
1021
1022void
1023TraCIAPI::LaneScope::setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const {
1024 setStringVector(libsumo::LANE_ALLOWED, laneID, allowedClasses);
1025}
1026
1027void
1028TraCIAPI::LaneScope::setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const {
1029 setStringVector(libsumo::LANE_DISALLOWED, laneID, disallowedClasses);
1030}
1031
1032void
1033TraCIAPI::LaneScope::setMaxSpeed(const std::string& laneID, double speed) const {
1034 setDouble(libsumo::VAR_MAXSPEED, laneID, speed);
1035}
1036
1037void
1038TraCIAPI::LaneScope::setLength(const std::string& laneID, double length) const {
1039 setDouble(libsumo::VAR_LENGTH, laneID, length);
1040}
1041
1042
1043// ---------------------------------------------------------------------------
1044// TraCIAPI::LaneAreaDetector-methods
1045// ---------------------------------------------------------------------------
1046
1047
1048// ---------------------------------------------------------------------------
1049// TraCIAPI::MeMeScope-methods
1050// ---------------------------------------------------------------------------
1051int
1052TraCIAPI::MeMeScope::getLastStepVehicleNumber(const std::string& detID) const {
1053 return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, detID);
1054}
1055
1056double
1057TraCIAPI::MeMeScope::getLastStepMeanSpeed(const std::string& detID) const {
1058 return getDouble(libsumo::LAST_STEP_MEAN_SPEED, detID);
1059}
1060
1061std::vector<std::string>
1062TraCIAPI::MeMeScope::getLastStepVehicleIDs(const std::string& detID) const {
1063 return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, detID);
1064}
1065
1066int
1067TraCIAPI::MeMeScope::getLastStepHaltingNumber(const std::string& detID) const {
1068 return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, detID);
1069}
1070
1071std::vector<std::string>
1072TraCIAPI::MeMeScope::getEntryLanes(const std::string& detID) const {
1073 return getStringVector(libsumo::VAR_LANES, detID);
1074}
1075
1076std::vector<std::string>
1077TraCIAPI::MeMeScope::getExitLanes(const std::string& detID) const {
1078 return getStringVector(libsumo::VAR_EXIT_LANES, detID);
1079}
1080
1081std::vector<double>
1082TraCIAPI::MeMeScope::getEntryPositions(const std::string& detID) const {
1083 return getDoubleVector(libsumo::VAR_POSITION, detID);
1084}
1085
1086std::vector<double>
1087TraCIAPI::MeMeScope::getExitPositions(const std::string& detID) const {
1088 return getDoubleVector(libsumo::VAR_EXIT_POSITIONS, detID);
1089}
1090
1091// ---------------------------------------------------------------------------
1092// TraCIAPI::POIScope-methods
1093// ---------------------------------------------------------------------------
1094std::string
1095TraCIAPI::POIScope::getType(const std::string& poiID) const {
1096 return getString(libsumo::VAR_TYPE, poiID);
1097}
1098
1100TraCIAPI::POIScope::getPosition(const std::string& poiID) const {
1101 return getPos(libsumo::VAR_POSITION, poiID);
1102}
1103
1105TraCIAPI::POIScope::getColor(const std::string& poiID) const {
1106 return getCol(libsumo::VAR_COLOR, poiID);
1107}
1108
1109double
1110TraCIAPI::POIScope::getWidth(const std::string& poiID) const {
1111 return getDouble(libsumo::VAR_WIDTH, poiID);
1112}
1113
1114double
1115TraCIAPI::POIScope::getHeight(const std::string& poiID) const {
1116 return getDouble(libsumo::VAR_HEIGHT, poiID);
1117}
1118
1119double
1120TraCIAPI::POIScope::getAngle(const std::string& poiID) const {
1121 return getDouble(libsumo::VAR_ANGLE, poiID);
1122}
1123
1124std::string
1125TraCIAPI::POIScope::getImageFile(const std::string& poiID) const {
1126 return getString(libsumo::VAR_IMAGEFILE, poiID);
1127}
1128
1129
1130void
1131TraCIAPI::POIScope::setType(const std::string& poiID, const std::string& setType) const {
1132 setString(libsumo::VAR_TYPE, poiID, setType);
1133}
1134
1135
1136void
1137TraCIAPI::POIScope::setPosition(const std::string& poiID, double x, double y) const {
1138 tcpip::Storage content;
1140 content.writeDouble(x);
1141 content.writeDouble(y);
1142 myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::VAR_POSITION, poiID, &content);
1143 myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1144}
1145
1146
1147void
1148TraCIAPI::POIScope::setColor(const std::string& poiID, const libsumo::TraCIColor& c) const {
1149 tcpip::Storage content;
1151 content.writeUnsignedByte(c.r);
1152 content.writeUnsignedByte(c.g);
1153 content.writeUnsignedByte(c.b);
1154 content.writeUnsignedByte(c.a);
1155 myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::VAR_COLOR, poiID, &content);
1156 myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1157}
1158
1159
1160void
1161TraCIAPI::POIScope::setWidth(const std::string& poiID, double width) const {
1162 setDouble(libsumo::VAR_WIDTH, poiID, width);
1163}
1164
1165
1166void
1167TraCIAPI::POIScope::setHeight(const std::string& poiID, double height) const {
1168 setDouble(libsumo::VAR_HEIGHT, poiID, height);
1169}
1170
1171
1172void
1173TraCIAPI::POIScope::setAngle(const std::string& poiID, double angle) const {
1174 setDouble(libsumo::VAR_ANGLE, poiID, angle);
1175}
1176
1177
1178void
1179TraCIAPI::POIScope::setImageFile(const std::string& poiID, const std::string& imageFile) const {
1180 setString(libsumo::VAR_IMAGEFILE, poiID, imageFile);
1181}
1182
1183
1184void
1185TraCIAPI::POIScope::add(const std::string& poiID, double x, double y, const libsumo::TraCIColor& c, const std::string& type, int layer, const std::string& imgFile, double width, double height, double angle) const {
1186 tcpip::Storage content;
1188 content.writeInt(8);
1190 content.writeString(type);
1192 content.writeUnsignedByte(c.r);
1193 content.writeUnsignedByte(c.g);
1194 content.writeUnsignedByte(c.b);
1195 content.writeUnsignedByte(c.a);
1197 content.writeInt(layer);
1199 content.writeDouble(x);
1200 content.writeDouble(y);
1202 content.writeString(imgFile);
1204 content.writeDouble(width);
1206 content.writeDouble(height);
1208 content.writeDouble(angle);
1209 myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::ADD, poiID, &content);
1210 myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1211}
1212
1213void
1214TraCIAPI::POIScope::remove(const std::string& poiID, int layer) const {
1215 tcpip::Storage content;
1217 content.writeInt(layer);
1218 myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::REMOVE, poiID, &content);
1219 myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1220}
1221
1222
1223// ---------------------------------------------------------------------------
1224// TraCIAPI::PolygonScope-methods
1225// ---------------------------------------------------------------------------
1226double
1227TraCIAPI::PolygonScope::getLineWidth(const std::string& polygonID) const {
1228 return getDouble(libsumo::VAR_WIDTH, polygonID);
1229}
1230
1231double
1232TraCIAPI::PolygonScope::getHeight(const std::string& polygonID) const {
1233 return getDouble(libsumo::VAR_HEIGHT, polygonID);
1234}
1235
1236bool
1237TraCIAPI::PolygonScope::getFilled(const std::string& polygonID) const {
1238 return getInt(libsumo::VAR_FILL, polygonID) != 0;
1239}
1240
1241std::string
1242TraCIAPI::PolygonScope::getType(const std::string& polygonID) const {
1243 return getString(libsumo::VAR_TYPE, polygonID);
1244}
1245
1247TraCIAPI::PolygonScope::getShape(const std::string& polygonID) const {
1248 return getPolygon(libsumo::VAR_SHAPE, polygonID);
1249}
1250
1252TraCIAPI::PolygonScope::getColor(const std::string& polygonID) const {
1253 return getCol(libsumo::VAR_COLOR, polygonID);
1254}
1255
1256void
1257TraCIAPI::PolygonScope::setLineWidth(const std::string& polygonID, const double lineWidth) const {
1258 tcpip::Storage content;
1260 content.writeDouble(lineWidth);
1261 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_WIDTH, polygonID, &content);
1262 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1263}
1264
1265void
1266TraCIAPI::PolygonScope::setHeight(const std::string& polygonID, const double height) const {
1267 tcpip::Storage content;
1269 content.writeDouble(height);
1270 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_HEIGHT, polygonID, &content);
1271 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1272}
1273
1274void
1275TraCIAPI::PolygonScope::setType(const std::string& polygonID, const std::string& setType) const {
1276 tcpip::Storage content;
1278 content.writeString(setType);
1279 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_TYPE, polygonID, &content);
1280 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1281}
1282
1283
1284void
1285TraCIAPI::PolygonScope::setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) const {
1286 tcpip::Storage content;
1288 if (shape.value.size() < 256) {
1289 content.writeUnsignedByte((int)shape.value.size());
1290 } else {
1291 content.writeUnsignedByte(0);
1292 content.writeInt((int)shape.value.size());
1293 }
1294 for (const libsumo::TraCIPosition& pos : shape.value) {
1295 content.writeDouble(pos.x);
1296 content.writeDouble(pos.y);
1297 }
1298 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_SHAPE, polygonID, &content);
1299 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1300}
1301
1302
1303void
1304TraCIAPI::PolygonScope::setColor(const std::string& polygonID, const libsumo::TraCIColor& c) const {
1305 tcpip::Storage content;
1307 content.writeUnsignedByte(c.r);
1308 content.writeUnsignedByte(c.g);
1309 content.writeUnsignedByte(c.b);
1310 content.writeUnsignedByte(c.a);
1311 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_COLOR, polygonID, &content);
1312 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1313}
1314
1315void
1316TraCIAPI::PolygonScope::add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& c, bool fill, const std::string& type, int layer) const {
1317 tcpip::Storage content;
1319 content.writeInt(5);
1321 content.writeString(type);
1323 content.writeUnsignedByte(c.r);
1324 content.writeUnsignedByte(c.g);
1325 content.writeUnsignedByte(c.b);
1326 content.writeUnsignedByte(c.a);
1328 int f = fill ? 1 : 0;
1329 content.writeUnsignedByte(f);
1331 content.writeInt(layer);
1333 content.writeUnsignedByte((int)shape.value.size());
1334 for (int i = 0; i < (int)shape.value.size(); ++i) {
1335 content.writeDouble(shape.value[i].x);
1336 content.writeDouble(shape.value[i].y);
1337 }
1338 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::ADD, polygonID, &content);
1339 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1340}
1341
1342void
1343TraCIAPI::PolygonScope::remove(const std::string& polygonID, int layer) const {
1344 tcpip::Storage content;
1346 content.writeInt(layer);
1347 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::REMOVE, polygonID, &content);
1348 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1349}
1350
1351
1352// ---------------------------------------------------------------------------
1353// TraCIAPI::RouteScope-methods
1354// ---------------------------------------------------------------------------
1355std::vector<std::string>
1356TraCIAPI::RouteScope::getEdges(const std::string& routeID) const {
1357 return getStringVector(libsumo::VAR_EDGES, routeID);
1358}
1359
1360
1361void
1362TraCIAPI::RouteScope::add(const std::string& routeID, const std::vector<std::string>& edges) const {
1363 tcpip::Storage content;
1365 content.writeStringList(edges);
1366 myParent.createCommand(libsumo::CMD_SET_ROUTE_VARIABLE, libsumo::ADD, routeID, &content);
1367 myParent.processSet(libsumo::CMD_SET_ROUTE_VARIABLE);
1368}
1369
1370
1371// ---------------------------------------------------------------------------
1372// TraCIAPI::SimulationScope-methods
1373// ---------------------------------------------------------------------------
1374int
1378
1379double
1381 return getDouble(libsumo::VAR_TIME, "");
1382}
1383
1384int
1388
1389std::vector<std::string>
1393
1394int
1398
1399std::vector<std::string>
1403
1404int
1408
1409std::vector<std::string>
1413
1414int
1418
1419std::vector<std::string>
1423
1424int
1428
1429std::vector<std::string>
1433
1434int
1438
1439std::vector<std::string>
1443
1444int
1448
1449std::vector<std::string>
1453
1454double
1456 return getDouble(libsumo::VAR_DELTA_T, "");
1457}
1458
1463
1464
1465int
1469
1470std::string
1471TraCIAPI::SimulationScope::getOption(const std::string& option) const {
1472 return getString(libsumo::VAR_OPTION, option);
1473}
1474
1475int
1476TraCIAPI::SimulationScope::getBusStopWaiting(const std::string& stopID) const {
1477 return (int) getInt(libsumo::VAR_BUS_STOP_WAITING, stopID);
1478}
1479
1480std::vector<std::string>
1482 return getStringVector(libsumo::VAR_BUS_STOP_WAITING_IDS, stopID);
1483}
1484
1485
1487TraCIAPI::SimulationScope::convert2D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) const {
1488 const int posType = toGeo ? libsumo::POSITION_LON_LAT : libsumo::POSITION_2D;
1490 tcpip::Storage content;
1492 content.writeInt(2);
1494 content.writeString(edgeID);
1495 content.writeDouble(pos);
1496 content.writeByte(laneIndex);
1498 content.writeByte(posType);
1499 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1500 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1501 result.x = myParent.myInput.readDouble();
1502 result.y = myParent.myInput.readDouble();
1503 }
1504 return result;
1505}
1506
1507
1509TraCIAPI::SimulationScope::convert3D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) const {
1510 const int posType = toGeo ? libsumo::POSITION_LON_LAT_ALT : libsumo::POSITION_3D;
1512 tcpip::Storage content;
1514 content.writeInt(2);
1516 content.writeString(edgeID);
1517 content.writeDouble(pos);
1518 content.writeByte(laneIndex);
1520 content.writeByte(posType);
1521 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1522 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1523 result.x = myParent.myInput.readDouble();
1524 result.y = myParent.myInput.readDouble();
1525 result.z = myParent.myInput.readDouble();
1526 }
1527 return result;
1528}
1529
1530
1532TraCIAPI::SimulationScope::convertRoad(double x, double y, bool isGeo, const std::string& vClass) const {
1534 tcpip::Storage content;
1536 content.writeInt(3);
1538 content.writeDouble(x);
1539 content.writeDouble(y);
1543 content.writeString(vClass);
1544 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1545 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_ROADMAP)) {
1546 result.edgeID = myParent.myInput.readString();
1547 result.pos = myParent.myInput.readDouble();
1548 result.laneIndex = myParent.myInput.readUnsignedByte();
1549 }
1550 return result;
1551}
1552
1553
1555TraCIAPI::SimulationScope::convertGeo(double x, double y, bool fromGeo) const {
1556 const int posType = fromGeo ? libsumo::POSITION_2D : libsumo::POSITION_LON_LAT;
1558 tcpip::Storage content;
1560 content.writeInt(2);
1562 content.writeDouble(x);
1563 content.writeDouble(y);
1565 content.writeByte(posType);
1566 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1567 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1568 result.x = myParent.myInput.readDouble();
1569 result.y = myParent.myInput.readDouble();
1570 }
1571 return result;
1572}
1573
1574
1575double
1576TraCIAPI::SimulationScope::getDistance2D(double x1, double y1, double x2, double y2, bool isGeo, bool isDriving) {
1577 tcpip::Storage content;
1579 content.writeInt(3);
1581 content.writeDouble(x1);
1582 content.writeDouble(y1);
1584 content.writeDouble(x2);
1585 content.writeDouble(y2);
1587 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::DISTANCE_REQUEST, "", &content);
1588 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::TYPE_DOUBLE)) {
1589 return myParent.myInput.readDouble();
1590 }
1591 return 0.;
1592}
1593
1594
1595double
1596TraCIAPI::SimulationScope::getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving) {
1597 tcpip::Storage content;
1599 content.writeInt(3);
1601 content.writeString(edgeID1);
1602 content.writeDouble(pos1);
1603 content.writeByte(0); // lane
1605 content.writeString(edgeID2);
1606 content.writeDouble(pos2);
1607 content.writeByte(0); // lane
1609 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::DISTANCE_REQUEST, "", &content);
1610 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::TYPE_DOUBLE)) {
1611 return myParent.myInput.readDouble();
1612 }
1613 return 0.;
1614}
1615
1616
1618TraCIAPI::SimulationScope::findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType, double pos, int routingMode) const {
1619 tcpip::Storage content;
1621 content.writeInt(5);
1623 content.writeString(fromEdge);
1625 content.writeString(toEdge);
1627 content.writeString(vType);
1629 content.writeDouble(pos);
1631 content.writeInt(routingMode);
1632 return getTraCIStage(libsumo::FIND_ROUTE, "", &content);
1633}
1634
1635void
1636TraCIAPI::SimulationScope::loadState(const std::string& path) const {
1637 tcpip::Storage content;
1639 content.writeString(path);
1640 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_LOAD_SIMSTATE, "", &content);
1641 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1642}
1643
1644void
1645TraCIAPI::SimulationScope::saveState(const std::string& destination) const {
1646 tcpip::Storage content;
1648 content.writeString(destination);
1649 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_SAVE_SIMSTATE, "", &content);
1650 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1651}
1652
1653void
1655 tcpip::Storage content;
1657 content.writeString(msg);
1658 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_MESSAGE, "", &content);
1659 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1660}
1661
1662
1663// ---------------------------------------------------------------------------
1664// TraCIAPI::TrafficLightScope-methods
1665// ---------------------------------------------------------------------------
1666std::string
1668 return getString(libsumo::TL_RED_YELLOW_GREEN_STATE, tlsID);
1669}
1670
1671std::vector<libsumo::TraCILogic>
1673 std::vector<libsumo::TraCILogic> ret;
1675 if (myParent.processGet(libsumo::CMD_GET_TL_VARIABLE, libsumo::TYPE_COMPOUND)) {
1676 const int logicNo = myParent.myInput.readInt();
1677 for (int i = 0; i < logicNo; ++i) {
1678 myParent.myInput.readUnsignedByte();
1679 myParent.myInput.readInt();
1680 myParent.myInput.readUnsignedByte();
1681 const std::string programID = myParent.myInput.readString();
1682 myParent.myInput.readUnsignedByte();
1683 const int type = myParent.myInput.readInt();
1684 myParent.myInput.readUnsignedByte();
1685 const int phaseIndex = myParent.myInput.readInt();
1686 myParent.myInput.readUnsignedByte();
1687 const int phaseNumber = myParent.myInput.readInt();
1688 libsumo::TraCILogic logic(programID, type, phaseIndex);
1689 for (int j = 0; j < phaseNumber; j++) {
1690 myParent.myInput.readUnsignedByte();
1691 myParent.myInput.readInt();
1692 myParent.myInput.readUnsignedByte();
1693 const double duration = myParent.myInput.readDouble();
1694 myParent.myInput.readUnsignedByte();
1695 const std::string state = myParent.myInput.readString();
1696 myParent.myInput.readUnsignedByte();
1697 const double minDur = myParent.myInput.readDouble();
1698 myParent.myInput.readUnsignedByte();
1699 const double maxDur = myParent.myInput.readDouble();
1700 myParent.myInput.readUnsignedByte();
1701 const int numNext = myParent.myInput.readInt();
1702 std::vector<int> next;
1703 for (int k = 0; k < numNext; k++) {
1704 myParent.myInput.readUnsignedByte();
1705 next.push_back(myParent.myInput.readInt());
1706 }
1707 myParent.myInput.readUnsignedByte();
1708 const std::string name = myParent.myInput.readString();
1709 logic.phases.emplace_back(new libsumo::TraCIPhase(duration, state, minDur, maxDur, next, name));
1710 }
1711 myParent.myInput.readUnsignedByte();
1712 const int paramNumber = myParent.myInput.readInt();
1713 for (int j = 0; j < paramNumber; j++) {
1714 myParent.myInput.readUnsignedByte();
1715 const std::vector<std::string> par = myParent.myInput.readStringList();
1716 logic.subParameter[par[0]] = par[1];
1717 }
1718 ret.emplace_back(logic);
1719 }
1720 }
1721 return ret;
1722}
1723
1724std::vector<std::string>
1726 return getStringVector(libsumo::TL_CONTROLLED_LANES, tlsID);
1727}
1728
1729std::vector<std::vector<libsumo::TraCILink> >
1731 std::vector<std::vector<libsumo::TraCILink> > result;
1732 myParent.createCommand(libsumo::CMD_GET_TL_VARIABLE, libsumo::TL_CONTROLLED_LINKS, tlsID);
1733 if (myParent.processGet(libsumo::CMD_GET_TL_VARIABLE, libsumo::TYPE_COMPOUND)) {
1734
1735 myParent.myInput.readUnsignedByte();
1736 myParent.myInput.readInt();
1737
1738 int linkNo = myParent.myInput.readInt();
1739 for (int i = 0; i < linkNo; ++i) {
1740 myParent.myInput.readUnsignedByte();
1741 int no = myParent.myInput.readInt();
1742 std::vector<libsumo::TraCILink> ret;
1743 for (int i1 = 0; i1 < no; ++i1) {
1744 myParent.myInput.readUnsignedByte();
1745 myParent.myInput.readInt();
1746 std::string from = myParent.myInput.readString();
1747 std::string to = myParent.myInput.readString();
1748 std::string via = myParent.myInput.readString();
1749 ret.emplace_back(libsumo::TraCILink(from, via, to));
1750 }
1751 result.emplace_back(ret);
1752 }
1753 }
1754 return result;
1755}
1756
1757std::string
1758TraCIAPI::TrafficLightScope::getProgram(const std::string& tlsID) const {
1759 return getString(libsumo::TL_CURRENT_PROGRAM, tlsID);
1760}
1761
1762int
1763TraCIAPI::TrafficLightScope::getPhase(const std::string& tlsID) const {
1764 return getInt(libsumo::TL_CURRENT_PHASE, tlsID);
1765}
1766
1767std::string
1768TraCIAPI::TrafficLightScope::getPhaseName(const std::string& tlsID) const {
1769 return getString(libsumo::VAR_NAME, tlsID);
1770}
1771
1772double
1773TraCIAPI::TrafficLightScope::getPhaseDuration(const std::string& tlsID) const {
1774 return getDouble(libsumo::TL_PHASE_DURATION, tlsID);
1775}
1776
1777double
1778TraCIAPI::TrafficLightScope::getNextSwitch(const std::string& tlsID) const {
1779 return getDouble(libsumo::TL_NEXT_SWITCH, tlsID);
1780}
1781
1782
1783int
1784TraCIAPI::TrafficLightScope::getServedPersonCount(const std::string& tlsID, int index) const {
1785 tcpip::Storage content;
1787 content.writeInt(index);
1788 return getInt(libsumo::VAR_PERSON_NUMBER, tlsID, &content);
1789}
1790
1791
1792void
1793TraCIAPI::TrafficLightScope::setRedYellowGreenState(const std::string& tlsID, const std::string& state) const {
1794 tcpip::Storage content;
1796 content.writeString(state);
1797 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_RED_YELLOW_GREEN_STATE, tlsID, &content);
1798 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1799}
1800
1801void
1802TraCIAPI::TrafficLightScope::setPhase(const std::string& tlsID, int index) const {
1803 tcpip::Storage content;
1805 content.writeInt(index);
1806 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PHASE_INDEX, tlsID, &content);
1807 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1808}
1809
1810void
1811TraCIAPI::TrafficLightScope::setPhaseName(const std::string& tlsID, const std::string& name) const {
1812 tcpip::Storage content;
1814 content.writeString(name);
1815 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::VAR_NAME, tlsID, &content);
1816 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1817}
1818
1819void
1820TraCIAPI::TrafficLightScope::setProgram(const std::string& tlsID, const std::string& programID) const {
1821 tcpip::Storage content;
1823 content.writeString(programID);
1824 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PROGRAM, tlsID, &content);
1825 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1826}
1827
1828void
1829TraCIAPI::TrafficLightScope::setPhaseDuration(const std::string& tlsID, double phaseDuration) const {
1830 tcpip::Storage content;
1832 content.writeDouble(phaseDuration);
1833 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PHASE_DURATION, tlsID, &content);
1834 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1835}
1836
1837void
1838TraCIAPI::TrafficLightScope::setProgramLogic(const std::string& tlsID, const libsumo::TraCILogic& logic) const {
1839 tcpip::Storage content;
1841 content.writeInt(5);
1843 content.writeString(logic.programID);
1845 content.writeInt(logic.type);
1847 content.writeInt(logic.currentPhaseIndex);
1849 content.writeInt((int)logic.phases.size());
1850 for (const std::shared_ptr<libsumo::TraCIPhase>& p : logic.phases) {
1852 content.writeInt(6);
1854 content.writeDouble(p->duration);
1856 content.writeString(p->state);
1858 content.writeDouble(p->minDur);
1860 content.writeDouble(p->maxDur);
1862 content.writeInt((int)p->next.size());
1863 for (int n : p->next) {
1865 content.writeInt(n);
1866 }
1868 content.writeString(p->name);
1869 }
1871 content.writeInt((int)logic.subParameter.size());
1872 for (const auto& item : logic.subParameter) {
1874 content.writeInt(2);
1875 content.writeString(item.first);
1876 content.writeString(item.second);
1877 }
1878 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_COMPLETE_PROGRAM_RYG, tlsID, &content);
1879 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1880}
1881
1882
1883// ---------------------------------------------------------------------------
1884// TraCIAPI::VehicleTypeScope-methods
1885// ---------------------------------------------------------------------------
1886double
1887TraCIAPI::VehicleTypeScope::getLength(const std::string& typeID) const {
1888 return getDouble(libsumo::VAR_LENGTH, typeID);
1889}
1890
1891double
1892TraCIAPI::VehicleTypeScope::getMaxSpeed(const std::string& typeID) const {
1893 return getDouble(libsumo::VAR_MAXSPEED, typeID);
1894}
1895
1896double
1897TraCIAPI::VehicleTypeScope::getSpeedFactor(const std::string& typeID) const {
1898 return getDouble(libsumo::VAR_SPEED_FACTOR, typeID);
1899}
1900
1901double
1902TraCIAPI::VehicleTypeScope::getSpeedDeviation(const std::string& typeID) const {
1903 return getDouble(libsumo::VAR_SPEED_DEVIATION, typeID);
1904}
1905
1906double
1907TraCIAPI::VehicleTypeScope::getAccel(const std::string& typeID) const {
1908 return getDouble(libsumo::VAR_ACCEL, typeID);
1909}
1910
1911double
1912TraCIAPI::VehicleTypeScope::getDecel(const std::string& typeID) const {
1913 return getDouble(libsumo::VAR_DECEL, typeID);
1914}
1915
1916double
1917TraCIAPI::VehicleTypeScope::getEmergencyDecel(const std::string& typeID) const {
1918 return getDouble(libsumo::VAR_EMERGENCY_DECEL, typeID);
1919}
1920
1921double
1922TraCIAPI::VehicleTypeScope::getApparentDecel(const std::string& typeID) const {
1923 return getDouble(libsumo::VAR_APPARENT_DECEL, typeID);
1924}
1925
1926double
1927TraCIAPI::VehicleTypeScope::getImperfection(const std::string& typeID) const {
1928 return getDouble(libsumo::VAR_IMPERFECTION, typeID);
1929}
1930
1931double
1932TraCIAPI::VehicleTypeScope::getTau(const std::string& typeID) const {
1933 return getDouble(libsumo::VAR_TAU, typeID);
1934}
1935
1936std::string
1937TraCIAPI::VehicleTypeScope::getVehicleClass(const std::string& typeID) const {
1938 return getString(libsumo::VAR_VEHICLECLASS, typeID);
1939}
1940
1941std::string
1942TraCIAPI::VehicleTypeScope::getEmissionClass(const std::string& typeID) const {
1943 return getString(libsumo::VAR_EMISSIONCLASS, typeID);
1944}
1945
1946std::string
1947TraCIAPI::VehicleTypeScope::getShapeClass(const std::string& typeID) const {
1948 return getString(libsumo::VAR_SHAPECLASS, typeID);
1949}
1950
1951double
1952TraCIAPI::VehicleTypeScope::getMinGap(const std::string& typeID) const {
1953 return getDouble(libsumo::VAR_MINGAP, typeID);
1954}
1955
1956double
1957TraCIAPI::VehicleTypeScope::getMinGapLat(const std::string& typeID) const {
1958 return getDouble(libsumo::VAR_MINGAP_LAT, typeID);
1959}
1960
1961double
1962TraCIAPI::VehicleTypeScope::getMaxSpeedLat(const std::string& typeID) const {
1963 return getDouble(libsumo::VAR_MAXSPEED_LAT, typeID);
1964}
1965
1966std::string
1967TraCIAPI::VehicleTypeScope::getLateralAlignment(const std::string& typeID) const {
1968 return getString(libsumo::VAR_LATALIGNMENT, typeID);
1969}
1970
1971int
1972TraCIAPI::VehicleTypeScope::getPersonCapacity(const std::string& typeID) const {
1973 return getInt(libsumo::VAR_PERSON_CAPACITY, typeID);
1974}
1975
1976double
1977TraCIAPI::VehicleTypeScope::getWidth(const std::string& typeID) const {
1978 return getDouble(libsumo::VAR_WIDTH, typeID);
1979}
1980
1981double
1982TraCIAPI::VehicleTypeScope::getHeight(const std::string& typeID) const {
1983 return getDouble(libsumo::VAR_HEIGHT, typeID);
1984}
1985
1987TraCIAPI::VehicleTypeScope::getColor(const std::string& typeID) const {
1988 return getCol(libsumo::VAR_COLOR, typeID);
1989}
1990
1991
1992
1993void
1994TraCIAPI::VehicleTypeScope::setLength(const std::string& typeID, double length) const {
1995 tcpip::Storage content;
1997 content.writeDouble(length);
1998 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_LENGTH, typeID, &content);
1999 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2000}
2001
2002void
2003TraCIAPI::VehicleTypeScope::setMaxSpeed(const std::string& typeID, double speed) const {
2004 tcpip::Storage content;
2006 content.writeDouble(speed);
2007 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MAXSPEED, typeID, &content);
2008 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2009}
2010
2011void
2012TraCIAPI::VehicleTypeScope::setVehicleClass(const std::string& typeID, const std::string& clazz) const {
2013 tcpip::Storage content;
2015 content.writeString(clazz);
2016 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_VEHICLECLASS, typeID, &content);
2017 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2018}
2019
2020void
2021TraCIAPI::VehicleTypeScope::setSpeedFactor(const std::string& typeID, double factor) const {
2022 tcpip::Storage content;
2024 content.writeDouble(factor);
2025 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SPEED_FACTOR, typeID, &content);
2026 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2027}
2028
2029void
2030TraCIAPI::VehicleTypeScope::setSpeedDeviation(const std::string& typeID, double deviation) const {
2031 tcpip::Storage content;
2033 content.writeDouble(deviation);
2034 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SPEED_DEVIATION, typeID, &content);
2035 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2036}
2037
2038
2039void
2040TraCIAPI::VehicleTypeScope::setEmissionClass(const std::string& typeID, const std::string& clazz) const {
2041 tcpip::Storage content;
2043 content.writeString(clazz);
2044 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_EMISSIONCLASS, typeID, &content);
2045 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2046}
2047
2048void
2049TraCIAPI::VehicleTypeScope::setWidth(const std::string& typeID, double width) const {
2050 tcpip::Storage content;
2052 content.writeDouble(width);
2053 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_WIDTH, typeID, &content);
2054 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2055}
2056
2057void
2058TraCIAPI::VehicleTypeScope::setHeight(const std::string& typeID, double height) const {
2059 tcpip::Storage content;
2061 content.writeDouble(height);
2062 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_HEIGHT, typeID, &content);
2063 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2064}
2065
2066void
2067TraCIAPI::VehicleTypeScope::setMinGap(const std::string& typeID, double minGap) const {
2068 tcpip::Storage content;
2070 content.writeDouble(minGap);
2071 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MINGAP, typeID, &content);
2072 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2073}
2074
2075
2076void
2077TraCIAPI::VehicleTypeScope::setMinGapLat(const std::string& typeID, double minGapLat) const {
2078 tcpip::Storage content;
2080 content.writeDouble(minGapLat);
2081 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MINGAP_LAT, typeID, &content);
2082 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2083}
2084
2085void
2086TraCIAPI::VehicleTypeScope::setMaxSpeedLat(const std::string& typeID, double speed) const {
2087 tcpip::Storage content;
2089 content.writeDouble(speed);
2090 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MAXSPEED_LAT, typeID, &content);
2091 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2092}
2093
2094void
2095TraCIAPI::VehicleTypeScope::setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const {
2096 tcpip::Storage content;
2098 content.writeString(latAlignment);
2099 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_LATALIGNMENT, typeID, &content);
2100 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2101}
2102
2103void
2104TraCIAPI::VehicleTypeScope::copy(const std::string& origTypeID, const std::string& newTypeID) const {
2105 tcpip::Storage content;
2107 content.writeString(newTypeID);
2108 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::COPY, origTypeID, &content);
2109 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2110}
2111
2112void
2113TraCIAPI::VehicleTypeScope::setShapeClass(const std::string& typeID, const std::string& clazz) const {
2114 tcpip::Storage content;
2116 content.writeString(clazz);
2117 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SHAPECLASS, typeID, &content);
2118 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2119}
2120
2121void
2122TraCIAPI::VehicleTypeScope::setAccel(const std::string& typeID, double accel) const {
2123 tcpip::Storage content;
2125 content.writeDouble(accel);
2126 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_ACCEL, typeID, &content);
2127 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2128}
2129
2130void
2131TraCIAPI::VehicleTypeScope::setDecel(const std::string& typeID, double decel) const {
2132 tcpip::Storage content;
2134 content.writeDouble(decel);
2135 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_DECEL, typeID, &content);
2136 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2137}
2138
2139void
2140TraCIAPI::VehicleTypeScope::setEmergencyDecel(const std::string& typeID, double decel) const {
2141 tcpip::Storage content;
2143 content.writeDouble(decel);
2144 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_EMERGENCY_DECEL, typeID, &content);
2145 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2146}
2147
2148void
2149TraCIAPI::VehicleTypeScope::setApparentDecel(const std::string& typeID, double decel) const {
2150 tcpip::Storage content;
2152 content.writeDouble(decel);
2153 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_APPARENT_DECEL, typeID, &content);
2154 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2155}
2156
2157void
2158TraCIAPI::VehicleTypeScope::setImperfection(const std::string& typeID, double imperfection) const {
2159 tcpip::Storage content;
2161 content.writeDouble(imperfection);
2162 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_IMPERFECTION, typeID, &content);
2163 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2164}
2165
2166void
2167TraCIAPI::VehicleTypeScope::setTau(const std::string& typeID, double tau) const {
2168 tcpip::Storage content;
2170 content.writeDouble(tau);
2171 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_TAU, typeID, &content);
2172 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2173}
2174
2175void
2176TraCIAPI::VehicleTypeScope::setColor(const std::string& typeID, const libsumo::TraCIColor& c) const {
2177 tcpip::Storage content;
2179 content.writeUnsignedByte(c.r);
2180 content.writeUnsignedByte(c.g);
2181 content.writeUnsignedByte(c.b);
2182 content.writeUnsignedByte(c.a);
2183 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_COLOR, typeID, &content);
2184 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2185}
2186
2187
2188// ---------------------------------------------------------------------------
2189// TraCIAPI::VehicleScope-methods
2190// ---------------------------------------------------------------------------
2191double
2192TraCIAPI::VehicleScope::getSpeed(const std::string& vehicleID) const {
2193 return getDouble(libsumo::VAR_SPEED, vehicleID);
2194}
2195
2196double
2197TraCIAPI::VehicleScope::getLateralSpeed(const std::string& vehicleID) const {
2198 return getDouble(libsumo::VAR_SPEED_LAT, vehicleID);
2199}
2200
2201double
2202TraCIAPI::VehicleScope::getAcceleration(const std::string& vehicleID) const {
2203 return getDouble(libsumo::VAR_ACCELERATION, vehicleID);
2204}
2205
2206double
2207TraCIAPI::VehicleScope::getFollowSpeed(const std::string& vehicleID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) const {
2208 tcpip::Storage content;
2210 content.writeInt(5);
2212 content.writeDouble(speed);
2214 content.writeDouble(gap);
2216 content.writeDouble(leaderSpeed);
2218 content.writeDouble(leaderMaxDecel);
2220 content.writeString(leaderID);
2221 return getDouble(libsumo::VAR_FOLLOW_SPEED, vehicleID, &content);
2222}
2223
2224
2225double
2226TraCIAPI::VehicleScope::getSecureGap(const std::string& vehicleID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) const {
2227 tcpip::Storage content;
2229 content.writeInt(4);
2231 content.writeDouble(speed);
2233 content.writeDouble(leaderSpeed);
2235 content.writeDouble(leaderMaxDecel);
2237 content.writeString(leaderID);
2238 return getDouble(libsumo::VAR_SECURE_GAP, vehicleID, &content);
2239}
2240
2241double
2242TraCIAPI::VehicleScope::getStopSpeed(const std::string& vehicleID, double speed, double gap) const {
2243 tcpip::Storage content;
2245 content.writeInt(2);
2247 content.writeDouble(speed);
2249 content.writeDouble(gap);
2250 return getDouble(libsumo::VAR_STOP_SPEED, vehicleID, &content);
2251}
2252
2253
2254double
2255TraCIAPI::VehicleScope::getMaxSpeed(const std::string& vehicleID) const {
2256 return getDouble(libsumo::VAR_MAXSPEED, vehicleID);
2257}
2258
2260TraCIAPI::VehicleScope::getPosition(const std::string& vehicleID) const {
2261 return getPos(libsumo::VAR_POSITION, vehicleID);
2262}
2263
2265TraCIAPI::VehicleScope::getPosition3D(const std::string& vehicleID) const {
2266 return getPos3D(libsumo::VAR_POSITION3D, vehicleID);
2267}
2268
2269double
2270TraCIAPI::VehicleScope::getAngle(const std::string& vehicleID) const {
2271 return getDouble(libsumo::VAR_ANGLE, vehicleID);
2272}
2273
2274std::string
2275TraCIAPI::VehicleScope::getRoadID(const std::string& vehicleID) const {
2276 return getString(libsumo::VAR_ROAD_ID, vehicleID);
2277}
2278
2279std::string
2280TraCIAPI::VehicleScope::getLaneID(const std::string& vehicleID) const {
2281 return getString(libsumo::VAR_LANE_ID, vehicleID);
2282}
2283
2284std::string
2285TraCIAPI::VehicleScope::getShadowLaneID(const std::string& vehicleID) const {
2286 return getString(libsumo::VAR_SHADOW_LANE_ID, vehicleID);
2287}
2288
2289int
2290TraCIAPI::VehicleScope::getLaneIndex(const std::string& vehicleID) const {
2291 return getInt(libsumo::VAR_LANE_INDEX, vehicleID);
2292}
2293
2294std::string
2295TraCIAPI::VehicleScope::getTypeID(const std::string& vehicleID) const {
2296 return getString(libsumo::VAR_TYPE, vehicleID);
2297}
2298
2299std::string
2300TraCIAPI::VehicleScope::getRouteID(const std::string& vehicleID) const {
2301 return getString(libsumo::VAR_ROUTE_ID, vehicleID);
2302}
2303
2304int
2305TraCIAPI::VehicleScope::getRouteIndex(const std::string& vehicleID) const {
2306 return getInt(libsumo::VAR_ROUTE_INDEX, vehicleID);
2307}
2308
2309
2310std::vector<std::string>
2311TraCIAPI::VehicleScope::getRoute(const std::string& vehicleID) const {
2312 return getStringVector(libsumo::VAR_EDGES, vehicleID);
2313}
2314
2316TraCIAPI::VehicleScope::getColor(const std::string& vehicleID) const {
2317 return getCol(libsumo::VAR_COLOR, vehicleID);
2318}
2319
2320double
2321TraCIAPI::VehicleScope::getLanePosition(const std::string& vehicleID) const {
2322 return getDouble(libsumo::VAR_LANEPOSITION, vehicleID);
2323}
2324
2325double
2326TraCIAPI::VehicleScope::getDistance(const std::string& vehicleID) const {
2327 return getDouble(libsumo::VAR_DISTANCE, vehicleID);
2328}
2329
2330int
2331TraCIAPI::VehicleScope::getSignals(const std::string& vehicleID) const {
2332 return getInt(libsumo::VAR_SIGNALS, vehicleID);
2333}
2334
2335double
2336TraCIAPI::VehicleScope::getLateralLanePosition(const std::string& vehicleID) const {
2337 return getDouble(libsumo::VAR_LANEPOSITION_LAT, vehicleID);
2338}
2339
2340double
2341TraCIAPI::VehicleScope::getCO2Emission(const std::string& vehicleID) const {
2342 return getDouble(libsumo::VAR_CO2EMISSION, vehicleID);
2343}
2344
2345double
2346TraCIAPI::VehicleScope::getCOEmission(const std::string& vehicleID) const {
2347 return getDouble(libsumo::VAR_COEMISSION, vehicleID);
2348}
2349
2350double
2351TraCIAPI::VehicleScope::getHCEmission(const std::string& vehicleID) const {
2352 return getDouble(libsumo::VAR_HCEMISSION, vehicleID);
2353}
2354
2355double
2356TraCIAPI::VehicleScope::getPMxEmission(const std::string& vehicleID) const {
2357 return getDouble(libsumo::VAR_PMXEMISSION, vehicleID);
2358}
2359
2360double
2361TraCIAPI::VehicleScope::getNOxEmission(const std::string& vehicleID) const {
2362 return getDouble(libsumo::VAR_NOXEMISSION, vehicleID);
2363}
2364
2365double
2366TraCIAPI::VehicleScope::getFuelConsumption(const std::string& vehicleID) const {
2367 return getDouble(libsumo::VAR_FUELCONSUMPTION, vehicleID);
2368}
2369
2370double
2371TraCIAPI::VehicleScope::getNoiseEmission(const std::string& vehicleID) const {
2372 return getDouble(libsumo::VAR_NOISEEMISSION, vehicleID);
2373}
2374
2375double
2376TraCIAPI::VehicleScope::getElectricityConsumption(const std::string& vehicleID) const {
2377 return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, vehicleID);
2378}
2379
2380double
2381TraCIAPI::VehicleScope::getWaitingTime(const std::string& vehID) const {
2382 return getDouble(libsumo::VAR_WAITING_TIME, vehID);
2383}
2384
2385int
2386TraCIAPI::VehicleScope::getLaneChangeMode(const std::string& vehID) const {
2387 return getInt(libsumo::VAR_LANECHANGE_MODE, vehID);
2388}
2389
2390
2391int
2392TraCIAPI::VehicleScope::getSpeedMode(const std::string& vehID) const {
2393 return getInt(libsumo::VAR_SPEEDSETMODE, vehID);
2394}
2395
2396
2397double
2398TraCIAPI::VehicleScope::getSlope(const std::string& vehID) const {
2399 return getDouble(libsumo::VAR_SLOPE, vehID);
2400}
2401
2402
2403std::string
2404TraCIAPI::VehicleScope::getLine(const std::string& typeID) const {
2405 return getString(libsumo::VAR_LINE, typeID);
2406}
2407
2408std::vector<std::string>
2409TraCIAPI::VehicleScope::getVia(const std::string& vehicleID) const {
2410 return getStringVector(libsumo::VAR_VIA, vehicleID);
2411}
2412
2413std::string
2414TraCIAPI::VehicleScope::getEmissionClass(const std::string& vehicleID) const {
2415 return getString(libsumo::VAR_EMISSIONCLASS, vehicleID);
2416}
2417
2418std::string
2419TraCIAPI::VehicleScope::getShapeClass(const std::string& vehicleID) const {
2420 return getString(libsumo::VAR_SHAPECLASS, vehicleID);
2421}
2422
2423std::vector<libsumo::TraCINextTLSData>
2424TraCIAPI::VehicleScope::getNextTLS(const std::string& vehID) const {
2425 std::vector<libsumo::TraCINextTLSData> result;
2426 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_NEXT_TLS, vehID);
2428 myParent.myInput.readInt(); // components
2429 // number of items
2430 myParent.myInput.readUnsignedByte();
2431 const int n = myParent.myInput.readInt();
2432 for (int i = 0; i < n; ++i) {
2434 myParent.myInput.readUnsignedByte();
2435 d.id = myParent.myInput.readString();
2436
2437 myParent.myInput.readUnsignedByte();
2438 d.tlIndex = myParent.myInput.readInt();
2439
2440 myParent.myInput.readUnsignedByte();
2441 d.dist = myParent.myInput.readDouble();
2442
2443 myParent.myInput.readUnsignedByte();
2444 d.state = (char)myParent.myInput.readByte();
2445
2446 result.push_back(d);
2447 }
2448 }
2449 return result;
2450}
2451
2452std::vector<libsumo::TraCIBestLanesData>
2453TraCIAPI::VehicleScope::getBestLanes(const std::string& vehicleID) const {
2454 std::vector<libsumo::TraCIBestLanesData> result;
2455 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_BEST_LANES, vehicleID);
2457 myParent.myInput.readInt();
2458 myParent.myInput.readUnsignedByte();
2459
2460 const int n = myParent.myInput.readInt(); // number of following edge information
2461 for (int i = 0; i < n; ++i) {
2463 myParent.myInput.readUnsignedByte();
2464 info.laneID = myParent.myInput.readString();
2465
2466 myParent.myInput.readUnsignedByte();
2467 info.length = myParent.myInput.readDouble();
2468
2469 myParent.myInput.readUnsignedByte();
2470 info.occupation = myParent.myInput.readDouble();
2471
2472 myParent.myInput.readUnsignedByte();
2473 info.bestLaneOffset = myParent.myInput.readByte();
2474
2475 myParent.myInput.readUnsignedByte();
2476 info.allowsContinuation = (myParent.myInput.readUnsignedByte() == 1);
2477
2478 myParent.myInput.readUnsignedByte();
2479 const int m = myParent.myInput.readInt();
2480 for (int j = 0; j < m; ++j) {
2481 info.continuationLanes.push_back(myParent.myInput.readString());
2482 }
2483
2484 result.push_back(info);
2485 }
2486 }
2487 return result;
2488}
2489
2490
2491std::pair<std::string, double>
2492TraCIAPI::VehicleScope::getLeader(const std::string& vehicleID, double dist) const {
2493 tcpip::Storage content;
2495 content.writeDouble(dist);
2496 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_LEADER, vehicleID, &content);
2498 myParent.myInput.readInt(); // components
2499 myParent.myInput.readUnsignedByte();
2500 const std::string leaderID = myParent.myInput.readString();
2501 myParent.myInput.readUnsignedByte();
2502 const double gap = myParent.myInput.readDouble();
2503 return std::make_pair(leaderID, gap);
2504 }
2505 return std::make_pair("", libsumo::INVALID_DOUBLE_VALUE);
2506}
2507
2508
2509std::pair<std::string, double>
2510TraCIAPI::VehicleScope::getFollower(const std::string& vehicleID, double dist) const {
2511 tcpip::Storage content;
2513 content.writeDouble(dist);
2514 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_FOLLOWER, vehicleID, &content);
2516 myParent.myInput.readInt(); // components
2517 myParent.myInput.readUnsignedByte();
2518 const std::string leaderID = myParent.myInput.readString();
2519 myParent.myInput.readUnsignedByte();
2520 const double gap = myParent.myInput.readDouble();
2521 return std::make_pair(leaderID, gap);
2522 }
2523 return std::make_pair("", libsumo::INVALID_DOUBLE_VALUE);
2524}
2525
2526
2527std::pair<int, int>
2528TraCIAPI::VehicleScope::getLaneChangeState(const std::string& vehicleID, int direction) const {
2529 tcpip::Storage content;
2531 content.writeInt(direction);
2532 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2534 myParent.myInput.readInt(); // components
2535 myParent.myInput.readUnsignedByte();
2536 const int stateWithoutTraCI = myParent.myInput.readInt();
2537 myParent.myInput.readUnsignedByte();
2538 const int state = myParent.myInput.readInt();
2539 return std::make_pair(stateWithoutTraCI, state);
2540 }
2542}
2543
2544
2545int
2546TraCIAPI::VehicleScope::getStopState(const std::string& vehicleID) const {
2547 return getInt(libsumo::VAR_STOPSTATE, vehicleID);
2548}
2549
2550int
2551TraCIAPI::VehicleScope::getRoutingMode(const std::string& vehicleID) const {
2552 return getInt(libsumo::VAR_ROUTING_MODE, vehicleID);
2553}
2554
2555double
2556TraCIAPI::VehicleScope::getStopDelay(const std::string& vehicleID) const {
2557 return getDouble(libsumo::VAR_STOP_DELAY, vehicleID);
2558}
2559
2560double
2561TraCIAPI::VehicleScope::getStopArrivalDelay(const std::string& vehicleID) const {
2562 return getDouble(libsumo::VAR_STOP_ARRIVALDELAY, vehicleID);
2563}
2564
2565
2566double
2567TraCIAPI::VehicleScope::getAccel(const std::string& vehicleID) const {
2568 return getDouble(libsumo::VAR_ACCEL, vehicleID);
2569}
2570
2571double
2572TraCIAPI::VehicleScope::getDecel(const std::string& vehicleID) const {
2573 return getDouble(libsumo::VAR_DECEL, vehicleID);
2574}
2575
2576double
2577TraCIAPI::VehicleScope::getTau(const std::string& vehicleID) const {
2578 return getDouble(libsumo::VAR_TAU, vehicleID);
2579}
2580
2581double
2582TraCIAPI::VehicleScope::getImperfection(const std::string& vehicleID) const {
2583 return getDouble(libsumo::VAR_IMPERFECTION, vehicleID);
2584}
2585
2586double
2587TraCIAPI::VehicleScope::getSpeedFactor(const std::string& vehicleID) const {
2588 return getDouble(libsumo::VAR_SPEED_FACTOR, vehicleID);
2589}
2590
2591double
2592TraCIAPI::VehicleScope::getSpeedDeviation(const std::string& vehicleID) const {
2593 return getDouble(libsumo::VAR_SPEED_DEVIATION, vehicleID);
2594}
2595
2596std::string
2597TraCIAPI::VehicleScope::getVehicleClass(const std::string& vehicleID) const {
2598 return getString(libsumo::VAR_VEHICLECLASS, vehicleID);
2599}
2600
2601double
2602TraCIAPI::VehicleScope::getMinGap(const std::string& vehicleID) const {
2603 return getDouble(libsumo::VAR_MINGAP, vehicleID);
2604}
2605
2606double
2607TraCIAPI::VehicleScope::getWidth(const std::string& vehicleID) const {
2608 return getDouble(libsumo::VAR_WIDTH, vehicleID);
2609}
2610
2611double
2612TraCIAPI::VehicleScope::getLength(const std::string& vehicleID) const {
2613 return getDouble(libsumo::VAR_LENGTH, vehicleID);
2614}
2615
2616double
2617TraCIAPI::VehicleScope::getHeight(const std::string& vehicleID) const {
2618 return getDouble(libsumo::VAR_HEIGHT, vehicleID);
2619}
2620
2621double
2622TraCIAPI::VehicleScope::getAccumulatedWaitingTime(const std::string& vehicleID) const {
2623 return getDouble(libsumo::VAR_ACCUMULATED_WAITING_TIME, vehicleID);
2624}
2625
2626double
2627TraCIAPI::VehicleScope::getAllowedSpeed(const std::string& vehicleID) const {
2628 return getDouble(libsumo::VAR_ALLOWED_SPEED, vehicleID);
2629}
2630
2631int
2632TraCIAPI::VehicleScope::getPersonNumber(const std::string& vehicleID) const {
2633 return getInt(libsumo::VAR_PERSON_NUMBER, vehicleID);
2634}
2635
2636int
2637TraCIAPI::VehicleScope::getPersonCapacity(const std::string& vehicleID) const {
2638 return getInt(libsumo::VAR_PERSON_CAPACITY, vehicleID);
2639}
2640
2641std::vector<std::string>
2642TraCIAPI::VehicleScope::getPersonIDList(const std::string& vehicleID) const {
2643 return getStringVector(libsumo::LAST_STEP_PERSON_ID_LIST, vehicleID);
2644}
2645
2646double
2647TraCIAPI::VehicleScope::getSpeedWithoutTraCI(const std::string& vehicleID) const {
2648 return getDouble(libsumo::VAR_SPEED_WITHOUT_TRACI, vehicleID);
2649}
2650
2651bool
2652TraCIAPI::VehicleScope::isRouteValid(const std::string& vehicleID) const {
2653 return getInt(libsumo::VAR_ROUTE_VALID, vehicleID) != 0;
2654}
2655
2656double
2657TraCIAPI::VehicleScope::getMaxSpeedLat(const std::string& vehicleID) const {
2658 return getDouble(libsumo::VAR_MAXSPEED_LAT, vehicleID);
2659}
2660
2661double
2662TraCIAPI::VehicleScope::getMinGapLat(const std::string& vehicleID) const {
2663 return getDouble(libsumo::VAR_MINGAP_LAT, vehicleID);
2664}
2665
2666std::string
2667TraCIAPI::VehicleScope::getLateralAlignment(const std::string& vehicleID) const {
2668 return getString(libsumo::VAR_LATALIGNMENT, vehicleID);
2669}
2670
2671void
2672TraCIAPI::VehicleScope::add(const std::string& vehicleID,
2673 const std::string& routeID,
2674 const std::string& typeID,
2675 std::string depart,
2676 const std::string& departLane,
2677 const std::string& departPos,
2678 const std::string& departSpeed,
2679 const std::string& arrivalLane,
2680 const std::string& arrivalPos,
2681 const std::string& arrivalSpeed,
2682 const std::string& fromTaz,
2683 const std::string& toTaz,
2684 const std::string& line,
2685 int personCapacity,
2686 int personNumber) const {
2687
2688 if (depart == "-1") {
2689 depart = toString(myParent.simulation.getCurrentTime() / 1000.0);
2690 }
2691 tcpip::Storage content;
2693 content.writeInt(14);
2695 content.writeString(routeID);
2697 content.writeString(typeID);
2699 content.writeString(depart);
2701 content.writeString(departLane);
2703 content.writeString(departPos);
2705 content.writeString(departSpeed);
2706
2708 content.writeString(arrivalLane);
2710 content.writeString(arrivalPos);
2712 content.writeString(arrivalSpeed);
2713
2715 content.writeString(fromTaz);
2717 content.writeString(toTaz);
2719 content.writeString(line);
2720
2722 content.writeInt(personCapacity);
2724 content.writeInt(personNumber);
2725
2726 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::ADD_FULL, vehicleID, &content);
2727 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2728}
2729
2730
2731void
2732TraCIAPI::VehicleScope::remove(const std::string& vehicleID, char reason) const {
2733 tcpip::Storage content;
2735 content.writeUnsignedByte(reason);
2736 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::REMOVE, vehicleID, &content);
2737 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2738
2739}
2740
2741
2742void
2743TraCIAPI::VehicleScope::changeTarget(const std::string& vehicleID, const std::string& edgeID) const {
2744 tcpip::Storage content;
2746 content.writeString(edgeID);
2747 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGETARGET, vehicleID, &content);
2748 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2749}
2750
2751
2752void
2753TraCIAPI::VehicleScope::changeLane(const std::string& vehicleID, int laneIndex, double duration) const {
2754 tcpip::Storage content;
2756 content.writeInt(2);
2758 content.writeByte(laneIndex);
2760 content.writeDouble(duration);
2761 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2762 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2763}
2764
2765
2766void
2767TraCIAPI::VehicleScope::changeLaneRelative(const std::string& vehicleID, int laneChange, double duration) const {
2768 tcpip::Storage content;
2770 content.writeInt(3);
2772 content.writeByte(laneChange);
2774 content.writeDouble(duration);
2776 content.writeByte(1);
2777 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2778 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2779}
2780
2781
2782void
2783TraCIAPI::VehicleScope::changeSublane(const std::string& vehicleID, double latDist) const {
2784 tcpip::Storage content;
2786 content.writeDouble(latDist);
2787 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGESUBLANE, vehicleID, &content);
2788 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2789}
2790
2791
2792void
2793TraCIAPI::VehicleScope::setRouteID(const std::string& vehicleID, const std::string& routeID) const {
2794 tcpip::Storage content;
2796 content.writeString(routeID);
2797 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE_ID, vehicleID, &content);
2798 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2799}
2800
2801
2802void
2803TraCIAPI::VehicleScope::setRoute(const std::string& vehicleID, const std::vector<std::string>& edges) const {
2804 tcpip::Storage content;
2806 content.writeInt((int)edges.size());
2807 for (int i = 0; i < (int)edges.size(); ++i) {
2808 content.writeString(edges[i]);
2809 }
2810 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE, vehicleID, &content);
2811 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2812}
2813
2814
2815void
2816TraCIAPI::VehicleScope::rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes) const {
2817 if (currentTravelTimes) {
2818 // updated edge weights with current network traveltimes (at most once per simulation step)
2819 std::vector<std::string> edges = myParent.edge.getIDList();
2820 for (std::vector<std::string>::iterator it = edges.begin(); it != edges.end(); ++it) {
2821 myParent.edge.adaptTraveltime(*it, myParent.edge.getTraveltime(*it));
2822 }
2823 }
2824
2825 tcpip::Storage content;
2827 content.writeInt(0);
2828 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_REROUTE_TRAVELTIME, vehicleID, &content);
2829 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2830}
2831
2832void
2833TraCIAPI::VehicleScope::moveTo(const std::string& vehicleID, const std::string& laneID, double position, int reason) const {
2834 tcpip::Storage content;
2836 content.writeInt(3);
2838 content.writeString(laneID);
2840 content.writeDouble(position);
2842 content.writeInt(reason);
2843 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MOVE_TO, vehicleID, &content);
2844 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2845}
2846
2847void
2848TraCIAPI::VehicleScope::moveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const {
2849 tcpip::Storage content;
2851 content.writeInt(6);
2853 content.writeString(edgeID);
2855 content.writeInt(lane);
2857 content.writeDouble(x);
2859 content.writeDouble(y);
2861 content.writeDouble(angle);
2863 content.writeByte(keepRoute);
2864 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::MOVE_TO_XY, vehicleID, &content);
2865 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2866}
2867
2868
2869void
2870TraCIAPI::VehicleScope::slowDown(const std::string& vehicleID, double speed, double duration) const {
2871 tcpip::Storage content;
2873 content.writeInt(2);
2875 content.writeDouble(speed);
2877 content.writeDouble(duration);
2878 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_SLOWDOWN, vehicleID, &content);
2879 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2880}
2881
2882void
2883TraCIAPI::VehicleScope::openGap(const std::string& vehicleID, double newTau, double duration, double changeRate, double maxDecel) const {
2884 tcpip::Storage content;
2886 if (maxDecel > 0) {
2887 content.writeInt(4);
2888 } else {
2889 content.writeInt(3);
2890 }
2892 content.writeDouble(newTau);
2894 content.writeDouble(duration);
2896 content.writeDouble(changeRate);
2897 if (maxDecel > 0) {
2899 content.writeDouble(maxDecel);
2900 }
2901 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_OPENGAP, vehicleID, &content);
2902 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2903}
2904
2905void
2906TraCIAPI::VehicleScope::setSpeed(const std::string& vehicleID, double speed) const {
2907 tcpip::Storage content;
2909 content.writeDouble(speed);
2910 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEED, vehicleID, &content);
2911 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2912}
2913
2914void
2915TraCIAPI::VehicleScope::setAcceleration(const std::string& vehicleID, double accel, double duration) const {
2916 tcpip::Storage content;
2918 content.writeInt(2);
2920 content.writeDouble(accel);
2922 content.writeDouble(duration);
2923 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ACCELERATION, vehicleID, &content);
2924 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2925}
2926
2927void
2928TraCIAPI::VehicleScope::setPreviousSpeed(const std::string& vehicleID, double prevSpeed, double prevAcceleration) const {
2929 tcpip::Storage content;
2931 content.writeInt(2);
2933 content.writeDouble(prevSpeed);
2935 content.writeDouble(prevAcceleration);
2936 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_PREV_SPEED, vehicleID, &content);
2937 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2938}
2939
2940void
2941TraCIAPI::VehicleScope::setLaneChangeMode(const std::string& vehicleID, int mode) const {
2942 tcpip::Storage content;
2944 content.writeInt(mode);
2945 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_LANECHANGE_MODE, vehicleID, &content);
2946 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2947}
2948
2949void
2950TraCIAPI::VehicleScope::setSpeedMode(const std::string& vehicleID, int mode) const {
2951 tcpip::Storage content;
2953 content.writeInt(mode);
2954 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEEDSETMODE, vehicleID, &content);
2955 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2956}
2957
2958void
2959TraCIAPI::VehicleScope::setStop(const std::string vehicleID, const std::string edgeID, const double endPos, const int laneIndex,
2960 const double duration, const int flags, const double startPos, const double until) const {
2961 tcpip::Storage content;
2963 content.writeInt(7);
2965 content.writeString(edgeID);
2967 content.writeDouble(endPos);
2969 content.writeByte(laneIndex);
2971 content.writeDouble(duration);
2973 content.writeByte(flags);
2975 content.writeDouble(startPos);
2977 content.writeDouble(until);
2978 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_STOP, vehicleID, &content);
2979 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2980}
2981
2982void
2983TraCIAPI::VehicleScope::setType(const std::string& vehicleID, const std::string& typeID) const {
2984 tcpip::Storage content;
2986 content.writeString(typeID);
2987 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_TYPE, vehicleID, &content);
2988 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2989}
2990
2991void
2992TraCIAPI::VehicleScope::setSpeedFactor(const std::string& vehicleID, double factor) const {
2993 tcpip::Storage content;
2995 content.writeDouble(factor);
2996 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEED_FACTOR, vehicleID, &content);
2997 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2998}
2999
3000void
3001TraCIAPI::VehicleScope::setMinGap(const std::string& vehicleID, double minGap) const {
3002 tcpip::Storage content;
3004 content.writeDouble(minGap);
3005 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MINGAP, vehicleID, &content);
3006 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3007}
3008
3009void
3010TraCIAPI::VehicleScope::setMaxSpeed(const std::string& vehicleID, double speed) const {
3011 tcpip::Storage content;
3013 content.writeDouble(speed);
3014 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MAXSPEED, vehicleID, &content);
3015 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3016}
3017
3018void
3019TraCIAPI::VehicleScope::setColor(const std::string& vehicleID, const libsumo::TraCIColor& c) const {
3020 tcpip::Storage content;
3022 content.writeUnsignedByte(c.r);
3023 content.writeUnsignedByte(c.g);
3024 content.writeUnsignedByte(c.b);
3025 content.writeUnsignedByte(c.a);
3026 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_COLOR, vehicleID, &content);
3027 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3028}
3029
3030void
3031TraCIAPI::VehicleScope::setLine(const std::string& vehicleID, const std::string& line) const {
3032 tcpip::Storage content;
3034 content.writeString(line);
3035 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_LINE, vehicleID, &content);
3036 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3037}
3038
3039void
3040TraCIAPI::VehicleScope::setVia(const std::string& vehicleID, const std::vector<std::string>& via) const {
3041 tcpip::Storage content;
3043 content.writeInt((int)via.size());
3044 for (int i = 0; i < (int)via.size(); ++i) {
3045 content.writeString(via[i]);
3046 }
3047 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_VIA, vehicleID, &content);
3048 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3049}
3050
3051void
3052TraCIAPI::VehicleScope::setSignals(const std::string& vehicleID, int signals) const {
3053 tcpip::Storage content;
3055 content.writeInt(signals);
3056 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SIGNALS, vehicleID, &content);
3057 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3058}
3059
3060void
3061TraCIAPI::VehicleScope::setRoutingMode(const std::string& vehicleID, int routingMode) const {
3062 tcpip::Storage content;
3064 content.writeInt(routingMode);
3065 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTING_MODE, vehicleID, &content);
3066 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3067}
3068
3069void
3070TraCIAPI::VehicleScope::setShapeClass(const std::string& vehicleID, const std::string& clazz) const {
3071 tcpip::Storage content;
3073 content.writeString(clazz);
3074 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SHAPECLASS, vehicleID, &content);
3075 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3076}
3077
3078
3079void
3080TraCIAPI::VehicleScope::setEmissionClass(const std::string& vehicleID, const std::string& clazz) const {
3081 tcpip::Storage content;
3083 content.writeString(clazz);
3084 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_EMISSIONCLASS, vehicleID, &content);
3085 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3086}
3087
3088void
3090 bool noOpposite, double downstreamDist, double upstreamDist) const {
3091 addSubscriptionFilterByteList(libsumo::FILTER_TYPE_LANES, lanes);
3092 if (noOpposite) {
3093 addSubscriptionFilterNoOpposite();
3094 }
3095 if (downstreamDist >= 0) {
3096 addSubscriptionFilterDownstreamDistance(downstreamDist);
3097 }
3098 if (upstreamDist >= 0) {
3099 addSubscriptionFilterUpstreamDistance(upstreamDist);
3100 }
3101}
3102
3103
3104void
3108
3109void
3113
3114void
3116 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_UPSTREAM_DIST, dist);
3117}
3118
3119
3120void
3121TraCIAPI::VehicleScope::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) const {
3122 addSubscriptionFilterLeadFollow(std::vector<int>({0}));
3123 if (downstreamDist >= 0) {
3124 addSubscriptionFilterDownstreamDistance(downstreamDist);
3125 }
3126 if (upstreamDist >= 0) {
3127 addSubscriptionFilterUpstreamDistance(upstreamDist);
3128 }
3129}
3130
3131void
3132TraCIAPI::VehicleScope::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) const {
3133 if (abs(direction) != 1) {
3134 std::cerr << "Ignoring lane change subscription filter with non-neighboring lane offset direction " << direction << "\n";
3135 return;
3136 }
3137 addSubscriptionFilterLeadFollow(std::vector<int>({0, direction}));
3138 if (noOpposite) {
3139 addSubscriptionFilterNoOpposite();
3140 }
3141 if (downstreamDist >= 0) {
3142 addSubscriptionFilterDownstreamDistance(downstreamDist);
3143 }
3144 if (upstreamDist >= 0) {
3145 addSubscriptionFilterUpstreamDistance(upstreamDist);
3146 }
3147}
3148
3149void
3151 addSubscriptionFilterEmpty(libsumo::FILTER_TYPE_LEAD_FOLLOW);
3152 addSubscriptionFilterByteList(libsumo::FILTER_TYPE_LANES, lanes);
3153}
3154
3155void
3156TraCIAPI::VehicleScope::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) const {
3157 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_TURN, foeDistToJunction);
3158 if (downstreamDist >= 0) {
3159 addSubscriptionFilterDownstreamDistance(downstreamDist);
3160 }
3161}
3162
3163
3164void
3165TraCIAPI::VehicleScope::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) const {
3166 addSubscriptionFilterStringList(libsumo::FILTER_TYPE_VCLASS, vClasses);
3167}
3168
3169
3170void
3171TraCIAPI::VehicleScope::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) const {
3172 addSubscriptionFilterStringList(libsumo::FILTER_TYPE_VTYPE, vTypes);
3173}
3174
3175
3176void
3178 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_FIELD_OF_VISION, angle);
3179}
3180
3181void
3182TraCIAPI::VehicleScope::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) const {
3183 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_LATERAL_DIST, lateralDist);
3184 if (downstreamDist >= 0) {
3185 addSubscriptionFilterDownstreamDistance(downstreamDist);
3186 }
3187 if (upstreamDist >= 0) {
3188 addSubscriptionFilterUpstreamDistance(upstreamDist);
3189 }
3190}
3191
3192void
3194 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType);
3195 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3196}
3197
3198void
3200 tcpip::Storage content;
3202 content.writeDouble(val);
3203 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3204 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3205}
3206
3207
3208void
3209TraCIAPI::VehicleScope::addSubscriptionFilterStringList(int filterType, const std::vector<std::string>& vals) const {
3210 tcpip::Storage content;
3212 content.writeStringList(vals);
3213 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3214 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3215}
3216
3217
3218void
3219TraCIAPI::VehicleScope::addSubscriptionFilterByteList(int filterType, const std::vector<int>& vals) const {
3220 tcpip::Storage content;
3221 content.writeUnsignedByte((int)vals.size());
3222 for (int i : vals) {
3223 content.writeByte(i);
3224 }
3225 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3226 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3227}
3228
3229
3230// ---------------------------------------------------------------------------
3231// TraCIAPI::PersonScope-methods
3232// ---------------------------------------------------------------------------
3233double
3234TraCIAPI::PersonScope::getSpeed(const std::string& personID) const {
3235 return getDouble(libsumo::VAR_SPEED, personID);
3236}
3237
3239TraCIAPI::PersonScope::getPosition(const std::string& personID) const {
3240 return getPos(libsumo::VAR_POSITION, personID);
3241}
3242
3244TraCIAPI::PersonScope::getPosition3D(const std::string& personID) const {
3245 return getPos3D(libsumo::VAR_POSITION3D, personID);
3246}
3247
3248double
3249TraCIAPI::PersonScope::getAngle(const std::string& personID) const {
3250 return getDouble(libsumo::VAR_ANGLE, personID);
3251}
3252
3253double
3254TraCIAPI::PersonScope::getSlope(const std::string& personID) const {
3255 return getDouble(libsumo::VAR_SLOPE, personID);
3256}
3257
3258double
3259TraCIAPI::PersonScope::getLanePosition(const std::string& personID) const {
3260 return getDouble(libsumo::VAR_LANEPOSITION, personID);
3261}
3262
3264TraCIAPI::PersonScope::getColor(const std::string& personID) const {
3265 return getCol(libsumo::VAR_COLOR, personID);
3266}
3267
3268double
3269TraCIAPI::PersonScope::getLength(const std::string& personID) const {
3270 return getDouble(libsumo::VAR_LENGTH, personID);
3271}
3272
3273std::string
3274TraCIAPI::PersonScope::getRoadID(const std::string& personID) const {
3275 return getString(libsumo::VAR_ROAD_ID, personID);
3276}
3277
3278std::string
3279TraCIAPI::PersonScope::getLaneID(const std::string& personID) const {
3280 return getString(libsumo::VAR_LANE_ID, personID);
3281}
3282
3283std::string
3284TraCIAPI::PersonScope::getTypeID(const std::string& personID) const {
3285 return getString(libsumo::VAR_TYPE, personID);
3286}
3287
3288double
3289TraCIAPI::PersonScope::getSpeedFactor(const std::string& personID) const {
3290 return getDouble(libsumo::VAR_SPEED_FACTOR, personID);
3291}
3292
3293double
3294TraCIAPI::PersonScope::getWaitingTime(const std::string& personID) const {
3295 return getDouble(libsumo::VAR_WAITING_TIME, personID);
3296}
3297
3298std::string
3299TraCIAPI::PersonScope::getNextEdge(const std::string& personID) const {
3300 return getString(libsumo::VAR_NEXT_EDGE, personID);
3301}
3302
3303
3304std::string
3305TraCIAPI::PersonScope::getVehicle(const std::string& personID) const {
3306 return getString(libsumo::VAR_VEHICLE, personID);
3307}
3308
3309int
3310TraCIAPI::PersonScope::getRemainingStages(const std::string& personID) const {
3311 return getInt(libsumo::VAR_STAGES_REMAINING, personID);
3312}
3313
3315TraCIAPI::PersonScope::getStage(const std::string& personID, int nextStageIndex) const {
3316 tcpip::Storage content;
3318 content.writeInt(nextStageIndex);
3319 return getTraCIStage(libsumo::VAR_STAGE, personID, &content);
3320}
3321
3322std::vector<std::string>
3323TraCIAPI::PersonScope::getEdges(const std::string& personID, int nextStageIndex) const {
3324 tcpip::Storage content;
3326 content.writeInt(nextStageIndex);
3327 return getStringVector(libsumo::VAR_EDGES, personID, &content);
3328}
3329
3330void
3331TraCIAPI::PersonScope::removeStages(const std::string& personID) const {
3332 // remove all stages after the current and then abort the current stage
3333 while (getRemainingStages(personID) > 1) {
3334 removeStage(personID, 1);
3335 }
3336 removeStage(personID, 0);
3337}
3338
3339
3340void
3341TraCIAPI::PersonScope::rerouteTraveltime(const std::string& personID) const {
3342 tcpip::Storage content;
3344 content.writeInt(0);
3345 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::CMD_REROUTE_TRAVELTIME, personID, &content);
3346 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3347}
3348
3349
3350void
3351TraCIAPI::PersonScope::add(const std::string& personID, const std::string& edgeID, double pos, double depart, const std::string typeID) {
3352 tcpip::Storage content;
3354 content.writeInt(4);
3356 content.writeString(typeID);
3358 content.writeString(edgeID);
3360 content.writeDouble(depart);
3362 content.writeDouble(pos);
3363 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::ADD, personID, &content);
3364 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3365}
3366
3367void
3368TraCIAPI::PersonScope::appendStage(const std::string& personID, const libsumo::TraCIStage& stage) {
3369 tcpip::Storage content;
3371 content.writeInt(13);
3373 content.writeInt(stage.type);
3375 content.writeString(stage.vType);
3377 content.writeString(stage.line);
3379 content.writeString(stage.destStop);
3381 content.writeStringList(stage.edges);
3383 content.writeDouble(stage.travelTime);
3385 content.writeDouble(stage.cost);
3387 content.writeDouble(stage.length);
3389 content.writeString(stage.intended);
3391 content.writeDouble(stage.depart);
3393 content.writeDouble(stage.departPos);
3395 content.writeDouble(stage.arrivalPos);
3397 content.writeString(stage.description);
3398 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3399 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3400}
3401
3402
3403void
3404TraCIAPI::PersonScope::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
3405 tcpip::Storage content;
3407 content.writeInt(4);
3411 content.writeDouble(duration);
3413 content.writeString(description);
3415 content.writeString(stopID);
3416 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3417 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3418}
3419
3420void
3421TraCIAPI::PersonScope::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
3422 tcpip::Storage content;
3424 content.writeInt(6);
3428 content.writeStringList(edges);
3430 content.writeDouble(arrivalPos);
3432 content.writeDouble(duration);
3434 content.writeDouble(speed);
3436 content.writeString(stopID);
3437 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3438 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3439}
3440
3441void
3442TraCIAPI::PersonScope::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
3443 tcpip::Storage content;
3445 content.writeInt(4);
3449 content.writeString(toEdge);
3451 content.writeString(lines);
3453 content.writeString(stopID);
3454 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3455 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3456}
3457
3458void
3459TraCIAPI::PersonScope::removeStage(const std::string& personID, int nextStageIndex) const {
3460 tcpip::Storage content;
3462 content.writeInt(nextStageIndex);
3463 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::REMOVE_STAGE, personID, &content);
3464 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3465}
3466
3467void
3468TraCIAPI::PersonScope::moveTo(const std::string& personID, const std::string& edgeID, double position) const {
3469 tcpip::Storage content;
3471 content.writeInt(2);
3473 content.writeString(edgeID);
3475 content.writeDouble(position);
3476 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_MOVE_TO, personID, &content);
3477 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3478}
3479
3480void
3481TraCIAPI::PersonScope::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute) const {
3482 tcpip::Storage content;
3484 content.writeInt(5);
3486 content.writeString(edgeID);
3488 content.writeDouble(x);
3490 content.writeDouble(y);
3492 content.writeDouble(angle);
3494 content.writeByte(keepRoute);
3495 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::MOVE_TO_XY, personID, &content);
3496 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3497}
3498
3499void
3500TraCIAPI::PersonScope::setSpeed(const std::string& personID, double speed) const {
3501 tcpip::Storage content;
3503 content.writeDouble(speed);
3504 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_SPEED, personID, &content);
3505 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3506}
3507
3508
3509void
3510TraCIAPI::PersonScope::setType(const std::string& personID, const std::string& typeID) const {
3511 tcpip::Storage content;
3513 content.writeString(typeID);
3514 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_TYPE, personID, &content);
3515 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3516}
3517
3518void
3519TraCIAPI::PersonScope::setSpeedFactor(const std::string& personID, double factor) const {
3520 tcpip::Storage content;
3522 content.writeDouble(factor);
3523 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_SPEED_FACTOR, personID, &content);
3524 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3525}
3526
3527void
3528TraCIAPI::PersonScope::setLength(const std::string& personID, double length) const {
3529 tcpip::Storage content;
3531 content.writeDouble(length);
3532 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_LENGTH, personID, &content);
3533 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3534}
3535
3536
3537void
3538TraCIAPI::PersonScope::setWidth(const std::string& personID, double width) const {
3539 tcpip::Storage content;
3541 content.writeDouble(width);
3542 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_WIDTH, personID, &content);
3543 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3544}
3545
3546void
3547TraCIAPI::PersonScope::setHeight(const std::string& personID, double height) const {
3548 tcpip::Storage content;
3550 content.writeDouble(height);
3551 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_HEIGHT, personID, &content);
3552 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3553}
3554
3555void
3556TraCIAPI::PersonScope::setMinGap(const std::string& personID, double minGap) const {
3557 tcpip::Storage content;
3559 content.writeDouble(minGap);
3560 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_MINGAP, personID, &content);
3561 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3562}
3563
3564
3565void
3566TraCIAPI::PersonScope::setColor(const std::string& personID, const libsumo::TraCIColor& c) const {
3567 tcpip::Storage content;
3569 content.writeUnsignedByte(c.r);
3570 content.writeUnsignedByte(c.g);
3571 content.writeUnsignedByte(c.b);
3572 content.writeUnsignedByte(c.a);
3573 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_COLOR, personID, &content);
3574 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3575}
3576
3577
3578// ---------------------------------------------------------------------------
3579// TraCIAPI::TraCIScopeWrapper-methods
3580// ---------------------------------------------------------------------------
3581
3582int
3583TraCIAPI::TraCIScopeWrapper::getUnsignedByte(int var, const std::string& id, tcpip::Storage* add) const {
3584 myParent.createCommand(myCmdGetID, var, id, add);
3585 if (myParent.processGet(myCmdGetID, libsumo::TYPE_UBYTE)) {
3586 return myParent.myInput.readUnsignedByte();
3587 }
3589}
3590
3591
3592int
3593TraCIAPI::TraCIScopeWrapper::getByte(int var, const std::string& id, tcpip::Storage* add) const {
3594 myParent.createCommand(myCmdGetID, var, id, add);
3595 if (myParent.processGet(myCmdGetID, libsumo::TYPE_BYTE)) {
3596 return myParent.myInput.readByte();
3597 }
3599}
3600
3601
3602
3603int
3604TraCIAPI::TraCIScopeWrapper::getInt(int var, const std::string& id, tcpip::Storage* add) const {
3605 myParent.createCommand(myCmdGetID, var, id, add);
3606 if (myParent.processGet(myCmdGetID, libsumo::TYPE_INTEGER)) {
3607 return myParent.myInput.readInt();
3608 }
3610}
3611
3612
3613double
3614TraCIAPI::TraCIScopeWrapper::getDouble(int var, const std::string& id, tcpip::Storage* add) const {
3615 myParent.createCommand(myCmdGetID, var, id, add);
3616 if (myParent.processGet(myCmdGetID, libsumo::TYPE_DOUBLE)) {
3617 return myParent.myInput.readDouble();
3618 }
3620}
3621
3622
3624TraCIAPI::TraCIScopeWrapper::getPolygon(int var, const std::string& id, tcpip::Storage* add) const {
3626 myParent.createCommand(myCmdGetID, var, id, add);
3627 if (myParent.processGet(myCmdGetID, libsumo::TYPE_POLYGON)) {
3628 int size = myParent.myInput.readUnsignedByte();
3629 if (size == 0) {
3630 size = myParent.myInput.readInt();
3631 }
3632 for (int i = 0; i < size; ++i) {
3634 p.x = myParent.myInput.readDouble();
3635 p.y = myParent.myInput.readDouble();
3636 p.z = 0.;
3637 ret.value.push_back(p);
3638 }
3639 }
3640 return ret;
3641}
3642
3643
3645TraCIAPI::TraCIScopeWrapper::getPos(int var, const std::string& id, tcpip::Storage* add) const {
3647 myParent.createCommand(myCmdGetID, var, id, add);
3648 if (myParent.processGet(myCmdGetID, libsumo::POSITION_2D)) {
3649 p.x = myParent.myInput.readDouble();
3650 p.y = myParent.myInput.readDouble();
3651 p.z = 0;
3652 }
3653 return p;
3654}
3655
3656
3658TraCIAPI::TraCIScopeWrapper::getPos3D(int var, const std::string& id, tcpip::Storage* add) const {
3660 myParent.createCommand(myCmdGetID, var, id, add);
3661 if (myParent.processGet(myCmdGetID, libsumo::POSITION_3D)) {
3662 p.x = myParent.myInput.readDouble();
3663 p.y = myParent.myInput.readDouble();
3664 p.z = myParent.myInput.readDouble();
3665 }
3666 return p;
3667}
3668
3669
3670std::string
3671TraCIAPI::TraCIScopeWrapper::getString(int var, const std::string& id, tcpip::Storage* add) const {
3672 myParent.createCommand(myCmdGetID, var, id, add);
3673 if (myParent.processGet(myCmdGetID, libsumo::TYPE_STRING)) {
3674 return myParent.myInput.readString();
3675 }
3676 return "";
3677}
3678
3679
3680std::vector<std::string>
3681TraCIAPI::TraCIScopeWrapper::getStringVector(int var, const std::string& id, tcpip::Storage* add) const {
3682 std::vector<std::string> r;
3683 myParent.createCommand(myCmdGetID, var, id, add);
3684 if (myParent.processGet(myCmdGetID, libsumo::TYPE_STRINGLIST)) {
3685 const int size = myParent.myInput.readInt();
3686 for (int i = 0; i < size; ++i) {
3687 r.push_back(myParent.myInput.readString());
3688 }
3689 }
3690 return r;
3691}
3692
3693
3694std::vector<double>
3695TraCIAPI::TraCIScopeWrapper::getDoubleVector(int var, const std::string& id, tcpip::Storage* add) const {
3696 std::vector<double> r;
3697 myParent.createCommand(myCmdGetID, var, id, add);
3698 if (myParent.processGet(myCmdGetID, libsumo::TYPE_DOUBLELIST)) {
3699 const int size = myParent.myInput.readInt();
3700 for (int i = 0; i < size; ++i) {
3701 r.push_back(myParent.myInput.readDouble());
3702 }
3703 }
3704 return r;
3705}
3706
3707
3709TraCIAPI::TraCIScopeWrapper::getCol(int var, const std::string& id, tcpip::Storage* add) const {
3711 myParent.createCommand(myCmdGetID, var, id, add);
3712 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COLOR)) {
3713 c.r = (unsigned char)myParent.myInput.readUnsignedByte();
3714 c.g = (unsigned char)myParent.myInput.readUnsignedByte();
3715 c.b = (unsigned char)myParent.myInput.readUnsignedByte();
3716 c.a = (unsigned char)myParent.myInput.readUnsignedByte();
3717 }
3718 return c;
3719}
3720
3721
3723TraCIAPI::TraCIScopeWrapper::getTraCIStage(int var, const std::string& id, tcpip::Storage* add) const {
3725 myParent.createCommand(myCmdGetID, var, id, add);
3726 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COMPOUND)) {
3727 myParent.myInput.readInt(); // components
3728 myParent.myInput.readUnsignedByte();
3729 s.type = myParent.myInput.readInt();
3730
3731 myParent.myInput.readUnsignedByte();
3732 s.vType = myParent.myInput.readString();
3733
3734 myParent.myInput.readUnsignedByte();
3735 s.line = myParent.myInput.readString();
3736
3737 myParent.myInput.readUnsignedByte();
3738 s.destStop = myParent.myInput.readString();
3739
3740 myParent.myInput.readUnsignedByte();
3741 s.edges = myParent.myInput.readStringList();
3742
3743 myParent.myInput.readUnsignedByte();
3744 s.travelTime = myParent.myInput.readDouble();
3745
3746 myParent.myInput.readUnsignedByte();
3747 s.cost = myParent.myInput.readDouble();
3748
3749 myParent.myInput.readUnsignedByte();
3750 s.length = myParent.myInput.readDouble();
3751
3752 myParent.myInput.readUnsignedByte();
3753 s.intended = myParent.myInput.readString();
3754
3755 myParent.myInput.readUnsignedByte();
3756 s.depart = myParent.myInput.readDouble();
3757
3758 myParent.myInput.readUnsignedByte();
3759 s.departPos = myParent.myInput.readDouble();
3760
3761 myParent.myInput.readUnsignedByte();
3762 s.arrivalPos = myParent.myInput.readDouble();
3763
3764 myParent.myInput.readUnsignedByte();
3765 s.description = myParent.myInput.readString();
3766 }
3767 return s;
3768}
3769
3770
3771std::vector<std::string>
3773 return getStringVector(libsumo::TRACI_ID_LIST, "");
3774}
3775
3776
3777int
3779 return getInt(libsumo::ID_COUNT, "");
3780}
3781
3782
3783std::string
3784TraCIAPI::TraCIScopeWrapper::getParameter(const std::string& objectID, const std::string& key) const {
3785 tcpip::Storage content;
3787 content.writeString(key);
3788 return getString(libsumo::VAR_PARAMETER, objectID, &content);
3789}
3790
3791
3792std::pair<std::string, std::string>
3793TraCIAPI::TraCIScopeWrapper::getParameterWithKey(const std::string& objectID, const std::string& key) const {
3794 tcpip::Storage content;
3796 content.writeString(key);
3797
3798 myParent.createCommand(myCmdGetID, libsumo::VAR_PARAMETER_WITH_KEY, objectID, &content);
3799 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COMPOUND)) {
3800 myParent.myInput.readInt(); // number of components
3801 myParent.myInput.readUnsignedByte();
3802 const std::string returnedKey = myParent.myInput.readString();
3803 myParent.myInput.readUnsignedByte();
3804 const std::string value = myParent.myInput.readString();
3805 return std::make_pair(returnedKey, value);
3806 }
3807 return std::make_pair(key, "");
3808}
3809
3810
3811void
3812TraCIAPI::TraCIScopeWrapper::setParameter(const std::string& objectID, const std::string& key, const std::string& value) const {
3813 tcpip::Storage content;
3815 content.writeInt(2);
3817 content.writeString(key);
3819 content.writeString(value);
3820 myParent.createCommand(myCmdSetID, libsumo::VAR_PARAMETER, objectID, &content);
3821 myParent.processSet(myCmdSetID);
3822}
3823
3824
3825void
3826TraCIAPI::TraCIScopeWrapper::setInt(int var, const std::string& id, int value) const {
3827 tcpip::Storage content;
3829 content.writeInt(value);
3830 myParent.createCommand(myCmdSetID, var, id, &content);
3831 myParent.processSet(myCmdSetID);
3832}
3833
3834
3835void
3836TraCIAPI::TraCIScopeWrapper::setDouble(int var, const std::string& id, double value) const {
3837 tcpip::Storage content;
3839 content.writeDouble(value);
3840 myParent.createCommand(myCmdSetID, var, id, &content);
3841 myParent.processSet(myCmdSetID);
3842}
3843
3844
3845void
3846TraCIAPI::TraCIScopeWrapper::setString(int var, const std::string& id, const std::string& value) const {
3847 tcpip::Storage content;
3849 content.writeString(value);
3850 myParent.createCommand(myCmdSetID, var, id, &content);
3851 myParent.processSet(myCmdSetID);
3852}
3853
3854
3855void
3856TraCIAPI::TraCIScopeWrapper::setStringVector(int var, const std::string& id, const std::vector<std::string>& value) const {
3857 tcpip::Storage content;
3859 content.writeInt((int)value.size());
3860 for (const std::string& s : value) {
3861 content.writeString(s);
3862 }
3863 myParent.createCommand(myCmdSetID, var, id, &content);
3864 myParent.processSet(myCmdSetID);
3865}
3866
3867
3868void
3869TraCIAPI::TraCIScopeWrapper::subscribe(const std::string& objID, const std::vector<int>& vars, double beginTime, double endTime) const {
3870 myParent.send_commandSubscribeObjectVariable(mySubscribeID, objID, beginTime, endTime, vars);
3871 tcpip::Storage inMsg;
3872 myParent.check_resultState(inMsg, mySubscribeID);
3873 if (vars.size() > 0) {
3874 myParent.check_commandGetResult(inMsg, mySubscribeID);
3875 myParent.readVariableSubscription(mySubscribeID + 0x10, inMsg);
3876 }
3877}
3878
3879
3880void
3881TraCIAPI::TraCIScopeWrapper::subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars, double beginTime, double endTime) const {
3882 myParent.send_commandSubscribeObjectContext(myContextSubscribeID, objID, beginTime, endTime, domain, range, vars);
3883 tcpip::Storage inMsg;
3884 myParent.check_resultState(inMsg, myContextSubscribeID);
3885 myParent.check_commandGetResult(inMsg, myContextSubscribeID);
3886 myParent.readContextSubscription(myContextSubscribeID + 0x60, inMsg);
3887}
3888
3889
3892 return mySubscriptionResults;
3893}
3894
3895
3898 if (mySubscriptionResults.find(objID) != mySubscriptionResults.end()) {
3899 return mySubscriptionResults.find(objID)->second;
3900 } else {
3901 return libsumo::TraCIResults();
3902 }
3903}
3904
3905
3908 return myContextSubscriptionResults;
3909}
3910
3911
3914 if (myContextSubscriptionResults.find(objID) != myContextSubscriptionResults.end()) {
3915 return myContextSubscriptionResults.find(objID)->second;
3916 } else {
3918 }
3919}
3920
3921
3922void
3924 mySubscriptionResults.clear();
3925 myContextSubscriptionResults.clear();
3926}
3927
3928
3931 return mySubscriptionResults;
3932}
3933
3934
3937 return myContextSubscriptionResults[objID];
3938}
3939
3940
3941/****************************************************************************/
double getElectricityConsumption(const std::string &edgeID) const
Definition TraCIAPI.cpp:554
double getLastStepHaltingNumber(const std::string &edgeID) const
Definition TraCIAPI.cpp:589
double getHCEmission(const std::string &edgeID) const
Definition TraCIAPI.cpp:529
void adaptTraveltime(const std::string &edgeID, double time, double beginSeconds=0., double endSeconds=std::numeric_limits< double >::max()) const
Definition TraCIAPI.cpp:612
double getLastStepOccupancy(const std::string &edgeID) const
Definition TraCIAPI.cpp:569
double getLastStepLength(const std::string &edgeID) const
Definition TraCIAPI.cpp:574
std::vector< std::string > getLastStepVehicleIDs(const std::string &edgeID) const
Definition TraCIAPI.cpp:594
double getNOxEmission(const std::string &edgeID) const
Definition TraCIAPI.cpp:539
void setMaxSpeed(const std::string &edgeID, double speed) const
Definition TraCIAPI.cpp:651
double getCO2Emission(const std::string &edgeID) const
Definition TraCIAPI.cpp:518
double getCOEmission(const std::string &edgeID) const
Definition TraCIAPI.cpp:524
int getLaneNumber(const std::string &edgeID) const
Definition TraCIAPI.cpp:600
double getMaxSpeed(const std::string &edgeID) const
Definition TraCIAPI.cpp:564
void setEffort(const std::string &edgeID, double effort, double beginSeconds=0., double endSeconds=std::numeric_limits< double >::max()) const
Definition TraCIAPI.cpp:632
double getNoiseEmission(const std::string &edgeID) const
Definition TraCIAPI.cpp:549
double getFuelConsumption(const std::string &edgeID) const
Definition TraCIAPI.cpp:544
double getTraveltime(const std::string &edgeID) const
Definition TraCIAPI.cpp:579
int getLastStepVehicleNumber(const std::string &edgeID) const
Definition TraCIAPI.cpp:584
std::string getStreetName(const std::string &id) const
Definition TraCIAPI.cpp:606
double getLastStepMeanSpeed(const std::string &edgeID) const
Definition TraCIAPI.cpp:559
double getPMxEmission(const std::string &edgeID) const
Definition TraCIAPI.cpp:534
double getAdaptedTraveltime(const std::string &edgeID, double time) const
Definition TraCIAPI.cpp:502
double getEffort(const std::string &edgeID, double time) const
Definition TraCIAPI.cpp:510
void setOffset(const std::string &viewID, double x, double y) const
Definition TraCIAPI.cpp:686
libsumo::TraCIPositionVector getBoundary(const std::string &viewID=DEFAULT_VIEW) const
Definition TraCIAPI.cpp:675
std::string getSchema(const std::string &viewID=DEFAULT_VIEW) const
Definition TraCIAPI.cpp:670
void setBoundary(const std::string &viewID, double xmin, double ymin, double xmax, double ymax) const
Definition TraCIAPI.cpp:701
void setZoom(const std::string &viewID, double zoom) const
Definition TraCIAPI.cpp:681
void trackVehicle(const std::string &viewID, const std::string &vehID) const
Definition TraCIAPI.cpp:729
void setSchema(const std::string &viewID, const std::string &schemeName) const
Definition TraCIAPI.cpp:696
libsumo::TraCIPosition getOffset(const std::string &viewID=DEFAULT_VIEW) const
Definition TraCIAPI.cpp:665
double getZoom(const std::string &viewID=DEFAULT_VIEW) const
Definition TraCIAPI.cpp:660
void screenshot(const std::string &viewID, const std::string &filename, const int width=-1, const int height=-1) const
Definition TraCIAPI.cpp:714
std::vector< libsumo::TraCIVehicleData > getVehicleData(const std::string &loopID) const
Definition TraCIAPI.cpp:784
int getIntervalVehicleNumber(const std::string &loopID) const
Definition TraCIAPI.cpp:738
double getPosition(const std::string &loopID) const
Definition TraCIAPI.cpp:743
double getLastStepMeanSpeed(const std::string &loopID) const
Definition TraCIAPI.cpp:758
double getTimeSinceDetection(const std::string &loopID) const
Definition TraCIAPI.cpp:778
double getLastStepMeanLength(const std::string &loopID) const
Definition TraCIAPI.cpp:773
std::vector< std::string > getLastStepVehicleIDs(const std::string &loopID) const
Definition TraCIAPI.cpp:763
double getLastStepOccupancy(const std::string &loopID) const
Definition TraCIAPI.cpp:768
int getLastStepVehicleNumber(const std::string &loopID) const
Definition TraCIAPI.cpp:753
std::string getLaneID(const std::string &loopID) const
Definition TraCIAPI.cpp:748
libsumo::TraCIPosition getPosition(const std::string &junctionID) const
Definition TraCIAPI.cpp:821
libsumo::TraCIPositionVector getShape(const std::string &junctionID) const
Definition TraCIAPI.cpp:826
int getLastStepVehicleNumber(const std::string &laneID) const
Definition TraCIAPI.cpp:985
double getPMxEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:940
int getLastStepHaltingNumber(const std::string &laneID) const
Definition TraCIAPI.cpp:990
std::string getEdgeID(const std::string &laneID) const
Definition TraCIAPI.cpp:920
void setDisallowed(const std::string &laneID, const std::vector< std::string > &disallowedClasses) const
libsumo::TraCIPositionVector getShape(const std::string &laneID) const
Definition TraCIAPI.cpp:915
double getLastStepLength(const std::string &laneID) const
Definition TraCIAPI.cpp:975
void setLength(const std::string &laneID, double length) const
double getLength(const std::string &laneID) const
Definition TraCIAPI.cpp:835
int getLinkNumber(const std::string &laneID) const
Definition TraCIAPI.cpp:860
double getTraveltime(const std::string &laneID) const
Definition TraCIAPI.cpp:980
double getCOEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:930
void setMaxSpeed(const std::string &laneID, double speed) const
std::vector< std::string > getInternalFoes(const std::string &laneID) const
void setAllowed(const std::string &laneID, const std::vector< std::string > &allowedClasses) const
std::vector< std::string > getDisallowed(const std::string &laneID) const
Definition TraCIAPI.cpp:855
double getNoiseEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:955
std::vector< std::string > getAllowed(const std::string &laneID) const
Definition TraCIAPI.cpp:850
double getFuelConsumption(const std::string &laneID) const
Definition TraCIAPI.cpp:950
double getWidth(const std::string &laneID) const
Definition TraCIAPI.cpp:845
double getCO2Emission(const std::string &laneID) const
Definition TraCIAPI.cpp:925
double getHCEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:935
std::vector< libsumo::TraCIConnection > getLinks(const std::string &laneID) const
Definition TraCIAPI.cpp:865
double getMaxSpeed(const std::string &laneID) const
Definition TraCIAPI.cpp:840
std::vector< std::string > getLastStepVehicleIDs(const std::string &laneID) const
Definition TraCIAPI.cpp:995
double getElectricityConsumption(const std::string &laneID) const
Definition TraCIAPI.cpp:960
std::vector< std::string > getFoes(const std::string &laneID, const std::string &toLaneID) const
double getLastStepMeanSpeed(const std::string &laneID) const
Definition TraCIAPI.cpp:965
double getNOxEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:945
double getLastStepOccupancy(const std::string &laneID) const
Definition TraCIAPI.cpp:970
std::vector< std::string > getLastStepVehicleIDs(const std::string &detID) const
int getLastStepVehicleNumber(const std::string &detID) const
std::vector< std::string > getExitLanes(const std::string &detID) const
std::vector< double > getExitPositions(const std::string &detID) const
double getLastStepMeanSpeed(const std::string &detID) const
int getLastStepHaltingNumber(const std::string &detID) const
std::vector< std::string > getEntryLanes(const std::string &detID) const
std::vector< double > getEntryPositions(const std::string &detID) const
libsumo::TraCIColor getColor(const std::string &poiID) const
void add(const std::string &poiID, double x, double y, const libsumo::TraCIColor &c, const std::string &type, int layer, const std::string &imgFile, double width, double height, double angle) const
std::string getImageFile(const std::string &poiID) const
void setWidth(const std::string &poiID, double width) const
libsumo::TraCIPosition getPosition(const std::string &poiID) const
void setImageFile(const std::string &poiID, const std::string &imageFile) const
void setHeight(const std::string &poiID, double height) const
void setAngle(const std::string &poiID, double angle) const
double getHeight(const std::string &poiID) const
double getAngle(const std::string &poiID) const
void remove(const std::string &poiID, int layer=0) const
void setColor(const std::string &poiID, const libsumo::TraCIColor &c) const
void setPosition(const std::string &poiID, double x, double y) const
double getWidth(const std::string &poiID) const
void setType(const std::string &poiID, const std::string &setType) const
std::string getType(const std::string &poiID) const
std::string getNextEdge(const std::string &personID) const
void setLength(const std::string &personID, double length) const
libsumo::TraCIColor getColor(const std::string &personID) const
double getSlope(const std::string &personID) const
int getRemainingStages(const std::string &personID) const
double getWaitingTime(const std::string &personID) const
void setSpeedFactor(const std::string &personID, double factor) const
libsumo::TraCIStage getStage(const std::string &personID, int nextStageIndex=0) const
void removeStage(const std::string &personID, int nextStageIndex) const
void add(const std::string &personID, const std::string &edgeID, double pos, double depart=libsumo::DEPARTFLAG_NOW, const std::string typeID="DEFAULT_PEDTYPE")
void appendWalkingStage(const std::string &personID, const std::vector< std::string > &edges, double arrivalPos, double duration=-1, double speed=-1, const std::string &stopID="")
void setSpeed(const std::string &personID, double speed) const
double getLength(const std::string &personID) const
void moveToXY(const std::string &personID, const std::string &edgeID, const double x, const double y, double angle, const int keepRoute) const
void setHeight(const std::string &personID, double height) const
void setType(const std::string &personID, const std::string &typeID) const
void setMinGap(const std::string &personID, double minGap) const
void moveTo(const std::string &personID, const std::string &edgeID, double position) const
libsumo::TraCIPosition getPosition(const std::string &personID) const
double getSpeedFactor(const std::string &personID) const
void removeStages(const std::string &personID) const
void setColor(const std::string &personID, const libsumo::TraCIColor &c) const
std::string getRoadID(const std::string &personID) const
double getSpeed(const std::string &personID) const
std::string getVehicle(const std::string &personID) const
void appendDrivingStage(const std::string &personID, const std::string &toEdge, const std::string &lines, const std::string &stopID="")
std::string getTypeID(const std::string &personID) const
void appendStage(const std::string &personID, const libsumo::TraCIStage &stage)
double getAngle(const std::string &personID) const
std::string getLaneID(const std::string &personID) const
libsumo::TraCIPosition getPosition3D(const std::string &personID) const
std::vector< std::string > getEdges(const std::string &personID, int nextStageIndex=0) const
void appendWaitingStage(const std::string &personID, double duration, const std::string &description="waiting", const std::string &stopID="")
double getLanePosition(const std::string &personID) const
void setWidth(const std::string &personID, double width) const
void rerouteTraveltime(const std::string &personID) const
void setHeight(const std::string &polygonID, const double height) const
libsumo::TraCIColor getColor(const std::string &polygonID) const
void setType(const std::string &polygonID, const std::string &setType) const
bool getFilled(const std::string &polygonID) const
double getHeight(const std::string &polygonID) const
void add(const std::string &polygonID, const libsumo::TraCIPositionVector &shape, const libsumo::TraCIColor &c, bool fill, const std::string &type, int layer) const
libsumo::TraCIPositionVector getShape(const std::string &polygonID) const
std::string getType(const std::string &polygonID) const
void remove(const std::string &polygonID, int layer=0) const
double getLineWidth(const std::string &polygonID) const
void setColor(const std::string &polygonID, const libsumo::TraCIColor &c) const
void setLineWidth(const std::string &polygonID, const double lineWidth) const
void setShape(const std::string &polygonID, const libsumo::TraCIPositionVector &shape) const
std::vector< std::string > getEdges(const std::string &routeID) const
void add(const std::string &routeID, const std::vector< std::string > &edges) const
double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo=false, bool isDriving=false)
libsumo::TraCIPosition convert2D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false) const
std::vector< std::string > getStartingTeleportIDList() const
int getStartingTeleportNumber() const
int getEndingTeleportNumber() const
int getBusStopWaiting(const std::string &stopID) const
libsumo::TraCIStage findRoute(const std::string &fromEdge, const std::string &toEdge, const std::string &vType="", double pos=-1., int routingMode=0) const
libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo=false, const std::string &vClass="ignoring") const
void loadState(const std::string &path) const
std::vector< std::string > getBusStopWaitingIDList(const std::string &stopID) const
int getDepartedPersonNumber() const
double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
std::vector< std::string > getArrivedPersonIDList() const
void saveState(const std::string &destination) const
std::vector< std::string > getEndingTeleportIDList() const
int getMinExpectedNumber() const
std::vector< std::string > getDepartedPersonIDList() const
std::vector< std::string > getDepartedIDList() const
int getArrivedPersonNumber() const
std::vector< std::string > getLoadedIDList() const
std::vector< std::string > getArrivedIDList() const
std::string getOption(const std::string &option) const
libsumo::TraCIPositionVector getNetBoundary() const
void writeMessage(const std::string msg)
libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo=false) const
libsumo::TraCIPosition convert3D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false) const
int getUnsignedByte(int var, const std::string &id, tcpip::Storage *add=0) const
const libsumo::SubscriptionResults getContextSubscriptionResults(const std::string &objID) const
int getInt(int var, const std::string &id, tcpip::Storage *add=0) const
std::vector< std::string > getStringVector(int var, const std::string &id, tcpip::Storage *add=0) const
double getDouble(int var, const std::string &id, tcpip::Storage *add=0) const
libsumo::TraCIPosition getPos3D(int var, const std::string &id, tcpip::Storage *add=0) const
std::pair< std::string, std::string > getParameterWithKey(const std::string &objectID, const std::string &key) const
retrieve generic parameter and return (key, value) tuple
libsumo::TraCIColor getCol(int var, const std::string &id, tcpip::Storage *add=0) const
const libsumo::SubscriptionResults getAllSubscriptionResults() const
void setStringVector(int var, const std::string &id, const std::vector< std::string > &value) const
std::vector< std::string > getIDList() const
libsumo::TraCIPositionVector getPolygon(int var, const std::string &id, tcpip::Storage *add=0) const
libsumo::SubscriptionResults & getModifiableSubscriptionResults()
const libsumo::TraCIResults getSubscriptionResults(const std::string &objID) const
void setString(int var, const std::string &id, const std::string &value) const
void subscribeContext(const std::string &objID, int domain, double range, const std::vector< int > &vars, double beginTime, double endTime) const
void setParameter(const std::string &objectID, const std::string &key, const std::string &value) const
set generic paramter
std::string getParameter(const std::string &objectID, const std::string &key) const
retrieve generic parameter
std::vector< double > getDoubleVector(int var, const std::string &id, tcpip::Storage *add=0) const
void setInt(int var, const std::string &id, int value) const
int getByte(int var, const std::string &id, tcpip::Storage *add=0) const
libsumo::TraCIStage getTraCIStage(int var, const std::string &id, tcpip::Storage *add=0) const
void subscribe(const std::string &objID, const std::vector< int > &vars, double beginTime, double endTime) const
std::string getString(int var, const std::string &id, tcpip::Storage *add=0) const
libsumo::TraCIPosition getPos(int var, const std::string &id, tcpip::Storage *add=0) const
const libsumo::ContextSubscriptionResults getAllContextSubscriptionResults() const
libsumo::SubscriptionResults & getModifiableContextSubscriptionResults(const std::string &objID)
void setDouble(int var, const std::string &id, double value) const
int getServedPersonCount(const std::string &tlsID, int index) const
std::string getRedYellowGreenState(const std::string &tlsID) const
int getPhase(const std::string &tlsID) const
std::string getPhaseName(const std::string &tlsID) const
void setRedYellowGreenState(const std::string &tlsID, const std::string &state) const
std::string getProgram(const std::string &tlsID) const
void setPhase(const std::string &tlsID, int index) const
void setPhaseName(const std::string &tlsID, const std::string &name) const
double getNextSwitch(const std::string &tlsID) const
std::vector< std::vector< libsumo::TraCILink > > getControlledLinks(const std::string &tlsID) const
double getPhaseDuration(const std::string &tlsID) const
std::vector< std::string > getControlledLanes(const std::string &tlsID) const
std::vector< libsumo::TraCILogic > getAllProgramLogics(const std::string &tlsID) const
void setPhaseDuration(const std::string &tlsID, double phaseDuration) const
void setProgramLogic(const std::string &tlsID, const libsumo::TraCILogic &logic) const
void setProgram(const std::string &tlsID, const std::string &programID) const
std::vector< libsumo::TraCINextTLSData > getNextTLS(const std::string &vehID) const
void changeLane(const std::string &vehicleID, int laneIndex, double duration) const
void setMinGap(const std::string &vehicleID, double minGap) const
double getLateralSpeed(const std::string &vehicleID) const
void setMaxSpeed(const std::string &vehicleID, double speed) const
void setPreviousSpeed(const std::string &vehicleID, double prevSpeed, double prevAcceleration=std::numeric_limits< int >::min()) const
double getSpeed(const std::string &vehicleID) const
int getStopState(const std::string &vehicleID) const
double getWaitingTime(const std::string &vehicleID) const
void addSubscriptionFilterCFManeuver(double downstreamDist=-1, double upstreamDist=-1) const
double getCOEmission(const std::string &vehicleID) const
void addSubscriptionFilterStringList(int filterType, const std::vector< std::string > &vals) const
void changeTarget(const std::string &vehicleID, const std::string &edgeID) const
libsumo::TraCIPosition getPosition(const std::string &vehicleID) const
bool isRouteValid(const std::string &vehicleID) const
void addSubscriptionFilterByteList(int filterType, const std::vector< int > &vals) const
double getSecureGap(const std::string &vehicleID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string &leaderID="") const
void setSpeedFactor(const std::string &vehicleID, double factor) const
void setShapeClass(const std::string &vehicleID, const std::string &clazz) const
void addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist=-1, double foeDistToJunction=-1) const
void setVia(const std::string &vehicleID, const std::vector< std::string > &via) const
void setEmissionClass(const std::string &vehicleID, const std::string &clazz) const
double getTau(const std::string &vehicleID) const
double getDistance(const std::string &vehicleID) const
void remove(const std::string &vehicleID, char reason=libsumo::REMOVE_VAPORIZED) const
void openGap(const std::string &vehicleID, double newTau, double duration, double changeRate, double maxDecel) const
void moveTo(const std::string &vehicleID, const std::string &laneID, double position, int reason=libsumo::MOVE_TELEPORT) const
void setSpeed(const std::string &vehicleID, double speed) const
std::string getEmissionClass(const std::string &vehicleID) const
void setStop(const std::string vehicleID, const std::string edgeID, const double endPos=1., const int laneIndex=0, const double duration=std::numeric_limits< double >::max(), const int flags=0, const double startPos=std::numeric_limits< int >::min(), const double until=-1) const
void setRouteID(const std::string &vehicleID, const std::string &routeID) const
std::pair< int, int > getLaneChangeState(const std::string &vehicleID, int direction) const
double getNoiseEmission(const std::string &vehicleID) const
std::string getShapeClass(const std::string &vehicleID) const
void addSubscriptionFilterLeadFollow(const std::vector< int > &lanes) const
std::string getLine(const std::string &vehicleID) const
double getElectricityConsumption(const std::string &vehicleID) const
double getSpeedFactor(const std::string &vehicleID) const
double getNOxEmission(const std::string &vehicleID) const
void setRoute(const std::string &vehicleID, const std::vector< std::string > &edge) const
int getSignals(const std::string &vehicleID) const
libsumo::TraCIColor getColor(const std::string &vehicleID) const
int getPersonCapacity(const std::string &vehicleID) const
void setSignals(const std::string &vehicleID, int signals) const
std::string getRoadID(const std::string &vehicleID) const
void addSubscriptionFilterVType(const std::vector< std::string > &vTypes) const
void addSubscriptionFilterUpstreamDistance(double dist) const
void addSubscriptionFilterFloat(int filterType, double val) const
double getAllowedSpeed(const std::string &vehicleID) const
void addSubscriptionFilterLanes(const std::vector< int > &lanes, bool noOpposite=false, double downstreamDist=-1, double upstreamDist=-1) const
double getCO2Emission(const std::string &vehicleID) const
double getFuelConsumption(const std::string &vehicleID) const
double getHCEmission(const std::string &vehicleID) const
void addSubscriptionFilterNoOpposite() const
void addSubscriptionFilterLCManeuver(int direction, bool noOpposite=false, double downstreamDist=-1, double upstreamDist=-1) const
std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist) const
double getAcceleration(const std::string &vehicleID) const
std::vector< std::string > getVia(const std::string &vehicleID) const
void addSubscriptionFilterVClass(const std::vector< std::string > &vClasses) const
double getImperfection(const std::string &vehicleID) const
std::string getLaneID(const std::string &vehicleID) const
double getAngle(const std::string &vehicleID) const
void addSubscriptionFilterDownstreamDistance(double dist) const
double getMinGap(const std::string &vehicleID) const
void addSubscriptionFilterEmpty(int filterType) const
double getStopArrivalDelay(const std::string &vehicleID) const
void setAcceleration(const std::string &vehicleID, double accel, double duration) const
std::vector< std::string > getPersonIDList(const std::string &vehicleID) const
double getStopDelay(const std::string &vehicleID) const
double getMinGapLat(const std::string &vehicleID) const
void setLine(const std::string &vehicleID, const std::string &line) const
double getSlope(const std::string &vehicleID) const
void setColor(const std::string &vehicleID, const libsumo::TraCIColor &c) const
void add(const std::string &vehicleID, const std::string &routeID, const std::string &typeID="DEFAULT_VEHTYPE", std::string depart="-1", const std::string &departLane="first", const std::string &departPos="base", const std::string &departSpeed="0", const std::string &arrivalLane="current", const std::string &arrivalPos="max", const std::string &arrivalSpeed="current", const std::string &fromTaz="", const std::string &toTaz="", const std::string &line="", int personCapacity=0, int personNumber=0) const
libsumo::TraCIPosition getPosition3D(const std::string &vehicleID) const
void setLaneChangeMode(const std::string &vehicleID, int mode) const
void setRoutingMode(const std::string &vehicleID, int routingMode) const
void addSubscriptionFilterTurn(double downstreamDist=-1, double upstreamDist=-1) const
double getDecel(const std::string &vehicleID) const
void moveToXY(const std::string &vehicleID, const std::string &edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const
double getHeight(const std::string &veihcleID) const
std::string getShadowLaneID(const std::string &vehicleID) const
int getRouteIndex(const std::string &vehicleID) const
double getMaxSpeedLat(const std::string &vehicleID) const
void changeSublane(const std::string &vehicleID, double latDist) const
std::string getLateralAlignment(const std::string &vehicleID) const
std::string getRouteID(const std::string &vehicleID) const
double getLanePosition(const std::string &vehicleID) const
int getLaneChangeMode(const std::string &vehicleID) const
int getSpeedMode(const std::string &vehicleID) const
std::vector< std::string > getRoute(const std::string &vehicleID) const
double getLateralLanePosition(const std::string &vehicleID) const
std::pair< std::string, double > getFollower(const std::string &vehicleID, double dist) const
double getPMxEmission(const std::string &vehicleID) const
double getLength(const std::string &vehicleID) const
double getMaxSpeed(const std::string &vehicleID) const
std::string getVehicleClass(const std::string &vehicleID) const
double getSpeedWithoutTraCI(const std::string &vehicleID) const
int getRoutingMode(const std::string &vehicleID) const
double getWidth(const std::string &vehicleID) const
double getSpeedDeviation(const std::string &vehicleID) const
int getPersonNumber(const std::string &vehicleID) const
double getFollowSpeed(const std::string &vehicleID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string &leaderID="") const
void setType(const std::string &vehicleID, const std::string &typeID) const
void addSubscriptionFilterFieldOfVision(double angle) const
std::vector< libsumo::TraCIBestLanesData > getBestLanes(const std::string &vehicleID) const
double getAccel(const std::string &vehicleID) const
void setSpeedMode(const std::string &vehicleID, int mode) const
void slowDown(const std::string &vehicleID, double speed, double duration) const
std::string getTypeID(const std::string &vehicleID) const
double getAccumulatedWaitingTime(const std::string &vehicleID) const
void changeLaneRelative(const std::string &vehicleID, int laneChange, double duration) const
void rerouteTraveltime(const std::string &vehicleID, bool currentTravelTimes=true) const
double getStopSpeed(const std::string &vehicleID, double speed, double gap) const
int getLaneIndex(const std::string &vehicleID) const
double getSpeedDeviation(const std::string &typeID) const
double getSpeedFactor(const std::string &typeID) const
void setImperfection(const std::string &typeID, double imperfection) const
void setApparentDecel(const std::string &typeID, double decel) const
void setHeight(const std::string &typeID, double height) const
std::string getShapeClass(const std::string &typeID) const
double getMinGapLat(const std::string &typeID) const
void copy(const std::string &origTypeID, const std::string &newTypeID) const
int getPersonCapacity(const std::string &typeID) const
void setVehicleClass(const std::string &typeID, const std::string &clazz) const
void setColor(const std::string &typeID, const libsumo::TraCIColor &c) const
void setDecel(const std::string &typeID, double decel) const
void setWidth(const std::string &typeID, double width) const
double getApparentDecel(const std::string &typeID) const
double getDecel(const std::string &typeID) const
void setLateralAlignment(const std::string &typeID, const std::string &latAlignment) const
void setMaxSpeed(const std::string &typeID, double speed) const
double getMinGap(const std::string &typeID) const
std::string getVehicleClass(const std::string &typeID) const
void setShapeClass(const std::string &typeID, const std::string &shapeClass) const
double getMaxSpeedLat(const std::string &typeID) const
double getEmergencyDecel(const std::string &typeID) const
double getWidth(const std::string &typeID) const
libsumo::TraCIColor getColor(const std::string &typeID) const
double getTau(const std::string &typeID) const
double getMaxSpeed(const std::string &typeID) const
double getLength(const std::string &typeID) const
std::string getEmissionClass(const std::string &typeID) const
double getImperfection(const std::string &typeID) const
void setEmissionClass(const std::string &typeID, const std::string &clazz) const
void setAccel(const std::string &typeID, double accel) const
void setMinGap(const std::string &typeID, double minGap) const
double getAccel(const std::string &typeID) const
void setSpeedFactor(const std::string &typeID, double factor) const
double getHeight(const std::string &typeID) const
void setEmergencyDecel(const std::string &typeID, double decel) const
void setSpeedDeviation(const std::string &typeID, double deviation) const
void setMaxSpeedLat(const std::string &typeID, double speed) const
std::string getLateralAlignment(const std::string &typeID) const
void setMinGapLat(const std::string &typeID, double minGapLat) const
void setLength(const std::string &typeID, double length) const
void setTau(const std::string &typeID, double tau) const
RouteScope route
Scope for interaction with routes.
Definition TraCIAPI.h:855
std::pair< int, std::string > getVersion()
return TraCI API and SUMO version
Definition TraCIAPI.cpp:484
void setOrder(int order)
set priority (execution order) for the client
Definition TraCIAPI.cpp:86
void readVariableSubscription(int cmdId, tcpip::Storage &inMsg)
Definition TraCIAPI.cpp:421
tcpip::Storage myInput
The reusable input storage.
Definition TraCIAPI.h:964
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition TraCIAPI.h:845
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition TraCIAPI.h:865
void send_commandSubscribeObjectVariable(int domID, const std::string &objID, double beginTime, double endTime, const std::vector< int > &vars) const
Sends a SubscribeVariable request.
Definition TraCIAPI.cpp:206
void send_commandSimulationStep(double time) const
Sends a SimulationStep command.
Definition TraCIAPI.cpp:122
GUIScope gui
Scope for interaction with the gui.
Definition TraCIAPI.h:835
void check_resultState(tcpip::Storage &inMsg, int command, bool ignoreCommandId=false, std::string *acknowledgement=0) const
Validates the result state of a command.
Definition TraCIAPI.cpp:265
PolygonScope polygon
Scope for interaction with polygons.
Definition TraCIAPI.h:851
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition TraCIAPI.h:946
TraCIAPI()
Constructor.
Definition TraCIAPI.cpp:37
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition TraCIAPI.cpp:73
tcpip::Socket * mySocket
The socket.
Definition TraCIAPI.h:960
void load(const std::vector< std::string > &args)
Let sumo load a simulation using the given command line like options.
Definition TraCIAPI.cpp:466
LaneAreaScope lanearea
Scope for interaction with lanes.
Definition TraCIAPI.h:843
void simulationStep(double time=0)
Advances by one step (or up to the given time)
Definition TraCIAPI.cpp:444
void createFilterCommand(int cmdID, int varID, tcpip::Storage *add=nullptr) const
Definition TraCIAPI.cpp:183
void createCommand(int cmdID, int varID, const std::string &objID, tcpip::Storage *add=nullptr) const
Sends a GetVariable / SetVariable request if mySocket is connected. Otherwise writes to myOutput only...
Definition TraCIAPI.cpp:159
void close()
ends the simulation and closes the connection
Definition TraCIAPI.cpp:101
LaneScope lane
Scope for interaction with lanes.
Definition TraCIAPI.h:841
std::map< int, TraCIScopeWrapper * > myDomains
Definition TraCIAPI.h:958
void send_commandSubscribeObjectContext(int domID, const std::string &objID, double beginTime, double endTime, int domain, double range, const std::vector< int > &vars) const
Sends a SubscribeContext request.
Definition TraCIAPI.cpp:234
bool processSet(int command)
Definition TraCIAPI.cpp:341
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition TraCIAPI.h:861
tcpip::Storage myOutput
The reusable output storage.
Definition TraCIAPI.h:962
POIScope poi
Scope for interaction with POIs.
Definition TraCIAPI.h:849
void closeSocket()
Closes the connection.
Definition TraCIAPI.cpp:111
int check_commandGetResult(tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const
Validates the result state of a command.
Definition TraCIAPI.cpp:304
VehicleScope vehicle
Scope for interaction with vehicles.
Definition TraCIAPI.h:863
JunctionScope junction
Scope for interaction with junctions.
Definition TraCIAPI.h:839
void send_commandClose() const
Sends a Close command.
Definition TraCIAPI.cpp:135
void send_commandSetOrder(int order) const
Sends a SetOrder command.
Definition TraCIAPI.cpp:146
~TraCIAPI()
Destructor.
Definition TraCIAPI.cpp:67
RouteProbeScope routeprobe
Scope for interaction with route probes.
Definition TraCIAPI.h:857
EdgeScope edge
Scope for interaction with edges.
Definition TraCIAPI.h:833
bool processGet(int command, int expectedType, bool ignoreCommandId=false)
Definition TraCIAPI.cpp:328
SimulationScope simulation
Scope for interaction with the simulation.
Definition TraCIAPI.h:859
void readContextSubscription(int cmdId, tcpip::Storage &inMsg)
Definition TraCIAPI.cpp:429
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, libsumo::SubscriptionResults &into)
Definition TraCIAPI.cpp:353
PersonScope person
Scope for interaction with persons.
Definition TraCIAPI.h:847
RerouterScope rerouter
Scope for interaction with rerouters.
Definition TraCIAPI.h:853
An error which allows to continue.
Definition TraCIDefs.h:145
bool receiveExact(Storage &)
Receive a complete TraCI message from Socket::socket_.
Definition socket.cpp:510
void sendExact(const Storage &)
Definition socket.cpp:413
void connect()
Connects to host_:port_.
Definition socket.cpp:332
void close()
Definition socket.cpp:365
virtual std::string readString()
Definition storage.cpp:180
virtual void writeString(const std::string &s)
Definition storage.cpp:197
virtual unsigned int position() const
Definition storage.cpp:76
virtual void writeInt(int)
Definition storage.cpp:321
virtual void writeDouble(double)
Definition storage.cpp:354
virtual int readUnsignedByte()
Definition storage.cpp:155
virtual void writeStringList(const std::vector< std::string > &s)
Definition storage.cpp:247
virtual void writeUnsignedByte(int)
Definition storage.cpp:165
StorageType::size_type size() const
Definition storage.h:119
virtual void writeByte(int)
Definition storage.cpp:140
virtual void writeStorage(tcpip::Storage &store)
Definition storage.cpp:388
virtual double readDouble()
Definition storage.cpp:362
virtual int readInt()
Definition storage.cpp:311
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int RESPONSE_SUBSCRIBE_GUI_VARIABLE
TRACI_CONST int LAST_STEP_VEHICLE_ID_LIST
TRACI_CONST int VAR_EXIT_POSITIONS
TRACI_CONST int TYPE_COLOR
TRACI_CONST int VAR_MIN_EXPECTED_VEHICLES
TRACI_CONST int CMD_SAVE_SIMSTATE
TRACI_CONST int FILTER_TYPE_DOWNSTREAM_DIST
TRACI_CONST int VAR_IMAGEFILE
TRACI_CONST int VAR_EDGES
TRACI_CONST int CMD_LOAD
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int POSITION_3D
TRACI_CONST int POSITION_ROADMAP
TRACI_CONST int VAR_NOXEMISSION
TRACI_CONST int VAR_LANECHANGE_MODE
TRACI_CONST int VAR_ARRIVED_VEHICLES_NUMBER
TRACI_CONST int VAR_NAME
TRACI_CONST int LAST_STEP_PERSON_ID_LIST
TRACI_CONST int RTYPE_NOTIMPLEMENTED
TRACI_CONST int RESPONSE_SUBSCRIBE_ROUTE_VARIABLE
TRACI_CONST int FILTER_TYPE_NOOPPOSITE
TRACI_CONST int VAR_VEHICLECLASS
TRACI_CONST int LANE_LINKS
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_LATALIGNMENT
TRACI_CONST int VAR_DEPARTED_VEHICLES_NUMBER
TRACI_CONST int CMD_GET_TL_VARIABLE
TRACI_CONST int VAR_VIEW_BOUNDARY
TRACI_CONST int LAST_STEP_VEHICLE_DATA
TRACI_CONST int VAR_TYPE
TRACI_CONST int CMD_CHANGESUBLANE
TRACI_CONST int CMD_LOAD_SIMSTATE
TRACI_CONST int CMD_SET_EDGE_VARIABLE
TRACI_CONST int RESPONSE_SUBSCRIBE_LANE_VARIABLE
TRACI_CONST int VAR_LAST_INTERVAL_NUMBER
TRACI_CONST int VAR_ROUTING_MODE
TRACI_CONST int VAR_MINGAP
TRACI_CONST int VAR_VEHICLE
TRACI_CONST int VAR_SECURE_GAP
TRACI_CONST int VAR_LANES
TRACI_CONST int VAR_SHAPECLASS
TRACI_CONST int VAR_WAITING_TIME
TRACI_CONST int CMD_STOP
TRACI_CONST int VAR_LINE
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:384
TRACI_CONST int LANE_LINK_NUMBER
TRACI_CONST int VAR_EDGE_TRAVELTIME
TRACI_CONST int VAR_ROAD_ID
TRACI_CONST int CMD_GET_VEHICLE_VARIABLE
TRACI_CONST int VAR_SCREENSHOT
TRACI_CONST int VAR_SPEED_FACTOR
TRACI_CONST int MOVE_TO_XY
TRACI_CONST int VAR_FOLLOW_SPEED
TRACI_CONST int VAR_STOP_ARRIVALDELAY
TRACI_CONST int VAR_SPEED_LAT
TRACI_CONST int LAST_STEP_LENGTH
TRACI_CONST int FILTER_TYPE_FIELD_OF_VISION
TRACI_CONST int TL_CONTROLLED_LANES
TRACI_CONST int VAR_ANGLE
TRACI_CONST int VAR_TAU
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int LANE_EDGE_ID
TRACI_CONST int VAR_NEXT_TLS
TRACI_CONST int RESPONSE_SUBSCRIBE_PERSON_VARIABLE
TRACI_CONST int VAR_EDGE_EFFORT
TRACI_CONST int RESPONSE_SUBSCRIBE_TL_VARIABLE
TRACI_CONST int VAR_VIEW_OFFSET
TRACI_CONST int RESPONSE_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE
TRACI_CONST int VAR_ROUTE
TRACI_CONST int VAR_BEST_LANES
TRACI_CONST int VAR_ALLOWED_SPEED
TRACI_CONST int VAR_LANE_INDEX
TRACI_CONST int VAR_PMXEMISSION
TRACI_CONST int VAR_SPEED_WITHOUT_TRACI
TRACI_CONST int VAR_DEPARTED_PERSONS_NUMBER
TRACI_CONST int TL_COMPLETE_DEFINITION_RYG
TRACI_CONST int TYPE_UBYTE
TRACI_CONST int VAR_STAGE
TRACI_CONST int CMD_SET_POI_VARIABLE
TRACI_CONST int VAR_MOVE_TO
TRACI_CONST int RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE
TRACI_CONST int VAR_PERSON_NUMBER
TRACI_CONST int RESPONSE_SUBSCRIBE_REROUTER_VARIABLE
TRACI_CONST int CMD_SET_POLYGON_VARIABLE
TRACI_CONST int VAR_COEMISSION
TRACI_CONST int RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
TRACI_CONST int VAR_COLOR
TRACI_CONST int VAR_POSITION
TRACI_CONST int VAR_WIDTH
TRACI_CONST int VAR_PERSON_CAPACITY
TRACI_CONST int VAR_VIEW_SCHEMA
TRACI_CONST int POSITION_2D
TRACI_CONST int VAR_MAXSPEED
TRACI_CONST int COPY
TRACI_CONST int VAR_ARRIVED_PERSONS_IDS
TRACI_CONST int VAR_LEADER
TRACI_CONST int CMD_CHANGETARGET
TRACI_CONST int CMD_CLOSE
TRACI_CONST int VAR_TIME
TRACI_CONST int TYPE_POLYGON
TRACI_CONST int LAST_STEP_MEAN_SPEED
TRACI_CONST int ADD_FULL
TRACI_CONST int STAGE_WAITING
TRACI_CONST int CMD_SET_ROUTE_VARIABLE
TRACI_CONST int CMD_SETORDER
TRACI_CONST int VAR_CO2EMISSION
TRACI_CONST int RESPONSE_SUBSCRIBE_JUNCTION_VARIABLE
TRACI_CONST int FILTER_TYPE_VTYPE
TRACI_CONST int CMD_REROUTE_TRAVELTIME
TRACI_CONST int VAR_NET_BOUNDING_BOX
TRACI_CONST int TYPE_STRINGLIST
TRACI_CONST int APPEND_STAGE
TRACI_CONST int VAR_VIEW_ZOOM
TRACI_CONST int CMD_SET_SIM_VARIABLE
TRACI_CONST int TL_CONTROLLED_LINKS
TRACI_CONST int TYPE_INTEGER
TRACI_CONST int VAR_PREV_SPEED
TRACI_CONST int VAR_ROUTE_VALID
TRACI_CONST int VAR_SPEEDSETMODE
TRACI_CONST int POSITION_LON_LAT
TRACI_CONST int CMD_ADD_SUBSCRIPTION_FILTER
TRACI_CONST int CMD_SET_VEHICLE_VARIABLE
TRACI_CONST int VAR_FUELCONSUMPTION
TRACI_CONST int CMD_SET_GUI_VARIABLE
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:383
TRACI_CONST int VAR_SLOPE
TRACI_CONST int VAR_SHAPE
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
TRACI_CONST int VAR_LENGTH
TRACI_CONST int VAR_MAXSPEED_LAT
TRACI_CONST int VAR_HCEMISSION
TRACI_CONST int VAR_BUS_STOP_WAITING_IDS
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_LANEPOSITION
TRACI_CONST int CMD_SET_VEHICLETYPE_VARIABLE
TRACI_CONST int REMOVE
TRACI_CONST int CMD_SET_PERSON_VARIABLE
TRACI_CONST int VAR_DEPARTED_VEHICLES_IDS
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_NUMBER
TRACI_CONST int CMD_GET_SIM_VARIABLE
TRACI_CONST int CMD_MESSAGE
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int VAR_STOP_SPEED
TRACI_CONST int VAR_IMPERFECTION
TRACI_CONST int RESPONSE_SUBSCRIBE_ROUTEPROBE_VARIABLE
TRACI_CONST int LAST_STEP_OCCUPANCY
TRACI_CONST int VAR_HEIGHT
TRACI_CONST int RESPONSE_SUBSCRIBE_LANEAREA_VARIABLE
TRACI_CONST int VAR_APPARENT_DECEL
TRACI_CONST int TL_NEXT_SWITCH
TRACI_CONST int VAR_NOISEEMISSION
TRACI_CONST int VAR_LOADED_VEHICLES_IDS
TRACI_CONST int VAR_EXIT_LANES
TRACI_CONST int FILTER_TYPE_LEAD_FOLLOW
TRACI_CONST int RESPONSE_SUBSCRIBE_VEHICLETYPE_VARIABLE
TRACI_CONST int VAR_DELTA_T
TRACI_CONST int REQUEST_DRIVINGDIST
TRACI_CONST int CMD_GET_LANE_VARIABLE
TRACI_CONST int STAGE_WALKING
TRACI_CONST int VAR_POSITION3D
TRACI_CONST int LANE_DISALLOWED
TRACI_CONST int REMOVE_STAGE
TRACI_CONST int VAR_SPEED
TRACI_CONST int VAR_DECEL
TRACI_CONST int VAR_SIGNALS
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int FILTER_TYPE_UPSTREAM_DIST
TRACI_CONST int TYPE_DOUBLELIST
TRACI_CONST int VAR_ACCUMULATED_WAITING_TIME
TRACI_CONST int VAR_MINGAP_LAT
TRACI_CONST int VAR_DEPARTED_PERSONS_IDS
TRACI_CONST int INVALID_INT_VALUE
TRACI_CONST int VAR_ARRIVED_PERSONS_NUMBER
TRACI_CONST int TL_PROGRAM
TRACI_CONST int VAR_ROUTE_INDEX
TRACI_CONST int TL_PHASE_DURATION
TRACI_CONST int CMD_SLOWDOWN
TRACI_CONST int VAR_NEXT_EDGE
TRACI_CONST int FILTER_TYPE_TURN
TRACI_CONST int VAR_ACCELERATION
TRACI_CONST int VAR_FILL
TRACI_CONST int FIND_ROUTE
TRACI_CONST int VAR_ROUTE_ID
TRACI_CONST int TL_PHASE_INDEX
TRACI_CONST int POSITION_CONVERSION
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int DISTANCE_REQUEST
TRACI_CONST int TYPE_BYTE
TRACI_CONST int TL_CURRENT_PHASE
TRACI_CONST int CMD_OPENGAP
TRACI_CONST int TL_COMPLETE_PROGRAM_RYG
TRACI_CONST int VAR_LOADED_VEHICLES_NUMBER
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_IDS
TRACI_CONST int CMD_SET_TL_VARIABLE
TRACI_CONST int VAR_LANEPOSITION_LAT
TRACI_CONST int FILTER_TYPE_VCLASS
TRACI_CONST int CMD_CHANGELANE
TRACI_CONST int VAR_CURRENT_TRAVELTIME
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_NUMBER
TRACI_CONST int TL_RED_YELLOW_GREEN_STATE
TRACI_CONST int RESPONSE_SUBSCRIBE_POI_VARIABLE
TRACI_CONST int VAR_STOP_DELAY
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_IDS
TRACI_CONST int CMD_GETVERSION
TRACI_CONST int REQUEST_AIRDIST
TRACI_CONST int VAR_BUS_STOP_WAITING
TRACI_CONST int RTYPE_ERR
TRACI_CONST int CMD_SIMSTEP
TRACI_CONST int VAR_TIME_STEP
TRACI_CONST int VAR_EMERGENCY_DECEL
TRACI_CONST int VAR_ARRIVED_VEHICLES_IDS
TRACI_CONST int RESPONSE_SUBSCRIBE_SIM_VARIABLE
TRACI_CONST int STAGE_DRIVING
TRACI_CONST int RTYPE_OK
TRACI_CONST int CMD_GET_INDUCTIONLOOP_VARIABLE
TRACI_CONST int LAST_STEP_TIME_SINCE_DETECTION
TRACI_CONST int VAR_STOPSTATE
TRACI_CONST int VAR_FOLLOWER
TRACI_CONST int POSITION_LON_LAT_ALT
TRACI_CONST int VAR_EMISSIONCLASS
TRACI_CONST int FILTER_TYPE_LANES
TRACI_CONST int VAR_ACCEL
TRACI_CONST int VAR_SHADOW_LANE_ID
TRACI_CONST int RESPONSE_SUBSCRIBE_POLYGON_VARIABLE
TRACI_CONST int ADD
std::map< int, std::shared_ptr< libsumo::TraCIResult > > TraCIResults
{variable->value}
Definition TraCIDefs.h:381
TRACI_CONST int VAR_FOES
TRACI_CONST int VAR_STAGES_REMAINING
TRACI_CONST int VAR_DISTANCE
TRACI_CONST int LANE_ALLOWED
TRACI_CONST int VAR_OPTION
TRACI_CONST int RESPONSE_SUBSCRIBE_EDGE_VARIABLE
TRACI_CONST int TL_CURRENT_PROGRAM
TRACI_CONST int FILTER_TYPE_LATERAL_DIST
TRACI_CONST int VAR_ELECTRICITYCONSUMPTION
TRACI_CONST int VAR_SPEED_DEVIATION
TRACI_CONST int VAR_VIA
TRACI_CONST int TYPE_STRING
double length
The length than can be driven from that lane without lane change.
Definition TraCIDefs.h:706
double occupation
The traffic density along length.
Definition TraCIDefs.h:708
bool allowsContinuation
Whether this lane allows continuing the route.
Definition TraCIDefs.h:712
int bestLaneOffset
The offset of this lane from the best lane.
Definition TraCIDefs.h:710
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition TraCIDefs.h:714
std::string laneID
The id of the lane.
Definition TraCIDefs.h:704
std::map< std::string, std::string > subParameter
Definition TraCIDefs.h:428
std::string programID
Definition TraCIDefs.h:424
std::vector< std::shared_ptr< libsumo::TraCIPhase > > phases
Definition TraCIDefs.h:427
double dist
The distance to the tls.
Definition TraCIDefs.h:572
int tlIndex
The tls index of the controlled link.
Definition TraCIDefs.h:570
std::string id
The id of the next tls.
Definition TraCIDefs.h:568
char state
The current state of the tls.
Definition TraCIDefs.h:574
A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
Definition TraCIDefs.h:184
A list of positions.
Definition TraCIDefs.h:245
std::vector< TraCIPosition > value
Definition TraCIDefs.h:255
An edgeId, position and laneIndex.
Definition TraCIDefs.h:206
std::string intended
id of the intended vehicle for public transport ride
Definition TraCIDefs.h:759
int type
The type of stage (walking, driving, ...)
Definition TraCIDefs.h:743
std::string destStop
The id of the destination stop.
Definition TraCIDefs.h:749
double length
length in m
Definition TraCIDefs.h:757
double travelTime
duration of the stage in seconds
Definition TraCIDefs.h:753
double departPos
position on the lane when starting the stage
Definition TraCIDefs.h:763
std::string description
arbitrary description string
Definition TraCIDefs.h:767
std::string line
The line or the id of the vehicle type.
Definition TraCIDefs.h:747
double cost
effort needed
Definition TraCIDefs.h:755
double depart
intended depart time for public transport ride or INVALID_DOUBLE_VALUE
Definition TraCIDefs.h:761
std::vector< std::string > edges
The sequence of edges to travel.
Definition TraCIDefs.h:751
double arrivalPos
position on the lane when ending the stage
Definition TraCIDefs.h:765
std::string vType
The vehicle type when using a private car or bike.
Definition TraCIDefs.h:745
mirrors MSInductLoop::VehicleData
Definition TraCIDefs.h:523
std::string id
The id of the vehicle.
Definition TraCIDefs.h:532
double entryTime
Entry-time of the vehicle in [s].
Definition TraCIDefs.h:536
std::string typeID
Type of the vehicle in.
Definition TraCIDefs.h:540
double length
Length of the vehicle.
Definition TraCIDefs.h:534
double leaveTime
Leave-time of the vehicle in [s].
Definition TraCIDefs.h:538