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 length = inMsg.readUnsignedByte();
579  answerLog << " PolygonValue: ";
580  for (int i = 0; i < length; i++) {
581  double x = inMsg.readDouble();
582  double y = inMsg.readDouble();
583  answerLog << "(" << x << "," << y << ") ";
584  }
585  answerLog << std::endl;
586  } else if (valueDataType == POSITION_3D) {
587  double x = inMsg.readDouble();
588  double y = inMsg.readDouble();
589  double z = inMsg.readDouble();
590  answerLog << " Position3DValue: " << std::endl;
591  answerLog << " x: " << x << " y: " << y
592  << " z: " << z << std::endl;
593  } else if (valueDataType == POSITION_ROADMAP) {
594  std::string roadId = inMsg.readString();
595  double pos = inMsg.readDouble();
596  int laneId = inMsg.readUnsignedByte();
597  answerLog << " RoadMapPositionValue: roadId=" << roadId
598  << " pos=" << pos
599  << " laneId=" << laneId << std::endl;
600  } else if (valueDataType == TYPE_TLPHASELIST) {
601  int length = inMsg.readUnsignedByte();
602  answerLog << " TLPhaseListValue: length=" << length << std::endl;
603  for (int i = 0; i < length; i++) {
604  std::string pred = inMsg.readString();
605  std::string succ = inMsg.readString();
606  int phase = inMsg.readUnsignedByte();
607  answerLog << " precRoad=" << pred << " succRoad=" << succ
608  << " phase=";
609  switch (phase) {
610  case TLPHASE_RED:
611  answerLog << "red" << std::endl;
612  break;
613  case TLPHASE_YELLOW:
614  answerLog << "yellow" << std::endl;
615  break;
616  case TLPHASE_GREEN:
617  answerLog << "green" << std::endl;
618  break;
619  default:
620  answerLog << "#Error: unknown phase value" << (int)phase << std::endl;
621  return;
622  }
623  }
624  } else if (valueDataType == TYPE_STRING) {
625  std::string s = inMsg.readString();
626  answerLog << " string value: " << s << std::endl;
627  } else if (valueDataType == TYPE_STRINGLIST) {
628  std::vector<std::string> s = inMsg.readStringList();
629  answerLog << " string list value: [ " << std::endl;
630  for (std::vector<std::string>::iterator i = s.begin(); i != s.end(); ++i) {
631  if (i != s.begin()) {
632  answerLog << ", ";
633  }
634  answerLog << '"' << *i << '"';
635  }
636  answerLog << " ]" << std::endl;
637  } else if (valueDataType == TYPE_COMPOUND) {
638  int no = inMsg.readInt();
639  answerLog << " compound value with " << no << " members: [ " << std::endl;
640  for (int i = 0; i < no; ++i) {
641  int currentValueDataType = inMsg.readUnsignedByte();
642  answerLog << " valueDataType=" << currentValueDataType;
643  readAndReportTypeDependent(inMsg, currentValueDataType);
644  }
645  answerLog << " ]" << std::endl;
646  } else if (valueDataType == POSITION_2D) {
647  double xv = inMsg.readDouble();
648  double yv = inMsg.readDouble();
649  answerLog << " position value: (" << xv << "," << yv << ")" << std::endl;
650  } else if (valueDataType == TYPE_COLOR) {
651  int r = inMsg.readUnsignedByte();
652  int g = inMsg.readUnsignedByte();
653  int b = inMsg.readUnsignedByte();
654  int a = inMsg.readUnsignedByte();
655  answerLog << " color value: (" << r << "," << g << "," << b << "," << a << ")" << std::endl;
656  } else {
657  answerLog << "#Error: unknown valueDataType!" << std::endl;
658  }
659 }
660 
661 
662 void
664  answerLog << "testAPI:\n";
665  answerLog << " setOrder:\n";
666  setOrder(0);
667  // edge
668  answerLog << " edge:\n";
669  answerLog << " getIDList: " << joinToString(edge.getIDList(), " ") << "\n";
670  answerLog << " getIDCount: " << edge.getIDCount() << "\n";
671  const std::string edgeID = "e_m0";
672  edge.adaptTraveltime(edgeID, 42, 0, 10);
673  edge.setEffort(edgeID, 420, 0, 10);
674  answerLog << " currentTraveltime: " << edge.getTraveltime(edgeID) << "\n";
675  answerLog << " adaptedTravelTime: " << edge.getAdaptedTraveltime(edgeID, 0) << "\n";
676  answerLog << " effort: " << edge.getEffort(edgeID, 0) << "\n";
677  answerLog << " laneNumber: " << edge.getLaneNumber(edgeID) << "\n";
678  answerLog << " streetName: " << edge.getStreetName(edgeID) << "\n";
679 
680  // lane
681  answerLog << " lane:\n";
682  answerLog << " getIDList: " << joinToString(lane.getIDList(), " ") << "\n";
683  answerLog << " getIDCount: " << lane.getIDCount() << "\n";
684  const std::string laneID = "e_m6_0";
685  answerLog << " getLinkNumber: " << lane.getLinkNumber(laneID) << "\n";
686  std::vector<libsumo::TraCIConnection> connections = lane.getLinks(laneID);
687  answerLog << " getLinks:\n";
688  for (int i = 0; i < (int)connections.size(); ++i) {
689  const libsumo::TraCIConnection& c = connections[i];
690  answerLog << " approachedLane=" << c.approachedLane
691  << " hasPrio=" << c.hasPrio
692  << " isOpen=" << c.isOpen
693  << " hasFoe=" << c.hasFoe
694  << " approachedInternal=" << c.approachedInternal
695  << " state=" << c.state
696  << " direction=" << c.direction
697  << " length=" << c.length
698  << "\n";
699  }
700  answerLog << " getFoes: " << joinToString(lane.getFoes("e_vu0_0", "e_m4_0"), " ") << "\n";
701  try {
702  answerLog << " getFoes (invalid): ";
703  answerLog << joinToString(lane.getFoes("e_vu0_0", "e_m4_1"), " ") << "\n";
704  } catch (libsumo::TraCIException& e) {
705  answerLog << " caught TraCIException(" << e.what() << ")\n";
706  }
707  answerLog << " getInternalFoes: " << joinToString(lane.getInternalFoes(":n_m4_2_0"), " ") << "\n";
708  try {
709  answerLog << " getInternalFoes (invalid): ";
710  answerLog << joinToString(lane.getInternalFoes("dummy"), " ") << "\n";
711  } catch (libsumo::TraCIException& e) {
712  answerLog << " caught TraCIException(" << e.what() << ")\n";
713  }
714 
715  // route
716  answerLog << " route:\n";
717  answerLog << " add:\n";
718  std::vector<std::string> edges;
719  edges.push_back("e_u1");
720  edges.push_back("e_u0");
721  route.add("e_u1", edges);
722  edges.clear();
723  edges.push_back("e_m4");
724  route.add("e_m4", edges);
725  answerLog << " getIDList: " << joinToString(route.getIDList(), " ") << "\n";
726 
727  // vehicletype
728  answerLog << " vehicleType:\n";
729  answerLog << " getIDList: " << joinToString(vehicletype.getIDList(), " ") << "\n";
730  vehicletype.setEmergencyDecel("t1", 9.9);
731  answerLog << " getEmergencyDecel: " << vehicletype.getEmergencyDecel("t1") << "\n";
732  vehicletype.setApparentDecel("t1", 99.9);
733  answerLog << " getApparentDecel: " << vehicletype.getApparentDecel("t1") << "\n";
734  vehicletype.setWidth("t1", 1.9);
735  answerLog << " getWidth: " << vehicletype.getWidth("t1") << "\n";
736  vehicletype.setHeight("t1", 1.8);
737  answerLog << " getHeight: " << vehicletype.getHeight("t1") << "\n";
738  vehicletype.setMinGapLat("t1", 1.5);
739  answerLog << " setMinGapLat: " << vehicletype.getMinGapLat("t1") << "\n";
740  vehicletype.setMaxSpeedLat("t1", 1.2);
741  answerLog << " setMaxSpeedLat: " << vehicletype.getMaxSpeedLat("t1") << "\n";
742  vehicletype.setLateralAlignment("t1", "compact");
743  answerLog << " getLateralAlignment: " << vehicletype.getLateralAlignment("t1") << "\n";
744  answerLog << " copy type 't1' to 't1_copy' and set accel to 100.\n";
745  vehicletype.copy("t1", "t1_copy");
746  answerLog << " getIDList: " << joinToString(vehicletype.getIDList(), " ") << "\n";
747  vehicletype.setAccel("t1_copy", 100.);
748  answerLog << " getAccel('t1'): " << vehicletype.getAccel("t1") << "\n";
749  answerLog << " getAccel('t1_copy'): " << vehicletype.getAccel("t1_copy") << "\n";
750 
751  // vehicle
752  answerLog << " vehicle:\n";
753  vehicle.setLine("0", "S42");
754  std::vector<std::string> via;
755  via.push_back("e_shape1");
756  vehicle.setVia("0", via);
757  vehicle.setType("0", "t1_copy");
758  answerLog << " getTypeID: " << vehicle.getTypeID("0") << "\n";
759  answerLog << " getRoadID: " << vehicle.getRoadID("0") << "\n";
760  answerLog << " getRouteID: " << vehicle.getRouteID("0") << "\n";
761  answerLog << " getLaneID: " << vehicle.getLaneID("0") << "\n";
762  answerLog << " getLanePosition: " << vehicle.getLanePosition("0") << "\n";
763  answerLog << " getLateralLanePosition: " << vehicle.getLateralLanePosition("0") << "\n";
764  answerLog << " getSpeed: " << vehicle.getSpeed("0") << "\n";
765  answerLog << " getAcceleration: " << vehicle.getAcceleration("0") << "\n";
766  answerLog << " getSpeedMode: " << vehicle.getSpeedMode("0") << "\n";
767  answerLog << " getSlope: " << vehicle.getSlope("0") << "\n";
768  answerLog << " getLine: " << vehicle.getLine("0") << "\n";
769  answerLog << " getVia: " << joinToString(vehicle.getVia("0"), ",") << "\n";
770  vehicle.setMaxSpeed("0", 30);
771  answerLog << " getMaxSpeed: " << vehicle.getMaxSpeed("0") << "\n";
772  answerLog << " isRouteValid: " << vehicle.isRouteValid("0") << "\n";
773  vehicle.setParameter("0", "meaningOfLife", "42");
774  answerLog << " param: " << vehicle.getParameter("0", "meaningOfLife") << "\n";
775  libsumo::TraCIColor col1;
776  col1.r = 255;
777  col1.g = 255;
778  col1.b = 0;
779  col1.a = 128;
780  vehicle.setColor("0", col1);
782  answerLog << " getColor: r=" << (int)col2.r << " g=" << (int)col2.g << " b=" << (int)col2.b << " a=" << (int)col2.a << "\n";
783  int signals = vehicle.getSignals("0");
784  answerLog << " getSignals: " << signals << "\n";
787  answerLog << " getRoutingMode: " << vehicle.getRoutingMode("0") << "\n";
788  answerLog << " getNextTLS:\n";
789  std::vector<libsumo::TraCINextTLSData> result = vehicle.getNextTLS("0");
790  for (int i = 0; i < (int)result.size(); ++i) {
791  const libsumo::TraCINextTLSData& d = result[i];
792  answerLog << " tls=" << d.id << " tlIndex=" << d.tlIndex << " dist=" << d.dist << " state=" << d.state << "\n";
793  }
794  answerLog << " moveToXY, simStep:\n";
795  vehicle.moveToXY("0", "dummy", 0, 2231.61, 498.29, 90, 1);
796  simulationStep();
797  answerLog << " getRoadID: " << vehicle.getRoadID("0") << "\n";
798  answerLog << " getLaneID: " << vehicle.getLaneID("0") << "\n";
799  vehicle.changeTarget("0", "e_o0");
800  std::vector<std::string> edges2 = vehicle.getRoute("0");
801  answerLog << " edges: " << joinToString(edges2, " ") << "\n";
802  vehicle.setRouteID("0", "e_m4");
803  answerLog << " edges: " << joinToString(vehicle.getRoute("0"), " ") << "\n";
804  vehicle.setRoute("0", edges2);
805  answerLog << " edges: " << joinToString(vehicle.getRoute("0"), " ") << "\n";
806  answerLog << " add:\n";
807  vehicle.add("1", "e_u1");
808  vehicle.add("2", "e_u1");
809  vehicle.moveTo("2", "e_u0_0", 5);
810  simulationStep();
811  answerLog << " getIDList: " << joinToString(vehicle.getIDList(), " ") << "\n";
812  answerLog << " getWaitingTime: " << vehicle.getWaitingTime("0") << "\n";
813  answerLog << " getAccumulatedWaitingTime: " << vehicle.getAccumulatedWaitingTime("0") << "\n";
814  vehicle.setShapeClass("0", "bicycle");
815  answerLog << " getShapeClass: " << vehicle.getShapeClass("0") << "\n";
816  std::pair<std::string, double> leader = vehicle.getLeader("1", 1000);
817  answerLog << " getLeader: " << leader.first << ", " << leader.second << "\n";
818  std::pair<int, int> state = vehicle.getLaneChangeState("1", 1);
819  answerLog << " getLaneChangeState (left): " << state.first << ", " << state.second << "\n";
820  state = vehicle.getLaneChangeState("1", -1);
821  answerLog << " getLaneChangeState (right): " << state.first << ", " << state.second << "\n";
823  vehicle.setSpeedFactor("0", 0.8);
824  answerLog << " remove:\n";
825  vehicle.remove("0");
826  answerLog << " getIDCount: " << vehicle.getIDCount() << "\n";
827 
828  // inductionLoop
829  answerLog << " inductionloop:\n";
830  answerLog << " getIDList: " << joinToString(inductionloop.getIDList(), " ") << "\n";
831  answerLog << " getVehicleData:\n";
832  std::vector<libsumo::TraCIVehicleData> result2 = inductionloop.getVehicleData("det1");
833  for (int i = 0; i < (int)result2.size(); ++i) {
834  const libsumo::TraCIVehicleData& vd = result2[i];
835  answerLog << " veh=" << vd.id << " length=" << vd.length << " entered=" << vd.entryTime << " left=" << vd.leaveTime << " type=" << vd.typeID << "\n";
836  }
837 
838  // simulation
839  answerLog << " simulation:\n";
840  answerLog << " getDistance2D_air: " << simulation.getDistance2D(2500, 500, 2000, 500, false, false) << "\n";
841  answerLog << " getDistance2D_driving: " << simulation.getDistance2D(2500, 500, 2000, 500, false, true) << "\n";
842  answerLog << " getDistanceRoad_air: " << simulation.getDistanceRoad("e_m5", 0, "e_m4", 0, false) << "\n";
843  answerLog << " getDistanceRoad_driving: " << simulation.getDistanceRoad("e_m5", 0, "e_m4", 0, true) << "\n";
844  answerLog << " getCurrentTime: " << simulation.getCurrentTime() << "\n";
845  answerLog << " getDeltaT: " << simulation.getDeltaT() << "\n";
846  answerLog << " parkingArea param: " << simulation.getParameter("park1", "parkingArea.capacity") << "\n";
847  answerLog << " subscribe to road and pos of vehicle '1':\n";
848  std::vector<int> vars;
849  vars.push_back(VAR_ROAD_ID);
850  vars.push_back(VAR_LANEPOSITION);
851  vehicle.subscribe("1", vars, 0, 100);
852  simulationStep();
853  answerLog << " subscription results:\n";
855  answerLog << " roadID=" << result3[VAR_ROAD_ID]->getString() << " pos=" << result3[VAR_LANEPOSITION]->getString() << "\n";
856 
857  answerLog << " subscribe to vehicles around edge 'e_u1':\n";
858  std::vector<int> vars2;
859  vars2.push_back(VAR_LANEPOSITION);
860  edge.subscribeContext("e_u1", CMD_GET_VEHICLE_VARIABLE, 100, vars2, 0, 100);
861  simulationStep();
862  answerLog << " context subscription results:\n";
864  for (libsumo::SubscriptionResults::iterator it = result4.begin(); it != result4.end(); ++it) {
865  answerLog << " vehicle=" << it->first << " pos=" << it->second[VAR_LANEPOSITION]->getString() << "\n";
866  }
867 
868  // person
869  answerLog << " person:\n";
870  person.setWidth("p0", 1);
871  person.setMinGap("p0", 2);
872  person.setLength("p0", 3);
873  person.setHeight("p0", 4);
874  person.setColor("p0", col1);
875  person.setType("p0", "stilts");
876  answerLog << " getIDList: " << joinToString(person.getIDList(), " ") << "\n";
877  answerLog << " getRoadID: " << person.getRoadID("p0") << "\n";
878  answerLog << " getTypeID: " << person.getTypeID("p0") << "\n";
879  answerLog << " getWaitingTime: " << person.getWaitingTime("p0") << "\n";
880  answerLog << " getNextEdge: " << person.getNextEdge("p0") << "\n";
881  answerLog << " getStage: " << person.getStage("p0") << "\n";
882  answerLog << " getRemainingStages: " << person.getRemainingStages("p0") << "\n";
883  answerLog << " getVehicle: " << person.getVehicle("p0") << "\n";
884  answerLog << " getEdges: " << joinToString(person.getEdges("p0"), " ") << "\n";
885  person.setParameter("p0", "foo", "bar");
886  answerLog << " param: " << person.getParameter("p0", "foo") << "\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 << " getIDCount: " << trafficlights.getIDCount() << "\n";
914  answerLog << " state: " << trafficlights.getRedYellowGreenState("n_m4") << "\n";
915  answerLog << " program: " << trafficlights.getProgram("n_m4") << "\n";
916  answerLog << " phase: " << trafficlights.getPhase("n_m4") << "\n";
917  answerLog << " phaseDuration: " << trafficlights.getPhaseDuration("n_m4") << "\n";
918  answerLog << " nextSwitch: " << trafficlights.getNextSwitch("n_m4") << "\n";
919  answerLog << " controlledLanes: " << joinToString(trafficlights.getControlledLanes("n_m4"), " ") << "\n";
920  std::vector<std::vector<libsumo::TraCILink> > links = trafficlights.getControlledLinks("n_m4");
921  answerLog << " controlledLinks:\n";
922  for (int i = 0; i < (int)links.size(); ++i) {
923  for (int j = 0; j < (int)links[i].size(); ++j) {
924  answerLog << " index=" << i << " link=" << j << " fromLane=" << links[i][j].fromLane << " viaLane=" << links[i][j].viaLane << " toLane=" << links[i][j].toLane << "\n";
925  }
926  }
927  std::vector<libsumo::TraCIPhase> phases({ libsumo::TraCIPhase(5, 5, 5, "rrrrrrr"), libsumo::TraCIPhase(10, 5, 15, "ggggggg"),
928  libsumo::TraCIPhase(3, 3, 3, "GGGGGGG"), libsumo::TraCIPhase(3, 3, 3, "yyyyyyy")
929  });
931 
932  std::vector<libsumo::TraCILogic> logics = trafficlights.getCompleteRedYellowGreenDefinition("n_m4");
933  answerLog << " completeDefinition:\n";
934  for (int i = 0; i < (int)logics.size(); ++i) {
935  answerLog << " subID=" << logics[i].subID << " type=" << logics[i].type << " phase=" << logics[i].currentPhaseIndex << "\n";
936  answerLog << " params=" << joinToString(logics[i].subParameter, " ", ":") << "\n";
937  for (int j = 0; j < (int)logics[i].phases.size(); ++j) {
938  answerLog << " phase=" << logics[i].phases[j].phase
939  << " dur=" << logics[i].phases[j].duration
940  << " minDur=" << logics[i].phases[j].duration1
941  << " maxDur=" << logics[i].phases[j].duration2
942  << "\n";
943  }
944  }
945  simulationStep();
946  answerLog << " state=" << trafficlights.getRedYellowGreenState("n_m4") << "\n";
947  trafficlights.setRedYellowGreenState("n_m4", "gGyruoO");
948  answerLog << " stateSet=" << trafficlights.getRedYellowGreenState("n_m4") << "\n";
949  answerLog << " program: " << trafficlights.getProgram("n_m4") << "\n";
950 
951  answerLog << " load:\n";
952  std::vector<std::string> args;
953  args.push_back("-n");
954  args.push_back("net.net.xml");
955  args.push_back("-r");
956  args.push_back("input_routes.rou.xml");
957  args.push_back("--no-step-log");
958  load(args);
959  simulationStep();
960  answerLog << " getCurrentTime: " << simulation.getCurrentTime() << "\n";
961  vehicle.subscribe("0", vars, 0, TIME2STEPS(100));
962  edge.subscribeContext("e_u1", CMD_GET_VEHICLE_VARIABLE, 100, vars2, 0, TIME2STEPS(100));
963 
964  answerLog << " gui:\n";
965  try {
966  answerLog << " setScheme: \n";
967  gui.setSchema("View #0", "real world");
968  answerLog << " getScheme: " << gui.getSchema("View #0") << "\n";
969  answerLog << " take screenshot: \n";
970  gui.screenshot("View #0", "image.png", 500, 500);
971  } catch (libsumo::TraCIException&) {
972  answerLog << " no support for gui commands\n";
973  }
974 }
EdgeScope edge
Scope for interaction with edges.
Definition: TraCIAPI.h:843
#define VAR_ROAD_ID
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:2306
unsigned char g
Definition: TraCIDefs.h:139
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1614
std::string getRouteID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2188
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:2048
void setRoute(const std::string &vehicleID, const std::vector< std::string > &edge) const
Definition: TraCIAPI.cpp:2656
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1466
std::string getParameter(const std::string &objectID, const std::string &key) const
retrieve generic paramter
Definition: TraCIAPI.cpp:3136
std::string id
The id of the next tls.
Definition: TraCIDefs.h:279
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:2579
void setMinGapLat(const std::string &typeID, double minGapLat) const
Definition: TraCIAPI.cpp:1998
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:271
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:1967
void setColor(const std::string &vehicleID, const libsumo::TraCIColor &c) const
Definition: TraCIAPI.cpp:2799
void appendDrivingStage(const std::string &personID, const std::string &toEdge, const std::string &lines, const std::string &stopID="")
Definition: TraCIAPI.cpp:3030
#define REQUEST_DRIVINGDIST
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:982
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:1673
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:74
double dist
The distance to the tls.
Definition: TraCIDefs.h:283
void setLength(const std::string &personID, double length) const
Definition: TraCIAPI.cpp:3080
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:273
void setSpeedFactor(const std::string &vehicleID, double factor) const
Definition: TraCIAPI.cpp:2779
void changeTarget(const std::string &vehicleID, const std::string &edgeID) const
Definition: TraCIAPI.cpp:2591
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:2822
virtual std::vector< std::string > readStringList()
#define RESPONSE_SUBSCRIBE_GUI_VARIABLE
#define POSITION_2D
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:263
void setRouteID(const std::string &vehicleID, const std::string &routeID) const
Definition: TraCIAPI.cpp:2645
void testAPI()
call all API methods once
void setParameter(const std::string &objectID, const std::string &key, const std::string &value) const
set generic paramter
Definition: TraCIAPI.cpp:3145
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:2413
double getWaitingTime(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2269
#define TYPE_UBYTE
#define RTYPE_OK
std::string getTypeID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2183
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:2391
void setSignals(const std::string &vehicleID, int signals) const
Definition: TraCIAPI.cpp:2835
double getEmergencyDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1834
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:851
virtual double readDouble()
#define TYPE_POLYGON
PersonScope person
Scope for interaction with persons.
Definition: TraCIAPI.h:857
int getIDCount() const
Definition: TraCIAPI.cpp:2133
double getMaxSpeedLat(const std::string &typeID) const
Definition: TraCIAPI.cpp:1879
void rerouteTraveltime(const std::string &vehicleID, bool currentTravelTimes=true) const
Definition: TraCIAPI.cpp:2670
void setMaxSpeedLat(const std::string &typeID, double speed) const
Definition: TraCIAPI.cpp:2008
double getMaxSpeed(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2148
void setLine(const std::string &vehicleID, const std::string &line) const
Definition: TraCIAPI.cpp:2812
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:2168
void appendWaitingStage(const std::string &personID, double duration, const std::string &description="waiting", const std::string &stopID="")
Definition: TraCIAPI.cpp:2986
std::vector< libsumo::TraCIVehicleData > getVehicleData(const std::string &loopID) const
Definition: TraCIAPI.cpp:927
double getNextSwitch(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1716
#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:586
double getSpeed(const std::string &personID) const
Definition: TraCIAPI.cpp:2891
void send_commandSetOrder(int order) const
Sends a SetOrder command.
Definition: TraCIAPI.cpp:147
#define POSITION_3D
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:112
std::string getNextEdge(const std::string &personID) const
Definition: TraCIAPI.cpp:2916
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:1624
TrafficLightScope trafficlights
Scope for interaction with traffic lights.
Definition: TraCIAPI.h:867
int getPhase(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1706
std::string getLine(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2286
double getDistanceRoad(const std::string &edgeID1, double pos1, const std::string &edgeID2, double pos2, bool isDriving=false)
Definition: TraCIAPI.cpp:1590
void removeStage(const std::string &personID, int nextStageIndex) const
Definition: TraCIAPI.cpp:3048
InductionLoopScope inductionloop
Scope for interaction with inductive loops.
Definition: TraCIAPI.h:847
virtual void writeInt(int)
std::vector< std::string > getRoute(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2199
#define TLPHASE_RED
#define TYPE_STRING
virtual int readUnsignedByte()
std::vector< libsumo::TraCIConnection > getLinks(const std::string &laneID) const
Definition: TraCIAPI.cpp:1022
#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:3204
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:2702
#define TLPHASE_YELLOW
double getPhaseDuration(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1711
void rerouteTraveltime(const std::string &personID) const
Definition: TraCIAPI.cpp:2958
#define TYPE_TLPHASELIST
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:1762
std::string getShapeClass(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2301
std::string getTypeID(const std::string &personID) const
Definition: TraCIAPI.cpp:2906
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:882
libsumo::TraCIColor getColor(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2204
void setHeight(const std::string &personID, double height) const
Definition: TraCIAPI.cpp:3101
std::vector< std::string > getVia(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2291
void setType(const std::string &vehicleID, const std::string &typeID) const
Definition: TraCIAPI.cpp:2769
std::string approachedInternal
Definition: TraCIDefs.h:255
virtual int readInt()
#define VAR_LANEPOSITION
void writeResult()
Writes the results file.
double getAccumulatedWaitingTime(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2473
virtual void writeByte(int)
RouteScope route
Scope for interaction with routes.
Definition: TraCIAPI.h:863
double getLateralLanePosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2224
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:716
void setLateralAlignment(const std::string &typeID, const std::string &latAlignment) const
Definition: TraCIAPI.cpp:2018
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 getDistance2D(double x1, double y1, double x2, double y2, bool isGeo=false, bool isDriving=false)
Definition: TraCIAPI.cpp:1571
void setRedYellowGreenState(const std::string &tlsID, const std::string &state) const
Definition: TraCIAPI.cpp:1722
int getIDCount() const
Definition: TraCIAPI.cpp:612
void subscribe(const std::string &objID, const std::vector< int > &vars, double beginTime, double endTime) const
Definition: TraCIAPI.cpp:3160
double length
Length of the vehicle.
Definition: TraCIDefs.h:267
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:2968
double getWaitingTime(const std::string &personID) const
Definition: TraCIAPI.cpp:2911
std::string getRoadID(const std::string &personID) const
Definition: TraCIAPI.cpp:2901
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:265
virtual std::string readString()
bool isRouteValid(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2498
void subscribeContext(const std::string &objID, int domain, double range, const std::vector< int > &vars, double beginTime, double endTime) const
Definition: TraCIAPI.cpp:3172
unsigned char r
Definition: TraCIDefs.h:139
void add(const std::string &routeID, const std::vector< std::string > &edges) const
Definition: TraCIAPI.cpp:1477
double getSpeed(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2138
std::string getProgram(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1701
void setWidth(const std::string &personID, double width) const
Definition: TraCIAPI.cpp:3091
void setSpeed(const std::string &personID, double speed) const
Definition: TraCIAPI.cpp:3059
const libsumo::TraCIResults getSubscriptionResults(const std::string &objID) const
Definition: TraCIAPI.cpp:3188
double getAcceleration(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2143
void setShapeClass(const std::string &vehicleID, const std::string &clazz) const
Definition: TraCIAPI.cpp:2855
std::string getVehicle(const std::string &personID) const
Definition: TraCIAPI.cpp:2922
std::string approachedLane
Definition: TraCIDefs.h:251
TraCITestClient(std::string outputFileName="testclient_result.out")
Constructor.
int getRemainingStages(const std::string &personID) const
Definition: TraCIAPI.cpp:2927
double getSlope(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2280
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, double beginTime, double endTime, int domain, double range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
int getLaneNumber(const std::string &edgeID) const
Definition: TraCIAPI.cpp:710
SimulationScope simulation
Scope for interaction with the simulation.
Definition: TraCIAPI.h:865
std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist) const
Definition: TraCIAPI.cpp:2374
virtual void writeString(const std::string &s)
void setMaxSpeed(const std::string &vehicleID, double speed) const
Definition: TraCIAPI.cpp:2789
void setColor(const std::string &personID, const libsumo::TraCIColor &c) const
Definition: TraCIAPI.cpp:3122
#define REQUEST_AIRDIST
VehicleScope vehicle
Scope for interaction with vehicles.
Definition: TraCIAPI.h:869
#define TYPE_DOUBLE
double getHeight(const std::string &typeID) const
Definition: TraCIAPI.cpp:1894
std::vector< std::string > getControlledLanes(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1668
#define ROUTING_MODE_AGGREGATED
int getLinkNumber(const std::string &laneID) const
Definition: TraCIAPI.cpp:1017
char state
The current state of the tls.
Definition: TraCIDefs.h:285
#define TYPE_BYTE
void simulationStep(int time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:564
void setEffort(const std::string &edgeID, double effort, double beginSeconds=0., double endSeconds=std::numeric_limits< double >::max()) const
Definition: TraCIAPI.cpp:743
void adaptTraveltime(const std::string &edgeID, double time, double beginSeconds=0., double endSeconds=std::numeric_limits< double >::max()) const
Definition: TraCIAPI.cpp:722
void setEmergencyDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2068
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:2028
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:2274
int getIDCount() const
Definition: TraCIAPI.cpp:987
void setSchema(const std::string &viewID, const std::string &schemeName) const
Definition: TraCIAPI.cpp:824
double getEffort(const std::string &edgeID, double time) const
Definition: TraCIAPI.cpp:625
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1799
virtual void writeDouble(double)
double getTraveltime(const std::string &edgeID) const
Definition: TraCIAPI.cpp:689
#define CMD_SETORDER
GUIScope gui
Scope for interaction with the gui.
Definition: TraCIAPI.h:845
void setMinGap(const std::string &personID, double minGap) const
Definition: TraCIAPI.cpp:3111
std::string getLateralAlignment(const std::string &typeID) const
Definition: TraCIAPI.cpp:1884
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:3005
void screenshot(const std::string &viewID, const std::string &filename, const int width=-1, const int height=-1) const
Definition: TraCIAPI.cpp:850
double getApparentDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1839
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:607
void setHeight(const std::string &typeID, double height) const
Definition: TraCIAPI.cpp:1977
std::string getLaneID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2173
int getStage(const std::string &personID, int nextStageIndex=0) const
Definition: TraCIAPI.cpp:2932
double getLanePosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2209
int getSignals(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2219
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:269
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:2948
double getAccel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1824
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:2518
double getAdaptedTraveltime(const std::string &edgeID, double time) const
Definition: TraCIAPI.cpp:617
double getDeltaT() const
Definition: TraCIAPI.cpp:1554
void setRoutingMode(const std::string &vehicleID, int routingMode) const
Definition: TraCIAPI.cpp:2845
#define TYPE_INTEGER
void setType(const std::string &personID, const std::string &typeID) const
Definition: TraCIAPI.cpp:3070
void moveTo(const std::string &vehicleID, const std::string &laneID, double position) const
Definition: TraCIAPI.cpp:2688
std::vector< std::string > getEdges(const std::string &personID, int nextStageIndex=0) const
Definition: TraCIAPI.cpp:2940
std::vector< std::string > getInternalFoes(const std::string &laneID) const
Definition: TraCIAPI.cpp:1174
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:281
std::vector< std::string > getFoes(const std::string &laneID, const std::string &toLaneID) const
Definition: TraCIAPI.cpp:1158
double getWidth(const std::string &typeID) const
Definition: TraCIAPI.cpp:1889
double getMinGapLat(const std::string &typeID) const
Definition: TraCIAPI.cpp:1874
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:230
#define CMD_SIMSTEP
virtual int readByte()
std::vector< libsumo::TraCILogic > getCompleteRedYellowGreenDefinition(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1629
~TraCITestClient()
Destructor.
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:2881
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:2128
std::string getSchema(const std::string &viewID=DEFAULT_VIEW) const
Definition: TraCIAPI.cpp:793
void setApparentDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2078
VehicleTypeScope vehicletype
Scope for interaction with vehicle types.
Definition: TraCIAPI.h:871