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