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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // APIs for getting/setting edge values via TraCI
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #ifndef NO_TRACI
34 
35 #include <utils/common/StdDefs.h>
37 #include <microsim/MSNet.h>
38 #include <microsim/MSEdgeControl.h>
40 #include <microsim/MSEdge.h>
41 #include <microsim/MSLane.h>
42 #include <microsim/MSVehicle.h>
46 #include <libsumo/Helper.h>
47 #include <libsumo/Simulation.h>
48 #include "TraCIConstants.h"
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 bool
57  tcpip::Storage& outputStorage) {
58  // variable & id
59  int variable = inputStorage.readUnsignedByte();
60  std::string id = inputStorage.readString();
61  // check variable
62  if (variable != VAR_TIME_STEP
63  && variable != VAR_LOADED_VEHICLES_NUMBER && variable != VAR_LOADED_VEHICLES_IDS
64  && variable != VAR_DEPARTED_VEHICLES_NUMBER && variable != VAR_DEPARTED_VEHICLES_IDS
67  && variable != VAR_ARRIVED_VEHICLES_NUMBER && variable != VAR_ARRIVED_VEHICLES_IDS
68  && variable != VAR_DELTA_T && variable != VAR_NET_BOUNDING_BOX
69  && variable != VAR_MIN_EXPECTED_VEHICLES
70  && variable != POSITION_CONVERSION && variable != DISTANCE_REQUEST
71  && variable != FIND_ROUTE && variable != FIND_INTERMODAL_ROUTE
72  && variable != VAR_BUS_STOP_WAITING
77  && variable != VAR_PARAMETER
78  ) {
79  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Get Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
80  }
81  // begin response building
82  tcpip::Storage tempMsg;
83  // response-code, variableID, objectID
85  tempMsg.writeUnsignedByte(variable);
86  tempMsg.writeString(id);
87  // process request
88  try {
89  switch (variable) {
90  case VAR_TIME_STEP:
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  break;
138  break;
141  break;
144  break;
147  break;
148  case VAR_DELTA_T:
151  break;
152  case VAR_NET_BOUNDING_BOX: {
155  tempMsg.writeDouble(tb.xMin);
156  tempMsg.writeDouble(tb.yMin);
157  tempMsg.writeDouble(tb.xMax);
158  tempMsg.writeDouble(tb.yMax);
159  break;
160  }
161  break;
165  break;
166  case POSITION_CONVERSION:
167  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
168  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Position conversion requires a compound object.", outputStorage);
169  }
170  if (inputStorage.readInt() != 2) {
171  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Position conversion requires a source position and a position type as parameter.", outputStorage);
172  }
173  if (!commandPositionConversion(server, inputStorage, tempMsg, CMD_GET_SIM_VARIABLE)) {
174  return false;
175  }
176  break;
177  case DISTANCE_REQUEST:
178  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
179  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of distance requires a compound object.", outputStorage);
180  }
181  if (inputStorage.readInt() != 3) {
182  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of distance requires two positions and a distance type as parameter.", outputStorage);
183  }
184  if (!commandDistanceRequest(server, inputStorage, tempMsg, CMD_GET_SIM_VARIABLE)) {
185  return false;
186  }
187  break;
188  case FIND_ROUTE: {
189  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
190  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a compound object.", outputStorage);
191  }
192  if (inputStorage.readInt() != 5) {
193  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires five parameter.", outputStorage);
194  }
195  std::string from, to, vtype;
196  double depart;
197  int routingMode;
198  if (!server.readTypeCheckingString(inputStorage, from)) {
199  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
200  }
201  if (!server.readTypeCheckingString(inputStorage, to)) {
202  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
203  }
204  if (!server.readTypeCheckingString(inputStorage, vtype)) {
205  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
206  }
207  if (!server.readTypeCheckingDouble(inputStorage, depart)) {
208  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
209  }
210  if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
211  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
212  }
213  writeStage(tempMsg, libsumo::Simulation::findRoute(from, to, vtype, TIME2STEPS(depart), routingMode));
214  break;
215  }
216  case FIND_INTERMODAL_ROUTE: {
217  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
218  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires a compound object.", outputStorage);
219  }
220  if (inputStorage.readInt() != 12) {
221  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires twelve parameter.", outputStorage);
222  }
223  std::string from, to, modes, ptype, vtype;
224  double depart, speed, walkFactor, departPos, arrivalPos, departPosLat;
225  int routingMode;
226  if (!server.readTypeCheckingString(inputStorage, from)) {
227  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
228  }
229  if (!server.readTypeCheckingString(inputStorage, to)) {
230  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
231  }
232  if (!server.readTypeCheckingString(inputStorage, modes)) {
233  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
234  }
235  if (!server.readTypeCheckingDouble(inputStorage, depart)) {
236  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
237  }
238  if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
239  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
240  }
241  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
242  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as sixth parameter.", outputStorage);
243  }
244  if (!server.readTypeCheckingDouble(inputStorage, walkFactor)) {
245  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as seventh parameter.", outputStorage);
246  }
247  if (!server.readTypeCheckingDouble(inputStorage, departPos)) {
248  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as eigth parameter.", outputStorage);
249  }
250  if (!server.readTypeCheckingDouble(inputStorage, arrivalPos)) {
251  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as nineth parameter.", outputStorage);
252  }
253  if (!server.readTypeCheckingDouble(inputStorage, departPosLat)) {
254  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as tenth parameter.", outputStorage);
255  }
256  if (!server.readTypeCheckingString(inputStorage, ptype)) {
257  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as eleventh parameter.", outputStorage);
258  }
259  if (!server.readTypeCheckingString(inputStorage, vtype)) {
260  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as twelvth parameter.", outputStorage);
261  }
262  const std::vector<libsumo::TraCIStage> result = libsumo::Simulation::findIntermodalRoute(from, to, modes, TIME2STEPS(depart), routingMode, speed, walkFactor, departPos, arrivalPos, departPosLat, ptype, vtype);
264  tempMsg.writeInt((int)result.size());
265  for (const libsumo::TraCIStage s : result) {
266  writeStage(tempMsg, s);
267  }
268  break;
269  }
270  case VAR_BUS_STOP_WAITING: {
272  if (s == 0) {
273  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Unknown bus stop '" + id + "'.", outputStorage);
274  }
276  tempMsg.writeInt(s->getTransportableNumber());
277  break;
278  }
279  case VAR_PARAMETER: {
280  std::string paramName = "";
281  if (!server.readTypeCheckingString(inputStorage, paramName)) {
282  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
283  }
285  tempMsg.writeString(libsumo::Simulation::getParameter(id, paramName));
286  }
287  break;
288  }
289  } catch (libsumo::TraCIException& e) {
290  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
291  }
292  server.writeStatusCmd(CMD_GET_SIM_VARIABLE, RTYPE_OK, "", outputStorage);
293  server.writeResponseWithLength(outputStorage, tempMsg);
294  return true;
295 }
296 
297 
298 bool
300  tcpip::Storage& outputStorage) {
301  std::string warning = ""; // additional description for response
302  // variable
303  int variable = inputStorage.readUnsignedByte();
304  if (variable != CMD_CLEAR_PENDING_VEHICLES
305  && variable != CMD_SAVE_SIMSTATE) {
306  return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "Set Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
307  }
308  // id
309  std::string id = inputStorage.readString();
310  // process
311  try {
312  switch (variable) {
314  //clear any pending vehicle insertions
315  std::string route;
316  if (!server.readTypeCheckingString(inputStorage, route)) {
317  return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "A string is needed for clearing pending vehicles.", outputStorage);
318  }
320  }
321  break;
322  case CMD_SAVE_SIMSTATE: {
323  //save current simulation state
324  std::string file;
325  if (!server.readTypeCheckingString(inputStorage, file)) {
326  return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "A string is needed for saving simulation state.", outputStorage);
327  }
328  MSStateHandler::saveState(file, MSNet::getInstance()->getCurrentTimeStep());
329  }
330  break;
331  default:
332  break;
333  }
334  } catch (libsumo::TraCIException& e) {
335  return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
336  }
337  server.writeStatusCmd(CMD_SET_SIM_VARIABLE, RTYPE_OK, warning, outputStorage);
338  return true;
339 }
340 
341 
342 void
344  const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
345  outputStorage.writeUnsignedByte(TYPE_INTEGER);
346  outputStorage.writeInt((int) ids.size());
347 }
348 
349 
350 void
352  const std::vector<std::string>& ids = server.getVehicleStateChanges().find(state)->second;
353  outputStorage.writeUnsignedByte(TYPE_STRINGLIST);
354  outputStorage.writeStringList(ids);
355 }
356 
357 
358 void
360  outputStorage.writeUnsignedByte(TYPE_COMPOUND);
361  outputStorage.writeInt(6);
362  outputStorage.writeUnsignedByte(TYPE_INTEGER);
363  outputStorage.writeInt(stage.type);
364  outputStorage.writeUnsignedByte(TYPE_STRING);
365  outputStorage.writeString(stage.line);
366  outputStorage.writeUnsignedByte(TYPE_STRING);
367  outputStorage.writeString(stage.destStop);
368  outputStorage.writeUnsignedByte(TYPE_STRINGLIST);
369  outputStorage.writeStringList(stage.edges);
370  outputStorage.writeUnsignedByte(TYPE_DOUBLE);
371  outputStorage.writeDouble(stage.travelTime);
372  outputStorage.writeUnsignedByte(TYPE_DOUBLE);
373  outputStorage.writeDouble(stage.cost);
374 }
375 
376 
377 std::pair<MSLane*, double>
379  std::pair<MSLane*, double> result;
380  std::vector<std::string> allEdgeIds;
381  double minDistance = std::numeric_limits<double>::max();
382 
383  allEdgeIds = MSNet::getInstance()->getEdgeControl().getEdgeNames();
384  for (std::vector<std::string>::iterator itId = allEdgeIds.begin(); itId != allEdgeIds.end(); itId++) {
385  const std::vector<MSLane*>& allLanes = MSEdge::dictionary((*itId))->getLanes();
386  for (std::vector<MSLane*>::const_iterator itLane = allLanes.begin(); itLane != allLanes.end(); itLane++) {
387  const double newDistance = (*itLane)->getShape().distance2D(pos);
388  if (newDistance < minDistance) {
389  minDistance = newDistance;
390  result.first = (*itLane);
391  }
392  }
393  }
394  // @todo this may be a place where 3D is required but 2D is delivered
395  result.second = result.first->getShape().nearest_offset_to_point2D(pos, false);
396  return result;
397 }
398 
399 
400 bool
402  tcpip::Storage& outputStorage, int commandId) {
403  std::pair<MSLane*, double> roadPos;
404  Position cartesianPos;
405  Position geoPos;
406  double z = 0;
407 
408  // actual position type that will be converted
409  int srcPosType = inputStorage.readUnsignedByte();
410 
411  switch (srcPosType) {
412  case POSITION_2D:
413  case POSITION_3D:
414  case POSITION_LON_LAT:
415  case POSITION_LON_LAT_ALT: {
416  double x = inputStorage.readDouble();
417  double y = inputStorage.readDouble();
418  if (srcPosType != POSITION_2D && srcPosType != POSITION_LON_LAT) {
419  z = inputStorage.readDouble();
420  }
421  geoPos.set(x, y);
422  cartesianPos.set(x, y);
423  if (srcPosType == POSITION_LON_LAT || srcPosType == POSITION_LON_LAT_ALT) {
425  } else {
427  }
428  }
429  break;
430  case POSITION_ROADMAP: {
431  std::string roadID = inputStorage.readString();
432  double pos = inputStorage.readDouble();
433  int laneIdx = inputStorage.readUnsignedByte();
434  try {
435  // convert edge,offset,laneIdx to cartesian position
436  cartesianPos = geoPos = libsumo::Helper::getLaneChecking(roadID, laneIdx, pos)->getShape().positionAtOffset(pos);
437  z = cartesianPos.z();
439  } catch (libsumo::TraCIException& e) {
440  server.writeStatusCmd(commandId, RTYPE_ERR, e.what());
441  return false;
442  }
443  }
444  break;
445  default:
446  server.writeStatusCmd(commandId, RTYPE_ERR, "Source position type not supported");
447  return false;
448  }
449 
450  int destPosType = 0;
451  if (!server.readTypeCheckingUnsignedByte(inputStorage, destPosType)) {
452  server.writeStatusCmd(commandId, RTYPE_ERR, "Destination position type must be of type ubyte.");
453  return false;
454  }
455 
456  switch (destPosType) {
457  case POSITION_ROADMAP: {
458  // convert cartesion position to edge,offset,lane_index
459  roadPos = convertCartesianToRoadMap(cartesianPos);
460  // write result that is added to response msg
461  outputStorage.writeUnsignedByte(POSITION_ROADMAP);
462  outputStorage.writeString(roadPos.first->getEdge().getID());
463  outputStorage.writeDouble(roadPos.second);
464  const std::vector<MSLane*> lanes = roadPos.first->getEdge().getLanes();
465  outputStorage.writeUnsignedByte((int)distance(lanes.begin(), find(lanes.begin(), lanes.end(), roadPos.first)));
466  }
467  break;
468  case POSITION_2D:
469  case POSITION_3D:
470  case POSITION_LON_LAT:
472  outputStorage.writeUnsignedByte(destPosType);
473  if (destPosType == POSITION_LON_LAT || destPosType == POSITION_LON_LAT_ALT) {
474  outputStorage.writeDouble(geoPos.x());
475  outputStorage.writeDouble(geoPos.y());
476  } else {
477  outputStorage.writeDouble(cartesianPos.x());
478  outputStorage.writeDouble(cartesianPos.y());
479  }
480  if (destPosType != POSITION_2D && destPosType != POSITION_LON_LAT) {
481  outputStorage.writeDouble(z);
482  }
483  break;
484  default:
485  server.writeStatusCmd(commandId, RTYPE_ERR, "Destination position type not supported");
486  return false;
487  }
488  return true;
489 }
490 
491 /****************************************************************************/
492 
493 bool
495  tcpip::Storage& outputStorage, int commandId) {
496  Position pos1;
497  Position pos2;
498  std::pair<const MSLane*, double> roadPos1;
499  std::pair<const MSLane*, double> roadPos2;
500 
501  // read position 1
502  int posType = inputStorage.readUnsignedByte();
503  switch (posType) {
504  case POSITION_ROADMAP:
505  try {
506  std::string roadID = inputStorage.readString();
507  roadPos1.second = inputStorage.readDouble();
508  roadPos1.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos1.second);
509  pos1 = roadPos1.first->getShape().positionAtOffset(roadPos1.second);
510  } catch (libsumo::TraCIException& e) {
511  server.writeStatusCmd(commandId, RTYPE_ERR, e.what());
512  return false;
513  }
514  break;
515  case POSITION_2D:
516  case POSITION_3D: {
517  double p1x = inputStorage.readDouble();
518  double p1y = inputStorage.readDouble();
519  pos1.set(p1x, p1y);
520  }
521  if (posType == POSITION_3D) {
522  inputStorage.readDouble();// z value is ignored
523  }
524  roadPos1 = convertCartesianToRoadMap(pos1);
525  break;
526  default:
527  server.writeStatusCmd(commandId, RTYPE_ERR, "Unknown position format used for distance request");
528  return false;
529  }
530 
531  // read position 2
532  posType = inputStorage.readUnsignedByte();
533  switch (posType) {
534  case POSITION_ROADMAP:
535  try {
536  std::string roadID = inputStorage.readString();
537  roadPos2.second = inputStorage.readDouble();
538  roadPos2.first = libsumo::Helper::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos2.second);
539  pos2 = roadPos2.first->getShape().positionAtOffset(roadPos2.second);
540  } catch (libsumo::TraCIException& e) {
541  server.writeStatusCmd(commandId, RTYPE_ERR, e.what());
542  return false;
543  }
544  break;
545  case POSITION_2D:
546  case POSITION_3D: {
547  double p2x = inputStorage.readDouble();
548  double p2y = inputStorage.readDouble();
549  pos2.set(p2x, p2y);
550  }
551  if (posType == POSITION_3D) {
552  inputStorage.readDouble();// z value is ignored
553  }
554  roadPos2 = convertCartesianToRoadMap(pos2);
555  break;
556  default:
557  server.writeStatusCmd(commandId, RTYPE_ERR, "Unknown position format used for distance request");
558  return false;
559  }
560 
561  // read distance type
562  int distType = inputStorage.readUnsignedByte();
563 
564  double distance = 0.0;
565  if (distType == REQUEST_DRIVINGDIST) {
566  // compute driving distance
567  if ((roadPos1.first == roadPos2.first) && (roadPos1.second <= roadPos2.second)) {
568  // same edge
569  distance = roadPos2.second - roadPos1.second;
570  } else {
571  ConstMSEdgeVector newRoute;
572  if (roadPos2.first->isInternal()) {
573  distance = roadPos2.second;
574  roadPos2.first = roadPos2.first->getLogicalPredecessorLane();
575  roadPos2.second = roadPos2.first->getLength();
576  }
578  &roadPos1.first->getEdge(), &roadPos2.first->getEdge(), 0, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
579  MSRoute route("", newRoute, false, 0, std::vector<SUMOVehicleParameter::Stop>());
580  distance += route.getDistanceBetween(roadPos1.second, roadPos2.second, &roadPos1.first->getEdge(), &roadPos2.first->getEdge());
581  }
582  } else {
583  // compute air distance (default)
584  distance = pos1.distanceTo(pos2);
585  }
586  // write response command
587  outputStorage.writeUnsignedByte(TYPE_DOUBLE);
588  outputStorage.writeDouble(distance);
589  return true;
590 }
591 
592 
593 #endif
594 
595 /****************************************************************************/
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:486
#define CMD_CLEAR_PENDING_VEHICLES
#define VAR_TIME_STEP
int type
The type of stage (walking, driving, ...)
Definition: TraCIDefs.h:212
#define REQUEST_DRIVINGDIST
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:214
double z() const
Returns the z-position.
Definition: Position.h:72
#define TYPE_COMPOUND
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:863
#define POSITION_2D
A lane area vehicles can halt at.
#define VAR_PARKING_STARTING_VEHICLES_IDS
#define VAR_STOP_ENDING_VEHICLES_IDS
#define VAR_PARKING_ENDING_VEHICLES_NUMBER
static void writeStage(tcpip::Storage &outputStorage, const libsumo::TraCIStage &stage)
#define POSITION_LON_LAT_ALT
std::string destStop
The id of the destination stop.
Definition: TraCIDefs.h:216
double y() const
Returns the y-position.
Definition: Position.h:67
#define RTYPE_OK
#define POSITION_ROADMAP
#define DISTANCE_REQUEST
virtual double readDouble()
static SUMOTime getCurrentTime()
Definition: Simulation.cpp:126
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:280
double x() const
Returns the x-position.
Definition: Position.h:62
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
A 3D-bounding box.
Definition: TraCIDefs.h:90
#define VAR_LOADED_VEHICLES_IDS
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:167
static std::string getParameter(const std::string &objectID, const std::string &key)
Definition: Simulation.cpp:275
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
#define TYPE_STRINGLIST
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:439
#define RESPONSE_GET_SIM_VARIABLE
#define POSITION_3D
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:744
#define VAR_TELEPORT_STARTING_VEHICLES_IDS
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
int getTransportableNumber() const
Returns the number of transportables waiting on this stop.
static TraCIStage findRoute(const std::string &from, const std::string &to, const std::string &typeID, const SUMOTime depart, const int routingMode)
Definition: Simulation.cpp:158
virtual void writeUnsignedByte(int)
void set(double x, double y)
set positions x and y
Definition: Position.h:92
#define POSITION_LON_LAT
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
#define VAR_LOADED_VEHICLES_NUMBER
double cost
effort needed
Definition: TraCIDefs.h:222
#define VAR_STOP_STARTING_VEHICLES_NUMBER
static void writeVehicleStateNumber(TraCIServer &server, tcpip::Storage &outputStorage, MSNet::VehicleState state)
virtual void writeInt(int)
#define TYPE_STRING
virtual int readUnsignedByte()
std::vector< std::string > getEdgeNames() const
Returns the list of names of all known edges.
The vehicles starts to stop.
Definition: MSNet.h:500
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
#define POSITION_CONVERSION
#define CMD_SAVE_SIMSTATE
#define VAR_DEPARTED_VEHICLES_NUMBER
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcb: Set Simulation Variable)
#define VAR_MIN_EXPECTED_VEHICLES
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:492
The vehicles starts to park.
Definition: MSNet.h:496
virtual int readInt()
#define VAR_STOP_STARTING_VEHICLES_IDS
#define VAR_NET_BOUNDING_BOX
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
std::vector< std::string > edges
The sequence of edges to travel.
Definition: TraCIDefs.h:218
#define VAR_TELEPORT_STARTING_VEHICLES_NUMBER
#define TYPE_BOUNDINGBOX
virtual void writeStringList(const std::vector< std::string > &s)
static bool commandPositionConversion(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, int commandId)
#define VAR_TELEPORT_ENDING_VEHICLES_IDS
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:253
#define FIND_ROUTE
The vehicle started to teleport.
Definition: MSNet.h:488
#define CMD_GET_SIM_VARIABLE
virtual std::string readString()
#define VAR_DEPARTED_VEHICLES_IDS
void clearPendingVehicles(std::string &route)
clears out all pending vehicles from a route, "" for all routes
The vehicle ends to park.
Definition: MSNet.h:498
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
#define VAR_DELTA_T
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:69
#define CMD_SET_SIM_VARIABLE
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:482
static bool commandDistanceRequest(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, int commandId)
The vehicle was built, but has not yet departed.
Definition: MSNet.h:484
#define VAR_ARRIVED_VEHICLES_NUMBER
static TraCIBoundary getNetBoundary()
Definition: Simulation.cpp:138
virtual void writeString(const std::string &s)
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:65
#define VAR_STOP_ENDING_VEHICLES_NUMBER
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:359
const std::map< MSNet::VehicleState, std::vector< std::string > > & getVehicleStateChanges() const
Definition: TraCIServer.h:154
double travelTime
duration of the stage
Definition: TraCIDefs.h:220
#define VAR_PARKING_ENDING_VEHICLES_IDS
The vehicle ends to stop.
Definition: MSNet.h:502
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
static std::vector< TraCIStage > findIntermodalRoute(const std::string &from, const std::string &to, const std::string &modes, const SUMOTime depart, const int routingMode, const double speed, const double walkFactor, const double departPos, const double arrivalPos, const double departPosLat, const std::string &pType, const std::string &vehType)
Definition: Simulation.cpp:194
static std::pair< MSLane *, double > convertCartesianToRoadMap(Position pos)
virtual void writeDouble(double)
#define VAR_TELEPORT_ENDING_VEHICLES_NUMBER
static int getMinExpectedNumber()
Definition: Simulation.cpp:152
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:239
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:349
#define VAR_PARKING_STARTING_VEHICLES_NUMBER
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:897
#define VAR_PARAMETER
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition: Helper.cpp:175
#define RTYPE_ERR
#define TYPE_INTEGER
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static SUMOTime getDeltaT()
Definition: Simulation.cpp:132
#define VAR_ARRIVED_VEHICLES_IDS
The vehicle ended being teleported.
Definition: MSNet.h:490
#define FIND_INTERMODAL_ROUTE
#define VAR_BUS_STOP_WAITING
static void saveState(const std::string &file, SUMOTime step)
Saves the current state.