SUMO - Simulation of Urban MObility
TraCITestClient.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2008-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
20 // A test execution class
21 /****************************************************************************/
22 /* =========================================================================
23  * included modules
24  * ======================================================================= */
25 #include <config.h>
26 
27 #include <vector>
28 #include <iostream>
29 #include <iomanip>
30 #include <fstream>
31 #include <sstream>
32 #include <ctime>
33 #include <cstdlib>
34 
35 #define BUILD_TCPIP
36 #include <foreign/tcpip/storage.h>
37 #include <foreign/tcpip/socket.h>
38 
40 #include <libsumo/TraCIDefs.h>
41 #include <utils/common/SUMOTime.h>
42 #include <utils/common/ToString.h>
43 #include "TraCITestClient.h"
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 TraCITestClient::TraCITestClient(std::string outputFileName)
50  : outputFileName(outputFileName), answerLog("") {
51  answerLog.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
52  answerLog.setf(std::ios::showpoint); // print decimal point
53  answerLog << std::setprecision(2);
54 }
55 
56 
58  writeResult();
59 }
60 
61 
62 int
63 TraCITestClient::run(std::string fileName, int port, std::string host) {
64  std::ifstream defFile;
65  std::string fileContentStr;
66  std::stringstream fileContent;
67  std::string lineCommand;
68  std::stringstream msg;
69  int repNo = 1;
70  bool commentRead = false;
71 
72  // try to connect
73  try {
74  TraCIAPI::connect(host, port);
75  } catch (tcpip::SocketException& e) {
76  std::stringstream msg;
77  msg << "#Error while connecting: " << e.what();
78  errorMsg(msg);
79  return 2;
80  }
81 
82  // read definition file and trigger commands according to it
83  defFile.open(fileName.c_str());
84  if (!defFile) {
85  msg << "Can not open definition file " << fileName << std::endl;
86  errorMsg(msg);
87  return 1;
88  }
89  defFile.unsetf(std::ios::dec);
90 
91  while (defFile >> lineCommand) {
92  repNo = 1;
93  if (lineCommand.compare("%") == 0) {
94  // a comment was read
95  commentRead = !commentRead;
96  continue;
97  }
98  if (commentRead) {
99  // wait until end of comment is reached
100  continue;
101  }
102  if (lineCommand.compare("repeat") == 0) {
103  defFile >> repNo;
104  defFile >> lineCommand;
105  }
106  if (lineCommand.compare("simstep2") == 0) {
107  // read parameter for command simulation step and trigger command
108  double time;
109  defFile >> time;
110  for (int i = 0; i < repNo; i++) {
111  commandSimulationStep(time);
112  }
113  } else if (lineCommand.compare("getvariable") == 0) {
114  // trigger command GetXXXVariable
115  int domID, varID;
116  std::string objID;
117  defFile >> domID >> varID >> objID;
118  commandGetVariable(domID, varID, objID);
119  } else if (lineCommand.compare("getvariable_plus") == 0) {
120  // trigger command GetXXXVariable with one parameter
121  int domID, varID;
122  std::string objID;
123  defFile >> domID >> varID >> objID;
124  std::stringstream msg;
125  tcpip::Storage tmp;
126  setValueTypeDependant(tmp, defFile, msg);
127  std::string msgS = msg.str();
128  if (msgS != "") {
129  errorMsg(msg);
130  }
131  commandGetVariable(domID, varID, objID, &tmp);
132  } else if (lineCommand.compare("subscribevariable") == 0) {
133  // trigger command SubscribeXXXVariable
134  int domID, varNo;
135  double beginTime, endTime;
136  std::string objID;
137  defFile >> domID >> objID >> beginTime >> endTime >> varNo;
138  commandSubscribeObjectVariable(domID, objID, beginTime, endTime, varNo, defFile);
139  } else if (lineCommand.compare("subscribecontext") == 0) {
140  // trigger command SubscribeXXXVariable
141  int domID, varNo, domain;
142  double range;
143  double beginTime, endTime;
144  std::string objID;
145  defFile >> domID >> objID >> beginTime >> endTime >> domain >> range >> varNo;
146  commandSubscribeContextVariable(domID, objID, beginTime, endTime, domain, range, varNo, defFile);
147  } else if (lineCommand.compare("setvalue") == 0) {
148  // trigger command SetXXXValue
149  int domID, varID;
150  std::string objID;
151  defFile >> domID >> varID >> objID;
152  commandSetValue(domID, varID, objID, defFile);
153  } else if (lineCommand.compare("testAPI") == 0) {
154  // call all native API methods
155  testAPI();
156  } else if (lineCommand.compare("setorder") == 0) {
157  // call setOrder
158  int order;
159  defFile >> order;
160  commandSetOrder(order);
161  } else {
162  msg << "Error in definition file: " << lineCommand << " is not a valid command";
163  errorMsg(msg);
164  commandClose();
165  closeSocket();
166  return 1;
167  }
168  }
169  defFile.close();
170  commandClose();
171  closeSocket();
172  return 0;
173 }
174 
175 
176 // ---------- Commands handling
177 void
179  try {
181  answerLog << std::endl << "-> Command sent: <SimulationStep>:" << std::endl;
182  tcpip::Storage inMsg;
183  std::string acknowledgement;
184  check_resultState(inMsg, CMD_SIMSTEP, false, &acknowledgement);
185  answerLog << acknowledgement << std::endl;
187  } catch (libsumo::TraCIException& e) {
188  answerLog << e.what() << std::endl;
189  }
190 }
191 
192 
193 void
195  try {
197  answerLog << std::endl << "-> Command sent: <Close>:" << std::endl;
198  tcpip::Storage inMsg;
199  std::string acknowledgement;
200  check_resultState(inMsg, CMD_CLOSE, false, &acknowledgement);
201  answerLog << acknowledgement << std::endl;
202  } catch (libsumo::TraCIException& e) {
203  answerLog << e.what() << std::endl;
204  }
205 }
206 
207 
208 void
210  try {
211  send_commandSetOrder(order);
212  answerLog << std::endl << "-> Command sent: <SetOrder>:" << std::endl;
213  tcpip::Storage inMsg;
214  std::string acknowledgement;
215  check_resultState(inMsg, CMD_SETORDER, false, &acknowledgement);
216  answerLog << acknowledgement << std::endl;
217  } catch (libsumo::TraCIException& e) {
218  answerLog << e.what() << std::endl;
219  }
220 }
221 
222 
223 void
224 TraCITestClient::commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData) {
225  tcpip::Storage inMsg;
226  try {
227  send_commandGetVariable(domID, varID, objID, addData);
228  answerLog << std::endl << "-> Command sent: <GetVariable>:" << std::endl
229  << " domID=" << domID << " varID=" << varID
230  << " objID=" << objID << std::endl;
231  std::string acknowledgement;
232  check_resultState(inMsg, domID, false, &acknowledgement);
233  answerLog << acknowledgement << std::endl;
234  } catch (libsumo::TraCIException& e) {
235  answerLog << e.what() << std::endl;
236  return;
237  }
238  check_commandGetResult(inMsg, domID, -1, false);
239  // report result state
240  try {
241  int variableID = inMsg.readUnsignedByte();
242  std::string objectID = inMsg.readString();
243  answerLog << " CommandID=" << (domID + 0x10) << " VariableID=" << variableID << " ObjectID=" << objectID;
244  int valueDataType = inMsg.readUnsignedByte();
245  answerLog << " valueDataType=" << valueDataType;
246  readAndReportTypeDependent(inMsg, valueDataType);
247  } catch (libsumo::TraCIException& e) {
248  std::stringstream msg;
249  msg << "Error while receiving command: " << e.what();
250  errorMsg(msg);
251  return;
252  }
253 }
254 
255 
256 void
257 TraCITestClient::commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile) {
258  std::stringstream msg;
259  tcpip::Storage inMsg, tmp;
260  setValueTypeDependant(tmp, defFile, msg);
261  std::string msgS = msg.str();
262  if (msgS != "") {
263  errorMsg(msg);
264  }
265  send_commandSetValue(domID, varID, objID, tmp);
266  answerLog << std::endl << "-> Command sent: <SetValue>:" << std::endl
267  << " domID=" << domID << " varID=" << varID
268  << " objID=" << objID << std::endl;
269  try {
270  std::string acknowledgement;
271  check_resultState(inMsg, domID, false, &acknowledgement);
272  answerLog << acknowledgement << std::endl;
273  } catch (libsumo::TraCIException& e) {
274  answerLog << e.what() << std::endl;
275  }
276 }
277 
278 
279 void
280 TraCITestClient::commandSubscribeObjectVariable(int domID, const std::string& objID, double beginTime, double endTime, int varNo, std::ifstream& defFile) {
281  std::vector<int> vars;
282  for (int i = 0; i < varNo; ++i) {
283  int var;
284  defFile >> var;
285  // variable id
286  vars.push_back(var);
287  }
288  send_commandSubscribeObjectVariable(domID, objID, beginTime, endTime, vars);
289  answerLog << std::endl << "-> Command sent: <SubscribeVariable>:" << std::endl
290  << " domID=" << domID << " objID=" << objID << " with " << varNo << " variables" << std::endl;
291  tcpip::Storage inMsg;
292  try {
293  std::string acknowledgement;
294  check_resultState(inMsg, domID, false, &acknowledgement);
295  answerLog << acknowledgement << std::endl;
296  validateSubscription(inMsg);
297  } catch (libsumo::TraCIException& e) {
298  answerLog << e.what() << std::endl;
299  }
300 }
301 
302 
303 void
304 TraCITestClient::commandSubscribeContextVariable(int domID, const std::string& objID, double beginTime, double endTime,
305  int domain, double range, int varNo, std::ifstream& defFile) {
306  std::vector<int> vars;
307  for (int i = 0; i < varNo; ++i) {
308  int var;
309  defFile >> var;
310  // variable id
311  vars.push_back(var);
312  }
313  send_commandSubscribeObjectContext(domID, objID, beginTime, endTime, domain, range, vars);
314  answerLog << std::endl << "-> Command sent: <SubscribeContext>:" << std::endl
315  << " domID=" << domID << " objID=" << objID << " domain=" << domain << " range=" << range
316  << " with " << varNo << " variables" << std::endl;
317  tcpip::Storage inMsg;
318  try {
319  std::string acknowledgement;
320  check_resultState(inMsg, domID, false, &acknowledgement);
321  answerLog << acknowledgement << std::endl;
322  validateSubscription(inMsg);
323  } catch (libsumo::TraCIException& e) {
324  answerLog << e.what() << std::endl;
325  }
326 }
327 
328 
329 // ---------- Report helper
330 void
332  time_t seconds;
333  tm* locTime;
334  std::ofstream outFile(outputFileName.c_str());
335  if (!outFile) {
336  std::cerr << "Unable to write result file" << std::endl;
337  }
338  time(&seconds);
339  locTime = localtime(&seconds);
340  outFile << "TraCITestClient output file. Date: " << asctime(locTime) << std::endl;
341  outFile << answerLog.str();
342  outFile.close();
343 }
344 
345 
346 void
347 TraCITestClient::errorMsg(std::stringstream& msg) {
348  std::cerr << msg.str() << std::endl;
349  answerLog << "----" << std::endl << msg.str() << std::endl;
350 }
351 
352 
353 
354 
355 
356 
357 bool
359  try {
360  int noSubscriptions = inMsg.readInt();
361  for (int s = 0; s < noSubscriptions; ++s) {
362  if (!validateSubscription(inMsg)) {
363  return false;
364  }
365  }
366  } catch (std::invalid_argument& e) {
367  answerLog << "#Error while reading message:" << e.what() << std::endl;
368  return false;
369  }
370  return true;
371 }
372 
373 
374 bool
376  try {
377  int length = inMsg.readUnsignedByte();
378  if (length == 0) {
379  length = inMsg.readInt();
380  }
381  int cmdId = inMsg.readUnsignedByte();
383  answerLog << " CommandID=" << cmdId;
384  answerLog << " ObjectID=" << inMsg.readString();
385  int varNo = inMsg.readUnsignedByte();
386  answerLog << " #variables=" << varNo << std::endl;
387  for (int i = 0; i < varNo; ++i) {
388  answerLog << " VariableID=" << inMsg.readUnsignedByte();
389  bool ok = inMsg.readUnsignedByte() == RTYPE_OK;
390  answerLog << " ok=" << ok;
391  int valueDataType = inMsg.readUnsignedByte();
392  answerLog << " valueDataType=" << valueDataType;
393  readAndReportTypeDependent(inMsg, valueDataType);
394  }
396  answerLog << " CommandID=" << cmdId;
397  answerLog << " ObjectID=" << inMsg.readString();
398  answerLog << " Domain=" << inMsg.readUnsignedByte();
399  int varNo = inMsg.readUnsignedByte();
400  answerLog << " #variables=" << varNo << std::endl;
401  int objNo = inMsg.readInt();
402  answerLog << " #objects=" << objNo << std::endl;
403  for (int j = 0; j < objNo; ++j) {
404  answerLog << " ObjectID=" << inMsg.readString() << std::endl;
405  for (int i = 0; i < varNo; ++i) {
406  answerLog << " VariableID=" << inMsg.readUnsignedByte();
407  bool ok = inMsg.readUnsignedByte() == RTYPE_OK;
408  answerLog << " ok=" << ok;
409  int valueDataType = inMsg.readUnsignedByte();
410  answerLog << " valueDataType=" << valueDataType;
411  readAndReportTypeDependent(inMsg, valueDataType);
412  }
413  }
414  } else {
415  answerLog << "#Error: received response with command id: " << cmdId << " but expected a subscription response (0xe0-0xef / 0x90-0x9f)" << std::endl;
416  return false;
417  }
418  } catch (std::invalid_argument& e) {
419  answerLog << "#Error while reading message:" << e.what() << std::endl;
420  return false;
421  }
422  return true;
423 }
424 
425 
426 
427 
428 
429 
430 
431 // ---------- Conversion helper
432 int
433 TraCITestClient::setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg) {
434  std::string dataTypeS;
435  defFile >> dataTypeS;
436  if (dataTypeS == "<airDist>") {
438  return 1;
439  } else if (dataTypeS == "<drivingDist>") {
441  return 1;
442  } else if (dataTypeS == "<objSubscription>") {
443  int beginTime, endTime, numVars;
444  defFile >> beginTime >> endTime >> numVars;
445  into.writeInt(beginTime);
446  into.writeInt(endTime);
447  into.writeInt(numVars);
448  for (int i = 0; i < numVars; ++i) {
449  int var;
450  defFile >> var;
451  into.writeUnsignedByte(var);
452  }
453  return 4 + 4 + 4 + numVars;
454  }
455  int valI;
456  double valF;
457  if (dataTypeS == "<int>") {
458  defFile >> valI;
460  into.writeInt(valI);
461  return 4 + 1;
462  } else if (dataTypeS == "<byte>") {
463  defFile >> valI;
465  into.writeByte(valI);
466  return 1 + 1;
467  } else if (dataTypeS == "<ubyte>") {
468  defFile >> valI;
470  into.writeUnsignedByte(valI);
471  return 1 + 1;
472  } else if (dataTypeS == "<double>") {
473  defFile >> valF;
475  into.writeDouble(valF);
476  return 8 + 1;
477  } else if (dataTypeS == "<string>") {
478  std::string valueS;
479  defFile >> valueS;
480  if (valueS == "\"\"") {
481  valueS = "";
482  }
484  into.writeString(valueS);
485  return 4 + 1 + (int) valueS.length();
486  } else if (dataTypeS == "<string*>") {
487  std::vector<std::string> slValue;
488  defFile >> valI;
489  int length = 1 + 4;
490  for (int i = 0; i < valI; ++i) {
491  std::string tmp;
492  defFile >> tmp;
493  slValue.push_back(tmp);
494  length += 4 + int(tmp.length());
495  }
497  into.writeStringList(slValue);
498  return length;
499  } else if (dataTypeS == "<compound>") {
500  defFile >> valI;
502  into.writeInt(valI);
503  int length = 1 + 4;
504  for (int i = 0; i < valI; ++i) {
505  length += setValueTypeDependant(into, defFile, msg);
506  }
507  return length;
508  } else if (dataTypeS == "<color>") {
509  defFile >> valI;
511  into.writeUnsignedByte(valI);
512  for (int i = 0; i < 3; ++i) {
513  defFile >> valI;
514  into.writeUnsignedByte(valI);
515  }
516  return 1 + 4;
517  } else if (dataTypeS == "<position2D>") {
518  defFile >> valF;
520  into.writeDouble(valF);
521  defFile >> valF;
522  into.writeDouble(valF);
523  return 1 + 8 + 8;
524  } else if (dataTypeS == "<position3D>") {
525  defFile >> valF;
527  into.writeDouble(valF);
528  defFile >> valF;
529  into.writeDouble(valF);
530  defFile >> valF;
531  into.writeDouble(valF);
532  return 1 + 8 + 8 + 8;
533  } else if (dataTypeS == "<positionRoadmap>") {
534  std::string valueS;
535  defFile >> valueS;
537  into.writeString(valueS);
538  int length = 1 + 8 + (int) valueS.length();
539  defFile >> valF;
540  into.writeDouble(valF);
541  defFile >> valI;
542  into.writeUnsignedByte(valI);
543  return length + 4 + 1;
544  } else if (dataTypeS == "<shape>") {
545  defFile >> valI;
547  into.writeUnsignedByte(valI);
548  int length = 1 + 1;
549  for (int i = 0; i < valI; ++i) {
550  double x, y;
551  defFile >> x >> y;
552  into.writeDouble(x);
553  into.writeDouble(y);
554  length += 8 + 8;
555  }
556  return length;
557  }
558  msg << "## Unknown data type: " << dataTypeS;
559  return 0;
560 }
561 
562 
563 void
565  if (valueDataType == TYPE_UBYTE) {
566  int ubyte = inMsg.readUnsignedByte();
567  answerLog << " Unsigned Byte Value: " << ubyte << std::endl;
568  } else if (valueDataType == TYPE_BYTE) {
569  int byte = inMsg.readByte();
570  answerLog << " Byte value: " << byte << std::endl;
571  } else if (valueDataType == TYPE_INTEGER) {
572  int integer = inMsg.readInt();
573  answerLog << " Int value: " << integer << std::endl;
574  } else if (valueDataType == TYPE_DOUBLE) {
575  double doublev = inMsg.readDouble();
576  answerLog << " Double value: " << doublev << std::endl;
577  } else if (valueDataType == TYPE_POLYGON) {
578  int size = inMsg.readUnsignedByte();
579  if (size == 0) {
580  size = inMsg.readInt();
581  }
582  answerLog << " PolygonValue: ";
583  for (int i = 0; i < size; i++) {
584  double x = inMsg.readDouble();
585  double y = inMsg.readDouble();
586  answerLog << "(" << x << "," << y << ") ";
587  }
588  answerLog << std::endl;
589  } else if (valueDataType == POSITION_3D) {
590  double x = inMsg.readDouble();
591  double y = inMsg.readDouble();
592  double z = inMsg.readDouble();
593  answerLog << " Position3DValue: " << std::endl;
594  answerLog << " x: " << x << " y: " << y
595  << " z: " << z << std::endl;
596  } else if (valueDataType == POSITION_ROADMAP) {
597  std::string roadId = inMsg.readString();
598  double pos = inMsg.readDouble();
599  int laneId = inMsg.readUnsignedByte();
600  answerLog << " RoadMapPositionValue: roadId=" << roadId
601  << " pos=" << pos
602  << " laneId=" << laneId << std::endl;
603  } else if (valueDataType == TYPE_STRING) {
604  std::string s = inMsg.readString();
605  answerLog << " string value: " << s << std::endl;
606  } else if (valueDataType == TYPE_STRINGLIST) {
607  std::vector<std::string> s = inMsg.readStringList();
608  answerLog << " string list value: [ " << std::endl;
609  for (std::vector<std::string>::iterator i = s.begin(); i != s.end(); ++i) {
610  if (i != s.begin()) {
611  answerLog << ", ";
612  }
613  answerLog << '"' << *i << '"';
614  }
615  answerLog << " ]" << std::endl;
616  } else if (valueDataType == TYPE_COMPOUND) {
617  int no = inMsg.readInt();
618  answerLog << " compound value with " << no << " members: [ " << std::endl;
619  for (int i = 0; i < no; ++i) {
620  int currentValueDataType = inMsg.readUnsignedByte();
621  answerLog << " valueDataType=" << currentValueDataType;
622  readAndReportTypeDependent(inMsg, currentValueDataType);
623  }
624  answerLog << " ]" << std::endl;
625  } else if (valueDataType == POSITION_2D) {
626  double xv = inMsg.readDouble();
627  double yv = inMsg.readDouble();
628  answerLog << " position value: (" << xv << "," << yv << ")" << std::endl;
629  } else if (valueDataType == TYPE_COLOR) {
630  int r = inMsg.readUnsignedByte();
631  int g = inMsg.readUnsignedByte();
632  int b = inMsg.readUnsignedByte();
633  int a = inMsg.readUnsignedByte();
634  answerLog << " color value: (" << r << "," << g << "," << b << "," << a << ")" << std::endl;
635  } else {
636  answerLog << "#Error: unknown valueDataType!" << std::endl;
637  }
638 }
639 
640 
641 void
643  answerLog << "testAPI:\n";
644  answerLog << " setOrder:\n";
645  setOrder(0);
646  // edge
647  answerLog << " edge:\n";
648  answerLog << " getIDList: " << joinToString(edge.getIDList(), " ") << "\n";
649  answerLog << " getIDCount: " << edge.getIDCount() << "\n";
650  const std::string edgeID = "e_m0";
651  edge.adaptTraveltime(edgeID, 42, 0, 10);
652  edge.setEffort(edgeID, 420, 0, 10);
653  answerLog << " currentTraveltime: " << edge.getTraveltime(edgeID) << "\n";
654  answerLog << " adaptedTravelTime: " << edge.getAdaptedTraveltime(edgeID, 0) << "\n";
655  answerLog << " effort: " << edge.getEffort(edgeID, 0) << "\n";
656  answerLog << " laneNumber: " << edge.getLaneNumber(edgeID) << "\n";
657  answerLog << " streetName: " << edge.getStreetName(edgeID) << "\n";
658 
659  // lane
660  answerLog << " lane:\n";
661  answerLog << " getIDList: " << joinToString(lane.getIDList(), " ") << "\n";
662  answerLog << " getIDCount: " << lane.getIDCount() << "\n";
663  const std::string laneID = "e_m6_0";
664  answerLog << " getLinkNumber: " << lane.getLinkNumber(laneID) << "\n";
665  std::vector<libsumo::TraCIConnection> connections = lane.getLinks(laneID);
666  answerLog << " getLinks:\n";
667  for (int i = 0; i < (int)connections.size(); ++i) {
668  const libsumo::TraCIConnection& c = connections[i];
669  answerLog << " approachedLane=" << c.approachedLane
670  << " hasPrio=" << c.hasPrio
671  << " isOpen=" << c.isOpen
672  << " hasFoe=" << c.hasFoe
673  << " approachedInternal=" << c.approachedInternal
674  << " state=" << c.state
675  << " direction=" << c.direction
676  << " length=" << c.length
677  << "\n";
678  }
679  answerLog << " getFoes: " << joinToString(lane.getFoes("e_vu0_0", "e_m4_0"), " ") << "\n";
680  try {
681  answerLog << " getFoes (invalid): ";
682  answerLog << joinToString(lane.getFoes("e_vu0_0", "e_m4_1"), " ") << "\n";
683  } catch (libsumo::TraCIException& e) {
684  answerLog << " caught TraCIException(" << e.what() << ")\n";
685  }
686  answerLog << " getInternalFoes: " << joinToString(lane.getInternalFoes(":n_m4_2_0"), " ") << "\n";
687  try {
688  answerLog << " getInternalFoes (invalid): ";
689  answerLog << joinToString(lane.getInternalFoes("dummy"), " ") << "\n";
690  } catch (libsumo::TraCIException& e) {
691  answerLog << " caught TraCIException(" << e.what() << ")\n";
692  }
693  // poi
694  answerLog << " POI:\n";
695  answerLog << " getIDList: " << joinToString(poi.getIDList(), " ") << "\n";
696  answerLog << " getIDCount: " << poi.getIDCount() << "\n";
697  answerLog << " getPosition: " << poi.getPosition("poi0").getString() << "\n";
698  answerLog << " getColor: " << poi.getColor("poi0").getString() << "\n";
699 
700  // poly
701  answerLog << " polygon:\n";
702  answerLog << " getIDList: " << joinToString(polygon.getIDList(), " ") << "\n";
703  answerLog << " getIDCount: " << polygon.getIDCount() << "\n";
704  std::vector<libsumo::TraCIPosition> shape = polygon.getShape("poly0");
705  std::string shapeStr;
706  for (auto pos : shape) {
707  shapeStr += pos.getString() + " ";
708  }
709  polygon.setLineWidth("poly0", 0.6);
710  answerLog << " getLineWidth: " << polygon.getLineWidth("poly0") << "\n";
711  answerLog << " getShape: " << shapeStr << "\n";
712  answerLog << " getColor: " << polygon.getColor("poly0").getString() << "\n";
713  shape[0].x = 42;
714  polygon.setShape("poly0", shape);
715  std::string shapeStr2;
716  for (auto pos : polygon.getShape("poly0")) {
717  shapeStr2 += pos.getString() + " ";
718  }
719  answerLog << " getShape after modification: " << shapeStr2 << "\n";
720 
721  // route
722  answerLog << " route:\n";
723  answerLog << " add:\n";
724  std::vector<std::string> edges;
725  edges.push_back("e_u1");
726  edges.push_back("e_u0");
727  route.add("e_u1", edges);
728  edges.clear();
729  edges.push_back("e_m4");
730  route.add("e_m4", edges);
731  answerLog << " getIDList: " << joinToString(route.getIDList(), " ") << "\n";
732 
733  // vehicletype
734  answerLog << " vehicleType:\n";
735  answerLog << " getIDList: " << joinToString(vehicletype.getIDList(), " ") << "\n";
736  vehicletype.setEmergencyDecel("t1", 9.9);
737  answerLog << " getEmergencyDecel: " << vehicletype.getEmergencyDecel("t1") << "\n";
738  vehicletype.setApparentDecel("t1", 99.9);
739  answerLog << " getApparentDecel: " << vehicletype.getApparentDecel("t1") << "\n";
740  vehicletype.setWidth("t1", 1.9);
741  answerLog << " getWidth: " << vehicletype.getWidth("t1") << "\n";
742  vehicletype.setHeight("t1", 1.8);
743  answerLog << " getHeight: " << vehicletype.getHeight("t1") << "\n";
744  vehicletype.setMinGapLat("t1", 1.5);
745  answerLog << " setMinGapLat: " << vehicletype.getMinGapLat("t1") << "\n";
746  vehicletype.setMaxSpeedLat("t1", 1.2);
747  answerLog << " setMaxSpeedLat: " << vehicletype.getMaxSpeedLat("t1") << "\n";
748  vehicletype.setLateralAlignment("t1", "compact");
749  answerLog << " getLateralAlignment: " << vehicletype.getLateralAlignment("t1") << "\n";
750  answerLog << " copy type 't1' to 't1_copy' and set accel to 100.\n";
751  vehicletype.copy("t1", "t1_copy");
752  answerLog << " getIDList: " << joinToString(vehicletype.getIDList(), " ") << "\n";
753  vehicletype.setAccel("t1_copy", 100.);
754  answerLog << " getAccel('t1'): " << vehicletype.getAccel("t1") << "\n";
755  answerLog << " getAccel('t1_copy'): " << vehicletype.getAccel("t1_copy") << "\n";
756 
757  // vehicle
758  answerLog << " vehicle:\n";
759  vehicle.setLine("0", "S42");
760  std::vector<std::string> via;
761  via.push_back("e_shape1");
762  vehicle.setVia("0", via);
763  vehicle.setType("0", "t1_copy");
764  answerLog << " getTypeID: " << vehicle.getTypeID("0") << "\n";
765  answerLog << " getRoadID: " << vehicle.getRoadID("0") << "\n";
766  answerLog << " getRouteID: " << vehicle.getRouteID("0") << "\n";
767  answerLog << " getLaneID: " << vehicle.getLaneID("0") << "\n";
768  answerLog << " getLanePosition: " << vehicle.getLanePosition("0") << "\n";
769  answerLog << " getLateralLanePosition: " << vehicle.getLateralLanePosition("0") << "\n";
770  answerLog << " getSpeed: " << vehicle.getSpeed("0") << "\n";
771  answerLog << " getAcceleration: " << vehicle.getAcceleration("0") << "\n";
772  answerLog << " getSpeedMode: " << vehicle.getSpeedMode("0") << "\n";
773  answerLog << " getSlope: " << vehicle.getSlope("0") << "\n";
774  answerLog << " getLine: " << vehicle.getLine("0") << "\n";
775  answerLog << " getVia: " << joinToString(vehicle.getVia("0"), ",") << "\n";
776  vehicle.setMaxSpeed("0", 30);
777  answerLog << " getMaxSpeed: " << vehicle.getMaxSpeed("0") << "\n";
778  answerLog << " isRouteValid: " << vehicle.isRouteValid("0") << "\n";
779  vehicle.setParameter("0", "meaningOfLife", "42");
780  answerLog << " param: " << vehicle.getParameter("0", "meaningOfLife") << "\n";
781  libsumo::TraCIColor col1;
782  col1.r = 255;
783  col1.g = 255;
784  col1.b = 0;
785  col1.a = 128;
786  vehicle.setColor("0", col1);
788  answerLog << " getColor: r=" << (int)col2.r << " g=" << (int)col2.g << " b=" << (int)col2.b << " a=" << (int)col2.a << "\n";
789  int signals = vehicle.getSignals("0");
790  answerLog << " getSignals: " << signals << "\n";
793  answerLog << " getRoutingMode: " << vehicle.getRoutingMode("0") << "\n";
794  answerLog << " getNextTLS:\n";
795  std::vector<libsumo::TraCINextTLSData> result = vehicle.getNextTLS("0");
796  for (int i = 0; i < (int)result.size(); ++i) {
797  const libsumo::TraCINextTLSData& d = result[i];
798  answerLog << " tls=" << d.id << " tlIndex=" << d.tlIndex << " dist=" << d.dist << " state=" << d.state << "\n";
799  }
800  answerLog << " moveToXY, simStep:\n";
801  vehicle.moveToXY("0", "dummy", 0, 2231.61, 498.29, 90, 1);
802  simulationStep();
803  answerLog << " getRoadID: " << vehicle.getRoadID("0") << "\n";
804  answerLog << " getLaneID: " << vehicle.getLaneID("0") << "\n";
805  vehicle.changeTarget("0", "e_o0");
806  std::vector<std::string> edges2 = vehicle.getRoute("0");
807  answerLog << " edges: " << joinToString(edges2, " ") << "\n";
808  vehicle.setRouteID("0", "e_m4");
809  answerLog << " edges: " << joinToString(vehicle.getRoute("0"), " ") << "\n";
810  vehicle.setRoute("0", edges2);
811  answerLog << " edges: " << joinToString(vehicle.getRoute("0"), " ") << "\n";
812  answerLog << " add:\n";
813  vehicle.add("1", "e_u1");
814  vehicle.add("2", "e_u1");
815  vehicle.moveTo("2", "e_u0_0", 5);
816  simulationStep();
817  answerLog << " getIDList: " << joinToString(vehicle.getIDList(), " ") << "\n";
818  answerLog << " getWaitingTime: " << vehicle.getWaitingTime("0") << "\n";
819  answerLog << " getAccumulatedWaitingTime: " << vehicle.getAccumulatedWaitingTime("0") << "\n";
820  vehicle.setShapeClass("0", "bicycle");
821  answerLog << " getShapeClass: " << vehicle.getShapeClass("0") << "\n";
822  std::pair<std::string, double> leader = vehicle.getLeader("1", 1000);
823  answerLog << " getLeader: " << leader.first << ", " << leader.second << "\n";
824  std::pair<int, int> state = vehicle.getLaneChangeState("1", 1);
825  answerLog << " getLaneChangeState (left): " << state.first << ", " << state.second << "\n";
826  state = vehicle.getLaneChangeState("1", -1);
827  answerLog << " getLaneChangeState (right): " << state.first << ", " << state.second << "\n";
829  vehicle.setSpeedFactor("0", 0.8);
830  answerLog << " remove:\n";
831  vehicle.remove("0");
832  answerLog << " getIDCount: " << vehicle.getIDCount() << "\n";
833 
834  // inductionLoop
835  answerLog << " inductionloop:\n";
836  answerLog << " getIDList: " << joinToString(inductionloop.getIDList(), " ") << "\n";
837  answerLog << " getVehicleData:\n";
838  std::vector<libsumo::TraCIVehicleData> result2 = inductionloop.getVehicleData("det1");
839  for (int i = 0; i < (int)result2.size(); ++i) {
840  const libsumo::TraCIVehicleData& vd = result2[i];
841  answerLog << " veh=" << vd.id << " length=" << vd.length << " entered=" << vd.entryTime << " left=" << vd.leaveTime << " type=" << vd.typeID << "\n";
842  }
843 
844  // simulation
845  answerLog << " simulation:\n";
846  answerLog << " getDistance2D_air: " << simulation.getDistance2D(2500, 500, 2000, 500, false, false) << "\n";
847  answerLog << " getDistance2D_driving: " << simulation.getDistance2D(2500, 500, 2000, 500, false, true) << "\n";
848  answerLog << " getDistanceRoad_air: " << simulation.getDistanceRoad("e_m5", 0, "e_m4", 0, false) << "\n";
849  answerLog << " getDistanceRoad_driving: " << simulation.getDistanceRoad("e_m5", 0, "e_m4", 0, true) << "\n";
850  answerLog << " getCurrentTime: " << simulation.getCurrentTime() << "\n";
851  answerLog << " getDeltaT: " << simulation.getDeltaT() << "\n";
852  answerLog << " parkingArea param: " << simulation.getParameter("park1", "parkingArea.capacity") << "\n";
853  answerLog << " subscribe to road and pos of vehicle '1':\n";
854  std::vector<int> vars;
855  vars.push_back(VAR_ROAD_ID);
856  vars.push_back(VAR_LANEPOSITION);
857  vehicle.subscribe("1", vars, 0, 100);
858  simulationStep();
859  answerLog << " subscription results:\n";
861  answerLog << " roadID=" << result3[VAR_ROAD_ID]->getString() << " pos=" << result3[VAR_LANEPOSITION]->getString() << "\n";
862 
863  answerLog << " subscribe to vehicles around edge 'e_u1':\n";
864  std::vector<int> vars2;
865  vars2.push_back(VAR_LANEPOSITION);
866  edge.subscribeContext("e_u1", CMD_GET_VEHICLE_VARIABLE, 100, vars2, 0, 100);
867  simulationStep();
868  answerLog << " context subscription results:\n";
870  for (libsumo::SubscriptionResults::iterator it = result4.begin(); it != result4.end(); ++it) {
871  answerLog << " vehicle=" << it->first << " pos=" << it->second[VAR_LANEPOSITION]->getString() << "\n";
872  }
873 
874  // person
875  answerLog << " person:\n";
876  person.setWidth("p0", 1);
877  person.setMinGap("p0", 2);
878  person.setLength("p0", 3);
879  person.setHeight("p0", 4);
880  person.setColor("p0", col1);
881  person.setType("p0", "stilts");
882  answerLog << " getIDList: " << joinToString(person.getIDList(), " ") << "\n";
883  answerLog << " getRoadID: " << person.getRoadID("p0") << "\n";
884  answerLog << " getTypeID: " << person.getTypeID("p0") << "\n";
885  answerLog << " getWaitingTime: " << person.getWaitingTime("p0") << "\n";
886  answerLog << " getNextEdge: " << person.getNextEdge("p0") << "\n";
887  answerLog << " getStage: " << person.getStage("p0") << "\n";
888  answerLog << " getRemainingStages: " << person.getRemainingStages("p0") << "\n";
889  answerLog << " getVehicle: " << person.getVehicle("p0") << "\n";
890  answerLog << " getEdges: " << joinToString(person.getEdges("p0"), " ") << "\n";
891  answerLog << " getPosition: " << person.getPosition("p0").getString() << "\n";
892  answerLog << " getPosition3D: " << person.getPosition3D("p0").getString() << "\n";
893  answerLog << " getAngle: " << person.getAngle("p0") << "\n";
894  answerLog << " getLanePosition: " << person.getLanePosition("p0") << "\n";
895  answerLog << " getLength: " << person.getLength("p0") << "\n";
896  answerLog << " getColor: " << person.getColor("p0").getString() << "\n";
897  person.setParameter("p0", "foo", "bar");
898  answerLog << " param: " << person.getParameter("p0", "foo") << "\n";
899  person.setSpeed("p0", 3);
900  simulationStep();
901  answerLog << " getSpeed: " << person.getSpeed("p0") << "\n";
902  person.add("p1", "e_u1", 10);
903  std::vector<std::string> walkEdges;
904  walkEdges.push_back("e_u1");
905  walkEdges.push_back("e_shape1");
906  person.appendWalkingStage("p1", walkEdges, -20);
907  person.appendWaitingStage("p1", 5);
908  person.appendDrivingStage("p1", "e_vu2", "BusLine42");
909  // expect 4 stages due to the initial waiting-for-departure stage
910  answerLog << " getRemainingStages: " << person.getRemainingStages("p1") << "\n";
911  person.removeStage("p1", 3);
912  answerLog << " getRemainingStages: " << person.getRemainingStages("p1") << "\n";
913  person.removeStages("p1");
914  answerLog << " getRemainingStages: " << person.getRemainingStages("p1") << "\n";
915  answerLog << " getStage: " << person.getStage("p1") << "\n";
916  walkEdges.push_back("e_m5");
917  person.appendWalkingStage("p1", walkEdges, -20);
918  simulationStep();
920  answerLog << " getEdges after rerouting: " << joinToString(person.getEdges("p1"), " ") << "\n";
921 
922  // trafficlights
923  answerLog << " trafficlights:\n";
924  answerLog << " getIDList: " << joinToString(trafficlights.getIDList(), " ") << "\n";
925  answerLog << " getIDCount: " << trafficlights.getIDCount() << "\n";
926  answerLog << " state: " << trafficlights.getRedYellowGreenState("n_m4") << "\n";
927  answerLog << " program: " << trafficlights.getProgram("n_m4") << "\n";
928  answerLog << " phase: " << trafficlights.getPhase("n_m4") << "\n";
929  answerLog << " phaseDuration: " << trafficlights.getPhaseDuration("n_m4") << "\n";
930  answerLog << " nextSwitch: " << trafficlights.getNextSwitch("n_m4") << "\n";
931  answerLog << " controlledLanes: " << joinToString(trafficlights.getControlledLanes("n_m4"), " ") << "\n";
932  std::vector<std::vector<libsumo::TraCILink> > links = trafficlights.getControlledLinks("n_m4");
933  answerLog << " controlledLinks:\n";
934  for (int i = 0; i < (int)links.size(); ++i) {
935  for (int j = 0; j < (int)links[i].size(); ++j) {
936  answerLog << " index=" << i << " link=" << j << " fromLane=" << links[i][j].fromLane << " viaLane=" << links[i][j].viaLane << " toLane=" << links[i][j].toLane << "\n";
937  }
938  }
939  libsumo::TraCILogic logic("custom", 0, 3);
940  logic.phases = std::vector<libsumo::TraCIPhase>({ libsumo::TraCIPhase(5, "rrrrrrr", 5, 5), libsumo::TraCIPhase(10, "ggggggg", 5, 15),
941  libsumo::TraCIPhase(3, "GGGGGGG", 3, 3), libsumo::TraCIPhase(3, "yyyyyyy", 3, 3)
942  });
944 
945  std::vector<libsumo::TraCILogic> logics = trafficlights.getCompleteRedYellowGreenDefinition("n_m4");
946  answerLog << " completeDefinition:\n";
947  for (int i = 0; i < (int)logics.size(); ++i) {
948  answerLog << " subID=" << logics[i].programID << " type=" << logics[i].type << " phase=" << logics[i].currentPhaseIndex << "\n";
949  answerLog << " params=" << joinToString(logics[i].subParameter, " ", ":") << "\n";
950  for (int j = 0; j < (int)logics[i].phases.size(); ++j) {
951  answerLog << " phase=" << logics[i].phases[j].state
952  << " dur=" << logics[i].phases[j].duration
953  << " minDur=" << logics[i].phases[j].minDur
954  << " maxDur=" << logics[i].phases[j].maxDur
955  << "\n";
956  }
957  }
958  simulationStep();
959  answerLog << " state=" << trafficlights.getRedYellowGreenState("n_m4") << "\n";
960  trafficlights.setRedYellowGreenState("n_m4", "gGyruoO");
961  answerLog << " stateSet=" << trafficlights.getRedYellowGreenState("n_m4") << "\n";
962  answerLog << " program: " << trafficlights.getProgram("n_m4") << "\n";
963 
964  answerLog << " load:\n";
965  std::vector<std::string> args;
966  args.push_back("-n");
967  args.push_back("net.net.xml");
968  args.push_back("-r");
969  args.push_back("input_routes.rou.xml");
970  args.push_back("--no-step-log");
971  load(args);
972  simulationStep();
973  answerLog << " getCurrentTime: " << simulation.getCurrentTime() << "\n";
974  vehicle.subscribe("0", vars, 0, TIME2STEPS(100));
975  edge.subscribeContext("e_u1", CMD_GET_VEHICLE_VARIABLE, 100, vars2, 0, TIME2STEPS(100));
976 
977  answerLog << " gui:\n";
978  try {
979  answerLog << " setScheme: \n";
980  gui.setSchema("View #0", "real world");
981  answerLog << " getScheme: " << gui.getSchema("View #0") << "\n";
982  answerLog << " take screenshot: \n";
983  gui.screenshot("View #0", "image.png", 500, 500);
984  } catch (libsumo::TraCIException&) {
985  answerLog << " no support for gui commands\n";
986  }
987 }
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1272
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:853
#define VAR_ROAD_ID
double getAngle(const std::string &personID) const
Definition: TraCIAPI.cpp:2980
int run(std::string fileName, int port, std::string host="localhost")
Runs a test.
std::vector< libsumo::TraCINextTLSData > getNextTLS(const std::string &vehID) const
Definition: TraCIAPI.cpp:2356
unsigned char g
Definition: TraCIDefs.h:139
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1646
std::string getRouteID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2238
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:199
#define RESPONSE_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
void setAccel(const std::string &typeID, double accel) const
Definition: TraCIAPI.cpp:2098
void setRoute(const std::string &vehicleID, const std::vector< std::string > &edge) const
Definition: TraCIAPI.cpp:2706
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1498
std::string getParameter(const std::string &objectID, const std::string &key) const
retrieve generic paramter
Definition: TraCIAPI.cpp:3235
std::string id
The id of the next tls.
Definition: TraCIDefs.h:288
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:187
void remove(const std::string &vehicleID, char reason=REMOVE_VAPORIZED) const
Definition: TraCIAPI.cpp:2629
void setMinGapLat(const std::string &typeID, double minGapLat) const
Definition: TraCIAPI.cpp:2048
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:280
void readAndReportTypeDependent(tcpip::Storage &inMsg, int valueDataType)
Reads a value of the given type from the given storage and reports it.
void setWidth(const std::string &typeID, double width) const
Definition: TraCIAPI.cpp:2017
void setColor(const std::string &vehicleID, const libsumo::TraCIColor &c) const
Definition: TraCIAPI.cpp:2873
void appendDrivingStage(const std::string &personID, const std::string &toEdge, const std::string &lines, const std::string &stopID="")
Definition: TraCIAPI.cpp:3129
#define REQUEST_DRIVINGDIST
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:983
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:286
std::vector< std::vector< libsumo::TraCILink > > getControlledLinks(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1713
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:74
libsumo::TraCIColor getColor(const std::string &poiID) const
Definition: TraCIAPI.cpp:1292
double dist
The distance to the tls.
Definition: TraCIDefs.h:292
void setLength(const std::string &personID, double length) const
Definition: TraCIAPI.cpp:3179
void commandSubscribeObjectVariable(int domID, const std::string &objID, double beginTime, double endTime, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeVariable command.
std::string typeID
Type of the vehicle in.
Definition: TraCIDefs.h:282
void setSpeedFactor(const std::string &vehicleID, double factor) const
Definition: TraCIAPI.cpp:2853
libsumo::TraCIColor getColor(const std::string &personID) const
Definition: TraCIAPI.cpp:2990
void changeTarget(const std::string &vehicleID, const std::string &edgeID) const
Definition: TraCIAPI.cpp:2641
void setOrder(int order)
set priority (execution order) for the client
Definition: TraCIAPI.cpp:87
#define CMD_GET_VEHICLE_VARIABLE
#define TYPE_COMPOUND
void commandSetOrder(int order)
Sends and validates a SetOrder command.
std::stringstream answerLog
Stream containing the log.
#define CMD_CLOSE
void setVia(const std::string &vehicleID, const std::vector< std::string > &via) const
Definition: TraCIAPI.cpp:2896
virtual std::vector< std::string > readStringList()
#define RESPONSE_SUBSCRIBE_GUI_VARIABLE
#define POSITION_2D
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:272
void setRouteID(const std::string &vehicleID, const std::string &routeID) const
Definition: TraCIAPI.cpp:2695
void testAPI()
call all API methods once
double getLineWidth(const std::string &polygonID) const
Definition: TraCIAPI.cpp:1381
void setParameter(const std::string &objectID, const std::string &key, const std::string &value) const
set generic paramter
Definition: TraCIAPI.cpp:3244
int setValueTypeDependant(tcpip::Storage &into, std::ifstream &defFile, std::stringstream &msg)
Parses the next value type / value pair from the stream and inserts it into the storage.
int getRoutingMode(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2463
double getWaitingTime(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2319
#define TYPE_UBYTE
#define RTYPE_OK
std::string getTypeID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2233
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:160
#define POSITION_ROADMAP
std::map< int, std::shared_ptr< TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:197
std::pair< int, int > getLaneChangeState(const std::string &vehicleID, int direction) const
Definition: TraCIAPI.cpp:2441
void setSignals(const std::string &vehicleID, int signals) const
Definition: TraCIAPI.cpp:2909
double getEmergencyDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1884
int getIDCount() const
Definition: TraCIAPI.cpp:1277
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:861
virtual double readDouble()
#define TYPE_POLYGON
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:867
int getIDCount() const
Definition: TraCIAPI.cpp:2183
double getMaxSpeedLat(const std::string &typeID) const
Definition: TraCIAPI.cpp:1929
void rerouteTraveltime(const std::string &vehicleID, bool currentTravelTimes=true) const
Definition: TraCIAPI.cpp:2720
void setMaxSpeedLat(const std::string &typeID, double speed) const
Definition: TraCIAPI.cpp:2058
double getMaxSpeed(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2198
void setLine(const std::string &vehicleID, const std::string &line) const
Definition: TraCIAPI.cpp:2886
bool validateSubscription(tcpip::Storage &inMsg)
Validates whether the given message is a valid subscription return message.
std::string getRoadID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2218
void appendWaitingStage(const std::string &personID, double duration, const std::string &description="waiting", const std::string &stopID="")
Definition: TraCIAPI.cpp:3085
std::vector< libsumo::TraCIVehicleData > getVehicleData(const std::string &loopID) const
Definition: TraCIAPI.cpp:928
double getNextSwitch(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1756
#define TYPE_COLOR
#define TYPE_STRINGLIST
void load(const std::vector< std::string > &args)
Let sumo load a simulation using the given command line like options.
Definition: TraCIAPI.cpp:589
libsumo::TraCIColor getColor(const std::string &polygonID) const
Definition: TraCIAPI.cpp:1396
double getSpeed(const std::string &personID) const
Definition: TraCIAPI.cpp:2965
void send_commandSetOrder(int order) const
Sends a SetOrder command.
Definition: TraCIAPI.cpp:147
#define POSITION_3D
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1371
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:112
libsumo::TraCIPosition getPosition3D(const std::string &personID) const
Definition: TraCIAPI.cpp:2975
std::string getNextEdge(const std::string &personID) const
Definition: TraCIAPI.cpp:3015
std::string outputFileName
The name of the file to write the results log into.
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
virtual void writeUnsignedByte(int)
std::string getRedYellowGreenState(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1656
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:877
int getIDCount() const
Definition: TraCIAPI.cpp:1376
int getPhase(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1746
std::vector< TraCIPhase > phases
Definition: TraCIDefs.h:234
std::string getLine(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2336
double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
Definition: TraCIAPI.cpp:1622
void removeStage(const std::string &personID, int nextStageIndex) const
Definition: TraCIAPI.cpp:3147
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:857
virtual void writeInt(int)
std::vector< std::string > getRoute(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2249
#define TYPE_STRING
virtual int readUnsignedByte()
std::vector< libsumo::TraCIConnection > getLinks(const std::string &laneID) const
Definition: TraCIAPI.cpp:1023
#define RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
bool validateSimulationStep2(tcpip::Storage &inMsg)
Validates whether the given message is a valid answer to CMD_SIMSTEP.
unsigned char b
Definition: TraCIDefs.h:139
const libsumo::SubscriptionResults getContextSubscriptionResults(const std::string &objID) const
Definition: TraCIAPI.cpp:3303
void commandSetValue(int domID, int varID, const std::string &objID, std::ifstream &defFile)
Sends and validates a SetVariable command.
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
Definition: TraCIAPI.cpp:2752
double getPhaseDuration(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1751
void rerouteTraveltime(const std::string &personID) const
Definition: TraCIAPI.cpp:3057
void commandSimulationStep(double time)
Sends and validates a simulation step command.
void setCompleteRedYellowGreenDefinition(const std::string &tlsID, const libsumo::TraCILogic &logic) const
Definition: TraCIAPI.cpp:1802
std::string getShapeClass(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2351
std::string getTypeID(const std::string &personID) const
Definition: TraCIAPI.cpp:3005
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:883
libsumo::TraCIColor getColor(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2254
void setHeight(const std::string &personID, double height) const
Definition: TraCIAPI.cpp:3200
std::vector< std::string > getVia(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2341
void setType(const std::string &vehicleID, const std::string &typeID) const
Definition: TraCIAPI.cpp:2843
std::string approachedInternal
Definition: TraCIDefs.h:264
virtual int readInt()
#define VAR_LANEPOSITION
void writeResult()
Writes the results file.
double getAccumulatedWaitingTime(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2523
virtual void writeByte(int)
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:873
double getLateralLanePosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2274
void simulationStep(double time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:567
unsigned char a
Definition: TraCIDefs.h:139
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:208
virtual void writeStringList(const std::vector< std::string > &s)
std::string getStreetName(const std::string &id) const
Definition: TraCIAPI.cpp:719
void setLateralAlignment(const std::string &typeID, const std::string &latAlignment) const
Definition: TraCIAPI.cpp:2068
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:236
double getLanePosition(const std::string &personID) const
Definition: TraCIAPI.cpp:2985
double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo=false, bool isDriving=false)
Definition: TraCIAPI.cpp:1603
void setRedYellowGreenState(const std::string &tlsID, const std::string &state) const
Definition: TraCIAPI.cpp:1762
int getIDCount() const
Definition: TraCIAPI.cpp:615
void subscribe(const std::string &objID, const std::vector< int > &vars, double beginTime, double endTime) const
Definition: TraCIAPI.cpp:3259
double length
Length of the vehicle.
Definition: TraCIDefs.h:276
void add(const std::string &personID, const std::string &edgeID, double pos, double depart=DEPARTFLAG_NOW, const std::string typeID="DEFAULT_PEDTYPE")
Definition: TraCIAPI.cpp:3067
double getWaitingTime(const std::string &personID) const
Definition: TraCIAPI.cpp:3010
std::string getRoadID(const std::string &personID) const
Definition: TraCIAPI.cpp:3000
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:274
virtual std::string readString()
bool isRouteValid(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2548
void subscribeContext(const std::string &objID, int domain, double range, const std::vector< int > &vars, double beginTime, double endTime) const
Definition: TraCIAPI.cpp:3271
unsigned char r
Definition: TraCIDefs.h:139
void add(const std::string &routeID, const std::vector< std::string > &edges) const
Definition: TraCIAPI.cpp:1509
void setLineWidth(const std::string &polygonID, const double lineWidth) const
Definition: TraCIAPI.cpp:1401
double getSpeed(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2188
std::string getProgram(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1741
void setWidth(const std::string &personID, double width) const
Definition: TraCIAPI.cpp:3190
libsumo::TraCIPosition getPosition(const std::string &personID) const
Definition: TraCIAPI.cpp:2970
void setSpeed(const std::string &personID, double speed) const
Definition: TraCIAPI.cpp:3158
libsumo::TraCIPositionVector getShape(const std::string &polygonID) const
Definition: TraCIAPI.cpp:1391
const libsumo::TraCIResults getSubscriptionResults(const std::string &objID) const
Definition: TraCIAPI.cpp:3287
double getAcceleration(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2193
void setShapeClass(const std::string &vehicleID, const std::string &clazz) const
Definition: TraCIAPI.cpp:2929
std::string getVehicle(const std::string &personID) const
Definition: TraCIAPI.cpp:3021
std::string approachedLane
Definition: TraCIDefs.h:260
TraCITestClient(std::string outputFileName="testclient_result.out")
Constructor.
int getRemainingStages(const std::string &personID) const
Definition: TraCIAPI.cpp:3026
POIScope poi
Scope for interaction with POIs.
Definition: TraCIAPI.h:869
double getSlope(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2330
void errorMsg(std::stringstream &msg)
Writes an error message.
#define RESPONSE_SUBSCRIBE_GUI_CONTEXT
void commandSubscribeContextVariable(int domID, const std::string &objID, double beginTime, double endTime, int domain, double range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
void setShape(const std::string &polygonID, const libsumo::TraCIPositionVector &shape) const
Definition: TraCIAPI.cpp:1422
int getLaneNumber(const std::string &edgeID) const
Definition: TraCIAPI.cpp:713
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:875
std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist) const
Definition: TraCIAPI.cpp:2424
virtual void writeString(const std::string &s)
void setMaxSpeed(const std::string &vehicleID, double speed) const
Definition: TraCIAPI.cpp:2863
void setColor(const std::string &personID, const libsumo::TraCIColor &c) const
Definition: TraCIAPI.cpp:3221
libsumo::TraCIPosition getPosition(const std::string &poiID) const
Definition: TraCIAPI.cpp:1287
#define REQUEST_AIRDIST
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:879
#define TYPE_DOUBLE
double getHeight(const std::string &typeID) const
Definition: TraCIAPI.cpp:1944
std::string getString()
Definition: TraCIDefs.h:108
std::vector< std::string > getControlledLanes(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1708
#define ROUTING_MODE_AGGREGATED
int getLinkNumber(const std::string &laneID) const
Definition: TraCIAPI.cpp:1018
char state
The current state of the tls.
Definition: TraCIDefs.h:294
#define TYPE_BYTE
void setEffort(const std::string &edgeID, double effort, double beginSeconds=0., double endSeconds=std::numeric_limits< double >::max()) const
Definition: TraCIAPI.cpp:746
PolygonScope polygon
Scope for interaction with polygons.
Definition: TraCIAPI.h:871
void adaptTraveltime(const std::string &edgeID, double time, double beginSeconds=0., double endSeconds=std::numeric_limits< double >::max()) const
Definition: TraCIAPI.cpp:725
void setEmergencyDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2118
void commandClose()
Sends and validates a Close command.
void send_commandSimulationStep(double time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:123
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:136
void copy(const std::string &origTypeID, const std::string &newTypeID) const
Definition: TraCIAPI.cpp:2078
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:325
int getSpeedMode(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2324
int getIDCount() const
Definition: TraCIAPI.cpp:988
void setSchema(const std::string &viewID, const std::string &schemeName) const
Definition: TraCIAPI.cpp:827
double getEffort(const std::string &edgeID, double time) const
Definition: TraCIAPI.cpp:628
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1849
virtual void writeDouble(double)
double getTraveltime(const std::string &edgeID) const
Definition: TraCIAPI.cpp:692
#define CMD_SETORDER
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:855
void setMinGap(const std::string &personID, double minGap) const
Definition: TraCIAPI.cpp:3210
std::string getLateralAlignment(const std::string &typeID) const
Definition: TraCIAPI.cpp:1934
void appendWalkingStage(const std::string &personID, const std::vector< std::string > &edges, double arrivalPos, double duration=-1, double speed=-1, const std::string &stopID="")
Definition: TraCIAPI.cpp:3104
void screenshot(const std::string &viewID, const std::string &filename, const int width=-1, const int height=-1) const
Definition: TraCIAPI.cpp:851
double getApparentDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1889
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:610
void setHeight(const std::string &typeID, double height) const
Definition: TraCIAPI.cpp:2027
double getLength(const std::string &personID) const
Definition: TraCIAPI.cpp:2995
std::string getLaneID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2223
int getStage(const std::string &personID, int nextStageIndex=0) const
Definition: TraCIAPI.cpp:3031
double getLanePosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2259
int getSignals(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2269
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:278
void commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *addData=0)
Sends and validates a GetVariable command.
void removeStages(const std::string &personID) const
Definition: TraCIAPI.cpp:3047
double getAccel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1874
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
Definition: TraCIAPI.cpp:2568
double getAdaptedTraveltime(const std::string &edgeID, double time) const
Definition: TraCIAPI.cpp:620
double getDeltaT() const
Definition: TraCIAPI.cpp:1586
void setRoutingMode(const std::string &vehicleID, int routingMode) const
Definition: TraCIAPI.cpp:2919
#define TYPE_INTEGER
void setType(const std::string &personID, const std::string &typeID) const
Definition: TraCIAPI.cpp:3169
void moveTo(const std::string &vehicleID, const std::string &laneID, double position) const
Definition: TraCIAPI.cpp:2738
std::vector< std::string > getEdges(const std::string &personID, int nextStageIndex=0) const
Definition: TraCIAPI.cpp:3039
std::vector< std::string > getInternalFoes(const std::string &laneID) const
Definition: TraCIAPI.cpp:1175
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:290
std::vector< std::string > getFoes(const std::string &laneID, const std::string &toLaneID) const
Definition: TraCIAPI.cpp:1159
double getWidth(const std::string &typeID) const
Definition: TraCIAPI.cpp:1939
double getMinGapLat(const std::string &typeID) const
Definition: TraCIAPI.cpp:1924
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:237
#define CMD_SIMSTEP
virtual int readByte()
std::vector< libsumo::TraCILogic > getCompleteRedYellowGreenDefinition(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1661
~TraCITestClient()
Destructor.
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:2955
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:2178
std::string getString()
Definition: TraCIDefs.h:134
std::string getSchema(const std::string &viewID=DEFAULT_VIEW) const
Definition: TraCIAPI.cpp:796
void setApparentDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2128
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:881