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