Eclipse SUMO - Simulation of Urban MObility
TraCIServerAPI_Simulation.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // APIs for getting/setting edge values via TraCI
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <utils/common/StdDefs.h>
29 #include <microsim/MSNet.h>
30 #include <microsim/MSEdgeControl.h>
32 #include <microsim/MSEdge.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSVehicle.h>
38 #include <libsumo/Helper.h>
39 #include <libsumo/Simulation.h>
40 #include <libsumo/TraCIConstants.h>
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 bool
49  tcpip::Storage& outputStorage) {
50  const int variable = inputStorage.readUnsignedByte();
51  const std::string id = inputStorage.readString();
52  server.initWrapper(libsumo::RESPONSE_GET_SIM_VARIABLE, variable, id);
53  try {
54  switch (variable) {
55  case libsumo::VAR_TIME:
58  break;
62  break;
65  break;
68  break;
71  break;
74  break;
77  break;
80  break;
83  break;
86  break;
89  break;
92  break;
95  break;
98  break;
101  break;
104  break;
107  break;
110  break;
113  break;
116  break;
119  break;
122  break;
125  break;
128  break;
132  break;
136  break;
139  break;
143  break;
146  break;
150  server.getWrapperStorage().writeByte(2);
151  server.getWrapperStorage().writeDouble(tb[0].x);
152  server.getWrapperStorage().writeDouble(tb[0].y);
153  server.getWrapperStorage().writeDouble(tb[1].x);
154  server.getWrapperStorage().writeDouble(tb[1].y);
155  break;
156  }
158  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
159  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Position conversion requires a compound object.", outputStorage);
160  }
161  const int compoundSize = inputStorage.readInt();
162  if (compoundSize < 2 || compoundSize > 3) {
163  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Position conversion requires a source position and a position type as parameter.", outputStorage);
164  }
165  if (!commandPositionConversion(server, inputStorage, compoundSize, server.getWrapperStorage(), libsumo::CMD_GET_SIM_VARIABLE)) {
166  return false;
167  }
168  break;
169  }
171  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
172  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of distance requires a compound object.", outputStorage);
173  }
174  if (inputStorage.readInt() != 3) {
175  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of distance requires two positions and a distance type as parameter.", outputStorage);
176  }
177  if (!commandDistanceRequest(server, inputStorage, server.getWrapperStorage(), libsumo::CMD_GET_SIM_VARIABLE)) {
178  return false;
179  }
180  break;
181  case libsumo::FIND_ROUTE: {
182  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
183  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a compound object.", outputStorage);
184  }
185  if (inputStorage.readInt() != 5) {
186  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires five parameter.", outputStorage);
187  }
188  std::string from, to, vtype;
189  double depart;
190  int routingMode;
191  if (!server.readTypeCheckingString(inputStorage, from)) {
192  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
193  }
194  if (!server.readTypeCheckingString(inputStorage, to)) {
195  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
196  }
197  if (!server.readTypeCheckingString(inputStorage, vtype)) {
198  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
199  }
200  if (!server.readTypeCheckingDouble(inputStorage, depart)) {
201  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
202  }
203  if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
204  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
205  }
206  writeStage(server.getWrapperStorage(), libsumo::Simulation::findRoute(from, to, vtype, depart, routingMode));
207  break;
208  }
210  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
211  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires a compound object.", outputStorage);
212  }
213  if (inputStorage.readInt() != 13) {
214  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires thirteen parameters.", outputStorage);
215  }
216  std::string from, to, modes, ptype, vtype, destStop;
217  double depart, speed, walkFactor, departPos, arrivalPos, departPosLat;
218  int routingMode;
219  if (!server.readTypeCheckingString(inputStorage, from)) {
220  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
221  }
222  if (!server.readTypeCheckingString(inputStorage, to)) {
223  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
224  }
225  if (!server.readTypeCheckingString(inputStorage, modes)) {
226  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
227  }
228  if (!server.readTypeCheckingDouble(inputStorage, depart)) {
229  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
230  }
231  if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
232  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
233  }
234  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
235  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as sixth parameter.", outputStorage);
236  }
237  if (!server.readTypeCheckingDouble(inputStorage, walkFactor)) {
238  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as seventh parameter.", outputStorage);
239  }
240  if (!server.readTypeCheckingDouble(inputStorage, departPos)) {
241  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as eigth parameter.", outputStorage);
242  }
243  if (!server.readTypeCheckingDouble(inputStorage, arrivalPos)) {
244  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as nineth parameter.", outputStorage);
245  }
246  if (!server.readTypeCheckingDouble(inputStorage, departPosLat)) {
247  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as tenth parameter.", outputStorage);
248  }
249  if (!server.readTypeCheckingString(inputStorage, ptype)) {
250  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as eleventh parameter.", outputStorage);
251  }
252  if (!server.readTypeCheckingString(inputStorage, vtype)) {
253  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as twelvth parameter.", outputStorage);
254  }
255  if (!server.readTypeCheckingString(inputStorage, destStop)) {
256  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as thirteenth parameter.", outputStorage);
257  }
258  const std::vector<libsumo::TraCIStage>& result = libsumo::Simulation::findIntermodalRoute(from, to, modes, depart, routingMode, speed, walkFactor, departPos, arrivalPos, departPosLat, ptype, vtype, destStop);
260  server.getWrapperStorage().writeInt((int)result.size());
261  for (const libsumo::TraCIStage& s : result) {
262  writeStage(server.getWrapperStorage(), s);
263  }
264  break;
265  }
266  case libsumo::VAR_PARAMETER: {
267  std::string paramName = "";
268  if (!server.readTypeCheckingString(inputStorage, paramName)) {
269  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
270  }
273  break;
274  }
275  default:
276  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Get Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
277  }
278  } catch (libsumo::TraCIException& e) {
279  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
280  }
282  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
283  return true;
284 }
285 
286 
287 bool
289  tcpip::Storage& outputStorage) {
290  std::string warning = ""; // additional description for response
291  // variable
292  int variable = inputStorage.readUnsignedByte();
294  && variable != libsumo::CMD_SAVE_SIMSTATE) {
295  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "Set Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
296  }
297  // id
298  std::string id = inputStorage.readString();
299  // process
300  try {
301  switch (variable) {
303  //clear any pending vehicle insertions
304  std::string route;
305  if (!server.readTypeCheckingString(inputStorage, route)) {
306  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for clearing pending vehicles.", outputStorage);
307  }
309  }
310  break;
312  //save current simulation state
313  std::string file;
314  if (!server.readTypeCheckingString(inputStorage, file)) {
315  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for saving simulation state.", outputStorage);
316  }
318  }
319  break;
320  default:
321  break;
322  }
323  } catch (libsumo::TraCIException& e) {
324  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
325  }
326  server.writeStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
327  return true;
328 }
329 
330 
331 void
333  const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
335  outputStorage.writeInt((int) ids.size());
336 }
337 
338 
339 void
341  const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
343  outputStorage.writeStringList(ids);
344 }
345 
346 
347 void
350  outputStorage.writeInt(13);
352  outputStorage.writeInt(stage.type);
354  outputStorage.writeString(stage.vType);
356  outputStorage.writeString(stage.line);
358  outputStorage.writeString(stage.destStop);
360  outputStorage.writeStringList(stage.edges);
362  outputStorage.writeDouble(stage.travelTime);
364  outputStorage.writeDouble(stage.cost);
366  outputStorage.writeDouble(stage.length);
368  outputStorage.writeString(stage.intended);
370  outputStorage.writeDouble(stage.depart);
372  outputStorage.writeDouble(stage.departPos);
374  outputStorage.writeDouble(stage.arrivalPos);
376  outputStorage.writeString(stage.description);
377 }
378 
381  auto* stage = new libsumo::TraCIStage();
382  server.readTypeCheckingInt(inputStorage, stage->type);
383  server.readTypeCheckingString(inputStorage, stage->vType);
384  server.readTypeCheckingString(inputStorage, stage->line);
385  server.readTypeCheckingString(inputStorage, stage->destStop);
386  server.readTypeCheckingStringList(inputStorage, stage->edges);
387  server.readTypeCheckingDouble(inputStorage, stage->travelTime);
388  server.readTypeCheckingDouble(inputStorage, stage->cost);
389  server.readTypeCheckingDouble(inputStorage, stage->length);
390  server.readTypeCheckingString(inputStorage, stage->intended);
391  server.readTypeCheckingDouble(inputStorage, stage->depart);
392  server.readTypeCheckingDouble(inputStorage, stage->departPos);
393  server.readTypeCheckingDouble(inputStorage, stage->arrivalPos);
394  server.readTypeCheckingString(inputStorage, stage->description);
395  return stage;
396 }
397 
398 bool
400  const int compoundSize, tcpip::Storage& outputStorage,
401  const int commandId) {
402  std::pair<MSLane*, double> roadPos;
403  Position cartesianPos;
404  Position geoPos;
405  double z = 0;
406 
407  // actual position type that will be converted
408  int srcPosType = inputStorage.readUnsignedByte();
409 
410  switch (srcPosType) {
415  const double x = inputStorage.readDouble();
416  const double y = inputStorage.readDouble();
417  if (srcPosType != libsumo::POSITION_2D && srcPosType != libsumo::POSITION_LON_LAT) {
418  z = inputStorage.readDouble();
419  }
420  geoPos.set(x, y);
421  cartesianPos.set(x, y);
422  if (srcPosType == libsumo::POSITION_LON_LAT || srcPosType == libsumo::POSITION_LON_LAT_ALT) {
424  } else {
426  }
427  }
428  break;
430  const std::string roadID = inputStorage.readString();
431  const double pos = inputStorage.readDouble();
432  const int laneIdx = inputStorage.readUnsignedByte();
433  try {
434  // convert edge,offset,laneIdx to cartesian position
435  cartesianPos = geoPos = libsumo::Helper::getLaneChecking(roadID, laneIdx, pos)->geometryPositionAtOffset(pos);
436  z = cartesianPos.z();
438  } catch (libsumo::TraCIException& e) {
439  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
440  return false;
441  }
442  }
443  break;
444  default:
445  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Source position type not supported");
446  return false;
447  }
448 
449  int destPosType = 0;
450  if (!server.readTypeCheckingUnsignedByte(inputStorage, destPosType)) {
451  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Destination position type must be of type ubyte.");
452  return false;
453  }
454 
456  if (compoundSize == 3) {
457  inputStorage.readUnsignedByte();
458  const std::string& vClassString = inputStorage.readString();
459  if (!SumoVehicleClassStrings.hasString(vClassString)) {
460  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown vehicle class '" + vClassString + "'.");
461  return false;
462  }
463  vClass = SumoVehicleClassStrings.get(vClassString);
464  }
465 
466  switch (destPosType) {
468  // convert cartesion position to edge,offset,lane_index
469  roadPos = libsumo::Helper::convertCartesianToRoadMap(cartesianPos, vClass);
470  if (roadPos.first == nullptr) {
471  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "No matching lane found.");
472  return false;
473  }
474  // write result that is added to response msg
476  outputStorage.writeString(roadPos.first->getEdge().getID());
477  outputStorage.writeDouble(roadPos.second);
478  outputStorage.writeUnsignedByte(roadPos.first->getIndex());
479  }
480  break;
485  outputStorage.writeUnsignedByte(destPosType);
486  if (destPosType == libsumo::POSITION_LON_LAT || destPosType == libsumo::POSITION_LON_LAT_ALT) {
487  outputStorage.writeDouble(geoPos.x());
488  outputStorage.writeDouble(geoPos.y());
489  } else {
490  outputStorage.writeDouble(cartesianPos.x());
491  outputStorage.writeDouble(cartesianPos.y());
492  }
493  if (destPosType != libsumo::POSITION_2D && destPosType != libsumo::POSITION_LON_LAT) {
494  outputStorage.writeDouble(z);
495  }
496  break;
497  default:
498  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Destination position type not supported");
499  return false;
500  }
501  return true;
502 }
503 
504 
505 bool
507  tcpip::Storage& outputStorage, int commandId) {
508  Position pos1;
509  Position pos2;
510  std::pair<const MSLane*, double> roadPos1;
511  std::pair<const MSLane*, double> roadPos2;
512 
513  // read position 1
514  int posType = inputStorage.readUnsignedByte();
515  switch (posType) {
517  try {
518  std::string roadID = inputStorage.readString();
519  roadPos1.second = inputStorage.readDouble();
520  roadPos1.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos1.second);
521  pos1 = roadPos1.first->geometryPositionAtOffset(roadPos1.second);
522  } catch (libsumo::TraCIException& e) {
523  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
524  return false;
525  }
526  break;
528  case libsumo::POSITION_3D: {
529  double p1x = inputStorage.readDouble();
530  double p1y = inputStorage.readDouble();
531  pos1.set(p1x, p1y);
532  }
533  if (posType == libsumo::POSITION_3D) {
534  inputStorage.readDouble();// z value is ignored
535  }
537  break;
538  default:
539  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown position format used for distance request");
540  return false;
541  }
542 
543  // read position 2
544  posType = inputStorage.readUnsignedByte();
545  switch (posType) {
547  try {
548  std::string roadID = inputStorage.readString();
549  roadPos2.second = inputStorage.readDouble();
550  roadPos2.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos2.second);
551  pos2 = roadPos2.first->geometryPositionAtOffset(roadPos2.second);
552  } catch (libsumo::TraCIException& e) {
553  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
554  return false;
555  }
556  break;
558  case libsumo::POSITION_3D: {
559  double p2x = inputStorage.readDouble();
560  double p2y = inputStorage.readDouble();
561  pos2.set(p2x, p2y);
562  }
563  if (posType == libsumo::POSITION_3D) {
564  inputStorage.readDouble();// z value is ignored
565  }
567  break;
568  default:
569  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown position format used for distance request");
570  return false;
571  }
572 
573  // read distance type
574  int distType = inputStorage.readUnsignedByte();
575 
576  double distance = 0.0;
577  if (distType == libsumo::REQUEST_DRIVINGDIST) {
578  // compute driving distance
579  if ((roadPos1.first == roadPos2.first) && (roadPos1.second <= roadPos2.second)) {
580  // same edge
581  distance = roadPos2.second - roadPos1.second;
582  } else {
583  ConstMSEdgeVector newRoute;
584  while (roadPos2.first->isInternal() && roadPos2.first != roadPos1.first) {
585  distance += roadPos2.second;
586  roadPos2.first = roadPos2.first->getLogicalPredecessorLane();
587  roadPos2.second = roadPos2.first->getLength();
588  }
590  &roadPos1.first->getEdge(), &roadPos2.first->getEdge(), nullptr, MSNet::getInstance()->getCurrentTimeStep(), newRoute, true);
591  if (newRoute.size() == 0) {
593  } else {
594  MSRoute route("", newRoute, false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
595  distance += route.getDistanceBetween(roadPos1.second, roadPos2.second, &roadPos1.first->getEdge(), &roadPos2.first->getEdge());
596  }
597  }
598  } else {
599  // compute air distance (default)
600  distance = pos1.distanceTo(pos2);
601  }
602  // write response command
604  outputStorage.writeDouble(distance);
605  return true;
606 }
607 
608 
609 /****************************************************************************/
TRACI_CONST int CMD_SAVE_SIMSTATE
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:540
TRACI_CONST int VAR_MIN_EXPECTED_VEHICLES
TRACI_CONST int VAR_PARKING_ENDING_VEHICLES_NUMBER
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:350
TRACI_CONST int POSITION_3D
TRACI_CONST int VAR_TIME
static void writeVehicleStateIDs(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::VehicleState state)
std::string line
The line or the id of the vehicle type.
Definition: TraCIDefs.h:354
double z() const
Returns the z-position.
Definition: Position.h:67
TRACI_CONST int VAR_TIME_STEP
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_NUMBER
static std::vector< TraCIStage > findIntermodalRoute(const std::string &fromEdge, const std::string &toEdge, const std::string &modes="", double depart=-1., const int routingMode=0, double speed=-1., double walkFactor=-1., double departPos=0, double arrivalPos=INVALID_DOUBLE_VALUE, const double departPosLat=0, const std::string &pType="", const std::string &vType="", const std::string &destStop="")
Definition: Simulation.cpp:483
static double getDeltaT()
Definition: Simulation.cpp:294
double arrivalPos
position on the lane when ending the stage
Definition: TraCIDefs.h:372
TRACI_CONST int RTYPE_OK
static void writeStage(tcpip::Storage &outputStorage, const libsumo::TraCIStage &stage)
double length
length in m
Definition: TraCIDefs.h:364
TRACI_CONST int CMD_CLEAR_PENDING_VEHICLES
TRACI_CONST int VAR_LOADED_VEHICLES_NUMBER
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:356
double y() const
Returns the y-position.
Definition: Position.h:62
virtual double readDouble()
TRACI_CONST int VAR_PARAMETER
double x() const
Returns the x-position.
Definition: Position.h:57
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xab: Get Simulation Variable)
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
static std::string getParameter(const std::string &objectID, const std::string &key)
Definition: Simulation.cpp:616
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
TRACI_CONST int VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER
TRACI_CONST int RESPONSE_GET_SIM_VARIABLE
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:290
TRACI_CONST int CMD_SET_SIM_VARIABLE
static libsumo::TraCIStage * readStage(TraCIServer &server, tcpip::Storage &inputStorage)
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
virtual void writeUnsignedByte(int)
TRACI_CONST int VAR_DEPARTED_VEHICLES_IDS
void set(double x, double y)
set positions x and y
Definition: Position.h:87
TRACI_CONST int POSITION_LON_LAT
double depart
intended depart time for public transport ride or INVALID_DOUBLE_VALUE
Definition: TraCIDefs.h:368
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
double departPos
position on the lane when starting the stage
Definition: TraCIDefs.h:370
double cost
effort needed
Definition: TraCIDefs.h:362
std::string description
arbitrary description string
Definition: TraCIDefs.h:374
TRACI_CONST int RTYPE_ERR
static void writeVehicleStateNumber(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::VehicleState state)
virtual void writeInt(int)
TRACI_CONST int VAR_BUS_STOP_WAITING
#define SIMTIME
Definition: SUMOTime.h:64
virtual int readUnsignedByte()
TRACI_CONST int VAR_BUS_STOP_WAITING_IDS
The vehicles starts to stop.
Definition: MSNet.h:554
TRACI_CONST int TYPE_INTEGER
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
TRACI_CONST int CMD_GET_SIM_VARIABLE
TRACI_CONST int VAR_ARRIVED_VEHICLES_NUMBER
static TraCIStage findRoute(const std::string &fromEdge, const std::string &toEdge, const std::string &vType="", const double depart=-1., const int routingMode=0)
Definition: Simulation.cpp:441
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcb: Set Simulation Variable)
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:546
TRACI_CONST int FIND_ROUTE
The vehicles starts to park.
Definition: MSNet.h:550
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
The vehicle is involved in a collision.
Definition: MSNet.h:558
TRACI_CONST int TYPE_POLYGON
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_IDS
virtual int readInt()
The vehicle had to brake harder than permitted.
Definition: MSNet.h:560
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static TraCIPositionVector getNetBoundary()
Definition: Simulation.cpp:300
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:358
virtual void writeByte(int)
bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
virtual void writeStringList(const std::vector< std::string > &s)
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:284
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
TRACI_CONST int VAR_DELTA_T
TRACI_CONST int TYPE_DOUBLE
The vehicle started to teleport.
Definition: MSNet.h:542
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_IDS
tcpip::Storage & getWrapperStorage()
TRACI_CONST int TYPE_STRINGLIST
virtual std::string readString()
TRACI_CONST int TYPE_STRING
TRACI_CONST int VAR_NET_BOUNDING_BOX
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition: Helper.cpp:307
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
The vehicle ends to park.
Definition: MSNet.h:552
static void saveState(const std::string &fileName)
Definition: Simulation.cpp:681
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:62
static std::vector< std::string > getBusStopIDList()
Definition: Simulation.cpp:264
TRACI_CONST int VAR_DEPARTED_VEHICLES_NUMBER
TRACI_CONST int DISTANCE_REQUEST
TRACI_CONST int POSITION_LON_LAT_ALT
std::string vType
The vehicle type when using a private car or bike.
Definition: TraCIDefs.h:352
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:536
static bool commandDistanceRequest(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, int commandId)
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_IDS
The vehicle was built, but has not yet departed.
Definition: MSNet.h:538
TRACI_CONST int VAR_COLLIDING_VEHICLES_IDS
static int getBusStopWaiting(const std::string &id)
Definition: Simulation.cpp:273
virtual void writeString(const std::string &s)
TRACI_CONST int POSITION_ROADMAP
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:58
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:150
TRACI_CONST int FIND_INTERMODAL_ROUTE
static std::vector< std::string > getBusStopWaitingIDList(const std::string &id)
Returns the IDs of the transportables on a given bus stop.
Definition: Simulation.cpp:282
TRACI_CONST int VAR_LOADED_VEHICLES_IDS
const std::map< MSNet::VehicleState, std::vector< std::string > > & getVehicleStateChanges() const
Definition: TraCIServer.h:136
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_IDS
TRACI_CONST int VAR_COLLIDING_VEHICLES_NUMBER
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:360
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_NUMBER
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
The vehicle ends to stop.
Definition: MSNet.h:556
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
TRACI_CONST int REQUEST_DRIVINGDIST
virtual void writeDouble(double)
TRACI_CONST int POSITION_CONVERSION
static int getMinExpectedNumber()
Definition: Simulation.cpp:314
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation. ...
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:234
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
TRACI_CONST int POSITION_2D
std::string intended
id of the intended vehicle for public transport ride
Definition: TraCIDefs.h:366
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:954
void initWrapper(const int domainID, const int variable, const std::string &objID)
static void clearPending(const std::string &routeID="")
Definition: Simulation.cpp:675
TRACI_CONST int VAR_ARRIVED_VEHICLES_IDS
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_IDS
TRACI_CONST int VAR_BUS_STOP_ID_LIST
TRACI_CONST double INVALID_DOUBLE_VALUE
static int getCurrentTime()
Definition: Simulation.cpp:121
The vehicle ended being teleported.
Definition: MSNet.h:544
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int VAR_PARKING_ENDING_VEHICLES_IDS
vehicles ignoring classes
TRACI_CONST int VAR_EMERGENCYSTOPPING_VEHICLES_IDS
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_NUMBER
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_NUMBER
static bool commandPositionConversion(TraCIServer &server, tcpip::Storage &inputStorage, const int compoundSize, tcpip::Storage &outputStorage, const int commandId)
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:277