SUMO - Simulation of Urban MObility
TraCIAPI.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // C++ TraCI client API implementation
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include "../../config.h"
32 #endif
33 
34 #include "TraCIAPI.h"
35 
36 
37 // ===========================================================================
38 // member definitions
39 // ===========================================================================
40 
41 // ---------------------------------------------------------------------------
42 // TraCIAPI-methods
43 // ---------------------------------------------------------------------------
44 #ifdef _MSC_VER
45 #pragma warning(push)
46 #pragma warning(disable: 4355)
47 #endif
49  : edge(*this), gui(*this), inductionloop(*this),
50  junction(*this), lane(*this), lanearea(*this), multientryexit(*this),
51  person(*this), poi(*this), polygon(*this), route(*this),
52  simulation(*this), trafficlights(*this),
53  vehicle(*this), vehicletype(*this),
54  mySocket(0) {}
55 #ifdef _MSC_VER
56 #pragma warning(pop)
57 #endif
58 
59 
61  delete mySocket;
62 }
63 
64 
65 void
66 TraCIAPI::connect(const std::string& host, int port) {
67  mySocket = new tcpip::Socket(host, port);
68  try {
69  mySocket->connect();
70  } catch (tcpip::SocketException&) {
71  delete mySocket;
72  mySocket = 0;
73  throw;
74  }
75 }
76 
77 
78 void
79 TraCIAPI::setOrder(int order) {
80  tcpip::Storage outMsg;
81  // command length
82  outMsg.writeUnsignedByte(1 + 1 + 4);
83  // command id
85  outMsg.writeInt(order);
86  // send request message
87  mySocket->sendExact(outMsg);
88  tcpip::Storage inMsg;
90 }
91 
92 
93 void
96  tcpip::Storage inMsg;
97  std::string acknowledgement;
98  check_resultState(inMsg, CMD_CLOSE, false, &acknowledgement);
99  closeSocket();
100 }
101 
102 
103 void
105  if (mySocket == 0) {
106  return;
107  }
108  mySocket->close();
109  delete mySocket;
110  mySocket = 0;
111 }
112 
113 
114 void
116  tcpip::Storage outMsg;
117  // command length
118  outMsg.writeUnsignedByte(1 + 1 + 4);
119  // command id
121  outMsg.writeInt((int)time);
122  // send request message
123  mySocket->sendExact(outMsg);
124 }
125 
126 
127 void
129  tcpip::Storage outMsg;
130  // command length
131  outMsg.writeUnsignedByte(1 + 1);
132  // command id
134  mySocket->sendExact(outMsg);
135 }
136 
137 
138 void
139 TraCIAPI::send_commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* add) const {
140  if (mySocket == 0) {
141  throw tcpip::SocketException("Socket is not initialised");
142  }
143  tcpip::Storage outMsg;
144  // command length
145  int length = 1 + 1 + 1 + 4 + (int) objID.length();
146  if (add != 0) {
147  length += (int)add->size();
148  }
149  outMsg.writeUnsignedByte(length);
150  // command id
151  outMsg.writeUnsignedByte(domID);
152  // variable id
153  outMsg.writeUnsignedByte(varID);
154  // object id
155  outMsg.writeString(objID);
156  // additional values
157  if (add != 0) {
158  outMsg.writeStorage(*add);
159  }
160  // send request message
161  mySocket->sendExact(outMsg);
162 }
163 
164 
165 void
166 TraCIAPI::send_commandSetValue(int domID, int varID, const std::string& objID, tcpip::Storage& content) const {
167  if (mySocket == 0) {
168  throw tcpip::SocketException("Socket is not initialised");
169  }
170  tcpip::Storage outMsg;
171  // command length (domID, varID, objID, dataType, data)
172  outMsg.writeUnsignedByte(1 + 1 + 1 + 4 + (int) objID.length() + (int)content.size());
173  // command id
174  outMsg.writeUnsignedByte(domID);
175  // variable id
176  outMsg.writeUnsignedByte(varID);
177  // object id
178  outMsg.writeString(objID);
179  // data type
180  outMsg.writeStorage(content);
181  // send message
182  mySocket->sendExact(outMsg);
183 }
184 
185 
186 void
187 TraCIAPI::send_commandSubscribeObjectVariable(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
188  const std::vector<int>& vars) const {
189  if (mySocket == 0) {
190  throw tcpip::SocketException("Socket is not initialised");
191  }
192  tcpip::Storage outMsg;
193  // command length (domID, objID, beginTime, endTime, length, vars)
194  int varNo = (int) vars.size();
195  outMsg.writeUnsignedByte(0);
196  outMsg.writeInt(5 + 1 + 4 + 4 + 4 + (int) objID.length() + 1 + varNo);
197  // command id
198  outMsg.writeUnsignedByte(domID);
199  // time
200  outMsg.writeInt((int)beginTime);
201  outMsg.writeInt((int)endTime);
202  // object id
203  outMsg.writeString(objID);
204  // command id
205  outMsg.writeUnsignedByte((int)vars.size());
206  for (int i = 0; i < varNo; ++i) {
207  outMsg.writeUnsignedByte(vars[i]);
208  }
209  // send message
210  mySocket->sendExact(outMsg);
211 }
212 
213 
214 void
215 TraCIAPI::send_commandSubscribeObjectContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime,
216  int domain, double range, const std::vector<int>& vars) const {
217  if (mySocket == 0) {
218  throw tcpip::SocketException("Socket is not initialised");
219  }
220  tcpip::Storage outMsg;
221  // command length (domID, objID, beginTime, endTime, length, vars)
222  int varNo = (int) vars.size();
223  outMsg.writeUnsignedByte(0);
224  outMsg.writeInt(5 + 1 + 4 + 4 + 4 + (int) objID.length() + 1 + 8 + 1 + varNo);
225  // command id
226  outMsg.writeUnsignedByte(domID);
227  // time
228  outMsg.writeInt((int)beginTime);
229  outMsg.writeInt((int)endTime);
230  // object id
231  outMsg.writeString(objID);
232  // domain and range
233  outMsg.writeUnsignedByte(domain);
234  outMsg.writeDouble(range);
235  // command id
236  outMsg.writeUnsignedByte((int)vars.size());
237  for (int i = 0; i < varNo; ++i) {
238  outMsg.writeUnsignedByte(vars[i]);
239  }
240  // send message
241  mySocket->sendExact(outMsg);
242 }
243 
244 void
245 TraCIAPI::send_commandMoveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const {
246  tcpip::Storage content;
248  content.writeInt(6);
250  content.writeString(edgeID);
252  content.writeInt(lane);
254  content.writeDouble(x);
256  content.writeDouble(y);
258  content.writeDouble(angle);
259  content.writeUnsignedByte(TYPE_BYTE);
260  content.writeByte(keepRoute);
262 }
263 
264 void
265 TraCIAPI::check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId, std::string* acknowledgement) const {
266  mySocket->receiveExact(inMsg);
267  int cmdLength;
268  int cmdId;
269  int resultType;
270  int cmdStart;
271  std::string msg;
272  try {
273  cmdStart = inMsg.position();
274  cmdLength = inMsg.readUnsignedByte();
275  cmdId = inMsg.readUnsignedByte();
276  if (command != cmdId && !ignoreCommandId) {
277  throw tcpip::SocketException("#Error: received status response to command: " + toString(cmdId) + " but expected: " + toString(command));
278  }
279  resultType = inMsg.readUnsignedByte();
280  msg = inMsg.readString();
281  } catch (std::invalid_argument&) {
282  throw tcpip::SocketException("#Error: an exception was thrown while reading result state message");
283  }
284  switch (resultType) {
285  case RTYPE_ERR:
286  throw tcpip::SocketException(".. Answered with error to command (" + toString(command) + "), [description: " + msg + "]");
288  throw tcpip::SocketException(".. Sent command is not implemented (" + toString(command) + "), [description: " + msg + "]");
289  case RTYPE_OK:
290  if (acknowledgement != 0) {
291  (*acknowledgement) = ".. Command acknowledged (" + toString(command) + "), [description: " + msg + "]";
292  }
293  break;
294  default:
295  throw tcpip::SocketException(".. Answered with unknown result code(" + toString(resultType) + ") to command(" + toString(command) + "), [description: " + msg + "]");
296  }
297  if ((cmdStart + cmdLength) != (int) inMsg.position()) {
298  throw tcpip::SocketException("#Error: command at position " + toString(cmdStart) + " has wrong length");
299  }
300 }
301 
302 
303 int
304 TraCIAPI::check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId) const {
305  inMsg.position(); // respStart
306  int length = inMsg.readUnsignedByte();
307  if (length == 0) {
308  length = inMsg.readInt();
309  }
310  int cmdId = inMsg.readUnsignedByte();
311  if (!ignoreCommandId && cmdId != (command + 0x10)) {
312  throw tcpip::SocketException("#Error: received response with command id: " + toString(cmdId) + "but expected: " + toString(command + 0x10));
313  }
314  if (expectedType >= 0) {
315  // not called from the TraCITestClient but from within the TraCIAPI
316  inMsg.readUnsignedByte(); // variableID
317  inMsg.readString(); // objectID
318  int valueDataType = inMsg.readUnsignedByte();
319  if (valueDataType != expectedType) {
320  throw tcpip::SocketException("Expected " + toString(expectedType) + " but got " + toString(valueDataType));
321  }
322  }
323  return cmdId;
324 }
325 
326 
327 void
328 TraCIAPI::processGET(tcpip::Storage& inMsg, int command, int expectedType, bool ignoreCommandId) const {
329  check_resultState(inMsg, command, ignoreCommandId);
330  check_commandGetResult(inMsg, command, expectedType, ignoreCommandId);
331 }
332 
333 
334 
335 
336 SUMOTime
337 TraCIAPI::getSUMOTime(int cmd, int var, const std::string& id, tcpip::Storage* add) {
338  tcpip::Storage inMsg;
339  send_commandGetVariable(cmd, var, id, add);
340  processGET(inMsg, cmd, TYPE_INTEGER);
341  return inMsg.readInt();
342 }
343 
344 
345 int
346 TraCIAPI::getUnsignedByte(int cmd, int var, const std::string& id, tcpip::Storage* add) {
347  tcpip::Storage inMsg;
348  send_commandGetVariable(cmd, var, id, add);
349  processGET(inMsg, cmd, TYPE_UBYTE);
350  return inMsg.readUnsignedByte();
351 }
352 
353 
354 int
355 TraCIAPI::getByte(int cmd, int var, const std::string& id, tcpip::Storage* add) {
356  tcpip::Storage inMsg;
357  send_commandGetVariable(cmd, var, id, add);
358  processGET(inMsg, cmd, TYPE_BYTE);
359  return inMsg.readByte();
360 }
361 
362 
363 int
364 TraCIAPI::getInt(int cmd, int var, const std::string& id, tcpip::Storage* add) {
365  tcpip::Storage inMsg;
366  send_commandGetVariable(cmd, var, id, add);
367  processGET(inMsg, cmd, TYPE_INTEGER);
368  return inMsg.readInt();
369 }
370 
371 
372 double
373 TraCIAPI::getFloat(int cmd, int var, const std::string& id, tcpip::Storage* add) {
374  tcpip::Storage inMsg;
375  send_commandGetVariable(cmd, var, id, add);
376  processGET(inMsg, cmd, TYPE_FLOAT);
377  return inMsg.readFloat();
378 }
379 
380 
381 double
382 TraCIAPI::getDouble(int cmd, int var, const std::string& id, tcpip::Storage* add) {
383  tcpip::Storage inMsg;
384  send_commandGetVariable(cmd, var, id, add);
385  processGET(inMsg, cmd, TYPE_DOUBLE);
386  return inMsg.readDouble();
387 }
388 
389 
391 TraCIAPI::getBoundingBox(int cmd, int var, const std::string& id, tcpip::Storage* add) {
392  tcpip::Storage inMsg;
393  send_commandGetVariable(cmd, var, id, add);
394  processGET(inMsg, cmd, TYPE_BOUNDINGBOX);
395  TraCIBoundary b;
396  b.xMin = inMsg.readDouble();
397  b.yMin = inMsg.readDouble();
398  b.zMin = 0;
399  b.xMax = inMsg.readDouble();
400  b.yMax = inMsg.readDouble();
401  b.zMax = 0;
402  return b;
403 }
404 
405 
407 TraCIAPI::getPolygon(int cmd, int var, const std::string& id, tcpip::Storage* add) {
408  tcpip::Storage inMsg;
409  send_commandGetVariable(cmd, var, id, add);
410  processGET(inMsg, cmd, TYPE_POLYGON);
411  int size = inMsg.readByte();
413  for (int i = 0; i < size; ++i) {
414  TraCIPosition p;
415  p.x = inMsg.readDouble();
416  p.y = inMsg.readDouble();
417  p.z = 0;
418  ret.push_back(p);
419  }
420  return ret;
421 }
422 
423 
425 TraCIAPI::getPosition(int cmd, int var, const std::string& id, tcpip::Storage* add) {
426  tcpip::Storage inMsg;
427  send_commandGetVariable(cmd, var, id, add);
428  processGET(inMsg, cmd, POSITION_2D);
429  TraCIPosition p;
430  p.x = inMsg.readDouble();
431  p.y = inMsg.readDouble();
432  p.z = 0;
433  return p;
434 }
435 
436 
438 TraCIAPI::getPosition3D(int cmd, int var, const std::string& id, tcpip::Storage* add) {
439  tcpip::Storage inMsg;
440  send_commandGetVariable(cmd, var, id, add);
441  processGET(inMsg, cmd, POSITION_3D);
442  TraCIPosition p;
443  p.x = inMsg.readDouble();
444  p.y = inMsg.readDouble();
445  p.z = inMsg.readDouble();
446  return p;
447 }
448 
449 
450 std::string
451 TraCIAPI::getString(int cmd, int var, const std::string& id, tcpip::Storage* add) {
452  tcpip::Storage inMsg;
453  send_commandGetVariable(cmd, var, id, add);
454  processGET(inMsg, cmd, TYPE_STRING);
455  return inMsg.readString();
456 }
457 
458 
459 std::vector<std::string>
460 TraCIAPI::getStringVector(int cmd, int var, const std::string& id, tcpip::Storage* add) {
461  tcpip::Storage inMsg;
462  send_commandGetVariable(cmd, var, id, add);
463  processGET(inMsg, cmd, TYPE_STRINGLIST);
464  int size = inMsg.readInt();
465  std::vector<std::string> r;
466  for (int i = 0; i < size; ++i) {
467  r.push_back(inMsg.readString());
468  }
469  return r;
470 }
471 
472 
474 TraCIAPI::getColor(int cmd, int var, const std::string& id, tcpip::Storage* add) {
475  tcpip::Storage inMsg;
476  send_commandGetVariable(cmd, var, id, add);
477  processGET(inMsg, cmd, TYPE_COLOR);
478  TraCIColor c;
479  c.r = (unsigned char)inMsg.readUnsignedByte();
480  c.g = (unsigned char)inMsg.readUnsignedByte();
481  c.b = (unsigned char)inMsg.readUnsignedByte();
482  c.a = (unsigned char)inMsg.readUnsignedByte();
483  return c;
484 }
485 
486 void
487 TraCIAPI::readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, SubscribedValues& into) {
488  while (variableCount > 0) {
489 
490  const int variableID = inMsg.readUnsignedByte();
491  const int status = inMsg.readUnsignedByte();
492  const int type = inMsg.readUnsignedByte();
493 
494  if (status == RTYPE_OK) {
495 
496  TraCIValue v;
497 
498  switch (type) {
499  case TYPE_DOUBLE:
500  v.scalar = inMsg.readDouble();
501  break;
502  case TYPE_STRING:
503  v.string = inMsg.readString();
504  break;
505  case POSITION_2D:
506  v.position.x = inMsg.readDouble();
507  v.position.y = inMsg.readDouble();
508  v.position.z = 0;
509  break;
510  case POSITION_3D:
511  v.position.x = inMsg.readDouble();
512  v.position.y = inMsg.readDouble();
513  v.position.z = inMsg.readDouble();
514  break;
515  case TYPE_COLOR:
516  v.color.r = (unsigned char)inMsg.readUnsignedByte();
517  v.color.g = (unsigned char)inMsg.readUnsignedByte();
518  v.color.b = (unsigned char)inMsg.readUnsignedByte();
519  v.color.a = (unsigned char)inMsg.readUnsignedByte();
520  break;
521  case TYPE_INTEGER:
522  v.scalar = inMsg.readInt();
523  break;
524  case TYPE_STRINGLIST: {
525  int n = inMsg.readInt();
526  for (int i = 0; i < n; ++i) {
527  v.stringList.push_back(inMsg.readString());
528  }
529  }
530  break;
531 
532  // TODO Other data types
533 
534  default:
535  throw tcpip::SocketException("Unimplemented subscription type: " + toString(type));
536  }
537 
538  into[objectID][variableID] = v;
539  } else {
540  throw tcpip::SocketException("Subscription response error: variableID=" + toString(variableID) + " status=" + toString(status));
541  }
542 
543  variableCount--;
544  }
545 }
546 
547 void
549  const std::string objectID = inMsg.readString();
550  const int variableCount = inMsg.readUnsignedByte();
551  readVariables(inMsg, objectID, variableCount, mySubscribedValues);
552 }
553 
554 void
556  const std::string contextID = inMsg.readString();
557  inMsg.readUnsignedByte(); // context domain
558  const int variableCount = inMsg.readUnsignedByte();
559  int numObjects = inMsg.readInt();
560 
561  while (numObjects > 0) {
562  std::string objectID = inMsg.readString();
563  readVariables(inMsg, objectID, variableCount, mySubscribedContextValues[contextID]);
564  numObjects--;
565  }
566 }
567 
568 void
571  tcpip::Storage inMsg;
573 
574  mySubscribedValues.clear();
576  int numSubs = inMsg.readInt();
577  while (numSubs > 0) {
578  int cmdId = check_commandGetResult(inMsg, 0, -1, true);
581  } else {
583  }
584  numSubs--;
585  }
586 }
587 
588 
589 void
590 TraCIAPI::load(const std::vector<std::string>& args) {
591  int numChars = 0;
592  for (int i = 0; i < (int)args.size(); ++i) {
593  numChars += (int)args[i].size();
594  }
595  tcpip::Storage content;
596  content.writeUnsignedByte(1 + 1 + 1 + 4 + numChars + 4 * (int)args.size());
597  content.writeUnsignedByte(CMD_LOAD);
599  content.writeStringList(args);
600  mySocket->sendExact(content);
601  tcpip::Storage inMsg;
602  check_resultState(inMsg, CMD_LOAD);
603 }
604 
605 
606 // ---------------------------------------------------------------------------
607 // TraCIAPI::EdgeScope-methods
608 // ---------------------------------------------------------------------------
609 std::vector<std::string>
611  return myParent.getStringVector(CMD_GET_EDGE_VARIABLE, ID_LIST, "");
612 }
613 
614 int
616  return myParent.getInt(CMD_GET_EDGE_VARIABLE, ID_COUNT, "");
617 }
618 
619 double
620 TraCIAPI::EdgeScope::getAdaptedTraveltime(const std::string& edgeID, double time) const {
621  tcpip::Storage content;
622  content.writeByte(TYPE_INTEGER);
623  content.writeInt((int)time);
624  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_EDGE_TRAVELTIME, edgeID, &content);
625 }
626 
627 double
628 TraCIAPI::EdgeScope::getEffort(const std::string& edgeID, SUMOTime time) const {
629  tcpip::Storage content;
630  content.writeByte(TYPE_INTEGER);
631  content.writeInt((int)time);
632  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_EDGE_EFFORT, edgeID, &content);
633 }
634 
635 double
636 TraCIAPI::EdgeScope::getCO2Emission(const std::string& edgeID) const {
637  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_CO2EMISSION, edgeID);
638 }
639 
640 
641 double
642 TraCIAPI::EdgeScope::getCOEmission(const std::string& edgeID) const {
643  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_COEMISSION, edgeID);
644 }
645 
646 double
647 TraCIAPI::EdgeScope::getHCEmission(const std::string& edgeID) const {
648  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_HCEMISSION, edgeID);
649 }
650 
651 double
652 TraCIAPI::EdgeScope::getPMxEmission(const std::string& edgeID) const {
653  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_PMXEMISSION, edgeID);
654 }
655 
656 double
657 TraCIAPI::EdgeScope::getNOxEmission(const std::string& edgeID) const {
658  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_NOXEMISSION, edgeID);
659 }
660 
661 double
662 TraCIAPI::EdgeScope::getFuelConsumption(const std::string& edgeID) const {
663  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_FUELCONSUMPTION, edgeID);
664 }
665 
666 double
667 TraCIAPI::EdgeScope::getNoiseEmission(const std::string& edgeID) const {
668  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_NOISEEMISSION, edgeID);
669 }
670 
671 double
672 TraCIAPI::EdgeScope::getElectricityConsumption(const std::string& edgeID) const {
673  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_ELECTRICITYCONSUMPTION, edgeID);
674 }
675 
676 double
677 TraCIAPI::EdgeScope::getLastStepMeanSpeed(const std::string& edgeID) const {
678  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, LAST_STEP_MEAN_SPEED, edgeID);
679 }
680 
681 double
682 TraCIAPI::EdgeScope::getLastStepOccupancy(const std::string& edgeID) const {
683  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, LAST_STEP_OCCUPANCY, edgeID);
684 }
685 
686 double
687 TraCIAPI::EdgeScope::getLastStepLength(const std::string& edgeID) const {
688  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, LAST_STEP_LENGTH, edgeID);
689 }
690 
691 double
692 TraCIAPI::EdgeScope::getTraveltime(const std::string& edgeID) const {
693  return myParent.getDouble(CMD_GET_EDGE_VARIABLE, VAR_CURRENT_TRAVELTIME, edgeID);
694 }
695 
696 int
697 TraCIAPI::EdgeScope::getLastStepVehicleNumber(const std::string& edgeID) const {
698  return myParent.getInt(CMD_GET_EDGE_VARIABLE, LAST_STEP_VEHICLE_NUMBER, edgeID);
699 }
700 
701 double
702 TraCIAPI::EdgeScope::getLastStepHaltingNumber(const std::string& edgeID) const {
703  return myParent.getInt(CMD_GET_EDGE_VARIABLE, LAST_STEP_VEHICLE_HALTING_NUMBER, edgeID);
704 }
705 
706 std::vector<std::string>
707 TraCIAPI::EdgeScope::getLastStepVehicleIDs(const std::string& edgeID) const {
708  return myParent.getStringVector(CMD_GET_EDGE_VARIABLE, LAST_STEP_VEHICLE_ID_LIST, edgeID);
709 }
710 
711 
712 
713 void
714 TraCIAPI::EdgeScope::adaptTraveltime(const std::string& edgeID, double time, double begin, double end) const {
715  tcpip::Storage content;
716  content.writeByte(TYPE_COMPOUND);
717  content.writeInt(3);
718  content.writeByte(TYPE_INTEGER);
719  content.writeInt((int)begin);
720  content.writeByte(TYPE_INTEGER);
721  content.writeInt((int)end);
722  content.writeByte(TYPE_DOUBLE);
723  content.writeDouble(time);
724  myParent.send_commandSetValue(CMD_SET_EDGE_VARIABLE, VAR_EDGE_TRAVELTIME, edgeID, content);
725  tcpip::Storage inMsg;
726  myParent.check_resultState(inMsg, CMD_SET_EDGE_VARIABLE);
727 }
728 
729 void
730 TraCIAPI::EdgeScope::setEffort(const std::string& edgeID, double effort, SUMOTime begin, SUMOTime end) const {
731  tcpip::Storage content;
732  content.writeByte(TYPE_COMPOUND);
733  content.writeInt(3);
734  content.writeByte(TYPE_INTEGER);
735  content.writeInt((int)begin);
736  content.writeByte(TYPE_INTEGER);
737  content.writeInt((int)end);
738  content.writeByte(TYPE_DOUBLE);
739  content.writeDouble(effort);
740  myParent.send_commandSetValue(CMD_SET_EDGE_VARIABLE, VAR_EDGE_EFFORT, edgeID, content);
741  tcpip::Storage inMsg;
742  myParent.check_resultState(inMsg, CMD_SET_EDGE_VARIABLE);
743 }
744 
745 void
746 TraCIAPI::EdgeScope::setMaxSpeed(const std::string& edgeID, double speed) const {
747  tcpip::Storage content;
748  content.writeDouble(speed);
749  myParent.send_commandSetValue(CMD_SET_EDGE_VARIABLE, VAR_MAXSPEED, edgeID, content);
750  tcpip::Storage inMsg;
751  myParent.check_resultState(inMsg, CMD_SET_EDGE_VARIABLE);
752 }
753 
754 
755 
756 
757 // ---------------------------------------------------------------------------
758 // TraCIAPI::GUIScope-methods
759 // ---------------------------------------------------------------------------
760 std::vector<std::string>
762  return myParent.getStringVector(CMD_GET_GUI_VARIABLE, ID_LIST, "");
763 }
764 
765 double
766 TraCIAPI::GUIScope::getZoom(const std::string& viewID) const {
767  return myParent.getDouble(CMD_GET_GUI_VARIABLE, VAR_VIEW_ZOOM, viewID);
768 }
769 
771 TraCIAPI::GUIScope::getOffset(const std::string& viewID) const {
772  return myParent.getPosition(CMD_GET_GUI_VARIABLE, VAR_VIEW_OFFSET, viewID);
773 }
774 
775 std::string
776 TraCIAPI::GUIScope::getSchema(const std::string& viewID) const {
777  return myParent.getString(CMD_GET_GUI_VARIABLE, VAR_VIEW_SCHEMA, viewID);
778 }
779 
781 TraCIAPI::GUIScope::getBoundary(const std::string& viewID) const {
782  return myParent.getBoundingBox(CMD_GET_GUI_VARIABLE, VAR_VIEW_BOUNDARY, viewID);
783 }
784 
785 
786 void
787 TraCIAPI::GUIScope::setZoom(const std::string& viewID, double zoom) const {
788  tcpip::Storage content;
789  content.writeDouble(zoom);
790  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_VIEW_ZOOM, viewID, content);
791  tcpip::Storage inMsg;
792  myParent.check_resultState(inMsg, CMD_SET_GUI_VARIABLE);
793 }
794 
795 void
796 TraCIAPI::GUIScope::setOffset(const std::string& viewID, double x, double y) const {
797  tcpip::Storage content;
799  content.writeDouble(x);
800  content.writeDouble(y);
801  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_VIEW_OFFSET, viewID, content);
802  tcpip::Storage inMsg;
803  myParent.check_resultState(inMsg, CMD_SET_GUI_VARIABLE);
804 }
805 
806 void
807 TraCIAPI::GUIScope::setSchema(const std::string& viewID, const std::string& schemeName) const {
808  tcpip::Storage content;
810  content.writeString(schemeName);
811  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_VIEW_SCHEMA, viewID, content);
812  tcpip::Storage inMsg;
813  myParent.check_resultState(inMsg, CMD_SET_GUI_VARIABLE);
814 }
815 
816 void
817 TraCIAPI::GUIScope::setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const {
818  tcpip::Storage content;
820  content.writeDouble(xmin);
821  content.writeDouble(ymin);
822  content.writeDouble(xmax);
823  content.writeDouble(ymax);
824  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_VIEW_BOUNDARY, viewID, content);
825  tcpip::Storage inMsg;
826  myParent.check_resultState(inMsg, CMD_SET_GUI_VARIABLE);
827 }
828 
829 void
830 TraCIAPI::GUIScope::screenshot(const std::string& viewID, const std::string& filename) const {
831  tcpip::Storage content;
833  content.writeString(filename);
834  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_SCREENSHOT, viewID, content);
835  tcpip::Storage inMsg;
836  myParent.check_resultState(inMsg, CMD_SET_GUI_VARIABLE);
837 }
838 
839 void
840 TraCIAPI::GUIScope::trackVehicle(const std::string& viewID, const std::string& vehID) const {
841  tcpip::Storage content;
843  content.writeString(vehID);
844  myParent.send_commandSetValue(CMD_SET_GUI_VARIABLE, VAR_TRACK_VEHICLE, viewID, content);
845  tcpip::Storage inMsg;
846  myParent.check_resultState(inMsg, CMD_SET_GUI_VARIABLE);
847 }
848 
849 
850 
851 
852 // ---------------------------------------------------------------------------
853 // TraCIAPI::InductionLoopScope-methods
854 // ---------------------------------------------------------------------------
855 std::vector<std::string>
857  return myParent.getStringVector(CMD_GET_INDUCTIONLOOP_VARIABLE, ID_LIST, "");
858 }
859 
860 double
861 TraCIAPI::InductionLoopScope::getPosition(const std::string& loopID) const {
862  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, VAR_POSITION, loopID);
863 }
864 
865 std::string
866 TraCIAPI::InductionLoopScope::getLaneID(const std::string& loopID) const {
867  return myParent.getString(CMD_GET_INDUCTIONLOOP_VARIABLE, VAR_LANE_ID, loopID);
868 }
869 
870 int
872  return myParent.getInt(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_VEHICLE_NUMBER, loopID);
873 }
874 
875 double
876 TraCIAPI::InductionLoopScope::getLastStepMeanSpeed(const std::string& loopID) const {
877  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_MEAN_SPEED, loopID);
878 }
879 
880 std::vector<std::string>
881 TraCIAPI::InductionLoopScope::getLastStepVehicleIDs(const std::string& loopID) const {
882  return myParent.getStringVector(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_VEHICLE_ID_LIST, loopID);
883 }
884 
885 double
886 TraCIAPI::InductionLoopScope::getLastStepOccupancy(const std::string& loopID) const {
887  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_OCCUPANCY, loopID);
888 }
889 
890 double
891 TraCIAPI::InductionLoopScope::getLastStepMeanLength(const std::string& loopID) const {
892  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_LENGTH, loopID);
893 }
894 
895 double
896 TraCIAPI::InductionLoopScope::getTimeSinceDetection(const std::string& loopID) const {
897  return myParent.getDouble(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_TIME_SINCE_DETECTION, loopID);
898 }
899 
900 std::vector<TraCIVehicleData>
901 TraCIAPI::InductionLoopScope::getVehicleData(const std::string& loopID) const {
902  tcpip::Storage inMsg;
903  myParent.send_commandGetVariable(CMD_GET_INDUCTIONLOOP_VARIABLE, LAST_STEP_VEHICLE_DATA, loopID);
904  myParent.processGET(inMsg, CMD_GET_INDUCTIONLOOP_VARIABLE, TYPE_COMPOUND);
905  std::vector<TraCIVehicleData> result;
906  inMsg.readInt(); // components
907  // number of items
908  inMsg.readUnsignedByte();
909  const int n = inMsg.readInt();
910  for (int i = 0; i < n; ++i) {
911  TraCIVehicleData vd;
912 
913  inMsg.readUnsignedByte();
914  vd.id = inMsg.readString();
915 
916  inMsg.readUnsignedByte();
917  vd.length = inMsg.readDouble();
918 
919  inMsg.readUnsignedByte();
920  vd.entryTime = inMsg.readDouble();
921 
922  inMsg.readUnsignedByte();
923  vd.leaveTime = inMsg.readDouble();
924 
925  inMsg.readUnsignedByte();
926  vd.typeID = inMsg.readString();
927 
928  result.push_back(vd);
929  }
930  return result;
931 }
932 
933 
934 
935 
936 // ---------------------------------------------------------------------------
937 // TraCIAPI::JunctionScope-methods
938 // ---------------------------------------------------------------------------
939 std::vector<std::string>
941  return myParent.getStringVector(CMD_GET_JUNCTION_VARIABLE, ID_LIST, "");
942 }
943 
945 TraCIAPI::JunctionScope::getPosition(const std::string& junctionID) const {
946  return myParent.getPosition(CMD_GET_JUNCTION_VARIABLE, VAR_POSITION, junctionID);
947 }
948 
949 
950 
951 
952 // ---------------------------------------------------------------------------
953 // TraCIAPI::LaneScope-methods
954 // ---------------------------------------------------------------------------
955 std::vector<std::string>
957  return myParent.getStringVector(CMD_GET_LANE_VARIABLE, ID_LIST, "");
958 }
959 
960 int
962  return myParent.getInt(CMD_GET_LANE_VARIABLE, ID_COUNT, "");
963 }
964 
965 double
966 TraCIAPI::LaneScope::getLength(const std::string& laneID) const {
967  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_LENGTH, laneID);
968 }
969 
970 double
971 TraCIAPI::LaneScope::getMaxSpeed(const std::string& laneID) const {
972  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_MAXSPEED, laneID);
973 }
974 
975 double
976 TraCIAPI::LaneScope::getWidth(const std::string& laneID) const {
977  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_WIDTH, laneID);
978 }
979 
980 std::vector<std::string>
981 TraCIAPI::LaneScope::getAllowed(const std::string& laneID) const {
982  return myParent.getStringVector(CMD_GET_LANE_VARIABLE, LANE_ALLOWED, laneID);
983 }
984 
985 std::vector<std::string>
986 TraCIAPI::LaneScope::getDisallowed(const std::string& laneID) const {
987  return myParent.getStringVector(CMD_GET_LANE_VARIABLE, LANE_DISALLOWED, laneID);
988 }
989 
990 int
991 TraCIAPI::LaneScope::getLinkNumber(const std::string& laneID) const {
992  return myParent.getUnsignedByte(CMD_GET_LANE_VARIABLE, LANE_LINK_NUMBER, laneID);
993 }
994 
995 std::vector<TraCIConnection>
996 TraCIAPI::LaneScope::getLinks(const std::string& laneID) const {
997  tcpip::Storage inMsg;
998  myParent.send_commandGetVariable(CMD_GET_LANE_VARIABLE, LANE_LINKS, laneID);
999  myParent.processGET(inMsg, CMD_GET_LANE_VARIABLE, TYPE_COMPOUND);
1000  std::vector<TraCIConnection> ret;
1001 
1002  inMsg.readUnsignedByte();
1003  inMsg.readInt();
1004 
1005  int linkNo = inMsg.readInt();
1006  for (int i = 0; i < linkNo; ++i) {
1007 
1008  inMsg.readUnsignedByte();
1009  std::string approachedLane = inMsg.readString();
1010 
1011  inMsg.readUnsignedByte();
1012  std::string approachedLaneInternal = inMsg.readString();
1013 
1014  inMsg.readUnsignedByte();
1015  bool hasPrio = inMsg.readUnsignedByte() != 0;
1016 
1017  inMsg.readUnsignedByte();
1018  bool isOpen = inMsg.readUnsignedByte() != 0;
1019 
1020  inMsg.readUnsignedByte();
1021  bool hasFoe = inMsg.readUnsignedByte() != 0;
1022 
1023  inMsg.readUnsignedByte();
1024  std::string state = inMsg.readString();
1025 
1026  inMsg.readUnsignedByte();
1027  std::string direction = inMsg.readString();
1028 
1029  inMsg.readUnsignedByte();
1030  double length = inMsg.readDouble();
1031 
1032  ret.push_back(TraCIConnection(approachedLane,
1033  hasPrio,
1034  isOpen,
1035  hasFoe,
1036  approachedLaneInternal,
1037  state,
1038  direction,
1039  length));
1040 
1041  }
1042  return ret;
1043 }
1044 
1046 TraCIAPI::LaneScope::getShape(const std::string& laneID) const {
1047  return myParent.getPolygon(CMD_GET_LANE_VARIABLE, VAR_SHAPE, laneID);
1048 }
1049 
1050 std::string
1051 TraCIAPI::LaneScope::getEdgeID(const std::string& laneID) const {
1052  return myParent.getString(CMD_GET_LANE_VARIABLE, LANE_EDGE_ID, laneID);
1053 }
1054 
1055 double
1056 TraCIAPI::LaneScope::getCO2Emission(const std::string& laneID) const {
1057  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_CO2EMISSION, laneID);
1058 }
1059 
1060 double
1061 TraCIAPI::LaneScope::getCOEmission(const std::string& laneID) const {
1062  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_COEMISSION, laneID);
1063 }
1064 
1065 double
1066 TraCIAPI::LaneScope::getHCEmission(const std::string& laneID) const {
1067  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_HCEMISSION, laneID);
1068 }
1069 
1070 double
1071 TraCIAPI::LaneScope::getPMxEmission(const std::string& laneID) const {
1072  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_PMXEMISSION, laneID);
1073 }
1074 
1075 double
1076 TraCIAPI::LaneScope::getNOxEmission(const std::string& laneID) const {
1077  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_NOXEMISSION, laneID);
1078 }
1079 
1080 double
1081 TraCIAPI::LaneScope::getFuelConsumption(const std::string& laneID) const {
1082  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_FUELCONSUMPTION, laneID);
1083 }
1084 
1085 double
1086 TraCIAPI::LaneScope::getNoiseEmission(const std::string& laneID) const {
1087  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_NOISEEMISSION, laneID);
1088 }
1089 
1090 double
1091 TraCIAPI::LaneScope::getElectricityConsumption(const std::string& laneID) const {
1092  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_ELECTRICITYCONSUMPTION, laneID);
1093 }
1094 
1095 double
1096 TraCIAPI::LaneScope::getLastStepMeanSpeed(const std::string& laneID) const {
1097  return myParent.getDouble(CMD_GET_LANE_VARIABLE, LAST_STEP_MEAN_SPEED, laneID);
1098 }
1099 
1100 double
1101 TraCIAPI::LaneScope::getLastStepOccupancy(const std::string& laneID) const {
1102  return myParent.getDouble(CMD_GET_LANE_VARIABLE, LAST_STEP_OCCUPANCY, laneID);
1103 }
1104 
1105 double
1106 TraCIAPI::LaneScope::getLastStepLength(const std::string& laneID) const {
1107  return myParent.getDouble(CMD_GET_LANE_VARIABLE, LAST_STEP_LENGTH, laneID);
1108 }
1109 
1110 double
1111 TraCIAPI::LaneScope::getTraveltime(const std::string& laneID) const {
1112  return myParent.getDouble(CMD_GET_LANE_VARIABLE, VAR_CURRENT_TRAVELTIME, laneID);
1113 }
1114 
1115 int
1116 TraCIAPI::LaneScope::getLastStepVehicleNumber(const std::string& laneID) const {
1117  return myParent.getInt(CMD_GET_LANE_VARIABLE, LAST_STEP_VEHICLE_NUMBER, laneID);
1118 }
1119 
1120 int
1121 TraCIAPI::LaneScope::getLastStepHaltingNumber(const std::string& laneID) const {
1122  return myParent.getInt(CMD_GET_LANE_VARIABLE, LAST_STEP_VEHICLE_HALTING_NUMBER, laneID);
1123 }
1124 
1125 std::vector<std::string>
1126 TraCIAPI::LaneScope::getLastStepVehicleIDs(const std::string& laneID) const {
1127  return myParent.getStringVector(CMD_GET_LANE_VARIABLE, LAST_STEP_VEHICLE_ID_LIST, laneID);
1128 }
1129 
1130 
1131 void
1132 TraCIAPI::LaneScope::setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const {
1133  tcpip::Storage content;
1135  content.writeInt((int)allowedClasses.size());
1136  for (int i = 0; i < (int)allowedClasses.size(); ++i) {
1137  content.writeString(allowedClasses[i]);
1138  }
1139  myParent.send_commandSetValue(CMD_SET_LANE_VARIABLE, LANE_ALLOWED, laneID, content);
1140  tcpip::Storage inMsg;
1141  myParent.check_resultState(inMsg, CMD_SET_LANE_VARIABLE);
1142 }
1143 
1144 void
1145 TraCIAPI::LaneScope::setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const {
1146  tcpip::Storage content;
1148  content.writeInt((int)disallowedClasses.size());
1149  for (int i = 0; i < (int)disallowedClasses.size(); ++i) {
1150  content.writeString(disallowedClasses[i]);
1151  }
1152  myParent.send_commandSetValue(CMD_SET_LANE_VARIABLE, LANE_DISALLOWED, laneID, content);
1153  tcpip::Storage inMsg;
1154  myParent.check_resultState(inMsg, CMD_SET_LANE_VARIABLE);
1155 }
1156 
1157 void
1158 TraCIAPI::LaneScope::setMaxSpeed(const std::string& laneID, double speed) const {
1159  tcpip::Storage content;
1160  content.writeUnsignedByte(TYPE_DOUBLE);
1161  content.writeDouble(speed);
1162  myParent.send_commandSetValue(CMD_SET_LANE_VARIABLE, VAR_MAXSPEED, laneID, content);
1163  tcpip::Storage inMsg;
1164  myParent.check_resultState(inMsg, CMD_SET_LANE_VARIABLE);
1165 }
1166 
1167 void
1168 TraCIAPI::LaneScope::setLength(const std::string& laneID, double length) const {
1169  tcpip::Storage content;
1170  content.writeUnsignedByte(TYPE_DOUBLE);
1171  content.writeDouble(length);
1172  myParent.send_commandSetValue(CMD_SET_LANE_VARIABLE, VAR_LENGTH, laneID, content);
1173  tcpip::Storage inMsg;
1174  myParent.check_resultState(inMsg, CMD_SET_LANE_VARIABLE);
1175 }
1176 
1177 
1178 // ---------------------------------------------------------------------------
1179 // TraCIAPI::LaneAreaDetector-methods
1180 // ---------------------------------------------------------------------------
1181 std::vector<std::string>
1183  return myParent.getStringVector(CMD_GET_LANEAREA_VARIABLE, ID_LIST, "");
1184 }
1185 
1186 
1187 
1188 
1189 // ---------------------------------------------------------------------------
1190 // TraCIAPI::MeMeScope-methods
1191 // ---------------------------------------------------------------------------
1192 std::vector<std::string>
1194  return myParent.getStringVector(CMD_GET_MULTIENTRYEXIT_VARIABLE, ID_LIST, "");
1195 }
1196 
1197 int
1198 TraCIAPI::MeMeScope::getLastStepVehicleNumber(const std::string& detID) const {
1199  return myParent.getInt(CMD_GET_MULTIENTRYEXIT_VARIABLE, LAST_STEP_VEHICLE_NUMBER, detID);
1200 }
1201 
1202 double
1203 TraCIAPI::MeMeScope::getLastStepMeanSpeed(const std::string& detID) const {
1204  return myParent.getInt(CMD_GET_MULTIENTRYEXIT_VARIABLE, LAST_STEP_MEAN_SPEED, detID);
1205 }
1206 
1207 std::vector<std::string>
1208 TraCIAPI::MeMeScope::getLastStepVehicleIDs(const std::string& detID) const {
1209  return myParent.getStringVector(CMD_GET_MULTIENTRYEXIT_VARIABLE, LAST_STEP_VEHICLE_ID_LIST, detID);
1210 }
1211 
1212 int
1213 TraCIAPI::MeMeScope::getLastStepHaltingNumber(const std::string& detID) const {
1214  return myParent.getInt(CMD_GET_MULTIENTRYEXIT_VARIABLE, LAST_STEP_VEHICLE_HALTING_NUMBER, detID);
1215 }
1216 
1217 
1218 
1219 // ---------------------------------------------------------------------------
1220 // TraCIAPI::POIScope-methods
1221 // ---------------------------------------------------------------------------
1222 std::vector<std::string>
1224  return myParent.getStringVector(CMD_GET_POI_VARIABLE, ID_LIST, "");
1225 }
1226 
1227 std::string
1228 TraCIAPI::POIScope::getType(const std::string& poiID) const {
1229  return myParent.getString(CMD_GET_POI_VARIABLE, VAR_TYPE, poiID);
1230 }
1231 
1233 TraCIAPI::POIScope::getPosition(const std::string& poiID) const {
1234  return myParent.getPosition(CMD_GET_POI_VARIABLE, VAR_POSITION, poiID);
1235 }
1236 
1237 TraCIColor
1238 TraCIAPI::POIScope::getColor(const std::string& poiID) const {
1239  return myParent.getColor(CMD_GET_POI_VARIABLE, VAR_COLOR, poiID);
1240 }
1241 
1242 
1243 void
1244 TraCIAPI::POIScope::setType(const std::string& poiID, const std::string& setType) const {
1245  tcpip::Storage content;
1246  content.writeUnsignedByte(TYPE_STRING);
1247  content.writeString(setType);
1248  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, VAR_TYPE, poiID, content);
1249  tcpip::Storage inMsg;
1250  myParent.check_resultState(inMsg, CMD_SET_POI_VARIABLE);
1251 }
1252 
1253 void
1254 TraCIAPI::POIScope::setPosition(const std::string& poiID, double x, double y) const {
1255  tcpip::Storage content;
1256  content.writeUnsignedByte(POSITION_2D);
1257  content.writeDouble(x);
1258  content.writeDouble(y);
1259  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, VAR_POSITION, poiID, content);
1260  tcpip::Storage inMsg;
1261  myParent.check_resultState(inMsg, CMD_SET_POI_VARIABLE);
1262 }
1263 
1264 void
1265 TraCIAPI::POIScope::setColor(const std::string& poiID, const TraCIColor& c) const {
1266  tcpip::Storage content;
1267  content.writeUnsignedByte(TYPE_COLOR);
1268  content.writeUnsignedByte(c.r);
1269  content.writeUnsignedByte(c.g);
1270  content.writeUnsignedByte(c.b);
1271  content.writeUnsignedByte(c.a);
1272  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, VAR_COLOR, poiID, content);
1273  tcpip::Storage inMsg;
1274  myParent.check_resultState(inMsg, CMD_SET_POI_VARIABLE);
1275 }
1276 
1277 void
1278 TraCIAPI::POIScope::add(const std::string& poiID, double x, double y, const TraCIColor& c, const std::string& type, int layer) const {
1279  tcpip::Storage content;
1281  content.writeInt(4);
1282  content.writeUnsignedByte(TYPE_STRING);
1283  content.writeString(type);
1284  content.writeUnsignedByte(TYPE_COLOR);
1285  content.writeUnsignedByte(c.r);
1286  content.writeUnsignedByte(c.g);
1287  content.writeUnsignedByte(c.b);
1288  content.writeUnsignedByte(c.a);
1290  content.writeInt(layer);
1291  content.writeUnsignedByte(POSITION_2D);
1292  content.writeDouble(x);
1293  content.writeDouble(y);
1294  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, ADD, poiID, content);
1295  tcpip::Storage inMsg;
1296  myParent.check_resultState(inMsg, CMD_SET_POI_VARIABLE);
1297 }
1298 
1299 void
1300 TraCIAPI::POIScope::remove(const std::string& poiID, int layer) const {
1301  tcpip::Storage content;
1303  content.writeInt(layer);
1304  myParent.send_commandSetValue(CMD_SET_POI_VARIABLE, REMOVE, poiID, content);
1305  tcpip::Storage inMsg;
1306  myParent.check_resultState(inMsg, CMD_SET_POI_VARIABLE);
1307 }
1308 
1309 
1310 
1311 // ---------------------------------------------------------------------------
1312 // TraCIAPI::PolygonScope-methods
1313 // ---------------------------------------------------------------------------
1314 std::vector<std::string>
1316  return myParent.getStringVector(CMD_GET_POLYGON_VARIABLE, ID_LIST, "");
1317 }
1318 
1319 std::string
1320 TraCIAPI::PolygonScope::getType(const std::string& polygonID) const {
1321  return myParent.getString(CMD_GET_POLYGON_VARIABLE, VAR_TYPE, polygonID);
1322 }
1323 
1325 TraCIAPI::PolygonScope::getShape(const std::string& polygonID) const {
1326  return myParent.getPolygon(CMD_GET_POLYGON_VARIABLE, VAR_SHAPE, polygonID);
1327 }
1328 
1329 TraCIColor
1330 TraCIAPI::PolygonScope::getColor(const std::string& polygonID) const {
1331  return myParent.getColor(CMD_GET_POLYGON_VARIABLE, VAR_COLOR, polygonID);
1332 }
1333 
1334 
1335 void
1336 TraCIAPI::PolygonScope::setType(const std::string& polygonID, const std::string& setType) const {
1337  tcpip::Storage content;
1338  content.writeUnsignedByte(TYPE_STRING);
1339  content.writeString(setType);
1340  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, VAR_TYPE, polygonID, content);
1341  tcpip::Storage inMsg;
1342  myParent.check_resultState(inMsg, CMD_SET_POLYGON_VARIABLE);
1343 }
1344 
1345 void
1346 TraCIAPI::PolygonScope::setShape(const std::string& polygonID, const TraCIPositionVector& shape) const {
1347  tcpip::Storage content;
1349  content.writeInt((int)shape.size());
1350  for (int i = 0; i < (int)shape.size(); ++i) {
1351  content.writeDouble(shape[i].x);
1352  content.writeDouble(shape[i].y);
1353  }
1354  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, VAR_POSITION, polygonID, content);
1355  tcpip::Storage inMsg;
1356  myParent.check_resultState(inMsg, CMD_SET_POLYGON_VARIABLE);
1357 }
1358 
1359 void
1360 TraCIAPI::PolygonScope::setColor(const std::string& polygonID, const TraCIColor& c) const {
1361  tcpip::Storage content;
1362  content.writeUnsignedByte(TYPE_COLOR);
1363  content.writeUnsignedByte(c.r);
1364  content.writeUnsignedByte(c.g);
1365  content.writeUnsignedByte(c.b);
1366  content.writeUnsignedByte(c.a);
1367  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, VAR_COLOR, polygonID, content);
1368  tcpip::Storage inMsg;
1369  myParent.check_resultState(inMsg, CMD_SET_POLYGON_VARIABLE);
1370 }
1371 
1372 void
1373 TraCIAPI::PolygonScope::add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) const {
1374  tcpip::Storage content;
1376  content.writeInt(5);
1377  content.writeUnsignedByte(TYPE_STRING);
1378  content.writeString(type);
1379  content.writeUnsignedByte(TYPE_COLOR);
1380  content.writeUnsignedByte(c.r);
1381  content.writeUnsignedByte(c.g);
1382  content.writeUnsignedByte(c.b);
1383  content.writeUnsignedByte(c.a);
1384  content.writeUnsignedByte(TYPE_UBYTE);
1385  int f = fill ? 1 : 0;
1386  content.writeUnsignedByte(f);
1388  content.writeInt(layer);
1390  content.writeUnsignedByte((int)shape.size());
1391  for (int i = 0; i < (int)shape.size(); ++i) {
1392  content.writeDouble(shape[i].x);
1393  content.writeDouble(shape[i].y);
1394  }
1395  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, ADD, polygonID, content);
1396  tcpip::Storage inMsg;
1397  myParent.check_resultState(inMsg, CMD_SET_POLYGON_VARIABLE);
1398 }
1399 
1400 void
1401 TraCIAPI::PolygonScope::remove(const std::string& polygonID, int layer) const {
1402  tcpip::Storage content;
1404  content.writeInt(layer);
1405  myParent.send_commandSetValue(CMD_SET_POLYGON_VARIABLE, REMOVE, polygonID, content);
1406  tcpip::Storage inMsg;
1407  myParent.check_resultState(inMsg, CMD_SET_POLYGON_VARIABLE);
1408 }
1409 
1410 
1411 
1412 // ---------------------------------------------------------------------------
1413 // TraCIAPI::RouteScope-methods
1414 // ---------------------------------------------------------------------------
1415 std::vector<std::string>
1417  return myParent.getStringVector(CMD_GET_ROUTE_VARIABLE, ID_LIST, "");
1418 }
1419 
1420 std::vector<std::string>
1421 TraCIAPI::RouteScope::getEdges(const std::string& routeID) const {
1422  return myParent.getStringVector(CMD_GET_ROUTE_VARIABLE, VAR_EDGES, routeID);
1423 }
1424 
1425 
1426 void
1427 TraCIAPI::RouteScope::add(const std::string& routeID, const std::vector<std::string>& edges) const {
1428  tcpip::Storage content;
1430  content.writeStringList(edges);
1431  myParent.send_commandSetValue(CMD_SET_ROUTE_VARIABLE, ADD, routeID, content);
1432  tcpip::Storage inMsg;
1433  myParent.check_resultState(inMsg, CMD_SET_ROUTE_VARIABLE);
1434 }
1435 
1436 
1437 
1438 
1439 
1440 // ---------------------------------------------------------------------------
1441 // TraCIAPI::SimulationScope-methods
1442 // ---------------------------------------------------------------------------
1443 SUMOTime
1445  return myParent.getSUMOTime(CMD_GET_SIM_VARIABLE, VAR_TIME_STEP, "");
1446 }
1447 
1448 int
1450  return (int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_LOADED_VEHICLES_NUMBER, "");
1451 }
1452 
1453 std::vector<std::string>
1455  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_LOADED_VEHICLES_IDS, "");
1456 }
1457 
1458 int
1460  return (int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_DEPARTED_VEHICLES_NUMBER, "");
1461 }
1462 
1463 std::vector<std::string>
1465  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_DEPARTED_VEHICLES_IDS, "");
1466 }
1467 
1468 int
1470  return (int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_ARRIVED_VEHICLES_NUMBER, "");
1471 }
1472 
1473 std::vector<std::string>
1475  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_ARRIVED_VEHICLES_IDS, "");
1476 }
1477 
1478 int
1480  return (int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_TELEPORT_STARTING_VEHICLES_NUMBER, "");
1481 }
1482 
1483 std::vector<std::string>
1485  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_TELEPORT_STARTING_VEHICLES_IDS, "");
1486 }
1487 
1488 int
1490  return (int) myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_TELEPORT_ENDING_VEHICLES_NUMBER, "");
1491 }
1492 
1493 std::vector<std::string>
1495  return myParent.getStringVector(CMD_GET_SIM_VARIABLE, VAR_TELEPORT_ENDING_VEHICLES_IDS, "");
1496 }
1497 
1498 SUMOTime
1500  return myParent.getSUMOTime(CMD_GET_SIM_VARIABLE, VAR_DELTA_T, "");
1501 }
1502 
1505  return myParent.getBoundingBox(CMD_GET_SIM_VARIABLE, VAR_NET_BOUNDING_BOX, "");
1506 }
1507 
1508 int
1510  return myParent.getInt(CMD_GET_SIM_VARIABLE, VAR_MIN_EXPECTED_VEHICLES, "");
1511 }
1512 
1513 void
1514 TraCIAPI::SimulationScope::subscribe(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, const std::vector<int>& vars) const {
1515  myParent.send_commandSubscribeObjectVariable(domID, objID, beginTime, endTime, vars);
1516  tcpip::Storage inMsg;
1517  myParent.check_resultState(inMsg, domID);
1518  if (vars.size() > 0) {
1519  myParent.check_commandGetResult(inMsg, domID);
1520  myParent.readVariableSubscription(inMsg);
1521  }
1522 }
1523 
1524 void
1525 TraCIAPI::SimulationScope::subscribeContext(int domID, const std::string& objID, SUMOTime beginTime, SUMOTime endTime, int domain, double range, const std::vector<int>& vars) const {
1526 
1527  myParent.send_commandSubscribeObjectContext(domID, objID, beginTime, endTime, domain, range, vars);
1528  tcpip::Storage inMsg;
1529  myParent.check_resultState(inMsg, domID);
1530  myParent.check_commandGetResult(inMsg, domID);
1531  myParent.readContextSubscription(inMsg);
1532 }
1533 
1536  return myParent.mySubscribedValues;
1537 }
1538 
1539 
1540 const TraCIAPI::TraCIValues&
1541 TraCIAPI::SimulationScope::getSubscriptionResults(const std::string& objID) const {
1542  if (myParent.mySubscribedValues.find(objID) != myParent.mySubscribedValues.end()) {
1543  return myParent.mySubscribedValues[objID];
1544  } else {
1545  throw; // Something?
1546  }
1547 }
1548 
1549 
1552  return myParent.mySubscribedContextValues;
1553 }
1554 
1555 
1558  if (myParent.mySubscribedContextValues.find(objID) != myParent.mySubscribedContextValues.end()) {
1559  return myParent.mySubscribedContextValues[objID];
1560  } else {
1561  throw; // Something?
1562  }
1563 }
1564 
1565 
1566 // ---------------------------------------------------------------------------
1567 // TraCIAPI::TrafficLightScope-methods
1568 // ---------------------------------------------------------------------------
1569 std::vector<std::string>
1571  return myParent.getStringVector(CMD_GET_TL_VARIABLE, ID_LIST, "");
1572 }
1573 
1574 std::string
1576  return myParent.getString(CMD_GET_TL_VARIABLE, TL_RED_YELLOW_GREEN_STATE, tlsID);
1577 }
1578 
1579 std::vector<TraCILogic>
1581  tcpip::Storage inMsg;
1582  myParent.send_commandGetVariable(CMD_GET_TL_VARIABLE, TL_COMPLETE_DEFINITION_RYG, tlsID);
1583  myParent.processGET(inMsg, CMD_GET_TL_VARIABLE, TYPE_COMPOUND);
1584  std::vector<TraCILogic> ret;
1585 
1586  inMsg.readUnsignedByte();
1587  inMsg.readInt();
1588 
1589  int logicNo = inMsg.readInt();
1590  for (int i = 0; i < logicNo; ++i) {
1591  inMsg.readUnsignedByte();
1592  std::string subID = inMsg.readString();
1593  inMsg.readUnsignedByte();
1594  int type = inMsg.readInt();
1595  inMsg.readUnsignedByte();
1596  inMsg.readInt(); // add
1597  inMsg.readUnsignedByte();
1598  int phaseIndex = inMsg.readInt();
1599  inMsg.readUnsignedByte();
1600  int phaseNumber = inMsg.readInt();
1601  std::vector<TraCIPhase> phases;
1602  for (int j = 0; j < phaseNumber; ++j) {
1603  inMsg.readUnsignedByte();
1604  int duration = inMsg.readInt();
1605  inMsg.readUnsignedByte();
1606  int duration1 = inMsg.readInt();
1607  inMsg.readUnsignedByte();
1608  int duration2 = inMsg.readInt();
1609  inMsg.readUnsignedByte();
1610  std::string phase = inMsg.readString();
1611  phases.push_back(TraCIPhase(duration, duration1, duration2, phase));
1612  }
1613  ret.push_back(TraCILogic(subID, type, std::map<std::string, double>(), phaseIndex, phases));
1614  }
1615  return ret;
1616 }
1617 
1618 std::vector<std::string>
1619 TraCIAPI::TrafficLightScope::getControlledLanes(const std::string& tlsID) const {
1620  return myParent.getStringVector(CMD_GET_TL_VARIABLE, TL_CONTROLLED_LANES, tlsID);
1621 }
1622 
1623 std::vector<TraCILink>
1624 TraCIAPI::TrafficLightScope::getControlledLinks(const std::string& tlsID) const {
1625  tcpip::Storage inMsg;
1626  myParent.send_commandGetVariable(CMD_GET_TL_VARIABLE, TL_CONTROLLED_LINKS, tlsID);
1627  myParent.processGET(inMsg, CMD_GET_TL_VARIABLE, TYPE_COMPOUND);
1628  std::vector<TraCILink> ret;
1629 
1630  inMsg.readUnsignedByte();
1631  inMsg.readInt();
1632 
1633  int linkNo = inMsg.readInt();
1634  for (int i = 0; i < linkNo; ++i) {
1635  inMsg.readUnsignedByte();
1636  int no = inMsg.readInt();
1637 
1638  for (int i1 = 0; i1 < no; ++i1) {
1639  inMsg.readUnsignedByte();
1640  inMsg.readInt();
1641  std::string from = inMsg.readString();
1642  std::string to = inMsg.readString();
1643  std::string via = inMsg.readString();
1644  ret.push_back(TraCILink(from, via, to));
1645  }
1646 
1647  }
1648  return ret;
1649 }
1650 
1651 std::string
1652 TraCIAPI::TrafficLightScope::getProgram(const std::string& tlsID) const {
1653  return myParent.getString(CMD_GET_TL_VARIABLE, TL_CURRENT_PROGRAM, tlsID);
1654 }
1655 
1656 int
1657 TraCIAPI::TrafficLightScope::getPhase(const std::string& tlsID) const {
1658  return myParent.getInt(CMD_GET_TL_VARIABLE, TL_CURRENT_PHASE, tlsID);
1659 }
1660 
1661 int
1662 TraCIAPI::TrafficLightScope::getNextSwitch(const std::string& tlsID) const {
1663  return myParent.getInt(CMD_GET_TL_VARIABLE, TL_NEXT_SWITCH, tlsID);
1664 }
1665 
1666 
1667 void
1668 TraCIAPI::TrafficLightScope::setRedYellowGreenState(const std::string& tlsID, const std::string& state) const {
1669  tcpip::Storage content;
1670  content.writeUnsignedByte(TYPE_STRING);
1671  content.writeString(state);
1672  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_RED_YELLOW_GREEN_STATE, tlsID, content);
1673  tcpip::Storage inMsg;
1674  myParent.check_resultState(inMsg, CMD_SET_TL_VARIABLE);
1675 }
1676 
1677 void
1678 TraCIAPI::TrafficLightScope::setPhase(const std::string& tlsID, int index) const {
1679  tcpip::Storage content;
1681  content.writeInt(index);
1682  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_PHASE_INDEX, tlsID, content);
1683  tcpip::Storage inMsg;
1684  myParent.check_resultState(inMsg, CMD_SET_TL_VARIABLE);
1685 }
1686 
1687 void
1688 TraCIAPI::TrafficLightScope::setProgram(const std::string& tlsID, const std::string& programID) const {
1689  tcpip::Storage content;
1690  content.writeUnsignedByte(TYPE_STRING);
1691  content.writeString(programID);
1692  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_PROGRAM, tlsID, content);
1693  tcpip::Storage inMsg;
1694  myParent.check_resultState(inMsg, CMD_SET_TL_VARIABLE);
1695 }
1696 
1697 void
1698 TraCIAPI::TrafficLightScope::setPhaseDuration(const std::string& tlsID, int phaseDuration) const {
1699  tcpip::Storage content;
1701  content.writeInt(int(1000 * phaseDuration));
1702  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_PHASE_DURATION, tlsID, content);
1703  tcpip::Storage inMsg;
1704  myParent.check_resultState(inMsg, CMD_SET_TL_VARIABLE);
1705 }
1706 
1707 void
1709  tcpip::Storage content;
1711  content.writeInt(5 + 4 * (int)logic.phases.size());
1712  content.writeUnsignedByte(TYPE_STRING);
1713  content.writeString(logic.subID);
1715  content.writeInt(logic.type);
1717  content.writeInt(0);
1719  content.writeInt(logic.currentPhaseIndex);
1721  content.writeInt((int)logic.phases.size());
1722  for (int i = 0; i < (int) logic.phases.size(); ++i) {
1724  content.writeInt((int)logic.phases[i].duration);
1726  content.writeInt((int)logic.phases[i].duration1);
1728  content.writeInt((int)logic.phases[i].duration2);
1729  content.writeUnsignedByte(TYPE_STRING);
1730  content.writeString(logic.phases[i].phase);
1731  }
1732  myParent.send_commandSetValue(CMD_SET_TL_VARIABLE, TL_COMPLETE_PROGRAM_RYG, tlsID, content);
1733  tcpip::Storage inMsg;
1734  myParent.check_resultState(inMsg, CMD_SET_TL_VARIABLE);
1735 }
1736 
1737 
1738 
1739 
1740 
1741 // ---------------------------------------------------------------------------
1742 // TraCIAPI::VehicleTypeScope-methods
1743 // ---------------------------------------------------------------------------
1744 std::vector<std::string>
1746  return myParent.getStringVector(CMD_GET_VEHICLETYPE_VARIABLE, ID_LIST, "");
1747 }
1748 
1749 double
1750 TraCIAPI::VehicleTypeScope::getLength(const std::string& typeID) const {
1751  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_LENGTH, typeID);
1752 }
1753 
1754 double
1755 TraCIAPI::VehicleTypeScope::getMaxSpeed(const std::string& typeID) const {
1756  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_MAXSPEED, typeID);
1757 }
1758 
1759 double
1760 TraCIAPI::VehicleTypeScope::getSpeedFactor(const std::string& typeID) const {
1761  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_SPEED_FACTOR, typeID);
1762 }
1763 
1764 double
1765 TraCIAPI::VehicleTypeScope::getSpeedDeviation(const std::string& typeID) const {
1766  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_SPEED_DEVIATION, typeID);
1767 }
1768 
1769 double
1770 TraCIAPI::VehicleTypeScope::getAccel(const std::string& typeID) const {
1771  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_ACCEL, typeID);
1772 }
1773 
1774 double
1775 TraCIAPI::VehicleTypeScope::getDecel(const std::string& typeID) const {
1776  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_DECEL, typeID);
1777 }
1778 
1779 double
1780 TraCIAPI::VehicleTypeScope::getEmergencyDecel(const std::string& typeID) const {
1781  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_EMERGENCY_DECEL, typeID);
1782 }
1783 
1784 double
1785 TraCIAPI::VehicleTypeScope::getApparentDecel(const std::string& typeID) const {
1786  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_APPARENT_DECEL, typeID);
1787 }
1788 
1789 double
1790 TraCIAPI::VehicleTypeScope::getImperfection(const std::string& typeID) const {
1791  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_IMPERFECTION, typeID);
1792 }
1793 
1794 double
1795 TraCIAPI::VehicleTypeScope::getTau(const std::string& typeID) const {
1796  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_TAU, typeID);
1797 }
1798 
1799 std::string
1800 TraCIAPI::VehicleTypeScope::getVehicleClass(const std::string& typeID) const {
1801  return myParent.getString(CMD_GET_VEHICLETYPE_VARIABLE, VAR_VEHICLECLASS, typeID);
1802 }
1803 
1804 std::string
1805 TraCIAPI::VehicleTypeScope::getEmissionClass(const std::string& typeID) const {
1806  return myParent.getString(CMD_GET_VEHICLETYPE_VARIABLE, VAR_EMISSIONCLASS, typeID);
1807 }
1808 
1809 std::string
1810 TraCIAPI::VehicleTypeScope::getShapeClass(const std::string& typeID) const {
1811  return myParent.getString(CMD_GET_VEHICLETYPE_VARIABLE, VAR_SHAPECLASS, typeID);
1812 }
1813 
1814 double
1815 TraCIAPI::VehicleTypeScope::getMinGap(const std::string& typeID) const {
1816  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_MINGAP, typeID);
1817 }
1818 
1819 double
1820 TraCIAPI::VehicleTypeScope::getMinGapLat(const std::string& typeID) const {
1821  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_MINGAP_LAT, typeID);
1822 }
1823 
1824 double
1825 TraCIAPI::VehicleTypeScope::getMaxSpeedLat(const std::string& typeID) const {
1826  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_MAXSPEED_LAT, typeID);
1827 }
1828 
1829 std::string
1830 TraCIAPI::VehicleTypeScope::getLateralAlignment(const std::string& typeID) const {
1831  return myParent.getString(CMD_GET_VEHICLETYPE_VARIABLE, VAR_LATALIGNMENT, typeID);
1832 }
1833 
1834 double
1835 TraCIAPI::VehicleTypeScope::getWidth(const std::string& typeID) const {
1836  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_WIDTH, typeID);
1837 }
1838 
1839 double
1840 TraCIAPI::VehicleTypeScope::getHeight(const std::string& typeID) const {
1841  return myParent.getDouble(CMD_GET_VEHICLETYPE_VARIABLE, VAR_HEIGHT, typeID);
1842 }
1843 
1844 TraCIColor
1845 TraCIAPI::VehicleTypeScope::getColor(const std::string& typeID) const {
1846  return myParent.getColor(CMD_GET_VEHICLETYPE_VARIABLE, VAR_COLOR, typeID);
1847 }
1848 
1849 
1850 
1851 void
1852 TraCIAPI::VehicleTypeScope::setLength(const std::string& typeID, double length) const {
1853  tcpip::Storage content;
1854  content.writeUnsignedByte(TYPE_DOUBLE);
1855  content.writeDouble(length);
1856  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_LENGTH, typeID, content);
1857  tcpip::Storage inMsg;
1858  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1859 }
1860 
1861 void
1862 TraCIAPI::VehicleTypeScope::setMaxSpeed(const std::string& typeID, double speed) const {
1863  tcpip::Storage content;
1864  content.writeUnsignedByte(TYPE_DOUBLE);
1865  content.writeDouble(speed);
1866  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_MAXSPEED, typeID, content);
1867  tcpip::Storage inMsg;
1868  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1869 }
1870 
1871 void
1872 TraCIAPI::VehicleTypeScope::setVehicleClass(const std::string& typeID, const std::string& clazz) const {
1873  tcpip::Storage content;
1874  content.writeUnsignedByte(TYPE_STRING);
1875  content.writeString(clazz);
1876  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_VEHICLECLASS, typeID, content);
1877  tcpip::Storage inMsg;
1878  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1879 }
1880 
1881 void
1882 TraCIAPI::VehicleTypeScope::setSpeedFactor(const std::string& typeID, double factor) const {
1883  tcpip::Storage content;
1884  content.writeUnsignedByte(TYPE_DOUBLE);
1885  content.writeDouble(factor);
1886  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_SPEED_FACTOR, typeID, content);
1887  tcpip::Storage inMsg;
1888  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1889 }
1890 
1891 void
1892 TraCIAPI::VehicleTypeScope::setSpeedDeviation(const std::string& typeID, double deviation) const {
1893  tcpip::Storage content;
1894  content.writeUnsignedByte(TYPE_DOUBLE);
1895  content.writeDouble(deviation);
1896  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_SPEED_DEVIATION, typeID, content);
1897  tcpip::Storage inMsg;
1898  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1899 }
1900 
1901 
1902 void
1903 TraCIAPI::VehicleTypeScope::setEmissionClass(const std::string& typeID, const std::string& clazz) const {
1904  tcpip::Storage content;
1905  content.writeUnsignedByte(TYPE_STRING);
1906  content.writeString(clazz);
1907  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_EMISSIONCLASS, typeID, content);
1908  tcpip::Storage inMsg;
1909  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1910 }
1911 
1912 void
1913 TraCIAPI::VehicleTypeScope::setWidth(const std::string& typeID, double width) const {
1914  tcpip::Storage content;
1915  content.writeUnsignedByte(TYPE_DOUBLE);
1916  content.writeDouble(width);
1917  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_WIDTH, typeID, content);
1918  tcpip::Storage inMsg;
1919  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1920 }
1921 
1922 void
1923 TraCIAPI::VehicleTypeScope::setHeight(const std::string& typeID, double height) const {
1924  tcpip::Storage content;
1925  content.writeUnsignedByte(TYPE_DOUBLE);
1926  content.writeDouble(height);
1927  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_HEIGHT, typeID, content);
1928  tcpip::Storage inMsg;
1929  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1930 }
1931 
1932 void
1933 TraCIAPI::VehicleTypeScope::setMinGap(const std::string& typeID, double minGap) const {
1934  tcpip::Storage content;
1935  content.writeUnsignedByte(TYPE_DOUBLE);
1936  content.writeDouble(minGap);
1937  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_MINGAP, typeID, content);
1938  tcpip::Storage inMsg;
1939  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1940 }
1941 
1942 
1943 void
1944 TraCIAPI::VehicleTypeScope::setMinGapLat(const std::string& typeID, double minGapLat) const {
1945  tcpip::Storage content;
1946  content.writeUnsignedByte(TYPE_DOUBLE);
1947  content.writeDouble(minGapLat);
1948  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_MINGAP_LAT, typeID, content);
1949  tcpip::Storage inMsg;
1950  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1951 }
1952 
1953 void
1954 TraCIAPI::VehicleTypeScope::setMaxSpeedLat(const std::string& typeID, double speed) const {
1955  tcpip::Storage content;
1956  content.writeUnsignedByte(TYPE_DOUBLE);
1957  content.writeDouble(speed);
1958  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_MAXSPEED_LAT, typeID, content);
1959  tcpip::Storage inMsg;
1960  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1961 }
1962 
1963 void
1964 TraCIAPI::VehicleTypeScope::setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const {
1965  tcpip::Storage content;
1966  content.writeUnsignedByte(TYPE_STRING);
1967  content.writeString(latAlignment);
1968  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_LATALIGNMENT, typeID, content);
1969  tcpip::Storage inMsg;
1970  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1971 }
1972 
1973 void
1974 TraCIAPI::VehicleTypeScope::copy(const std::string& origTypeID, const std::string& newTypeID) const {
1975  tcpip::Storage content;
1976  content.writeUnsignedByte(TYPE_STRING);
1977  content.writeString(newTypeID);
1978  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, COPY, origTypeID, content);
1979  tcpip::Storage inMsg;
1980  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1981 }
1982 
1983 void
1984 TraCIAPI::VehicleTypeScope::setShapeClass(const std::string& typeID, const std::string& clazz) const {
1985  tcpip::Storage content;
1986  content.writeUnsignedByte(TYPE_STRING);
1987  content.writeString(clazz);
1988  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_SHAPECLASS, typeID, content);
1989  tcpip::Storage inMsg;
1990  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
1991 }
1992 
1993 void
1994 TraCIAPI::VehicleTypeScope::setAccel(const std::string& typeID, double accel) const {
1995  tcpip::Storage content;
1996  content.writeUnsignedByte(TYPE_DOUBLE);
1997  content.writeDouble(accel);
1998  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_ACCEL, typeID, content);
1999  tcpip::Storage inMsg;
2000  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
2001 }
2002 
2003 void
2004 TraCIAPI::VehicleTypeScope::setDecel(const std::string& typeID, double decel) const {
2005  tcpip::Storage content;
2006  content.writeUnsignedByte(TYPE_DOUBLE);
2007  content.writeDouble(decel);
2008  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_DECEL, typeID, content);
2009  tcpip::Storage inMsg;
2010  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
2011 }
2012 
2013 void
2014 TraCIAPI::VehicleTypeScope::setEmergencyDecel(const std::string& typeID, double decel) const {
2015  tcpip::Storage content;
2016  content.writeUnsignedByte(TYPE_DOUBLE);
2017  content.writeDouble(decel);
2018  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_EMERGENCY_DECEL, typeID, content);
2019  tcpip::Storage inMsg;
2020  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
2021 }
2022 
2023 void
2024 TraCIAPI::VehicleTypeScope::setApparentDecel(const std::string& typeID, double decel) const {
2025  tcpip::Storage content;
2026  content.writeUnsignedByte(TYPE_DOUBLE);
2027  content.writeDouble(decel);
2028  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_APPARENT_DECEL, typeID, content);
2029  tcpip::Storage inMsg;
2030  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
2031 }
2032 
2033 void
2034 TraCIAPI::VehicleTypeScope::setImperfection(const std::string& typeID, double imperfection) const {
2035  tcpip::Storage content;
2036  content.writeUnsignedByte(TYPE_DOUBLE);
2037  content.writeDouble(imperfection);
2038  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_IMPERFECTION, typeID, content);
2039  tcpip::Storage inMsg;
2040  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
2041 }
2042 
2043 void
2044 TraCIAPI::VehicleTypeScope::setTau(const std::string& typeID, double tau) const {
2045  tcpip::Storage content;
2046  content.writeUnsignedByte(TYPE_DOUBLE);
2047  content.writeDouble(tau);
2048  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_TAU, typeID, content);
2049  tcpip::Storage inMsg;
2050  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
2051 }
2052 
2053 void
2054 TraCIAPI::VehicleTypeScope::setColor(const std::string& typeID, const TraCIColor& c) const {
2055  tcpip::Storage content;
2056  content.writeUnsignedByte(TYPE_COLOR);
2057  content.writeUnsignedByte(c.r);
2058  content.writeUnsignedByte(c.g);
2059  content.writeUnsignedByte(c.b);
2060  content.writeUnsignedByte(c.a);
2061  myParent.send_commandSetValue(CMD_SET_VEHICLETYPE_VARIABLE, VAR_COLOR, typeID, content);
2062  tcpip::Storage inMsg;
2063  myParent.check_resultState(inMsg, CMD_SET_VEHICLETYPE_VARIABLE);
2064 }
2065 
2066 
2067 
2068 
2069 
2070 // ---------------------------------------------------------------------------
2071 // TraCIAPI::VehicleScope-methods
2072 // ---------------------------------------------------------------------------
2073 std::vector<std::string>
2075  return myParent.getStringVector(CMD_GET_VEHICLE_VARIABLE, ID_LIST, "");
2076 }
2077 
2078 int
2080  return myParent.getInt(CMD_GET_VEHICLE_VARIABLE, ID_COUNT, "");
2081 }
2082 
2083 double
2084 TraCIAPI::VehicleScope::getSpeed(const std::string& vehicleID) const {
2085  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_SPEED, vehicleID);
2086 }
2087 
2088 double
2089 TraCIAPI::VehicleScope::getMaxSpeed(const std::string& vehicleID) const {
2090  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_MAXSPEED, vehicleID);
2091 }
2092 
2094 TraCIAPI::VehicleScope::getPosition(const std::string& vehicleID) const {
2095  return myParent.getPosition(CMD_GET_VEHICLE_VARIABLE, VAR_POSITION, vehicleID);
2096 }
2097 
2099 TraCIAPI::VehicleScope::getPosition3D(const std::string& vehicleID) const {
2100  return myParent.getPosition3D(CMD_GET_VEHICLE_VARIABLE, VAR_POSITION3D, vehicleID);
2101 }
2102 
2103 double
2104 TraCIAPI::VehicleScope::getAngle(const std::string& vehicleID) const {
2105  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_ANGLE, vehicleID);
2106 }
2107 
2108 std::string
2109 TraCIAPI::VehicleScope::getRoadID(const std::string& vehicleID) const {
2110  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_ROAD_ID, vehicleID);
2111 }
2112 
2113 std::string
2114 TraCIAPI::VehicleScope::getLaneID(const std::string& vehicleID) const {
2115  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_LANE_ID, vehicleID);
2116 }
2117 
2118 int
2119 TraCIAPI::VehicleScope::getLaneIndex(const std::string& vehicleID) const {
2120  return myParent.getInt(CMD_GET_VEHICLE_VARIABLE, VAR_LANE_INDEX, vehicleID);
2121 }
2122 
2123 std::string
2124 TraCIAPI::VehicleScope::getTypeID(const std::string& vehicleID) const {
2125  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_TYPE, vehicleID);
2126 }
2127 
2128 std::string
2129 TraCIAPI::VehicleScope::getRouteID(const std::string& vehicleID) const {
2130  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_ROUTE_ID, vehicleID);
2131 }
2132 
2133 int
2134 TraCIAPI::VehicleScope::getRouteIndex(const std::string& vehicleID) const {
2135  return myParent.getInt(CMD_GET_VEHICLE_VARIABLE, VAR_ROUTE_INDEX, vehicleID);
2136 }
2137 
2138 std::vector<std::string>
2139 TraCIAPI::VehicleScope::getEdges(const std::string& vehicleID) const {
2140  return getRoute(vehicleID);
2141 }
2142 
2143 std::vector<std::string>
2144 TraCIAPI::VehicleScope::getRoute(const std::string& vehicleID) const {
2145  return myParent.getStringVector(CMD_GET_VEHICLE_VARIABLE, VAR_EDGES, vehicleID);
2146 }
2147 
2148 TraCIColor
2149 TraCIAPI::VehicleScope::getColor(const std::string& vehicleID) const {
2150  return myParent.getColor(CMD_GET_VEHICLE_VARIABLE, VAR_COLOR, vehicleID);
2151 }
2152 
2153 double
2154 TraCIAPI::VehicleScope::getLanePosition(const std::string& vehicleID) const {
2155  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_LANEPOSITION, vehicleID);
2156 }
2157 
2158 double
2159 TraCIAPI::VehicleScope::getDistance(const std::string& vehicleID) const {
2160  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_DISTANCE, vehicleID);
2161 }
2162 
2163 double
2164 TraCIAPI::VehicleScope::getLateralLanePosition(const std::string& vehicleID) const {
2165  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_LANEPOSITION_LAT, vehicleID);
2166 }
2167 
2168 double
2169 TraCIAPI::VehicleScope::getCO2Emission(const std::string& vehicleID) const {
2170  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_CO2EMISSION, vehicleID);
2171 }
2172 
2173 double
2174 TraCIAPI::VehicleScope::getCOEmission(const std::string& vehicleID) const {
2175  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_COEMISSION, vehicleID);
2176 }
2177 
2178 double
2179 TraCIAPI::VehicleScope::getHCEmission(const std::string& vehicleID) const {
2180  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_HCEMISSION, vehicleID);
2181 }
2182 
2183 double
2184 TraCIAPI::VehicleScope::getPMxEmission(const std::string& vehicleID) const {
2185  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_PMXEMISSION, vehicleID);
2186 }
2187 
2188 double
2189 TraCIAPI::VehicleScope::getNOxEmission(const std::string& vehicleID) const {
2190  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_NOXEMISSION, vehicleID);
2191 }
2192 
2193 double
2194 TraCIAPI::VehicleScope::getFuelConsumption(const std::string& vehicleID) const {
2195  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_FUELCONSUMPTION, vehicleID);
2196 }
2197 
2198 double
2199 TraCIAPI::VehicleScope::getNoiseEmission(const std::string& vehicleID) const {
2200  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_NOISEEMISSION, vehicleID);
2201 }
2202 
2203 double
2204 TraCIAPI::VehicleScope::getElectricityConsumption(const std::string& vehicleID) const {
2205  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_ELECTRICITYCONSUMPTION, vehicleID);
2206 }
2207 
2208 double
2209 TraCIAPI::VehicleScope::getWaitingTime(const std::string& vehID) const {
2210  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_WAITING_TIME, vehID);
2211 }
2212 
2213 int
2214 TraCIAPI::VehicleScope::getSpeedMode(const std::string& vehID) const {
2215  return myParent.getInt(CMD_GET_VEHICLE_VARIABLE, VAR_SPEEDSETMODE, vehID);
2216 }
2217 
2218 
2219 double
2220 TraCIAPI::VehicleScope::getSlope(const std::string& vehID) const {
2221  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_SLOPE, vehID);
2222 }
2223 
2224 
2225 std::string
2226 TraCIAPI::VehicleScope::getLine(const std::string& typeID) const {
2227  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_LINE, typeID);
2228 }
2229 
2230 std::vector<std::string>
2231 TraCIAPI::VehicleScope::getVia(const std::string& vehicleID) const {
2232  return myParent.getStringVector(CMD_GET_VEHICLE_VARIABLE, VAR_VIA, vehicleID);
2233 }
2234 
2235 std::string
2236 TraCIAPI::VehicleScope::getEmissionClass(const std::string& vehicleID) const {
2237  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_EMISSIONCLASS, vehicleID);
2238 }
2239 
2240 std::string
2241 TraCIAPI::VehicleScope::getShapeClass(const std::string& vehicleID) const {
2242  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_SHAPECLASS, vehicleID);
2243 }
2244 
2245 std::vector<TraCINextTLSData>
2246 TraCIAPI::VehicleScope::getNextTLS(const std::string& vehID) const {
2247  tcpip::Storage inMsg;
2248  myParent.send_commandGetVariable(CMD_GET_VEHICLE_VARIABLE, VAR_NEXT_TLS, vehID);
2249  myParent.processGET(inMsg, CMD_GET_VEHICLE_VARIABLE, TYPE_COMPOUND);
2250  std::vector<TraCINextTLSData> result;
2251  inMsg.readInt(); // components
2252  // number of items
2253  inMsg.readUnsignedByte();
2254  const int n = inMsg.readInt();
2255  for (int i = 0; i < n; ++i) {
2256  TraCINextTLSData d;
2257  inMsg.readUnsignedByte();
2258  d.id = inMsg.readString();
2259 
2260  inMsg.readUnsignedByte();
2261  d.tlIndex = inMsg.readInt();
2262 
2263  inMsg.readUnsignedByte();
2264  d.dist = inMsg.readDouble();
2265 
2266  inMsg.readUnsignedByte();
2267  d.state = (char)inMsg.readByte();
2268 
2269  result.push_back(d);
2270  }
2271  return result;
2272 }
2273 
2274 std::vector<TraCIBestLanesData>
2275 TraCIAPI::VehicleScope::getBestLanes(const std::string& vehicleID) const {
2276  tcpip::Storage inMsg;
2277  myParent.send_commandGetVariable(CMD_GET_VEHICLE_VARIABLE, VAR_BEST_LANES, vehicleID);
2278  myParent.processGET(inMsg, CMD_GET_VEHICLE_VARIABLE, TYPE_COMPOUND);
2279  inMsg.readInt();
2280  inMsg.readUnsignedByte();
2281 
2282  std::vector<TraCIBestLanesData> result;
2283  const int n = inMsg.readInt(); // number of following edge information
2284  for (int i = 0; i < n; ++i) {
2285  TraCIBestLanesData info;
2286  inMsg.readUnsignedByte();
2287  info.laneID = inMsg.readString();
2288 
2289  inMsg.readUnsignedByte();
2290  info.length = inMsg.readDouble();
2291 
2292  inMsg.readUnsignedByte();
2293  info.occupation = inMsg.readDouble();
2294 
2295  inMsg.readUnsignedByte();
2296  info.bestLaneOffset = inMsg.readByte();
2297 
2298  inMsg.readUnsignedByte();
2299  info.allowsContinuation = (inMsg.readUnsignedByte() == 1);
2300 
2301  inMsg.readUnsignedByte();
2302  const int m = inMsg.readInt();
2303  for (int i = 0; i < m; ++i) {
2304  info.continuationLanes.push_back(inMsg.readString());
2305  }
2306 
2307  result.push_back(info);
2308  }
2309  return result;
2310 }
2311 
2312 
2313 std::pair<std::string, double>
2314 TraCIAPI::VehicleScope::getLeader(const std::string& vehicleID, double dist) const {
2315  tcpip::Storage content;
2316  content.writeByte(TYPE_DOUBLE);
2317  content.writeDouble(dist);
2318  myParent.send_commandGetVariable(CMD_GET_VEHICLE_VARIABLE, VAR_LEADER, vehicleID, &content);
2319  tcpip::Storage inMsg;
2320  myParent.processGET(inMsg, CMD_GET_VEHICLE_VARIABLE, TYPE_COMPOUND);
2321  inMsg.readInt(); // components
2322  inMsg.readUnsignedByte();
2323  const std::string leaderID = inMsg.readString();
2324  inMsg.readUnsignedByte();
2325  const double gap = inMsg.readDouble();
2326  return make_pair(leaderID, gap);
2327 }
2328 
2329 
2330 int
2331 TraCIAPI::VehicleScope::getStopState(const std::string& vehicleID) const {
2332  return myParent.getUnsignedByte(CMD_GET_VEHICLE_VARIABLE, VAR_STOPSTATE, vehicleID);
2333 }
2334 
2335 double
2336 TraCIAPI::VehicleScope::getAccel(const std::string& vehicleID) const {
2337  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_ACCEL, vehicleID);
2338 }
2339 
2340 double
2341 TraCIAPI::VehicleScope::getDecel(const std::string& vehicleID) const {
2342  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_DECEL, vehicleID);
2343 }
2344 
2345 double
2346 TraCIAPI::VehicleScope::getTau(const std::string& vehicleID) const {
2347  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_TAU, vehicleID);
2348 }
2349 
2350 double
2351 TraCIAPI::VehicleScope::getImperfection(const std::string& vehicleID) const {
2352  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_IMPERFECTION, vehicleID);
2353 }
2354 
2355 double
2356 TraCIAPI::VehicleScope::getSpeedFactor(const std::string& vehicleID) const {
2357  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_SPEED_FACTOR, vehicleID);
2358 }
2359 
2360 double
2361 TraCIAPI::VehicleScope::getSpeedDeviation(const std::string& vehicleID) const {
2362  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_SPEED_DEVIATION, vehicleID);
2363 }
2364 
2365 std::string
2366 TraCIAPI::VehicleScope::getVehicleClass(const std::string& vehicleID) const {
2367  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_VEHICLECLASS, vehicleID);
2368 }
2369 
2370 double
2371 TraCIAPI::VehicleScope::getMinGap(const std::string& vehicleID) const {
2372  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_MINGAP, vehicleID);
2373 }
2374 
2375 double
2376 TraCIAPI::VehicleScope::getWidth(const std::string& vehicleID) const {
2377  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_WIDTH, vehicleID);
2378 }
2379 
2380 double
2381 TraCIAPI::VehicleScope::getLength(const std::string& vehicleID) const {
2382  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_LENGTH, vehicleID);
2383 }
2384 
2385 double
2386 TraCIAPI::VehicleScope::getHeight(const std::string& vehicleID) const {
2387  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_HEIGHT, vehicleID);
2388 }
2389 
2390 double
2391 TraCIAPI::VehicleScope::getAccumulatedWaitingTime(const std::string& vehicleID) const {
2392  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_ACCUMULATED_WAITING_TIME, vehicleID);
2393 }
2394 
2395 double
2396 TraCIAPI::VehicleScope::getAllowedSpeed(const std::string& vehicleID) const {
2397  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_ALLOWED_SPEED, vehicleID);
2398 }
2399 
2400 int
2401 TraCIAPI::VehicleScope::getPersonNumber(const std::string& vehicleID) const {
2402  return myParent.getInt(CMD_GET_VEHICLE_VARIABLE, VAR_PERSON_NUMBER, vehicleID);
2403 }
2404 
2405 double
2406 TraCIAPI::VehicleScope::getSpeedWithoutTraCI(const std::string& vehicleID) const {
2407  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_SPEED_WITHOUT_TRACI, vehicleID);
2408 }
2409 
2410 bool
2411 TraCIAPI::VehicleScope::isRouteValid(const std::string& vehicleID) const {
2412  return myParent.getUnsignedByte(CMD_GET_VEHICLE_VARIABLE, VAR_ROUTE_VALID, vehicleID) != 0;
2413 }
2414 
2415 double
2416 TraCIAPI::VehicleScope::getMaxSpeedLat(const std::string& vehicleID) const {
2417  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_MAXSPEED_LAT, vehicleID);
2418 }
2419 
2420 double
2421 TraCIAPI::VehicleScope::getMinGapLat(const std::string& vehicleID) const {
2422  return myParent.getDouble(CMD_GET_VEHICLE_VARIABLE, VAR_MINGAP_LAT, vehicleID);
2423 }
2424 
2425 std::string
2426 TraCIAPI::VehicleScope::getLateralAlignment(const std::string& vehicleID) const {
2427  return myParent.getString(CMD_GET_VEHICLE_VARIABLE, VAR_LATALIGNMENT, vehicleID);
2428 }
2429 
2430 void
2431 TraCIAPI::VehicleScope::add(const std::string& vehicleID,
2432  const std::string& routeID,
2433  const std::string& typeID,
2434  std::string depart,
2435  const std::string& departLane,
2436  const std::string& departPos,
2437  const std::string& departSpeed,
2438  const std::string& arrivalLane,
2439  const std::string& arrivalPos,
2440  const std::string& arrivalSpeed,
2441  const std::string& fromTaz,
2442  const std::string& toTaz,
2443  const std::string& line,
2444  int personCapacity,
2445  int personNumber) const {
2446 
2447  if (depart == "-1") {
2448  depart = toString(myParent.simulation.getCurrentTime() / 1000.0);
2449  }
2450  tcpip::Storage content;
2452  content.writeInt(14);
2453  content.writeUnsignedByte(TYPE_STRING);
2454  content.writeString(routeID);
2455  content.writeUnsignedByte(TYPE_STRING);
2456  content.writeString(typeID);
2457  content.writeUnsignedByte(TYPE_STRING);
2458  content.writeString(depart);
2459  content.writeUnsignedByte(TYPE_STRING);
2460  content.writeString(departLane);
2461  content.writeUnsignedByte(TYPE_STRING);
2462  content.writeString(departPos);
2463  content.writeUnsignedByte(TYPE_STRING);
2464  content.writeString(departSpeed);
2465 
2466  content.writeUnsignedByte(TYPE_STRING);
2467  content.writeString(arrivalLane);
2468  content.writeUnsignedByte(TYPE_STRING);
2469  content.writeString(arrivalPos);
2470  content.writeUnsignedByte(TYPE_STRING);
2471  content.writeString(arrivalSpeed);
2472 
2473  content.writeUnsignedByte(TYPE_STRING);
2474  content.writeString(fromTaz);
2475  content.writeUnsignedByte(TYPE_STRING);
2476  content.writeString(toTaz);
2477  content.writeUnsignedByte(TYPE_STRING);
2478  content.writeString(line);
2479 
2481  content.writeInt(personCapacity);
2483  content.writeInt(personNumber);
2484 
2485  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, ADD_FULL, vehicleID, content);
2486  tcpip::Storage inMsg;
2487  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2488 }
2489 
2490 
2491 void
2492 TraCIAPI::VehicleScope::remove(const std::string& vehicleID, char reason) const {
2493  tcpip::Storage content;
2494  content.writeUnsignedByte(TYPE_BYTE);
2495  content.writeUnsignedByte(reason);
2496  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, REMOVE, vehicleID, content);
2497  tcpip::Storage inMsg;
2498  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2499 
2500 }
2501 
2502 void
2503 TraCIAPI::VehicleScope::changeTarget(const std::string& vehicleID, const std::string& edgeID) const {
2504  tcpip::Storage content;
2505  content.writeUnsignedByte(TYPE_STRING);
2506  content.writeString(edgeID);
2507  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, CMD_CHANGETARGET, vehicleID, content);
2508  tcpip::Storage inMsg;
2509  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2510 }
2511 
2512 void
2513 TraCIAPI::VehicleScope::setRouteID(const std::string& vehicleID, const std::string& routeID) const {
2514  tcpip::Storage content;
2515  content.writeUnsignedByte(TYPE_STRING);
2516  content.writeString(routeID);
2517  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_ROUTE_ID, vehicleID, content);
2518  tcpip::Storage inMsg;
2519  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2520 }
2521 
2522 
2523 void
2524 TraCIAPI::VehicleScope::setRoute(const std::string& vehicleID, const std::vector<std::string>& edges) const {
2525  tcpip::Storage content;
2527  content.writeInt((int)edges.size());
2528  for (int i = 0; i < (int)edges.size(); ++i) {
2529  content.writeString(edges[i]);
2530  }
2531  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_ROUTE, vehicleID, content);
2532  tcpip::Storage inMsg;
2533  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2534 }
2535 
2536 
2537 void
2538 TraCIAPI::VehicleScope::rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes) const {
2539  if (currentTravelTimes) {
2540  // updated edge weights with current network traveltimes (at most once per simulation step)
2541  SUMOTime time = myParent.simulation.getCurrentTime();
2542  if (time != LAST_TRAVEL_TIME_UPDATE) {
2543  LAST_TRAVEL_TIME_UPDATE = time;
2544  }
2545  std::vector<std::string> edges = myParent.edge.getIDList();
2546  for (std::vector<std::string>::iterator it = edges.begin(); it != edges.end(); ++it) {
2547  myParent.edge.adaptTraveltime(*it, myParent.edge.getTraveltime(*it));
2548  }
2549  }
2550 
2551  tcpip::Storage content;
2553  content.writeInt(0);
2554  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, CMD_REROUTE_TRAVELTIME, vehicleID, content);
2555  tcpip::Storage inMsg;
2556  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2557 }
2558 
2559 void
2560 TraCIAPI::VehicleScope::moveTo(const std::string& vehicleID, const std::string& laneID, double position) const {
2561  tcpip::Storage content;
2563  content.writeInt(2);
2564  content.writeUnsignedByte(TYPE_STRING);
2565  content.writeString(laneID);
2566  content.writeUnsignedByte(TYPE_DOUBLE);
2567  content.writeDouble(position);
2568  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_MOVE_TO, vehicleID, content);
2569  tcpip::Storage inMsg;
2570  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2571 }
2572 
2573 void
2574 TraCIAPI::VehicleScope::moveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const {
2575  myParent.send_commandMoveToXY(vehicleID, edgeID, lane, x, y, angle, keepRoute);
2576  tcpip::Storage inMsg;
2577  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2578 }
2579 
2580 
2581 void
2582 TraCIAPI::VehicleScope::slowDown(const std::string& vehicleID, double speed, int duration) const {
2583  tcpip::Storage content;
2585  content.writeInt(2);
2586  content.writeUnsignedByte(TYPE_DOUBLE);
2587  content.writeDouble(speed);
2589  content.writeInt(duration);
2590  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, CMD_SLOWDOWN, vehicleID, content);
2591  tcpip::Storage inMsg;
2592  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2593 }
2594 
2595 void
2596 TraCIAPI::VehicleScope::setSpeed(const std::string& vehicleID, double speed) const {
2597  tcpip::Storage content;
2598  content.writeUnsignedByte(TYPE_DOUBLE);
2599  content.writeDouble(speed);
2600  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_SPEED, vehicleID, content);
2601  tcpip::Storage inMsg;
2602  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2603 }
2604 
2605 void
2606 TraCIAPI::VehicleScope::setMaxSpeed(const std::string& vehicleID, double speed) const {
2607  tcpip::Storage content;
2608  content.writeUnsignedByte(TYPE_DOUBLE);
2609  content.writeDouble(speed);
2610  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_MAXSPEED, vehicleID, content);
2611  tcpip::Storage inMsg;
2612  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2613 }
2614 
2615 void
2616 TraCIAPI::VehicleScope::setColor(const std::string& vehicleID, const TraCIColor& c) const {
2617  tcpip::Storage content;
2618  content.writeUnsignedByte(TYPE_COLOR);
2619  content.writeUnsignedByte(c.r);
2620  content.writeUnsignedByte(c.g);
2621  content.writeUnsignedByte(c.b);
2622  content.writeUnsignedByte(c.a);
2623  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_COLOR, vehicleID, content);
2624  tcpip::Storage inMsg;
2625  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2626 }
2627 
2628 void
2629 TraCIAPI::VehicleScope::setLine(const std::string& vehicleID, const std::string& line) const {
2630  tcpip::Storage content;
2631  content.writeUnsignedByte(TYPE_STRING);
2632  content.writeString(line);
2633  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_LINE, vehicleID, content);
2634  tcpip::Storage inMsg;
2635  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2636 }
2637 
2638 void
2639 TraCIAPI::VehicleScope::setVia(const std::string& vehicleID, const std::vector<std::string>& via) const {
2640  tcpip::Storage content;
2642  content.writeInt((int)via.size());
2643  for (int i = 0; i < (int)via.size(); ++i) {
2644  content.writeString(via[i]);
2645  }
2646  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_VIA, vehicleID, content);
2647  tcpip::Storage inMsg;
2648  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2649 }
2650 
2651 
2652 void
2653 TraCIAPI::VehicleScope::setShapeClass(const std::string& vehicleID, const std::string& clazz) const {
2654  tcpip::Storage content;
2655  content.writeUnsignedByte(TYPE_STRING);
2656  content.writeString(clazz);
2657  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_SHAPECLASS, vehicleID, content);
2658  tcpip::Storage inMsg;
2659  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2660 }
2661 
2662 
2663 void
2664 TraCIAPI::VehicleScope::setEmissionClass(const std::string& vehicleID, const std::string& clazz) const {
2665  tcpip::Storage content;
2666  content.writeUnsignedByte(TYPE_STRING);
2667  content.writeString(clazz);
2668  myParent.send_commandSetValue(CMD_SET_VEHICLE_VARIABLE, VAR_EMISSIONCLASS, vehicleID, content);
2669  tcpip::Storage inMsg;
2670  myParent.check_resultState(inMsg, CMD_SET_VEHICLE_VARIABLE);
2671 }
2672 
2673 
2674 // ---------------------------------------------------------------------------
2675 // // TraCIAPI::PersonScope-methods
2676 // ---------------------------------------------------------------------------
2677 
2678 std::vector<std::string>
2680  return myParent.getStringVector(CMD_GET_PERSON_VARIABLE, ID_LIST, "");
2681 }
2682 
2683 int
2685  return myParent.getInt(CMD_GET_PERSON_VARIABLE, ID_COUNT, "");
2686 }
2687 
2688 double
2689 TraCIAPI::PersonScope::getSpeed(const std::string& personID) const {
2690  return myParent.getDouble(CMD_GET_PERSON_VARIABLE, VAR_SPEED, personID);
2691 }
2692 
2694 TraCIAPI::PersonScope::getPosition(const std::string& personID) const {
2695  return myParent.getPosition(CMD_GET_PERSON_VARIABLE, VAR_POSITION, personID);
2696 }
2697 
2698 std::string
2699 TraCIAPI::PersonScope::getRoadID(const std::string& personID) const {
2700  return myParent.getString(CMD_GET_PERSON_VARIABLE, VAR_ROAD_ID, personID);
2701 }
2702 
2703 std::string
2704 TraCIAPI::PersonScope::getTypeID(const std::string& personID) const {
2705  return myParent.getString(CMD_GET_PERSON_VARIABLE, VAR_TYPE, personID);
2706 }
2707 
2708 double
2709 TraCIAPI::PersonScope::getWaitingTime(const std::string& personID) const {
2710  return myParent.getDouble(CMD_GET_PERSON_VARIABLE, VAR_WAITING_TIME, personID);
2711 }
2712 
2713 std::string
2714 TraCIAPI::PersonScope::getNextEdge(const std::string& personID) const {
2715  return myParent.getString(CMD_GET_PERSON_VARIABLE, VAR_NEXT_EDGE, personID);
2716 }
2717 
2718 
2719 std::string
2720 TraCIAPI::PersonScope::getVehicle(const std::string& personID) const {
2721  return myParent.getString(CMD_GET_PERSON_VARIABLE, VAR_VEHICLE, personID);
2722 }
2723 
2724 int
2725 TraCIAPI::PersonScope::getRemainingStages(const std::string& personID) const {
2726  return myParent.getInt(CMD_GET_PERSON_VARIABLE, VAR_STAGES_REMAINING, personID);
2727 }
2728 
2729 int
2730 TraCIAPI::PersonScope::getStage(const std::string& personID, int nextStageIndex) const {
2731  tcpip::Storage content;
2732  content.writeByte(TYPE_INTEGER);
2733  content.writeInt(nextStageIndex);
2734  return myParent.getInt(CMD_GET_PERSON_VARIABLE, VAR_STAGE, personID, &content);
2735 }
2736 
2737 std::vector<std::string>
2738 TraCIAPI::PersonScope::getEdges(const std::string& personID, int nextStageIndex) const {
2739  tcpip::Storage content;
2740  content.writeByte(TYPE_INTEGER);
2741  content.writeInt(nextStageIndex);
2742  return myParent.getStringVector(CMD_GET_PERSON_VARIABLE, VAR_EDGES, personID, &content);
2743 }
2744 
2745 void
2746 TraCIAPI::PersonScope::removeStages(const std::string& personID) const {
2747  // remove all stages after the current and then abort the current stage
2748  while (getRemainingStages(personID) > 1) {
2749  removeStage(personID, 1);
2750  }
2751  removeStage(personID, 0);
2752 }
2753 
2754 
2755 void
2756 TraCIAPI::PersonScope::rerouteTraveltime(const std::string& personID) const {
2757  tcpip::Storage content;
2759  content.writeInt(0);
2760  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, CMD_REROUTE_TRAVELTIME, personID, content);
2761  tcpip::Storage inMsg;
2762  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2763 }
2764 
2765 void
2766 TraCIAPI::PersonScope::add(const std::string& personID, const std::string& edgeID, double pos, double depart, const std::string typeID) {
2767  if (depart > 0) {
2768  depart *= 1000;
2769  }
2770  tcpip::Storage content;
2772  content.writeInt(4);
2773  content.writeUnsignedByte(TYPE_STRING);
2774  content.writeString(typeID);
2775  content.writeUnsignedByte(TYPE_STRING);
2776  content.writeString(edgeID);
2778  content.writeInt((int)depart);
2779  content.writeUnsignedByte(TYPE_DOUBLE);
2780  content.writeDouble(pos);
2781  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, ADD, personID, content);
2782  tcpip::Storage inMsg;
2783  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2784 }
2785 
2786 void
2787 TraCIAPI::PersonScope::appendWaitingStage(const std::string& personID, double duration, const std::string& description, const std::string& stopID) {
2788  duration *= 1000;
2789  tcpip::Storage content;
2791  content.writeInt(4);
2793  content.writeInt(STAGE_WAITING);
2795  content.writeInt((int)duration);
2796  content.writeUnsignedByte(TYPE_STRING);
2797  content.writeString(description);
2798  content.writeUnsignedByte(TYPE_STRING);
2799  content.writeString(stopID);
2800  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, APPEND_STAGE, personID, content);
2801  tcpip::Storage inMsg;
2802  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2803 }
2804 
2805 void
2806 TraCIAPI::PersonScope::appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration, double speed, const std::string& stopID) {
2807  if (duration > 0) {
2808  duration *= 1000;
2809  }
2810  tcpip::Storage content;
2812  content.writeInt(6);
2814  content.writeInt(STAGE_WALKING);
2816  content.writeStringList(edges);
2817  content.writeUnsignedByte(TYPE_DOUBLE);
2818  content.writeDouble(arrivalPos);
2820  content.writeInt((int)duration);
2821  content.writeUnsignedByte(TYPE_DOUBLE);
2822  content.writeDouble(speed);
2823  content.writeUnsignedByte(TYPE_STRING);
2824  content.writeString(stopID);
2825  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, APPEND_STAGE, personID, content);
2826  tcpip::Storage inMsg;
2827  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2828 }
2829 
2830 void
2831 TraCIAPI::PersonScope::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
2832  tcpip::Storage content;
2834  content.writeInt(4);
2836  content.writeInt(STAGE_DRIVING);
2837  content.writeUnsignedByte(TYPE_STRING);
2838  content.writeString(toEdge);
2839  content.writeUnsignedByte(TYPE_STRING);
2840  content.writeString(lines);
2841  content.writeUnsignedByte(TYPE_STRING);
2842  content.writeString(stopID);
2843  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, APPEND_STAGE, personID, content);
2844  tcpip::Storage inMsg;
2845  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2846 }
2847 
2848 void
2849 TraCIAPI::PersonScope::removeStage(const std::string& personID, int nextStageIndex) const {
2850  tcpip::Storage content;
2851  content.writeByte(TYPE_INTEGER);
2852  content.writeInt(nextStageIndex);
2853  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, REMOVE_STAGE, personID, content);
2854  tcpip::Storage inMsg;
2855  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2856 }
2857 
2858 
2859 void
2860 TraCIAPI::PersonScope::setSpeed(const std::string& personID, double speed) const {
2861  tcpip::Storage content;
2862  content.writeUnsignedByte(TYPE_DOUBLE);
2863  content.writeDouble(speed);
2864  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, VAR_SPEED, personID, content);
2865  tcpip::Storage inMsg;
2866  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2867 }
2868 
2869 
2870 void
2871 TraCIAPI::PersonScope::setType(const std::string& personID, const std::string& typeID) const {
2872  tcpip::Storage content;
2873  content.writeUnsignedByte(TYPE_STRING);
2874  content.writeString(typeID);
2875  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, VAR_TYPE, personID, content);
2876  tcpip::Storage inMsg;
2877  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2878 }
2879 
2880 void
2881 TraCIAPI::PersonScope::setLength(const std::string& personID, double length) const {
2882  tcpip::Storage content;
2883  content.writeUnsignedByte(TYPE_DOUBLE);
2884  content.writeDouble(length);
2885  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, VAR_LENGTH, personID, content);
2886  tcpip::Storage inMsg;
2887  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2888 }
2889 
2890 
2891 void
2892 TraCIAPI::PersonScope::setWidth(const std::string& personID, double width) const {
2893  tcpip::Storage content;
2894  content.writeUnsignedByte(TYPE_DOUBLE);
2895  content.writeDouble(width);
2896  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, VAR_WIDTH, personID, content);
2897  tcpip::Storage inMsg;
2898  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2899 }
2900 
2901 void
2902 TraCIAPI::PersonScope::setHeight(const std::string& personID, double height) const {
2903  tcpip::Storage content;
2904  content.writeUnsignedByte(TYPE_DOUBLE);
2905  content.writeDouble(height);
2906  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, VAR_HEIGHT, personID, content);
2907  tcpip::Storage inMsg;
2908  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2909 }
2910 
2911 void
2912 TraCIAPI::PersonScope::setMinGap(const std::string& personID, double minGap) const {
2913  tcpip::Storage content;
2914  content.writeUnsignedByte(TYPE_DOUBLE);
2915  content.writeDouble(minGap);
2916  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, VAR_MINGAP, personID, content);
2917  tcpip::Storage inMsg;
2918  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2919 }
2920 
2921 
2922 void
2923 TraCIAPI::PersonScope::setColor(const std::string& personID, const TraCIColor& c) const {
2924  tcpip::Storage content;
2925  content.writeUnsignedByte(TYPE_COLOR);
2926  content.writeUnsignedByte(c.r);
2927  content.writeUnsignedByte(c.g);
2928  content.writeUnsignedByte(c.b);
2929  content.writeUnsignedByte(c.a);
2930  myParent.send_commandSetValue(CMD_SET_PERSON_VARIABLE, VAR_COLOR, personID, content);
2931  tcpip::Storage inMsg;
2932  myParent.check_resultState(inMsg, CMD_SET_PERSON_VARIABLE);
2933 }
2934 
2935 
2936 /****************************************************************************/
2937 
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1416
double getWidth(const std::string &laneID) const
Definition: TraCIAPI.cpp:976
#define VAR_ROAD_ID
#define LAST_STEP_MEAN_SPEED
double x
Definition: TraCIDefs.h:72
int getIDCount() const
Definition: TraCIAPI.cpp:961
void setMaxSpeed(const std::string &edgeID, double speed) const
Definition: TraCIAPI.cpp:746
double getMaxSpeed(const std::string &typeID) const
Definition: TraCIAPI.cpp:1755
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1182
double xMin
Definition: TraCIDefs.h:91
void setRoute(const std::string &vehicleID, const std::vector< std::string > &edge) const
Definition: TraCIAPI.cpp:2524
double getZoom(const std::string &viewID=DEFAULT_VIEW) const
Definition: TraCIAPI.cpp:766
void copy(const std::string &origTypeID, const std::string &newTypeID) const
Definition: TraCIAPI.cpp:1974
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:956
#define TL_NEXT_SWITCH
#define VAR_TIME_STEP
int getStartingTeleportNumber() const
Definition: TraCIAPI.cpp:1479
double getMinGapLat(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2421
double getLength(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2381
int getLastStepVehicleNumber(const std::string &loopID) const
Definition: TraCIAPI.cpp:871
#define VAR_EMISSIONCLASS
double getLastStepMeanSpeed(const std::string &detID) const
Definition: TraCIAPI.cpp:1203
void appendDrivingStage(const std::string &personID, const std::string &toEdge, const std::string &lines, const std::string &stopID="")
Definition: TraCIAPI.cpp:2831
void setMaxSpeed(const std::string &vehicleID, double speed) const
Definition: TraCIAPI.cpp:2606
double getSpeedDeviation(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2361
std::vector< TraCIBestLanesData > getBestLanes(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2275
#define VAR_VIA
tcpip::Socket * mySocket
The socket.
Definition: TraCIAPI.h:923
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1745
void setEffort(const std::string &edgeID, double effort, SUMOTime begin=0, SUMOTime end=SUMOTime_MAX) const
Definition: TraCIAPI.cpp:730
double getSlope(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2220
#define VAR_CO2EMISSION
std::vector< std::string > getLoadedIDList() const
Definition: TraCIAPI.cpp:1454
void close()
ends the simulation and closes the connection
Definition: TraCIAPI.cpp:94
const SubscribedValues & getSubscriptionResults() const
Definition: TraCIAPI.cpp:1535
void connect(const std::string &host, int port)
Connects to the specified SUMO server.
Definition: TraCIAPI.cpp:66
#define CMD_GET_TL_VARIABLE
std::vector< std::string > getArrivedIDList() const
Definition: TraCIAPI.cpp:1474
#define VAR_LENGTH
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:205
void setLine(const std::string &vehicleID, const std::string &line) const
Definition: TraCIAPI.cpp:2629
double getMaxSpeedLat(const std::string &typeID) const
Definition: TraCIAPI.cpp:1825
void setEmergencyDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2014
#define VAR_LATALIGNMENT
double length
Length of the vehicle.
Definition: TraCIDefs.h:169
std::string getRouteID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2129
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:761
double getNOxEmission(const std::string &edgeID) const
Definition: TraCIAPI.cpp:657
std::vector< std::string > getRoute(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2144
std::string getEmissionClass(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2236
void setOrder(int order)
set priority (execution order) for the client
Definition: TraCIAPI.cpp:79
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:2431
#define CMD_GET_VEHICLE_VARIABLE
#define TYPE_COMPOUND
#define VAR_ACCUMULATED_WAITING_TIME
#define VAR_CURRENT_TRAVELTIME
#define LANE_LINKS
double getDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1775
double getElectricityConsumption(const std::string &laneID) const
Definition: TraCIAPI.cpp:1091
double getDistance(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2159
double getNoiseEmission(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2199
int getIDCount() const
Definition: TraCIAPI.cpp:2684
std::string getLateralAlignment(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2426
#define CMD_CLOSE
std::string getTypeID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2124
double getNoiseEmission(const std::string &edgeID) const
Definition: TraCIAPI.cpp:667
std::vector< std::string > getDisallowed(const std::string &laneID) const
Definition: TraCIAPI.cpp:986
double getAngle(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2104
#define POSITION_2D
TraCIPositionVector getShape(const std::string &polygonID) const
Definition: TraCIAPI.cpp:1325
#define VAR_POSITION
double getLastStepMeanSpeed(const std::string &edgeID) const
Definition: TraCIAPI.cpp:677
void setSpeed(const std::string &vehicleID, double speed) const
Definition: TraCIAPI.cpp:2596
void setProgram(const std::string &tlsID, const std::string &programID) const
Definition: TraCIAPI.cpp:1688
void setPhase(const std::string &tlsID, int index) const
Definition: TraCIAPI.cpp:1678
void setColor(const std::string &vehicleID, const TraCIColor &c) const
Definition: TraCIAPI.cpp:2616
void setVehicleClass(const std::string &typeID, const std::string &clazz) const
Definition: TraCIAPI.cpp:1872
double getLastStepOccupancy(const std::string &laneID) const
Definition: TraCIAPI.cpp:1101
bool receiveExact(Storage &)
Receive a complete TraCI message from Socket::socket_.
Definition: socket.cpp:504
#define CMD_GET_INDUCTIONLOOP_VARIABLE
std::string subID
Definition: TraCIDefs.h:122
#define VAR_ROUTE
std::map< int, TraCIValue > TraCIValues
{object->{variable->value}}
Definition: TraCIAPI.h:470
#define STAGE_WAITING
#define VAR_SPEEDSETMODE
#define VAR_TAU
double getCO2Emission(const std::string &laneID) const
Definition: TraCIAPI.cpp:1056
std::string getVehicleClass(const std::string &typeID) const
Definition: TraCIAPI.cpp:1800
double leaveTime
Leave-time of the vehicle in [s].
Definition: TraCIDefs.h:173
#define LANE_EDGE_ID
#define LANE_LINK_NUMBER
void setColor(const std::string &polygonID, const TraCIColor &c) const
Definition: TraCIAPI.cpp:1360
#define LAST_STEP_VEHICLE_DATA
void send_commandClose() const
Sends a Close command.
Definition: TraCIAPI.cpp:128
void setVia(const std::string &vehicleID, const std::vector< std::string > &via) const
Definition: TraCIAPI.cpp:2639
virtual unsigned int position() const
#define VAR_ALLOWED_SPEED
double getSpeed(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2084
#define TYPE_UBYTE
#define RTYPE_OK
double getWaitingTime(const std::string &personID) const
Definition: TraCIAPI.cpp:2709
#define VAR_HEIGHT
int getLastStepHaltingNumber(const std::string &laneID) const
Definition: TraCIAPI.cpp:1121
#define CMD_GET_LANEAREA_VARIABLE
LaneScope lane
Scope for interaction with lanes.
Definition: TraCIAPI.h:803
#define VAR_WAITING_TIME
#define CMD_GET_PERSON_VARIABLE
virtual double readDouble()
#define VAR_TYPE
#define TYPE_POLYGON
std::string getEmissionClass(const std::string &typeID) const
Definition: TraCIAPI.cpp:1805
#define VAR_ROUTE_ID
void add(const std::string &polygonID, const TraCIPositionVector &shape, const TraCIColor &c, bool fill, const std::string &type, int layer) const
Definition: TraCIAPI.cpp:1373
#define VAR_VEHICLE
unsigned char g
Definition: TraCIDefs.h:79
double getPMxEmission(const std::string &laneID) const
Definition: TraCIAPI.cpp:1071
double getLastStepMeanLength(const std::string &loopID) const
Definition: TraCIAPI.cpp:891
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:2074
#define VAR_VEHICLECLASS
void setImperfection(const std::string &typeID, double imperfection) const
Definition: TraCIAPI.cpp:2034
double getApparentDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1785
void processGET(tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
Definition: TraCIAPI.cpp:328
StorageType::size_type size() const
Definition: storage.h:115
int getLastStepHaltingNumber(const std::string &detID) const
Definition: TraCIAPI.cpp:1213
#define VAR_SPEED_FACTOR
#define VAR_COLOR
double getSpeedDeviation(const std::string &typeID) const
Definition: TraCIAPI.cpp:1765
#define VAR_LOADED_VEHICLES_IDS
std::vector< std::string > getLastStepVehicleIDs(const std::string &loopID) const
Definition: TraCIAPI.cpp:881
void appendWaitingStage(const std::string &personID, double duration, const std::string &description="waiting", const std::string &stopID="")
Definition: TraCIAPI.cpp:2787
void trackVehicle(const std::string &viewID, const std::string &vehID) const
Definition: TraCIAPI.cpp:840
double getMaxSpeed(const std::string &laneID) const
Definition: TraCIAPI.cpp:971
void rerouteTraveltime(const std::string &vehicleID, bool currentTravelTimes=true) const
Definition: TraCIAPI.cpp:2538
void setColor(const std::string &personID, const TraCIColor &c) const
Definition: TraCIAPI.cpp:2923
#define APPEND_STAGE
#define TYPE_COLOR
double getNOxEmission(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2189
#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:590
TraCIBoundary getBoundary(const std::string &viewID=DEFAULT_VIEW) const
Definition: TraCIAPI.cpp:781
double getCO2Emission(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2169
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:940
unsigned char r
Definition: TraCIDefs.h:79
#define POSITION_3D
SUMOTime getCurrentTime() const
Definition: TraCIAPI.cpp:1444
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1315
int getRouteIndex(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2134
SubscribedContextValues mySubscribedContextValues
Definition: TraCIAPI.h:926
#define VAR_TELEPORT_STARTING_VEHICLES_IDS
void closeSocket()
Closes the connection.
Definition: TraCIAPI.cpp:104
double getNoiseEmission(const std::string &laneID) const
Definition: TraCIAPI.cpp:1086
#define CMD_GET_POLYGON_VARIABLE
void simulationStep(SUMOTime time=0)
Advances by one step (or up to the given time)
Definition: TraCIAPI.cpp:569
#define VAR_BEST_LANES
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:2574
void setSpeed(const std::string &personID, double speed) const
Definition: TraCIAPI.cpp:2860
TraCIPosition getOffset(const std::string &viewID=DEFAULT_VIEW) const
Definition: TraCIAPI.cpp:771
std::vector< std::string > getControlledLanes(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1619
void setAllowed(const std::string &laneID, const std::vector< std::string > &allowedClasses) const
Definition: TraCIAPI.cpp:1132
void setZoom(const std::string &viewID, double zoom) const
Definition: TraCIAPI.cpp:787
void adaptTraveltime(const std::string &edgeID, double time, double begin=0, double end=SUMOTime_MAX/1000.0) const
Definition: TraCIAPI.cpp:714
#define VAR_STAGE
double getCOEmission(const std::string &edgeID) const
Definition: TraCIAPI.cpp:642
virtual void writeUnsignedByte(int)
double getLastStepMeanSpeed(const std::string &loopID) const
Definition: TraCIAPI.cpp:876
#define CMD_SET_EDGE_VARIABLE
#define VAR_NEXT_TLS
#define CMD_SET_GUI_VARIABLE
void setLength(const std::string &laneID, double length) const
Definition: TraCIAPI.cpp:1168
#define TL_CURRENT_PHASE
bool isRouteValid(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2411
void readVariableSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:548
std::string getProgram(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1652
unsigned char a
Definition: TraCIDefs.h:79
std::map< std::string, SubscribedValues > SubscribedContextValues
Definition: TraCIAPI.h:472
TraCIPosition getPosition3D(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2099
#define VAR_LOADED_VEHICLES_NUMBER
std::string getShapeClass(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2241
#define VAR_SHAPE
double getAllowedSpeed(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2396
#define VAR_SPEED_DEVIATION
int getLastStepVehicleNumber(const std::string &laneID) const
Definition: TraCIAPI.cpp:1116
#define VAR_NOISEEMISSION
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:610
#define VAR_NEXT_EDGE
#define VAR_FUELCONSUMPTION
double zMin
Definition: TraCIDefs.h:91
#define CMD_GET_ROUTE_VARIABLE
double getElectricityConsumption(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2204
double getSpeed(const std::string &personID) const
Definition: TraCIAPI.cpp:2689
void setPosition(const std::string &poiID, double x, double y) const
Definition: TraCIAPI.cpp:1254
#define REMOVE_STAGE
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:2679
virtual void writeInt(int)
#define VAR_POSITION3D
void setDisallowed(const std::string &laneID, const std::vector< std::string > &disallowedClasses) const
Definition: TraCIAPI.cpp:1145
std::vector< std::string > getAllowed(const std::string &laneID) const
Definition: TraCIAPI.cpp:981
double getSpeedWithoutTraCI(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2406
#define TYPE_STRING
virtual int readUnsignedByte()
#define TL_PHASE_DURATION
TraCIPosition getPosition(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:425
double getSpeedFactor(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2356
void connect()
Connects to host_:port_.
Definition: socket.cpp:331
#define LAST_STEP_LENGTH
void setMinGap(const std::string &personID, double minGap) const
Definition: TraCIAPI.cpp:2912
double getHCEmission(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2179
#define VAR_NOXEMISSION
#define RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
#define TL_CURRENT_PROGRAM
int getStopState(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2331
double zMax
Definition: TraCIDefs.h:92
#define CMD_SET_TL_VARIABLE
double z
Definition: TraCIDefs.h:72
double getCOEmission(const std::string &laneID) const
Definition: TraCIAPI.cpp:1061
std::string getVehicleClass(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2366
#define VAR_ANGLE
#define CMD_GET_VEHICLETYPE_VARIABLE
double getMinGapLat(const std::string &typeID) const
Definition: TraCIAPI.cpp:1820
void remove(const std::string &polygonID, int layer=0) const
Definition: TraCIAPI.cpp:1401
double getCOEmission(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2174
void send_commandSimulationStep(SUMOTime time) const
Sends a SimulationStep command.
Definition: TraCIAPI.cpp:115
SubscribedValues mySubscribedValues
Definition: TraCIAPI.h:925
void setLength(const std::string &personID, double length) const
Definition: TraCIAPI.cpp:2881
#define VAR_PERSON_NUMBER
#define LANE_ALLOWED
std::string getRedYellowGreenState(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1575
int getLaneIndex(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2119
double getLanePosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2154
#define VAR_DEPARTED_VEHICLES_NUMBER
#define LAST_STEP_TIME_SINCE_DETECTION
void send_commandMoveToXY(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:245
#define CMD_SLOWDOWN
#define CMD_SET_ROUTE_VARIABLE
std::vector< TraCIVehicleData > getVehicleData(const std::string &loopID) const
Definition: TraCIAPI.cpp:901
#define TYPE_FLOAT
#define VAR_SHAPECLASS
std::string id
The id of the vehicle.
Definition: TraCIDefs.h:167
#define VAR_MIN_EXPECTED_VEHICLES
#define VAR_SCREENSHOT
TraCIBoundary getNetBoundary() const
Definition: TraCIAPI.cpp:1504
#define VAR_VIEW_BOUNDARY
#define CMD_LOAD
#define VAR_TRACK_VEHICLE
int getPhase(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1657
#define MOVE_TO_XY
void remove(const std::string &vehicleID, char reason=REMOVE_VAPORIZED) const
Definition: TraCIAPI.cpp:2492
std::map< std::string, TraCIValues > SubscribedValues
Definition: TraCIAPI.h:471
int getArrivedNumber() const
Definition: TraCIAPI.cpp:1469
void slowDown(const std::string &vehicleID, double speed, int duration) const
Definition: TraCIAPI.cpp:2582
#define STAGE_DRIVING
std::string getLateralAlignment(const std::string &typeID) const
Definition: TraCIAPI.cpp:1830
#define VAR_ACCEL
SUMOTime getDeltaT() const
Definition: TraCIAPI.cpp:1499
void setSchema(const std::string &viewID, const std::string &schemeName) const
Definition: TraCIAPI.cpp:807
#define CMD_CHANGETARGET
virtual int readInt()
#define TL_COMPLETE_PROGRAM_RYG
std::string getType(const std::string &polygonID) const
Definition: TraCIAPI.cpp:1320
void setType(const std::string &poiID, const std::string &setType) const
Definition: TraCIAPI.cpp:1244
A 3D-position.
Definition: TraCIDefs.h:71
double getImperfection(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2351
#define VAR_NET_BOUNDING_BOX
void send_commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
Sends a GetVariable request.
Definition: TraCIAPI.cpp:139
#define CMD_GET_POI_VARIABLE
double getLastStepOccupancy(const std::string &edgeID) const
Definition: TraCIAPI.cpp:682
#define VAR_LANEPOSITION
double getFloat(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:373
std::vector< TraCILogic > getCompleteRedYellowGreenDefinition(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1580
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1223
double getLastStepLength(const std::string &edgeID) const
Definition: TraCIAPI.cpp:687
double scalar
Definition: TraCIDefs.h:97
void setMaxSpeed(const std::string &typeID, double speed) const
Definition: TraCIAPI.cpp:1862
double getAccel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1770
~TraCIAPI()
Destructor.
Definition: TraCIAPI.cpp:60
double getPosition(const std::string &loopID) const
Definition: TraCIAPI.cpp:861
void screenshot(const std::string &viewID, const std::string &filename) const
Definition: TraCIAPI.cpp:830
std::vector< std::string > getDepartedIDList() const
Definition: TraCIAPI.cpp:1464
void rerouteTraveltime(const std::string &personID) const
Definition: TraCIAPI.cpp:2756
void setCompleteRedYellowGreenDefinition(const std::string &tlsID, const TraCILogic &logic) const
Definition: TraCIAPI.cpp:1708
std::vector< std::string > getEdges(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2139
#define TL_COMPLETE_DEFINITION_RYG
#define VAR_TELEPORT_STARTING_VEHICLES_NUMBER
void setMinGap(const std::string &typeID, double minGap) const
Definition: TraCIAPI.cpp:1933
#define CMD_SET_VEHICLETYPE_VARIABLE
virtual void writeByte(int)
double getFuelConsumption(const std::string &edgeID) const
Definition: TraCIAPI.cpp:662
void setDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2004
#define TYPE_BOUNDINGBOX
void setRouteID(const std::string &vehicleID, const std::string &routeID) const
Definition: TraCIAPI.cpp:2513
#define VAR_EMERGENCY_DECEL
double getAccumulatedWaitingTime(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2391
void setEmissionClass(const std::string &typeID, const std::string &clazz) const
Definition: TraCIAPI.cpp:1903
double getMaxSpeed(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2089
TraCIPosition getPosition(const std::string &junctionID) const
Definition: TraCIAPI.cpp:945
#define VAR_VIEW_SCHEMA
virtual void writeStringList(const std::vector< std::string > &s)
int getEndingTeleportNumber() const
Definition: TraCIAPI.cpp:1489
#define VAR_PMXEMISSION
#define VAR_TELEPORT_ENDING_VEHICLES_IDS
#define CMD_GET_LANE_VARIABLE
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:185
int getInt(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:364
double getLastStepOccupancy(const std::string &loopID) const
Definition: TraCIAPI.cpp:886
#define CMD_SET_VEHICLE_VARIABLE
std::string getRoadID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2109
void setWidth(const std::string &typeID, double width) const
Definition: TraCIAPI.cpp:1913
double getTraveltime(const std::string &laneID) const
Definition: TraCIAPI.cpp:1111
void setBoundary(const std::string &viewID, double xmin, double ymin, double xmax, double ymax) const
Definition: TraCIAPI.cpp:817
double getLength(const std::string &laneID) const
Definition: TraCIAPI.cpp:966
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:2766
void setSpeedDeviation(const std::string &typeID, double deviation) const
Definition: TraCIAPI.cpp:1892
#define VAR_IMPERFECTION
std::vector< std::string > getEdges(const std::string &personID, int nextStageIndex=0) const
Definition: TraCIAPI.cpp:2738
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1570
void setRedYellowGreenState(const std::string &tlsID, const std::string &state) const
Definition: TraCIAPI.cpp:1668
void setHeight(const std::string &typeID, double height) const
Definition: TraCIAPI.cpp:1923
#define CMD_GET_SIM_VARIABLE
virtual std::string readString()
std::string getShapeClass(const std::string &typeID) const
Definition: TraCIAPI.cpp:1810
#define CMD_GET_EDGE_VARIABLE
int getByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:355
#define VAR_EDGES
static std::string toString(const T &t, std::streamsize accuracy=PRECISION)
Definition: TraCIAPI.h:910
std::vector< TraCILink > getControlledLinks(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1624
#define CMD_GET_GUI_VARIABLE
TraCIColor getColor(const std::string &typeID) const
Definition: TraCIAPI.cpp:1845
std::string getSchema(const std::string &viewID=DEFAULT_VIEW) const
Definition: TraCIAPI.cpp:776
int getIDCount() const
Definition: TraCIAPI.cpp:2079
#define VAR_DEPARTED_VEHICLES_IDS
void setShapeClass(const std::string &typeID, const std::string &shapeClass) const
Definition: TraCIAPI.cpp:1984
#define CMD_SET_POI_VARIABLE
int getUnsignedByte(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:346
double getDouble(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:382
#define VAR_EDGE_EFFORT
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:1525
TraCIColor getColor(const std::string &polygonID) const
Definition: TraCIAPI.cpp:1330
#define VAR_STOPSTATE
std::vector< std::string > getEndingTeleportIDList() const
Definition: TraCIAPI.cpp:1494
#define ADD
#define CMD_GET_JUNCTION_VARIABLE
std::string getRoadID(const std::string &personID) const
Definition: TraCIAPI.cpp:2699
#define VAR_SLOPE
#define VAR_DELTA_T
#define REMOVE
void removeStage(const std::string &personID, int nextStageIndex) const
Definition: TraCIAPI.cpp:2849
std::string getEdgeID(const std::string &laneID) const
Definition: TraCIAPI.cpp:1051
int getStage(const std::string &personID, int nextStageIndex=0) const
Definition: TraCIAPI.cpp:2730
double getWidth(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2376
virtual void writeStorage(tcpip::Storage &store)
void changeTarget(const std::string &vehicleID, const std::string &edgeID) const
Definition: TraCIAPI.cpp:2503
#define VAR_LEADER
#define TL_CONTROLLED_LINKS
void readContextSubscription(tcpip::Storage &inMsg)
Definition: TraCIAPI.cpp:555
double dist
The distance to the tls.
Definition: TraCIDefs.h:187
#define COPY
int check_commandGetResult(tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const
Validates the result state of a command.
Definition: TraCIAPI.cpp:304
TraCIPositionVector getPolygon(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:407
int getRemainingStages(const std::string &personID) const
Definition: TraCIAPI.cpp:2725
TraCIPosition position
Definition: TraCIDefs.h:98
std::string getTypeID(const std::string &personID) const
Definition: TraCIAPI.cpp:2704
void setSpeedFactor(const std::string &typeID, double factor) const
Definition: TraCIAPI.cpp:1882
double yMax
Definition: TraCIDefs.h:92
void readVariables(tcpip::Storage &inMsg, const std::string &objectID, int variableCount, SubscribedValues &into)
Definition: TraCIAPI.cpp:487
#define VAR_SPEED
std::vector< std::string > getStringVector(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:460
void setLength(const std::string &typeID, double length) const
Definition: TraCIAPI.cpp:1852
std::string id
The id of the next tls.
Definition: TraCIDefs.h:183
#define TL_RED_YELLOW_GREEN_STATE
#define STAGE_WALKING
double getNOxEmission(const std::string &laneID) const
Definition: TraCIAPI.cpp:1076
std::vector< TraCIConnection > getLinks(const std::string &laneID) const
Definition: TraCIAPI.cpp:996
double getAdaptedTraveltime(const std::string &edgeID, double time) const
Definition: TraCIAPI.cpp:620
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:215
void setShapeClass(const std::string &vehicleID, const std::string &clazz) const
Definition: TraCIAPI.cpp:2653
#define LAST_STEP_VEHICLE_NUMBER
void setType(const std::string &personID, const std::string &typeID) const
Definition: TraCIAPI.cpp:2871
TraCIPosition getPosition(const std::string &poiID) const
Definition: TraCIAPI.cpp:1233
double getMaxSpeedLat(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2416
#define VAR_EDGE_TRAVELTIME
#define VAR_VIEW_ZOOM
#define VAR_ARRIVED_VEHICLES_NUMBER
TraCIColor getColor(const std::string &poiID) const
Definition: TraCIAPI.cpp:1238
std::vector< TraCIPhase > phases
Definition: TraCIDefs.h:126
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:187
double getTau(const std::string &typeID) const
Definition: TraCIAPI.cpp:1795
double getCO2Emission(const std::string &edgeID) const
Definition: TraCIAPI.cpp:636
int getLastStepVehicleNumber(const std::string &edgeID) const
Definition: TraCIAPI.cpp:697
#define CMD_SET_POLYGON_VARIABLE
TraCIPosition getPosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2094
#define VAR_COEMISSION
double getEmergencyDecel(const std::string &typeID) const
Definition: TraCIAPI.cpp:1780
virtual void writeString(const std::string &s)
int getMinExpectedNumber() const
Definition: TraCIAPI.cpp:1509
#define RTYPE_NOTIMPLEMENTED
void setType(const std::string &polygonID, const std::string &setType) const
Definition: TraCIAPI.cpp:1336
double getElectricityConsumption(const std::string &edgeID) const
Definition: TraCIAPI.cpp:672
std::vector< std::string > stringList
Definition: TraCIDefs.h:102
int getNextSwitch(const std::string &tlsID) const
Definition: TraCIAPI.cpp:1662
#define VAR_LANEPOSITION_LAT
#define LAST_STEP_VEHICLE_ID_LIST
#define LANE_DISALLOWED
void add(const std::string &poiID, double x, double y, const TraCIColor &c, const std::string &type, int layer) const
Definition: TraCIAPI.cpp:1278
#define VAR_MOVE_TO
const SubscribedContextValues & getContextSubscriptionResults() const
Definition: TraCIAPI.cpp:1551
#define TL_PROGRAM
SUMOTime getSUMOTime(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:337
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:197
#define TYPE_DOUBLE
void setMinGapLat(const std::string &typeID, double minGapLat) const
Definition: TraCIAPI.cpp:1944
double getHCEmission(const std::string &laneID) const
Definition: TraCIAPI.cpp:1066
std::string typeID
Type of the vehicle in.
Definition: TraCIDefs.h:175
double getHeight(const std::string &typeID) const
Definition: TraCIAPI.cpp:1840
std::vector< std::string > getLastStepVehicleIDs(const std::string &detID) const
Definition: TraCIAPI.cpp:1208
double getLastStepHaltingNumber(const std::string &edgeID) const
Definition: TraCIAPI.cpp:702
#define CMD_REROUTE_TRAVELTIME
A 3D-bounding box.
Definition: TraCIDefs.h:90
void sendExact(const Storage &)
Definition: socket.cpp:405
double getDecel(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2341
virtual float readFloat()
double getWidth(const std::string &typeID) const
Definition: TraCIAPI.cpp:1835
#define TYPE_BYTE
std::string getType(const std::string &poiID) const
Definition: TraCIAPI.cpp:1228
double getWaitingTime(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2209
#define CMD_SET_LANE_VARIABLE
#define VAR_ELECTRICITYCONSUMPTION
void setApparentDecel(const std::string &typeID, double decel) const
Definition: TraCIAPI.cpp:2024
#define VAR_ROUTE_INDEX
double getEffort(const std::string &edgeID, SUMOTime time) const
Definition: TraCIAPI.cpp:628
double getLength(const std::string &typeID) const
Definition: TraCIAPI.cpp:1750
std::string getLaneID(const std::string &loopID) const
Definition: TraCIAPI.cpp:866
int getIDCount() const
Definition: TraCIAPI.cpp:615
#define CMD_GET_MULTIENTRYEXIT_VARIABLE
void subscribe(int domID, const std::string &objID, SUMOTime beginTime, SUMOTime endTime, const std::vector< int > &vars) const
Definition: TraCIAPI.cpp:1514
double getSpeedFactor(const std::string &typeID) const
Definition: TraCIAPI.cpp:1760
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:856
void check_resultState(tcpip::Storage &inMsg, int command, bool ignoreCommandId=false, std::string *acknowledgement=0) const
Validates the result state of a command.
Definition: TraCIAPI.cpp:265
void setTau(const std::string &typeID, double tau) const
Definition: TraCIAPI.cpp:2044
double length
The length than can be driven from that lane without lane change.
Definition: TraCIDefs.h:199
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:203
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:207
TraCIColor getColor(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2149
void setMaxSpeed(const std::string &laneID, double speed) const
Definition: TraCIAPI.cpp:1158
double occupation
The traffic density along length.
Definition: TraCIDefs.h:201
int currentPhaseIndex
Definition: TraCIDefs.h:125
double getTraveltime(const std::string &edgeID) const
Definition: TraCIAPI.cpp:692
int getSpeedMode(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2214
TraCIPosition getPosition3D(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:438
char state
The current state of the tls.
Definition: TraCIDefs.h:189
std::vector< std::string > getLastStepVehicleIDs(const std::string &laneID) const
Definition: TraCIAPI.cpp:1126
int getDepartedNumber() const
Definition: TraCIAPI.cpp:1459
virtual void writeDouble(double)
TraCIBoundary getBoundingBox(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:391
#define CMD_SETORDER
#define VAR_TELEPORT_ENDING_VEHICLES_NUMBER
void setShape(const std::string &polygonID, const TraCIPositionVector &shape) const
Definition: TraCIAPI.cpp:1346
double getTimeSinceDetection(const std::string &loopID) const
Definition: TraCIAPI.cpp:896
unsigned char b
Definition: TraCIDefs.h:79
void setColor(const std::string &typeID, const TraCIColor &c) const
Definition: TraCIAPI.cpp:2054
void moveTo(const std::string &vehicleID, const std::string &laneID, double position) const
Definition: TraCIAPI.cpp:2560
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:2806
void send_commandSetValue(int domID, int varID, const std::string &objID, tcpip::Storage &content) const
Sends a SetVariable request.
Definition: TraCIAPI.cpp:166
TraCIColor getColor(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:474
void setEmissionClass(const std::string &vehicleID, const std::string &clazz) const
Definition: TraCIAPI.cpp:2664
double getHeight(const std::string &veihcleID) const
Definition: TraCIAPI.cpp:2386
std::string getLine(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2226
int getLinkNumber(const std::string &laneID) const
Definition: TraCIAPI.cpp:991
int getLastStepVehicleNumber(const std::string &detID) const
Definition: TraCIAPI.cpp:1198
#define VAR_APPARENT_DECEL
#define LAST_STEP_OCCUPANCY
#define VAR_SPEED_WITHOUT_TRACI
double getPMxEmission(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2184
long long int SUMOTime
Definition: TraCIDefs.h:52
#define TL_CONTROLLED_LANES
std::string getString(int cmd, int var, const std::string &id, tcpip::Storage *add=0)
Definition: TraCIAPI.cpp:451
double getHCEmission(const std::string &edgeID) const
Definition: TraCIAPI.cpp:647
int getPersonNumber(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2401
std::string getLaneID(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2114
double y
Definition: TraCIDefs.h:72
#define VAR_MAXSPEED
double getAccel(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2336
#define VAR_MINGAP_LAT
#define CMD_SET_PERSON_VARIABLE
#define VAR_DECEL
#define VAR_ROUTE_VALID
void setOffset(const std::string &viewID, double x, double y) const
Definition: TraCIAPI.cpp:796
#define RESPONSE_SUBSCRIBE_PERSON_VARIABLE
void removeStages(const std::string &personID) const
Definition: TraCIAPI.cpp:2746
TraCIAPI()
Constructor.
Definition: TraCIAPI.cpp:48
#define ID_COUNT
#define VAR_LANE_INDEX
TraCIPosition getPosition(const std::string &personID) const
Definition: TraCIAPI.cpp:2694
void setMaxSpeedLat(const std::string &typeID, double speed) const
Definition: TraCIAPI.cpp:1954
#define VAR_LANE_ID
#define VAR_LINE
std::vector< std::string > getEdges(const std::string &routeID) const
Definition: TraCIAPI.cpp:1421
double getMinGap(const std::string &typeID) const
Definition: TraCIAPI.cpp:1815
void remove(const std::string &poiID, int layer=0) const
Definition: TraCIAPI.cpp:1300
void setWidth(const std::string &personID, double width) const
Definition: TraCIAPI.cpp:2892
double getLastStepMeanSpeed(const std::string &laneID) const
Definition: TraCIAPI.cpp:1096
double getFuelConsumption(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2194
#define RTYPE_ERR
double entryTime
Entry-time of the vehicle in [s].
Definition: TraCIDefs.h:171
double getPMxEmission(const std::string &edgeID) const
Definition: TraCIAPI.cpp:652
double getImperfection(const std::string &typeID) const
Definition: TraCIAPI.cpp:1790
std::vector< TraCINextTLSData > getNextTLS(const std::string &vehID) const
Definition: TraCIAPI.cpp:2246
#define TYPE_INTEGER
#define VAR_MINGAP
#define ID_LIST
void setLateralAlignment(const std::string &typeID, const std::string &latAlignment) const
Definition: TraCIAPI.cpp:1964
std::vector< std::string > getVia(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2231
#define ADD_FULL
#define VAR_STAGES_REMAINING
#define TL_PHASE_INDEX
#define VAR_ARRIVED_VEHICLES_IDS
std::vector< std::string > getLastStepVehicleIDs(const std::string &edgeID) const
Definition: TraCIAPI.cpp:707
A list of positions.
int getLoadedNumber() const
Definition: TraCIAPI.cpp:1449
#define VAR_VIEW_OFFSET
std::string getVehicle(const std::string &personID) const
Definition: TraCIAPI.cpp:2720
TraCIPositionVector getShape(const std::string &laneID) const
Definition: TraCIAPI.cpp:1046
double getMinGap(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2371
#define VAR_MAXSPEED_LAT
#define LAST_STEP_VEHICLE_HALTING_NUMBER
double getLateralLanePosition(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2164
TraCIColor color
Definition: TraCIDefs.h:99
#define VAR_DISTANCE
#define CMD_SIMSTEP
std::string getNextEdge(const std::string &personID) const
Definition: TraCIAPI.cpp:2714
virtual int readByte()
#define VAR_HCEMISSION
void setColor(const std::string &poiID, const TraCIColor &c) const
Definition: TraCIAPI.cpp:1265
std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist) const
Definition: TraCIAPI.cpp:2314
double getFuelConsumption(const std::string &laneID) const
Definition: TraCIAPI.cpp:1081
std::string string
Definition: TraCIDefs.h:101
void close()
Definition: socket.cpp:356
void add(const std::string &routeID, const std::vector< std::string > &edges) const
Definition: TraCIAPI.cpp:1427
double yMin
Definition: TraCIDefs.h:91
std::vector< std::string > getIDList() const
Definition: TraCIAPI.cpp:1193
void setPhaseDuration(const std::string &tlsID, int phaseDuration) const
Definition: TraCIAPI.cpp:1698
void setHeight(const std::string &personID, double height) const
Definition: TraCIAPI.cpp:2902
#define VAR_WIDTH
void setAccel(const std::string &typeID, double accel) const
Definition: TraCIAPI.cpp:1994
std::vector< std::string > getStartingTeleportIDList() const
Definition: TraCIAPI.cpp:1484
double getTau(const std::string &vehicleID) const
Definition: TraCIAPI.cpp:2346
double getLastStepLength(const std::string &laneID) const
Definition: TraCIAPI.cpp:1106
double xMax
Definition: TraCIDefs.h:92