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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
22 // A test execution class
23 /****************************************************************************/
24 /* =========================================================================
25  * included modules
26  * ======================================================================= */
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <iostream>
35 #include <iomanip>
36 #include <fstream>
37 #include <sstream>
38 #include <ctime>
39 #include <cstdlib>
40 
41 #define BUILD_TCPIP
42 #include <foreign/tcpip/storage.h>
43 #include <foreign/tcpip/socket.h>
44 
46 #include <libsumo/TraCIDefs.h>
47 #include <utils/common/SUMOTime.h>
48 #include <utils/common/ToString.h>
49 #include "TraCITestClient.h"
50 
51 using namespace libsumo;
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 TraCITestClient::TraCITestClient(std::string outputFileName)
58  : outputFileName(outputFileName), answerLog("") {
59  answerLog.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
60  answerLog.setf(std::ios::showpoint); // print decimal point
61  answerLog << std::setprecision(2);
62 }
63 
64 
66  writeResult();
67 }
68 
69 
70 int
71 TraCITestClient::run(std::string fileName, int port, std::string host) {
72  std::ifstream defFile;
73  std::string fileContentStr;
74  std::stringstream fileContent;
75  std::string lineCommand;
76  std::stringstream msg;
77  int repNo = 1;
78  bool commentRead = false;
79 
80  // try to connect
81  try {
82  TraCIAPI::connect(host, port);
83  } catch (tcpip::SocketException& e) {
84  std::stringstream msg;
85  msg << "#Error while connecting: " << e.what();
86  errorMsg(msg);
87  return 2;
88  }
89 
90  // read definition file and trigger commands according to it
91  defFile.open(fileName.c_str());
92  if (!defFile) {
93  msg << "Can not open definition file " << fileName << std::endl;
94  errorMsg(msg);
95  return 1;
96  }
97  defFile.unsetf(std::ios::dec);
98 
99  while (defFile >> lineCommand) {
100  repNo = 1;
101  if (lineCommand.compare("%") == 0) {
102  // a comment was read
103  commentRead = !commentRead;
104  continue;
105  }
106  if (commentRead) {
107  // wait until end of comment is reached
108  continue;
109  }
110  if (lineCommand.compare("repeat") == 0) {
111  defFile >> repNo;
112  defFile >> lineCommand;
113  }
114  if (lineCommand.compare("simstep2") == 0) {
115  // read parameter for command simulation step and trigger command
116  std::string time;
117  defFile >> time;
118  for (int i = 0; i < repNo; i++) {
120  }
121  } else if (lineCommand.compare("getvariable") == 0) {
122  // trigger command GetXXXVariable
123  int domID, varID;
124  std::string objID;
125  defFile >> domID >> varID >> objID;
126  commandGetVariable(domID, varID, objID);
127  } else if (lineCommand.compare("getvariable_plus") == 0) {
128  // trigger command GetXXXVariable with one parameter
129  int domID, varID;
130  std::string objID;
131  defFile >> domID >> varID >> objID;
132  std::stringstream msg;
133  tcpip::Storage tmp;
134  setValueTypeDependant(tmp, defFile, msg);
135  std::string msgS = msg.str();
136  if (msgS != "") {
137  errorMsg(msg);
138  }
139  commandGetVariable(domID, varID, objID, &tmp);
140  } else if (lineCommand.compare("subscribevariable") == 0) {
141  // trigger command SubscribeXXXVariable
142  int domID, varNo;
143  std::string beginTime, endTime;
144  std::string objID;
145  defFile >> domID >> objID >> beginTime >> endTime >> varNo;
146  commandSubscribeObjectVariable(domID, objID, string2time(beginTime), string2time(endTime), varNo, defFile);
147  } else if (lineCommand.compare("subscribecontext") == 0) {
148  // trigger command SubscribeXXXVariable
149  int domID, varNo, domain;
150  double range;
151  std::string beginTime, endTime;
152  std::string objID;
153  defFile >> domID >> objID >> beginTime >> endTime >> domain >> range >> varNo;
154  commandSubscribeContextVariable(domID, objID, string2time(beginTime), string2time(endTime), domain, range, varNo, defFile);
155  } else if (lineCommand.compare("setvalue") == 0) {
156  // trigger command SetXXXValue
157  int domID, varID;
158  std::string objID;
159  defFile >> domID >> varID >> objID;
160  commandSetValue(domID, varID, objID, defFile);
161  } else if (lineCommand.compare("testAPI") == 0) {
162  // call all native API methods
163  testAPI();
164  } else if (lineCommand.compare("setorder") == 0) {
165  // call setOrder
166  int order;
167  defFile >> order;
168  commandSetOrder(order);
169  } else {
170  msg << "Error in definition file: " << lineCommand << " is not a valid command";
171  errorMsg(msg);
172  commandClose();
173  closeSocket();
174  return 1;
175  }
176  }
177  defFile.close();
178  commandClose();
179  closeSocket();
180  return 0;
181 }
182 
183 
184 // ---------- Commands handling
185 void
187  try {
189  answerLog << std::endl << "-> Command sent: <SimulationStep>:" << std::endl;
190  tcpip::Storage inMsg;
191  std::string acknowledgement;
192  check_resultState(inMsg, CMD_SIMSTEP, false, &acknowledgement);
193  answerLog << acknowledgement << std::endl;
195  } catch (tcpip::SocketException& e) {
196  answerLog << e.what() << std::endl;
197  }
198 }
199 
200 
201 void
203  try {
205  answerLog << std::endl << "-> Command sent: <Close>:" << std::endl;
206  tcpip::Storage inMsg;
207  std::string acknowledgement;
208  check_resultState(inMsg, CMD_CLOSE, false, &acknowledgement);
209  answerLog << acknowledgement << std::endl;
210  } catch (tcpip::SocketException& e) {
211  answerLog << e.what() << std::endl;
212  }
213 }
214 
215 
216 void
218  try {
219  send_commandSetOrder(order);
220  answerLog << std::endl << "-> Command sent: <SetOrder>:" << std::endl;
221  tcpip::Storage inMsg;
222  std::string acknowledgement;
223  check_resultState(inMsg, CMD_SETORDER, false, &acknowledgement);
224  answerLog << acknowledgement << std::endl;
225  } catch (tcpip::SocketException& e) {
226  answerLog << e.what() << std::endl;
227  }
228 }
229 
230 
231 void
232 TraCITestClient::commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData) {
233  tcpip::Storage inMsg;
234  try {
235  send_commandGetVariable(domID, varID, objID, addData);
236  answerLog << std::endl << "-> Command sent: <GetVariable>:" << std::endl
237  << " domID=" << domID << " varID=" << varID
238  << " objID=" << objID << std::endl;
239  std::string acknowledgement;
240  check_resultState(inMsg, domID, false, &acknowledgement);
241  answerLog << acknowledgement << std::endl;
242  } catch (tcpip::SocketException& e) {
243  answerLog << e.what() << std::endl;
244  return;
245  }
246  check_commandGetResult(inMsg, domID, -1, false);
247  // report result state
248  try {
249  int variableID = inMsg.readUnsignedByte();
250  std::string objectID = inMsg.readString();
251  answerLog << " CommandID=" << (domID + 0x10) << " VariableID=" << variableID << " ObjectID=" << objectID;
252  int valueDataType = inMsg.readUnsignedByte();
253  answerLog << " valueDataType=" << valueDataType;
254  readAndReportTypeDependent(inMsg, valueDataType);
255  } catch (tcpip::SocketException& e) {
256  std::stringstream msg;
257  msg << "Error while receiving command: " << e.what();
258  errorMsg(msg);
259  return;
260  }
261 }
262 
263 
264 void
265 TraCITestClient::commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile) {
266  std::stringstream msg;
267  tcpip::Storage inMsg, tmp;
268  setValueTypeDependant(tmp, defFile, msg);
269  std::string msgS = msg.str();
270  if (msgS != "") {
271  errorMsg(msg);
272  }
273  send_commandSetValue(domID, varID, objID, tmp);
274  answerLog << std::endl << "-> Command sent: <SetValue>:" << std::endl
275  << " domID=" << domID << " varID=" << varID
276  << " objID=" << objID << std::endl;
277  try {
278  std::string acknowledgement;
279  check_resultState(inMsg, domID, false, &acknowledgement);
280  answerLog << acknowledgement << std::endl;
281  } catch (tcpip::SocketException& e) {
282  answerLog << e.what() << std::endl;
283  }
284 }
285 
286 
287 void
288 TraCITestClient::commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int varNo, std::ifstream& defFile) {
289  std::vector<int> vars;
290  for (int i = 0; i < varNo; ++i) {
291  int var;
292  defFile >> var;
293  // variable id
294  vars.push_back(var);
295  }
296  send_commandSubscribeObjectVariable(domID, objID, beginTime, endTime, vars);
297  answerLog << std::endl << "-> Command sent: <SubscribeVariable>:" << std::endl
298  << " domID=" << domID << " objID=" << objID << " with " << varNo << " variables" << std::endl;
299  tcpip::Storage inMsg;
300  try {
301  std::string acknowledgement;
302  check_resultState(inMsg, domID, false, &acknowledgement);
303  answerLog << acknowledgement << std::endl;
304  validateSubscription(inMsg);
305  } catch (tcpip::SocketException& e) {
306  answerLog << e.what() << std::endl;
307  }
308 }
309 
310 
311 void
312 TraCITestClient::commandSubscribeContextVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
313  int domain, double range, int varNo, std::ifstream& defFile) {
314  std::vector<int> vars;
315  for (int i = 0; i < varNo; ++i) {
316  int var;
317  defFile >> var;
318  // variable id
319  vars.push_back(var);
320  }
321  send_commandSubscribeObjectContext(domID, objID, beginTime, endTime, domain, range, vars);
322  answerLog << std::endl << "-> Command sent: <SubscribeContext>:" << std::endl
323  << " domID=" << domID << " objID=" << objID << " domain=" << domain << " range=" << range
324  << " with " << varNo << " variables" << std::endl;
325  tcpip::Storage inMsg;
326  try {
327  std::string acknowledgement;
328  check_resultState(inMsg, domID, false, &acknowledgement);
329  answerLog << acknowledgement << std::endl;
330  validateSubscription(inMsg);
331  } catch (tcpip::SocketException& e) {
332  answerLog << e.what() << std::endl;
333  }
334 }
335 
336 
337 // ---------- Report helper
338 void
340  time_t seconds;
341  tm* locTime;
342  std::ofstream outFile(outputFileName.c_str());
343  if (!outFile) {
344  std::cerr << "Unable to write result file" << std::endl;
345  }
346  time(&seconds);
347  locTime = localtime(&seconds);
348  outFile << "TraCITestClient output file. Date: " << asctime(locTime) << std::endl;
349  outFile << answerLog.str();
350  outFile.close();
351 }
352 
353 
354 void
355 TraCITestClient::errorMsg(std::stringstream& msg) {
356  std::cerr << msg.str() << std::endl;
357  answerLog << "----" << std::endl << msg.str() << std::endl;
358 }
359 
360 
361 
362 
363 
364 
365 bool
367  try {
368  int noSubscriptions = inMsg.readInt();
369  for (int s = 0; s < noSubscriptions; ++s) {
370  if (!validateSubscription(inMsg)) {
371  return false;
372  }
373  }
374  } catch (std::invalid_argument& e) {
375  answerLog << "#Error while reading message:" << e.what() << std::endl;
376  return false;
377  }
378  return true;
379 }
380 
381 
382 bool
384  try {
385  int length = inMsg.readUnsignedByte();
386  if (length == 0) {
387  length = inMsg.readInt();
388  }
389  int cmdId = inMsg.readUnsignedByte();
391  answerLog << " CommandID=" << cmdId;
392  answerLog << " ObjectID=" << inMsg.readString();
393  int varNo = inMsg.readUnsignedByte();
394  answerLog << " #variables=" << varNo << std::endl;
395  for (int i = 0; i < varNo; ++i) {
396  answerLog << " VariableID=" << inMsg.readUnsignedByte();
397  bool ok = inMsg.readUnsignedByte() == RTYPE_OK;
398  answerLog << " ok=" << ok;
399  int valueDataType = inMsg.readUnsignedByte();
400  answerLog << " valueDataType=" << valueDataType;
401  readAndReportTypeDependent(inMsg, valueDataType);
402  }
404  answerLog << " CommandID=" << cmdId;
405  answerLog << " ObjectID=" << inMsg.readString();
406  answerLog << " Domain=" << inMsg.readUnsignedByte();
407  int varNo = inMsg.readUnsignedByte();
408  answerLog << " #variables=" << varNo << std::endl;
409  int objNo = inMsg.readInt();
410  answerLog << " #objects=" << objNo << std::endl;
411  for (int j = 0; j < objNo; ++j) {
412  answerLog << " ObjectID=" << inMsg.readString() << std::endl;
413  for (int i = 0; i < varNo; ++i) {
414  answerLog << " VariableID=" << inMsg.readUnsignedByte();
415  bool ok = inMsg.readUnsignedByte() == RTYPE_OK;
416  answerLog << " ok=" << ok;
417  int valueDataType = inMsg.readUnsignedByte();
418  answerLog << " valueDataType=" << valueDataType;
419  readAndReportTypeDependent(inMsg, valueDataType);
420  }
421  }
422  } else {
423  answerLog << "#Error: received response with command id: " << cmdId << " but expected a subscription response (0xe0-0xef / 0x90-0x9f)" << std::endl;
424  return false;
425  }
426  } catch (std::invalid_argument& e) {
427  answerLog << "#Error while reading message:" << e.what() << std::endl;
428  return false;
429  }
430  return true;
431 }
432 
433 
434 
435 
436 
437 
438 
439 // ---------- Conversion helper
440 int
441 TraCITestClient::setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg) {
442  std::string dataTypeS;
443  defFile >> dataTypeS;
444  if (dataTypeS == "<airDist>") {
446  return 1;
447  } else if (dataTypeS == "<drivingDist>") {
449  return 1;
450  } else if (dataTypeS == "<objSubscription>") {
451  int beginTime, endTime, numVars;
452  defFile >> beginTime >> endTime >> numVars;
453  into.writeInt(beginTime);
454  into.writeInt(endTime);
455  into.writeInt(numVars);
456  for (int i = 0; i < numVars; ++i) {
457  int var;
458  defFile >> var;
459  into.writeUnsignedByte(var);
460  }
461  return 4 + 4 + 4 + numVars;
462  }
463  int valI;
464  double valF;
465  if (dataTypeS == "<int>") {
466  defFile >> valI;
468  into.writeInt(valI);
469  return 4 + 1;
470  } else if (dataTypeS == "<byte>") {
471  defFile >> valI;
473  into.writeByte(valI);
474  return 1 + 1;
475  } else if (dataTypeS == "<ubyte>") {
476  defFile >> valI;
478  into.writeUnsignedByte(valI);
479  return 1 + 1;
480  } else if (dataTypeS == "<float>") {
481  defFile >> valF;
483  into.writeFloat(float(valF));
484  return 4 + 1;
485  } else if (dataTypeS == "<double>") {
486  defFile >> valF;
488  into.writeDouble(valF);
489  return 8 + 1;
490  } else if (dataTypeS == "<string>") {
491  std::string valueS;
492  defFile >> valueS;
493  if (valueS == "\"\"") {
494  valueS = "";
495  }
497  into.writeString(valueS);
498  return 4 + 1 + (int) valueS.length();
499  } else if (dataTypeS == "<string*>") {
500  std::vector<std::string> slValue;
501  defFile >> valI;
502  int length = 1 + 4;
503  for (int i = 0; i < valI; ++i) {
504  std::string tmp;
505  defFile >> tmp;
506  slValue.push_back(tmp);
507  length += 4 + int(tmp.length());
508  }
510  into.writeStringList(slValue);
511  return length;
512  } else if (dataTypeS == "<compound>") {
513  defFile >> valI;
515  into.writeInt(valI);
516  int length = 1 + 4;
517  for (int i = 0; i < valI; ++i) {
518  length += setValueTypeDependant(into, defFile, msg);
519  }
520  return length;
521  } else if (dataTypeS == "<color>") {
522  defFile >> valI;
524  into.writeUnsignedByte(valI);
525  for (int i = 0; i < 3; ++i) {
526  defFile >> valI;
527  into.writeUnsignedByte(valI);
528  }
529  return 1 + 4;
530  } else if (dataTypeS == "<position2D>") {
531  defFile >> valF;
533  into.writeDouble(valF);
534  defFile >> valF;
535  into.writeDouble(valF);
536  return 1 + 8 + 8;
537  } else if (dataTypeS == "<position3D>") {
538  defFile >> valF;
540  into.writeDouble(valF);
541  defFile >> valF;
542  into.writeDouble(valF);
543  defFile >> valF;
544  into.writeDouble(valF);
545  return 1 + 8 + 8 + 8;
546  } else if (dataTypeS == "<positionRoadmap>") {
547  std::string valueS;
548  defFile >> valueS;
550  into.writeString(valueS);
551  int length = 1 + 8 + (int) valueS.length();
552  defFile >> valF;
553  into.writeDouble(valF);
554  defFile >> valI;
555  into.writeUnsignedByte(valI);
556  return length + 4 + 1;
557  } else if (dataTypeS == "<shape>") {
558  defFile >> valI;
560  into.writeUnsignedByte(valI);
561  int length = 1 + 1;
562  for (int i = 0; i < valI; ++i) {
563  double x, y;
564  defFile >> x >> y;
565  into.writeDouble(x);
566  into.writeDouble(y);
567  length += 8 + 8;
568  }
569  return length;
570  }
571  msg << "## Unknown data type: " << dataTypeS;
572  return 0;
573 }
574 
575 
576 void
578  if (valueDataType == TYPE_UBYTE) {
579  int ubyte = inMsg.readUnsignedByte();
580  answerLog << " Unsigned Byte Value: " << ubyte << std::endl;
581  } else if (valueDataType == TYPE_BYTE) {
582  int byte = inMsg.readByte();
583  answerLog << " Byte value: " << byte << std::endl;
584  } else if (valueDataType == TYPE_INTEGER) {
585  int integer = inMsg.readInt();
586  answerLog << " Int value: " << integer << std::endl;
587  } else if (valueDataType == TYPE_FLOAT) {
588  float floatv = inMsg.readFloat();
589  if (floatv < 0.1 && floatv > 0) {
590  answerLog.setf(std::ios::scientific, std::ios::floatfield);
591  }
592  answerLog << " float value: " << floatv << std::endl;
593  answerLog.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
594  answerLog.setf(std::ios::showpoint); // print decimal point
595  answerLog << std::setprecision(2);
596  } else if (valueDataType == TYPE_DOUBLE) {
597  double doublev = inMsg.readDouble();
598  answerLog << " Double value: " << doublev << std::endl;
599  } else if (valueDataType == TYPE_BOUNDINGBOX) {
600  double lowerLeftX = inMsg.readDouble();
601  double lowerLeftY = inMsg.readDouble();
602  double upperRightX = inMsg.readDouble();
603  double upperRightY = inMsg.readDouble();
604  answerLog << " BoundaryBoxValue: lowerLeft x=" << lowerLeftX
605  << " y=" << lowerLeftY << " upperRight x=" << upperRightX
606  << " y=" << upperRightY << std::endl;
607  } else if (valueDataType == TYPE_POLYGON) {
608  int length = inMsg.readUnsignedByte();
609  answerLog << " PolygonValue: ";
610  for (int i = 0; i < length; i++) {
611  double x = inMsg.readDouble();
612  double y = inMsg.readDouble();
613  answerLog << "(" << x << "," << y << ") ";
614  }
615  answerLog << std::endl;
616  } else if (valueDataType == POSITION_3D) {
617  double x = inMsg.readDouble();
618  double y = inMsg.readDouble();
619  double z = inMsg.readDouble();
620  answerLog << " Position3DValue: " << std::endl;
621  answerLog << " x: " << x << " y: " << y
622  << " z: " << z << std::endl;
623  } else if (valueDataType == POSITION_ROADMAP) {
624  std::string roadId = inMsg.readString();
625  double pos = inMsg.readDouble();
626  int laneId = inMsg.readUnsignedByte();
627  answerLog << " RoadMapPositionValue: roadId=" << roadId
628  << " pos=" << pos
629  << " laneId=" << laneId << std::endl;
630  } else if (valueDataType == TYPE_TLPHASELIST) {
631  int length = inMsg.readUnsignedByte();
632  answerLog << " TLPhaseListValue: length=" << length << std::endl;
633  for (int i = 0; i < length; i++) {
634  std::string pred = inMsg.readString();
635  std::string succ = inMsg.readString();
636  int phase = inMsg.readUnsignedByte();
637  answerLog << " precRoad=" << pred << " succRoad=" << succ
638  << " phase=";
639  switch (phase) {
640  case TLPHASE_RED:
641  answerLog << "red" << std::endl;
642  break;
643  case TLPHASE_YELLOW:
644  answerLog << "yellow" << std::endl;
645  break;
646  case TLPHASE_GREEN:
647  answerLog << "green" << std::endl;
648  break;
649  default:
650  answerLog << "#Error: unknown phase value" << (int)phase << std::endl;
651  return;
652  }
653  }
654  } else if (valueDataType == TYPE_STRING) {
655  std::string s = inMsg.readString();
656  answerLog << " string value: " << s << std::endl;
657  } else if (valueDataType == TYPE_STRINGLIST) {
658  std::vector<std::string> s = inMsg.readStringList();
659  answerLog << " string list value: [ " << std::endl;
660  for (std::vector<std::string>::iterator i = s.begin(); i != s.end(); ++i) {
661  if (i != s.begin()) {
662  answerLog << ", ";
663  }
664  answerLog << '"' << *i << '"';
665  }
666  answerLog << " ]" << std::endl;
667  } else if (valueDataType == TYPE_COMPOUND) {
668  int no = inMsg.readInt();
669  answerLog << " compound value with " << no << " members: [ " << std::endl;
670  for (int i = 0; i < no; ++i) {
671  int currentValueDataType = inMsg.readUnsignedByte();
672  answerLog << " valueDataType=" << currentValueDataType;
673  readAndReportTypeDependent(inMsg, currentValueDataType);
674  }
675  answerLog << " ]" << std::endl;
676  } else if (valueDataType == POSITION_2D) {
677  double xv = inMsg.readDouble();
678  double yv = inMsg.readDouble();
679  answerLog << " position value: (" << xv << "," << yv << ")" << std::endl;
680  } else if (valueDataType == TYPE_COLOR) {
681  int r = inMsg.readUnsignedByte();
682  int g = inMsg.readUnsignedByte();
683  int b = inMsg.readUnsignedByte();
684  int a = inMsg.readUnsignedByte();
685  answerLog << " color value: (" << r << "," << g << "," << b << "," << a << ")" << std::endl;
686  } else {
687  answerLog << "#Error: unknown valueDataType!" << std::endl;
688  }
689 }
690 
691 
692 void
694  answerLog << "testAPI:\n";
695  answerLog << " setOrder:\n";
696  setOrder(0);
697  // edge
698  answerLog << " edge:\n";
699  answerLog << " getIDList: " << joinToString(edge.getIDList(), " ") << "\n";
700  answerLog << " getIDCount: " << edge.getIDCount() << "\n";
701  const std::string edgeID = "e_m0";
702  edge.adaptTraveltime(edgeID, 42, 0, 10);
703  edge.setEffort(edgeID, 420, 0, 10);
704  answerLog << " currentTraveltime: " << edge.getTraveltime(edgeID) << "\n";
705  answerLog << " adaptedTravelTime: " << edge.getAdaptedTraveltime(edgeID, 0) << "\n";
706  answerLog << " effort: " << edge.getEffort(edgeID, 0) << "\n";
707 
708  // lane
709  answerLog << " lane:\n";
710  answerLog << " getIDList: " << joinToString(lane.getIDList(), " ") << "\n";
711  answerLog << " getIDCount: " << lane.getIDCount() << "\n";
712  const std::string laneID = "e_m6_0";
713  answerLog << " getLinkNumber: " << lane.getLinkNumber(laneID) << "\n";
714  std::vector<TraCIConnection> connections = lane.getLinks(laneID);
715  answerLog << " getLinks:\n";
716  for (int i = 0; i < (int)connections.size(); ++i) {
717  const TraCIConnection& c = connections[i];
718  answerLog << " approachedLane=" << c.approachedLane
719  << " hasPrio=" << c.hasPrio
720  << " isOpen=" << c.isOpen
721  << " hasFoe=" << c.hasFoe
722  << " approachedInternal=" << c.approachedInternal
723  << " state=" << c.state
724  << " direction=" << c.direction
725  << " length=" << c.length
726  << "\n";
727  }
728  answerLog << " getFoes: " << joinToString(lane.getFoes("e_vu0_0", "e_m4_0"), " ") << "\n";
729  try {
730  answerLog << " getFoes (invalid): " << joinToString(lane.getFoes("e_vu0_0", "e_m4_1"), " ") << "\n";
731  } catch (tcpip::SocketException&) {}
732  answerLog << " getInternalFoes: " << joinToString(lane.getInternalFoes(":n_m4_2_0"), " ") << "\n";
733  try {
734  answerLog << " getInternalFoes (invalid): " << joinToString(lane.getInternalFoes("dummy"), " ") << "\n";
735  } catch (tcpip::SocketException&) {}
736 
737  // route
738  answerLog << " route:\n";
739  answerLog << " add:\n";
740  std::vector<std::string> edges;
741  edges.push_back("e_u1");
742  edges.push_back("e_u0");
743  route.add("e_u1", edges);
744  edges.clear();
745  edges.push_back("e_m4");
746  route.add("e_m4", edges);
747  answerLog << " getIDList: " << joinToString(route.getIDList(), " ") << "\n";
748 
749  // vehicletype
750  answerLog << " vehicleType:\n";
751  answerLog << " getIDList: " << joinToString(vehicletype.getIDList(), " ") << "\n";
752  vehicletype.setEmergencyDecel("t1", 9.9);
753  answerLog << " getEmergencyDecel: " << vehicletype.getEmergencyDecel("t1") << "\n";
754  vehicletype.setApparentDecel("t1", 99.9);
755  answerLog << " getApparentDecel: " << vehicletype.getApparentDecel("t1") << "\n";
756  vehicletype.setWidth("t1", 1.9);
757  answerLog << " getWidth: " << vehicletype.getWidth("t1") << "\n";
758  vehicletype.setHeight("t1", 1.8);
759  answerLog << " getHeight: " << vehicletype.getHeight("t1") << "\n";
760  vehicletype.setMinGapLat("t1", 1.5);
761  answerLog << " setMinGapLat: " << vehicletype.getMinGapLat("t1") << "\n";
762  vehicletype.setMaxSpeedLat("t1", 1.2);
763  answerLog << " setMaxSpeedLat: " << vehicletype.getMaxSpeedLat("t1") << "\n";
764  vehicletype.setLateralAlignment("t1", "compact");
765  answerLog << " getLateralAlignment: " << vehicletype.getLateralAlignment("t1") << "\n";
766  answerLog << " copy type 't1' to 't1_copy' and set accel to 100.\n";
767  vehicletype.copy("t1", "t1_copy");
768  answerLog << " getIDList: " << joinToString(vehicletype.getIDList(), " ") << "\n";
769  vehicletype.setAccel("t1_copy", 100.);
770  answerLog << " getAccel('t1'): " << vehicletype.getAccel("t1") << "\n";
771  answerLog << " getAccel('t1_copy'): " << vehicletype.getAccel("t1_copy") << "\n";
772 
773  // vehicle
774  answerLog << " vehicle:\n";
775  vehicle.setLine("0", "S42");
776  std::vector<std::string> via;
777  via.push_back("e_shape1");
778  vehicle.setVia("0", via);
779  vehicle.setType("0", "t1_copy");
780  answerLog << " getTypeID: " << vehicle.getTypeID("0") << "\n";
781  answerLog << " getRoadID: " << vehicle.getRoadID("0") << "\n";
782  answerLog << " getRouteID: " << vehicle.getRouteID("0") << "\n";
783  answerLog << " getLaneID: " << vehicle.getLaneID("0") << "\n";
784  answerLog << " getLanePosition: " << vehicle.getLanePosition("0") << "\n";
785  answerLog << " getLateralLanePosition: " << vehicle.getLateralLanePosition("0") << "\n";
786  answerLog << " getSpeedMode: " << vehicle.getSpeedMode("0") << "\n";
787  answerLog << " getSlope: " << vehicle.getSlope("0") << "\n";
788  answerLog << " getLine: " << vehicle.getLine("0") << "\n";
789  answerLog << " getVia: " << joinToString(vehicle.getVia("0"), ",") << "\n";
790  vehicle.setMaxSpeed("0", 30);
791  answerLog << " getMaxSpeed: " << vehicle.getMaxSpeed("0") << "\n";
792  answerLog << " isRouteValid: " << vehicle.isRouteValid("0") << "\n";
793  TraCIColor col1;
794  col1.r = 255;
795  col1.g = 255;
796  col1.b = 0;
797  col1.a = 128;
798  vehicle.setColor("0", col1);
799  TraCIColor col2 = vehicle.getColor("0");
800  answerLog << " getColor: r=" << (int)col2.r << " g=" << (int)col2.g << " b=" << (int)col2.b << " a=" << (int)col2.a << "\n";
801  answerLog << " getNextTLS:\n";
802  std::vector<TraCINextTLSData> result = vehicle.getNextTLS("0");
803  for (int i = 0; i < (int)result.size(); ++i) {
804  const TraCINextTLSData& d = result[i];
805  answerLog << " tls=" << d.id << " tlIndex=" << d.tlIndex << " dist=" << d.dist << " state=" << d.state << "\n";
806  }
807  answerLog << " moveToXY, simStep:\n";
808  vehicle.moveToXY("0", "dummy", 0, 2231.61, 498.29, 90, 1);
809  simulationStep();
810  answerLog << " getRoadID: " << vehicle.getRoadID("0") << "\n";
811  answerLog << " getLaneID: " << vehicle.getLaneID("0") << "\n";
812  vehicle.changeTarget("0", "e_o0");
813  std::vector<std::string> edges2 = vehicle.getEdges("0");
814  answerLog << " edges: " << joinToString(edges2, " ") << "\n";
815  vehicle.setRouteID("0", "e_m4");
816  answerLog << " edges: " << joinToString(vehicle.getEdges("0"), " ") << "\n";
817  vehicle.setRoute("0", edges2);
818  answerLog << " edges: " << joinToString(vehicle.getEdges("0"), " ") << "\n";
819  answerLog << " add:\n";
820  vehicle.add("1", "e_u1");
821  vehicle.add("2", "e_u1");
822  vehicle.moveTo("2", "e_u0_0", 5);
823  simulationStep();
824  answerLog << " getIDList: " << joinToString(vehicle.getIDList(), " ") << "\n";
825  answerLog << " getWaitingTime: " << vehicle.getWaitingTime("0") << "\n";
826  answerLog << " getAccumulatedWaitingTime: " << vehicle.getAccumulatedWaitingTime("0") << "\n";
827  vehicle.setShapeClass("0", "bicycle");
828  answerLog << " getShapeClass: " << vehicle.getShapeClass("0") << "\n";
829  std::pair<std::string, double> leader = vehicle.getLeader("1", 1000);
830  answerLog << " getLeader: " << leader.first << ", " << leader.second << "\n";
832  answerLog << " remove:\n";
833  vehicle.remove("0");
834  answerLog << " getIDCount: " << vehicle.getIDCount() << "\n";
835 
836  // inductionLoop
837  answerLog << " inductionloop:\n";
838  answerLog << " getIDList: " << joinToString(inductionloop.getIDList(), " ") << "\n";
839  answerLog << " getVehicleData:\n";
840  std::vector<TraCIVehicleData> result2 = inductionloop.getVehicleData("det1");
841  for (int i = 0; i < (int)result2.size(); ++i) {
842  const TraCIVehicleData& vd = result2[i];
843  answerLog << " veh=" << vd.id << " length=" << vd.length << " entered=" << vd.entryTime << " left=" << vd.leaveTime << " type=" << vd.typeID << "\n";
844  }
845 
846  // simulaton
847  answerLog << " simulation:\n";
848  answerLog << " getCurrentTime: " << simulation.getCurrentTime() << "\n";
849  answerLog << " subscribe to road and pos of vehicle '1':\n";
850  std::vector<int> vars;
851  vars.push_back(VAR_ROAD_ID);
852  vars.push_back(VAR_LANEPOSITION);
854  simulationStep();
855  answerLog << " subscription results:\n";
857  answerLog << " roadID=" << result3[VAR_ROAD_ID].string << " pos=" << result3[VAR_LANEPOSITION].scalar << "\n";
858 
859  answerLog << " subscribe to vehicles around edge 'e_u1':\n";
860  std::vector<int> vars2;
861  vars2.push_back(VAR_LANEPOSITION);
863  simulationStep();
864  answerLog << " context subscription results:\n";
866  for (SubscribedValues::iterator it = result4.begin(); it != result4.end(); ++it) {
867  answerLog << " vehicle=" << it->first << " pos=" << it->second[VAR_LANEPOSITION].scalar << "\n";
868  }
869 
870  // person
871  answerLog << " person:\n";
872  person.setWidth("p0", 1);
873  person.setMinGap("p0", 2);
874  person.setLength("p0", 3);
875  person.setHeight("p0", 4);
876  person.setColor("p0", col1);
877  person.setType("p0", "stilts");
878  answerLog << " getIDList: " << joinToString(person.getIDList(), " ") << "\n";
879  answerLog << " getRoadID: " << person.getRoadID("p0") << "\n";
880  answerLog << " getTypeID: " << person.getTypeID("p0") << "\n";
881  answerLog << " getWaitingTime: " << person.getWaitingTime("p0") << "\n";
882  answerLog << " getNextEdge: " << person.getNextEdge("p0") << "\n";
883  answerLog << " getStage: " << person.getStage("p0") << "\n";
884  answerLog << " getRemainingStages: " << person.getRemainingStages("p0") << "\n";
885  answerLog << " getVehicle: " << person.getVehicle("p0") << "\n";
886  answerLog << " getEdges: " << joinToString(person.getEdges("p0"), " ") << "\n";
887  person.setSpeed("p0", 3);
888  simulationStep();
889  answerLog << " getSpeed: " << person.getSpeed("p0") << "\n";
890  person.add("p1", "e_u1", 10);
891  std::vector<std::string> walkEdges;
892  walkEdges.push_back("e_u1");
893  walkEdges.push_back("e_shape1");
894  person.appendWalkingStage("p1", walkEdges, -20);
895  person.appendWaitingStage("p1", 5);
896  person.appendDrivingStage("p1", "e_vu2", "BusLine42");
897  // expect 4 stages due to the initial waiting-for-departure stage
898  answerLog << " getRemainingStages: " << person.getRemainingStages("p1") << "\n";
899  person.removeStage("p1", 3);
900  answerLog << " getRemainingStages: " << person.getRemainingStages("p1") << "\n";
901  person.removeStages("p1");
902  answerLog << " getRemainingStages: " << person.getRemainingStages("p1") << "\n";
903  answerLog << " getStage: " << person.getStage("p1") << "\n";
904  walkEdges.push_back("e_m5");
905  person.appendWalkingStage("p1", walkEdges, -20);
906  simulationStep();
908  answerLog << " getEdges after rerouting: " << joinToString(person.getEdges("p1"), " ") << "\n";
909 
910  // trafficlights
911  answerLog << " trafficlights:\n";
912  answerLog << " getIDList: " << joinToString(trafficlights.getIDList(), " ") << "\n";
913  answerLog << " state: " << trafficlights.getRedYellowGreenState("n_m4") << "\n";
914  answerLog << " program: " << trafficlights.getProgram("n_m4") << "\n";
915  answerLog << " phase: " << trafficlights.getPhase("n_m4") << "\n";
916  answerLog << " nextSwitch: " << trafficlights.getNextSwitch("n_m4") << "\n";
917  answerLog << " controlledLanes: " << joinToString(trafficlights.getControlledLanes("n_m4"), " ") << "\n";
918  std::vector<std::vector<TraCILink> > links = trafficlights.getControlledLinks("n_m4");
919  answerLog << " controlledLinks:\n";
920  for (int i = 0; i < (int)links.size(); ++i) {
921  for (int j = 0; j < (int)links[i].size(); ++j) {
922  answerLog << " index=" << i << " link=" << j << " from=" << links[i][j].from << " via=" << links[i][j].via << " to=" << links[i][j].to << "\n";
923  }
924  }
925  std::vector<TraCILogic> logics = trafficlights.getCompleteRedYellowGreenDefinition("n_m4");
926  answerLog << " completeDefinition:\n";
927  for (int i = 0; i < (int)logics.size(); ++i) {
928  answerLog << " subID=" << logics[i].subID << " type=" << logics[i].type << " phase=" << logics[i].currentPhaseIndex << "\n";
929  answerLog << " params=" << joinToString(logics[i].subParameter, " ", ":") << "\n";
930  for (int j = 0; j < (int)logics[i].phases.size(); ++j) {
931  answerLog << " phase=" << logics[i].phases[j].phase
932  << " dur=" << logics[i].phases[j].duration
933  << " minDur=" << logics[i].phases[j].duration1
934  << " maxDur=" << logics[i].phases[j].duration2
935  << "\n";
936  }
937  }
938  answerLog << " load:\n";
939  std::vector<std::string> args;
940  args.push_back("-n");
941  args.push_back("net.net.xml");
942  args.push_back("-r");
943  args.push_back("input_routes.rou.xml");
944  args.push_back("--no-step-log");
945  load(args);
946  simulationStep();
947  answerLog << " getCurrentTime: " << simulation.getCurrentTime() << "\n";
950 
951  answerLog << " gui:\n";
952  try {
953  answerLog << " setScheme: \n";
954  gui.setSchema("View #0", "real world");
955  answerLog << " getScheme: " << gui.getSchema("View #0") << "\n";
956  answerLog << " take screenshot: \n";
957  gui.screenshot("View #0", "image.png");
958  } catch (tcpip::SocketException&) {
959  answerLog << " no support for gui commands\n";
960  }
961 }
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:798
#define VAR_ROAD_ID
int run(std::string fileName, int port, std::string host="localhost")
Runs a test.
unsigned char g
Definition: TraCIDefs.h:79
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1615
std::string getRouteID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2174
#define RESPONSE_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
void setAccel(const std::string &typeID, double accel) const
Definition: TraCIAPI.cpp:2039
void setRoute(const std::string &vehicleID, const std::vector< std::string > &edge) const
Definition: TraCIAPI.cpp:2569
std::vector< libsumo::TraCILogic > getCompleteRedYellowGreenDefinition(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1625
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1461
std::string id
The id of the next tls.
Definition: TraCIDefs.h:181
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:180
void remove(const std::string &vehicleID, char reason=REMOVE_VAPORIZED) const
Definition: TraCIAPI.cpp:2537
void setMinGapLat(const std::string &typeID, double minGapLat) const
Definition: TraCIAPI.cpp:1989
int getNextSwitch(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1707
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:173
void readAndReportTypeDependent(tcpip::Storage &inMsg, int valueDataType)
Reads a value of the given type from the given storage and reports it.
void screenshot(const std::string &viewID, const std::string &filename) const
Definition: TraCIAPI.cpp:853
void setWidth(const std::string &typeID, double width) const
Definition: TraCIAPI.cpp:1958
void setColor(const std::string &vehicleID, const libsumo::TraCIColor &c) const
Definition: TraCIAPI.cpp:2671
void appendDrivingStage(const std::string &personID, const std::string &toEdge, const std::string &lines, const std::string &stopID="")
Definition: TraCIAPI.cpp:2886
#define REQUEST_DRIVINGDIST
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:979
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:279
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:67
double dist
The distance to the tls.
Definition: TraCIDefs.h:185
void setLength(const std::string &personID, double length) const
Definition: TraCIAPI.cpp:2936
std::string typeID
Type of the vehicle in.
Definition: TraCIDefs.h:175
void changeTarget(const std::string &vehicleID, const std::string &edgeID) const
Definition: TraCIAPI.cpp:2548
void setOrder(int order)
set priority (execution order) for the client
Definition: TraCIAPI.cpp:80
#define CMD_GET_VEHICLE_VARIABLE
#define TYPE_COMPOUND
std::vector< libsumo::TraCIConnection > getLinks(const std::string &laneID) const
Definition: TraCIAPI.cpp:1019
void commandSetOrder(int order)
Sends and validates a SetOrder command.
SUMOTime getCurrentTime() const
Definition: TraCIAPI.cpp:1489
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:2694
virtual std::vector< std::string > readStringList()
#define RESPONSE_SUBSCRIBE_GUI_VARIABLE
#define POSITION_2D
void commandSubscribeObjectVariable(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeVariable command.
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:165
void setRouteID(const std::string &vehicleID, const std::string &routeID) const
Definition: TraCIAPI.cpp:2558
void testAPI()
call all API methods once
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.
libsumo::TraCIColor getColor(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2194
std::vector< libsumo::TraCINextTLSData > getNextTLS(const std::string &vehID) const
Definition: TraCIAPI.cpp:2291
double getWaitingTime(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2254
#define TYPE_UBYTE
#define RTYPE_OK
std::string getTypeID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2169
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:153
#define POSITION_ROADMAP
double getEmergencyDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1825
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:806
virtual double readDouble()
#define TYPE_POLYGON
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:812
int getIDCount() const
Definition: TraCIAPI.cpp:2124
double getMaxSpeedLat(const std::string &typeID) const
Definition: TraCIAPI.cpp:1870
void rerouteTraveltime(const std::string &vehicleID, bool currentTravelTimes=true) const
Definition: TraCIAPI.cpp:2583
void setMaxSpeedLat(const std::string &typeID, double speed) const
Definition: TraCIAPI.cpp:1999
double getMaxSpeed(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2134
void setLine(const std::string &vehicleID, const std::string &line) const
Definition: TraCIAPI.cpp:2684
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:2154
void appendWaitingStage(const std::string &personID, double duration, const std::string &description="waiting", const std::string &stopID="")
Definition: TraCIAPI.cpp:2842
#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:604
double getSpeed(const std::string &personID) const
Definition: TraCIAPI.cpp:2744
void send_commandSetOrder(int order) const
Sends a SetOrder command.
Definition: TraCIAPI.cpp:140
#define POSITION_3D
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:105
void simulationStep(SUMOTime time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:583
std::string getNextEdge(const std::string &personID) const
Definition: TraCIAPI.cpp:2769
std::string outputFileName
The name of the file to write the results log into.
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
virtual void writeUnsignedByte(int)
std::string getRedYellowGreenState(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1620
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:822
int getPhase(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1702
std::string getLine(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2271
void removeStage(const std::string &personID, int nextStageIndex) const
Definition: TraCIAPI.cpp:2904
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:802
virtual void writeInt(int)
std::vector< std::string > getEdges(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2184
#define TLPHASE_RED
#define TYPE_STRING
virtual int readUnsignedByte()
std::vector< libsumo::TraCIVehicleData > getVehicleData(const std::string &loopID) const
Definition: TraCIAPI.cpp:924
#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:79
const SubscribedValues & getSubscriptionResults() const
Definition: TraCIAPI.cpp:1580
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:2619
#define TLPHASE_YELLOW
void rerouteTraveltime(const std::string &personID) const
Definition: TraCIAPI.cpp:2811
#define TYPE_FLOAT
#define TYPE_TLPHASELIST
std::string getShapeClass(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2286
std::string getTypeID(const std::string &personID) const
Definition: TraCIAPI.cpp:2759
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:879
void setHeight(const std::string &personID, double height) const
Definition: TraCIAPI.cpp:2957
std::vector< std::string > getVia(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2276
std::map< std::string, TraCIValues > SubscribedValues
Definition: TraCIAPI.h:468
void setType(const std::string &vehicleID, const std::string &typeID) const
Definition: TraCIAPI.cpp:2651
std::string approachedInternal
Definition: TraCIDefs.h:157
virtual int readInt()
#define VAR_LANEPOSITION
void writeResult()
Writes the results file.
void send_commandSubscribeObjectVariable(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, const std::vector< int > &vars) const
Sends a SubscribeVariable request.
Definition: TraCIAPI.cpp:201
double getAccumulatedWaitingTime(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2436
virtual void writeByte(int)
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:818
std::map< int, libsumo::TraCIValue > TraCIValues
{object->{variable->value}}
Definition: TraCIAPI.h:467
#define TYPE_BOUNDINGBOX
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:116
virtual const char * what() const
Definition: socket.h:70
double getLateralLanePosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2209
unsigned char a
Definition: TraCIDefs.h:79
virtual void writeStringList(const std::vector< std::string > &s)
void setLateralAlignment(const std::string &typeID, const std::string &latAlignment) const
Definition: TraCIAPI.cpp:2009
int getIDCount() const
Definition: TraCIAPI.cpp:630
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
double length
Length of the vehicle.
Definition: TraCIDefs.h:169
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:2821
double getWaitingTime(const std::string &personID) const
Definition: TraCIAPI.cpp:2764
std::string getRoadID(const std::string &personID) const
Definition: TraCIAPI.cpp:2754
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:167
virtual std::string readString()
bool isRouteValid(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2456
unsigned char r
Definition: TraCIDefs.h:79
void add(const std::string &routeID, const std::vector< std::string > &edges) const
Definition: TraCIAPI.cpp:1472
std::string getProgram(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1697
#define CMD_SUBSCRIBE_EDGE_CONTEXT
void setWidth(const std::string &personID, double width) const
Definition: TraCIAPI.cpp:2947
void setSpeed(const std::string &personID, double speed) const
Definition: TraCIAPI.cpp:2915
void setShapeClass(const std::string &vehicleID, const std::string &clazz) const
Definition: TraCIAPI.cpp:2708
std::string getVehicle(const std::string &personID) const
Definition: TraCIAPI.cpp:2775
std::string approachedLane
Definition: TraCIDefs.h:153
Definition: Edge.cpp:31
TraCITestClient(std::string outputFileName="testclient_result.out")
Constructor.
virtual void writeFloat(float)
const SubscribedContextValues & getContextSubscriptionResults() const
Definition: TraCIAPI.cpp:1596
double getEffort(const std::string &edgeID, SUMOTime time) const
Definition: TraCIAPI.cpp:643
int getRemainingStages(const std::string &personID) const
Definition: TraCIAPI.cpp:2780
double getSlope(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2265
void errorMsg(std::stringstream &msg)
Writes an error message.
#define TLPHASE_GREEN
#define RESPONSE_SUBSCRIBE_GUI_CONTEXT
void commandSubscribeContextVariable(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:820
std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist) const
Definition: TraCIAPI.cpp:2359
virtual void writeString(const std::string &s)
void setMaxSpeed(const std::string &vehicleID, double speed) const
Definition: TraCIAPI.cpp:2661
void setColor(const std::string &personID, const libsumo::TraCIColor &c) const
Definition: TraCIAPI.cpp:2978
#define REQUEST_AIRDIST
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:824
void adaptTraveltime(const std::string &edgeID, double time, int beginSeconds=0, int endSeconds=std::numeric_limits< int >::max()) const
Definition: TraCIAPI.cpp:729
#define TYPE_DOUBLE
#define CMD_SUBSCRIBE_VEHICLE_VARIABLE
double getHeight(const std::string &typeID) const
Definition: TraCIAPI.cpp:1885
std::vector< std::string > getControlledLanes(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1664
int getLinkNumber(const std::string &laneID) const
Definition: TraCIAPI.cpp:1014
virtual float readFloat()
char state
The current state of the tls.
Definition: TraCIDefs.h:187
#define TYPE_BYTE
void setEmergencyDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2059
void commandClose()
Sends and validates a Close command.
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:129
void copy(const std::string &origTypeID, const std::string &newTypeID) const
Definition: TraCIAPI.cpp:2019
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:318
int getSpeedMode(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2259
int getIDCount() const
Definition: TraCIAPI.cpp:984
void setSchema(const std::string &viewID, const std::string &schemeName) const
Definition: TraCIAPI.cpp:830
void setEffort(const std::string &edgeID, double effort, int beginSeconds=0, int endSeconds=std::numeric_limits< int >::max()) const
Definition: TraCIAPI.cpp:749
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1790
virtual void writeDouble(double)
double getTraveltime(const std::string &edgeID) const
Definition: TraCIAPI.cpp:707
#define CMD_SETORDER
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:800
void setMinGap(const std::string &personID, double minGap) const
Definition: TraCIAPI.cpp:2967
void subscribe(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, const std::vector< int > &vars) const
Definition: TraCIAPI.cpp:1559
void subscribeContext(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector< int > &vars) const
Definition: TraCIAPI.cpp:1570
std::string getLateralAlignment(const std::string &typeID) const
Definition: TraCIAPI.cpp:1875
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:2861
double getApparentDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1830
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:625
void setHeight(const std::string &typeID, double height) const
Definition: TraCIAPI.cpp:1968
std::string getLaneID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2159
long long int SUMOTime
Definition: TraCIDefs.h:51
std::vector< std::vector< libsumo::TraCILink > > getControlledLinks(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1669
int getStage(const std::string &personID, int nextStageIndex=0) const
Definition: TraCIAPI.cpp:2785
double getLanePosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2199
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:171
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:2801
double getAccel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1815
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:2476
void commandSimulationStep(SUMOTime time)
Sends and validates a simulation step command.
double getAdaptedTraveltime(const std::string &edgeID, double time) const
Definition: TraCIAPI.cpp:635
#define TYPE_INTEGER
void setType(const std::string &personID, const std::string &typeID) const
Definition: TraCIAPI.cpp:2926
void moveTo(const std::string &vehicleID, const std::string &laneID, double position) const
Definition: TraCIAPI.cpp:2605
void send_commandSubscribeObjectContext(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector< int > &vars) const
Sends a SubscribeContext request.
Definition: TraCIAPI.cpp:229
std::vector< std::string > getEdges(const std::string &personID, int nextStageIndex=0) const
Definition: TraCIAPI.cpp:2793
std::vector< std::string > getInternalFoes(const std::string &laneID) const
Definition: TraCIAPI.cpp:1171
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:183
std::vector< std::string > getFoes(const std::string &laneID, const std::string &toLaneID) const
Definition: TraCIAPI.cpp:1155
double getWidth(const std::string &typeID) const
Definition: TraCIAPI.cpp:1880
double getMinGapLat(const std::string &typeID) const
Definition: TraCIAPI.cpp:1865
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:236
#define CMD_SIMSTEP
virtual int readByte()
~TraCITestClient()
Destructor.
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:2734
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:2119
std::string getSchema(const std::string &viewID=DEFAULT_VIEW) const
Definition: TraCIAPI.cpp:799
void setApparentDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2069
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:826