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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // APIs for getting/setting edge values via TraCI
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <utils/common/StdDefs.h>
27 #include <microsim/MSNet.h>
28 #include <microsim/MSEdgeControl.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSVehicle.h>
36 #include <libsumo/Helper.h>
37 #include <libsumo/Simulation.h>
38 #include <libsumo/TraCIConstants.h>
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 bool
47  tcpip::Storage& outputStorage) {
48  const int variable = inputStorage.readUnsignedByte();
49  const std::string id = inputStorage.readString();
50  server.initWrapper(libsumo::RESPONSE_GET_SIM_VARIABLE, variable, id);
51  try {
52  switch (variable) {
53  case libsumo::VAR_TIME:
56  break;
59  server.getWrapperStorage().writeInt((int)libsumo::Simulation::getCurrentTime());
60  break;
63  break;
66  break;
69  break;
72  break;
75  break;
78  break;
81  break;
84  break;
87  break;
90  break;
93  break;
96  break;
99  break;
102  break;
105  break;
108  break;
111  break;
114  break;
117  break;
120  break;
123  break;
126  break;
129  break;
132  break;
135  server.getWrapperStorage().writeDouble(libsumo::Simulation::getDeltaT());
136  break;
139  server.getWrapperStorage().writeInt(libsumo::Simulation::getMinExpectedNumber());
140  break;
142  server.wrapStringList(id, variable, libsumo::Simulation::getBusStopIDList());
143  break;
146  server.getWrapperStorage().writeInt(libsumo::Simulation::getBusStopWaiting(id));
147  break;
149  server.wrapStringList(id, variable, libsumo::Simulation::getBusStopWaitingIDList(id));
150  break;
153  libsumo::TraCIPositionVector tb = libsumo::Simulation::getNetBoundary();
154  server.getWrapperStorage().writeByte(2);
155  server.getWrapperStorage().writeDouble(tb[0].x);
156  server.getWrapperStorage().writeDouble(tb[0].y);
157  server.getWrapperStorage().writeDouble(tb[1].x);
158  server.getWrapperStorage().writeDouble(tb[1].y);
159  break;
160  }
162  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
163  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Position conversion requires a compound object.", outputStorage);
164  }
165  const int compoundSize = inputStorage.readInt();
166  if (compoundSize < 2 || compoundSize > 3) {
167  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Position conversion requires a source position and a position type as parameter.", outputStorage);
168  }
169  if (!commandPositionConversion(server, inputStorage, compoundSize, server.getWrapperStorage(), libsumo::CMD_GET_SIM_VARIABLE)) {
170  return false;
171  }
172  break;
173  }
175  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
176  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of distance requires a compound object.", outputStorage);
177  }
178  if (inputStorage.readInt() != 3) {
179  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of distance requires two positions and a distance type as parameter.", outputStorage);
180  }
181  if (!commandDistanceRequest(server, inputStorage, server.getWrapperStorage(), libsumo::CMD_GET_SIM_VARIABLE)) {
182  return false;
183  }
184  break;
185  case libsumo::FIND_ROUTE: {
186  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
187  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a compound object.", outputStorage);
188  }
189  if (inputStorage.readInt() != 5) {
190  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires five parameter.", outputStorage);
191  }
192  std::string from, to, vtype;
193  double depart;
194  int routingMode;
195  if (!server.readTypeCheckingString(inputStorage, from)) {
196  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
197  }
198  if (!server.readTypeCheckingString(inputStorage, to)) {
199  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
200  }
201  if (!server.readTypeCheckingString(inputStorage, vtype)) {
202  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
203  }
204  if (!server.readTypeCheckingDouble(inputStorage, depart)) {
205  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
206  }
207  if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
208  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
209  }
210  writeStage(server.getWrapperStorage(), libsumo::Simulation::findRoute(from, to, vtype, depart, routingMode));
211  break;
212  }
214  if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
215  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires a compound object.", outputStorage);
216  }
217  if (inputStorage.readInt() != 13) {
218  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires thirteen parameters.", outputStorage);
219  }
220  std::string from, to, modes, ptype, vtype, destStop;
221  double depart, speed, walkFactor, departPos, arrivalPos, departPosLat;
222  int routingMode;
223  if (!server.readTypeCheckingString(inputStorage, from)) {
224  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
225  }
226  if (!server.readTypeCheckingString(inputStorage, to)) {
227  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
228  }
229  if (!server.readTypeCheckingString(inputStorage, modes)) {
230  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
231  }
232  if (!server.readTypeCheckingDouble(inputStorage, depart)) {
233  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
234  }
235  if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
236  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
237  }
238  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
239  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as sixth parameter.", outputStorage);
240  }
241  if (!server.readTypeCheckingDouble(inputStorage, walkFactor)) {
242  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as seventh parameter.", outputStorage);
243  }
244  if (!server.readTypeCheckingDouble(inputStorage, departPos)) {
245  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as eigth parameter.", outputStorage);
246  }
247  if (!server.readTypeCheckingDouble(inputStorage, arrivalPos)) {
248  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as nineth parameter.", outputStorage);
249  }
250  if (!server.readTypeCheckingDouble(inputStorage, departPosLat)) {
251  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as tenth parameter.", outputStorage);
252  }
253  if (!server.readTypeCheckingString(inputStorage, ptype)) {
254  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as eleventh parameter.", outputStorage);
255  }
256  if (!server.readTypeCheckingString(inputStorage, vtype)) {
257  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as twelvth parameter.", outputStorage);
258  }
259  if (!server.readTypeCheckingString(inputStorage, destStop)) {
260  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as thirteenth parameter.", outputStorage);
261  }
262  const std::vector<libsumo::TraCIStage>& result = libsumo::Simulation::findIntermodalRoute(from, to, modes, depart, routingMode, speed, walkFactor, departPos, arrivalPos, departPosLat, ptype, vtype, destStop);
264  server.getWrapperStorage().writeInt((int)result.size());
265  for (const libsumo::TraCIStage& s : result) {
266  writeStage(server.getWrapperStorage(), s);
267  }
268  break;
269  }
270  case libsumo::VAR_PARAMETER: {
271  std::string paramName = "";
272  if (!server.readTypeCheckingString(inputStorage, paramName)) {
273  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
274  }
276  server.getWrapperStorage().writeString(libsumo::Simulation::getParameter(id, paramName));
277  break;
278  }
280  std::string paramName = "";
281  if (!server.readTypeCheckingString(inputStorage, paramName)) {
282  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
283  }
285  server.getWrapperStorage().writeInt(2);
287  server.getWrapperStorage().writeString(paramName);
289  server.getWrapperStorage().writeString(libsumo::Simulation::getParameter(id, paramName));
290  break;
291  }
292  default:
293  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, "Get Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
294  }
295  } catch (libsumo::TraCIException& e) {
296  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
297  }
299  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
300  return true;
301 }
302 
303 
304 bool
306  tcpip::Storage& outputStorage) {
307  std::string warning = ""; // additional description for response
308  // variable
309  int variable = inputStorage.readUnsignedByte();
311  && variable != libsumo::CMD_SAVE_SIMSTATE
312  && variable != libsumo::CMD_LOAD_SIMSTATE
313  && variable != libsumo::CMD_MESSAGE
314  ) {
315  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "Set Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
316  }
317  // id
318  std::string id = inputStorage.readString();
319  // process
320  try {
321  switch (variable) {
323  //clear any pending vehicle insertions
324  std::string route;
325  if (!server.readTypeCheckingString(inputStorage, route)) {
326  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for clearing pending vehicles.", outputStorage);
327  }
328  libsumo::Simulation::clearPending(route);
329  }
330  break;
332  //save current simulation state
333  std::string file;
334  if (!server.readTypeCheckingString(inputStorage, file)) {
335  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for saving simulation state.", outputStorage);
336  }
337  libsumo::Simulation::saveState(file);
338  }
339  break;
341  //quick-load simulation state
342  std::string file;
343  if (!server.readTypeCheckingString(inputStorage, file)) {
344  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for loading simulation state.", outputStorage);
345  }
346  double time = libsumo::Simulation::loadState(file);
348  }
349  break;
350  case libsumo::CMD_MESSAGE: {
351  std::string msg;
352  if (!server.readTypeCheckingString(inputStorage, msg)) {
353  return server.writeErrorStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, "A string is needed for adding a log message.", outputStorage);
354  }
355  libsumo::Simulation::writeMessage(msg);
356  }
357  break;
358  default:
359  break;
360  }
361  } catch (libsumo::TraCIException& e) {
362  return server.writeErrorStatusCmd(libsumo::CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
363  }
364  server.writeStatusCmd(libsumo::CMD_SET_SIM_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
365  return true;
366 }
367 
368 
369 void
371  const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
373  outputStorage.writeInt((int) ids.size());
374 }
375 
376 
377 void
379  const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
381  outputStorage.writeStringList(ids);
382 }
383 
384 
385 void
388  outputStorage.writeInt(13);
390  outputStorage.writeInt(stage.type);
392  outputStorage.writeString(stage.vType);
394  outputStorage.writeString(stage.line);
396  outputStorage.writeString(stage.destStop);
398  outputStorage.writeStringList(stage.edges);
400  outputStorage.writeDouble(stage.travelTime);
402  outputStorage.writeDouble(stage.cost);
404  outputStorage.writeDouble(stage.length);
406  outputStorage.writeString(stage.intended);
408  outputStorage.writeDouble(stage.depart);
410  outputStorage.writeDouble(stage.departPos);
412  outputStorage.writeDouble(stage.arrivalPos);
414  outputStorage.writeString(stage.description);
415 }
416 
419  auto* stage = new libsumo::TraCIStage();
420  server.readTypeCheckingInt(inputStorage, stage->type);
421  server.readTypeCheckingString(inputStorage, stage->vType);
422  server.readTypeCheckingString(inputStorage, stage->line);
423  server.readTypeCheckingString(inputStorage, stage->destStop);
424  server.readTypeCheckingStringList(inputStorage, stage->edges);
425  server.readTypeCheckingDouble(inputStorage, stage->travelTime);
426  server.readTypeCheckingDouble(inputStorage, stage->cost);
427  server.readTypeCheckingDouble(inputStorage, stage->length);
428  server.readTypeCheckingString(inputStorage, stage->intended);
429  server.readTypeCheckingDouble(inputStorage, stage->depart);
430  server.readTypeCheckingDouble(inputStorage, stage->departPos);
431  server.readTypeCheckingDouble(inputStorage, stage->arrivalPos);
432  server.readTypeCheckingString(inputStorage, stage->description);
433  return stage;
434 }
435 
436 bool
438  const int compoundSize, tcpip::Storage& outputStorage,
439  const int commandId) {
440  std::pair<MSLane*, double> roadPos;
441  Position cartesianPos;
442  Position geoPos;
443  double z = 0;
444 
445  // actual position type that will be converted
446  int srcPosType = inputStorage.readUnsignedByte();
447 
448  switch (srcPosType) {
453  const double x = inputStorage.readDouble();
454  const double y = inputStorage.readDouble();
455  if (srcPosType != libsumo::POSITION_2D && srcPosType != libsumo::POSITION_LON_LAT) {
456  z = inputStorage.readDouble();
457  }
458  geoPos.set(x, y);
459  cartesianPos.set(x, y);
460  if (srcPosType == libsumo::POSITION_LON_LAT || srcPosType == libsumo::POSITION_LON_LAT_ALT) {
462  } else {
464  }
465  }
466  break;
468  const std::string roadID = inputStorage.readString();
469  const double pos = inputStorage.readDouble();
470  const int laneIdx = inputStorage.readUnsignedByte();
471  try {
472  // convert edge,offset,laneIdx to cartesian position
473  cartesianPos = geoPos = libsumo::Helper::getLaneChecking(roadID, laneIdx, pos)->geometryPositionAtOffset(pos);
474  z = cartesianPos.z();
476  } catch (libsumo::TraCIException& e) {
477  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
478  return false;
479  }
480  }
481  break;
482  default:
483  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Source position type not supported");
484  return false;
485  }
486 
487  int destPosType = 0;
488  if (!server.readTypeCheckingUnsignedByte(inputStorage, destPosType)) {
489  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Destination position type must be of type ubyte.");
490  return false;
491  }
492 
494  if (compoundSize == 3) {
495  inputStorage.readUnsignedByte();
496  const std::string& vClassString = inputStorage.readString();
497  if (!SumoVehicleClassStrings.hasString(vClassString)) {
498  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown vehicle class '" + vClassString + "'.");
499  return false;
500  }
501  vClass = SumoVehicleClassStrings.get(vClassString);
502  }
503 
504  switch (destPosType) {
506  // convert cartesion position to edge,offset,lane_index
507  roadPos = libsumo::Helper::convertCartesianToRoadMap(cartesianPos, vClass);
508  if (roadPos.first == nullptr) {
509  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "No matching lane found.");
510  return false;
511  }
512  // write result that is added to response msg
514  outputStorage.writeString(roadPos.first->getEdge().getID());
515  outputStorage.writeDouble(roadPos.second);
516  outputStorage.writeUnsignedByte(roadPos.first->getIndex());
517  }
518  break;
523  outputStorage.writeUnsignedByte(destPosType);
524  if (destPosType == libsumo::POSITION_LON_LAT || destPosType == libsumo::POSITION_LON_LAT_ALT) {
525  outputStorage.writeDouble(geoPos.x());
526  outputStorage.writeDouble(geoPos.y());
527  } else {
528  outputStorage.writeDouble(cartesianPos.x());
529  outputStorage.writeDouble(cartesianPos.y());
530  }
531  if (destPosType != libsumo::POSITION_2D && destPosType != libsumo::POSITION_LON_LAT) {
532  outputStorage.writeDouble(z);
533  }
534  break;
535  default:
536  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Destination position type not supported");
537  return false;
538  }
539  return true;
540 }
541 
542 
543 bool
545  tcpip::Storage& outputStorage, int commandId) {
546  Position pos1;
547  Position pos2;
548  std::pair<const MSLane*, double> roadPos1;
549  std::pair<const MSLane*, double> roadPos2;
550 
551  // read position 1
552  int posType = inputStorage.readUnsignedByte();
553  switch (posType) {
555  try {
556  std::string roadID = inputStorage.readString();
557  roadPos1.second = inputStorage.readDouble();
558  roadPos1.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos1.second);
559  pos1 = roadPos1.first->geometryPositionAtOffset(roadPos1.second);
560  } catch (libsumo::TraCIException& e) {
561  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
562  return false;
563  }
564  break;
566  case libsumo::POSITION_3D: {
567  double p1x = inputStorage.readDouble();
568  double p1y = inputStorage.readDouble();
569  pos1.set(p1x, p1y);
570  }
571  if (posType == libsumo::POSITION_3D) {
572  inputStorage.readDouble();// z value is ignored
573  }
575  break;
576  default:
577  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown position format used for distance request");
578  return false;
579  }
580 
581  // read position 2
582  posType = inputStorage.readUnsignedByte();
583  switch (posType) {
585  try {
586  std::string roadID = inputStorage.readString();
587  roadPos2.second = inputStorage.readDouble();
588  roadPos2.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos2.second);
589  pos2 = roadPos2.first->geometryPositionAtOffset(roadPos2.second);
590  } catch (libsumo::TraCIException& e) {
591  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, e.what());
592  return false;
593  }
594  break;
596  case libsumo::POSITION_3D: {
597  double p2x = inputStorage.readDouble();
598  double p2y = inputStorage.readDouble();
599  pos2.set(p2x, p2y);
600  }
601  if (posType == libsumo::POSITION_3D) {
602  inputStorage.readDouble();// z value is ignored
603  }
605  break;
606  default:
607  server.writeStatusCmd(commandId, libsumo::RTYPE_ERR, "Unknown position format used for distance request");
608  return false;
609  }
610 
611  // read distance type
612  const int distType = inputStorage.readUnsignedByte();
613 
614  double distance = 0.0;
615  if (distType == libsumo::REQUEST_DRIVINGDIST) {
616  distance = libsumo::Helper::getDrivingDistance(roadPos1, roadPos2);
617  } else {
618  // compute air distance (default)
619  distance = pos1.distanceTo(pos2);
620  }
621  // write response command
623  outputStorage.writeDouble(distance);
624  return true;
625 }
626 
627 
628 /****************************************************************************/
#define SIMTIME
Definition: SUMOTime.h:60
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:54
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:503
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:587
@ VEHICLE_STATE_ENDING_TELEPORT
The vehicle ended being teleported.
Definition: MSNet.h:595
@ VEHICLE_STATE_DEPARTED
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:591
@ VEHICLE_STATE_STARTING_PARKING
The vehicles starts to park.
Definition: MSNet.h:601
@ VEHICLE_STATE_MANEUVERING
Vehicle maneuvering either entering or exiting a parking space.
Definition: MSNet.h:613
@ VEHICLE_STATE_ENDING_STOP
The vehicle ends to stop.
Definition: MSNet.h:607
@ VEHICLE_STATE_ARRIVED
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:597
@ VEHICLE_STATE_COLLISION
The vehicle is involved in a collision.
Definition: MSNet.h:609
@ VEHICLE_STATE_EMERGENCYSTOP
The vehicle had to brake harder than permitted.
Definition: MSNet.h:611
@ VEHICLE_STATE_STARTING_TELEPORT
The vehicle started to teleport.
Definition: MSNet.h:593
@ VEHICLE_STATE_STARTING_STOP
The vehicles starts to stop.
Definition: MSNet.h:605
@ VEHICLE_STATE_ENDING_PARKING
The vehicle ends to park.
Definition: MSNet.h:603
@ VEHICLE_STATE_BUILT
The vehicle was built, but has not yet departed.
Definition: MSNet.h:589
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
void set(double x, double y)
set positions x and y
Definition: Position.h:84
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:231
double x() const
Returns the x-position.
Definition: Position.h:54
double z() const
Returns the z-position.
Definition: Position.h:64
double y() const
Returns the y-position.
Definition: Position.h:59
static libsumo::TraCIStage * readStage(TraCIServer &server, tcpip::Storage &inputStorage)
static bool commandPositionConversion(TraCIServer &server, tcpip::Storage &inputStorage, const int compoundSize, tcpip::Storage &outputStorage, const int commandId)
static bool commandDistanceRequest(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, int commandId)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcb: Set Simulation Variable)
static void writeVehicleStateIDs(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::VehicleState state)
static void writeVehicleStateNumber(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::VehicleState state)
static void writeStage(tcpip::Storage &outputStorage, const libsumo::TraCIStage &stage)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xab: Get Simulation Variable)
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:59
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
void stateLoaded(SUMOTime targetTime)
updates myTargetTime and resets vehicle state changes after loading a simulation state
tcpip::Storage & getWrapperStorage()
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
void initWrapper(const int domainID, const int variable, const std::string &objID)
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
static TraCIServer * getInstance()
Definition: TraCIServer.h:68
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
const std::map< MSNet::VehicleState, std::vector< std::string > > & getVehicleStateChanges() const
Definition: TraCIServer.h:133
bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)
static double getDrivingDistance(std::pair< const MSLane *, double > &roadPos1, std::pair< const MSLane *, double > &roadPos2)
Definition: Helper.cpp:463
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition: Helper.cpp:431
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:414
std::string intended
id of the intended vehicle for public transport ride
Definition: TraCIDefs.h:494
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:478
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:484
double length
length in m
Definition: TraCIDefs.h:492
double travelTime
duration of the stage in seconds
Definition: TraCIDefs.h:488
double departPos
position on the lane when starting the stage
Definition: TraCIDefs.h:498
std::string description
arbitrary description string
Definition: TraCIDefs.h:502
std::string line
The line or the id of the vehicle type.
Definition: TraCIDefs.h:482
double cost
effort needed
Definition: TraCIDefs.h:490
double depart
intended depart time for public transport ride or INVALID_DOUBLE_VALUE
Definition: TraCIDefs.h:496
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:486
double arrivalPos
position on the lane when ending the stage
Definition: TraCIDefs.h:500
std::string vType
The vehicle type when using a private car or bike.
Definition: TraCIDefs.h:480
virtual std::string readString()
Definition: storage.cpp:175
virtual void writeString(const std::string &s)
Definition: storage.cpp:192
virtual void writeInt(int)
Definition: storage.cpp:316
virtual void writeDouble(double)
Definition: storage.cpp:349
virtual int readUnsignedByte()
Definition: storage.cpp:150
virtual void writeStringList(const std::vector< std::string > &s)
Definition: storage.cpp:242
virtual void writeUnsignedByte(int)
Definition: storage.cpp:160
virtual void writeByte(int)
Definition: storage.cpp:135
virtual double readDouble()
Definition: storage.cpp:357
virtual int readInt()
Definition: storage.cpp:306
TRACI_CONST int VAR_MIN_EXPECTED_VEHICLES
TRACI_CONST int CMD_SAVE_SIMSTATE
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_IDS
TRACI_CONST int POSITION_3D
TRACI_CONST int POSITION_ROADMAP
TRACI_CONST int VAR_ARRIVED_VEHICLES_NUMBER
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
TRACI_CONST int VAR_DEPARTED_VEHICLES_NUMBER
TRACI_CONST int CMD_LOAD_SIMSTATE
TRACI_CONST int VAR_COLLIDING_VEHICLES_NUMBER
TRACI_CONST int CMD_CLEAR_PENDING_VEHICLES
TRACI_CONST int VAR_PARKING_ENDING_VEHICLES_IDS
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_IDS
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int VAR_PARKING_MANEUVERING_VEHICLES_IDS
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:196
TRACI_CONST int FIND_INTERMODAL_ROUTE
TRACI_CONST int VAR_PARKING_MANEUVERING_VEHICLES_NUMBER
TRACI_CONST int POSITION_2D
TRACI_CONST int VAR_TIME
TRACI_CONST int TYPE_POLYGON
TRACI_CONST int VAR_NET_BOUNDING_BOX
TRACI_CONST int TYPE_STRINGLIST
TRACI_CONST int CMD_SET_SIM_VARIABLE
TRACI_CONST int TYPE_INTEGER
TRACI_CONST int VAR_BUS_STOP_ID_LIST
TRACI_CONST int POSITION_LON_LAT
TRACI_CONST int VAR_EMERGENCYSTOPPING_VEHICLES_IDS
TRACI_CONST int VAR_BUS_STOP_WAITING_IDS
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_DEPARTED_VEHICLES_IDS
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_NUMBER
TRACI_CONST int CMD_GET_SIM_VARIABLE
TRACI_CONST int CMD_MESSAGE
TRACI_CONST int VAR_PARKING_ENDING_VEHICLES_NUMBER
TRACI_CONST int VAR_LOADED_VEHICLES_IDS
TRACI_CONST int VAR_DELTA_T
TRACI_CONST int REQUEST_DRIVINGDIST
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int RESPONSE_GET_SIM_VARIABLE
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_IDS
TRACI_CONST int FIND_ROUTE
TRACI_CONST int VAR_STOP_ENDING_VEHICLES_NUMBER
TRACI_CONST int POSITION_CONVERSION
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int DISTANCE_REQUEST
TRACI_CONST int VAR_LOADED_VEHICLES_NUMBER
TRACI_CONST int VAR_TELEPORT_ENDING_VEHICLES_IDS
TRACI_CONST int VAR_COLLIDING_VEHICLES_IDS
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_NUMBER
TRACI_CONST int VAR_TELEPORT_STARTING_VEHICLES_IDS
TRACI_CONST int VAR_BUS_STOP_WAITING
TRACI_CONST int RTYPE_ERR
TRACI_CONST int VAR_TIME_STEP
TRACI_CONST int VAR_ARRIVED_VEHICLES_IDS
TRACI_CONST int RTYPE_OK
TRACI_CONST int VAR_PARKING_STARTING_VEHICLES_NUMBER
TRACI_CONST int POSITION_LON_LAT_ALT
TRACI_CONST int VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER
TRACI_CONST int TYPE_STRING