Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
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::getLastStepOccupancy(const std::string& edgeID) const {
565 return getDouble(libsumo::LAST_STEP_OCCUPANCY, edgeID);
566}
567
568double
569TraCIAPI::EdgeScope::getLastStepLength(const std::string& edgeID) const {
570 return getDouble(libsumo::LAST_STEP_LENGTH, edgeID);
571}
572
573double
574TraCIAPI::EdgeScope::getTraveltime(const std::string& edgeID) const {
575 return getDouble(libsumo::VAR_CURRENT_TRAVELTIME, edgeID);
576}
577
578int
579TraCIAPI::EdgeScope::getLastStepVehicleNumber(const std::string& edgeID) const {
580 return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, edgeID);
581}
582
583double
584TraCIAPI::EdgeScope::getLastStepHaltingNumber(const std::string& edgeID) const {
585 return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, edgeID);
586}
587
588std::vector<std::string>
589TraCIAPI::EdgeScope::getLastStepVehicleIDs(const std::string& edgeID) const {
590 return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, edgeID);
591}
592
593
594int
595TraCIAPI::EdgeScope::getLaneNumber(const std::string& edgeID) const {
596 return getInt(libsumo::VAR_LANE_INDEX, edgeID);
597}
598
599
600std::string
601TraCIAPI::EdgeScope::getStreetName(const std::string& edgeID) const {
602 return getString(libsumo::VAR_NAME, edgeID);
603}
604
605
606void
607TraCIAPI::EdgeScope::adaptTraveltime(const std::string& edgeID, double time, double beginSeconds, double endSeconds) const {
608 tcpip::Storage content;
610 if (endSeconds != std::numeric_limits<double>::max()) {
611 content.writeInt(3);
613 content.writeDouble(beginSeconds);
615 content.writeDouble(endSeconds);
616 } else {
617 content.writeInt(1);
618 }
620 content.writeDouble(time);
621 myParent.createCommand(libsumo::CMD_SET_EDGE_VARIABLE, libsumo::VAR_EDGE_TRAVELTIME, edgeID, &content);
622 myParent.processSet(libsumo::CMD_SET_EDGE_VARIABLE);
623}
624
625
626void
627TraCIAPI::EdgeScope::setEffort(const std::string& edgeID, double effort, double beginSeconds, double endSeconds) const {
628 tcpip::Storage content;
630 if (endSeconds != std::numeric_limits<double>::max()) {
631 content.writeInt(3);
633 content.writeDouble(beginSeconds);
635 content.writeDouble(endSeconds);
636 } else {
637 content.writeInt(1);
638 }
640 content.writeDouble(effort);
641 myParent.createCommand(libsumo::CMD_SET_EDGE_VARIABLE, libsumo::VAR_EDGE_EFFORT, edgeID, &content);
642 myParent.processSet(libsumo::CMD_SET_EDGE_VARIABLE);
643}
644
645void
646TraCIAPI::EdgeScope::setMaxSpeed(const std::string& edgeID, double speed) const {
647 setDouble(libsumo::VAR_MAXSPEED, edgeID, speed);
648}
649
650
651// ---------------------------------------------------------------------------
652// TraCIAPI::GUIScope-methods
653// ---------------------------------------------------------------------------
654double
655TraCIAPI::GUIScope::getZoom(const std::string& viewID) const {
656 return getDouble(libsumo::VAR_VIEW_ZOOM, viewID);
657}
658
660TraCIAPI::GUIScope::getOffset(const std::string& viewID) const {
661 return getPos(libsumo::VAR_VIEW_OFFSET, viewID);
662}
663
664std::string
665TraCIAPI::GUIScope::getSchema(const std::string& viewID) const {
666 return getString(libsumo::VAR_VIEW_SCHEMA, viewID);
667}
668
670TraCIAPI::GUIScope::getBoundary(const std::string& viewID) const {
671 return getPolygon(libsumo::VAR_VIEW_BOUNDARY, viewID);
672}
673
674
675void
676TraCIAPI::GUIScope::setZoom(const std::string& viewID, double zoom) const {
677 setDouble(libsumo::VAR_VIEW_ZOOM, viewID, zoom);
678}
679
680void
681TraCIAPI::GUIScope::setOffset(const std::string& viewID, double x, double y) const {
682 tcpip::Storage content;
684 content.writeDouble(x);
685 content.writeDouble(y);
686 myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_VIEW_OFFSET, viewID, &content);
687 myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
688}
689
690void
691TraCIAPI::GUIScope::setSchema(const std::string& viewID, const std::string& schemeName) const {
692 setString(libsumo::VAR_VIEW_SCHEMA, viewID, schemeName);
693}
694
695void
696TraCIAPI::GUIScope::setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const {
697 tcpip::Storage content;
699 content.writeByte(2);
700 content.writeDouble(xmin);
701 content.writeDouble(ymin);
702 content.writeDouble(xmax);
703 content.writeDouble(ymax);
704 myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_VIEW_BOUNDARY, viewID, &content);
705 myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
706}
707
708void
709TraCIAPI::GUIScope::screenshot(const std::string& viewID, const std::string& filename, const int width, const int height) const {
710 tcpip::Storage content;
712 content.writeInt(3);
714 content.writeString(filename);
716 content.writeInt(width);
718 content.writeInt(height);
719 myParent.createCommand(libsumo::CMD_SET_GUI_VARIABLE, libsumo::VAR_SCREENSHOT, viewID, &content);
720 myParent.processSet(libsumo::CMD_SET_GUI_VARIABLE);
721}
722
723void
724TraCIAPI::GUIScope::trackVehicle(const std::string& viewID, const std::string& vehID) const {
725 setString(libsumo::VAR_VIEW_SCHEMA, viewID, vehID);
726}
727
728
729// ---------------------------------------------------------------------------
730// TraCIAPI::InductionLoopScope-methods
731// ---------------------------------------------------------------------------
732
733int TraCIAPI::InductionLoopScope::getIntervalVehicleNumber(const std::string& loopID) const {
734 return getInt(libsumo::VAR_LAST_INTERVAL_NUMBER, loopID);
735}
736
737double
738TraCIAPI::InductionLoopScope::getPosition(const std::string& loopID) const {
739 return getDouble(libsumo::VAR_POSITION, loopID);
740}
741
742std::string
743TraCIAPI::InductionLoopScope::getLaneID(const std::string& loopID) const {
744 return getString(libsumo::VAR_LANE_ID, loopID);
745}
746
747int
749 return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, loopID);
750}
751
752double
754 return getDouble(libsumo::LAST_STEP_MEAN_SPEED, loopID);
755}
756
757std::vector<std::string>
759 return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, loopID);
760}
761
762double
764 return getDouble(libsumo::LAST_STEP_OCCUPANCY, loopID);
765}
766
767double
769 return getDouble(libsumo::LAST_STEP_LENGTH, loopID);
770}
771
772double
774 return getDouble(libsumo::LAST_STEP_TIME_SINCE_DETECTION, loopID);
775}
776
777
778std::vector<libsumo::TraCIVehicleData>
779TraCIAPI::InductionLoopScope::getVehicleData(const std::string& loopID) const {
780 std::vector<libsumo::TraCIVehicleData> result;
783 myParent.myInput.readInt(); // components
784 // number of items
785 myParent.myInput.readUnsignedByte();
786 const int n = myParent.myInput.readInt();
787 for (int i = 0; i < n; ++i) {
789
790 myParent.myInput.readUnsignedByte();
791 vd.id = myParent.myInput.readString();
792
793 myParent.myInput.readUnsignedByte();
794 vd.length = myParent.myInput.readDouble();
795
796 myParent.myInput.readUnsignedByte();
797 vd.entryTime = myParent.myInput.readDouble();
798
799 myParent.myInput.readUnsignedByte();
800 vd.leaveTime = myParent.myInput.readDouble();
801
802 myParent.myInput.readUnsignedByte();
803 vd.typeID = myParent.myInput.readString();
804
805 result.push_back(vd);
806 }
807 }
808 return result;
809}
810
811
812// ---------------------------------------------------------------------------
813// TraCIAPI::JunctionScope-methods
814// ---------------------------------------------------------------------------
816TraCIAPI::JunctionScope::getPosition(const std::string& junctionID) const {
817 return getPos(libsumo::VAR_POSITION, junctionID);
818}
819
821TraCIAPI::JunctionScope::getShape(const std::string& junctionID) const {
822 return getPolygon(libsumo::VAR_SHAPE, junctionID);
823}
824
825
826// ---------------------------------------------------------------------------
827// TraCIAPI::LaneScope-methods
828// ---------------------------------------------------------------------------
829double
830TraCIAPI::LaneScope::getLength(const std::string& laneID) const {
831 return getDouble(libsumo::VAR_LENGTH, laneID);
832}
833
834double
835TraCIAPI::LaneScope::getMaxSpeed(const std::string& laneID) const {
836 return getDouble(libsumo::VAR_MAXSPEED, laneID);
837}
838
839double
840TraCIAPI::LaneScope::getWidth(const std::string& laneID) const {
841 return getDouble(libsumo::VAR_WIDTH, laneID);
842}
843
844std::vector<std::string>
845TraCIAPI::LaneScope::getAllowed(const std::string& laneID) const {
846 return getStringVector(libsumo::LANE_ALLOWED, laneID);
847}
848
849std::vector<std::string>
850TraCIAPI::LaneScope::getDisallowed(const std::string& laneID) const {
851 return getStringVector(libsumo::LANE_DISALLOWED, laneID);
852}
853
854int
855TraCIAPI::LaneScope::getLinkNumber(const std::string& laneID) const {
856 return getInt(libsumo::LANE_LINK_NUMBER, laneID);
857}
858
859std::vector<libsumo::TraCIConnection>
860TraCIAPI::LaneScope::getLinks(const std::string& laneID) const {
861 std::vector<libsumo::TraCIConnection> ret;
862 myParent.createCommand(libsumo::CMD_GET_LANE_VARIABLE, libsumo::LANE_LINKS, laneID);
863 if (myParent.processGet(libsumo::CMD_GET_LANE_VARIABLE, libsumo::TYPE_COMPOUND)) {
864 myParent.myInput.readUnsignedByte();
865 myParent.myInput.readInt();
866
867 int linkNo = myParent.myInput.readInt();
868 for (int i = 0; i < linkNo; ++i) {
869
870 myParent.myInput.readUnsignedByte();
871 std::string approachedLane = myParent.myInput.readString();
872
873 myParent.myInput.readUnsignedByte();
874 std::string approachedLaneInternal = myParent.myInput.readString();
875
876 myParent.myInput.readUnsignedByte();
877 bool hasPrio = myParent.myInput.readUnsignedByte() != 0;
878
879 myParent.myInput.readUnsignedByte();
880 bool isOpen = myParent.myInput.readUnsignedByte() != 0;
881
882 myParent.myInput.readUnsignedByte();
883 bool hasFoe = myParent.myInput.readUnsignedByte() != 0;
884
885 myParent.myInput.readUnsignedByte();
886 std::string state = myParent.myInput.readString();
887
888 myParent.myInput.readUnsignedByte();
889 std::string direction = myParent.myInput.readString();
890
891 myParent.myInput.readUnsignedByte();
892 double length = myParent.myInput.readDouble();
893
894 ret.push_back(libsumo::TraCIConnection(approachedLane,
895 hasPrio,
896 isOpen,
897 hasFoe,
898 approachedLaneInternal,
899 state,
900 direction,
901 length));
902
903 }
904
905 }
906 return ret;
907}
908
910TraCIAPI::LaneScope::getShape(const std::string& laneID) const {
911 return getPolygon(libsumo::VAR_SHAPE, laneID);
912}
913
914std::string
915TraCIAPI::LaneScope::getEdgeID(const std::string& laneID) const {
916 return getString(libsumo::LANE_EDGE_ID, laneID);
917}
918
919double
920TraCIAPI::LaneScope::getCO2Emission(const std::string& laneID) const {
921 return getDouble(libsumo::VAR_CO2EMISSION, laneID);
922}
923
924double
925TraCIAPI::LaneScope::getCOEmission(const std::string& laneID) const {
926 return getDouble(libsumo::VAR_COEMISSION, laneID);
927}
928
929double
930TraCIAPI::LaneScope::getHCEmission(const std::string& laneID) const {
931 return getDouble(libsumo::VAR_HCEMISSION, laneID);
932}
933
934double
935TraCIAPI::LaneScope::getPMxEmission(const std::string& laneID) const {
936 return getDouble(libsumo::VAR_PMXEMISSION, laneID);
937}
938
939double
940TraCIAPI::LaneScope::getNOxEmission(const std::string& laneID) const {
941 return getDouble(libsumo::VAR_NOXEMISSION, laneID);
942}
943
944double
945TraCIAPI::LaneScope::getFuelConsumption(const std::string& laneID) const {
946 return getDouble(libsumo::VAR_FUELCONSUMPTION, laneID);
947}
948
949double
950TraCIAPI::LaneScope::getNoiseEmission(const std::string& laneID) const {
951 return getDouble(libsumo::VAR_NOISEEMISSION, laneID);
952}
953
954double
955TraCIAPI::LaneScope::getElectricityConsumption(const std::string& laneID) const {
956 return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, laneID);
957}
958
959double
960TraCIAPI::LaneScope::getLastStepMeanSpeed(const std::string& laneID) const {
961 return getDouble(libsumo::LAST_STEP_MEAN_SPEED, laneID);
962}
963
964double
965TraCIAPI::LaneScope::getLastStepOccupancy(const std::string& laneID) const {
966 return getDouble(libsumo::LAST_STEP_OCCUPANCY, laneID);
967}
968
969double
970TraCIAPI::LaneScope::getLastStepLength(const std::string& laneID) const {
971 return getDouble(libsumo::LAST_STEP_LENGTH, laneID);
972}
973
974double
975TraCIAPI::LaneScope::getTraveltime(const std::string& laneID) const {
976 return getDouble(libsumo::VAR_CURRENT_TRAVELTIME, laneID);
977}
978
979int
980TraCIAPI::LaneScope::getLastStepVehicleNumber(const std::string& laneID) const {
981 return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, laneID);
982}
983
984int
985TraCIAPI::LaneScope::getLastStepHaltingNumber(const std::string& laneID) const {
986 return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, laneID);
987}
988
989std::vector<std::string>
990TraCIAPI::LaneScope::getLastStepVehicleIDs(const std::string& laneID) const {
991 return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, laneID);
992}
993
994
995std::vector<std::string>
996TraCIAPI::LaneScope::getFoes(const std::string& laneID, const std::string& toLaneID) const {
997 std::vector<std::string> r;
998 tcpip::Storage content;
1000 content.writeString(toLaneID);
1001 myParent.createCommand(libsumo::CMD_GET_LANE_VARIABLE, libsumo::VAR_FOES, laneID, &content);
1002 if (myParent.processGet(libsumo::CMD_GET_LANE_VARIABLE, libsumo::TYPE_STRINGLIST)) {
1003 const int size = myParent.myInput.readInt();
1004 for (int i = 0; i < size; ++i) {
1005 r.push_back(myParent.myInput.readString());
1006 }
1007 }
1008 return r;
1009}
1010
1011std::vector<std::string>
1012TraCIAPI::LaneScope::getInternalFoes(const std::string& laneID) const {
1013 return getFoes(laneID, "");
1014}
1015
1016
1017void
1018TraCIAPI::LaneScope::setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const {
1019 setStringVector(libsumo::LANE_ALLOWED, laneID, allowedClasses);
1020}
1021
1022void
1023TraCIAPI::LaneScope::setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const {
1024 setStringVector(libsumo::LANE_DISALLOWED, laneID, disallowedClasses);
1025}
1026
1027void
1028TraCIAPI::LaneScope::setMaxSpeed(const std::string& laneID, double speed) const {
1029 setDouble(libsumo::VAR_MAXSPEED, laneID, speed);
1030}
1031
1032void
1033TraCIAPI::LaneScope::setLength(const std::string& laneID, double length) const {
1034 setDouble(libsumo::VAR_LENGTH, laneID, length);
1035}
1036
1037
1038// ---------------------------------------------------------------------------
1039// TraCIAPI::LaneAreaDetector-methods
1040// ---------------------------------------------------------------------------
1041
1042
1043// ---------------------------------------------------------------------------
1044// TraCIAPI::MeMeScope-methods
1045// ---------------------------------------------------------------------------
1046int
1047TraCIAPI::MeMeScope::getLastStepVehicleNumber(const std::string& detID) const {
1048 return getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, detID);
1049}
1050
1051double
1052TraCIAPI::MeMeScope::getLastStepMeanSpeed(const std::string& detID) const {
1053 return getDouble(libsumo::LAST_STEP_MEAN_SPEED, detID);
1054}
1055
1056std::vector<std::string>
1057TraCIAPI::MeMeScope::getLastStepVehicleIDs(const std::string& detID) const {
1058 return getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, detID);
1059}
1060
1061int
1062TraCIAPI::MeMeScope::getLastStepHaltingNumber(const std::string& detID) const {
1063 return getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, detID);
1064}
1065
1066std::vector<std::string>
1067TraCIAPI::MeMeScope::getEntryLanes(const std::string& detID) const {
1068 return getStringVector(libsumo::VAR_LANES, detID);
1069}
1070
1071std::vector<std::string>
1072TraCIAPI::MeMeScope::getExitLanes(const std::string& detID) const {
1073 return getStringVector(libsumo::VAR_EXIT_LANES, detID);
1074}
1075
1076std::vector<double>
1077TraCIAPI::MeMeScope::getEntryPositions(const std::string& detID) const {
1078 return getDoubleVector(libsumo::VAR_POSITION, detID);
1079}
1080
1081std::vector<double>
1082TraCIAPI::MeMeScope::getExitPositions(const std::string& detID) const {
1083 return getDoubleVector(libsumo::VAR_EXIT_POSITIONS, detID);
1084}
1085
1086// ---------------------------------------------------------------------------
1087// TraCIAPI::POIScope-methods
1088// ---------------------------------------------------------------------------
1089std::string
1090TraCIAPI::POIScope::getType(const std::string& poiID) const {
1091 return getString(libsumo::VAR_TYPE, poiID);
1092}
1093
1095TraCIAPI::POIScope::getPosition(const std::string& poiID) const {
1096 return getPos(libsumo::VAR_POSITION, poiID);
1097}
1098
1100TraCIAPI::POIScope::getColor(const std::string& poiID) const {
1101 return getCol(libsumo::VAR_COLOR, poiID);
1102}
1103
1104double
1105TraCIAPI::POIScope::getWidth(const std::string& poiID) const {
1106 return getDouble(libsumo::VAR_WIDTH, poiID);
1107}
1108
1109double
1110TraCIAPI::POIScope::getHeight(const std::string& poiID) const {
1111 return getDouble(libsumo::VAR_HEIGHT, poiID);
1112}
1113
1114double
1115TraCIAPI::POIScope::getAngle(const std::string& poiID) const {
1116 return getDouble(libsumo::VAR_ANGLE, poiID);
1117}
1118
1119std::string
1120TraCIAPI::POIScope::getImageFile(const std::string& poiID) const {
1121 return getString(libsumo::VAR_IMAGEFILE, poiID);
1122}
1123
1124
1125void
1126TraCIAPI::POIScope::setType(const std::string& poiID, const std::string& setType) const {
1127 setString(libsumo::VAR_TYPE, poiID, setType);
1128}
1129
1130
1131void
1132TraCIAPI::POIScope::setPosition(const std::string& poiID, double x, double y) const {
1133 tcpip::Storage content;
1135 content.writeDouble(x);
1136 content.writeDouble(y);
1137 myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::VAR_POSITION, poiID, &content);
1138 myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1139}
1140
1141
1142void
1143TraCIAPI::POIScope::setColor(const std::string& poiID, const libsumo::TraCIColor& c) const {
1144 tcpip::Storage content;
1146 content.writeUnsignedByte(c.r);
1147 content.writeUnsignedByte(c.g);
1148 content.writeUnsignedByte(c.b);
1149 content.writeUnsignedByte(c.a);
1150 myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::VAR_COLOR, poiID, &content);
1151 myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1152}
1153
1154
1155void
1156TraCIAPI::POIScope::setWidth(const std::string& poiID, double width) const {
1157 setDouble(libsumo::VAR_WIDTH, poiID, width);
1158}
1159
1160
1161void
1162TraCIAPI::POIScope::setHeight(const std::string& poiID, double height) const {
1163 setDouble(libsumo::VAR_HEIGHT, poiID, height);
1164}
1165
1166
1167void
1168TraCIAPI::POIScope::setAngle(const std::string& poiID, double angle) const {
1169 setDouble(libsumo::VAR_ANGLE, poiID, angle);
1170}
1171
1172
1173void
1174TraCIAPI::POIScope::setImageFile(const std::string& poiID, const std::string& imageFile) const {
1175 setString(libsumo::VAR_IMAGEFILE, poiID, imageFile);
1176}
1177
1178
1179void
1180TraCIAPI::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 {
1181 tcpip::Storage content;
1183 content.writeInt(8);
1185 content.writeString(type);
1187 content.writeUnsignedByte(c.r);
1188 content.writeUnsignedByte(c.g);
1189 content.writeUnsignedByte(c.b);
1190 content.writeUnsignedByte(c.a);
1192 content.writeInt(layer);
1194 content.writeDouble(x);
1195 content.writeDouble(y);
1197 content.writeString(imgFile);
1199 content.writeDouble(width);
1201 content.writeDouble(height);
1203 content.writeDouble(angle);
1204 myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::ADD, poiID, &content);
1205 myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1206}
1207
1208void
1209TraCIAPI::POIScope::remove(const std::string& poiID, int layer) const {
1210 tcpip::Storage content;
1212 content.writeInt(layer);
1213 myParent.createCommand(libsumo::CMD_SET_POI_VARIABLE, libsumo::REMOVE, poiID, &content);
1214 myParent.processSet(libsumo::CMD_SET_POI_VARIABLE);
1215}
1216
1217
1218// ---------------------------------------------------------------------------
1219// TraCIAPI::PolygonScope-methods
1220// ---------------------------------------------------------------------------
1221double
1222TraCIAPI::PolygonScope::getLineWidth(const std::string& polygonID) const {
1223 return getDouble(libsumo::VAR_WIDTH, polygonID);
1224}
1225
1226bool
1227TraCIAPI::PolygonScope::getFilled(const std::string& polygonID) const {
1228 return getInt(libsumo::VAR_FILL, polygonID) != 0;
1229}
1230
1231std::string
1232TraCIAPI::PolygonScope::getType(const std::string& polygonID) const {
1233 return getString(libsumo::VAR_TYPE, polygonID);
1234}
1235
1237TraCIAPI::PolygonScope::getShape(const std::string& polygonID) const {
1238 return getPolygon(libsumo::VAR_SHAPE, polygonID);
1239}
1240
1242TraCIAPI::PolygonScope::getColor(const std::string& polygonID) const {
1243 return getCol(libsumo::VAR_COLOR, polygonID);
1244}
1245
1246void
1247TraCIAPI::PolygonScope::setLineWidth(const std::string& polygonID, const double lineWidth) const {
1248 tcpip::Storage content;
1250 content.writeDouble(lineWidth);
1251 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_WIDTH, polygonID, &content);
1252 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1253}
1254
1255void
1256TraCIAPI::PolygonScope::setType(const std::string& polygonID, const std::string& setType) const {
1257 tcpip::Storage content;
1259 content.writeString(setType);
1260 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_TYPE, polygonID, &content);
1261 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1262}
1263
1264
1265void
1266TraCIAPI::PolygonScope::setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) const {
1267 tcpip::Storage content;
1269 if (shape.value.size() < 256) {
1270 content.writeUnsignedByte((int)shape.value.size());
1271 } else {
1272 content.writeUnsignedByte(0);
1273 content.writeInt((int)shape.value.size());
1274 }
1275 for (const libsumo::TraCIPosition& pos : shape.value) {
1276 content.writeDouble(pos.x);
1277 content.writeDouble(pos.y);
1278 }
1279 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_SHAPE, polygonID, &content);
1280 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1281}
1282
1283
1284void
1285TraCIAPI::PolygonScope::setColor(const std::string& polygonID, const libsumo::TraCIColor& c) const {
1286 tcpip::Storage content;
1288 content.writeUnsignedByte(c.r);
1289 content.writeUnsignedByte(c.g);
1290 content.writeUnsignedByte(c.b);
1291 content.writeUnsignedByte(c.a);
1292 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_COLOR, polygonID, &content);
1293 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1294}
1295
1296void
1297TraCIAPI::PolygonScope::add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& c, bool fill, const std::string& type, int layer) const {
1298 tcpip::Storage content;
1300 content.writeInt(5);
1302 content.writeString(type);
1304 content.writeUnsignedByte(c.r);
1305 content.writeUnsignedByte(c.g);
1306 content.writeUnsignedByte(c.b);
1307 content.writeUnsignedByte(c.a);
1309 int f = fill ? 1 : 0;
1310 content.writeUnsignedByte(f);
1312 content.writeInt(layer);
1314 content.writeUnsignedByte((int)shape.value.size());
1315 for (int i = 0; i < (int)shape.value.size(); ++i) {
1316 content.writeDouble(shape.value[i].x);
1317 content.writeDouble(shape.value[i].y);
1318 }
1319 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::ADD, polygonID, &content);
1320 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1321}
1322
1323void
1324TraCIAPI::PolygonScope::remove(const std::string& polygonID, int layer) const {
1325 tcpip::Storage content;
1327 content.writeInt(layer);
1328 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::REMOVE, polygonID, &content);
1329 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1330}
1331
1332
1333// ---------------------------------------------------------------------------
1334// TraCIAPI::RouteScope-methods
1335// ---------------------------------------------------------------------------
1336std::vector<std::string>
1337TraCIAPI::RouteScope::getEdges(const std::string& routeID) const {
1338 return getStringVector(libsumo::VAR_EDGES, routeID);
1339}
1340
1341
1342void
1343TraCIAPI::RouteScope::add(const std::string& routeID, const std::vector<std::string>& edges) const {
1344 tcpip::Storage content;
1346 content.writeStringList(edges);
1347 myParent.createCommand(libsumo::CMD_SET_ROUTE_VARIABLE, libsumo::ADD, routeID, &content);
1348 myParent.processSet(libsumo::CMD_SET_ROUTE_VARIABLE);
1349}
1350
1351
1352// ---------------------------------------------------------------------------
1353// TraCIAPI::SimulationScope-methods
1354// ---------------------------------------------------------------------------
1355int
1359
1360double
1362 return getDouble(libsumo::VAR_TIME, "");
1363}
1364
1365int
1369
1370std::vector<std::string>
1374
1375int
1379
1380std::vector<std::string>
1384
1385int
1389
1390std::vector<std::string>
1394
1395int
1399
1400std::vector<std::string>
1404
1405int
1409
1410std::vector<std::string>
1414
1415int
1419
1420std::vector<std::string>
1424
1425int
1429
1430std::vector<std::string>
1434
1435double
1437 return getDouble(libsumo::VAR_DELTA_T, "");
1438}
1439
1444
1445
1446int
1450
1451std::string
1452TraCIAPI::SimulationScope::getOption(const std::string& option) const {
1453 return getString(libsumo::VAR_OPTION, option);
1454}
1455
1456int
1457TraCIAPI::SimulationScope::getBusStopWaiting(const std::string& stopID) const {
1458 return (int) getInt(libsumo::VAR_BUS_STOP_WAITING, stopID);
1459}
1460
1461std::vector<std::string>
1463 return getStringVector(libsumo::VAR_BUS_STOP_WAITING_IDS, stopID);
1464}
1465
1466
1468TraCIAPI::SimulationScope::convert2D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) const {
1469 const int posType = toGeo ? libsumo::POSITION_LON_LAT : libsumo::POSITION_2D;
1471 tcpip::Storage content;
1473 content.writeInt(2);
1475 content.writeString(edgeID);
1476 content.writeDouble(pos);
1477 content.writeByte(laneIndex);
1479 content.writeByte(posType);
1480 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1481 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1482 result.x = myParent.myInput.readDouble();
1483 result.y = myParent.myInput.readDouble();
1484 }
1485 return result;
1486}
1487
1488
1490TraCIAPI::SimulationScope::convert3D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) const {
1491 const int posType = toGeo ? libsumo::POSITION_LON_LAT_ALT : libsumo::POSITION_3D;
1493 tcpip::Storage content;
1495 content.writeInt(2);
1497 content.writeString(edgeID);
1498 content.writeDouble(pos);
1499 content.writeByte(laneIndex);
1501 content.writeByte(posType);
1502 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1503 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1504 result.x = myParent.myInput.readDouble();
1505 result.y = myParent.myInput.readDouble();
1506 result.z = myParent.myInput.readDouble();
1507 }
1508 return result;
1509}
1510
1511
1513TraCIAPI::SimulationScope::convertRoad(double x, double y, bool isGeo, const std::string& vClass) const {
1515 tcpip::Storage content;
1517 content.writeInt(3);
1519 content.writeDouble(x);
1520 content.writeDouble(y);
1524 content.writeString(vClass);
1525 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1526 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_ROADMAP)) {
1527 result.edgeID = myParent.myInput.readString();
1528 result.pos = myParent.myInput.readDouble();
1529 result.laneIndex = myParent.myInput.readUnsignedByte();
1530 }
1531 return result;
1532}
1533
1534
1536TraCIAPI::SimulationScope::convertGeo(double x, double y, bool fromGeo) const {
1537 const int posType = fromGeo ? libsumo::POSITION_2D : libsumo::POSITION_LON_LAT;
1539 tcpip::Storage content;
1541 content.writeInt(2);
1543 content.writeDouble(x);
1544 content.writeDouble(y);
1546 content.writeByte(posType);
1547 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1548 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1549 result.x = myParent.myInput.readDouble();
1550 result.y = myParent.myInput.readDouble();
1551 }
1552 return result;
1553}
1554
1555
1556double
1557TraCIAPI::SimulationScope::getDistance2D(double x1, double y1, double x2, double y2, bool isGeo, bool isDriving) {
1558 tcpip::Storage content;
1560 content.writeInt(3);
1562 content.writeDouble(x1);
1563 content.writeDouble(y1);
1565 content.writeDouble(x2);
1566 content.writeDouble(y2);
1568 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::DISTANCE_REQUEST, "", &content);
1569 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::TYPE_DOUBLE)) {
1570 return myParent.myInput.readDouble();
1571 }
1572 return 0.;
1573}
1574
1575
1576double
1577TraCIAPI::SimulationScope::getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving) {
1578 tcpip::Storage content;
1580 content.writeInt(3);
1582 content.writeString(edgeID1);
1583 content.writeDouble(pos1);
1584 content.writeByte(0); // lane
1586 content.writeString(edgeID2);
1587 content.writeDouble(pos2);
1588 content.writeByte(0); // lane
1590 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::DISTANCE_REQUEST, "", &content);
1591 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::TYPE_DOUBLE)) {
1592 return myParent.myInput.readDouble();
1593 }
1594 return 0.;
1595}
1596
1597
1599TraCIAPI::SimulationScope::findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType, double pos, int routingMode) const {
1600 tcpip::Storage content;
1602 content.writeInt(5);
1604 content.writeString(fromEdge);
1606 content.writeString(toEdge);
1608 content.writeString(vType);
1610 content.writeDouble(pos);
1612 content.writeInt(routingMode);
1613 return getTraCIStage(libsumo::FIND_ROUTE, "", &content);
1614}
1615
1616void
1617TraCIAPI::SimulationScope::loadState(const std::string& path) const {
1618 tcpip::Storage content;
1620 content.writeString(path);
1621 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_LOAD_SIMSTATE, "", &content);
1622 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1623}
1624
1625void
1626TraCIAPI::SimulationScope::saveState(const std::string& destination) const {
1627 tcpip::Storage content;
1629 content.writeString(destination);
1630 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_SAVE_SIMSTATE, "", &content);
1631 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1632}
1633
1634void
1636 tcpip::Storage content;
1638 content.writeString(msg);
1639 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_MESSAGE, "", &content);
1640 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1641}
1642
1643
1644// ---------------------------------------------------------------------------
1645// TraCIAPI::TrafficLightScope-methods
1646// ---------------------------------------------------------------------------
1647std::string
1649 return getString(libsumo::TL_RED_YELLOW_GREEN_STATE, tlsID);
1650}
1651
1652std::vector<libsumo::TraCILogic>
1654 std::vector<libsumo::TraCILogic> ret;
1656 if (myParent.processGet(libsumo::CMD_GET_TL_VARIABLE, libsumo::TYPE_COMPOUND)) {
1657 const int logicNo = myParent.myInput.readInt();
1658 for (int i = 0; i < logicNo; ++i) {
1659 myParent.myInput.readUnsignedByte();
1660 myParent.myInput.readInt();
1661 myParent.myInput.readUnsignedByte();
1662 const std::string programID = myParent.myInput.readString();
1663 myParent.myInput.readUnsignedByte();
1664 const int type = myParent.myInput.readInt();
1665 myParent.myInput.readUnsignedByte();
1666 const int phaseIndex = myParent.myInput.readInt();
1667 myParent.myInput.readUnsignedByte();
1668 const int phaseNumber = myParent.myInput.readInt();
1669 libsumo::TraCILogic logic(programID, type, phaseIndex);
1670 for (int j = 0; j < phaseNumber; j++) {
1671 myParent.myInput.readUnsignedByte();
1672 myParent.myInput.readInt();
1673 myParent.myInput.readUnsignedByte();
1674 const double duration = myParent.myInput.readDouble();
1675 myParent.myInput.readUnsignedByte();
1676 const std::string state = myParent.myInput.readString();
1677 myParent.myInput.readUnsignedByte();
1678 const double minDur = myParent.myInput.readDouble();
1679 myParent.myInput.readUnsignedByte();
1680 const double maxDur = myParent.myInput.readDouble();
1681 myParent.myInput.readUnsignedByte();
1682 const int numNext = myParent.myInput.readInt();
1683 std::vector<int> next;
1684 for (int k = 0; k < numNext; k++) {
1685 myParent.myInput.readUnsignedByte();
1686 next.push_back(myParent.myInput.readInt());
1687 }
1688 myParent.myInput.readUnsignedByte();
1689 const std::string name = myParent.myInput.readString();
1690 logic.phases.emplace_back(new libsumo::TraCIPhase(duration, state, minDur, maxDur, next, name));
1691 }
1692 myParent.myInput.readUnsignedByte();
1693 const int paramNumber = myParent.myInput.readInt();
1694 for (int j = 0; j < paramNumber; j++) {
1695 myParent.myInput.readUnsignedByte();
1696 const std::vector<std::string> par = myParent.myInput.readStringList();
1697 logic.subParameter[par[0]] = par[1];
1698 }
1699 ret.emplace_back(logic);
1700 }
1701 }
1702 return ret;
1703}
1704
1705std::vector<std::string>
1707 return getStringVector(libsumo::TL_CONTROLLED_LANES, tlsID);
1708}
1709
1710std::vector<std::vector<libsumo::TraCILink> >
1712 std::vector<std::vector<libsumo::TraCILink> > result;
1713 myParent.createCommand(libsumo::CMD_GET_TL_VARIABLE, libsumo::TL_CONTROLLED_LINKS, tlsID);
1714 if (myParent.processGet(libsumo::CMD_GET_TL_VARIABLE, libsumo::TYPE_COMPOUND)) {
1715
1716 myParent.myInput.readUnsignedByte();
1717 myParent.myInput.readInt();
1718
1719 int linkNo = myParent.myInput.readInt();
1720 for (int i = 0; i < linkNo; ++i) {
1721 myParent.myInput.readUnsignedByte();
1722 int no = myParent.myInput.readInt();
1723 std::vector<libsumo::TraCILink> ret;
1724 for (int i1 = 0; i1 < no; ++i1) {
1725 myParent.myInput.readUnsignedByte();
1726 myParent.myInput.readInt();
1727 std::string from = myParent.myInput.readString();
1728 std::string to = myParent.myInput.readString();
1729 std::string via = myParent.myInput.readString();
1730 ret.emplace_back(libsumo::TraCILink(from, via, to));
1731 }
1732 result.emplace_back(ret);
1733 }
1734 }
1735 return result;
1736}
1737
1738std::string
1739TraCIAPI::TrafficLightScope::getProgram(const std::string& tlsID) const {
1740 return getString(libsumo::TL_CURRENT_PROGRAM, tlsID);
1741}
1742
1743int
1744TraCIAPI::TrafficLightScope::getPhase(const std::string& tlsID) const {
1745 return getInt(libsumo::TL_CURRENT_PHASE, tlsID);
1746}
1747
1748std::string
1749TraCIAPI::TrafficLightScope::getPhaseName(const std::string& tlsID) const {
1750 return getString(libsumo::VAR_NAME, tlsID);
1751}
1752
1753double
1754TraCIAPI::TrafficLightScope::getPhaseDuration(const std::string& tlsID) const {
1755 return getDouble(libsumo::TL_PHASE_DURATION, tlsID);
1756}
1757
1758double
1759TraCIAPI::TrafficLightScope::getNextSwitch(const std::string& tlsID) const {
1760 return getDouble(libsumo::TL_NEXT_SWITCH, tlsID);
1761}
1762
1763
1764int
1765TraCIAPI::TrafficLightScope::getServedPersonCount(const std::string& tlsID, int index) const {
1766 tcpip::Storage content;
1768 content.writeInt(index);
1769 return getInt(libsumo::VAR_PERSON_NUMBER, tlsID, &content);
1770}
1771
1772
1773void
1774TraCIAPI::TrafficLightScope::setRedYellowGreenState(const std::string& tlsID, const std::string& state) const {
1775 tcpip::Storage content;
1777 content.writeString(state);
1778 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_RED_YELLOW_GREEN_STATE, tlsID, &content);
1779 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1780}
1781
1782void
1783TraCIAPI::TrafficLightScope::setPhase(const std::string& tlsID, int index) const {
1784 tcpip::Storage content;
1786 content.writeInt(index);
1787 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PHASE_INDEX, tlsID, &content);
1788 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1789}
1790
1791void
1792TraCIAPI::TrafficLightScope::setPhaseName(const std::string& tlsID, const std::string& name) const {
1793 tcpip::Storage content;
1795 content.writeString(name);
1796 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::VAR_NAME, tlsID, &content);
1797 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1798}
1799
1800void
1801TraCIAPI::TrafficLightScope::setProgram(const std::string& tlsID, const std::string& programID) const {
1802 tcpip::Storage content;
1804 content.writeString(programID);
1805 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PROGRAM, tlsID, &content);
1806 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1807}
1808
1809void
1810TraCIAPI::TrafficLightScope::setPhaseDuration(const std::string& tlsID, double phaseDuration) const {
1811 tcpip::Storage content;
1813 content.writeDouble(phaseDuration);
1814 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PHASE_DURATION, tlsID, &content);
1815 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1816}
1817
1818void
1819TraCIAPI::TrafficLightScope::setProgramLogic(const std::string& tlsID, const libsumo::TraCILogic& logic) const {
1820 tcpip::Storage content;
1822 content.writeInt(5);
1824 content.writeString(logic.programID);
1826 content.writeInt(logic.type);
1828 content.writeInt(logic.currentPhaseIndex);
1830 content.writeInt((int)logic.phases.size());
1831 for (const std::shared_ptr<libsumo::TraCIPhase>& p : logic.phases) {
1833 content.writeInt(6);
1835 content.writeDouble(p->duration);
1837 content.writeString(p->state);
1839 content.writeDouble(p->minDur);
1841 content.writeDouble(p->maxDur);
1843 content.writeInt((int)p->next.size());
1844 for (int n : p->next) {
1846 content.writeInt(n);
1847 }
1849 content.writeString(p->name);
1850 }
1852 content.writeInt((int)logic.subParameter.size());
1853 for (const auto& item : logic.subParameter) {
1855 content.writeInt(2);
1856 content.writeString(item.first);
1857 content.writeString(item.second);
1858 }
1859 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_COMPLETE_PROGRAM_RYG, tlsID, &content);
1860 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1861}
1862
1863
1864// ---------------------------------------------------------------------------
1865// TraCIAPI::VehicleTypeScope-methods
1866// ---------------------------------------------------------------------------
1867double
1868TraCIAPI::VehicleTypeScope::getLength(const std::string& typeID) const {
1869 return getDouble(libsumo::VAR_LENGTH, typeID);
1870}
1871
1872double
1873TraCIAPI::VehicleTypeScope::getMaxSpeed(const std::string& typeID) const {
1874 return getDouble(libsumo::VAR_MAXSPEED, typeID);
1875}
1876
1877double
1878TraCIAPI::VehicleTypeScope::getSpeedFactor(const std::string& typeID) const {
1879 return getDouble(libsumo::VAR_SPEED_FACTOR, typeID);
1880}
1881
1882double
1883TraCIAPI::VehicleTypeScope::getSpeedDeviation(const std::string& typeID) const {
1884 return getDouble(libsumo::VAR_SPEED_DEVIATION, typeID);
1885}
1886
1887double
1888TraCIAPI::VehicleTypeScope::getAccel(const std::string& typeID) const {
1889 return getDouble(libsumo::VAR_ACCEL, typeID);
1890}
1891
1892double
1893TraCIAPI::VehicleTypeScope::getDecel(const std::string& typeID) const {
1894 return getDouble(libsumo::VAR_DECEL, typeID);
1895}
1896
1897double
1898TraCIAPI::VehicleTypeScope::getEmergencyDecel(const std::string& typeID) const {
1899 return getDouble(libsumo::VAR_EMERGENCY_DECEL, typeID);
1900}
1901
1902double
1903TraCIAPI::VehicleTypeScope::getApparentDecel(const std::string& typeID) const {
1904 return getDouble(libsumo::VAR_APPARENT_DECEL, typeID);
1905}
1906
1907double
1908TraCIAPI::VehicleTypeScope::getImperfection(const std::string& typeID) const {
1909 return getDouble(libsumo::VAR_IMPERFECTION, typeID);
1910}
1911
1912double
1913TraCIAPI::VehicleTypeScope::getTau(const std::string& typeID) const {
1914 return getDouble(libsumo::VAR_TAU, typeID);
1915}
1916
1917std::string
1918TraCIAPI::VehicleTypeScope::getVehicleClass(const std::string& typeID) const {
1919 return getString(libsumo::VAR_VEHICLECLASS, typeID);
1920}
1921
1922std::string
1923TraCIAPI::VehicleTypeScope::getEmissionClass(const std::string& typeID) const {
1924 return getString(libsumo::VAR_EMISSIONCLASS, typeID);
1925}
1926
1927std::string
1928TraCIAPI::VehicleTypeScope::getShapeClass(const std::string& typeID) const {
1929 return getString(libsumo::VAR_SHAPECLASS, typeID);
1930}
1931
1932double
1933TraCIAPI::VehicleTypeScope::getMinGap(const std::string& typeID) const {
1934 return getDouble(libsumo::VAR_MINGAP, typeID);
1935}
1936
1937double
1938TraCIAPI::VehicleTypeScope::getMinGapLat(const std::string& typeID) const {
1939 return getDouble(libsumo::VAR_MINGAP_LAT, typeID);
1940}
1941
1942double
1943TraCIAPI::VehicleTypeScope::getMaxSpeedLat(const std::string& typeID) const {
1944 return getDouble(libsumo::VAR_MAXSPEED_LAT, typeID);
1945}
1946
1947std::string
1948TraCIAPI::VehicleTypeScope::getLateralAlignment(const std::string& typeID) const {
1949 return getString(libsumo::VAR_LATALIGNMENT, typeID);
1950}
1951
1952int
1953TraCIAPI::VehicleTypeScope::getPersonCapacity(const std::string& typeID) const {
1954 return getInt(libsumo::VAR_PERSON_CAPACITY, typeID);
1955}
1956
1957double
1958TraCIAPI::VehicleTypeScope::getWidth(const std::string& typeID) const {
1959 return getDouble(libsumo::VAR_WIDTH, typeID);
1960}
1961
1962double
1963TraCIAPI::VehicleTypeScope::getHeight(const std::string& typeID) const {
1964 return getDouble(libsumo::VAR_HEIGHT, typeID);
1965}
1966
1968TraCIAPI::VehicleTypeScope::getColor(const std::string& typeID) const {
1969 return getCol(libsumo::VAR_COLOR, typeID);
1970}
1971
1972
1973
1974void
1975TraCIAPI::VehicleTypeScope::setLength(const std::string& typeID, double length) const {
1976 tcpip::Storage content;
1978 content.writeDouble(length);
1979 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_LENGTH, typeID, &content);
1980 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
1981}
1982
1983void
1984TraCIAPI::VehicleTypeScope::setMaxSpeed(const std::string& typeID, double speed) const {
1985 tcpip::Storage content;
1987 content.writeDouble(speed);
1988 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MAXSPEED, typeID, &content);
1989 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
1990}
1991
1992void
1993TraCIAPI::VehicleTypeScope::setVehicleClass(const std::string& typeID, const std::string& clazz) const {
1994 tcpip::Storage content;
1996 content.writeString(clazz);
1997 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_VEHICLECLASS, typeID, &content);
1998 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
1999}
2000
2001void
2002TraCIAPI::VehicleTypeScope::setSpeedFactor(const std::string& typeID, double factor) const {
2003 tcpip::Storage content;
2005 content.writeDouble(factor);
2006 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SPEED_FACTOR, typeID, &content);
2007 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2008}
2009
2010void
2011TraCIAPI::VehicleTypeScope::setSpeedDeviation(const std::string& typeID, double deviation) const {
2012 tcpip::Storage content;
2014 content.writeDouble(deviation);
2015 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SPEED_DEVIATION, typeID, &content);
2016 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2017}
2018
2019
2020void
2021TraCIAPI::VehicleTypeScope::setEmissionClass(const std::string& typeID, const std::string& clazz) const {
2022 tcpip::Storage content;
2024 content.writeString(clazz);
2025 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_EMISSIONCLASS, typeID, &content);
2026 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2027}
2028
2029void
2030TraCIAPI::VehicleTypeScope::setWidth(const std::string& typeID, double width) const {
2031 tcpip::Storage content;
2033 content.writeDouble(width);
2034 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_WIDTH, typeID, &content);
2035 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2036}
2037
2038void
2039TraCIAPI::VehicleTypeScope::setHeight(const std::string& typeID, double height) const {
2040 tcpip::Storage content;
2042 content.writeDouble(height);
2043 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_HEIGHT, typeID, &content);
2044 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2045}
2046
2047void
2048TraCIAPI::VehicleTypeScope::setMinGap(const std::string& typeID, double minGap) const {
2049 tcpip::Storage content;
2051 content.writeDouble(minGap);
2052 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MINGAP, typeID, &content);
2053 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2054}
2055
2056
2057void
2058TraCIAPI::VehicleTypeScope::setMinGapLat(const std::string& typeID, double minGapLat) const {
2059 tcpip::Storage content;
2061 content.writeDouble(minGapLat);
2062 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MINGAP_LAT, typeID, &content);
2063 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2064}
2065
2066void
2067TraCIAPI::VehicleTypeScope::setMaxSpeedLat(const std::string& typeID, double speed) const {
2068 tcpip::Storage content;
2070 content.writeDouble(speed);
2071 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MAXSPEED_LAT, typeID, &content);
2072 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2073}
2074
2075void
2076TraCIAPI::VehicleTypeScope::setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const {
2077 tcpip::Storage content;
2079 content.writeString(latAlignment);
2080 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_LATALIGNMENT, typeID, &content);
2081 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2082}
2083
2084void
2085TraCIAPI::VehicleTypeScope::copy(const std::string& origTypeID, const std::string& newTypeID) const {
2086 tcpip::Storage content;
2088 content.writeString(newTypeID);
2089 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::COPY, origTypeID, &content);
2090 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2091}
2092
2093void
2094TraCIAPI::VehicleTypeScope::setShapeClass(const std::string& typeID, const std::string& clazz) const {
2095 tcpip::Storage content;
2097 content.writeString(clazz);
2098 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SHAPECLASS, typeID, &content);
2099 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2100}
2101
2102void
2103TraCIAPI::VehicleTypeScope::setAccel(const std::string& typeID, double accel) const {
2104 tcpip::Storage content;
2106 content.writeDouble(accel);
2107 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_ACCEL, typeID, &content);
2108 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2109}
2110
2111void
2112TraCIAPI::VehicleTypeScope::setDecel(const std::string& typeID, double decel) const {
2113 tcpip::Storage content;
2115 content.writeDouble(decel);
2116 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_DECEL, typeID, &content);
2117 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2118}
2119
2120void
2121TraCIAPI::VehicleTypeScope::setEmergencyDecel(const std::string& typeID, double decel) const {
2122 tcpip::Storage content;
2124 content.writeDouble(decel);
2125 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_EMERGENCY_DECEL, typeID, &content);
2126 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2127}
2128
2129void
2130TraCIAPI::VehicleTypeScope::setApparentDecel(const std::string& typeID, double decel) const {
2131 tcpip::Storage content;
2133 content.writeDouble(decel);
2134 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_APPARENT_DECEL, typeID, &content);
2135 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2136}
2137
2138void
2139TraCIAPI::VehicleTypeScope::setImperfection(const std::string& typeID, double imperfection) const {
2140 tcpip::Storage content;
2142 content.writeDouble(imperfection);
2143 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_IMPERFECTION, typeID, &content);
2144 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2145}
2146
2147void
2148TraCIAPI::VehicleTypeScope::setTau(const std::string& typeID, double tau) const {
2149 tcpip::Storage content;
2151 content.writeDouble(tau);
2152 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_TAU, typeID, &content);
2153 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2154}
2155
2156void
2157TraCIAPI::VehicleTypeScope::setColor(const std::string& typeID, const libsumo::TraCIColor& c) const {
2158 tcpip::Storage content;
2160 content.writeUnsignedByte(c.r);
2161 content.writeUnsignedByte(c.g);
2162 content.writeUnsignedByte(c.b);
2163 content.writeUnsignedByte(c.a);
2164 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_COLOR, typeID, &content);
2165 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2166}
2167
2168
2169// ---------------------------------------------------------------------------
2170// TraCIAPI::VehicleScope-methods
2171// ---------------------------------------------------------------------------
2172double
2173TraCIAPI::VehicleScope::getSpeed(const std::string& vehicleID) const {
2174 return getDouble(libsumo::VAR_SPEED, vehicleID);
2175}
2176
2177double
2178TraCIAPI::VehicleScope::getLateralSpeed(const std::string& vehicleID) const {
2179 return getDouble(libsumo::VAR_SPEED_LAT, vehicleID);
2180}
2181
2182double
2183TraCIAPI::VehicleScope::getAcceleration(const std::string& vehicleID) const {
2184 return getDouble(libsumo::VAR_ACCELERATION, vehicleID);
2185}
2186
2187double
2188TraCIAPI::VehicleScope::getFollowSpeed(const std::string& vehicleID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) const {
2189 tcpip::Storage content;
2191 content.writeInt(5);
2193 content.writeDouble(speed);
2195 content.writeDouble(gap);
2197 content.writeDouble(leaderSpeed);
2199 content.writeDouble(leaderMaxDecel);
2201 content.writeString(leaderID);
2202 return getDouble(libsumo::VAR_FOLLOW_SPEED, vehicleID, &content);
2203}
2204
2205
2206double
2207TraCIAPI::VehicleScope::getSecureGap(const std::string& vehicleID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) const {
2208 tcpip::Storage content;
2210 content.writeInt(4);
2212 content.writeDouble(speed);
2214 content.writeDouble(leaderSpeed);
2216 content.writeDouble(leaderMaxDecel);
2218 content.writeString(leaderID);
2219 return getDouble(libsumo::VAR_SECURE_GAP, vehicleID, &content);
2220}
2221
2222double
2223TraCIAPI::VehicleScope::getStopSpeed(const std::string& vehicleID, double speed, double gap) const {
2224 tcpip::Storage content;
2226 content.writeInt(2);
2228 content.writeDouble(speed);
2230 content.writeDouble(gap);
2231 return getDouble(libsumo::VAR_STOP_SPEED, vehicleID, &content);
2232}
2233
2234
2235double
2236TraCIAPI::VehicleScope::getMaxSpeed(const std::string& vehicleID) const {
2237 return getDouble(libsumo::VAR_MAXSPEED, vehicleID);
2238}
2239
2241TraCIAPI::VehicleScope::getPosition(const std::string& vehicleID) const {
2242 return getPos(libsumo::VAR_POSITION, vehicleID);
2243}
2244
2246TraCIAPI::VehicleScope::getPosition3D(const std::string& vehicleID) const {
2247 return getPos3D(libsumo::VAR_POSITION3D, vehicleID);
2248}
2249
2250double
2251TraCIAPI::VehicleScope::getAngle(const std::string& vehicleID) const {
2252 return getDouble(libsumo::VAR_ANGLE, vehicleID);
2253}
2254
2255std::string
2256TraCIAPI::VehicleScope::getRoadID(const std::string& vehicleID) const {
2257 return getString(libsumo::VAR_ROAD_ID, vehicleID);
2258}
2259
2260std::string
2261TraCIAPI::VehicleScope::getLaneID(const std::string& vehicleID) const {
2262 return getString(libsumo::VAR_LANE_ID, vehicleID);
2263}
2264
2265int
2266TraCIAPI::VehicleScope::getLaneIndex(const std::string& vehicleID) const {
2267 return getInt(libsumo::VAR_LANE_INDEX, vehicleID);
2268}
2269
2270std::string
2271TraCIAPI::VehicleScope::getTypeID(const std::string& vehicleID) const {
2272 return getString(libsumo::VAR_TYPE, vehicleID);
2273}
2274
2275std::string
2276TraCIAPI::VehicleScope::getRouteID(const std::string& vehicleID) const {
2277 return getString(libsumo::VAR_ROUTE_ID, vehicleID);
2278}
2279
2280int
2281TraCIAPI::VehicleScope::getRouteIndex(const std::string& vehicleID) const {
2282 return getInt(libsumo::VAR_ROUTE_INDEX, vehicleID);
2283}
2284
2285
2286std::vector<std::string>
2287TraCIAPI::VehicleScope::getRoute(const std::string& vehicleID) const {
2288 return getStringVector(libsumo::VAR_EDGES, vehicleID);
2289}
2290
2292TraCIAPI::VehicleScope::getColor(const std::string& vehicleID) const {
2293 return getCol(libsumo::VAR_COLOR, vehicleID);
2294}
2295
2296double
2297TraCIAPI::VehicleScope::getLanePosition(const std::string& vehicleID) const {
2298 return getDouble(libsumo::VAR_LANEPOSITION, vehicleID);
2299}
2300
2301double
2302TraCIAPI::VehicleScope::getDistance(const std::string& vehicleID) const {
2303 return getDouble(libsumo::VAR_DISTANCE, vehicleID);
2304}
2305
2306int
2307TraCIAPI::VehicleScope::getSignals(const std::string& vehicleID) const {
2308 return getInt(libsumo::VAR_SIGNALS, vehicleID);
2309}
2310
2311double
2312TraCIAPI::VehicleScope::getLateralLanePosition(const std::string& vehicleID) const {
2313 return getDouble(libsumo::VAR_LANEPOSITION_LAT, vehicleID);
2314}
2315
2316double
2317TraCIAPI::VehicleScope::getCO2Emission(const std::string& vehicleID) const {
2318 return getDouble(libsumo::VAR_CO2EMISSION, vehicleID);
2319}
2320
2321double
2322TraCIAPI::VehicleScope::getCOEmission(const std::string& vehicleID) const {
2323 return getDouble(libsumo::VAR_COEMISSION, vehicleID);
2324}
2325
2326double
2327TraCIAPI::VehicleScope::getHCEmission(const std::string& vehicleID) const {
2328 return getDouble(libsumo::VAR_HCEMISSION, vehicleID);
2329}
2330
2331double
2332TraCIAPI::VehicleScope::getPMxEmission(const std::string& vehicleID) const {
2333 return getDouble(libsumo::VAR_PMXEMISSION, vehicleID);
2334}
2335
2336double
2337TraCIAPI::VehicleScope::getNOxEmission(const std::string& vehicleID) const {
2338 return getDouble(libsumo::VAR_NOXEMISSION, vehicleID);
2339}
2340
2341double
2342TraCIAPI::VehicleScope::getFuelConsumption(const std::string& vehicleID) const {
2343 return getDouble(libsumo::VAR_FUELCONSUMPTION, vehicleID);
2344}
2345
2346double
2347TraCIAPI::VehicleScope::getNoiseEmission(const std::string& vehicleID) const {
2348 return getDouble(libsumo::VAR_NOISEEMISSION, vehicleID);
2349}
2350
2351double
2352TraCIAPI::VehicleScope::getElectricityConsumption(const std::string& vehicleID) const {
2353 return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, vehicleID);
2354}
2355
2356double
2357TraCIAPI::VehicleScope::getWaitingTime(const std::string& vehID) const {
2358 return getDouble(libsumo::VAR_WAITING_TIME, vehID);
2359}
2360
2361int
2362TraCIAPI::VehicleScope::getLaneChangeMode(const std::string& vehID) const {
2363 return getInt(libsumo::VAR_LANECHANGE_MODE, vehID);
2364}
2365
2366
2367int
2368TraCIAPI::VehicleScope::getSpeedMode(const std::string& vehID) const {
2369 return getInt(libsumo::VAR_SPEEDSETMODE, vehID);
2370}
2371
2372
2373double
2374TraCIAPI::VehicleScope::getSlope(const std::string& vehID) const {
2375 return getDouble(libsumo::VAR_SLOPE, vehID);
2376}
2377
2378
2379std::string
2380TraCIAPI::VehicleScope::getLine(const std::string& typeID) const {
2381 return getString(libsumo::VAR_LINE, typeID);
2382}
2383
2384std::vector<std::string>
2385TraCIAPI::VehicleScope::getVia(const std::string& vehicleID) const {
2386 return getStringVector(libsumo::VAR_VIA, vehicleID);
2387}
2388
2389std::string
2390TraCIAPI::VehicleScope::getEmissionClass(const std::string& vehicleID) const {
2391 return getString(libsumo::VAR_EMISSIONCLASS, vehicleID);
2392}
2393
2394std::string
2395TraCIAPI::VehicleScope::getShapeClass(const std::string& vehicleID) const {
2396 return getString(libsumo::VAR_SHAPECLASS, vehicleID);
2397}
2398
2399std::vector<libsumo::TraCINextTLSData>
2400TraCIAPI::VehicleScope::getNextTLS(const std::string& vehID) const {
2401 std::vector<libsumo::TraCINextTLSData> result;
2402 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_NEXT_TLS, vehID);
2404 myParent.myInput.readInt(); // components
2405 // number of items
2406 myParent.myInput.readUnsignedByte();
2407 const int n = myParent.myInput.readInt();
2408 for (int i = 0; i < n; ++i) {
2410 myParent.myInput.readUnsignedByte();
2411 d.id = myParent.myInput.readString();
2412
2413 myParent.myInput.readUnsignedByte();
2414 d.tlIndex = myParent.myInput.readInt();
2415
2416 myParent.myInput.readUnsignedByte();
2417 d.dist = myParent.myInput.readDouble();
2418
2419 myParent.myInput.readUnsignedByte();
2420 d.state = (char)myParent.myInput.readByte();
2421
2422 result.push_back(d);
2423 }
2424 }
2425 return result;
2426}
2427
2428std::vector<libsumo::TraCIBestLanesData>
2429TraCIAPI::VehicleScope::getBestLanes(const std::string& vehicleID) const {
2430 std::vector<libsumo::TraCIBestLanesData> result;
2431 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_BEST_LANES, vehicleID);
2433 myParent.myInput.readInt();
2434 myParent.myInput.readUnsignedByte();
2435
2436 const int n = myParent.myInput.readInt(); // number of following edge information
2437 for (int i = 0; i < n; ++i) {
2439 myParent.myInput.readUnsignedByte();
2440 info.laneID = myParent.myInput.readString();
2441
2442 myParent.myInput.readUnsignedByte();
2443 info.length = myParent.myInput.readDouble();
2444
2445 myParent.myInput.readUnsignedByte();
2446 info.occupation = myParent.myInput.readDouble();
2447
2448 myParent.myInput.readUnsignedByte();
2449 info.bestLaneOffset = myParent.myInput.readByte();
2450
2451 myParent.myInput.readUnsignedByte();
2452 info.allowsContinuation = (myParent.myInput.readUnsignedByte() == 1);
2453
2454 myParent.myInput.readUnsignedByte();
2455 const int m = myParent.myInput.readInt();
2456 for (int j = 0; j < m; ++j) {
2457 info.continuationLanes.push_back(myParent.myInput.readString());
2458 }
2459
2460 result.push_back(info);
2461 }
2462 }
2463 return result;
2464}
2465
2466
2467std::pair<std::string, double>
2468TraCIAPI::VehicleScope::getLeader(const std::string& vehicleID, double dist) const {
2469 tcpip::Storage content;
2471 content.writeDouble(dist);
2472 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_LEADER, vehicleID, &content);
2474 myParent.myInput.readInt(); // components
2475 myParent.myInput.readUnsignedByte();
2476 const std::string leaderID = myParent.myInput.readString();
2477 myParent.myInput.readUnsignedByte();
2478 const double gap = myParent.myInput.readDouble();
2479 return std::make_pair(leaderID, gap);
2480 }
2481 return std::make_pair("", libsumo::INVALID_DOUBLE_VALUE);
2482}
2483
2484
2485std::pair<std::string, double>
2486TraCIAPI::VehicleScope::getFollower(const std::string& vehicleID, double dist) const {
2487 tcpip::Storage content;
2489 content.writeDouble(dist);
2490 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_FOLLOWER, vehicleID, &content);
2492 myParent.myInput.readInt(); // components
2493 myParent.myInput.readUnsignedByte();
2494 const std::string leaderID = myParent.myInput.readString();
2495 myParent.myInput.readUnsignedByte();
2496 const double gap = myParent.myInput.readDouble();
2497 return std::make_pair(leaderID, gap);
2498 }
2499 return std::make_pair("", libsumo::INVALID_DOUBLE_VALUE);
2500}
2501
2502
2503std::pair<int, int>
2504TraCIAPI::VehicleScope::getLaneChangeState(const std::string& vehicleID, int direction) const {
2505 tcpip::Storage content;
2507 content.writeInt(direction);
2508 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2510 myParent.myInput.readInt(); // components
2511 myParent.myInput.readUnsignedByte();
2512 const int stateWithoutTraCI = myParent.myInput.readInt();
2513 myParent.myInput.readUnsignedByte();
2514 const int state = myParent.myInput.readInt();
2515 return std::make_pair(stateWithoutTraCI, state);
2516 }
2518}
2519
2520
2521int
2522TraCIAPI::VehicleScope::getStopState(const std::string& vehicleID) const {
2523 return getInt(libsumo::VAR_STOPSTATE, vehicleID);
2524}
2525
2526int
2527TraCIAPI::VehicleScope::getRoutingMode(const std::string& vehicleID) const {
2528 return getInt(libsumo::VAR_ROUTING_MODE, vehicleID);
2529}
2530
2531double
2532TraCIAPI::VehicleScope::getStopDelay(const std::string& vehicleID) const {
2533 return getDouble(libsumo::VAR_STOP_DELAY, vehicleID);
2534}
2535
2536double
2537TraCIAPI::VehicleScope::getStopArrivalDelay(const std::string& vehicleID) const {
2538 return getDouble(libsumo::VAR_STOP_ARRIVALDELAY, vehicleID);
2539}
2540
2541
2542double
2543TraCIAPI::VehicleScope::getAccel(const std::string& vehicleID) const {
2544 return getDouble(libsumo::VAR_ACCEL, vehicleID);
2545}
2546
2547double
2548TraCIAPI::VehicleScope::getDecel(const std::string& vehicleID) const {
2549 return getDouble(libsumo::VAR_DECEL, vehicleID);
2550}
2551
2552double
2553TraCIAPI::VehicleScope::getTau(const std::string& vehicleID) const {
2554 return getDouble(libsumo::VAR_TAU, vehicleID);
2555}
2556
2557double
2558TraCIAPI::VehicleScope::getImperfection(const std::string& vehicleID) const {
2559 return getDouble(libsumo::VAR_IMPERFECTION, vehicleID);
2560}
2561
2562double
2563TraCIAPI::VehicleScope::getSpeedFactor(const std::string& vehicleID) const {
2564 return getDouble(libsumo::VAR_SPEED_FACTOR, vehicleID);
2565}
2566
2567double
2568TraCIAPI::VehicleScope::getSpeedDeviation(const std::string& vehicleID) const {
2569 return getDouble(libsumo::VAR_SPEED_DEVIATION, vehicleID);
2570}
2571
2572std::string
2573TraCIAPI::VehicleScope::getVehicleClass(const std::string& vehicleID) const {
2574 return getString(libsumo::VAR_VEHICLECLASS, vehicleID);
2575}
2576
2577double
2578TraCIAPI::VehicleScope::getMinGap(const std::string& vehicleID) const {
2579 return getDouble(libsumo::VAR_MINGAP, vehicleID);
2580}
2581
2582double
2583TraCIAPI::VehicleScope::getWidth(const std::string& vehicleID) const {
2584 return getDouble(libsumo::VAR_WIDTH, vehicleID);
2585}
2586
2587double
2588TraCIAPI::VehicleScope::getLength(const std::string& vehicleID) const {
2589 return getDouble(libsumo::VAR_LENGTH, vehicleID);
2590}
2591
2592double
2593TraCIAPI::VehicleScope::getHeight(const std::string& vehicleID) const {
2594 return getDouble(libsumo::VAR_HEIGHT, vehicleID);
2595}
2596
2597double
2598TraCIAPI::VehicleScope::getAccumulatedWaitingTime(const std::string& vehicleID) const {
2599 return getDouble(libsumo::VAR_ACCUMULATED_WAITING_TIME, vehicleID);
2600}
2601
2602double
2603TraCIAPI::VehicleScope::getAllowedSpeed(const std::string& vehicleID) const {
2604 return getDouble(libsumo::VAR_ALLOWED_SPEED, vehicleID);
2605}
2606
2607int
2608TraCIAPI::VehicleScope::getPersonNumber(const std::string& vehicleID) const {
2609 return getInt(libsumo::VAR_PERSON_NUMBER, vehicleID);
2610}
2611
2612int
2613TraCIAPI::VehicleScope::getPersonCapacity(const std::string& vehicleID) const {
2614 return getInt(libsumo::VAR_PERSON_CAPACITY, vehicleID);
2615}
2616
2617std::vector<std::string>
2618TraCIAPI::VehicleScope::getPersonIDList(const std::string& vehicleID) const {
2619 return getStringVector(libsumo::LAST_STEP_PERSON_ID_LIST, vehicleID);
2620}
2621
2622double
2623TraCIAPI::VehicleScope::getSpeedWithoutTraCI(const std::string& vehicleID) const {
2624 return getDouble(libsumo::VAR_SPEED_WITHOUT_TRACI, vehicleID);
2625}
2626
2627bool
2628TraCIAPI::VehicleScope::isRouteValid(const std::string& vehicleID) const {
2629 return getInt(libsumo::VAR_ROUTE_VALID, vehicleID) != 0;
2630}
2631
2632double
2633TraCIAPI::VehicleScope::getMaxSpeedLat(const std::string& vehicleID) const {
2634 return getDouble(libsumo::VAR_MAXSPEED_LAT, vehicleID);
2635}
2636
2637double
2638TraCIAPI::VehicleScope::getMinGapLat(const std::string& vehicleID) const {
2639 return getDouble(libsumo::VAR_MINGAP_LAT, vehicleID);
2640}
2641
2642std::string
2643TraCIAPI::VehicleScope::getLateralAlignment(const std::string& vehicleID) const {
2644 return getString(libsumo::VAR_LATALIGNMENT, vehicleID);
2645}
2646
2647void
2648TraCIAPI::VehicleScope::add(const std::string& vehicleID,
2649 const std::string& routeID,
2650 const std::string& typeID,
2651 std::string depart,
2652 const std::string& departLane,
2653 const std::string& departPos,
2654 const std::string& departSpeed,
2655 const std::string& arrivalLane,
2656 const std::string& arrivalPos,
2657 const std::string& arrivalSpeed,
2658 const std::string& fromTaz,
2659 const std::string& toTaz,
2660 const std::string& line,
2661 int personCapacity,
2662 int personNumber) const {
2663
2664 if (depart == "-1") {
2665 depart = toString(myParent.simulation.getCurrentTime() / 1000.0);
2666 }
2667 tcpip::Storage content;
2669 content.writeInt(14);
2671 content.writeString(routeID);
2673 content.writeString(typeID);
2675 content.writeString(depart);
2677 content.writeString(departLane);
2679 content.writeString(departPos);
2681 content.writeString(departSpeed);
2682
2684 content.writeString(arrivalLane);
2686 content.writeString(arrivalPos);
2688 content.writeString(arrivalSpeed);
2689
2691 content.writeString(fromTaz);
2693 content.writeString(toTaz);
2695 content.writeString(line);
2696
2698 content.writeInt(personCapacity);
2700 content.writeInt(personNumber);
2701
2702 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::ADD_FULL, vehicleID, &content);
2703 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2704}
2705
2706
2707void
2708TraCIAPI::VehicleScope::remove(const std::string& vehicleID, char reason) const {
2709 tcpip::Storage content;
2711 content.writeUnsignedByte(reason);
2712 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::REMOVE, vehicleID, &content);
2713 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2714
2715}
2716
2717
2718void
2719TraCIAPI::VehicleScope::changeTarget(const std::string& vehicleID, const std::string& edgeID) const {
2720 tcpip::Storage content;
2722 content.writeString(edgeID);
2723 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGETARGET, vehicleID, &content);
2724 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2725}
2726
2727
2728void
2729TraCIAPI::VehicleScope::changeLane(const std::string& vehicleID, int laneIndex, double duration) const {
2730 tcpip::Storage content;
2732 content.writeInt(2);
2734 content.writeByte(laneIndex);
2736 content.writeDouble(duration);
2737 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2738 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2739}
2740
2741
2742void
2743TraCIAPI::VehicleScope::changeLaneRelative(const std::string& vehicleID, int laneChange, double duration) const {
2744 tcpip::Storage content;
2746 content.writeInt(3);
2748 content.writeByte(laneChange);
2750 content.writeDouble(duration);
2752 content.writeByte(1);
2753 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2754 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2755}
2756
2757
2758void
2759TraCIAPI::VehicleScope::changeSublane(const std::string& vehicleID, double latDist) const {
2760 tcpip::Storage content;
2762 content.writeDouble(latDist);
2763 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGESUBLANE, vehicleID, &content);
2764 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2765}
2766
2767
2768void
2769TraCIAPI::VehicleScope::setRouteID(const std::string& vehicleID, const std::string& routeID) const {
2770 tcpip::Storage content;
2772 content.writeString(routeID);
2773 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE_ID, vehicleID, &content);
2774 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2775}
2776
2777
2778void
2779TraCIAPI::VehicleScope::setRoute(const std::string& vehicleID, const std::vector<std::string>& edges) const {
2780 tcpip::Storage content;
2782 content.writeInt((int)edges.size());
2783 for (int i = 0; i < (int)edges.size(); ++i) {
2784 content.writeString(edges[i]);
2785 }
2786 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE, vehicleID, &content);
2787 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2788}
2789
2790
2791void
2792TraCIAPI::VehicleScope::rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes) const {
2793 if (currentTravelTimes) {
2794 // updated edge weights with current network traveltimes (at most once per simulation step)
2795 std::vector<std::string> edges = myParent.edge.getIDList();
2796 for (std::vector<std::string>::iterator it = edges.begin(); it != edges.end(); ++it) {
2797 myParent.edge.adaptTraveltime(*it, myParent.edge.getTraveltime(*it));
2798 }
2799 }
2800
2801 tcpip::Storage content;
2803 content.writeInt(0);
2804 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_REROUTE_TRAVELTIME, vehicleID, &content);
2805 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2806}
2807
2808void
2809TraCIAPI::VehicleScope::moveTo(const std::string& vehicleID, const std::string& laneID, double position, int reason) const {
2810 tcpip::Storage content;
2812 content.writeInt(3);
2814 content.writeString(laneID);
2816 content.writeDouble(position);
2818 content.writeInt(reason);
2819 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MOVE_TO, vehicleID, &content);
2820 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2821}
2822
2823void
2824TraCIAPI::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 {
2825 tcpip::Storage content;
2827 content.writeInt(6);
2829 content.writeString(edgeID);
2831 content.writeInt(lane);
2833 content.writeDouble(x);
2835 content.writeDouble(y);
2837 content.writeDouble(angle);
2839 content.writeByte(keepRoute);
2840 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::MOVE_TO_XY, vehicleID, &content);
2841 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2842}
2843
2844
2845void
2846TraCIAPI::VehicleScope::slowDown(const std::string& vehicleID, double speed, double duration) const {
2847 tcpip::Storage content;
2849 content.writeInt(2);
2851 content.writeDouble(speed);
2853 content.writeDouble(duration);
2854 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_SLOWDOWN, vehicleID, &content);
2855 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2856}
2857
2858void
2859TraCIAPI::VehicleScope::openGap(const std::string& vehicleID, double newTau, double duration, double changeRate, double maxDecel) const {
2860 tcpip::Storage content;
2862 if (maxDecel > 0) {
2863 content.writeInt(4);
2864 } else {
2865 content.writeInt(3);
2866 }
2868 content.writeDouble(newTau);
2870 content.writeDouble(duration);
2872 content.writeDouble(changeRate);
2873 if (maxDecel > 0) {
2875 content.writeDouble(maxDecel);
2876 }
2877 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_OPENGAP, vehicleID, &content);
2878 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2879}
2880
2881void
2882TraCIAPI::VehicleScope::setSpeed(const std::string& vehicleID, double speed) const {
2883 tcpip::Storage content;
2885 content.writeDouble(speed);
2886 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEED, vehicleID, &content);
2887 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2888}
2889
2890void
2891TraCIAPI::VehicleScope::setAcceleration(const std::string& vehicleID, double accel, double duration) const {
2892 tcpip::Storage content;
2894 content.writeInt(2);
2896 content.writeDouble(accel);
2898 content.writeDouble(duration);
2899 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ACCELERATION, vehicleID, &content);
2900 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2901}
2902
2903void
2904TraCIAPI::VehicleScope::setPreviousSpeed(const std::string& vehicleID, double prevSpeed, double prevAcceleration) const {
2905 tcpip::Storage content;
2907 content.writeInt(2);
2909 content.writeDouble(prevSpeed);
2911 content.writeDouble(prevAcceleration);
2912 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_PREV_SPEED, vehicleID, &content);
2913 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2914}
2915
2916void
2917TraCIAPI::VehicleScope::setLaneChangeMode(const std::string& vehicleID, int mode) const {
2918 tcpip::Storage content;
2920 content.writeInt(mode);
2921 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_LANECHANGE_MODE, vehicleID, &content);
2922 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2923}
2924
2925void
2926TraCIAPI::VehicleScope::setSpeedMode(const std::string& vehicleID, int mode) const {
2927 tcpip::Storage content;
2929 content.writeInt(mode);
2930 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEEDSETMODE, vehicleID, &content);
2931 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2932}
2933
2934void
2935TraCIAPI::VehicleScope::setStop(const std::string vehicleID, const std::string edgeID, const double endPos, const int laneIndex,
2936 const double duration, const int flags, const double startPos, const double until) const {
2937 tcpip::Storage content;
2939 content.writeInt(7);
2941 content.writeString(edgeID);
2943 content.writeDouble(endPos);
2945 content.writeByte(laneIndex);
2947 content.writeDouble(duration);
2949 content.writeByte(flags);
2951 content.writeDouble(startPos);
2953 content.writeDouble(until);
2954 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_STOP, vehicleID, &content);
2955 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2956}
2957
2958void
2959TraCIAPI::VehicleScope::setType(const std::string& vehicleID, const std::string& typeID) const {
2960 tcpip::Storage content;
2962 content.writeString(typeID);
2963 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_TYPE, vehicleID, &content);
2964 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2965}
2966
2967void
2968TraCIAPI::VehicleScope::setSpeedFactor(const std::string& vehicleID, double factor) const {
2969 tcpip::Storage content;
2971 content.writeDouble(factor);
2972 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEED_FACTOR, vehicleID, &content);
2973 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2974}
2975
2976void
2977TraCIAPI::VehicleScope::setMinGap(const std::string& vehicleID, double minGap) const {
2978 tcpip::Storage content;
2980 content.writeDouble(minGap);
2981 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MINGAP, vehicleID, &content);
2982 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2983}
2984
2985void
2986TraCIAPI::VehicleScope::setMaxSpeed(const std::string& vehicleID, double speed) const {
2987 tcpip::Storage content;
2989 content.writeDouble(speed);
2990 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MAXSPEED, vehicleID, &content);
2991 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2992}
2993
2994void
2995TraCIAPI::VehicleScope::setColor(const std::string& vehicleID, const libsumo::TraCIColor& c) const {
2996 tcpip::Storage content;
2998 content.writeUnsignedByte(c.r);
2999 content.writeUnsignedByte(c.g);
3000 content.writeUnsignedByte(c.b);
3001 content.writeUnsignedByte(c.a);
3002 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_COLOR, vehicleID, &content);
3003 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3004}
3005
3006void
3007TraCIAPI::VehicleScope::setLine(const std::string& vehicleID, const std::string& line) const {
3008 tcpip::Storage content;
3010 content.writeString(line);
3011 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_LINE, vehicleID, &content);
3012 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3013}
3014
3015void
3016TraCIAPI::VehicleScope::setVia(const std::string& vehicleID, const std::vector<std::string>& via) const {
3017 tcpip::Storage content;
3019 content.writeInt((int)via.size());
3020 for (int i = 0; i < (int)via.size(); ++i) {
3021 content.writeString(via[i]);
3022 }
3023 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_VIA, vehicleID, &content);
3024 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3025}
3026
3027void
3028TraCIAPI::VehicleScope::setSignals(const std::string& vehicleID, int signals) const {
3029 tcpip::Storage content;
3031 content.writeInt(signals);
3032 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SIGNALS, vehicleID, &content);
3033 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3034}
3035
3036void
3037TraCIAPI::VehicleScope::setRoutingMode(const std::string& vehicleID, int routingMode) const {
3038 tcpip::Storage content;
3040 content.writeInt(routingMode);
3041 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTING_MODE, vehicleID, &content);
3042 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3043}
3044
3045void
3046TraCIAPI::VehicleScope::setShapeClass(const std::string& vehicleID, const std::string& clazz) const {
3047 tcpip::Storage content;
3049 content.writeString(clazz);
3050 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SHAPECLASS, vehicleID, &content);
3051 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3052}
3053
3054
3055void
3056TraCIAPI::VehicleScope::setEmissionClass(const std::string& vehicleID, const std::string& clazz) const {
3057 tcpip::Storage content;
3059 content.writeString(clazz);
3060 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_EMISSIONCLASS, vehicleID, &content);
3061 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3062}
3063
3064void
3066 bool noOpposite, double downstreamDist, double upstreamDist) const {
3067 addSubscriptionFilterByteList(libsumo::FILTER_TYPE_LANES, lanes);
3068 if (noOpposite) {
3069 addSubscriptionFilterNoOpposite();
3070 }
3071 if (downstreamDist >= 0) {
3072 addSubscriptionFilterDownstreamDistance(downstreamDist);
3073 }
3074 if (upstreamDist >= 0) {
3075 addSubscriptionFilterUpstreamDistance(upstreamDist);
3076 }
3077}
3078
3079
3080void
3084
3085void
3089
3090void
3092 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_UPSTREAM_DIST, dist);
3093}
3094
3095
3096void
3097TraCIAPI::VehicleScope::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) const {
3098 addSubscriptionFilterLeadFollow(std::vector<int>({0}));
3099 if (downstreamDist >= 0) {
3100 addSubscriptionFilterDownstreamDistance(downstreamDist);
3101 }
3102 if (upstreamDist >= 0) {
3103 addSubscriptionFilterUpstreamDistance(upstreamDist);
3104 }
3105}
3106
3107void
3108TraCIAPI::VehicleScope::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) const {
3109 if (abs(direction) != 1) {
3110 std::cerr << "Ignoring lane change subscription filter with non-neighboring lane offset direction " << direction << "\n";
3111 return;
3112 }
3113 addSubscriptionFilterLeadFollow(std::vector<int>({0, direction}));
3114 if (noOpposite) {
3115 addSubscriptionFilterNoOpposite();
3116 }
3117 if (downstreamDist >= 0) {
3118 addSubscriptionFilterDownstreamDistance(downstreamDist);
3119 }
3120 if (upstreamDist >= 0) {
3121 addSubscriptionFilterUpstreamDistance(upstreamDist);
3122 }
3123}
3124
3125void
3127 addSubscriptionFilterEmpty(libsumo::FILTER_TYPE_LEAD_FOLLOW);
3128 addSubscriptionFilterByteList(libsumo::FILTER_TYPE_LANES, lanes);
3129}
3130
3131void
3132TraCIAPI::VehicleScope::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) const {
3133 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_TURN, foeDistToJunction);
3134 if (downstreamDist >= 0) {
3135 addSubscriptionFilterDownstreamDistance(downstreamDist);
3136 }
3137}
3138
3139
3140void
3141TraCIAPI::VehicleScope::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) const {
3142 addSubscriptionFilterStringList(libsumo::FILTER_TYPE_VCLASS, vClasses);
3143}
3144
3145
3146void
3147TraCIAPI::VehicleScope::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) const {
3148 addSubscriptionFilterStringList(libsumo::FILTER_TYPE_VTYPE, vTypes);
3149}
3150
3151
3152void
3154 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_FIELD_OF_VISION, angle);
3155}
3156
3157void
3158TraCIAPI::VehicleScope::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) const {
3159 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_LATERAL_DIST, lateralDist);
3160 if (downstreamDist >= 0) {
3161 addSubscriptionFilterDownstreamDistance(downstreamDist);
3162 }
3163 if (upstreamDist >= 0) {
3164 addSubscriptionFilterUpstreamDistance(upstreamDist);
3165 }
3166}
3167
3168void
3170 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType);
3171 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3172}
3173
3174void
3176 tcpip::Storage content;
3178 content.writeDouble(val);
3179 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3180 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3181}
3182
3183
3184void
3185TraCIAPI::VehicleScope::addSubscriptionFilterStringList(int filterType, const std::vector<std::string>& vals) const {
3186 tcpip::Storage content;
3188 content.writeStringList(vals);
3189 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3190 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3191}
3192
3193
3194void
3195TraCIAPI::VehicleScope::addSubscriptionFilterByteList(int filterType, const std::vector<int>& vals) const {
3196 tcpip::Storage content;
3197 content.writeUnsignedByte((int)vals.size());
3198 for (int i : vals) {
3199 content.writeByte(i);
3200 }
3201 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3202 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3203}
3204
3205
3206// ---------------------------------------------------------------------------
3207// TraCIAPI::PersonScope-methods
3208// ---------------------------------------------------------------------------
3209double
3210TraCIAPI::PersonScope::getSpeed(const std::string& personID) const {
3211 return getDouble(libsumo::VAR_SPEED, personID);
3212}
3213
3215TraCIAPI::PersonScope::getPosition(const std::string& personID) const {
3216 return getPos(libsumo::VAR_POSITION, personID);
3217}
3218
3220TraCIAPI::PersonScope::getPosition3D(const std::string& personID) const {
3221 return getPos3D(libsumo::VAR_POSITION3D, personID);
3222}
3223
3224double
3225TraCIAPI::PersonScope::getAngle(const std::string& personID) const {
3226 return getDouble(libsumo::VAR_ANGLE, personID);
3227}
3228
3229double
3230TraCIAPI::PersonScope::getSlope(const std::string& personID) const {
3231 return getDouble(libsumo::VAR_SLOPE, personID);
3232}
3233
3234double
3235TraCIAPI::PersonScope::getLanePosition(const std::string& personID) const {
3236 return getDouble(libsumo::VAR_LANEPOSITION, personID);
3237}
3238
3240TraCIAPI::PersonScope::getColor(const std::string& personID) const {
3241 return getCol(libsumo::VAR_COLOR, personID);
3242}
3243
3244double
3245TraCIAPI::PersonScope::getLength(const std::string& personID) const {
3246 return getDouble(libsumo::VAR_LENGTH, personID);
3247}
3248
3249std::string
3250TraCIAPI::PersonScope::getRoadID(const std::string& personID) const {
3251 return getString(libsumo::VAR_ROAD_ID, personID);
3252}
3253
3254std::string
3255TraCIAPI::PersonScope::getLaneID(const std::string& personID) const {
3256 return getString(libsumo::VAR_LANE_ID, personID);
3257}
3258
3259std::string
3260TraCIAPI::PersonScope::getTypeID(const std::string& personID) const {
3261 return getString(libsumo::VAR_TYPE, personID);
3262}
3263
3264double
3265TraCIAPI::PersonScope::getSpeedFactor(const std::string& personID) const {
3266 return getDouble(libsumo::VAR_SPEED_FACTOR, personID);
3267}
3268
3269double
3270TraCIAPI::PersonScope::getWaitingTime(const std::string& personID) const {
3271 return getDouble(libsumo::VAR_WAITING_TIME, personID);
3272}
3273
3274std::string
3275TraCIAPI::PersonScope::getNextEdge(const std::string& personID) const {
3276 return getString(libsumo::VAR_NEXT_EDGE, personID);
3277}
3278
3279
3280std::string
3281TraCIAPI::PersonScope::getVehicle(const std::string& personID) const {
3282 return getString(libsumo::VAR_VEHICLE, personID);
3283}
3284
3285int
3286TraCIAPI::PersonScope::getRemainingStages(const std::string& personID) const {
3287 return getInt(libsumo::VAR_STAGES_REMAINING, personID);
3288}
3289
3291TraCIAPI::PersonScope::getStage(const std::string& personID, int nextStageIndex) const {
3292 tcpip::Storage content;
3294 content.writeInt(nextStageIndex);
3295 return getTraCIStage(libsumo::VAR_STAGE, personID, &content);
3296}
3297
3298std::vector<std::string>
3299TraCIAPI::PersonScope::getEdges(const std::string& personID, int nextStageIndex) const {
3300 tcpip::Storage content;
3302 content.writeInt(nextStageIndex);
3303 return getStringVector(libsumo::VAR_EDGES, personID, &content);
3304}
3305
3306void
3307TraCIAPI::PersonScope::removeStages(const std::string& personID) const {
3308 // remove all stages after the current and then abort the current stage
3309 while (getRemainingStages(personID) > 1) {
3310 removeStage(personID, 1);
3311 }
3312 removeStage(personID, 0);
3313}
3314
3315
3316void
3317TraCIAPI::PersonScope::rerouteTraveltime(const std::string& personID) const {
3318 tcpip::Storage content;
3320 content.writeInt(0);
3321 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::CMD_REROUTE_TRAVELTIME, personID, &content);
3322 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3323}
3324
3325
3326void
3327TraCIAPI::PersonScope::add(const std::string& personID, const std::string& edgeID, double pos, double depart, const std::string typeID) {
3328 tcpip::Storage content;
3330 content.writeInt(4);
3332 content.writeString(typeID);
3334 content.writeString(edgeID);
3336 content.writeDouble(depart);
3338 content.writeDouble(pos);
3339 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::ADD, personID, &content);
3340 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3341}
3342
3343void
3344TraCIAPI::PersonScope::appendStage(const std::string& personID, const libsumo::TraCIStage& stage) {
3345 tcpip::Storage content;
3347 content.writeInt(13);
3349 content.writeInt(stage.type);
3351 content.writeString(stage.vType);
3353 content.writeString(stage.line);
3355 content.writeString(stage.destStop);
3357 content.writeStringList(stage.edges);
3359 content.writeDouble(stage.travelTime);
3361 content.writeDouble(stage.cost);
3363 content.writeDouble(stage.length);
3365 content.writeString(stage.intended);
3367 content.writeDouble(stage.depart);
3369 content.writeDouble(stage.departPos);
3371 content.writeDouble(stage.arrivalPos);
3373 content.writeString(stage.description);
3374 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3375 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3376}
3377
3378
3379void
3380TraCIAPI::PersonScope::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
3381 tcpip::Storage content;
3383 content.writeInt(4);
3387 content.writeDouble(duration);
3389 content.writeString(description);
3391 content.writeString(stopID);
3392 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3393 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3394}
3395
3396void
3397TraCIAPI::PersonScope::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
3398 tcpip::Storage content;
3400 content.writeInt(6);
3404 content.writeStringList(edges);
3406 content.writeDouble(arrivalPos);
3408 content.writeDouble(duration);
3410 content.writeDouble(speed);
3412 content.writeString(stopID);
3413 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3414 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3415}
3416
3417void
3418TraCIAPI::PersonScope::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
3419 tcpip::Storage content;
3421 content.writeInt(4);
3425 content.writeString(toEdge);
3427 content.writeString(lines);
3429 content.writeString(stopID);
3430 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3431 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3432}
3433
3434void
3435TraCIAPI::PersonScope::removeStage(const std::string& personID, int nextStageIndex) const {
3436 tcpip::Storage content;
3438 content.writeInt(nextStageIndex);
3439 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::REMOVE_STAGE, personID, &content);
3440 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3441}
3442
3443void
3444TraCIAPI::PersonScope::moveTo(const std::string& personID, const std::string& edgeID, double position) const {
3445 tcpip::Storage content;
3447 content.writeInt(2);
3449 content.writeString(edgeID);
3451 content.writeDouble(position);
3452 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_MOVE_TO, personID, &content);
3453 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3454}
3455
3456void
3457TraCIAPI::PersonScope::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute) const {
3458 tcpip::Storage content;
3460 content.writeInt(5);
3462 content.writeString(edgeID);
3464 content.writeDouble(x);
3466 content.writeDouble(y);
3468 content.writeDouble(angle);
3470 content.writeByte(keepRoute);
3471 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::MOVE_TO_XY, personID, &content);
3472 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3473}
3474
3475void
3476TraCIAPI::PersonScope::setSpeed(const std::string& personID, double speed) const {
3477 tcpip::Storage content;
3479 content.writeDouble(speed);
3480 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_SPEED, personID, &content);
3481 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3482}
3483
3484
3485void
3486TraCIAPI::PersonScope::setType(const std::string& personID, const std::string& typeID) const {
3487 tcpip::Storage content;
3489 content.writeString(typeID);
3490 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_TYPE, personID, &content);
3491 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3492}
3493
3494void
3495TraCIAPI::PersonScope::setSpeedFactor(const std::string& personID, double factor) const {
3496 tcpip::Storage content;
3498 content.writeDouble(factor);
3499 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_SPEED_FACTOR, personID, &content);
3500 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3501}
3502
3503void
3504TraCIAPI::PersonScope::setLength(const std::string& personID, double length) const {
3505 tcpip::Storage content;
3507 content.writeDouble(length);
3508 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_LENGTH, personID, &content);
3509 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3510}
3511
3512
3513void
3514TraCIAPI::PersonScope::setWidth(const std::string& personID, double width) const {
3515 tcpip::Storage content;
3517 content.writeDouble(width);
3518 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_WIDTH, personID, &content);
3519 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3520}
3521
3522void
3523TraCIAPI::PersonScope::setHeight(const std::string& personID, double height) const {
3524 tcpip::Storage content;
3526 content.writeDouble(height);
3527 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_HEIGHT, personID, &content);
3528 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3529}
3530
3531void
3532TraCIAPI::PersonScope::setMinGap(const std::string& personID, double minGap) const {
3533 tcpip::Storage content;
3535 content.writeDouble(minGap);
3536 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_MINGAP, personID, &content);
3537 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3538}
3539
3540
3541void
3542TraCIAPI::PersonScope::setColor(const std::string& personID, const libsumo::TraCIColor& c) const {
3543 tcpip::Storage content;
3545 content.writeUnsignedByte(c.r);
3546 content.writeUnsignedByte(c.g);
3547 content.writeUnsignedByte(c.b);
3548 content.writeUnsignedByte(c.a);
3549 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_COLOR, personID, &content);
3550 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3551}
3552
3553
3554// ---------------------------------------------------------------------------
3555// TraCIAPI::TraCIScopeWrapper-methods
3556// ---------------------------------------------------------------------------
3557
3558int
3559TraCIAPI::TraCIScopeWrapper::getUnsignedByte(int var, const std::string& id, tcpip::Storage* add) const {
3560 myParent.createCommand(myCmdGetID, var, id, add);
3561 if (myParent.processGet(myCmdGetID, libsumo::TYPE_UBYTE)) {
3562 return myParent.myInput.readUnsignedByte();
3563 }
3565}
3566
3567
3568int
3569TraCIAPI::TraCIScopeWrapper::getByte(int var, const std::string& id, tcpip::Storage* add) const {
3570 myParent.createCommand(myCmdGetID, var, id, add);
3571 if (myParent.processGet(myCmdGetID, libsumo::TYPE_BYTE)) {
3572 return myParent.myInput.readByte();
3573 }
3575}
3576
3577
3578
3579int
3580TraCIAPI::TraCIScopeWrapper::getInt(int var, const std::string& id, tcpip::Storage* add) const {
3581 myParent.createCommand(myCmdGetID, var, id, add);
3582 if (myParent.processGet(myCmdGetID, libsumo::TYPE_INTEGER)) {
3583 return myParent.myInput.readInt();
3584 }
3586}
3587
3588
3589double
3590TraCIAPI::TraCIScopeWrapper::getDouble(int var, const std::string& id, tcpip::Storage* add) const {
3591 myParent.createCommand(myCmdGetID, var, id, add);
3592 if (myParent.processGet(myCmdGetID, libsumo::TYPE_DOUBLE)) {
3593 return myParent.myInput.readDouble();
3594 }
3596}
3597
3598
3600TraCIAPI::TraCIScopeWrapper::getPolygon(int var, const std::string& id, tcpip::Storage* add) const {
3602 myParent.createCommand(myCmdGetID, var, id, add);
3603 if (myParent.processGet(myCmdGetID, libsumo::TYPE_POLYGON)) {
3604 int size = myParent.myInput.readUnsignedByte();
3605 if (size == 0) {
3606 size = myParent.myInput.readInt();
3607 }
3608 for (int i = 0; i < size; ++i) {
3610 p.x = myParent.myInput.readDouble();
3611 p.y = myParent.myInput.readDouble();
3612 p.z = 0.;
3613 ret.value.push_back(p);
3614 }
3615 }
3616 return ret;
3617}
3618
3619
3621TraCIAPI::TraCIScopeWrapper::getPos(int var, const std::string& id, tcpip::Storage* add) const {
3623 myParent.createCommand(myCmdGetID, var, id, add);
3624 if (myParent.processGet(myCmdGetID, libsumo::POSITION_2D)) {
3625 p.x = myParent.myInput.readDouble();
3626 p.y = myParent.myInput.readDouble();
3627 p.z = 0;
3628 }
3629 return p;
3630}
3631
3632
3634TraCIAPI::TraCIScopeWrapper::getPos3D(int var, const std::string& id, tcpip::Storage* add) const {
3636 myParent.createCommand(myCmdGetID, var, id, add);
3637 if (myParent.processGet(myCmdGetID, libsumo::POSITION_3D)) {
3638 p.x = myParent.myInput.readDouble();
3639 p.y = myParent.myInput.readDouble();
3640 p.z = myParent.myInput.readDouble();
3641 }
3642 return p;
3643}
3644
3645
3646std::string
3647TraCIAPI::TraCIScopeWrapper::getString(int var, const std::string& id, tcpip::Storage* add) const {
3648 myParent.createCommand(myCmdGetID, var, id, add);
3649 if (myParent.processGet(myCmdGetID, libsumo::TYPE_STRING)) {
3650 return myParent.myInput.readString();
3651 }
3652 return "";
3653}
3654
3655
3656std::vector<std::string>
3657TraCIAPI::TraCIScopeWrapper::getStringVector(int var, const std::string& id, tcpip::Storage* add) const {
3658 std::vector<std::string> r;
3659 myParent.createCommand(myCmdGetID, var, id, add);
3660 if (myParent.processGet(myCmdGetID, libsumo::TYPE_STRINGLIST)) {
3661 const int size = myParent.myInput.readInt();
3662 for (int i = 0; i < size; ++i) {
3663 r.push_back(myParent.myInput.readString());
3664 }
3665 }
3666 return r;
3667}
3668
3669
3670std::vector<double>
3671TraCIAPI::TraCIScopeWrapper::getDoubleVector(int var, const std::string& id, tcpip::Storage* add) const {
3672 std::vector<double> r;
3673 myParent.createCommand(myCmdGetID, var, id, add);
3674 if (myParent.processGet(myCmdGetID, libsumo::TYPE_DOUBLELIST)) {
3675 const int size = myParent.myInput.readInt();
3676 for (int i = 0; i < size; ++i) {
3677 r.push_back(myParent.myInput.readDouble());
3678 }
3679 }
3680 return r;
3681}
3682
3683
3685TraCIAPI::TraCIScopeWrapper::getCol(int var, const std::string& id, tcpip::Storage* add) const {
3687 myParent.createCommand(myCmdGetID, var, id, add);
3688 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COLOR)) {
3689 c.r = (unsigned char)myParent.myInput.readUnsignedByte();
3690 c.g = (unsigned char)myParent.myInput.readUnsignedByte();
3691 c.b = (unsigned char)myParent.myInput.readUnsignedByte();
3692 c.a = (unsigned char)myParent.myInput.readUnsignedByte();
3693 }
3694 return c;
3695}
3696
3697
3699TraCIAPI::TraCIScopeWrapper::getTraCIStage(int var, const std::string& id, tcpip::Storage* add) const {
3701 myParent.createCommand(myCmdGetID, var, id, add);
3702 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COMPOUND)) {
3703 myParent.myInput.readInt(); // components
3704 myParent.myInput.readUnsignedByte();
3705 s.type = myParent.myInput.readInt();
3706
3707 myParent.myInput.readUnsignedByte();
3708 s.vType = myParent.myInput.readString();
3709
3710 myParent.myInput.readUnsignedByte();
3711 s.line = myParent.myInput.readString();
3712
3713 myParent.myInput.readUnsignedByte();
3714 s.destStop = myParent.myInput.readString();
3715
3716 myParent.myInput.readUnsignedByte();
3717 s.edges = myParent.myInput.readStringList();
3718
3719 myParent.myInput.readUnsignedByte();
3720 s.travelTime = myParent.myInput.readDouble();
3721
3722 myParent.myInput.readUnsignedByte();
3723 s.cost = myParent.myInput.readDouble();
3724
3725 myParent.myInput.readUnsignedByte();
3726 s.length = myParent.myInput.readDouble();
3727
3728 myParent.myInput.readUnsignedByte();
3729 s.intended = myParent.myInput.readString();
3730
3731 myParent.myInput.readUnsignedByte();
3732 s.depart = myParent.myInput.readDouble();
3733
3734 myParent.myInput.readUnsignedByte();
3735 s.departPos = myParent.myInput.readDouble();
3736
3737 myParent.myInput.readUnsignedByte();
3738 s.arrivalPos = myParent.myInput.readDouble();
3739
3740 myParent.myInput.readUnsignedByte();
3741 s.description = myParent.myInput.readString();
3742 }
3743 return s;
3744}
3745
3746
3747std::vector<std::string>
3749 return getStringVector(libsumo::TRACI_ID_LIST, "");
3750}
3751
3752
3753int
3755 return getInt(libsumo::ID_COUNT, "");
3756}
3757
3758
3759std::string
3760TraCIAPI::TraCIScopeWrapper::getParameter(const std::string& objectID, const std::string& key) const {
3761 tcpip::Storage content;
3763 content.writeString(key);
3764 return getString(libsumo::VAR_PARAMETER, objectID, &content);
3765}
3766
3767
3768std::pair<std::string, std::string>
3769TraCIAPI::TraCIScopeWrapper::getParameterWithKey(const std::string& objectID, const std::string& key) const {
3770 tcpip::Storage content;
3772 content.writeString(key);
3773
3774 myParent.createCommand(myCmdGetID, libsumo::VAR_PARAMETER_WITH_KEY, objectID, &content);
3775 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COMPOUND)) {
3776 myParent.myInput.readInt(); // number of components
3777 myParent.myInput.readUnsignedByte();
3778 const std::string returnedKey = myParent.myInput.readString();
3779 myParent.myInput.readUnsignedByte();
3780 const std::string value = myParent.myInput.readString();
3781 return std::make_pair(returnedKey, value);
3782 }
3783 return std::make_pair(key, "");
3784}
3785
3786
3787void
3788TraCIAPI::TraCIScopeWrapper::setParameter(const std::string& objectID, const std::string& key, const std::string& value) const {
3789 tcpip::Storage content;
3791 content.writeInt(2);
3793 content.writeString(key);
3795 content.writeString(value);
3796 myParent.createCommand(myCmdSetID, libsumo::VAR_PARAMETER, objectID, &content);
3797 myParent.processSet(myCmdSetID);
3798}
3799
3800
3801void
3802TraCIAPI::TraCIScopeWrapper::setInt(int var, const std::string& id, int value) const {
3803 tcpip::Storage content;
3805 content.writeInt(value);
3806 myParent.createCommand(myCmdSetID, var, id, &content);
3807 myParent.processSet(myCmdSetID);
3808}
3809
3810
3811void
3812TraCIAPI::TraCIScopeWrapper::setDouble(int var, const std::string& id, double value) const {
3813 tcpip::Storage content;
3815 content.writeDouble(value);
3816 myParent.createCommand(myCmdSetID, var, id, &content);
3817 myParent.processSet(myCmdSetID);
3818}
3819
3820
3821void
3822TraCIAPI::TraCIScopeWrapper::setString(int var, const std::string& id, const std::string& value) const {
3823 tcpip::Storage content;
3825 content.writeString(value);
3826 myParent.createCommand(myCmdSetID, var, id, &content);
3827 myParent.processSet(myCmdSetID);
3828}
3829
3830
3831void
3832TraCIAPI::TraCIScopeWrapper::setStringVector(int var, const std::string& id, const std::vector<std::string>& value) const {
3833 tcpip::Storage content;
3835 content.writeInt((int)value.size());
3836 for (const std::string& s : value) {
3837 content.writeString(s);
3838 }
3839 myParent.createCommand(myCmdSetID, var, id, &content);
3840 myParent.processSet(myCmdSetID);
3841}
3842
3843
3844void
3845TraCIAPI::TraCIScopeWrapper::subscribe(const std::string& objID, const std::vector<int>& vars, double beginTime, double endTime) const {
3846 myParent.send_commandSubscribeObjectVariable(mySubscribeID, objID, beginTime, endTime, vars);
3847 tcpip::Storage inMsg;
3848 myParent.check_resultState(inMsg, mySubscribeID);
3849 if (vars.size() > 0) {
3850 myParent.check_commandGetResult(inMsg, mySubscribeID);
3851 myParent.readVariableSubscription(mySubscribeID + 0x10, inMsg);
3852 }
3853}
3854
3855
3856void
3857TraCIAPI::TraCIScopeWrapper::subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars, double beginTime, double endTime) const {
3858 myParent.send_commandSubscribeObjectContext(myContextSubscribeID, objID, beginTime, endTime, domain, range, vars);
3859 tcpip::Storage inMsg;
3860 myParent.check_resultState(inMsg, myContextSubscribeID);
3861 myParent.check_commandGetResult(inMsg, myContextSubscribeID);
3862 myParent.readContextSubscription(myContextSubscribeID + 0x60, inMsg);
3863}
3864
3865
3868 return mySubscriptionResults;
3869}
3870
3871
3874 if (mySubscriptionResults.find(objID) != mySubscriptionResults.end()) {
3875 return mySubscriptionResults.find(objID)->second;
3876 } else {
3877 return libsumo::TraCIResults();
3878 }
3879}
3880
3881
3884 return myContextSubscriptionResults;
3885}
3886
3887
3890 if (myContextSubscriptionResults.find(objID) != myContextSubscriptionResults.end()) {
3891 return myContextSubscriptionResults.find(objID)->second;
3892 } else {
3894 }
3895}
3896
3897
3898void
3900 mySubscriptionResults.clear();
3901 myContextSubscriptionResults.clear();
3902}
3903
3904
3907 return mySubscriptionResults;
3908}
3909
3910
3913 return myContextSubscriptionResults[objID];
3914}
3915
3916
3917/****************************************************************************/
double getElectricityConsumption(const std::string &edgeID) const
Definition TraCIAPI.cpp:554
double getLastStepHaltingNumber(const std::string &edgeID) const
Definition TraCIAPI.cpp:584
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:607
double getLastStepOccupancy(const std::string &edgeID) const
Definition TraCIAPI.cpp:564
double getLastStepLength(const std::string &edgeID) const
Definition TraCIAPI.cpp:569
std::vector< std::string > getLastStepVehicleIDs(const std::string &edgeID) const
Definition TraCIAPI.cpp:589
double getNOxEmission(const std::string &edgeID) const
Definition TraCIAPI.cpp:539
void setMaxSpeed(const std::string &edgeID, double speed) const
Definition TraCIAPI.cpp:646
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:595
void setEffort(const std::string &edgeID, double effort, double beginSeconds=0., double endSeconds=std::numeric_limits< double >::max()) const
Definition TraCIAPI.cpp:627
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:574
int getLastStepVehicleNumber(const std::string &edgeID) const
Definition TraCIAPI.cpp:579
std::string getStreetName(const std::string &id) const
Definition TraCIAPI.cpp:601
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:681
libsumo::TraCIPositionVector getBoundary(const std::string &viewID=DEFAULT_VIEW) const
Definition TraCIAPI.cpp:670
std::string getSchema(const std::string &viewID=DEFAULT_VIEW) const
Definition TraCIAPI.cpp:665
void setBoundary(const std::string &viewID, double xmin, double ymin, double xmax, double ymax) const
Definition TraCIAPI.cpp:696
void setZoom(const std::string &viewID, double zoom) const
Definition TraCIAPI.cpp:676
void trackVehicle(const std::string &viewID, const std::string &vehID) const
Definition TraCIAPI.cpp:724
void setSchema(const std::string &viewID, const std::string &schemeName) const
Definition TraCIAPI.cpp:691
libsumo::TraCIPosition getOffset(const std::string &viewID=DEFAULT_VIEW) const
Definition TraCIAPI.cpp:660
double getZoom(const std::string &viewID=DEFAULT_VIEW) const
Definition TraCIAPI.cpp:655
void screenshot(const std::string &viewID, const std::string &filename, const int width=-1, const int height=-1) const
Definition TraCIAPI.cpp:709
std::vector< libsumo::TraCIVehicleData > getVehicleData(const std::string &loopID) const
Definition TraCIAPI.cpp:779
int getIntervalVehicleNumber(const std::string &loopID) const
Definition TraCIAPI.cpp:733
double getPosition(const std::string &loopID) const
Definition TraCIAPI.cpp:738
double getLastStepMeanSpeed(const std::string &loopID) const
Definition TraCIAPI.cpp:753
double getTimeSinceDetection(const std::string &loopID) const
Definition TraCIAPI.cpp:773
double getLastStepMeanLength(const std::string &loopID) const
Definition TraCIAPI.cpp:768
std::vector< std::string > getLastStepVehicleIDs(const std::string &loopID) const
Definition TraCIAPI.cpp:758
double getLastStepOccupancy(const std::string &loopID) const
Definition TraCIAPI.cpp:763
int getLastStepVehicleNumber(const std::string &loopID) const
Definition TraCIAPI.cpp:748
std::string getLaneID(const std::string &loopID) const
Definition TraCIAPI.cpp:743
libsumo::TraCIPosition getPosition(const std::string &junctionID) const
Definition TraCIAPI.cpp:816
libsumo::TraCIPositionVector getShape(const std::string &junctionID) const
Definition TraCIAPI.cpp:821
int getLastStepVehicleNumber(const std::string &laneID) const
Definition TraCIAPI.cpp:980
double getPMxEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:935
int getLastStepHaltingNumber(const std::string &laneID) const
Definition TraCIAPI.cpp:985
std::string getEdgeID(const std::string &laneID) const
Definition TraCIAPI.cpp:915
void setDisallowed(const std::string &laneID, const std::vector< std::string > &disallowedClasses) const
libsumo::TraCIPositionVector getShape(const std::string &laneID) const
Definition TraCIAPI.cpp:910
double getLastStepLength(const std::string &laneID) const
Definition TraCIAPI.cpp:970
void setLength(const std::string &laneID, double length) const
double getLength(const std::string &laneID) const
Definition TraCIAPI.cpp:830
int getLinkNumber(const std::string &laneID) const
Definition TraCIAPI.cpp:855
double getTraveltime(const std::string &laneID) const
Definition TraCIAPI.cpp:975
double getCOEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:925
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:850
double getNoiseEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:950
std::vector< std::string > getAllowed(const std::string &laneID) const
Definition TraCIAPI.cpp:845
double getFuelConsumption(const std::string &laneID) const
Definition TraCIAPI.cpp:945
double getWidth(const std::string &laneID) const
Definition TraCIAPI.cpp:840
double getCO2Emission(const std::string &laneID) const
Definition TraCIAPI.cpp:920
double getHCEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:930
std::vector< libsumo::TraCIConnection > getLinks(const std::string &laneID) const
Definition TraCIAPI.cpp:860
double getMaxSpeed(const std::string &laneID) const
Definition TraCIAPI.cpp:835
std::vector< std::string > getLastStepVehicleIDs(const std::string &laneID) const
Definition TraCIAPI.cpp:990
double getElectricityConsumption(const std::string &laneID) const
Definition TraCIAPI.cpp:955
std::vector< std::string > getFoes(const std::string &laneID, const std::string &toLaneID) const
Definition TraCIAPI.cpp:996
double getLastStepMeanSpeed(const std::string &laneID) const
Definition TraCIAPI.cpp:960
double getNOxEmission(const std::string &laneID) const
Definition TraCIAPI.cpp:940
double getLastStepOccupancy(const std::string &laneID) const
Definition TraCIAPI.cpp:965
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
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
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
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:851
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:960
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition TraCIAPI.h:841
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition TraCIAPI.h:861
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:831
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:847
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition TraCIAPI.h:942
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:956
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:839
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:837
std::map< int, TraCIScopeWrapper * > myDomains
Definition TraCIAPI.h:954
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:857
tcpip::Storage myOutput
The reusable output storage.
Definition TraCIAPI.h:958
POIScope poi
Scope for interaction with POIs.
Definition TraCIAPI.h:845
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:859
JunctionScope junction
Scope for interaction with junctions.
Definition TraCIAPI.h:835
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:853
EdgeScope edge
Scope for interaction with edges.
Definition TraCIAPI.h:829
bool processGet(int command, int expectedType, bool ignoreCommandId=false)
Definition TraCIAPI.cpp:328
SimulationScope simulation
Scope for interaction with the simulation.
Definition TraCIAPI.h:855
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:843
RerouterScope rerouter
Scope for interaction with rerouters.
Definition TraCIAPI.h:849
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:379
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:378
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 RESPONSE_SUBSCRIBE_POLYGON_VARIABLE
TRACI_CONST int ADD
std::map< int, std::shared_ptr< libsumo::TraCIResult > > TraCIResults
{variable->value}
Definition TraCIDefs.h:376
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:705
double occupation
The traffic density along length.
Definition TraCIDefs.h:707
bool allowsContinuation
Whether this lane allows continuing the route.
Definition TraCIDefs.h:711
int bestLaneOffset
The offset of this lane from the best lane.
Definition TraCIDefs.h:709
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition TraCIDefs.h:713
std::string laneID
The id of the lane.
Definition TraCIDefs.h:703
std::map< std::string, std::string > subParameter
Definition TraCIDefs.h:425
std::string programID
Definition TraCIDefs.h:421
std::vector< std::shared_ptr< libsumo::TraCIPhase > > phases
Definition TraCIDefs.h:424
double dist
The distance to the tls.
Definition TraCIDefs.h:571
int tlIndex
The tls index of the controlled link.
Definition TraCIDefs.h:569
std::string id
The id of the next tls.
Definition TraCIDefs.h:567
char state
The current state of the tls.
Definition TraCIDefs.h:573
A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
Definition TraCIDefs.h:179
A list of positions.
Definition TraCIDefs.h:240
std::vector< TraCIPosition > value
Definition TraCIDefs.h:250
An edgeId, position and laneIndex.
Definition TraCIDefs.h:201
std::string intended
id of the intended vehicle for public transport ride
Definition TraCIDefs.h:758
int type
The type of stage (walking, driving, ...)
Definition TraCIDefs.h:742
std::string destStop
The id of the destination stop.
Definition TraCIDefs.h:748
double length
length in m
Definition TraCIDefs.h:756
double travelTime
duration of the stage in seconds
Definition TraCIDefs.h:752
double departPos
position on the lane when starting the stage
Definition TraCIDefs.h:762
std::string description
arbitrary description string
Definition TraCIDefs.h:766
std::string line
The line or the id of the vehicle type.
Definition TraCIDefs.h:746
double cost
effort needed
Definition TraCIDefs.h:754
double depart
intended depart time for public transport ride or INVALID_DOUBLE_VALUE
Definition TraCIDefs.h:760
std::vector< std::string > edges
The sequence of edges to travel.
Definition TraCIDefs.h:750
double arrivalPos
position on the lane when ending the stage
Definition TraCIDefs.h:764
std::string vType
The vehicle type when using a private car or bike.
Definition TraCIDefs.h:744
mirrors MSInductLoop::VehicleData
Definition TraCIDefs.h:522
std::string id
The id of the vehicle.
Definition TraCIDefs.h:531
double entryTime
Entry-time of the vehicle in [s].
Definition TraCIDefs.h:535
std::string typeID
Type of the vehicle in.
Definition TraCIDefs.h:539
double length
Length of the vehicle.
Definition TraCIDefs.h:533
double leaveTime
Leave-time of the vehicle in [s].
Definition TraCIDefs.h:537