Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
TraCIAPI.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// C++ TraCI client API implementation
22/****************************************************************************/
23#include "TraCIAPI.h"
24
25
26// ===========================================================================
27// member definitions
28// ===========================================================================
29
30// ---------------------------------------------------------------------------
31// TraCIAPI-methods
32// ---------------------------------------------------------------------------
33#ifdef _MSC_VER
34#pragma warning(push)
35#pragma warning(disable: 4355) // mask warning about "this" in initializers
36#endif
38 edge(*this), gui(*this), inductionloop(*this),
39 junction(*this), lane(*this), lanearea(*this), multientryexit(*this),
40 person(*this), poi(*this), polygon(*this),
41 rerouter(*this), route(*this), routeprobe(*this),
42 simulation(*this), trafficlights(*this),
43 vehicle(*this), vehicletype(*this),
44 mySocket(nullptr) {
45 std::cerr << "TraCIAPI is deprecated. Please use libtraci instead, see https://sumo.dlr.de/docs/Libtraci.html.\n";
62}
63#ifdef _MSC_VER
64#pragma warning(pop)
65#endif
66
68 delete mySocket;
69}
70
71
72void
73TraCIAPI::connect(const std::string& host, int port) {
74 mySocket = new tcpip::Socket(host, port);
75 try {
77 } catch (tcpip::SocketException&) {
78 delete mySocket;
79 mySocket = nullptr;
80 throw;
81 }
82}
83
84
85void
87 tcpip::Storage outMsg;
88 // command length
89 outMsg.writeUnsignedByte(1 + 1 + 4);
90 // command id
92 outMsg.writeInt(order);
93 // send request message
94 mySocket->sendExact(outMsg);
95 tcpip::Storage inMsg;
97}
98
99
100void
103 tcpip::Storage inMsg;
104 std::string acknowledgement;
105 check_resultState(inMsg, libsumo::CMD_CLOSE, false, &acknowledgement);
106 closeSocket();
107}
108
109
110void
112 if (mySocket == nullptr) {
113 return;
114 }
115 mySocket->close();
116 delete mySocket;
117 mySocket = nullptr;
118}
119
120
121void
123 tcpip::Storage outMsg;
124 // command length
125 outMsg.writeUnsignedByte(1 + 1 + 8);
126 // command id
128 outMsg.writeDouble(time);
129 // send request message
130 mySocket->sendExact(outMsg);
131}
132
133
134void
136 tcpip::Storage outMsg;
137 // command length
138 outMsg.writeUnsignedByte(1 + 1);
139 // command id
141 mySocket->sendExact(outMsg);
142}
143
144
145void
147 tcpip::Storage outMsg;
148 // command length
149 outMsg.writeUnsignedByte(1 + 1 + 4);
150 // command id
152 // client index
153 outMsg.writeInt(order);
154 mySocket->sendExact(outMsg);
155}
156
157
158void
159TraCIAPI::createCommand(int cmdID, int varID, const std::string& objID, tcpip::Storage* add) const {
160 myOutput.reset();
161 // command length
162 int length = 1 + 1 + 1 + 4 + (int) objID.length();
163 if (add != nullptr) {
164 length += (int)add->size();
165 }
166 if (length <= 255) {
168 } else {
170 myOutput.writeInt(length + 4);
171 }
174 myOutput.writeString(objID);
175 // additional values
176 if (add != nullptr) {
178 }
179}
180
181
182void
183TraCIAPI::createFilterCommand(int cmdID, int varID, tcpip::Storage* add) const {
184 myOutput.reset();
185 // command length
186 int length = 1 + 1 + 1;
187 if (add != nullptr) {
188 length += (int)add->size();
189 }
190 if (length <= 255) {
192 } else {
194 myOutput.writeInt(length + 4);
195 }
198 // additional values
199 if (add != nullptr) {
201 }
202}
203
204
205void
206TraCIAPI::send_commandSubscribeObjectVariable(int domID, const std::string& objID, double beginTime, double endTime,
207 const std::vector<int>& vars) const {
208 if (mySocket == nullptr) {
209 throw tcpip::SocketException("Socket is not initialised");
210 }
211 tcpip::Storage outMsg;
212 // command length (domID, objID, beginTime, endTime, length, vars)
213 int varNo = (int) vars.size();
214 outMsg.writeUnsignedByte(0);
215 outMsg.writeInt(5 + 1 + 8 + 8 + 4 + (int) objID.length() + 1 + varNo);
216 // command id
217 outMsg.writeUnsignedByte(domID);
218 // time
219 outMsg.writeDouble(beginTime);
220 outMsg.writeDouble(endTime);
221 // object id
222 outMsg.writeString(objID);
223 // command id
224 outMsg.writeUnsignedByte((int)vars.size());
225 for (int i = 0; i < varNo; ++i) {
226 outMsg.writeUnsignedByte(vars[i]);
227 }
228 // send message
229 mySocket->sendExact(outMsg);
230}
231
232
233void
234TraCIAPI::send_commandSubscribeObjectContext(int domID, const std::string& objID, double beginTime, double endTime,
235 int domain, double range, const std::vector<int>& vars) const {
236 if (mySocket == nullptr) {
237 throw tcpip::SocketException("Socket is not initialised");
238 }
239 tcpip::Storage outMsg;
240 // command length (domID, objID, beginTime, endTime, length, vars)
241 int varNo = (int) vars.size();
242 outMsg.writeUnsignedByte(0);
243 outMsg.writeInt(5 + 1 + 8 + 8 + 4 + (int) objID.length() + 1 + 8 + 1 + varNo);
244 // command id
245 outMsg.writeUnsignedByte(domID);
246 // time
247 outMsg.writeDouble(beginTime);
248 outMsg.writeDouble(endTime);
249 // object id
250 outMsg.writeString(objID);
251 // domain and range
252 outMsg.writeUnsignedByte(domain);
253 outMsg.writeDouble(range);
254 // command id
255 outMsg.writeUnsignedByte((int)vars.size());
256 for (int i = 0; i < varNo; ++i) {
257 outMsg.writeUnsignedByte(vars[i]);
258 }
259 // send message
260 mySocket->sendExact(outMsg);
261}
262
263
264void
265TraCIAPI::check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId, std::string* acknowledgement) const {
266 mySocket->receiveExact(inMsg);
267 int cmdLength;
268 int cmdId;
269 int resultType;
270 int cmdStart;
271 std::string msg;
272 try {
273 cmdStart = inMsg.position();
274 cmdLength = inMsg.readUnsignedByte();
275 cmdId = inMsg.readUnsignedByte();
276 if (command != cmdId && !ignoreCommandId) {
277 throw libsumo::TraCIException("#Error: received status response to command: " + toString(cmdId) + " but expected: " + toString(command));
278 }
279 resultType = inMsg.readUnsignedByte();
280 msg = inMsg.readString();
281 } catch (std::invalid_argument&) {
282 throw libsumo::TraCIException("#Error: an exception was thrown while reading result state message");
283 }
284 switch (resultType) {
286 throw libsumo::TraCIException(".. Answered with error to command (" + toString(command) + "), [description: " + msg + "]");
288 throw libsumo::TraCIException(".. Sent command is not implemented (" + toString(command) + "), [description: " + msg + "]");
290 if (acknowledgement != nullptr) {
291 (*acknowledgement) = ".. Command acknowledged (" + toString(command) + "), [description: " + msg + "]";
292 }
293 break;
294 default:
295 throw libsumo::TraCIException(".. Answered with unknown result code(" + toString(resultType) + ") to command(" + toString(command) + "), [description: " + msg + "]");
296 }
297 if ((cmdStart + cmdLength) != (int) inMsg.position()) {
298 throw libsumo::TraCIException("#Error: command at position " + toString(cmdStart) + " has wrong length");
299 }
300}
301
302
303int
304TraCIAPI::check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId) const {
305 inMsg.position(); // respStart
306 int length = inMsg.readUnsignedByte();
307 if (length == 0) {
308 length = inMsg.readInt();
309 }
310 int cmdId = inMsg.readUnsignedByte();
311 if (!ignoreCommandId && cmdId != (command + 0x10)) {
312 throw libsumo::TraCIException("#Error: received response with command id: " + toString(cmdId) + "but expected: " + toString(command + 0x10));
313 }
314 if (expectedType >= 0) {
315 // not called from the TraCITestClient but from within the TraCIAPI
316 inMsg.readUnsignedByte(); // variableID
317 inMsg.readString(); // objectID
318 int valueDataType = inMsg.readUnsignedByte();
319 if (valueDataType != expectedType) {
320 throw libsumo::TraCIException("Expected " + toString(expectedType) + " but got " + toString(valueDataType));
321 }
322 }
323 return cmdId;
324}
325
326
327bool
328TraCIAPI::processGet(int command, int expectedType, bool ignoreCommandId) {
329 if (mySocket != nullptr) {
331 myInput.reset();
332 check_resultState(myInput, command, ignoreCommandId);
333 check_commandGetResult(myInput, command, expectedType, ignoreCommandId);
334 return true;
335 }
336 return false;
337}
338
339
340bool
342 if (mySocket != nullptr) {
344 myInput.reset();
345 check_resultState(myInput, command);
346 return true;
347 }
348 return false;
349}
350
351
352void
353TraCIAPI::readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, libsumo::SubscriptionResults& into) {
354 while (variableCount > 0) {
355
356 const int variableID = inMsg.readUnsignedByte();
357 const int status = inMsg.readUnsignedByte();
358 const int type = inMsg.readUnsignedByte();
359
360 if (status == libsumo::RTYPE_OK) {
361 switch (type) {
363 into[objectID][variableID] = std::make_shared<libsumo::TraCIDouble>(inMsg.readDouble());
364 break;
366 into[objectID][variableID] = std::make_shared<libsumo::TraCIString>(inMsg.readString());
367 break;
369 auto p = std::make_shared<libsumo::TraCIPosition>();
370 p->x = inMsg.readDouble();
371 p->y = inMsg.readDouble();
372 p->z = 0.;
373 into[objectID][variableID] = p;
374 break;
375 }
377 auto p = std::make_shared<libsumo::TraCIPosition>();
378 p->x = inMsg.readDouble();
379 p->y = inMsg.readDouble();
380 p->z = inMsg.readDouble();
381 into[objectID][variableID] = p;
382 break;
383 }
384 case libsumo::TYPE_COLOR: {
385 auto c = std::make_shared<libsumo::TraCIColor>();
386 c->r = (unsigned char)inMsg.readUnsignedByte();
387 c->g = (unsigned char)inMsg.readUnsignedByte();
388 c->b = (unsigned char)inMsg.readUnsignedByte();
389 c->a = (unsigned char)inMsg.readUnsignedByte();
390 into[objectID][variableID] = c;
391 break;
392 }
394 into[objectID][variableID] = std::make_shared<libsumo::TraCIInt>(inMsg.readInt());
395 break;
397 auto sl = std::make_shared<libsumo::TraCIStringList>();
398 int n = inMsg.readInt();
399 for (int i = 0; i < n; ++i) {
400 sl->value.push_back(inMsg.readString());
401 }
402 into[objectID][variableID] = sl;
403 }
404 break;
405
406 // TODO Other data types
407
408 default:
409 throw libsumo::TraCIException("Unimplemented subscription type: " + toString(type));
410 }
411 } else {
412 throw libsumo::TraCIException("Subscription response error: variableID=" + toString(variableID) + " status=" + toString(status));
413 }
414
415 variableCount--;
416 }
417}
418
419
420void
422 const std::string objectID = inMsg.readString();
423 const int variableCount = inMsg.readUnsignedByte();
424 readVariables(inMsg, objectID, variableCount, myDomains[cmdId]->getModifiableSubscriptionResults());
425}
426
427
428void
430 const std::string contextID = inMsg.readString();
431 inMsg.readUnsignedByte(); // context domain
432 const int variableCount = inMsg.readUnsignedByte();
433 int numObjects = inMsg.readInt();
434
435 while (numObjects > 0) {
436 std::string objectID = inMsg.readString();
437 readVariables(inMsg, objectID, variableCount, myDomains[cmdId]->getModifiableContextSubscriptionResults(contextID));
438 numObjects--;
439 }
440}
441
442
443void
446 tcpip::Storage inMsg;
448
449 for (auto it : myDomains) {
450 it.second->clearSubscriptionResults();
451 }
452 int numSubs = inMsg.readInt();
453 while (numSubs > 0) {
454 int cmdId = check_commandGetResult(inMsg, 0, -1, true);
456 readVariableSubscription(cmdId, inMsg);
457 } else {
458 readContextSubscription(cmdId + 0x50, inMsg);
459 }
460 numSubs--;
461 }
462}
463
464
465void
466TraCIAPI::load(const std::vector<std::string>& args) {
467 int numChars = 0;
468 for (int i = 0; i < (int)args.size(); ++i) {
469 numChars += (int)args[i].size();
470 }
471 tcpip::Storage content;
472 content.writeUnsignedByte(0);
473 content.writeInt(1 + 4 + 1 + 1 + 4 + numChars + 4 * (int)args.size());
476 content.writeStringList(args);
477 mySocket->sendExact(content);
478 tcpip::Storage inMsg;
480}
481
482
483std::pair<int, std::string>
485 tcpip::Storage content;
486 content.writeUnsignedByte(2);
488 mySocket->sendExact(content);
489 tcpip::Storage inMsg;
491 inMsg.readUnsignedByte(); // msg length
492 inMsg.readUnsignedByte(); // libsumo::CMD_GETVERSION again, see #7284
493 const int traciVersion = inMsg.readInt(); // to fix evaluation order
494 return std::make_pair(traciVersion, inMsg.readString());
495}
496
497
498// ---------------------------------------------------------------------------
499// TraCIAPI::EdgeScope-methods
500// ---------------------------------------------------------------------------
501double
502TraCIAPI::EdgeScope::getAdaptedTraveltime(const std::string& edgeID, double time) const {
503 tcpip::Storage content;
505 content.writeDouble(time);
506 return getDouble(libsumo::VAR_EDGE_TRAVELTIME, edgeID, &content);
507}
508
509double
510TraCIAPI::EdgeScope::getEffort(const std::string& edgeID, double time) const {
511 tcpip::Storage content;
513 content.writeDouble(time);
514 return getDouble(libsumo::VAR_EDGE_EFFORT, edgeID, &content);
515}
516
517double
518TraCIAPI::EdgeScope::getCO2Emission(const std::string& edgeID) const {
519 return getDouble(libsumo::VAR_CO2EMISSION, edgeID);
520}
521
522
523double
524TraCIAPI::EdgeScope::getCOEmission(const std::string& edgeID) const {
525 return getDouble(libsumo::VAR_COEMISSION, edgeID);
526}
527
528double
529TraCIAPI::EdgeScope::getHCEmission(const std::string& edgeID) const {
530 return getDouble(libsumo::VAR_HCEMISSION, edgeID);
531}
532
533double
534TraCIAPI::EdgeScope::getPMxEmission(const std::string& edgeID) const {
535 return getDouble(libsumo::VAR_PMXEMISSION, edgeID);
536}
537
538double
539TraCIAPI::EdgeScope::getNOxEmission(const std::string& edgeID) const {
540 return getDouble(libsumo::VAR_NOXEMISSION, edgeID);
541}
542
543double
544TraCIAPI::EdgeScope::getFuelConsumption(const std::string& edgeID) const {
545 return getDouble(libsumo::VAR_FUELCONSUMPTION, edgeID);
546}
547
548double
549TraCIAPI::EdgeScope::getNoiseEmission(const std::string& edgeID) const {
550 return getDouble(libsumo::VAR_NOISEEMISSION, edgeID);
551}
552
553double
554TraCIAPI::EdgeScope::getElectricityConsumption(const std::string& edgeID) const {
555 return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, edgeID);
556}
557
558double
559TraCIAPI::EdgeScope::getLastStepMeanSpeed(const std::string& edgeID) const {
560 return getDouble(libsumo::LAST_STEP_MEAN_SPEED, edgeID);
561}
562
563double
564TraCIAPI::EdgeScope::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
1226double
1227TraCIAPI::PolygonScope::getHeight(const std::string& polygonID) const {
1228 return getDouble(libsumo::VAR_HEIGHT, polygonID);
1229}
1230
1231bool
1232TraCIAPI::PolygonScope::getFilled(const std::string& polygonID) const {
1233 return getInt(libsumo::VAR_FILL, polygonID) != 0;
1234}
1235
1236std::string
1237TraCIAPI::PolygonScope::getType(const std::string& polygonID) const {
1238 return getString(libsumo::VAR_TYPE, polygonID);
1239}
1240
1242TraCIAPI::PolygonScope::getShape(const std::string& polygonID) const {
1243 return getPolygon(libsumo::VAR_SHAPE, polygonID);
1244}
1245
1247TraCIAPI::PolygonScope::getColor(const std::string& polygonID) const {
1248 return getCol(libsumo::VAR_COLOR, polygonID);
1249}
1250
1251void
1252TraCIAPI::PolygonScope::setLineWidth(const std::string& polygonID, const double lineWidth) const {
1253 tcpip::Storage content;
1255 content.writeDouble(lineWidth);
1256 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_WIDTH, polygonID, &content);
1257 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1258}
1259
1260void
1261TraCIAPI::PolygonScope::setHeight(const std::string& polygonID, const double height) const {
1262 tcpip::Storage content;
1264 content.writeDouble(height);
1265 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_HEIGHT, polygonID, &content);
1266 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1267}
1268
1269void
1270TraCIAPI::PolygonScope::setType(const std::string& polygonID, const std::string& setType) const {
1271 tcpip::Storage content;
1273 content.writeString(setType);
1274 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_TYPE, polygonID, &content);
1275 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1276}
1277
1278
1279void
1280TraCIAPI::PolygonScope::setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) const {
1281 tcpip::Storage content;
1283 if (shape.value.size() < 256) {
1284 content.writeUnsignedByte((int)shape.value.size());
1285 } else {
1286 content.writeUnsignedByte(0);
1287 content.writeInt((int)shape.value.size());
1288 }
1289 for (const libsumo::TraCIPosition& pos : shape.value) {
1290 content.writeDouble(pos.x);
1291 content.writeDouble(pos.y);
1292 }
1293 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_SHAPE, polygonID, &content);
1294 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1295}
1296
1297
1298void
1299TraCIAPI::PolygonScope::setColor(const std::string& polygonID, const libsumo::TraCIColor& c) const {
1300 tcpip::Storage content;
1302 content.writeUnsignedByte(c.r);
1303 content.writeUnsignedByte(c.g);
1304 content.writeUnsignedByte(c.b);
1305 content.writeUnsignedByte(c.a);
1306 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::VAR_COLOR, polygonID, &content);
1307 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1308}
1309
1310void
1311TraCIAPI::PolygonScope::add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& c, bool fill, const std::string& type, int layer) const {
1312 tcpip::Storage content;
1314 content.writeInt(5);
1316 content.writeString(type);
1318 content.writeUnsignedByte(c.r);
1319 content.writeUnsignedByte(c.g);
1320 content.writeUnsignedByte(c.b);
1321 content.writeUnsignedByte(c.a);
1323 int f = fill ? 1 : 0;
1324 content.writeUnsignedByte(f);
1326 content.writeInt(layer);
1328 content.writeUnsignedByte((int)shape.value.size());
1329 for (int i = 0; i < (int)shape.value.size(); ++i) {
1330 content.writeDouble(shape.value[i].x);
1331 content.writeDouble(shape.value[i].y);
1332 }
1333 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::ADD, polygonID, &content);
1334 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1335}
1336
1337void
1338TraCIAPI::PolygonScope::remove(const std::string& polygonID, int layer) const {
1339 tcpip::Storage content;
1341 content.writeInt(layer);
1342 myParent.createCommand(libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::REMOVE, polygonID, &content);
1343 myParent.processSet(libsumo::CMD_SET_POLYGON_VARIABLE);
1344}
1345
1346
1347// ---------------------------------------------------------------------------
1348// TraCIAPI::RouteScope-methods
1349// ---------------------------------------------------------------------------
1350std::vector<std::string>
1351TraCIAPI::RouteScope::getEdges(const std::string& routeID) const {
1352 return getStringVector(libsumo::VAR_EDGES, routeID);
1353}
1354
1355
1356void
1357TraCIAPI::RouteScope::add(const std::string& routeID, const std::vector<std::string>& edges) const {
1358 tcpip::Storage content;
1360 content.writeStringList(edges);
1361 myParent.createCommand(libsumo::CMD_SET_ROUTE_VARIABLE, libsumo::ADD, routeID, &content);
1362 myParent.processSet(libsumo::CMD_SET_ROUTE_VARIABLE);
1363}
1364
1365
1366// ---------------------------------------------------------------------------
1367// TraCIAPI::SimulationScope-methods
1368// ---------------------------------------------------------------------------
1369int
1373
1374double
1376 return getDouble(libsumo::VAR_TIME, "");
1377}
1378
1379int
1383
1384std::vector<std::string>
1388
1389int
1393
1394std::vector<std::string>
1398
1399int
1403
1404std::vector<std::string>
1408
1409int
1413
1414std::vector<std::string>
1418
1419int
1423
1424std::vector<std::string>
1428
1429int
1433
1434std::vector<std::string>
1438
1439int
1443
1444std::vector<std::string>
1448
1449double
1451 return getDouble(libsumo::VAR_DELTA_T, "");
1452}
1453
1458
1459
1460int
1464
1465std::string
1466TraCIAPI::SimulationScope::getOption(const std::string& option) const {
1467 return getString(libsumo::VAR_OPTION, option);
1468}
1469
1470int
1471TraCIAPI::SimulationScope::getBusStopWaiting(const std::string& stopID) const {
1472 return (int) getInt(libsumo::VAR_BUS_STOP_WAITING, stopID);
1473}
1474
1475std::vector<std::string>
1477 return getStringVector(libsumo::VAR_BUS_STOP_WAITING_IDS, stopID);
1478}
1479
1480
1482TraCIAPI::SimulationScope::convert2D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) const {
1483 const int posType = toGeo ? libsumo::POSITION_LON_LAT : libsumo::POSITION_2D;
1485 tcpip::Storage content;
1487 content.writeInt(2);
1489 content.writeString(edgeID);
1490 content.writeDouble(pos);
1491 content.writeByte(laneIndex);
1493 content.writeByte(posType);
1494 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1495 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1496 result.x = myParent.myInput.readDouble();
1497 result.y = myParent.myInput.readDouble();
1498 }
1499 return result;
1500}
1501
1502
1504TraCIAPI::SimulationScope::convert3D(const std::string& edgeID, double pos, int laneIndex, bool toGeo) const {
1505 const int posType = toGeo ? libsumo::POSITION_LON_LAT_ALT : libsumo::POSITION_3D;
1507 tcpip::Storage content;
1509 content.writeInt(2);
1511 content.writeString(edgeID);
1512 content.writeDouble(pos);
1513 content.writeByte(laneIndex);
1515 content.writeByte(posType);
1516 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1517 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1518 result.x = myParent.myInput.readDouble();
1519 result.y = myParent.myInput.readDouble();
1520 result.z = myParent.myInput.readDouble();
1521 }
1522 return result;
1523}
1524
1525
1527TraCIAPI::SimulationScope::convertRoad(double x, double y, bool isGeo, const std::string& vClass) const {
1529 tcpip::Storage content;
1531 content.writeInt(3);
1533 content.writeDouble(x);
1534 content.writeDouble(y);
1538 content.writeString(vClass);
1539 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1540 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_ROADMAP)) {
1541 result.edgeID = myParent.myInput.readString();
1542 result.pos = myParent.myInput.readDouble();
1543 result.laneIndex = myParent.myInput.readUnsignedByte();
1544 }
1545 return result;
1546}
1547
1548
1550TraCIAPI::SimulationScope::convertGeo(double x, double y, bool fromGeo) const {
1551 const int posType = fromGeo ? libsumo::POSITION_2D : libsumo::POSITION_LON_LAT;
1553 tcpip::Storage content;
1555 content.writeInt(2);
1557 content.writeDouble(x);
1558 content.writeDouble(y);
1560 content.writeByte(posType);
1561 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::POSITION_CONVERSION, "", &content);
1562 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, posType)) {
1563 result.x = myParent.myInput.readDouble();
1564 result.y = myParent.myInput.readDouble();
1565 }
1566 return result;
1567}
1568
1569
1570double
1571TraCIAPI::SimulationScope::getDistance2D(double x1, double y1, double x2, double y2, bool isGeo, bool isDriving) {
1572 tcpip::Storage content;
1574 content.writeInt(3);
1576 content.writeDouble(x1);
1577 content.writeDouble(y1);
1579 content.writeDouble(x2);
1580 content.writeDouble(y2);
1582 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::DISTANCE_REQUEST, "", &content);
1583 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::TYPE_DOUBLE)) {
1584 return myParent.myInput.readDouble();
1585 }
1586 return 0.;
1587}
1588
1589
1590double
1591TraCIAPI::SimulationScope::getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving) {
1592 tcpip::Storage content;
1594 content.writeInt(3);
1596 content.writeString(edgeID1);
1597 content.writeDouble(pos1);
1598 content.writeByte(0); // lane
1600 content.writeString(edgeID2);
1601 content.writeDouble(pos2);
1602 content.writeByte(0); // lane
1604 myParent.createCommand(libsumo::CMD_GET_SIM_VARIABLE, libsumo::DISTANCE_REQUEST, "", &content);
1605 if (myParent.processGet(libsumo::CMD_GET_SIM_VARIABLE, libsumo::TYPE_DOUBLE)) {
1606 return myParent.myInput.readDouble();
1607 }
1608 return 0.;
1609}
1610
1611
1613TraCIAPI::SimulationScope::findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType, double pos, int routingMode) const {
1614 tcpip::Storage content;
1616 content.writeInt(5);
1618 content.writeString(fromEdge);
1620 content.writeString(toEdge);
1622 content.writeString(vType);
1624 content.writeDouble(pos);
1626 content.writeInt(routingMode);
1627 return getTraCIStage(libsumo::FIND_ROUTE, "", &content);
1628}
1629
1630void
1631TraCIAPI::SimulationScope::loadState(const std::string& path) const {
1632 tcpip::Storage content;
1634 content.writeString(path);
1635 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_LOAD_SIMSTATE, "", &content);
1636 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1637}
1638
1639void
1640TraCIAPI::SimulationScope::saveState(const std::string& destination) const {
1641 tcpip::Storage content;
1643 content.writeString(destination);
1644 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_SAVE_SIMSTATE, "", &content);
1645 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1646}
1647
1648void
1650 tcpip::Storage content;
1652 content.writeString(msg);
1653 myParent.createCommand(libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_MESSAGE, "", &content);
1654 myParent.processSet(libsumo::CMD_SET_SIM_VARIABLE);
1655}
1656
1657
1658// ---------------------------------------------------------------------------
1659// TraCIAPI::TrafficLightScope-methods
1660// ---------------------------------------------------------------------------
1661std::string
1663 return getString(libsumo::TL_RED_YELLOW_GREEN_STATE, tlsID);
1664}
1665
1666std::vector<libsumo::TraCILogic>
1668 std::vector<libsumo::TraCILogic> ret;
1670 if (myParent.processGet(libsumo::CMD_GET_TL_VARIABLE, libsumo::TYPE_COMPOUND)) {
1671 const int logicNo = myParent.myInput.readInt();
1672 for (int i = 0; i < logicNo; ++i) {
1673 myParent.myInput.readUnsignedByte();
1674 myParent.myInput.readInt();
1675 myParent.myInput.readUnsignedByte();
1676 const std::string programID = myParent.myInput.readString();
1677 myParent.myInput.readUnsignedByte();
1678 const int type = myParent.myInput.readInt();
1679 myParent.myInput.readUnsignedByte();
1680 const int phaseIndex = myParent.myInput.readInt();
1681 myParent.myInput.readUnsignedByte();
1682 const int phaseNumber = myParent.myInput.readInt();
1683 libsumo::TraCILogic logic(programID, type, phaseIndex);
1684 for (int j = 0; j < phaseNumber; j++) {
1685 myParent.myInput.readUnsignedByte();
1686 myParent.myInput.readInt();
1687 myParent.myInput.readUnsignedByte();
1688 const double duration = myParent.myInput.readDouble();
1689 myParent.myInput.readUnsignedByte();
1690 const std::string state = myParent.myInput.readString();
1691 myParent.myInput.readUnsignedByte();
1692 const double minDur = myParent.myInput.readDouble();
1693 myParent.myInput.readUnsignedByte();
1694 const double maxDur = myParent.myInput.readDouble();
1695 myParent.myInput.readUnsignedByte();
1696 const int numNext = myParent.myInput.readInt();
1697 std::vector<int> next;
1698 for (int k = 0; k < numNext; k++) {
1699 myParent.myInput.readUnsignedByte();
1700 next.push_back(myParent.myInput.readInt());
1701 }
1702 myParent.myInput.readUnsignedByte();
1703 const std::string name = myParent.myInput.readString();
1704 logic.phases.emplace_back(new libsumo::TraCIPhase(duration, state, minDur, maxDur, next, name));
1705 }
1706 myParent.myInput.readUnsignedByte();
1707 const int paramNumber = myParent.myInput.readInt();
1708 for (int j = 0; j < paramNumber; j++) {
1709 myParent.myInput.readUnsignedByte();
1710 const std::vector<std::string> par = myParent.myInput.readStringList();
1711 logic.subParameter[par[0]] = par[1];
1712 }
1713 ret.emplace_back(logic);
1714 }
1715 }
1716 return ret;
1717}
1718
1719std::vector<std::string>
1721 return getStringVector(libsumo::TL_CONTROLLED_LANES, tlsID);
1722}
1723
1724std::vector<std::vector<libsumo::TraCILink> >
1726 std::vector<std::vector<libsumo::TraCILink> > result;
1727 myParent.createCommand(libsumo::CMD_GET_TL_VARIABLE, libsumo::TL_CONTROLLED_LINKS, tlsID);
1728 if (myParent.processGet(libsumo::CMD_GET_TL_VARIABLE, libsumo::TYPE_COMPOUND)) {
1729
1730 myParent.myInput.readUnsignedByte();
1731 myParent.myInput.readInt();
1732
1733 int linkNo = myParent.myInput.readInt();
1734 for (int i = 0; i < linkNo; ++i) {
1735 myParent.myInput.readUnsignedByte();
1736 int no = myParent.myInput.readInt();
1737 std::vector<libsumo::TraCILink> ret;
1738 for (int i1 = 0; i1 < no; ++i1) {
1739 myParent.myInput.readUnsignedByte();
1740 myParent.myInput.readInt();
1741 std::string from = myParent.myInput.readString();
1742 std::string to = myParent.myInput.readString();
1743 std::string via = myParent.myInput.readString();
1744 ret.emplace_back(libsumo::TraCILink(from, via, to));
1745 }
1746 result.emplace_back(ret);
1747 }
1748 }
1749 return result;
1750}
1751
1752std::string
1753TraCIAPI::TrafficLightScope::getProgram(const std::string& tlsID) const {
1754 return getString(libsumo::TL_CURRENT_PROGRAM, tlsID);
1755}
1756
1757int
1758TraCIAPI::TrafficLightScope::getPhase(const std::string& tlsID) const {
1759 return getInt(libsumo::TL_CURRENT_PHASE, tlsID);
1760}
1761
1762std::string
1763TraCIAPI::TrafficLightScope::getPhaseName(const std::string& tlsID) const {
1764 return getString(libsumo::VAR_NAME, tlsID);
1765}
1766
1767double
1768TraCIAPI::TrafficLightScope::getPhaseDuration(const std::string& tlsID) const {
1769 return getDouble(libsumo::TL_PHASE_DURATION, tlsID);
1770}
1771
1772double
1773TraCIAPI::TrafficLightScope::getNextSwitch(const std::string& tlsID) const {
1774 return getDouble(libsumo::TL_NEXT_SWITCH, tlsID);
1775}
1776
1777
1778int
1779TraCIAPI::TrafficLightScope::getServedPersonCount(const std::string& tlsID, int index) const {
1780 tcpip::Storage content;
1782 content.writeInt(index);
1783 return getInt(libsumo::VAR_PERSON_NUMBER, tlsID, &content);
1784}
1785
1786
1787void
1788TraCIAPI::TrafficLightScope::setRedYellowGreenState(const std::string& tlsID, const std::string& state) const {
1789 tcpip::Storage content;
1791 content.writeString(state);
1792 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_RED_YELLOW_GREEN_STATE, tlsID, &content);
1793 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1794}
1795
1796void
1797TraCIAPI::TrafficLightScope::setPhase(const std::string& tlsID, int index) const {
1798 tcpip::Storage content;
1800 content.writeInt(index);
1801 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PHASE_INDEX, tlsID, &content);
1802 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1803}
1804
1805void
1806TraCIAPI::TrafficLightScope::setPhaseName(const std::string& tlsID, const std::string& name) const {
1807 tcpip::Storage content;
1809 content.writeString(name);
1810 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::VAR_NAME, tlsID, &content);
1811 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1812}
1813
1814void
1815TraCIAPI::TrafficLightScope::setProgram(const std::string& tlsID, const std::string& programID) const {
1816 tcpip::Storage content;
1818 content.writeString(programID);
1819 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PROGRAM, tlsID, &content);
1820 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1821}
1822
1823void
1824TraCIAPI::TrafficLightScope::setPhaseDuration(const std::string& tlsID, double phaseDuration) const {
1825 tcpip::Storage content;
1827 content.writeDouble(phaseDuration);
1828 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_PHASE_DURATION, tlsID, &content);
1829 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1830}
1831
1832void
1833TraCIAPI::TrafficLightScope::setProgramLogic(const std::string& tlsID, const libsumo::TraCILogic& logic) const {
1834 tcpip::Storage content;
1836 content.writeInt(5);
1838 content.writeString(logic.programID);
1840 content.writeInt(logic.type);
1842 content.writeInt(logic.currentPhaseIndex);
1844 content.writeInt((int)logic.phases.size());
1845 for (const std::shared_ptr<libsumo::TraCIPhase>& p : logic.phases) {
1847 content.writeInt(6);
1849 content.writeDouble(p->duration);
1851 content.writeString(p->state);
1853 content.writeDouble(p->minDur);
1855 content.writeDouble(p->maxDur);
1857 content.writeInt((int)p->next.size());
1858 for (int n : p->next) {
1860 content.writeInt(n);
1861 }
1863 content.writeString(p->name);
1864 }
1866 content.writeInt((int)logic.subParameter.size());
1867 for (const auto& item : logic.subParameter) {
1869 content.writeInt(2);
1870 content.writeString(item.first);
1871 content.writeString(item.second);
1872 }
1873 myParent.createCommand(libsumo::CMD_SET_TL_VARIABLE, libsumo::TL_COMPLETE_PROGRAM_RYG, tlsID, &content);
1874 myParent.processSet(libsumo::CMD_SET_TL_VARIABLE);
1875}
1876
1877
1878// ---------------------------------------------------------------------------
1879// TraCIAPI::VehicleTypeScope-methods
1880// ---------------------------------------------------------------------------
1881double
1882TraCIAPI::VehicleTypeScope::getLength(const std::string& typeID) const {
1883 return getDouble(libsumo::VAR_LENGTH, typeID);
1884}
1885
1886double
1887TraCIAPI::VehicleTypeScope::getMaxSpeed(const std::string& typeID) const {
1888 return getDouble(libsumo::VAR_MAXSPEED, typeID);
1889}
1890
1891double
1892TraCIAPI::VehicleTypeScope::getSpeedFactor(const std::string& typeID) const {
1893 return getDouble(libsumo::VAR_SPEED_FACTOR, typeID);
1894}
1895
1896double
1897TraCIAPI::VehicleTypeScope::getSpeedDeviation(const std::string& typeID) const {
1898 return getDouble(libsumo::VAR_SPEED_DEVIATION, typeID);
1899}
1900
1901double
1902TraCIAPI::VehicleTypeScope::getAccel(const std::string& typeID) const {
1903 return getDouble(libsumo::VAR_ACCEL, typeID);
1904}
1905
1906double
1907TraCIAPI::VehicleTypeScope::getDecel(const std::string& typeID) const {
1908 return getDouble(libsumo::VAR_DECEL, typeID);
1909}
1910
1911double
1912TraCIAPI::VehicleTypeScope::getEmergencyDecel(const std::string& typeID) const {
1913 return getDouble(libsumo::VAR_EMERGENCY_DECEL, typeID);
1914}
1915
1916double
1917TraCIAPI::VehicleTypeScope::getApparentDecel(const std::string& typeID) const {
1918 return getDouble(libsumo::VAR_APPARENT_DECEL, typeID);
1919}
1920
1921double
1922TraCIAPI::VehicleTypeScope::getImperfection(const std::string& typeID) const {
1923 return getDouble(libsumo::VAR_IMPERFECTION, typeID);
1924}
1925
1926double
1927TraCIAPI::VehicleTypeScope::getTau(const std::string& typeID) const {
1928 return getDouble(libsumo::VAR_TAU, typeID);
1929}
1930
1931std::string
1932TraCIAPI::VehicleTypeScope::getVehicleClass(const std::string& typeID) const {
1933 return getString(libsumo::VAR_VEHICLECLASS, typeID);
1934}
1935
1936std::string
1937TraCIAPI::VehicleTypeScope::getEmissionClass(const std::string& typeID) const {
1938 return getString(libsumo::VAR_EMISSIONCLASS, typeID);
1939}
1940
1941std::string
1942TraCIAPI::VehicleTypeScope::getShapeClass(const std::string& typeID) const {
1943 return getString(libsumo::VAR_SHAPECLASS, typeID);
1944}
1945
1946double
1947TraCIAPI::VehicleTypeScope::getMinGap(const std::string& typeID) const {
1948 return getDouble(libsumo::VAR_MINGAP, typeID);
1949}
1950
1951double
1952TraCIAPI::VehicleTypeScope::getMinGapLat(const std::string& typeID) const {
1953 return getDouble(libsumo::VAR_MINGAP_LAT, typeID);
1954}
1955
1956double
1957TraCIAPI::VehicleTypeScope::getMaxSpeedLat(const std::string& typeID) const {
1958 return getDouble(libsumo::VAR_MAXSPEED_LAT, typeID);
1959}
1960
1961std::string
1962TraCIAPI::VehicleTypeScope::getLateralAlignment(const std::string& typeID) const {
1963 return getString(libsumo::VAR_LATALIGNMENT, typeID);
1964}
1965
1966int
1967TraCIAPI::VehicleTypeScope::getPersonCapacity(const std::string& typeID) const {
1968 return getInt(libsumo::VAR_PERSON_CAPACITY, typeID);
1969}
1970
1971double
1972TraCIAPI::VehicleTypeScope::getWidth(const std::string& typeID) const {
1973 return getDouble(libsumo::VAR_WIDTH, typeID);
1974}
1975
1976double
1977TraCIAPI::VehicleTypeScope::getHeight(const std::string& typeID) const {
1978 return getDouble(libsumo::VAR_HEIGHT, typeID);
1979}
1980
1982TraCIAPI::VehicleTypeScope::getColor(const std::string& typeID) const {
1983 return getCol(libsumo::VAR_COLOR, typeID);
1984}
1985
1986
1987
1988void
1989TraCIAPI::VehicleTypeScope::setLength(const std::string& typeID, double length) const {
1990 tcpip::Storage content;
1992 content.writeDouble(length);
1993 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_LENGTH, typeID, &content);
1994 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
1995}
1996
1997void
1998TraCIAPI::VehicleTypeScope::setMaxSpeed(const std::string& typeID, double speed) const {
1999 tcpip::Storage content;
2001 content.writeDouble(speed);
2002 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MAXSPEED, typeID, &content);
2003 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2004}
2005
2006void
2007TraCIAPI::VehicleTypeScope::setVehicleClass(const std::string& typeID, const std::string& clazz) const {
2008 tcpip::Storage content;
2010 content.writeString(clazz);
2011 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_VEHICLECLASS, typeID, &content);
2012 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2013}
2014
2015void
2016TraCIAPI::VehicleTypeScope::setSpeedFactor(const std::string& typeID, double factor) const {
2017 tcpip::Storage content;
2019 content.writeDouble(factor);
2020 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SPEED_FACTOR, typeID, &content);
2021 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2022}
2023
2024void
2025TraCIAPI::VehicleTypeScope::setSpeedDeviation(const std::string& typeID, double deviation) const {
2026 tcpip::Storage content;
2028 content.writeDouble(deviation);
2029 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SPEED_DEVIATION, typeID, &content);
2030 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2031}
2032
2033
2034void
2035TraCIAPI::VehicleTypeScope::setEmissionClass(const std::string& typeID, const std::string& clazz) const {
2036 tcpip::Storage content;
2038 content.writeString(clazz);
2039 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_EMISSIONCLASS, typeID, &content);
2040 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2041}
2042
2043void
2044TraCIAPI::VehicleTypeScope::setWidth(const std::string& typeID, double width) const {
2045 tcpip::Storage content;
2047 content.writeDouble(width);
2048 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_WIDTH, typeID, &content);
2049 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2050}
2051
2052void
2053TraCIAPI::VehicleTypeScope::setHeight(const std::string& typeID, double height) const {
2054 tcpip::Storage content;
2056 content.writeDouble(height);
2057 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_HEIGHT, typeID, &content);
2058 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2059}
2060
2061void
2062TraCIAPI::VehicleTypeScope::setMinGap(const std::string& typeID, double minGap) const {
2063 tcpip::Storage content;
2065 content.writeDouble(minGap);
2066 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MINGAP, typeID, &content);
2067 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2068}
2069
2070
2071void
2072TraCIAPI::VehicleTypeScope::setMinGapLat(const std::string& typeID, double minGapLat) const {
2073 tcpip::Storage content;
2075 content.writeDouble(minGapLat);
2076 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MINGAP_LAT, typeID, &content);
2077 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2078}
2079
2080void
2081TraCIAPI::VehicleTypeScope::setMaxSpeedLat(const std::string& typeID, double speed) const {
2082 tcpip::Storage content;
2084 content.writeDouble(speed);
2085 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_MAXSPEED_LAT, typeID, &content);
2086 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2087}
2088
2089void
2090TraCIAPI::VehicleTypeScope::setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const {
2091 tcpip::Storage content;
2093 content.writeString(latAlignment);
2094 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_LATALIGNMENT, typeID, &content);
2095 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2096}
2097
2098void
2099TraCIAPI::VehicleTypeScope::copy(const std::string& origTypeID, const std::string& newTypeID) const {
2100 tcpip::Storage content;
2102 content.writeString(newTypeID);
2103 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::COPY, origTypeID, &content);
2104 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2105}
2106
2107void
2108TraCIAPI::VehicleTypeScope::setShapeClass(const std::string& typeID, const std::string& clazz) const {
2109 tcpip::Storage content;
2111 content.writeString(clazz);
2112 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_SHAPECLASS, typeID, &content);
2113 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2114}
2115
2116void
2117TraCIAPI::VehicleTypeScope::setAccel(const std::string& typeID, double accel) const {
2118 tcpip::Storage content;
2120 content.writeDouble(accel);
2121 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_ACCEL, typeID, &content);
2122 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2123}
2124
2125void
2126TraCIAPI::VehicleTypeScope::setDecel(const std::string& typeID, double decel) const {
2127 tcpip::Storage content;
2129 content.writeDouble(decel);
2130 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_DECEL, typeID, &content);
2131 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2132}
2133
2134void
2135TraCIAPI::VehicleTypeScope::setEmergencyDecel(const std::string& typeID, double decel) const {
2136 tcpip::Storage content;
2138 content.writeDouble(decel);
2139 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_EMERGENCY_DECEL, typeID, &content);
2140 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2141}
2142
2143void
2144TraCIAPI::VehicleTypeScope::setApparentDecel(const std::string& typeID, double decel) const {
2145 tcpip::Storage content;
2147 content.writeDouble(decel);
2148 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_APPARENT_DECEL, typeID, &content);
2149 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2150}
2151
2152void
2153TraCIAPI::VehicleTypeScope::setImperfection(const std::string& typeID, double imperfection) const {
2154 tcpip::Storage content;
2156 content.writeDouble(imperfection);
2157 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_IMPERFECTION, typeID, &content);
2158 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2159}
2160
2161void
2162TraCIAPI::VehicleTypeScope::setTau(const std::string& typeID, double tau) const {
2163 tcpip::Storage content;
2165 content.writeDouble(tau);
2166 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_TAU, typeID, &content);
2167 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2168}
2169
2170void
2171TraCIAPI::VehicleTypeScope::setColor(const std::string& typeID, const libsumo::TraCIColor& c) const {
2172 tcpip::Storage content;
2174 content.writeUnsignedByte(c.r);
2175 content.writeUnsignedByte(c.g);
2176 content.writeUnsignedByte(c.b);
2177 content.writeUnsignedByte(c.a);
2178 myParent.createCommand(libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::VAR_COLOR, typeID, &content);
2179 myParent.processSet(libsumo::CMD_SET_VEHICLETYPE_VARIABLE);
2180}
2181
2182
2183// ---------------------------------------------------------------------------
2184// TraCIAPI::VehicleScope-methods
2185// ---------------------------------------------------------------------------
2186double
2187TraCIAPI::VehicleScope::getSpeed(const std::string& vehicleID) const {
2188 return getDouble(libsumo::VAR_SPEED, vehicleID);
2189}
2190
2191double
2192TraCIAPI::VehicleScope::getLateralSpeed(const std::string& vehicleID) const {
2193 return getDouble(libsumo::VAR_SPEED_LAT, vehicleID);
2194}
2195
2196double
2197TraCIAPI::VehicleScope::getAcceleration(const std::string& vehicleID) const {
2198 return getDouble(libsumo::VAR_ACCELERATION, vehicleID);
2199}
2200
2201double
2202TraCIAPI::VehicleScope::getFollowSpeed(const std::string& vehicleID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) const {
2203 tcpip::Storage content;
2205 content.writeInt(5);
2207 content.writeDouble(speed);
2209 content.writeDouble(gap);
2211 content.writeDouble(leaderSpeed);
2213 content.writeDouble(leaderMaxDecel);
2215 content.writeString(leaderID);
2216 return getDouble(libsumo::VAR_FOLLOW_SPEED, vehicleID, &content);
2217}
2218
2219
2220double
2221TraCIAPI::VehicleScope::getSecureGap(const std::string& vehicleID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) const {
2222 tcpip::Storage content;
2224 content.writeInt(4);
2226 content.writeDouble(speed);
2228 content.writeDouble(leaderSpeed);
2230 content.writeDouble(leaderMaxDecel);
2232 content.writeString(leaderID);
2233 return getDouble(libsumo::VAR_SECURE_GAP, vehicleID, &content);
2234}
2235
2236double
2237TraCIAPI::VehicleScope::getStopSpeed(const std::string& vehicleID, double speed, double gap) const {
2238 tcpip::Storage content;
2240 content.writeInt(2);
2242 content.writeDouble(speed);
2244 content.writeDouble(gap);
2245 return getDouble(libsumo::VAR_STOP_SPEED, vehicleID, &content);
2246}
2247
2248
2249double
2250TraCIAPI::VehicleScope::getMaxSpeed(const std::string& vehicleID) const {
2251 return getDouble(libsumo::VAR_MAXSPEED, vehicleID);
2252}
2253
2255TraCIAPI::VehicleScope::getPosition(const std::string& vehicleID) const {
2256 return getPos(libsumo::VAR_POSITION, vehicleID);
2257}
2258
2260TraCIAPI::VehicleScope::getPosition3D(const std::string& vehicleID) const {
2261 return getPos3D(libsumo::VAR_POSITION3D, vehicleID);
2262}
2263
2264double
2265TraCIAPI::VehicleScope::getAngle(const std::string& vehicleID) const {
2266 return getDouble(libsumo::VAR_ANGLE, vehicleID);
2267}
2268
2269std::string
2270TraCIAPI::VehicleScope::getRoadID(const std::string& vehicleID) const {
2271 return getString(libsumo::VAR_ROAD_ID, vehicleID);
2272}
2273
2274std::string
2275TraCIAPI::VehicleScope::getLaneID(const std::string& vehicleID) const {
2276 return getString(libsumo::VAR_LANE_ID, vehicleID);
2277}
2278
2279int
2280TraCIAPI::VehicleScope::getLaneIndex(const std::string& vehicleID) const {
2281 return getInt(libsumo::VAR_LANE_INDEX, vehicleID);
2282}
2283
2284std::string
2285TraCIAPI::VehicleScope::getTypeID(const std::string& vehicleID) const {
2286 return getString(libsumo::VAR_TYPE, vehicleID);
2287}
2288
2289std::string
2290TraCIAPI::VehicleScope::getRouteID(const std::string& vehicleID) const {
2291 return getString(libsumo::VAR_ROUTE_ID, vehicleID);
2292}
2293
2294int
2295TraCIAPI::VehicleScope::getRouteIndex(const std::string& vehicleID) const {
2296 return getInt(libsumo::VAR_ROUTE_INDEX, vehicleID);
2297}
2298
2299
2300std::vector<std::string>
2301TraCIAPI::VehicleScope::getRoute(const std::string& vehicleID) const {
2302 return getStringVector(libsumo::VAR_EDGES, vehicleID);
2303}
2304
2306TraCIAPI::VehicleScope::getColor(const std::string& vehicleID) const {
2307 return getCol(libsumo::VAR_COLOR, vehicleID);
2308}
2309
2310double
2311TraCIAPI::VehicleScope::getLanePosition(const std::string& vehicleID) const {
2312 return getDouble(libsumo::VAR_LANEPOSITION, vehicleID);
2313}
2314
2315double
2316TraCIAPI::VehicleScope::getDistance(const std::string& vehicleID) const {
2317 return getDouble(libsumo::VAR_DISTANCE, vehicleID);
2318}
2319
2320int
2321TraCIAPI::VehicleScope::getSignals(const std::string& vehicleID) const {
2322 return getInt(libsumo::VAR_SIGNALS, vehicleID);
2323}
2324
2325double
2326TraCIAPI::VehicleScope::getLateralLanePosition(const std::string& vehicleID) const {
2327 return getDouble(libsumo::VAR_LANEPOSITION_LAT, vehicleID);
2328}
2329
2330double
2331TraCIAPI::VehicleScope::getCO2Emission(const std::string& vehicleID) const {
2332 return getDouble(libsumo::VAR_CO2EMISSION, vehicleID);
2333}
2334
2335double
2336TraCIAPI::VehicleScope::getCOEmission(const std::string& vehicleID) const {
2337 return getDouble(libsumo::VAR_COEMISSION, vehicleID);
2338}
2339
2340double
2341TraCIAPI::VehicleScope::getHCEmission(const std::string& vehicleID) const {
2342 return getDouble(libsumo::VAR_HCEMISSION, vehicleID);
2343}
2344
2345double
2346TraCIAPI::VehicleScope::getPMxEmission(const std::string& vehicleID) const {
2347 return getDouble(libsumo::VAR_PMXEMISSION, vehicleID);
2348}
2349
2350double
2351TraCIAPI::VehicleScope::getNOxEmission(const std::string& vehicleID) const {
2352 return getDouble(libsumo::VAR_NOXEMISSION, vehicleID);
2353}
2354
2355double
2356TraCIAPI::VehicleScope::getFuelConsumption(const std::string& vehicleID) const {
2357 return getDouble(libsumo::VAR_FUELCONSUMPTION, vehicleID);
2358}
2359
2360double
2361TraCIAPI::VehicleScope::getNoiseEmission(const std::string& vehicleID) const {
2362 return getDouble(libsumo::VAR_NOISEEMISSION, vehicleID);
2363}
2364
2365double
2366TraCIAPI::VehicleScope::getElectricityConsumption(const std::string& vehicleID) const {
2367 return getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, vehicleID);
2368}
2369
2370double
2371TraCIAPI::VehicleScope::getWaitingTime(const std::string& vehID) const {
2372 return getDouble(libsumo::VAR_WAITING_TIME, vehID);
2373}
2374
2375int
2376TraCIAPI::VehicleScope::getLaneChangeMode(const std::string& vehID) const {
2377 return getInt(libsumo::VAR_LANECHANGE_MODE, vehID);
2378}
2379
2380
2381int
2382TraCIAPI::VehicleScope::getSpeedMode(const std::string& vehID) const {
2383 return getInt(libsumo::VAR_SPEEDSETMODE, vehID);
2384}
2385
2386
2387double
2388TraCIAPI::VehicleScope::getSlope(const std::string& vehID) const {
2389 return getDouble(libsumo::VAR_SLOPE, vehID);
2390}
2391
2392
2393std::string
2394TraCIAPI::VehicleScope::getLine(const std::string& typeID) const {
2395 return getString(libsumo::VAR_LINE, typeID);
2396}
2397
2398std::vector<std::string>
2399TraCIAPI::VehicleScope::getVia(const std::string& vehicleID) const {
2400 return getStringVector(libsumo::VAR_VIA, vehicleID);
2401}
2402
2403std::string
2404TraCIAPI::VehicleScope::getEmissionClass(const std::string& vehicleID) const {
2405 return getString(libsumo::VAR_EMISSIONCLASS, vehicleID);
2406}
2407
2408std::string
2409TraCIAPI::VehicleScope::getShapeClass(const std::string& vehicleID) const {
2410 return getString(libsumo::VAR_SHAPECLASS, vehicleID);
2411}
2412
2413std::vector<libsumo::TraCINextTLSData>
2414TraCIAPI::VehicleScope::getNextTLS(const std::string& vehID) const {
2415 std::vector<libsumo::TraCINextTLSData> result;
2416 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_NEXT_TLS, vehID);
2418 myParent.myInput.readInt(); // components
2419 // number of items
2420 myParent.myInput.readUnsignedByte();
2421 const int n = myParent.myInput.readInt();
2422 for (int i = 0; i < n; ++i) {
2424 myParent.myInput.readUnsignedByte();
2425 d.id = myParent.myInput.readString();
2426
2427 myParent.myInput.readUnsignedByte();
2428 d.tlIndex = myParent.myInput.readInt();
2429
2430 myParent.myInput.readUnsignedByte();
2431 d.dist = myParent.myInput.readDouble();
2432
2433 myParent.myInput.readUnsignedByte();
2434 d.state = (char)myParent.myInput.readByte();
2435
2436 result.push_back(d);
2437 }
2438 }
2439 return result;
2440}
2441
2442std::vector<libsumo::TraCIBestLanesData>
2443TraCIAPI::VehicleScope::getBestLanes(const std::string& vehicleID) const {
2444 std::vector<libsumo::TraCIBestLanesData> result;
2445 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_BEST_LANES, vehicleID);
2447 myParent.myInput.readInt();
2448 myParent.myInput.readUnsignedByte();
2449
2450 const int n = myParent.myInput.readInt(); // number of following edge information
2451 for (int i = 0; i < n; ++i) {
2453 myParent.myInput.readUnsignedByte();
2454 info.laneID = myParent.myInput.readString();
2455
2456 myParent.myInput.readUnsignedByte();
2457 info.length = myParent.myInput.readDouble();
2458
2459 myParent.myInput.readUnsignedByte();
2460 info.occupation = myParent.myInput.readDouble();
2461
2462 myParent.myInput.readUnsignedByte();
2463 info.bestLaneOffset = myParent.myInput.readByte();
2464
2465 myParent.myInput.readUnsignedByte();
2466 info.allowsContinuation = (myParent.myInput.readUnsignedByte() == 1);
2467
2468 myParent.myInput.readUnsignedByte();
2469 const int m = myParent.myInput.readInt();
2470 for (int j = 0; j < m; ++j) {
2471 info.continuationLanes.push_back(myParent.myInput.readString());
2472 }
2473
2474 result.push_back(info);
2475 }
2476 }
2477 return result;
2478}
2479
2480
2481std::pair<std::string, double>
2482TraCIAPI::VehicleScope::getLeader(const std::string& vehicleID, double dist) const {
2483 tcpip::Storage content;
2485 content.writeDouble(dist);
2486 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_LEADER, vehicleID, &content);
2488 myParent.myInput.readInt(); // components
2489 myParent.myInput.readUnsignedByte();
2490 const std::string leaderID = myParent.myInput.readString();
2491 myParent.myInput.readUnsignedByte();
2492 const double gap = myParent.myInput.readDouble();
2493 return std::make_pair(leaderID, gap);
2494 }
2495 return std::make_pair("", libsumo::INVALID_DOUBLE_VALUE);
2496}
2497
2498
2499std::pair<std::string, double>
2500TraCIAPI::VehicleScope::getFollower(const std::string& vehicleID, double dist) const {
2501 tcpip::Storage content;
2503 content.writeDouble(dist);
2504 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::VAR_FOLLOWER, vehicleID, &content);
2506 myParent.myInput.readInt(); // components
2507 myParent.myInput.readUnsignedByte();
2508 const std::string leaderID = myParent.myInput.readString();
2509 myParent.myInput.readUnsignedByte();
2510 const double gap = myParent.myInput.readDouble();
2511 return std::make_pair(leaderID, gap);
2512 }
2513 return std::make_pair("", libsumo::INVALID_DOUBLE_VALUE);
2514}
2515
2516
2517std::pair<int, int>
2518TraCIAPI::VehicleScope::getLaneChangeState(const std::string& vehicleID, int direction) const {
2519 tcpip::Storage content;
2521 content.writeInt(direction);
2522 myParent.createCommand(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2524 myParent.myInput.readInt(); // components
2525 myParent.myInput.readUnsignedByte();
2526 const int stateWithoutTraCI = myParent.myInput.readInt();
2527 myParent.myInput.readUnsignedByte();
2528 const int state = myParent.myInput.readInt();
2529 return std::make_pair(stateWithoutTraCI, state);
2530 }
2532}
2533
2534
2535int
2536TraCIAPI::VehicleScope::getStopState(const std::string& vehicleID) const {
2537 return getInt(libsumo::VAR_STOPSTATE, vehicleID);
2538}
2539
2540int
2541TraCIAPI::VehicleScope::getRoutingMode(const std::string& vehicleID) const {
2542 return getInt(libsumo::VAR_ROUTING_MODE, vehicleID);
2543}
2544
2545double
2546TraCIAPI::VehicleScope::getStopDelay(const std::string& vehicleID) const {
2547 return getDouble(libsumo::VAR_STOP_DELAY, vehicleID);
2548}
2549
2550double
2551TraCIAPI::VehicleScope::getStopArrivalDelay(const std::string& vehicleID) const {
2552 return getDouble(libsumo::VAR_STOP_ARRIVALDELAY, vehicleID);
2553}
2554
2555
2556double
2557TraCIAPI::VehicleScope::getAccel(const std::string& vehicleID) const {
2558 return getDouble(libsumo::VAR_ACCEL, vehicleID);
2559}
2560
2561double
2562TraCIAPI::VehicleScope::getDecel(const std::string& vehicleID) const {
2563 return getDouble(libsumo::VAR_DECEL, vehicleID);
2564}
2565
2566double
2567TraCIAPI::VehicleScope::getTau(const std::string& vehicleID) const {
2568 return getDouble(libsumo::VAR_TAU, vehicleID);
2569}
2570
2571double
2572TraCIAPI::VehicleScope::getImperfection(const std::string& vehicleID) const {
2573 return getDouble(libsumo::VAR_IMPERFECTION, vehicleID);
2574}
2575
2576double
2577TraCIAPI::VehicleScope::getSpeedFactor(const std::string& vehicleID) const {
2578 return getDouble(libsumo::VAR_SPEED_FACTOR, vehicleID);
2579}
2580
2581double
2582TraCIAPI::VehicleScope::getSpeedDeviation(const std::string& vehicleID) const {
2583 return getDouble(libsumo::VAR_SPEED_DEVIATION, vehicleID);
2584}
2585
2586std::string
2587TraCIAPI::VehicleScope::getVehicleClass(const std::string& vehicleID) const {
2588 return getString(libsumo::VAR_VEHICLECLASS, vehicleID);
2589}
2590
2591double
2592TraCIAPI::VehicleScope::getMinGap(const std::string& vehicleID) const {
2593 return getDouble(libsumo::VAR_MINGAP, vehicleID);
2594}
2595
2596double
2597TraCIAPI::VehicleScope::getWidth(const std::string& vehicleID) const {
2598 return getDouble(libsumo::VAR_WIDTH, vehicleID);
2599}
2600
2601double
2602TraCIAPI::VehicleScope::getLength(const std::string& vehicleID) const {
2603 return getDouble(libsumo::VAR_LENGTH, vehicleID);
2604}
2605
2606double
2607TraCIAPI::VehicleScope::getHeight(const std::string& vehicleID) const {
2608 return getDouble(libsumo::VAR_HEIGHT, vehicleID);
2609}
2610
2611double
2612TraCIAPI::VehicleScope::getAccumulatedWaitingTime(const std::string& vehicleID) const {
2613 return getDouble(libsumo::VAR_ACCUMULATED_WAITING_TIME, vehicleID);
2614}
2615
2616double
2617TraCIAPI::VehicleScope::getAllowedSpeed(const std::string& vehicleID) const {
2618 return getDouble(libsumo::VAR_ALLOWED_SPEED, vehicleID);
2619}
2620
2621int
2622TraCIAPI::VehicleScope::getPersonNumber(const std::string& vehicleID) const {
2623 return getInt(libsumo::VAR_PERSON_NUMBER, vehicleID);
2624}
2625
2626int
2627TraCIAPI::VehicleScope::getPersonCapacity(const std::string& vehicleID) const {
2628 return getInt(libsumo::VAR_PERSON_CAPACITY, vehicleID);
2629}
2630
2631std::vector<std::string>
2632TraCIAPI::VehicleScope::getPersonIDList(const std::string& vehicleID) const {
2633 return getStringVector(libsumo::LAST_STEP_PERSON_ID_LIST, vehicleID);
2634}
2635
2636double
2637TraCIAPI::VehicleScope::getSpeedWithoutTraCI(const std::string& vehicleID) const {
2638 return getDouble(libsumo::VAR_SPEED_WITHOUT_TRACI, vehicleID);
2639}
2640
2641bool
2642TraCIAPI::VehicleScope::isRouteValid(const std::string& vehicleID) const {
2643 return getInt(libsumo::VAR_ROUTE_VALID, vehicleID) != 0;
2644}
2645
2646double
2647TraCIAPI::VehicleScope::getMaxSpeedLat(const std::string& vehicleID) const {
2648 return getDouble(libsumo::VAR_MAXSPEED_LAT, vehicleID);
2649}
2650
2651double
2652TraCIAPI::VehicleScope::getMinGapLat(const std::string& vehicleID) const {
2653 return getDouble(libsumo::VAR_MINGAP_LAT, vehicleID);
2654}
2655
2656std::string
2657TraCIAPI::VehicleScope::getLateralAlignment(const std::string& vehicleID) const {
2658 return getString(libsumo::VAR_LATALIGNMENT, vehicleID);
2659}
2660
2661void
2662TraCIAPI::VehicleScope::add(const std::string& vehicleID,
2663 const std::string& routeID,
2664 const std::string& typeID,
2665 std::string depart,
2666 const std::string& departLane,
2667 const std::string& departPos,
2668 const std::string& departSpeed,
2669 const std::string& arrivalLane,
2670 const std::string& arrivalPos,
2671 const std::string& arrivalSpeed,
2672 const std::string& fromTaz,
2673 const std::string& toTaz,
2674 const std::string& line,
2675 int personCapacity,
2676 int personNumber) const {
2677
2678 if (depart == "-1") {
2679 depart = toString(myParent.simulation.getCurrentTime() / 1000.0);
2680 }
2681 tcpip::Storage content;
2683 content.writeInt(14);
2685 content.writeString(routeID);
2687 content.writeString(typeID);
2689 content.writeString(depart);
2691 content.writeString(departLane);
2693 content.writeString(departPos);
2695 content.writeString(departSpeed);
2696
2698 content.writeString(arrivalLane);
2700 content.writeString(arrivalPos);
2702 content.writeString(arrivalSpeed);
2703
2705 content.writeString(fromTaz);
2707 content.writeString(toTaz);
2709 content.writeString(line);
2710
2712 content.writeInt(personCapacity);
2714 content.writeInt(personNumber);
2715
2716 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::ADD_FULL, vehicleID, &content);
2717 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2718}
2719
2720
2721void
2722TraCIAPI::VehicleScope::remove(const std::string& vehicleID, char reason) const {
2723 tcpip::Storage content;
2725 content.writeUnsignedByte(reason);
2726 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::REMOVE, vehicleID, &content);
2727 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2728
2729}
2730
2731
2732void
2733TraCIAPI::VehicleScope::changeTarget(const std::string& vehicleID, const std::string& edgeID) const {
2734 tcpip::Storage content;
2736 content.writeString(edgeID);
2737 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGETARGET, vehicleID, &content);
2738 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2739}
2740
2741
2742void
2743TraCIAPI::VehicleScope::changeLane(const std::string& vehicleID, int laneIndex, double duration) const {
2744 tcpip::Storage content;
2746 content.writeInt(2);
2748 content.writeByte(laneIndex);
2750 content.writeDouble(duration);
2751 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2752 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2753}
2754
2755
2756void
2757TraCIAPI::VehicleScope::changeLaneRelative(const std::string& vehicleID, int laneChange, double duration) const {
2758 tcpip::Storage content;
2760 content.writeInt(3);
2762 content.writeByte(laneChange);
2764 content.writeDouble(duration);
2766 content.writeByte(1);
2767 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGELANE, vehicleID, &content);
2768 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2769}
2770
2771
2772void
2773TraCIAPI::VehicleScope::changeSublane(const std::string& vehicleID, double latDist) const {
2774 tcpip::Storage content;
2776 content.writeDouble(latDist);
2777 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_CHANGESUBLANE, vehicleID, &content);
2778 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2779}
2780
2781
2782void
2783TraCIAPI::VehicleScope::setRouteID(const std::string& vehicleID, const std::string& routeID) const {
2784 tcpip::Storage content;
2786 content.writeString(routeID);
2787 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE_ID, vehicleID, &content);
2788 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2789}
2790
2791
2792void
2793TraCIAPI::VehicleScope::setRoute(const std::string& vehicleID, const std::vector<std::string>& edges) const {
2794 tcpip::Storage content;
2796 content.writeInt((int)edges.size());
2797 for (int i = 0; i < (int)edges.size(); ++i) {
2798 content.writeString(edges[i]);
2799 }
2800 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTE, vehicleID, &content);
2801 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2802}
2803
2804
2805void
2806TraCIAPI::VehicleScope::rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes) const {
2807 if (currentTravelTimes) {
2808 // updated edge weights with current network traveltimes (at most once per simulation step)
2809 std::vector<std::string> edges = myParent.edge.getIDList();
2810 for (std::vector<std::string>::iterator it = edges.begin(); it != edges.end(); ++it) {
2811 myParent.edge.adaptTraveltime(*it, myParent.edge.getTraveltime(*it));
2812 }
2813 }
2814
2815 tcpip::Storage content;
2817 content.writeInt(0);
2818 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_REROUTE_TRAVELTIME, vehicleID, &content);
2819 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2820}
2821
2822void
2823TraCIAPI::VehicleScope::moveTo(const std::string& vehicleID, const std::string& laneID, double position, int reason) const {
2824 tcpip::Storage content;
2826 content.writeInt(3);
2828 content.writeString(laneID);
2830 content.writeDouble(position);
2832 content.writeInt(reason);
2833 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MOVE_TO, vehicleID, &content);
2834 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2835}
2836
2837void
2838TraCIAPI::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 {
2839 tcpip::Storage content;
2841 content.writeInt(6);
2843 content.writeString(edgeID);
2845 content.writeInt(lane);
2847 content.writeDouble(x);
2849 content.writeDouble(y);
2851 content.writeDouble(angle);
2853 content.writeByte(keepRoute);
2854 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::MOVE_TO_XY, vehicleID, &content);
2855 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2856}
2857
2858
2859void
2860TraCIAPI::VehicleScope::slowDown(const std::string& vehicleID, double speed, double duration) const {
2861 tcpip::Storage content;
2863 content.writeInt(2);
2865 content.writeDouble(speed);
2867 content.writeDouble(duration);
2868 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_SLOWDOWN, vehicleID, &content);
2869 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2870}
2871
2872void
2873TraCIAPI::VehicleScope::openGap(const std::string& vehicleID, double newTau, double duration, double changeRate, double maxDecel) const {
2874 tcpip::Storage content;
2876 if (maxDecel > 0) {
2877 content.writeInt(4);
2878 } else {
2879 content.writeInt(3);
2880 }
2882 content.writeDouble(newTau);
2884 content.writeDouble(duration);
2886 content.writeDouble(changeRate);
2887 if (maxDecel > 0) {
2889 content.writeDouble(maxDecel);
2890 }
2891 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_OPENGAP, vehicleID, &content);
2892 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2893}
2894
2895void
2896TraCIAPI::VehicleScope::setSpeed(const std::string& vehicleID, double speed) const {
2897 tcpip::Storage content;
2899 content.writeDouble(speed);
2900 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEED, vehicleID, &content);
2901 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2902}
2903
2904void
2905TraCIAPI::VehicleScope::setAcceleration(const std::string& vehicleID, double accel, double duration) const {
2906 tcpip::Storage content;
2908 content.writeInt(2);
2910 content.writeDouble(accel);
2912 content.writeDouble(duration);
2913 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ACCELERATION, vehicleID, &content);
2914 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2915}
2916
2917void
2918TraCIAPI::VehicleScope::setPreviousSpeed(const std::string& vehicleID, double prevSpeed, double prevAcceleration) const {
2919 tcpip::Storage content;
2921 content.writeInt(2);
2923 content.writeDouble(prevSpeed);
2925 content.writeDouble(prevAcceleration);
2926 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_PREV_SPEED, vehicleID, &content);
2927 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2928}
2929
2930void
2931TraCIAPI::VehicleScope::setLaneChangeMode(const std::string& vehicleID, int mode) const {
2932 tcpip::Storage content;
2934 content.writeInt(mode);
2935 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_LANECHANGE_MODE, vehicleID, &content);
2936 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2937}
2938
2939void
2940TraCIAPI::VehicleScope::setSpeedMode(const std::string& vehicleID, int mode) const {
2941 tcpip::Storage content;
2943 content.writeInt(mode);
2944 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEEDSETMODE, vehicleID, &content);
2945 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2946}
2947
2948void
2949TraCIAPI::VehicleScope::setStop(const std::string vehicleID, const std::string edgeID, const double endPos, const int laneIndex,
2950 const double duration, const int flags, const double startPos, const double until) const {
2951 tcpip::Storage content;
2953 content.writeInt(7);
2955 content.writeString(edgeID);
2957 content.writeDouble(endPos);
2959 content.writeByte(laneIndex);
2961 content.writeDouble(duration);
2963 content.writeByte(flags);
2965 content.writeDouble(startPos);
2967 content.writeDouble(until);
2968 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_STOP, vehicleID, &content);
2969 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2970}
2971
2972void
2973TraCIAPI::VehicleScope::setType(const std::string& vehicleID, const std::string& typeID) const {
2974 tcpip::Storage content;
2976 content.writeString(typeID);
2977 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_TYPE, vehicleID, &content);
2978 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2979}
2980
2981void
2982TraCIAPI::VehicleScope::setSpeedFactor(const std::string& vehicleID, double factor) const {
2983 tcpip::Storage content;
2985 content.writeDouble(factor);
2986 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SPEED_FACTOR, vehicleID, &content);
2987 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2988}
2989
2990void
2991TraCIAPI::VehicleScope::setMinGap(const std::string& vehicleID, double minGap) const {
2992 tcpip::Storage content;
2994 content.writeDouble(minGap);
2995 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MINGAP, vehicleID, &content);
2996 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
2997}
2998
2999void
3000TraCIAPI::VehicleScope::setMaxSpeed(const std::string& vehicleID, double speed) const {
3001 tcpip::Storage content;
3003 content.writeDouble(speed);
3004 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_MAXSPEED, vehicleID, &content);
3005 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3006}
3007
3008void
3009TraCIAPI::VehicleScope::setColor(const std::string& vehicleID, const libsumo::TraCIColor& c) const {
3010 tcpip::Storage content;
3012 content.writeUnsignedByte(c.r);
3013 content.writeUnsignedByte(c.g);
3014 content.writeUnsignedByte(c.b);
3015 content.writeUnsignedByte(c.a);
3016 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_COLOR, vehicleID, &content);
3017 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3018}
3019
3020void
3021TraCIAPI::VehicleScope::setLine(const std::string& vehicleID, const std::string& line) const {
3022 tcpip::Storage content;
3024 content.writeString(line);
3025 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_LINE, vehicleID, &content);
3026 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3027}
3028
3029void
3030TraCIAPI::VehicleScope::setVia(const std::string& vehicleID, const std::vector<std::string>& via) const {
3031 tcpip::Storage content;
3033 content.writeInt((int)via.size());
3034 for (int i = 0; i < (int)via.size(); ++i) {
3035 content.writeString(via[i]);
3036 }
3037 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_VIA, vehicleID, &content);
3038 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3039}
3040
3041void
3042TraCIAPI::VehicleScope::setSignals(const std::string& vehicleID, int signals) const {
3043 tcpip::Storage content;
3045 content.writeInt(signals);
3046 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SIGNALS, vehicleID, &content);
3047 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3048}
3049
3050void
3051TraCIAPI::VehicleScope::setRoutingMode(const std::string& vehicleID, int routingMode) const {
3052 tcpip::Storage content;
3054 content.writeInt(routingMode);
3055 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_ROUTING_MODE, vehicleID, &content);
3056 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3057}
3058
3059void
3060TraCIAPI::VehicleScope::setShapeClass(const std::string& vehicleID, const std::string& clazz) const {
3061 tcpip::Storage content;
3063 content.writeString(clazz);
3064 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_SHAPECLASS, vehicleID, &content);
3065 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3066}
3067
3068
3069void
3070TraCIAPI::VehicleScope::setEmissionClass(const std::string& vehicleID, const std::string& clazz) const {
3071 tcpip::Storage content;
3073 content.writeString(clazz);
3074 myParent.createCommand(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::VAR_EMISSIONCLASS, vehicleID, &content);
3075 myParent.processSet(libsumo::CMD_SET_VEHICLE_VARIABLE);
3076}
3077
3078void
3080 bool noOpposite, double downstreamDist, double upstreamDist) const {
3081 addSubscriptionFilterByteList(libsumo::FILTER_TYPE_LANES, lanes);
3082 if (noOpposite) {
3083 addSubscriptionFilterNoOpposite();
3084 }
3085 if (downstreamDist >= 0) {
3086 addSubscriptionFilterDownstreamDistance(downstreamDist);
3087 }
3088 if (upstreamDist >= 0) {
3089 addSubscriptionFilterUpstreamDistance(upstreamDist);
3090 }
3091}
3092
3093
3094void
3098
3099void
3103
3104void
3106 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_UPSTREAM_DIST, dist);
3107}
3108
3109
3110void
3111TraCIAPI::VehicleScope::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) const {
3112 addSubscriptionFilterLeadFollow(std::vector<int>({0}));
3113 if (downstreamDist >= 0) {
3114 addSubscriptionFilterDownstreamDistance(downstreamDist);
3115 }
3116 if (upstreamDist >= 0) {
3117 addSubscriptionFilterUpstreamDistance(upstreamDist);
3118 }
3119}
3120
3121void
3122TraCIAPI::VehicleScope::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) const {
3123 if (abs(direction) != 1) {
3124 std::cerr << "Ignoring lane change subscription filter with non-neighboring lane offset direction " << direction << "\n";
3125 return;
3126 }
3127 addSubscriptionFilterLeadFollow(std::vector<int>({0, direction}));
3128 if (noOpposite) {
3129 addSubscriptionFilterNoOpposite();
3130 }
3131 if (downstreamDist >= 0) {
3132 addSubscriptionFilterDownstreamDistance(downstreamDist);
3133 }
3134 if (upstreamDist >= 0) {
3135 addSubscriptionFilterUpstreamDistance(upstreamDist);
3136 }
3137}
3138
3139void
3141 addSubscriptionFilterEmpty(libsumo::FILTER_TYPE_LEAD_FOLLOW);
3142 addSubscriptionFilterByteList(libsumo::FILTER_TYPE_LANES, lanes);
3143}
3144
3145void
3146TraCIAPI::VehicleScope::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) const {
3147 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_TURN, foeDistToJunction);
3148 if (downstreamDist >= 0) {
3149 addSubscriptionFilterDownstreamDistance(downstreamDist);
3150 }
3151}
3152
3153
3154void
3155TraCIAPI::VehicleScope::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) const {
3156 addSubscriptionFilterStringList(libsumo::FILTER_TYPE_VCLASS, vClasses);
3157}
3158
3159
3160void
3161TraCIAPI::VehicleScope::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) const {
3162 addSubscriptionFilterStringList(libsumo::FILTER_TYPE_VTYPE, vTypes);
3163}
3164
3165
3166void
3168 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_FIELD_OF_VISION, angle);
3169}
3170
3171void
3172TraCIAPI::VehicleScope::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) const {
3173 addSubscriptionFilterFloat(libsumo::FILTER_TYPE_LATERAL_DIST, lateralDist);
3174 if (downstreamDist >= 0) {
3175 addSubscriptionFilterDownstreamDistance(downstreamDist);
3176 }
3177 if (upstreamDist >= 0) {
3178 addSubscriptionFilterUpstreamDistance(upstreamDist);
3179 }
3180}
3181
3182void
3184 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType);
3185 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3186}
3187
3188void
3190 tcpip::Storage content;
3192 content.writeDouble(val);
3193 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3194 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3195}
3196
3197
3198void
3199TraCIAPI::VehicleScope::addSubscriptionFilterStringList(int filterType, const std::vector<std::string>& vals) const {
3200 tcpip::Storage content;
3202 content.writeStringList(vals);
3203 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3204 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3205}
3206
3207
3208void
3209TraCIAPI::VehicleScope::addSubscriptionFilterByteList(int filterType, const std::vector<int>& vals) const {
3210 tcpip::Storage content;
3211 content.writeUnsignedByte((int)vals.size());
3212 for (int i : vals) {
3213 content.writeByte(i);
3214 }
3215 myParent.createFilterCommand(libsumo::CMD_ADD_SUBSCRIPTION_FILTER, filterType, &content);
3216 myParent.processSet(libsumo::CMD_ADD_SUBSCRIPTION_FILTER);
3217}
3218
3219
3220// ---------------------------------------------------------------------------
3221// TraCIAPI::PersonScope-methods
3222// ---------------------------------------------------------------------------
3223double
3224TraCIAPI::PersonScope::getSpeed(const std::string& personID) const {
3225 return getDouble(libsumo::VAR_SPEED, personID);
3226}
3227
3229TraCIAPI::PersonScope::getPosition(const std::string& personID) const {
3230 return getPos(libsumo::VAR_POSITION, personID);
3231}
3232
3234TraCIAPI::PersonScope::getPosition3D(const std::string& personID) const {
3235 return getPos3D(libsumo::VAR_POSITION3D, personID);
3236}
3237
3238double
3239TraCIAPI::PersonScope::getAngle(const std::string& personID) const {
3240 return getDouble(libsumo::VAR_ANGLE, personID);
3241}
3242
3243double
3244TraCIAPI::PersonScope::getSlope(const std::string& personID) const {
3245 return getDouble(libsumo::VAR_SLOPE, personID);
3246}
3247
3248double
3249TraCIAPI::PersonScope::getLanePosition(const std::string& personID) const {
3250 return getDouble(libsumo::VAR_LANEPOSITION, personID);
3251}
3252
3254TraCIAPI::PersonScope::getColor(const std::string& personID) const {
3255 return getCol(libsumo::VAR_COLOR, personID);
3256}
3257
3258double
3259TraCIAPI::PersonScope::getLength(const std::string& personID) const {
3260 return getDouble(libsumo::VAR_LENGTH, personID);
3261}
3262
3263std::string
3264TraCIAPI::PersonScope::getRoadID(const std::string& personID) const {
3265 return getString(libsumo::VAR_ROAD_ID, personID);
3266}
3267
3268std::string
3269TraCIAPI::PersonScope::getLaneID(const std::string& personID) const {
3270 return getString(libsumo::VAR_LANE_ID, personID);
3271}
3272
3273std::string
3274TraCIAPI::PersonScope::getTypeID(const std::string& personID) const {
3275 return getString(libsumo::VAR_TYPE, personID);
3276}
3277
3278double
3279TraCIAPI::PersonScope::getSpeedFactor(const std::string& personID) const {
3280 return getDouble(libsumo::VAR_SPEED_FACTOR, personID);
3281}
3282
3283double
3284TraCIAPI::PersonScope::getWaitingTime(const std::string& personID) const {
3285 return getDouble(libsumo::VAR_WAITING_TIME, personID);
3286}
3287
3288std::string
3289TraCIAPI::PersonScope::getNextEdge(const std::string& personID) const {
3290 return getString(libsumo::VAR_NEXT_EDGE, personID);
3291}
3292
3293
3294std::string
3295TraCIAPI::PersonScope::getVehicle(const std::string& personID) const {
3296 return getString(libsumo::VAR_VEHICLE, personID);
3297}
3298
3299int
3300TraCIAPI::PersonScope::getRemainingStages(const std::string& personID) const {
3301 return getInt(libsumo::VAR_STAGES_REMAINING, personID);
3302}
3303
3305TraCIAPI::PersonScope::getStage(const std::string& personID, int nextStageIndex) const {
3306 tcpip::Storage content;
3308 content.writeInt(nextStageIndex);
3309 return getTraCIStage(libsumo::VAR_STAGE, personID, &content);
3310}
3311
3312std::vector<std::string>
3313TraCIAPI::PersonScope::getEdges(const std::string& personID, int nextStageIndex) const {
3314 tcpip::Storage content;
3316 content.writeInt(nextStageIndex);
3317 return getStringVector(libsumo::VAR_EDGES, personID, &content);
3318}
3319
3320void
3321TraCIAPI::PersonScope::removeStages(const std::string& personID) const {
3322 // remove all stages after the current and then abort the current stage
3323 while (getRemainingStages(personID) > 1) {
3324 removeStage(personID, 1);
3325 }
3326 removeStage(personID, 0);
3327}
3328
3329
3330void
3331TraCIAPI::PersonScope::rerouteTraveltime(const std::string& personID) const {
3332 tcpip::Storage content;
3334 content.writeInt(0);
3335 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::CMD_REROUTE_TRAVELTIME, personID, &content);
3336 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3337}
3338
3339
3340void
3341TraCIAPI::PersonScope::add(const std::string& personID, const std::string& edgeID, double pos, double depart, const std::string typeID) {
3342 tcpip::Storage content;
3344 content.writeInt(4);
3346 content.writeString(typeID);
3348 content.writeString(edgeID);
3350 content.writeDouble(depart);
3352 content.writeDouble(pos);
3353 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::ADD, personID, &content);
3354 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3355}
3356
3357void
3358TraCIAPI::PersonScope::appendStage(const std::string& personID, const libsumo::TraCIStage& stage) {
3359 tcpip::Storage content;
3361 content.writeInt(13);
3363 content.writeInt(stage.type);
3365 content.writeString(stage.vType);
3367 content.writeString(stage.line);
3369 content.writeString(stage.destStop);
3371 content.writeStringList(stage.edges);
3373 content.writeDouble(stage.travelTime);
3375 content.writeDouble(stage.cost);
3377 content.writeDouble(stage.length);
3379 content.writeString(stage.intended);
3381 content.writeDouble(stage.depart);
3383 content.writeDouble(stage.departPos);
3385 content.writeDouble(stage.arrivalPos);
3387 content.writeString(stage.description);
3388 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3389 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3390}
3391
3392
3393void
3394TraCIAPI::PersonScope::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
3395 tcpip::Storage content;
3397 content.writeInt(4);
3401 content.writeDouble(duration);
3403 content.writeString(description);
3405 content.writeString(stopID);
3406 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3407 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3408}
3409
3410void
3411TraCIAPI::PersonScope::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
3412 tcpip::Storage content;
3414 content.writeInt(6);
3418 content.writeStringList(edges);
3420 content.writeDouble(arrivalPos);
3422 content.writeDouble(duration);
3424 content.writeDouble(speed);
3426 content.writeString(stopID);
3427 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3428 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3429}
3430
3431void
3432TraCIAPI::PersonScope::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
3433 tcpip::Storage content;
3435 content.writeInt(4);
3439 content.writeString(toEdge);
3441 content.writeString(lines);
3443 content.writeString(stopID);
3444 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::APPEND_STAGE, personID, &content);
3445 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3446}
3447
3448void
3449TraCIAPI::PersonScope::removeStage(const std::string& personID, int nextStageIndex) const {
3450 tcpip::Storage content;
3452 content.writeInt(nextStageIndex);
3453 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::REMOVE_STAGE, personID, &content);
3454 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3455}
3456
3457void
3458TraCIAPI::PersonScope::moveTo(const std::string& personID, const std::string& edgeID, double position) const {
3459 tcpip::Storage content;
3461 content.writeInt(2);
3463 content.writeString(edgeID);
3465 content.writeDouble(position);
3466 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_MOVE_TO, personID, &content);
3467 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3468}
3469
3470void
3471TraCIAPI::PersonScope::moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute) const {
3472 tcpip::Storage content;
3474 content.writeInt(5);
3476 content.writeString(edgeID);
3478 content.writeDouble(x);
3480 content.writeDouble(y);
3482 content.writeDouble(angle);
3484 content.writeByte(keepRoute);
3485 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::MOVE_TO_XY, personID, &content);
3486 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3487}
3488
3489void
3490TraCIAPI::PersonScope::setSpeed(const std::string& personID, double speed) const {
3491 tcpip::Storage content;
3493 content.writeDouble(speed);
3494 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_SPEED, personID, &content);
3495 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3496}
3497
3498
3499void
3500TraCIAPI::PersonScope::setType(const std::string& personID, const std::string& typeID) const {
3501 tcpip::Storage content;
3503 content.writeString(typeID);
3504 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_TYPE, personID, &content);
3505 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3506}
3507
3508void
3509TraCIAPI::PersonScope::setSpeedFactor(const std::string& personID, double factor) const {
3510 tcpip::Storage content;
3512 content.writeDouble(factor);
3513 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_SPEED_FACTOR, personID, &content);
3514 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3515}
3516
3517void
3518TraCIAPI::PersonScope::setLength(const std::string& personID, double length) const {
3519 tcpip::Storage content;
3521 content.writeDouble(length);
3522 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_LENGTH, personID, &content);
3523 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3524}
3525
3526
3527void
3528TraCIAPI::PersonScope::setWidth(const std::string& personID, double width) const {
3529 tcpip::Storage content;
3531 content.writeDouble(width);
3532 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_WIDTH, personID, &content);
3533 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3534}
3535
3536void
3537TraCIAPI::PersonScope::setHeight(const std::string& personID, double height) const {
3538 tcpip::Storage content;
3540 content.writeDouble(height);
3541 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_HEIGHT, personID, &content);
3542 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3543}
3544
3545void
3546TraCIAPI::PersonScope::setMinGap(const std::string& personID, double minGap) const {
3547 tcpip::Storage content;
3549 content.writeDouble(minGap);
3550 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_MINGAP, personID, &content);
3551 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3552}
3553
3554
3555void
3556TraCIAPI::PersonScope::setColor(const std::string& personID, const libsumo::TraCIColor& c) const {
3557 tcpip::Storage content;
3559 content.writeUnsignedByte(c.r);
3560 content.writeUnsignedByte(c.g);
3561 content.writeUnsignedByte(c.b);
3562 content.writeUnsignedByte(c.a);
3563 myParent.createCommand(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::VAR_COLOR, personID, &content);
3564 myParent.processSet(libsumo::CMD_SET_PERSON_VARIABLE);
3565}
3566
3567
3568// ---------------------------------------------------------------------------
3569// TraCIAPI::TraCIScopeWrapper-methods
3570// ---------------------------------------------------------------------------
3571
3572int
3573TraCIAPI::TraCIScopeWrapper::getUnsignedByte(int var, const std::string& id, tcpip::Storage* add) const {
3574 myParent.createCommand(myCmdGetID, var, id, add);
3575 if (myParent.processGet(myCmdGetID, libsumo::TYPE_UBYTE)) {
3576 return myParent.myInput.readUnsignedByte();
3577 }
3579}
3580
3581
3582int
3583TraCIAPI::TraCIScopeWrapper::getByte(int var, const std::string& id, tcpip::Storage* add) const {
3584 myParent.createCommand(myCmdGetID, var, id, add);
3585 if (myParent.processGet(myCmdGetID, libsumo::TYPE_BYTE)) {
3586 return myParent.myInput.readByte();
3587 }
3589}
3590
3591
3592
3593int
3594TraCIAPI::TraCIScopeWrapper::getInt(int var, const std::string& id, tcpip::Storage* add) const {
3595 myParent.createCommand(myCmdGetID, var, id, add);
3596 if (myParent.processGet(myCmdGetID, libsumo::TYPE_INTEGER)) {
3597 return myParent.myInput.readInt();
3598 }
3600}
3601
3602
3603double
3604TraCIAPI::TraCIScopeWrapper::getDouble(int var, const std::string& id, tcpip::Storage* add) const {
3605 myParent.createCommand(myCmdGetID, var, id, add);
3606 if (myParent.processGet(myCmdGetID, libsumo::TYPE_DOUBLE)) {
3607 return myParent.myInput.readDouble();
3608 }
3610}
3611
3612
3614TraCIAPI::TraCIScopeWrapper::getPolygon(int var, const std::string& id, tcpip::Storage* add) const {
3616 myParent.createCommand(myCmdGetID, var, id, add);
3617 if (myParent.processGet(myCmdGetID, libsumo::TYPE_POLYGON)) {
3618 int size = myParent.myInput.readUnsignedByte();
3619 if (size == 0) {
3620 size = myParent.myInput.readInt();
3621 }
3622 for (int i = 0; i < size; ++i) {
3624 p.x = myParent.myInput.readDouble();
3625 p.y = myParent.myInput.readDouble();
3626 p.z = 0.;
3627 ret.value.push_back(p);
3628 }
3629 }
3630 return ret;
3631}
3632
3633
3635TraCIAPI::TraCIScopeWrapper::getPos(int var, const std::string& id, tcpip::Storage* add) const {
3637 myParent.createCommand(myCmdGetID, var, id, add);
3638 if (myParent.processGet(myCmdGetID, libsumo::POSITION_2D)) {
3639 p.x = myParent.myInput.readDouble();
3640 p.y = myParent.myInput.readDouble();
3641 p.z = 0;
3642 }
3643 return p;
3644}
3645
3646
3648TraCIAPI::TraCIScopeWrapper::getPos3D(int var, const std::string& id, tcpip::Storage* add) const {
3650 myParent.createCommand(myCmdGetID, var, id, add);
3651 if (myParent.processGet(myCmdGetID, libsumo::POSITION_3D)) {
3652 p.x = myParent.myInput.readDouble();
3653 p.y = myParent.myInput.readDouble();
3654 p.z = myParent.myInput.readDouble();
3655 }
3656 return p;
3657}
3658
3659
3660std::string
3661TraCIAPI::TraCIScopeWrapper::getString(int var, const std::string& id, tcpip::Storage* add) const {
3662 myParent.createCommand(myCmdGetID, var, id, add);
3663 if (myParent.processGet(myCmdGetID, libsumo::TYPE_STRING)) {
3664 return myParent.myInput.readString();
3665 }
3666 return "";
3667}
3668
3669
3670std::vector<std::string>
3671TraCIAPI::TraCIScopeWrapper::getStringVector(int var, const std::string& id, tcpip::Storage* add) const {
3672 std::vector<std::string> r;
3673 myParent.createCommand(myCmdGetID, var, id, add);
3674 if (myParent.processGet(myCmdGetID, libsumo::TYPE_STRINGLIST)) {
3675 const int size = myParent.myInput.readInt();
3676 for (int i = 0; i < size; ++i) {
3677 r.push_back(myParent.myInput.readString());
3678 }
3679 }
3680 return r;
3681}
3682
3683
3684std::vector<double>
3685TraCIAPI::TraCIScopeWrapper::getDoubleVector(int var, const std::string& id, tcpip::Storage* add) const {
3686 std::vector<double> r;
3687 myParent.createCommand(myCmdGetID, var, id, add);
3688 if (myParent.processGet(myCmdGetID, libsumo::TYPE_DOUBLELIST)) {
3689 const int size = myParent.myInput.readInt();
3690 for (int i = 0; i < size; ++i) {
3691 r.push_back(myParent.myInput.readDouble());
3692 }
3693 }
3694 return r;
3695}
3696
3697
3699TraCIAPI::TraCIScopeWrapper::getCol(int var, const std::string& id, tcpip::Storage* add) const {
3701 myParent.createCommand(myCmdGetID, var, id, add);
3702 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COLOR)) {
3703 c.r = (unsigned char)myParent.myInput.readUnsignedByte();
3704 c.g = (unsigned char)myParent.myInput.readUnsignedByte();
3705 c.b = (unsigned char)myParent.myInput.readUnsignedByte();
3706 c.a = (unsigned char)myParent.myInput.readUnsignedByte();
3707 }
3708 return c;
3709}
3710
3711
3713TraCIAPI::TraCIScopeWrapper::getTraCIStage(int var, const std::string& id, tcpip::Storage* add) const {
3715 myParent.createCommand(myCmdGetID, var, id, add);
3716 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COMPOUND)) {
3717 myParent.myInput.readInt(); // components
3718 myParent.myInput.readUnsignedByte();
3719 s.type = myParent.myInput.readInt();
3720
3721 myParent.myInput.readUnsignedByte();
3722 s.vType = myParent.myInput.readString();
3723
3724 myParent.myInput.readUnsignedByte();
3725 s.line = myParent.myInput.readString();
3726
3727 myParent.myInput.readUnsignedByte();
3728 s.destStop = myParent.myInput.readString();
3729
3730 myParent.myInput.readUnsignedByte();
3731 s.edges = myParent.myInput.readStringList();
3732
3733 myParent.myInput.readUnsignedByte();
3734 s.travelTime = myParent.myInput.readDouble();
3735
3736 myParent.myInput.readUnsignedByte();
3737 s.cost = myParent.myInput.readDouble();
3738
3739 myParent.myInput.readUnsignedByte();
3740 s.length = myParent.myInput.readDouble();
3741
3742 myParent.myInput.readUnsignedByte();
3743 s.intended = myParent.myInput.readString();
3744
3745 myParent.myInput.readUnsignedByte();
3746 s.depart = myParent.myInput.readDouble();
3747
3748 myParent.myInput.readUnsignedByte();
3749 s.departPos = myParent.myInput.readDouble();
3750
3751 myParent.myInput.readUnsignedByte();
3752 s.arrivalPos = myParent.myInput.readDouble();
3753
3754 myParent.myInput.readUnsignedByte();
3755 s.description = myParent.myInput.readString();
3756 }
3757 return s;
3758}
3759
3760
3761std::vector<std::string>
3763 return getStringVector(libsumo::TRACI_ID_LIST, "");
3764}
3765
3766
3767int
3769 return getInt(libsumo::ID_COUNT, "");
3770}
3771
3772
3773std::string
3774TraCIAPI::TraCIScopeWrapper::getParameter(const std::string& objectID, const std::string& key) const {
3775 tcpip::Storage content;
3777 content.writeString(key);
3778 return getString(libsumo::VAR_PARAMETER, objectID, &content);
3779}
3780
3781
3782std::pair<std::string, std::string>
3783TraCIAPI::TraCIScopeWrapper::getParameterWithKey(const std::string& objectID, const std::string& key) const {
3784 tcpip::Storage content;
3786 content.writeString(key);
3787
3788 myParent.createCommand(myCmdGetID, libsumo::VAR_PARAMETER_WITH_KEY, objectID, &content);
3789 if (myParent.processGet(myCmdGetID, libsumo::TYPE_COMPOUND)) {
3790 myParent.myInput.readInt(); // number of components
3791 myParent.myInput.readUnsignedByte();
3792 const std::string returnedKey = myParent.myInput.readString();
3793 myParent.myInput.readUnsignedByte();
3794 const std::string value = myParent.myInput.readString();
3795 return std::make_pair(returnedKey, value);
3796 }
3797 return std::make_pair(key, "");
3798}
3799
3800
3801void
3802TraCIAPI::TraCIScopeWrapper::setParameter(const std::string& objectID, const std::string& key, const std::string& value) const {
3803 tcpip::Storage content;
3805 content.writeInt(2);
3807 content.writeString(key);
3809 content.writeString(value);
3810 myParent.createCommand(myCmdSetID, libsumo::VAR_PARAMETER, objectID, &content);
3811 myParent.processSet(myCmdSetID);
3812}
3813
3814
3815void
3816TraCIAPI::TraCIScopeWrapper::setInt(int var, const std::string& id, int value) const {
3817 tcpip::Storage content;
3819 content.writeInt(value);
3820 myParent.createCommand(myCmdSetID, var, id, &content);
3821 myParent.processSet(myCmdSetID);
3822}
3823
3824
3825void
3826TraCIAPI::TraCIScopeWrapper::setDouble(int var, const std::string& id, double value) const {
3827 tcpip::Storage content;
3829 content.writeDouble(value);
3830 myParent.createCommand(myCmdSetID, var, id, &content);
3831 myParent.processSet(myCmdSetID);
3832}
3833
3834
3835void
3836TraCIAPI::TraCIScopeWrapper::setString(int var, const std::string& id, const std::string& value) const {
3837 tcpip::Storage content;
3839 content.writeString(value);
3840 myParent.createCommand(myCmdSetID, var, id, &content);
3841 myParent.processSet(myCmdSetID);
3842}
3843
3844
3845void
3846TraCIAPI::TraCIScopeWrapper::setStringVector(int var, const std::string& id, const std::vector<std::string>& value) const {
3847 tcpip::Storage content;
3849 content.writeInt((int)value.size());
3850 for (const std::string& s : value) {
3851 content.writeString(s);
3852 }
3853 myParent.createCommand(myCmdSetID, var, id, &content);
3854 myParent.processSet(myCmdSetID);
3855}
3856
3857
3858void
3859TraCIAPI::TraCIScopeWrapper::subscribe(const std::string& objID, const std::vector<int>& vars, double beginTime, double endTime) const {
3860 myParent.send_commandSubscribeObjectVariable(mySubscribeID, objID, beginTime, endTime, vars);
3861 tcpip::Storage inMsg;
3862 myParent.check_resultState(inMsg, mySubscribeID);
3863 if (vars.size() > 0) {
3864 myParent.check_commandGetResult(inMsg, mySubscribeID);
3865 myParent.readVariableSubscription(mySubscribeID + 0x10, inMsg);
3866 }
3867}
3868
3869
3870void
3871TraCIAPI::TraCIScopeWrapper::subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars, double beginTime, double endTime) const {
3872 myParent.send_commandSubscribeObjectContext(myContextSubscribeID, objID, beginTime, endTime, domain, range, vars);
3873 tcpip::Storage inMsg;
3874 myParent.check_resultState(inMsg, myContextSubscribeID);
3875 myParent.check_commandGetResult(inMsg, myContextSubscribeID);
3876 myParent.readContextSubscription(myContextSubscribeID + 0x60, inMsg);
3877}
3878
3879
3882 return mySubscriptionResults;
3883}
3884
3885
3888 if (mySubscriptionResults.find(objID) != mySubscriptionResults.end()) {
3889 return mySubscriptionResults.find(objID)->second;
3890 } else {
3891 return libsumo::TraCIResults();
3892 }
3893}
3894
3895
3898 return myContextSubscriptionResults;
3899}
3900
3901
3904 if (myContextSubscriptionResults.find(objID) != myContextSubscriptionResults.end()) {
3905 return myContextSubscriptionResults.find(objID)->second;
3906 } else {
3908 }
3909}
3910
3911
3912void
3914 mySubscriptionResults.clear();
3915 myContextSubscriptionResults.clear();
3916}
3917
3918
3921 return mySubscriptionResults;
3922}
3923
3924
3927 return myContextSubscriptionResults[objID];
3928}
3929
3930
3931/****************************************************************************/
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
void setHeight(const std::string &polygonID, const double height) const
libsumo::TraCIColor getColor(const std::string &polygonID) const
void setType(const std::string &polygonID, const std::string &setType) const
bool getFilled(const std::string &polygonID) const
double getHeight(const std::string &polygonID) const
void add(const std::string &polygonID, const libsumo::TraCIPositionVector &shape, const libsumo::TraCIColor &c, bool fill, const std::string &type, int layer) const
libsumo::TraCIPositionVector getShape(const std::string &polygonID) const
std::string getType(const std::string &polygonID) const
void remove(const std::string &polygonID, int layer=0) const
double getLineWidth(const std::string &polygonID) const
void setColor(const std::string &polygonID, const libsumo::TraCIColor &c) const
void setLineWidth(const std::string &polygonID, const double lineWidth) const
void setShape(const std::string &polygonID, const libsumo::TraCIPositionVector &shape) const
std::vector< std::string > getEdges(const std::string &routeID) const
void add(const std::string &routeID, const std::vector< std::string > &edges) const
double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo=false, bool isDriving=false)
libsumo::TraCIPosition convert2D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false) const
std::vector< std::string > getStartingTeleportIDList() const
int getStartingTeleportNumber() const
int getEndingTeleportNumber() const
int getBusStopWaiting(const std::string &stopID) const
libsumo::TraCIStage findRoute(const std::string &fromEdge, const std::string &toEdge, const std::string &vType="", double pos=-1., int routingMode=0) const
libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo=false, const std::string &vClass="ignoring") const
void loadState(const std::string &path) const
std::vector< std::string > getBusStopWaitingIDList(const std::string &stopID) const
int getDepartedPersonNumber() const
double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
std::vector< std::string > getArrivedPersonIDList() const
void saveState(const std::string &destination) const
std::vector< std::string > getEndingTeleportIDList() const
int getMinExpectedNumber() const
std::vector< std::string > getDepartedPersonIDList() const
std::vector< std::string > getDepartedIDList() const
int getArrivedPersonNumber() const
std::vector< std::string > getLoadedIDList() const
std::vector< std::string > getArrivedIDList() const
std::string getOption(const std::string &option) const
libsumo::TraCIPositionVector getNetBoundary() const
void writeMessage(const std::string msg)
libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo=false) const
libsumo::TraCIPosition convert3D(const std::string &edgeID, double pos, int laneIndex=0, bool toGeo=false) const
int getUnsignedByte(int var, const std::string &id, tcpip::Storage *add=0) const
const libsumo::SubscriptionResults getContextSubscriptionResults(const std::string &objID) const
int getInt(int var, const std::string &id, tcpip::Storage *add=0) const
std::vector< std::string > getStringVector(int var, const std::string &id, tcpip::Storage *add=0) const
double getDouble(int var, const std::string &id, tcpip::Storage *add=0) const
libsumo::TraCIPosition getPos3D(int var, const std::string &id, tcpip::Storage *add=0) const
std::pair< std::string, std::string > getParameterWithKey(const std::string &objectID, const std::string &key) const
retrieve generic parameter and return (key, value) tuple
libsumo::TraCIColor getCol(int var, const std::string &id, tcpip::Storage *add=0) const
const libsumo::SubscriptionResults getAllSubscriptionResults() const
void setStringVector(int var, const std::string &id, const std::vector< std::string > &value) const
std::vector< std::string > getIDList() const
libsumo::TraCIPositionVector getPolygon(int var, const std::string &id, tcpip::Storage *add=0) const
libsumo::SubscriptionResults & getModifiableSubscriptionResults()
const libsumo::TraCIResults getSubscriptionResults(const std::string &objID) const
void setString(int var, const std::string &id, const std::string &value) const
void subscribeContext(const std::string &objID, int domain, double range, const std::vector< int > &vars, double beginTime, double endTime) const
void setParameter(const std::string &objectID, const std::string &key, const std::string &value) const
set generic paramter
std::string getParameter(const std::string &objectID, const std::string &key) const
retrieve generic parameter
std::vector< double > getDoubleVector(int var, const std::string &id, tcpip::Storage *add=0) const
void setInt(int var, const std::string &id, int value) const
int getByte(int var, const std::string &id, tcpip::Storage *add=0) const
libsumo::TraCIStage getTraCIStage(int var, const std::string &id, tcpip::Storage *add=0) const
void subscribe(const std::string &objID, const std::vector< int > &vars, double beginTime, double endTime) const
std::string getString(int var, const std::string &id, tcpip::Storage *add=0) const
libsumo::TraCIPosition getPos(int var, const std::string &id, tcpip::Storage *add=0) const
const libsumo::ContextSubscriptionResults getAllContextSubscriptionResults() const
libsumo::SubscriptionResults & getModifiableContextSubscriptionResults(const std::string &objID)
void setDouble(int var, const std::string &id, double value) const
int getServedPersonCount(const std::string &tlsID, int index) const
std::string getRedYellowGreenState(const std::string &tlsID) const
int getPhase(const std::string &tlsID) const
std::string getPhaseName(const std::string &tlsID) const
void setRedYellowGreenState(const std::string &tlsID, const std::string &state) const
std::string getProgram(const std::string &tlsID) const
void setPhase(const std::string &tlsID, int index) const
void setPhaseName(const std::string &tlsID, const std::string &name) const
double getNextSwitch(const std::string &tlsID) const
std::vector< std::vector< libsumo::TraCILink > > getControlledLinks(const std::string &tlsID) const
double getPhaseDuration(const std::string &tlsID) const
std::vector< std::string > getControlledLanes(const std::string &tlsID) const
std::vector< libsumo::TraCILogic > getAllProgramLogics(const std::string &tlsID) const
void setPhaseDuration(const std::string &tlsID, double phaseDuration) const
void setProgramLogic(const std::string &tlsID, const libsumo::TraCILogic &logic) const
void setProgram(const std::string &tlsID, const std::string &programID) const
std::vector< libsumo::TraCINextTLSData > getNextTLS(const std::string &vehID) const
void changeLane(const std::string &vehicleID, int laneIndex, double duration) const
void setMinGap(const std::string &vehicleID, double minGap) const
double getLateralSpeed(const std::string &vehicleID) const
void setMaxSpeed(const std::string &vehicleID, double speed) const
void setPreviousSpeed(const std::string &vehicleID, double prevSpeed, double prevAcceleration=std::numeric_limits< int >::min()) const
double getSpeed(const std::string &vehicleID) const
int getStopState(const std::string &vehicleID) const
double getWaitingTime(const std::string &vehicleID) const
void addSubscriptionFilterCFManeuver(double downstreamDist=-1, double upstreamDist=-1) const
double getCOEmission(const std::string &vehicleID) const
void addSubscriptionFilterStringList(int filterType, const std::vector< std::string > &vals) const
void changeTarget(const std::string &vehicleID, const std::string &edgeID) const
libsumo::TraCIPosition getPosition(const std::string &vehicleID) const
bool isRouteValid(const std::string &vehicleID) const
void addSubscriptionFilterByteList(int filterType, const std::vector< int > &vals) const
double getSecureGap(const std::string &vehicleID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string &leaderID="") const
void setSpeedFactor(const std::string &vehicleID, double factor) const
void setShapeClass(const std::string &vehicleID, const std::string &clazz) const
void addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist=-1, double foeDistToJunction=-1) const
void setVia(const std::string &vehicleID, const std::vector< std::string > &via) const
void setEmissionClass(const std::string &vehicleID, const std::string &clazz) const
double getTau(const std::string &vehicleID) const
double getDistance(const std::string &vehicleID) const
void remove(const std::string &vehicleID, char reason=libsumo::REMOVE_VAPORIZED) const
void openGap(const std::string &vehicleID, double newTau, double duration, double changeRate, double maxDecel) const
void moveTo(const std::string &vehicleID, const std::string &laneID, double position, int reason=libsumo::MOVE_TELEPORT) const
void setSpeed(const std::string &vehicleID, double speed) const
std::string getEmissionClass(const std::string &vehicleID) const
void setStop(const std::string vehicleID, const std::string edgeID, const double endPos=1., const int laneIndex=0, const double duration=std::numeric_limits< double >::max(), const int flags=0, const double startPos=std::numeric_limits< int >::min(), const double until=-1) const
void setRouteID(const std::string &vehicleID, const std::string &routeID) const
std::pair< int, int > getLaneChangeState(const std::string &vehicleID, int direction) const
double getNoiseEmission(const std::string &vehicleID) const
std::string getShapeClass(const std::string &vehicleID) const
void addSubscriptionFilterLeadFollow(const std::vector< int > &lanes) const
std::string getLine(const std::string &vehicleID) const
double getElectricityConsumption(const std::string &vehicleID) const
double getSpeedFactor(const std::string &vehicleID) const
double getNOxEmission(const std::string &vehicleID) const
void setRoute(const std::string &vehicleID, const std::vector< std::string > &edge) const
int getSignals(const std::string &vehicleID) const
libsumo::TraCIColor getColor(const std::string &vehicleID) const
int getPersonCapacity(const std::string &vehicleID) const
void setSignals(const std::string &vehicleID, int signals) const
std::string getRoadID(const std::string &vehicleID) const
void addSubscriptionFilterVType(const std::vector< std::string > &vTypes) const
void addSubscriptionFilterUpstreamDistance(double dist) const
void addSubscriptionFilterFloat(int filterType, double val) const
double getAllowedSpeed(const std::string &vehicleID) const
void addSubscriptionFilterLanes(const std::vector< int > &lanes, bool noOpposite=false, double downstreamDist=-1, double upstreamDist=-1) const
double getCO2Emission(const std::string &vehicleID) const
double getFuelConsumption(const std::string &vehicleID) const
double getHCEmission(const std::string &vehicleID) const
void addSubscriptionFilterNoOpposite() const
void addSubscriptionFilterLCManeuver(int direction, bool noOpposite=false, double downstreamDist=-1, double upstreamDist=-1) const
std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist) const
double getAcceleration(const std::string &vehicleID) const
std::vector< std::string > getVia(const std::string &vehicleID) const
void addSubscriptionFilterVClass(const std::vector< std::string > &vClasses) const
double getImperfection(const std::string &vehicleID) const
std::string getLaneID(const std::string &vehicleID) const
double getAngle(const std::string &vehicleID) const
void addSubscriptionFilterDownstreamDistance(double dist) const
double getMinGap(const std::string &vehicleID) const
void addSubscriptionFilterEmpty(int filterType) const
double getStopArrivalDelay(const std::string &vehicleID) const
void setAcceleration(const std::string &vehicleID, double accel, double duration) const
std::vector< std::string > getPersonIDList(const std::string &vehicleID) const
double getStopDelay(const std::string &vehicleID) const
double getMinGapLat(const std::string &vehicleID) const
void setLine(const std::string &vehicleID, const std::string &line) const
double getSlope(const std::string &vehicleID) const
void setColor(const std::string &vehicleID, const libsumo::TraCIColor &c) const
void add(const std::string &vehicleID, const std::string &routeID, const std::string &typeID="DEFAULT_VEHTYPE", std::string depart="-1", const std::string &departLane="first", const std::string &departPos="base", const std::string &departSpeed="0", const std::string &arrivalLane="current", const std::string &arrivalPos="max", const std::string &arrivalSpeed="current", const std::string &fromTaz="", const std::string &toTaz="", const std::string &line="", int personCapacity=0, int personNumber=0) const
libsumo::TraCIPosition getPosition3D(const std::string &vehicleID) const
void setLaneChangeMode(const std::string &vehicleID, int mode) const
void setRoutingMode(const std::string &vehicleID, int routingMode) const
void addSubscriptionFilterTurn(double downstreamDist=-1, double upstreamDist=-1) const
double getDecel(const std::string &vehicleID) const
void moveToXY(const std::string &vehicleID, const std::string &edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const
double getHeight(const std::string &veihcleID) const
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:853
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:962
MeMeScope multientryexit
Scope for interaction with multi-entry/-exit detectors.
Definition TraCIAPI.h:843
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition TraCIAPI.h:863
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:833
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:849
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition TraCIAPI.h:944
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:958
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:841
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:839
std::map< int, TraCIScopeWrapper * > myDomains
Definition TraCIAPI.h:956
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:859
tcpip::Storage myOutput
The reusable output storage.
Definition TraCIAPI.h:960
POIScope poi
Scope for interaction with POIs.
Definition TraCIAPI.h:847
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:861
JunctionScope junction
Scope for interaction with junctions.
Definition TraCIAPI.h:837
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:855
EdgeScope edge
Scope for interaction with edges.
Definition TraCIAPI.h:831
bool processGet(int command, int expectedType, bool ignoreCommandId=false)
Definition TraCIAPI.cpp:328
SimulationScope simulation
Scope for interaction with the simulation.
Definition TraCIAPI.h:857
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:845
RerouterScope rerouter
Scope for interaction with rerouters.
Definition TraCIAPI.h:851
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