SUMO - Simulation of Urban MObility
TraCIServerAPI_Vehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
13 // APIs for getting/setting vehicle values via TraCI
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
16 // Copyright (C) 2009-2016 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #ifndef NO_TRACI
38 
39 #include <microsim/MSNet.h>
41 #include <microsim/MSVehicle.h>
42 #include <microsim/MSLane.h>
43 #include <microsim/MSEdge.h>
45 #include <microsim/MSGlobals.h>
53 #include "TraCIConstants.h"
55 #include "TraCIServerAPI_Vehicle.h"
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif // CHECK_MEMORY_LEAKS
61 
62 //#define DEBUG_VTD 1
63 //#define DEBUG_VTD_ANGLE 1
64 
65 
66 // ===========================================================================
67 // static member variables
68 // ===========================================================================
69 std::map<std::string, std::vector<MSLane*> > TraCIServerAPI_Vehicle::gVTDMap;
70 
71 
72 // ===========================================================================
73 // method definitions
74 // ===========================================================================
75 bool
77  tcpip::Storage& outputStorage) {
78  // variable & id
79  int variable = inputStorage.readUnsignedByte();
80  std::string id = inputStorage.readString();
81  // check variable
82  if (variable != ID_LIST && variable != VAR_SPEED && variable != VAR_SPEED_WITHOUT_TRACI
83  && variable != VAR_POSITION && variable != VAR_ANGLE && variable != VAR_POSITION3D
84  && variable != VAR_ROAD_ID && variable != VAR_LANE_ID && variable != VAR_LANE_INDEX
85  && variable != VAR_TYPE && variable != VAR_ROUTE_ID && variable != VAR_COLOR
86  && variable != VAR_LANEPOSITION
87  && variable != VAR_CO2EMISSION && variable != VAR_COEMISSION
88  && variable != VAR_HCEMISSION && variable != VAR_PMXEMISSION
89  && variable != VAR_NOXEMISSION && variable != VAR_FUELCONSUMPTION && variable != VAR_NOISEEMISSION
90  && variable != VAR_ELECTRICITYCONSUMPTION && variable != VAR_PERSON_NUMBER && variable != VAR_LEADER
91  && variable != VAR_EDGE_TRAVELTIME && variable != VAR_EDGE_EFFORT
92  && variable != VAR_ROUTE_VALID && variable != VAR_EDGES
93  && variable != VAR_SIGNALS && variable != VAR_DISTANCE
94  && variable != VAR_LENGTH && variable != VAR_MAXSPEED && variable != VAR_VEHICLECLASS
95  && variable != VAR_SPEED_FACTOR && variable != VAR_SPEED_DEVIATION
96  && variable != VAR_ALLOWED_SPEED && variable != VAR_EMISSIONCLASS
97  && variable != VAR_WIDTH && variable != VAR_MINGAP && variable != VAR_SHAPECLASS
98  && variable != VAR_ACCEL && variable != VAR_DECEL && variable != VAR_IMPERFECTION
99  && variable != VAR_TAU && variable != VAR_BEST_LANES && variable != DISTANCE_REQUEST
100  && variable != ID_COUNT && variable != VAR_STOPSTATE && variable != VAR_WAITING_TIME
101  && variable != VAR_ROUTE_INDEX
102  && variable != VAR_PARAMETER
103  && variable != VAR_SPEEDSETMODE
104  && variable != VAR_NEXT_TLS
105  && variable != VAR_SLOPE
106  ) {
107  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Get Vehicle Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
108  }
109  // begin response building
110  tcpip::Storage tempMsg;
111  // response-code, variableID, objectID
113  tempMsg.writeUnsignedByte(variable);
114  tempMsg.writeString(id);
115  // process request
116  if (variable == ID_LIST || variable == ID_COUNT) {
117  std::vector<std::string> ids;
119  for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
120  if ((*i).second->isOnRoad() || (*i).second->isParking()) {
121  ids.push_back((*i).first);
122  }
123  }
124  if (variable == ID_LIST) {
126  tempMsg.writeStringList(ids);
127  } else {
129  tempMsg.writeInt((int) ids.size());
130  }
131  } else {
133  if (sumoVehicle == 0) {
134  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not known", outputStorage);
135  }
136  MSVehicle* v = dynamic_cast<MSVehicle*>(sumoVehicle);
137  if (v == 0) {
138  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not a micro-simulation vehicle", outputStorage);
139  }
140  const bool onRoad = v->isOnRoad();
141  const bool visible = onRoad || v->isParking();
142  switch (variable) {
143  case VAR_SPEED:
145  tempMsg.writeDouble(visible ? v->getSpeed() : INVALID_DOUBLE_VALUE);
146  break;
150  break;
151  case VAR_POSITION:
153  tempMsg.writeDouble(visible ? v->getPosition().x() : INVALID_DOUBLE_VALUE);
154  tempMsg.writeDouble(visible ? v->getPosition().y() : INVALID_DOUBLE_VALUE);
155  break;
156  case VAR_POSITION3D:
158  tempMsg.writeDouble(visible ? v->getPosition().x() : INVALID_DOUBLE_VALUE);
159  tempMsg.writeDouble(visible ? v->getPosition().y() : INVALID_DOUBLE_VALUE);
160  tempMsg.writeDouble(visible ? v->getPosition().z() : INVALID_DOUBLE_VALUE);
161  break;
162  case VAR_ANGLE:
165  break;
166  case VAR_SLOPE:
168  tempMsg.writeDouble(onRoad ? v->getSlope() : INVALID_DOUBLE_VALUE);
169  break;
170  case VAR_ROAD_ID:
172  tempMsg.writeString(visible ? v->getLane()->getEdge().getID() : "");
173  break;
174  case VAR_LANE_ID:
176  tempMsg.writeString(onRoad ? v->getLane()->getID() : "");
177  break;
178  case VAR_LANE_INDEX:
180  if (onRoad) {
181  const std::vector<MSLane*>& lanes = v->getLane()->getEdge().getLanes();
182  tempMsg.writeInt((int)std::distance(lanes.begin(), std::find(lanes.begin(), lanes.end(), v->getLane())));
183  } else {
184  tempMsg.writeInt(INVALID_INT_VALUE);
185  }
186  break;
187  case VAR_TYPE:
189  tempMsg.writeString(v->getVehicleType().getID());
190  break;
191  case VAR_ROUTE_ID:
193  tempMsg.writeString(v->getRoute().getID());
194  break;
195  case VAR_ROUTE_INDEX:
197  if (v->hasDeparted()) {
198  tempMsg.writeInt((int)v->getRoutePosition());
199  } else {
200  tempMsg.writeInt(INVALID_INT_VALUE);
201  }
202  break;
203  case VAR_COLOR:
204  tempMsg.writeUnsignedByte(TYPE_COLOR);
205  tempMsg.writeUnsignedByte(v->getParameter().color.red());
206  tempMsg.writeUnsignedByte(v->getParameter().color.green());
207  tempMsg.writeUnsignedByte(v->getParameter().color.blue());
208  tempMsg.writeUnsignedByte(v->getParameter().color.alpha());
209  break;
210  case VAR_LANEPOSITION:
212  tempMsg.writeDouble(onRoad ? v->getPositionOnLane() : INVALID_DOUBLE_VALUE);
213  break;
214  case VAR_CO2EMISSION:
216  tempMsg.writeDouble(visible ? v->getCO2Emissions() : INVALID_DOUBLE_VALUE);
217  break;
218  case VAR_COEMISSION:
220  tempMsg.writeDouble(visible ? v->getCOEmissions() : INVALID_DOUBLE_VALUE);
221  break;
222  case VAR_HCEMISSION:
224  tempMsg.writeDouble(visible ? v->getHCEmissions() : INVALID_DOUBLE_VALUE);
225  break;
226  case VAR_PMXEMISSION:
228  tempMsg.writeDouble(visible ? v->getPMxEmissions() : INVALID_DOUBLE_VALUE);
229  break;
230  case VAR_NOXEMISSION:
232  tempMsg.writeDouble(visible ? v->getNOxEmissions() : INVALID_DOUBLE_VALUE);
233  break;
234  case VAR_FUELCONSUMPTION:
236  tempMsg.writeDouble(visible ? v->getFuelConsumption() : INVALID_DOUBLE_VALUE);
237  break;
238  case VAR_NOISEEMISSION:
241  break;
245  break;
246  case VAR_PERSON_NUMBER:
248  tempMsg.writeInt(v->getPersonNumber());
249  break;
250  case VAR_LEADER: {
251  double dist = 0;
252  if (!server.readTypeCheckingDouble(inputStorage, dist)) {
253  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Leader retrieval requires a double.", outputStorage);
254  }
255  std::pair<const MSVehicle* const, SUMOReal> leaderInfo = v->getLeader(dist);
257  tempMsg.writeInt(2);
259  tempMsg.writeString(leaderInfo.first != 0 ? leaderInfo.first->getID() : "");
261  tempMsg.writeDouble(leaderInfo.second);
262  }
263  break;
264  case VAR_WAITING_TIME:
266  tempMsg.writeDouble(v->getWaitingSeconds());
267  break;
268  case VAR_EDGE_TRAVELTIME: {
269  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
270  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires a compound object.", outputStorage);
271  }
272  if (inputStorage.readInt() != 2) {
273  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires time, and edge as parameter.", outputStorage);
274  }
275  // time
276  int time = 0;
277  if (!server.readTypeCheckingInt(inputStorage, time)) {
278  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires the referenced time as first parameter.", outputStorage);
279  }
280  // edge
281  std::string edgeID;
282  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
283  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires the referenced edge as second parameter.", outputStorage);
284  }
285  MSEdge* edge = MSEdge::dictionary(edgeID);
286  if (edge == 0) {
287  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
288  }
289  // retrieve
291  SUMOReal value;
292  if (!v->getWeightsStorage().retrieveExistingTravelTime(edge, time, value)) {
294  } else {
295  tempMsg.writeDouble(value);
296  }
297 
298  }
299  break;
300  case VAR_EDGE_EFFORT: {
301  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
302  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires a compound object.", outputStorage);
303  }
304  if (inputStorage.readInt() != 2) {
305  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires time, and edge as parameter.", outputStorage);
306  }
307  // time
308  int time = 0;
309  if (!server.readTypeCheckingInt(inputStorage, time)) {
310  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of effort requires the referenced time as first parameter.", outputStorage);
311  }
312  // edge
313  std::string edgeID;
314  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
315  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of effort requires the referenced edge as second parameter.", outputStorage);
316  }
317  MSEdge* edge = MSEdge::dictionary(edgeID);
318  if (edge == 0) {
319  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
320  }
321  // retrieve
323  SUMOReal value;
324  if (!v->getWeightsStorage().retrieveExistingEffort(edge, time, value)) {
326  } else {
327  tempMsg.writeDouble(value);
328  }
329 
330  }
331  break;
332  case VAR_ROUTE_VALID: {
333  std::string msg;
334  tempMsg.writeUnsignedByte(TYPE_UBYTE);
335  tempMsg.writeUnsignedByte(v->hasValidRoute(msg));
336  }
337  break;
338  case VAR_EDGES: {
339  const MSRoute& r = v->getRoute();
341  tempMsg.writeInt(r.size());
342  for (MSRouteIterator i = r.begin(); i != r.end(); ++i) {
343  tempMsg.writeString((*i)->getID());
344  }
345  }
346  break;
347  case VAR_SIGNALS:
349  tempMsg.writeInt(v->getSignals());
350  break;
351  case VAR_BEST_LANES: {
353  tcpip::Storage tempContent;
354  int cnt = 0;
355  tempContent.writeUnsignedByte(TYPE_INTEGER);
356  const std::vector<MSVehicle::LaneQ>& bestLanes = onRoad ? v->getBestLanes() : std::vector<MSVehicle::LaneQ>();
357  tempContent.writeInt((int) bestLanes.size());
358  ++cnt;
359  for (std::vector<MSVehicle::LaneQ>::const_iterator i = bestLanes.begin(); i != bestLanes.end(); ++i) {
360  const MSVehicle::LaneQ& lq = *i;
361  tempContent.writeUnsignedByte(TYPE_STRING);
362  tempContent.writeString(lq.lane->getID());
363  ++cnt;
364  tempContent.writeUnsignedByte(TYPE_DOUBLE);
365  tempContent.writeDouble(lq.length);
366  ++cnt;
367  tempContent.writeUnsignedByte(TYPE_DOUBLE);
368  tempContent.writeDouble(lq.nextOccupation);
369  ++cnt;
370  tempContent.writeUnsignedByte(TYPE_BYTE);
371  tempContent.writeByte(lq.bestLaneOffset);
372  ++cnt;
373  tempContent.writeUnsignedByte(TYPE_UBYTE);
374  lq.allowsContinuation ? tempContent.writeUnsignedByte(1) : tempContent.writeUnsignedByte(0);
375  ++cnt;
376  std::vector<std::string> bestContIDs;
377  for (std::vector<MSLane*>::const_iterator j = lq.bestContinuations.begin(); j != lq.bestContinuations.end(); ++j) {
378  if ((*j) != 0) {
379  bestContIDs.push_back((*j)->getID());
380  }
381  }
382  tempContent.writeUnsignedByte(TYPE_STRINGLIST);
383  tempContent.writeStringList(bestContIDs);
384  ++cnt;
385  }
386  tempMsg.writeInt((int) cnt);
387  tempMsg.writeStorage(tempContent);
388  }
389  break;
390  case VAR_NEXT_TLS: {
391  int cnt = 0; // number of elements in compound message
392  int tlsLinks = 0; // number of tls links within bestlanes range
393  tcpip::Storage tempContent;
394  if (onRoad) {
395  const MSLane* lane = v->getLane();
396  const std::vector<MSLane*>& bestLaneConts = v->getBestLanesContinuation(lane);
397  SUMOReal seen = v->getLane()->getLength() - v->getPositionOnLane();
398  int view = 1;
399  MSLinkCont::const_iterator link = MSLane::succLinkSec(*v, view, *lane, bestLaneConts);
400  while (!lane->isLinkEnd(link)) {
401  if (!lane->getEdge().isInternal()) {
402  if ((*link)->isTLSControlled()) {
403  tlsLinks++;
404  tempContent.writeUnsignedByte(TYPE_STRING);
405  tempContent.writeString((*link)->getTLLogic()->getID());
406  ++cnt;
407  tempContent.writeUnsignedByte(TYPE_INTEGER);
408  tempContent.writeInt((*link)->getTLIndex());
409  ++cnt;
410  tempContent.writeUnsignedByte(TYPE_DOUBLE);
411  tempContent.writeDouble(seen);
412  ++cnt;
413  tempContent.writeUnsignedByte(TYPE_BYTE);
414  tempContent.writeByte((*link)->getState());
415  ++cnt;
416  }
417  }
418  lane = (*link)->getViaLaneOrLane();
419  if (!lane->getEdge().isInternal()) {
420  view++;
421  }
422  seen += lane->getLength();
423  link = MSLane::succLinkSec(*v, view, *lane, bestLaneConts);
424  }
425  }
426  ++cnt; // tlsLinks, everyting else was already included
428  tempMsg.writeInt((int) cnt);
430  tempMsg.writeInt(tlsLinks);
431  tempMsg.writeStorage(tempContent);
432  }
433  break;
434  case VAR_STOPSTATE: {
435  char b = 0;
436  if (v->isStopped()) {
437  const MSVehicle::Stop& stop = v->getNextStop();
438  b = 1 + (stop.parking ? 2 : 0) +
439  (stop.triggered ? 4 : 0) +
440  (stop.containerTriggered ? 8 : 0) +
441  (stop.busstop != 0 ? 16 : 0) +
442  (stop.containerstop != 0 ? 32 : 0);
443  }
444  tempMsg.writeUnsignedByte(TYPE_UBYTE);
445  tempMsg.writeUnsignedByte(b);
446  }
447  break;
448  case VAR_DISTANCE: {
450  SUMOReal distance = onRoad ? v->getRoute().getDistanceBetween(v->getDepartPos(), v->getPositionOnLane(), v->getRoute().getEdges()[0], &v->getLane()->getEdge()) : INVALID_DOUBLE_VALUE;
451  if (distance == std::numeric_limits<SUMOReal>::max()) {
452  distance = INVALID_DOUBLE_VALUE;
453  }
454  tempMsg.writeDouble(distance);
455  }
456  break;
457  case DISTANCE_REQUEST:
458  if (!commandDistanceRequest(server, inputStorage, tempMsg, v)) {
459  return false;
460  }
461  break;
462  case VAR_ALLOWED_SPEED:
464  tempMsg.writeDouble(onRoad ? v->getLane()->getVehicleMaxSpeed(v) : INVALID_DOUBLE_VALUE);
465  break;
466  case VAR_SPEED_FACTOR:
468  tempMsg.writeDouble(v->getChosenSpeedFactor());
469  break;
470  case VAR_SPEEDSETMODE:
472  tempMsg.writeInt(v->getInfluencer().getSpeedMode());
473  break;
474  case VAR_PARAMETER: {
475  std::string paramName = "";
476  if (!server.readTypeCheckingString(inputStorage, paramName)) {
477  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
478  }
480  tempMsg.writeString(v->getParameter().getParameter(paramName, ""));
481  }
482  break;
483  default:
485  break;
486  }
487  }
488  server.writeStatusCmd(CMD_GET_VEHICLE_VARIABLE, RTYPE_OK, "", outputStorage);
489  server.writeResponseWithLength(outputStorage, tempMsg);
490  return true;
491 }
492 
493 
494 bool
496  tcpip::Storage& outputStorage) {
497  std::string warning = ""; // additional description for response
498  // variable
499  int variable = inputStorage.readUnsignedByte();
500  if (variable != CMD_STOP && variable != CMD_CHANGELANE
501  && variable != CMD_SLOWDOWN && variable != CMD_CHANGETARGET && variable != CMD_RESUME
502  && variable != VAR_TYPE && variable != VAR_ROUTE_ID && variable != VAR_ROUTE
503  && variable != VAR_EDGE_TRAVELTIME && variable != VAR_EDGE_EFFORT
504  && variable != CMD_REROUTE_TRAVELTIME && variable != CMD_REROUTE_EFFORT
505  && variable != VAR_SIGNALS && variable != VAR_MOVE_TO
506  && variable != VAR_LENGTH && variable != VAR_MAXSPEED && variable != VAR_VEHICLECLASS
507  && variable != VAR_SPEED_FACTOR && variable != VAR_EMISSIONCLASS
508  && variable != VAR_WIDTH && variable != VAR_MINGAP && variable != VAR_SHAPECLASS
509  && variable != VAR_ACCEL && variable != VAR_DECEL && variable != VAR_IMPERFECTION
510  && variable != VAR_TAU && variable != VAR_LANECHANGE_MODE
511  && variable != VAR_SPEED && variable != VAR_SPEEDSETMODE && variable != VAR_COLOR
512  && variable != ADD && variable != ADD_FULL && variable != REMOVE
513  && variable != VAR_MOVE_TO_VTD && variable != VAR_PARAMETER/* && variable != VAR_SPEED_TIME_LINE && variable != VAR_LANE_TIME_LINE*/
514  ) {
515  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Change Vehicle State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
516  }
517  // id
518  std::string id = inputStorage.readString();
519 #ifdef DEBUG_VTD
520  WRITE_MESSAGE("Processing " + id);
521 #endif
522  const bool shouldExist = variable != ADD && variable != ADD_FULL;
524  if (sumoVehicle == 0) {
525  if (shouldExist) {
526  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not known", outputStorage);
527  }
528  }
529  MSVehicle* v = dynamic_cast<MSVehicle*>(sumoVehicle);
530  if (v == 0 && shouldExist) {
531  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not a micro-simulation vehicle", outputStorage);
532  }
533  switch (variable) {
534  case CMD_STOP: {
535  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
536  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description.", outputStorage);
537  }
538  int compoundSize = inputStorage.readInt();
539  if (compoundSize < 4 || compoundSize > 7) {
540  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description of four to seven items.", outputStorage);
541  }
542  // read road map position
543  std::string roadId;
544  if (!server.readTypeCheckingString(inputStorage, roadId)) {
545  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first stop parameter must be the edge id given as a string.", outputStorage);
546  }
547  double pos = 0;
548  if (!server.readTypeCheckingDouble(inputStorage, pos)) {
549  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second stop parameter must be the end position along the edge given as a double.", outputStorage);
550  }
551  int laneIndex = 0;
552  if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
553  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The third stop parameter must be the lane index given as a byte.", outputStorage);
554  }
555  // waitTime
556  int waitTime = -1;
557  if (!server.readTypeCheckingInt(inputStorage, waitTime)) {
558  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "The fourth stop parameter must be the waiting time given as an integer.", outputStorage);
559  }
560  // optional stop flags
561  bool parking = false;
562  bool triggered = false;
563  bool containerTriggered = false;
564  bool isBusStop = false;
565  bool isContainerStop = false;
566  if (compoundSize >= 5) {
567  int stopFlags;
568  if (!server.readTypeCheckingByte(inputStorage, stopFlags)) {
569  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The fifth stop parameter must be a byte indicating its parking/triggered status.", outputStorage);
570  }
571  parking = ((stopFlags & 1) != 0);
572  triggered = ((stopFlags & 2) != 0);
573  containerTriggered = ((stopFlags & 4) != 0);
574  isBusStop = ((stopFlags & 8) != 0);
575  isContainerStop = ((stopFlags & 16) != 0);
576  }
577  double startPos = pos - POSITION_EPS;
578  if (compoundSize >= 6) {
579  double tmp;
580  if (!server.readTypeCheckingDouble(inputStorage, tmp)) {
581  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The sixth stop parameter must be the start position along the edge given as a double.", outputStorage);
582  }
583  if (tmp != INVALID_DOUBLE_VALUE) {
584  startPos = tmp;
585  }
586  }
587  int until = -1;
588  if (compoundSize >= 7) {
589  if (!server.readTypeCheckingInt(inputStorage, until)) {
590  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The seventh stop parameter must be the waiting end time given as integer.", outputStorage);
591  }
592  }
593  std::string error;
594  if (isBusStop || isContainerStop) {
595  // Forward command to vehicle
596  if (!v->addTraciBusOrContainerStop(roadId, waitTime, until, parking, triggered, containerTriggered, isContainerStop, error)) {
597  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
598  }
599  } else {
600  // check
601  if (startPos < 0) {
602  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Position on lane must not be negative.", outputStorage);
603  }
604  if (pos < startPos) {
605  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "End position on lane must be after start position.", outputStorage);
606  }
607  // get the actual lane that is referenced by laneIndex
608  MSEdge* road = MSEdge::dictionary(roadId);
609  if (road == 0) {
610  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Unable to retrieve road with given id.", outputStorage);
611  }
612  const std::vector<MSLane*>& allLanes = road->getLanes();
613  if ((laneIndex < 0) || laneIndex >= (int)(allLanes.size())) {
614  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "No lane with index '" + toString(laneIndex) + "' on road '" + roadId + "'.", outputStorage);
615  }
616  // Forward command to vehicle
617  if (!v->addTraciStop(allLanes[laneIndex], startPos, pos, waitTime, until, parking, triggered, containerTriggered, error)) {
618  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
619  }
620  }
621  }
622  break;
623  case CMD_RESUME: {
624  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
625  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_ERR, "Resuming requires a compound object.", outputStorage);
626  return false;
627  }
628  if (inputStorage.readInt() != 0) {
629  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_ERR, "Resuming should obtain an empty compound object.", outputStorage);
630  return false;
631  }
632  if (!static_cast<MSVehicle*>(v)->hasStops()) {
633  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_ERR, "Failed to resume vehicle '" + v->getID() + "', it has no stops.", outputStorage);
634  return false;
635  }
636  if (!static_cast<MSVehicle*>(v)->resumeFromStopping()) {
637  MSVehicle::Stop& sto = (static_cast<MSVehicle*>(v))->getNextStop();
638  std::ostringstream strs;
639  strs << "reached: " << sto.reached;
640  strs << ", duration:" << sto.duration;
641  strs << ", edge:" << (*sto.edge)->getID();
642  strs << ", startPos: " << sto.startPos;
643  std::string posStr = strs.str();
644  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_ERR, "Failed to resume a non parking vehicle '" + v->getID() + "', " + posStr, outputStorage);
645  return false;
646  }
647  }
648  break;
649  case CMD_CHANGELANE: {
650  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
651  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description.", outputStorage);
652  }
653  if (inputStorage.readInt() != 2) {
654  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description of two items.", outputStorage);
655  }
656  // Lane ID
657  int laneIndex = 0;
658  if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
659  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first lane change parameter must be the lane index given as a byte.", outputStorage);
660  }
661  // stickyTime
662  int stickyTime = 0;
663  if (!server.readTypeCheckingInt(inputStorage, stickyTime)) {
664  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second lane change parameter must be the duration given as an integer.", outputStorage);
665  }
666  if ((laneIndex < 0) || (laneIndex >= (int)(v->getEdge()->getLanes().size()))) {
667  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "No lane with index '" + toString(laneIndex) + "' on road '" + v->getEdge()->getID() + "'.", outputStorage);
668  }
669  // Forward command to vehicle
670  std::vector<std::pair<SUMOTime, int> > laneTimeLine;
671  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
672  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + stickyTime, laneIndex));
673  v->getInfluencer().setLaneTimeLine(laneTimeLine);
674  }
675  break;
676  /*
677  case VAR_LANE_TIME_LINE: {
678  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
679  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description.", outputStorage);
680  }
681  if (inputStorage.readInt() != 2) {
682  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description of two items.", outputStorage);
683  }
684  // Lane ID
685  int laneIndex = 0;
686  if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
687  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first lane change parameter must be the lane index given as a byte.", outputStorage);
688  }
689  // stickyTime
690  SUMOTime stickyTime = 0;
691  if (!server.readTypeCheckingInt(inputStorage, stickyTime)) {
692  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second lane change parameter must be the duration given as an integer.", outputStorage);
693  }
694  if ((laneIndex < 0) || (laneIndex >= (int)(v->getEdge()->getLanes().size()))) {
695  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "No lane existing with given id on the current road", outputStorage);
696  }
697  // Forward command to vehicle
698  std::vector<std::pair<SUMOTime, int> > laneTimeLine;
699  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
700  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + stickyTime, laneIndex));
701  v->getInfluencer().setLaneTimeLine(laneTimeLine);
702  MSVehicle::ChangeRequest req = v->getInfluencer().checkForLaneChanges(MSNet::getInstance()->getCurrentTimeStep(),
703  *v->getEdge(), v->getLaneIndex());
704  v->getLaneChangeModel().requestLaneChange(req);
705  }
706  break;
707  */
708  case CMD_SLOWDOWN: {
709  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
710  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description.", outputStorage);
711  }
712  if (inputStorage.readInt() != 2) {
713  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description of two items.", outputStorage);
714  }
715  double newSpeed = 0;
716  if (!server.readTypeCheckingDouble(inputStorage, newSpeed)) {
717  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first slow down parameter must be the speed given as a double.", outputStorage);
718  }
719  if (newSpeed < 0) {
720  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Speed must not be negative", outputStorage);
721  }
722  int duration = 0;
723  if (!server.readTypeCheckingInt(inputStorage, duration)) {
724  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second slow down parameter must be the duration given as an integer.", outputStorage);
725  }
726  if (duration < 0 || STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()) + STEPS2TIME(duration) > STEPS2TIME(SUMOTime_MAX - DELTA_T)) {
727  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid time interval", outputStorage);
728  }
729  std::vector<std::pair<SUMOTime, SUMOReal> > speedTimeLine;
730  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), v->getSpeed()));
731  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + duration, newSpeed));
732  v->getInfluencer().setSpeedTimeLine(speedTimeLine);
733  }
734  break;
735  case CMD_CHANGETARGET: {
736  std::string edgeID;
737  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
738  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Change target requires a string containing the id of the new destination edge as parameter.", outputStorage);
739  }
740  const MSEdge* destEdge = MSEdge::dictionary(edgeID);
741  if (destEdge == 0) {
742  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Can not retrieve road with ID " + edgeID, outputStorage);
743  }
744  // build a new route between the vehicle's current edge and destination edge
745  ConstMSEdgeVector newRoute;
746  const MSEdge* currentEdge = v->getRerouteOrigin();
748  currentEdge, destEdge, (const MSVehicle * const) v, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
749  // replace the vehicle's route by the new one
750  if (!v->replaceRouteEdges(newRoute, v->getLane() == 0)) {
751  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Route replacement failed for " + v->getID(), outputStorage);
752  }
753  }
754  break;
755  case VAR_TYPE: {
756  std::string vTypeID;
757  if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
758  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle type id must be given as a string.", outputStorage);
759  }
760  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(vTypeID);
761  if (vehicleType == 0) {
762  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle type '" + vTypeID + "' is not known.", outputStorage);
763  }
764  v->replaceVehicleType(vehicleType);
765  }
766  break;
767  case VAR_ROUTE_ID: {
768  std::string rid;
769  if (!server.readTypeCheckingString(inputStorage, rid)) {
770  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The route id must be given as a string.", outputStorage);
771  }
772  const MSRoute* r = MSRoute::dictionary(rid);
773  if (r == 0) {
774  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The route '" + rid + "' is not known.", outputStorage);
775  }
776  std::string msg;
777  if (!v->hasValidRoute(msg, r)) {
778  WRITE_WARNING("Invalid route replacement for vehicle '" + v->getID() + "'. " + msg);
780  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Route replacement failed for " + v->getID(), outputStorage);
781  }
782  }
783 
784  if (!v->replaceRoute(r, v->getLane() == 0)) {
785  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Route replacement failed for " + v->getID(), outputStorage);
786  }
787  }
788  break;
789  case VAR_ROUTE: {
790  std::vector<std::string> edgeIDs;
791  if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
792  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "A route must be defined as a list of edge ids.", outputStorage);
793  }
794  ConstMSEdgeVector edges;
795  MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
796  if (!v->replaceRouteEdges(edges, v->getLane() == 0, true)) {
797  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Route replacement failed for " + v->getID(), outputStorage);
798  }
799  }
800  break;
801  case VAR_EDGE_TRAVELTIME: {
802  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
803  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires a compound object.", outputStorage);
804  }
805  int parameterCount = inputStorage.readInt();
806  if (parameterCount == 4) {
807  // begin time
808  int begTime = 0, endTime = 0;
809  if (!server.readTypeCheckingInt(inputStorage, begTime)) {
810  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the begin time as first parameter.", outputStorage);
811  }
812  // begin time
813  if (!server.readTypeCheckingInt(inputStorage, endTime)) {
814  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the end time as second parameter.", outputStorage);
815  }
816  // edge
817  std::string edgeID;
818  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
819  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the referenced edge as third parameter.", outputStorage);
820  }
821  MSEdge* edge = MSEdge::dictionary(edgeID);
822  if (edge == 0) {
823  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
824  }
825  // value
826  double value = 0;
827  if (!server.readTypeCheckingDouble(inputStorage, value)) {
828  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the travel time as double as fourth parameter.", outputStorage);
829  }
830  // retrieve
831  v->getWeightsStorage().addTravelTime(edge, begTime, endTime, value);
832  } else if (parameterCount == 2) {
833  // edge
834  std::string edgeID;
835  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
836  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the referenced edge as first parameter.", outputStorage);
837  }
838  MSEdge* edge = MSEdge::dictionary(edgeID);
839  if (edge == 0) {
840  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
841  }
842  // value
843  double value = 0;
844  if (!server.readTypeCheckingDouble(inputStorage, value)) {
845  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the travel time as second parameter.", outputStorage);
846  }
847  // retrieve
848  while (v->getWeightsStorage().knowsTravelTime(edge)) {
850  }
852  } else if (parameterCount == 1) {
853  // edge
854  std::string edgeID;
855  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
856  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 1 parameter requires the referenced edge as first parameter.", outputStorage);
857  }
858  MSEdge* edge = MSEdge::dictionary(edgeID);
859  if (edge == 0) {
860  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
861  }
862  // retrieve
863  while (v->getWeightsStorage().knowsTravelTime(edge)) {
865  }
866  } else {
867  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires 1, 2, or 4 parameters.", outputStorage);
868  }
869  }
870  break;
871  case VAR_EDGE_EFFORT: {
872  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
873  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort requires a compound object.", outputStorage);
874  }
875  int parameterCount = inputStorage.readInt();
876  if (parameterCount == 4) {
877  // begin time
878  int begTime = 0, endTime = 0;
879  if (!server.readTypeCheckingInt(inputStorage, begTime)) {
880  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the begin time as first parameter.", outputStorage);
881  }
882  // begin time
883  if (!server.readTypeCheckingInt(inputStorage, endTime)) {
884  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the end time as second parameter.", outputStorage);
885  }
886  // edge
887  std::string edgeID;
888  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
889  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the referenced edge as third parameter.", outputStorage);
890  }
891  MSEdge* edge = MSEdge::dictionary(edgeID);
892  if (edge == 0) {
893  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
894  }
895  // value
896  double value = 0;
897  if (!server.readTypeCheckingDouble(inputStorage, value)) {
898  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the travel time as fourth parameter.", outputStorage);
899  }
900  // retrieve
901  v->getWeightsStorage().addEffort(edge, begTime, endTime, value);
902  } else if (parameterCount == 2) {
903  // edge
904  std::string edgeID;
905  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
906  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the referenced edge as first parameter.", outputStorage);
907  }
908  MSEdge* edge = MSEdge::dictionary(edgeID);
909  if (edge == 0) {
910  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
911  }
912  // value
913  double value = 0;
914  if (!server.readTypeCheckingDouble(inputStorage, value)) {
915  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the travel time as second parameter.", outputStorage);
916  }
917  // retrieve
918  while (v->getWeightsStorage().knowsEffort(edge)) {
919  v->getWeightsStorage().removeEffort(edge);
920  }
921  v->getWeightsStorage().addEffort(edge, SUMOReal(0), SUMOReal(SUMOTime_MAX), value);
922  } else if (parameterCount == 1) {
923  // edge
924  std::string edgeID;
925  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
926  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 1 parameter requires the referenced edge as first parameter.", outputStorage);
927  }
928  MSEdge* edge = MSEdge::dictionary(edgeID);
929  if (edge == 0) {
930  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
931  }
932  // retrieve
933  while (v->getWeightsStorage().knowsEffort(edge)) {
934  v->getWeightsStorage().removeEffort(edge);
935  }
936  } else {
937  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort requires 1, 2, or 4 parameters.", outputStorage);
938  }
939  }
940  break;
941  case CMD_REROUTE_TRAVELTIME: {
942  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
943  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);
944  }
945  if (inputStorage.readInt() != 0) {
946  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
947  }
948  v->reroute(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getRouterTT());
949  }
950  break;
951  case CMD_REROUTE_EFFORT: {
952  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
953  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);
954  }
955  if (inputStorage.readInt() != 0) {
956  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
957  }
958  v->reroute(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getRouterEffort());
959  }
960  break;
961  case VAR_SIGNALS: {
962  int signals = 0;
963  if (!server.readTypeCheckingInt(inputStorage, signals)) {
964  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting signals requires an integer.", outputStorage);
965  }
966  v->switchOffSignal(0x0fffffff);
967  v->switchOnSignal(signals);
968  }
969  break;
970  case VAR_MOVE_TO: {
971  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
972  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting position requires a compound object.", outputStorage);
973  }
974  if (inputStorage.readInt() != 2) {
975  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting position should obtain the lane id and the position.", outputStorage);
976  }
977  // lane ID
978  std::string laneID;
979  if (!server.readTypeCheckingString(inputStorage, laneID)) {
980  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first parameter for setting a position must be the lane ID given as a string.", outputStorage);
981  }
982  // position on lane
983  double position = 0;
984  if (!server.readTypeCheckingDouble(inputStorage, position)) {
985  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second parameter for setting a position must be the position given as a double.", outputStorage);
986  }
987  // process
988  MSLane* l = MSLane::dictionary(laneID);
989  if (l == 0) {
990  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Unknown lane '" + laneID + "'.", outputStorage);
991  }
992  MSEdge& destinationEdge = l->getEdge();
993  if (!v->willPass(&destinationEdge)) {
994  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Vehicle '" + laneID + "' may be set onto an edge to pass only.", outputStorage);
995  }
997  if (v->getLane() != 0) {
999  } else {
1000  v->setTentativeLaneAndPosition(l, position);
1001  }
1002  while (v->getEdge() != &destinationEdge) {
1003  const MSEdge* nextEdge = v->succEdge(1);
1004  // let the vehicle move to the next edge
1005  if (v->enterLaneAtMove(nextEdge->getLanes()[0], true)) {
1007  continue;
1008  }
1009  }
1010  if (!v->isOnRoad()) {
1012 
1013  }
1015  }
1016  break;
1017  case VAR_SPEED: {
1018  double speed = 0;
1019  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
1020  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting speed requires a double.", outputStorage);
1021  }
1022  std::vector<std::pair<SUMOTime, SUMOReal> > speedTimeLine;
1023  if (speed >= 0) {
1024  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), speed));
1025  speedTimeLine.push_back(std::make_pair(SUMOTime_MAX - DELTA_T, speed));
1026  }
1027  v->getInfluencer().setSpeedTimeLine(speedTimeLine);
1028  }
1029  break;
1030  case VAR_SPEEDSETMODE: {
1031  int speedMode = 0;
1032  if (!server.readTypeCheckingInt(inputStorage, speedMode)) {
1033  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting speed mode requires an integer.", outputStorage);
1034  }
1035  v->getInfluencer().setConsiderSafeVelocity((speedMode & 1) != 0);
1036  v->getInfluencer().setConsiderMaxAcceleration((speedMode & 2) != 0);
1037  v->getInfluencer().setConsiderMaxDeceleration((speedMode & 4) != 0);
1038  v->getInfluencer().setRespectJunctionPriority((speedMode & 8) != 0);
1039  v->getInfluencer().setEmergencyBrakeRedLight((speedMode & 16) != 0);
1040  }
1041  break;
1042  case VAR_LANECHANGE_MODE: {
1043  int laneChangeMode = 0;
1044  if (!server.readTypeCheckingInt(inputStorage, laneChangeMode)) {
1045  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting lane change mode requires an integer.", outputStorage);
1046  }
1047  v->getInfluencer().setLaneChangeMode(laneChangeMode);
1048  }
1049  break;
1050  case VAR_COLOR: {
1051  RGBColor col;
1052  if (!server.readTypeCheckingColor(inputStorage, col)) {
1053  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The color must be given using the according type.", outputStorage);
1054  }
1055  v->getParameter().color.set(col.red(), col.green(), col.blue(), col.alpha());
1057  }
1058  break;
1059  case ADD: {
1060  if (v != 0) {
1061  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle " + id + " to add already exists.", outputStorage);
1062  }
1063  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
1064  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);
1065  }
1066  if (inputStorage.readInt() != 6) {
1067  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle needs six parameters.", outputStorage);
1068  }
1069  SUMOVehicleParameter vehicleParams;
1070  vehicleParams.id = id;
1071 
1072  std::string vTypeID;
1073  if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
1074  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);
1075  }
1076  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(vTypeID);
1077  if (!vehicleType) {
1078  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid type '" + vTypeID + "' for vehicle '" + id + "'", outputStorage);
1079  }
1080 
1081  std::string routeID;
1082  if (!server.readTypeCheckingString(inputStorage, routeID)) {
1083  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);
1084  }
1085  const MSRoute* route = MSRoute::dictionary(routeID);
1086  if (!route) {
1087  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid route '" + routeID + "' for vehicle: '" + id + "'", outputStorage);
1088  }
1089  int depart;
1090  if (!server.readTypeCheckingInt(inputStorage, depart)) {
1091  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Third parameter (depart) requires an integer.", outputStorage);
1092  }
1093  if (depart < 0) {
1094  const int proc = -depart;
1095  if (proc >= static_cast<int>(DEPART_DEF_MAX)) {
1096  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid departure time.", outputStorage);
1097  }
1098  vehicleParams.departProcedure = (DepartDefinition)proc;
1099  } else if (depart < MSNet::getInstance()->getCurrentTimeStep()) {
1100  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
1101  WRITE_WARNING("Departure time for vehicle '" + id + "' is in the past; using current time instead.");
1102  } else {
1103  vehicleParams.depart = depart;
1104  }
1105 
1106  double pos;
1107  if (!server.readTypeCheckingDouble(inputStorage, pos)) {
1108  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (position) requires a double.", outputStorage);
1109  }
1110  vehicleParams.departPos = pos;
1111  if (vehicleParams.departPos < 0) {
1112  const int proc = static_cast<int>(-vehicleParams.departPos);
1113  if (fabs(proc + vehicleParams.departPos) > NUMERICAL_EPS || proc >= static_cast<int>(DEPART_POS_DEF_MAX) || proc == static_cast<int>(DEPART_POS_GIVEN)) {
1114  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid departure position.", outputStorage);
1115  }
1116  vehicleParams.departPosProcedure = (DepartPosDefinition)proc;
1117  } else {
1118  vehicleParams.departPosProcedure = DEPART_POS_GIVEN;
1119  }
1120 
1121  double speed;
1122  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
1123  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (speed) requires a double.", outputStorage);
1124  }
1125  vehicleParams.departSpeed = speed;
1126  if (vehicleParams.departSpeed < 0) {
1127  const int proc = static_cast<int>(-vehicleParams.departSpeed);
1128  if (proc >= static_cast<int>(DEPART_SPEED_DEF_MAX)) {
1129  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid departure speed.", outputStorage);
1130  }
1131  vehicleParams.departSpeedProcedure = (DepartSpeedDefinition)proc;
1132  } else {
1133  vehicleParams.departSpeedProcedure = DEPART_SPEED_GIVEN;
1134  }
1135 
1136  if (!server.readTypeCheckingByte(inputStorage, vehicleParams.departLane)) {
1137  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (lane) requires a byte.", outputStorage);
1138  }
1139 
1140  if (vehicleParams.departLane < 0) {
1141  const int proc = static_cast<int>(-vehicleParams.departLane);
1142  if (proc >= static_cast<int>(DEPART_LANE_DEF_MAX)) {
1143  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid departure lane.", outputStorage);
1144  }
1145  vehicleParams.departLaneProcedure = (DepartLaneDefinition)proc;
1146  } else {
1147  vehicleParams.departLaneProcedure = DEPART_LANE_GIVEN;
1148  }
1149 
1150  SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
1151  try {
1152  SUMOVehicle* vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(params, route, vehicleType, true, false);
1153  MSNet::getInstance()->getVehicleControl().addVehicle(vehicleParams.id, vehicle);
1155  } catch (ProcessError& e) {
1156  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1157  }
1158  }
1159  break;
1160  case ADD_FULL: {
1161  if (v != 0) {
1162  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle " + id + " to add already exists.", outputStorage);
1163  }
1164  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
1165  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);
1166  }
1167  if (inputStorage.readInt() != 14) {
1168  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Adding a fully specified vehicle needs fourteen parameters.", outputStorage);
1169  }
1170  SUMOVehicleParameter vehicleParams;
1171  vehicleParams.id = id;
1172 
1173  std::string routeID;
1174  if (!server.readTypeCheckingString(inputStorage, routeID)) {
1175  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);
1176  }
1177  const MSRoute* route = MSRoute::dictionary(routeID);
1178  if (!route) {
1179  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid route '" + routeID + "' for vehicle: '" + id + "'", outputStorage);
1180  }
1181 
1182  std::string vTypeID;
1183  if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
1184  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);
1185  }
1186  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(vTypeID);
1187  if (!vehicleType) {
1188  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid type '" + vTypeID + "' for vehicle '" + id + "'", outputStorage);
1189  }
1190 
1191  std::string helper;
1192  std::string error;
1193  if (!server.readTypeCheckingString(inputStorage, helper)) {
1194  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Third parameter (depart) requires an string.", outputStorage);
1195  }
1196  if (!SUMOVehicleParameter::parseDepart(helper, "vehicle", id, vehicleParams.depart, vehicleParams.departProcedure, error)) {
1197  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1198  }
1199  if (vehicleParams.departProcedure == DEPART_GIVEN && vehicleParams.depart < MSNet::getInstance()->getCurrentTimeStep()) {
1200  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Departure time in the past.", outputStorage);
1201  }
1202 
1203  if (!server.readTypeCheckingString(inputStorage, helper)) {
1204  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (depart lane) requires a string.", outputStorage);
1205  }
1206  if (!SUMOVehicleParameter::parseDepartLane(helper, "vehicle", id, vehicleParams.departLane, vehicleParams.departLaneProcedure, error)) {
1207  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1208  }
1209  if (!server.readTypeCheckingString(inputStorage, helper)) {
1210  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (depart position) requires a string.", outputStorage);
1211  }
1212  if (!SUMOVehicleParameter::parseDepartPos(helper, "vehicle", id, vehicleParams.departPos, vehicleParams.departPosProcedure, error)) {
1213  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1214  }
1215  if (!server.readTypeCheckingString(inputStorage, helper)) {
1216  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (depart speed) requires a string.", outputStorage);
1217  }
1218  if (!SUMOVehicleParameter::parseDepartSpeed(helper, "vehicle", id, vehicleParams.departSpeed, vehicleParams.departSpeedProcedure, error)) {
1219  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1220  }
1221 
1222  if (!server.readTypeCheckingString(inputStorage, helper)) {
1223  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Seventh parameter (arrival lane) requires a string.", outputStorage);
1224  }
1225  if (!SUMOVehicleParameter::parseArrivalLane(helper, "vehicle", id, vehicleParams.arrivalLane, vehicleParams.arrivalLaneProcedure, error)) {
1226  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1227  }
1228  if (!server.readTypeCheckingString(inputStorage, helper)) {
1229  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Eighth parameter (arrival position) requires a string.", outputStorage);
1230  }
1231  if (!SUMOVehicleParameter::parseArrivalPos(helper, "vehicle", id, vehicleParams.arrivalPos, vehicleParams.arrivalPosProcedure, error)) {
1232  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1233  }
1234  if (!server.readTypeCheckingString(inputStorage, helper)) {
1235  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Ninth parameter (arrival speed) requires a string.", outputStorage);
1236  }
1237  if (!SUMOVehicleParameter::parseArrivalSpeed(helper, "vehicle", id, vehicleParams.arrivalSpeed, vehicleParams.arrivalSpeedProcedure, error)) {
1238  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1239  }
1240 
1241  if (!server.readTypeCheckingString(inputStorage, vehicleParams.fromTaz)) {
1242  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Tenth parameter (from taz) requires a string.", outputStorage);
1243  }
1244  if (!server.readTypeCheckingString(inputStorage, vehicleParams.toTaz)) {
1245  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Eleventh parameter (to taz) requires a string.", outputStorage);
1246  }
1247  if (!server.readTypeCheckingString(inputStorage, vehicleParams.line)) {
1248  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Twelth parameter (line) requires a string.", outputStorage);
1249  }
1250 
1251  int num;
1252  if (!server.readTypeCheckingInt(inputStorage, num)) {
1253  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "13th parameter (person capacity) requires an int.", outputStorage);
1254  }
1255  if (!server.readTypeCheckingInt(inputStorage, num)) {
1256  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "14th parameter (person number) requires an int.", outputStorage);
1257  }
1258  vehicleParams.personNumber = num;
1259 
1260  SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
1261  try {
1262  SUMOVehicle* vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(params, route, vehicleType, true, false);
1263  MSNet::getInstance()->getVehicleControl().addVehicle(vehicleParams.id, vehicle);
1265  } catch (ProcessError& e) {
1266  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1267  }
1268  }
1269  break;
1270  case REMOVE: {
1271  int why = 0;
1272  if (!server.readTypeCheckingByte(inputStorage, why)) {
1273  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Removing a vehicle requires a byte.", outputStorage);
1274  }
1276  switch (why) {
1277  case REMOVE_TELEPORT:
1278  // XXX semantics unclear
1279  // n = MSMoveReminder::NOTIFICATION_TELEPORT;
1281  break;
1282  case REMOVE_PARKING:
1283  // XXX semantics unclear
1284  // n = MSMoveReminder::NOTIFICATION_PARKING;
1286  break;
1287  case REMOVE_ARRIVED:
1289  break;
1290  case REMOVE_VAPORIZED:
1292  break;
1295  break;
1296  default:
1297  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Unknown removal status.", outputStorage);
1298  }
1299  if (v->hasDeparted()) {
1300  v->onRemovalFromNet(n);
1301  if (v->getLane() != 0) {
1302  v->getLane()->removeVehicle(v, n);
1303  }
1305  }
1306  }
1307  break;
1308  case VAR_MOVE_TO_VTD: {
1309  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
1310  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting VTD vehicle requires a compound object.", outputStorage);
1311  }
1312  const int numArgs = inputStorage.readInt();
1313  if (numArgs != 5 && numArgs != 6) {
1314  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting VTD vehicle should obtain: edgeID, lane, x, y, angle and optionally keepRouteFlag.", outputStorage);
1315  }
1316  // edge ID
1317  std::string edgeID;
1318  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
1319  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first parameter for setting a VTD vehicle must be the edge ID given as a string.", outputStorage);
1320  }
1321  // lane index
1322  int laneNum = 0;
1323  if (!server.readTypeCheckingInt(inputStorage, laneNum)) {
1324  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second parameter for setting a VTD vehicle must be lane given as an int.", outputStorage);
1325  }
1326  // x
1327  double x = 0;
1328  double y = 0;
1329  double origAngle = 0;
1330  if (!server.readTypeCheckingDouble(inputStorage, x)) {
1331  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The third parameter for setting a VTD vehicle must be the x-position given as a double.", outputStorage);
1332  }
1333  // y
1334  if (!server.readTypeCheckingDouble(inputStorage, y)) {
1335  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for setting a VTD vehicle must be the y-position given as a double.", outputStorage);
1336  }
1337  // angle
1338  if (!server.readTypeCheckingDouble(inputStorage, origAngle)) {
1339  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The fifth parameter for setting a VTD vehicle must be the angle given as a double.", outputStorage);
1340  }
1341  bool keepRoute = v->getID() != "VTD_EGO";
1342  bool mayLeaveNetwork = false;
1343  if (numArgs == 6) {
1344  int keepRouteFlag;
1345  if (!server.readTypeCheckingByte(inputStorage, keepRouteFlag)) {
1346  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The sixth parameter for setting a VTD vehicle must be the keepRouteFlag given as a byte.", outputStorage);
1347  }
1348  keepRoute = (keepRouteFlag == 1);
1349  mayLeaveNetwork = (keepRouteFlag == 2);
1350  }
1351  // process
1352  std::string origID = edgeID + " " + toString(laneNum);
1353  if (laneNum < 0) {
1354  edgeID = '-' + edgeID;
1355  laneNum = -laneNum;
1356  }
1357  Position pos(x, y);
1358  SUMOReal angle = origAngle;
1359  if (angle >= 180.) {
1360  angle = -360. + angle;
1361  } else if (angle <= -180.) {
1362  angle = 360. + angle;
1363  }
1364 
1365  Position vehPos = v->getPosition();
1366 #ifdef DEBUG_VTD
1367  std::cout << std::endl << "begin vehicle " << v->getID() << " vehPos:" << vehPos << " lane:" << v->getLane()->getID() << std::endl;
1368  std::cout << " want pos:" << pos << " edge:" << edgeID << " laneNum:" << laneNum << " origAngle:" << origAngle << " angle:" << angle << " keepRoute:" << keepRoute << std::endl;
1369 #endif
1370 
1371  ConstMSEdgeVector edges;
1372  MSLane* lane = 0;
1373  SUMOReal lanePos;
1374  SUMOReal lanePosLat = 0;
1376  int routeOffset = 0;
1377  bool found;
1378  SUMOReal maxRouteDistance = 100;
1379  /* EGO vehicle is known to have a fixed route. @todo make this into a parameter of the TraCI call */
1380  if (keepRoute) {
1381  // case a): vehicle is on its earlier route
1382  // we additionally assume it is moving forward (SUMO-limit);
1383  // note that the route ("edges") is not changed in this case
1384  found = vtdMap_matchingRoutePosition(pos, origID, *v, bestDistance, &lane, lanePos, routeOffset, edges);
1385  // @note silenty ignoring mapping failure
1386  } else {
1387  found = vtdMap(pos, maxRouteDistance, origID, angle, *v, server, bestDistance, &lane, lanePos, routeOffset, edges);
1388  }
1389  if ((found && bestDistance <= maxRouteDistance) || mayLeaveNetwork) {
1390  // optionally compute lateral offset
1391  if (found && (MSGlobals::gLateralResolution > 0 || mayLeaveNetwork)) {
1392  const SUMOReal perpDist = lane->getShape().distance2D(pos, true);
1393  if (perpDist != GeomHelper::INVALID_OFFSET) {
1394  lanePosLat = perpDist;
1395  if (!mayLeaveNetwork) {
1396  lanePosLat = MIN2(lanePosLat, (SUMOReal)0.5 * (lane->getWidth() + v->getVehicleType().getWidth() - MSGlobals::gLateralResolution));
1397  }
1398  // figure out whether the offset is to the left or to the right
1399  PositionVector tmp = lane->getShape();
1400  tmp.move2side(-lanePosLat); // moved to left
1401  //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
1402  if (tmp.distance2D(pos) > perpDist) {
1403  lanePosLat = -lanePosLat;
1404  }
1405  }
1406  }
1407  assert((found && lane != 0) || (!found && lane == 0));
1408  // use the best we have
1409  server.setVTDControlled(v, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
1410  if (!v->isOnRoad()) {
1412 
1413  }
1414  } else {
1415  if (lane == 0) {
1416  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Could not map vehicle '" + id + "' no road found within " + toString(maxRouteDistance) + "m.", outputStorage);
1417  } else {
1418  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Could not map vehicle '" + id + "' distance to road is " + toString(bestDistance) + ".", outputStorage);
1419  }
1420  }
1421  }
1422  break;
1423  case VAR_SPEED_FACTOR: {
1424  double factor = 0;
1425  if (!server.readTypeCheckingDouble(inputStorage, factor)) {
1426  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting speed factor requires a double.", outputStorage);
1427  }
1428  v->setChosenSpeedFactor(factor);
1429  }
1430  break;
1431  case VAR_PARAMETER: {
1432  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
1433  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
1434  }
1435  //readt itemNo
1436  inputStorage.readInt();
1437  std::string name;
1438  if (!server.readTypeCheckingString(inputStorage, name)) {
1439  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);
1440  }
1441  std::string value;
1442  if (!server.readTypeCheckingString(inputStorage, value)) {
1443  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
1444  }
1445  ((SUMOVehicleParameter&) v->getParameter()).addParameter(name, value);
1446  }
1447  break;
1448  default:
1449  try {
1450  if (!TraCIServerAPI_VehicleType::setVariable(CMD_SET_VEHICLE_VARIABLE, variable, getSingularType(v), server, inputStorage, outputStorage)) {
1451  return false;
1452  }
1453  } catch (ProcessError& e) {
1454  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1455  }
1456  break;
1457  }
1458  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_OK, warning, outputStorage);
1459  return true;
1460 }
1461 
1462 
1463 bool
1464 TraCIServerAPI_Vehicle::vtdMap(const Position& pos, SUMOReal maxRouteDistance, const std::string& origID, const SUMOReal angle, MSVehicle& v, TraCIServer& server,
1465  SUMOReal& bestDistance, MSLane** lane, SUMOReal& lanePos, int& routeOffset, ConstMSEdgeVector& edges) {
1466  // collect edges around the vehicle
1467  SUMOReal speed = pos.distanceTo2D(v.getPosition()); // !!!v.getSpeed();
1468  std::set<std::string> into;
1469  PositionVector shape;
1470  shape.push_back(pos);
1471  server.collectObjectsInRange(CMD_GET_EDGE_VARIABLE, shape, maxRouteDistance, into);
1472  SUMOReal maxDist = 0;
1473  std::map<MSLane*, LaneUtility> lane2utility;
1474  // compute utility for all candidate edges
1475  for (std::set<std::string>::const_iterator j = into.begin(); j != into.end(); ++j) {
1476  MSEdge* e = MSEdge::dictionary(*j);
1477  const MSEdge* prevEdge = 0;
1478  const MSEdge* nextEdge = 0;
1480  bool onRoute = false;
1481  // the next if/the clause sets "onRoute", "prevEdge", and "nextEdge", depending on
1482  // whether the currently seen edge is an internal one or a normal one
1483  if (ef != MSEdge::EDGEFUNCTION_INTERNAL) {
1484 #ifdef DEBUG_VTD_ANGLE
1485  std::cout << "Ego on normal" << std::endl;
1486 #endif
1487  // a normal edge
1488  //
1489  // check whether the currently seen edge is in the vehicle's route
1490  // - either the one it's on or one of the next edges
1491  const ConstMSEdgeVector& ev = v.getRoute().getEdges();
1492  int routePosition = v.getRoutePosition();
1494  ++routePosition;
1495  }
1496  ConstMSEdgeVector::const_iterator edgePos = std::find(ev.begin() + routePosition, ev.end(), e);
1497  onRoute = edgePos != ev.end(); // no? -> onRoute is false
1498  if (edgePos == ev.end() - 1 && v.getEdge() == e) {
1499  // onRoute is false as well if the vehicle is beyond the edge
1500  onRoute &= v.getEdge()->getLanes()[0]->getLength() > v.getPositionOnLane() + SPEED2DIST(speed);
1501  }
1502  // save prior and next edges
1503  prevEdge = e;
1504  nextEdge = !onRoute || edgePos == ev.end() - 1 ? 0 : *(edgePos + 1);
1505 #ifdef DEBUG_VTD_ANGLE
1506  std::cout << "normal:" << e->getID() << " prev:" << prevEdge->getID() << " next:";
1507  if (nextEdge != 0) {
1508  std::cout << nextEdge->getID();
1509  }
1510  std::cout << std::endl;
1511 #endif
1512  } else {
1513 #ifdef DEBUG_VTD_ANGLE
1514  std::cout << "Ego on internal" << std::endl;
1515 #endif
1516  // an internal edge
1517  // get the previous edge
1518  prevEdge = e;
1519  while (prevEdge != 0 && prevEdge->getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
1520  MSLane* l = prevEdge->getLanes()[0];
1521  l = l->getLogicalPredecessorLane();
1522  prevEdge = l == 0 ? 0 : &l->getEdge();
1523  }
1524  // check whether the previous edge is on the route (was on the route)
1525  const ConstMSEdgeVector& ev = v.getRoute().getEdges();
1526  ConstMSEdgeVector::const_iterator prevEdgePos = std::find(ev.begin() + v.getRoutePosition(), ev.end(), prevEdge);
1527  nextEdge = e;
1528  while (nextEdge != 0 && nextEdge->getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
1529  nextEdge = nextEdge->getSuccessors()[0]; // should be only one for an internal edge
1530  }
1531  if (prevEdgePos != ev.end() && (prevEdgePos + 1) != ev.end()) {
1532  onRoute = *(prevEdgePos + 1) == nextEdge;
1533  }
1534 #ifdef DEBUG_VTD_ANGLE
1535  std::cout << "internal:" << e->getID() << " prev:" << prevEdge->getID() << " next:" << nextEdge->getID() << std::endl;
1536 #endif
1537  }
1538 
1539 
1540  // weight the lanes...
1541  const std::vector<MSLane*>& lanes = e->getLanes();
1542  for (std::vector<MSLane*>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
1543  MSLane* lane = *k;
1544  SUMOReal off = lane->getShape().nearest_offset_to_point2D(pos);
1545  SUMOReal langle = 180.;
1546  SUMOReal dist = 1000.;
1547  if (off >= 0) {
1548  dist = lane->getShape().distance2D(pos);
1549  if (dist > lane->getLength()) { // this is a workaround
1550  // a SmartDB, running at :49_2 delivers off=~9.24 while dist>24.?
1551  dist = 1000.;
1552  } else {
1554  }
1555  }
1556  bool sameEdge = v.isOnRoad() && &lane->getEdge() == &v.getLane()->getEdge() && v.getEdge()->getLanes()[0]->getLength() > v.getPositionOnLane() + SPEED2DIST(speed);
1557  /*
1558  const MSEdge* rNextEdge = nextEdge;
1559  while(rNextEdge==0&&lane->getEdge().getPurpose()==MSEdge::EDGEFUNCTION_INTERNAL) {
1560  MSLane* next = lane->getLinkCont()[0]->getLane();
1561  rNextEdge = next == 0 ? 0 : &next->getEdge();
1562  }
1563  */
1564 #ifdef DEBUG_VTD_ANGLE
1565  std::cout << lane->getID() << ": " << langle << " " << off << std::endl;
1566 #endif
1567  lane2utility[lane] = LaneUtility(
1568  dist, GeomHelper::getMinAngleDiff(angle, langle),
1569  lane->getParameter("origId", "") == origID,
1570  onRoute, sameEdge, prevEdge, nextEdge);
1571  // update scaling value
1572  if (dist < 1000) {
1573  maxDist = MAX2(maxDist, dist);
1574  }
1575 
1576  }
1577  }
1578 
1579  // get the best lane given the previously computed values
1580  SUMOReal bestValue = 0;
1581  MSLane* bestLane = 0;
1582  for (std::map<MSLane*, LaneUtility>::iterator i = lane2utility.begin(); i != lane2utility.end(); ++i) {
1583  MSLane* l = (*i).first;
1584  const LaneUtility& u = (*i).second;
1585  SUMOReal distN = u.dist > 999 ? -10 : 1. - (u.dist / maxDist);
1586  SUMOReal angleDiffN = 1. - (u.angleDiff / 180.);
1587  SUMOReal idN = u.ID ? 1 : 0;
1588  SUMOReal onRouteN = u.onRoute ? 1 : 0;
1589  SUMOReal sameEdgeN = u.sameEdge ? MIN2(v.getEdge()->getLength() / speed, (SUMOReal)1.) : 0;
1590  SUMOReal value = (distN * .35
1591  + angleDiffN * 0.35 /*.5 */
1592  + idN * .1
1593  + onRouteN * 0.1
1594  + sameEdgeN * 0.1);
1595 #ifdef DEBUG_VTD
1596  std::cout << " x; l:" << l->getID() << " d:" << u.dist << " dN:" << distN << " aD:" << angleDiffN <<
1597  " ID:" << idN << " oRN:" << onRouteN << " sEN:" << sameEdgeN << " value:" << value << std::endl;
1598 #endif
1599  if (value > bestValue || bestLane == 0) {
1600  bestValue = value;
1601  bestLane = l;
1602  }
1603  }
1604  // no best lane found, return
1605  if (bestLane == 0) {
1606  return false;
1607  }
1608  const LaneUtility& u = lane2utility.find(bestLane)->second;
1609  bestDistance = u.dist;
1610  *lane = bestLane;
1611  lanePos = bestLane->getShape().nearest_offset_to_point2D(pos);
1612  const MSEdge* prevEdge = u.prevEdge;
1613  if (u.onRoute) {
1614  const ConstMSEdgeVector& ev = v.getRoute().getEdges();
1615  ConstMSEdgeVector::const_iterator prevEdgePos = std::find(ev.begin(), ev.end(), prevEdge);
1616  routeOffset = (int)std::distance(ev.begin(), prevEdgePos);
1617  //std::cout << SIMTIME << "vtdMap vehicle=" << v.getID() << " currLane=" << v.getLane()->getID() << " routeOffset=" << routeOffset << " edges=" << toString(ev) << " bestLane=" << bestLane->getID() << " prevEdge=" << prevEdge->getID() << "\n";
1618  } else {
1619  edges.push_back(u.prevEdge);
1620  /*
1621  if(bestLane->getEdge().getPurpose()!=MSEdge::EDGEFUNCTION_INTERNAL) {
1622  edges.push_back(&bestLane->getEdge());
1623  }
1624  */
1625  if (u.nextEdge != 0) {
1626  edges.push_back(u.nextEdge);
1627  }
1628  routeOffset = 0;
1629 #ifdef DEBUG_VTD_ANGLE
1630  std::cout << "internal2:" << " prev:";
1631  if (u.prevEdge != 0) {
1632  std::cout << u.prevEdge->getID();
1633  }
1634  std::cout << " next:";
1635  if (u.nextEdge != 0) {
1636  std::cout << u.nextEdge->getID();
1637  }
1638  std::cout << std::endl;
1639 #endif
1640  }
1641  return true;
1642 }
1643 
1644 
1645 bool
1646 TraCIServerAPI_Vehicle::findCloserLane(const MSEdge* edge, const Position& pos, SUMOReal& bestDistance, MSLane** lane) {
1647  if (edge == 0) {
1648  return false;
1649  }
1650  const std::vector<MSLane*>& lanes = edge->getLanes();
1651  bool newBest = false;
1652  for (std::vector<MSLane*>::const_iterator k = lanes.begin(); k != lanes.end() && bestDistance > POSITION_EPS; ++k) {
1653  MSLane* candidateLane = *k;
1654  const SUMOReal dist = candidateLane->getShape().distance2D(pos); // get distance
1655 #ifdef DEBUG_VTD
1656  std::cout << " b at lane " << candidateLane->getID() << " dist:" << dist << " best:" << bestDistance << std::endl;
1657 #endif
1658  if (dist < bestDistance) {
1659  // is the new distance the best one? keep then...
1660  bestDistance = dist;
1661  *lane = candidateLane;
1662  newBest = true;
1663  }
1664  }
1665  return newBest;
1666 }
1667 
1668 bool
1670  SUMOReal& bestDistance, MSLane** lane, SUMOReal& lanePos, int& routeOffset, ConstMSEdgeVector& /*edges*/) {
1671 
1672  const ConstMSEdgeVector& edges = v.getRoute().getEdges();
1673  routeOffset = 0;
1674  // routes may be looped which makes routeOffset ambiguous. We first try to
1675  // find the closest upcoming edge on the route and then look for closer passed edges
1676 
1677  // look forward along the route
1678  const MSEdge* prev = 0;
1679  UNUSED_PARAMETER(prev); // silence 'unused variable' warning when built without INTERNAL_LANES
1680  for (ConstMSEdgeVector::const_iterator i = v.getCurrentRouteEdge(); i != edges.end(); ++i) {
1681 #ifdef HAVE_INTERNAL_LANES
1682  while (prev != 0) {
1683  // check internal edge(s)
1684  const MSEdge* internalCand = prev->getInternalFollowingEdge(*i);
1685  findCloserLane(internalCand, pos, bestDistance, lane);
1686  prev = internalCand;
1687  }
1688 #endif
1689  if (findCloserLane(*i, pos, bestDistance, lane)) {
1690  routeOffset = (int)std::distance(edges.begin(), i);
1691  }
1692  prev = *i;
1693  }
1694  // look backward along the route
1695  const MSEdge* next = *v.getCurrentRouteEdge();
1696  UNUSED_PARAMETER(next); // silence 'unused variable' warning when built without INTERNAL_LANES
1697  for (ConstMSEdgeVector::const_iterator i = v.getCurrentRouteEdge(); i != edges.begin(); --i) {
1698  prev = *i;
1699 #ifdef HAVE_INTERNAL_LANES
1700  while (prev != 0) {
1701  // check internal edge(s)
1702  const MSEdge* internalCand = prev->getInternalFollowingEdge(next);
1703  findCloserLane(internalCand, pos, bestDistance, lane);
1704  prev = internalCand;
1705  }
1706 #endif
1707  if (findCloserLane(*i, pos, bestDistance, lane)) {
1708  routeOffset = (int)std::distance(edges.begin(), i);
1709  }
1710  next = *i;
1711  }
1712 
1713  assert(lane != 0);
1714  // quit if no solution was found, reporting a failure
1715  if (lane == 0) {
1716 #ifdef DEBUG_VTD
1717  std::cout << " b failed - no best route lane" << std::endl;
1718 #endif
1719  return false;
1720  }
1721 
1722 
1723  // position may be inaccurate; let's checkt the given index, too
1724  // a) is enabled for non-internal lanes only, as otherwise the position information may ambiguous
1725  // b) it's something one has to enable when building the nework - keepin the OSM IDs - is probably not always done
1726  if ((*lane)->getEdge().getPurpose() != MSEdge::EDGEFUNCTION_INTERNAL) {
1727  const std::vector<MSLane*>& lanes = (*lane)->getEdge().getLanes();
1728  for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
1729  if ((*i)->getParameter("origId", "") == origID) {
1730  *lane = *i;
1731  break;
1732  }
1733  }
1734  }
1735  // check position, stuff, we should have the best lane along the route
1736  lanePos = MAX2(SUMOReal(0), MIN2(SUMOReal((*lane)->getLength() - POSITION_EPS), (*lane)->getShape().nearest_offset_to_point2D(pos, false)));
1737  //std::cout << SIMTIME << " vtdMap_matchingRoutePosition vehicle=" << v.getID() << " currLane=" << v.getLane()->getID() << " routeOffset=" << routeOffset << " edges=" << toString(edges) << " lane=" << (*lane)->getID() << "\n";
1738 #ifdef DEBUG_VTD
1739  std::cout << " b ok lane " << (*lane)->getID() << " lanePos:" << lanePos << std::endl;
1740 #endif
1741  return true;
1742 }
1743 
1744 
1745 bool
1747  tcpip::Storage& outputStorage, const MSVehicle* v) {
1748  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
1749  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of distance requires a compound object.", outputStorage);
1750  }
1751  if (inputStorage.readInt() != 2) {
1752  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of distance requires position and distance type as parameter.", outputStorage);
1753  }
1754 
1755  Position pos;
1756  std::pair<const MSLane*, SUMOReal> roadPos;
1757 
1758  // read position
1759  int posType = inputStorage.readUnsignedByte();
1760  switch (posType) {
1761  case POSITION_ROADMAP:
1762  try {
1763  std::string roadID = inputStorage.readString();
1764  roadPos.second = inputStorage.readDouble();
1765  roadPos.first = TraCIServerAPI_Simulation::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos.second);
1766  pos = roadPos.first->getShape().positionAtOffset(roadPos.second);
1767  } catch (TraCIException& e) {
1768  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, e.what(), outputStorage);
1769  }
1770  break;
1771  case POSITION_2D:
1772  case POSITION_3D: {
1773  const double p1x = inputStorage.readDouble();
1774  const double p1y = inputStorage.readDouble();
1775  pos.set(p1x, p1y);
1776  }
1777  if (posType == POSITION_3D) {
1778  inputStorage.readDouble(); // z value is ignored
1779  }
1781  break;
1782  default:
1783  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Unknown position format used for distance request", outputStorage);
1784  }
1785 
1786  // read distance type
1787  int distType = inputStorage.readUnsignedByte();
1788 
1789  SUMOReal distance = INVALID_DOUBLE_VALUE;
1790  if (v->isOnRoad()) {
1791  if (distType == REQUEST_DRIVINGDIST) {
1792  distance = v->getRoute().getDistanceBetween(v->getPositionOnLane(), roadPos.second,
1793  v->getEdge(), &roadPos.first->getEdge());
1794  if (distance == std::numeric_limits<SUMOReal>::max()) {
1795  distance = INVALID_DOUBLE_VALUE;
1796  }
1797  } else {
1798  // compute air distance (default)
1799  distance = v->getPosition().distanceTo(pos);
1800  }
1801  }
1802  // write response command
1803  outputStorage.writeUnsignedByte(TYPE_DOUBLE);
1804  outputStorage.writeDouble(distance);
1805  return true;
1806 }
1807 
1808 
1809 // ------ helper functions ------
1810 bool
1811 TraCIServerAPI_Vehicle::getPosition(const std::string& id, Position& p) {
1812  MSVehicle* v = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(id));
1813  if (v == 0) {
1814  return false;
1815  }
1816  p = v->getPosition();
1817  return true;
1818 }
1819 
1820 
1823  const MSVehicleType& oType = veh->getVehicleType();
1824  std::string newID = oType.getID().find('@') == std::string::npos ? oType.getID() + "@" + veh->getID() : oType.getID();
1825  MSVehicleType* type = MSVehicleType::build(newID, &oType);
1826  static_cast<MSVehicle*>(veh)->replaceVehicleType(type);
1827  return *type;
1828 }
1829 
1830 
1831 #include <microsim/MSEdgeControl.h>
1832 
1833 const std::map<std::string, std::vector<MSLane*> >&
1835  if (gVTDMap.size() == 0) {
1837  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
1838  const std::vector<MSLane*>& lanes = (*i)->getLanes();
1839  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1840  if ((*j)->knowsParameter("origId")) {
1841  std::string origID = (*j)->getParameter("origId", "");
1842  if (gVTDMap.find(origID) == gVTDMap.end()) {
1843  gVTDMap[origID] = std::vector<MSLane*>();
1844  }
1845  gVTDMap[origID].push_back(*j);
1846  }
1847  }
1848  }
1849  if (gVTDMap.size() == 0) {
1850  gVTDMap["unknown"] = std::vector<MSLane*>();
1851  }
1852  }
1853  return gVTDMap;
1854 }
1855 
1856 
1857 #endif
1858 
1859 
1860 /****************************************************************************/
1861 
#define VAR_ROAD_ID
static bool setVariable(const int cmd, const int variable, MSVehicleType &v, TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value for the given type.
#define REMOVE_PARKING
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
Definition: MSVehicle.cpp:3088
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:2288
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:567
RGBColor color
The vehicle&#39;s color.
static bool commandDistanceRequest(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, const MSVehicle *v)
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:81
bool isLinkEnd(MSLinkCont::const_iterator &i) const
Definition: MSLane.cpp:1334
#define VAR_EMISSIONCLASS
#define VAR_CO2EMISSION
static MSLinkCont::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
Definition: MSLane.cpp:1396
#define REQUEST_DRIVINGDIST
#define VAR_LENGTH
void collectObjectsInRange(int domain, const PositionVector &shape, SUMOReal range, std::set< std::string > &into)
The time is given.
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, SUMOReal &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
#define RESPONSE_GET_VEHICLE_VARIABLE
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
static MSVehicleType & getSingularType(SUMOVehicle *const veh)
#define CMD_GET_VEHICLE_VARIABLE
#define TYPE_COMPOUND
static std::map< std::string, std::vector< MSLane * > > gVTDMap
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, SUMOReal &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
void setTentativeLaneAndPosition(MSLane *lane, SUMOReal pos, SUMOReal posLat=0)
set tentative lane and position during insertion to ensure that all cfmodels work (some of them requi...
Definition: MSVehicle.cpp:3103
#define CMD_RESUME
Stop & getNextStop()
Definition: MSVehicle.cpp:3442
#define POSITION_2D
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc4: Change Vehicle State)
SUMOReal getDepartPos() const
Returns this vehicle&#39;s real departure position.
#define VAR_POSITION
void setVTDControlled(MSVehicle *v, Position xyPos, MSLane *l, SUMOReal pos, SUMOReal posLat, SUMOReal angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
static const MSLane * getLaneChecking(std::string roadID, int laneIndex, SUMOReal pos)
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive...
Definition: MSVehicle.h:626
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
#define VAR_ROUTE
static bool vtdMap(const Position &pos, SUMOReal maxRouteDistance, const std::string &origID, const SUMOReal angle, MSVehicle &v, TraCIServer &server, SUMOReal &bestDistance, MSLane **lane, SUMOReal &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
#define CMD_CHANGELANE
bool readTypeCheckingColor(tcpip::Storage &inputStorage, RGBColor &into)
Reads the value type and a color, verifying the type.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
#define VAR_SPEEDSETMODE
#define VAR_TAU
SUMOReal getSpeedWithoutTraciInfluence() const
Returns the uninfluenced velocity.
Definition: MSVehicle.cpp:3463
void setRespectJunctionPriority(bool value)
Sets whether junction priority rules shall be respected.
Definition: MSVehicle.cpp:412
#define CMD_STOP
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
SUMOReal getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:475
Position getPosition(const SUMOReal offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:761
SUMOReal departSpeed
(optional) The initial speed of the vehicle
#define VAR_ALLOWED_SPEED
#define TYPE_UBYTE
The position is given.
#define RTYPE_OK
#define POSITION_ROADMAP
#define DISTANCE_REQUEST
Tag for the last element in the enum for safe int casting.
static bool getVariable(const int variable, const MSVehicleType &v, tcpip::Storage &tempMsg)
Processes a value request for the given type.
#define VAR_WAITING_TIME
virtual double readDouble()
SUMOReal arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
#define VAR_SIGNALS
#define VAR_TYPE
#define VAR_ROUTE_ID
Notification
Definition of a vehicle state.
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:1476
#define VAR_VEHICLECLASS
bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0)
Replaces the current route by the given one.
Definition: MSVehicle.cpp:610
#define VAR_SPEED_FACTOR
#define VAR_COLOR
SUMOReal getHCEmissions() const
Returns HC emission of the current state.
Definition: MSVehicle.cpp:2929
static bool getPosition(const std::string &id, Position &p)
Returns the named vehicle&#39;s position.
SUMOReal getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:491
bool reached
Information whether the stop has been reached.
Definition: MSVehicle.h:746
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
SUMOReal arrivalPos
(optional) The position the vehicle shall arrive on
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
T MAX2(T a, T b)
Definition: StdDefs.h:75
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:89
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...
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
#define TYPE_COLOR
#define TYPE_STRINGLIST
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
bool hasDeparted() const
Returns whether this vehicle has already departed.
The vehicle got vaporized.
#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:666
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
static std::pair< MSLane *, SUMOReal > convertCartesianToRoadMap(Position pos)
Definition of vehicle stop (position and duration)
Definition: MSVehicle.h:720
#define VAR_BEST_LANES
SUMOReal getCO2Emissions() const
Returns CO2 emission of the current state.
Definition: MSVehicle.cpp:2917
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
std::pair< const MSVehicle *const, SUMOReal > getLeader(SUMOReal dist=0) const
Returns the leader of the vehicle looking for a fixed distance.
Definition: MSVehicle.cpp:2879
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:221
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle&#39;s end speed shall be chosen.
SUMOReal getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:350
virtual void writeUnsignedByte(int)
#define VAR_NEXT_TLS
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:254
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:89
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
Tag for the last element in the enum for safe int casting.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
#define VAR_SPEED_DEVIATION
SUMOReal length
The overall length which may be driven when using this lane without a lane change.
Definition: MSVehicle.h:618
#define VAR_NOISEEMISSION
#define VAR_FUELCONSUMPTION
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
void addEffort(const MSEdge *const e, SUMOReal begin, SUMOReal end, SUMOReal value)
Adds an effort information for an edge and a time span.
static MSVehicleType * build(SUMOVTypeParameter &from)
Builds the microsim vehicle type described by the given parameter.
virtual void writeInt(int)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
#define VAR_POSITION3D
The speed is given.
The car-following model and parameter.
Definition: MSVehicleType.h:74
bool triggered
whether an arriving person lets the vehicle continue
Definition: MSVehicle.h:740
SUMOReal distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector) ...
#define TYPE_STRING
virtual int readUnsignedByte()
std::string toTaz
The vehicle&#39;s destination zone (district)
The lane is given.
void addTravelTime(const MSEdge *const e, SUMOReal begin, SUMOReal end, SUMOReal value)
Adds a travel time information for an edge and a time span.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa4: Get Vehicle Variable)
SUMOReal nextOccupation
As occupation, but without the first lane.
Definition: MSVehicle.h:624
#define VAR_NOXEMISSION
SUMOReal getElectricityConsumption() const
Returns electricity consumption of the current state.
Definition: MSVehicle.cpp:2953
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
#define VAR_ANGLE
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:80
MSLane * lane
The described lane.
Definition: MSVehicle.h:616
#define VAR_PERSON_NUMBER
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:585
#define CMD_SLOWDOWN
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Definition: MSLane.cpp:1883
#define VAR_SHAPECLASS
#define max(a, b)
Definition: polyfonts.c:65
void setEmergencyBrakeRedLight(bool value)
Sets whether red lights shall be a reason to brake.
Definition: MSVehicle.cpp:418
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle&#39;s initial speed shall be chosen.
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
#define REMOVE_ARRIVED
DepartLaneDefinition
Possible ways to choose a lane on depart.
#define VAR_ACCEL
#define CMD_CHANGETARGET
Representation of a vehicle.
Definition: SUMOVehicle.h:66
MSStoppingPlace * containerstop
(Optional) container stop if one is assigned to the stop
Definition: MSVehicle.h:728
void setChosenSpeedFactor(const SUMOReal factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
virtual int readInt()
static bool gCheckRoutes
Definition: MSGlobals.h:78
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal 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:285
#define REMOVE_TELEPORT_ARRIVED
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the subpart of best lanes that describes the vehicle&#39;s current lane and their successors...
Definition: MSVehicle.cpp:2808
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition: RGBColor.cpp:87
bool willPass(const MSEdge *const edge) const
Returns whether the vehicle wil pass the given edge.
Definition: MSVehicle.cpp:663
#define VAR_LANEPOSITION
A list of positions.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:90
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:99
virtual void writeByte(int)
#define REMOVE_TELEPORT
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
The vehicle arrived at its destination (is deleted)
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MSVehicle.cpp:988
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
virtual void writeStringList(const std::vector< std::string > &s)
SUMOTime depart
The vehicle&#39;s departure time.
#define VAR_PMXEMISSION
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:128
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime duration
The stopping duration.
Definition: MSVehicle.h:736
#define CMD_SET_VEHICLE_VARIABLE
T MIN2(T a, T b)
Definition: StdDefs.h:69
#define VAR_IMPERFECTION
#define POSITION_EPS
Definition: config.h:187
std::string fromTaz
The vehicle&#39;s origin zone (district)
virtual std::string readString()
#define CMD_GET_EDGE_VARIABLE
Tag for the last element in the enum for safe int casting.
A structure representing the best lanes for continuing the route.
Definition: MSVehicle.h:614
#define VAR_EDGES
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:591
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
#define VAR_EDGE_EFFORT
#define CMD_REROUTE_EFFORT
#define VAR_STOPSTATE
#define ADD
#define VAR_SLOPE
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
#define REMOVE
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:73
const int VEHPARS_COLOR_SET
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:254
virtual void writeStorage(tcpip::Storage &store)
#define VAR_LEADER
int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons) ...
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:994
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
Definition: MSVehicle.cpp:2474
int getRoutePosition() const
Definition: MSVehicle.cpp:669
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, SUMOReal &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
int getPersonNumber() const
Returns the number of persons.
Definition: MSVehicle.cpp:3027
bool allowsContinuation
Whether this lane allows to continue the drive.
Definition: MSVehicle.h:628
SUMOReal getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
Definition: MSVehicle.cpp:2959
static SUMOReal naviDegree(const SUMOReal angle)
Definition: GeomHelper.cpp:191
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
std::string line
The vehicle&#39;s line (mainly for public transport)
#define INVALID_DOUBLE_VALUE
#define VAR_SPEED
DepartSpeedDefinition
Possible ways to choose the departure speed.
SUMOReal getNOxEmissions() const
Returns NOx emission of the current state.
Definition: MSVehicle.cpp:2935
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
static bool findCloserLane(const MSEdge *edge, const Position &pos, SUMOReal &bestDistance, MSLane **lane)
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:856
void forceVehicleInsertion(MSVehicle *veh, SUMOReal pos, MSMoveReminder::Notification notification, SUMOReal posLat=0)
Inserts the given vehicle at the given position.
Definition: MSLane.cpp:743
static bool parseArrivalSpeed(const std::string &val, const std::string &element, const std::string &id, SUMOReal &speed, ArrivalSpeedDefinition &asd, std::string &error)
Validates a given arrivalSpeed value.
SUMOReal getPMxEmissions() const
Returns PMx emission of the current state.
Definition: MSVehicle.cpp:2941
SUMOReal getCOEmissions() const
Returns CO emission of the current state.
Definition: MSVehicle.cpp:2923
#define VAR_EDGE_TRAVELTIME
SUMOReal getWidth() const
Get the width which vehicles of this class shall have when being drawn.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1226
#define VAR_COEMISSION
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, SUMOReal > > &speedTimeLine)
Sets a new velocity timeline.
Definition: MSVehicle.cpp:246
virtual void writeString(const std::string &s)
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:249
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:3448
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
Structure representing possible vehicle parameter.
#define INVALID_INT_VALUE
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:84
#define VAR_MOVE_TO
#define SUMOTime_MAX
Definition: SUMOTime.h:44
#define TYPE_DOUBLE
SUMOReal getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:750
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:65
bool containerTriggered
whether an arriving container lets the vehicle continue
Definition: MSVehicle.h:742
void setConsiderMaxDeceleration(bool value)
Sets whether the maximum deceleration shall be regarded.
Definition: MSVehicle.cpp:406
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:360
int setParameter
Information for the router which parameter were set.
#define CMD_REROUTE_TRAVELTIME
std::vector< MSLane * > bestContinuations
Consecutive lane that can be followed without a lane change (contribute to length and occupation) ...
Definition: MSVehicle.h:630
#define TYPE_BYTE
#define VAR_ELECTRICITYCONSUMPTION
#define VAR_ROUTE_INDEX
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
SUMOReal getFuelConsumption() const
Returns fuel consumption of the current state.
Definition: MSVehicle.cpp:2947
static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:172
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:97
static SUMOReal gLateralResolution
Definition: MSGlobals.h:84
void set(SUMOReal x, SUMOReal y)
Definition: Position.h:78
void setConsiderSafeVelocity(bool value)
Sets whether the safe velocity shall be regarded.
Definition: MSVehicle.cpp:394
bool replaceRouteEdges(ConstMSEdgeVector &edges, bool onInit=false, bool check=false)
Replaces the current route by the given edges.
MSRouteIterator edge
The edge in the route to stop at.
Definition: MSVehicle.h:722
SUMOReal getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
bool addTraciBusOrContainerStop(const std::string &stopId, const SUMOTime duration, const SUMOTime until, const bool parking, const bool triggered, const bool containerTriggered, const bool isContainerStop, std::string &errorMsg)
Definition: MSVehicle.cpp:3355
const std::string & getID() const
Returns the name of the vehicle type.
SUMOReal getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:410
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
SUMOReal departPos
(optional) The position the vehicle shall depart from
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void setLaneChangeMode(int value)
Sets lane changing behavior.
Definition: MSVehicle.cpp:424
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:502
virtual void writeDouble(double)
#define REMOVE_VAPORIZED
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:422
#define VAR_MOVE_TO_VTD
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:232
void move2side(SUMOReal amount)
move position vector to side using certain ammount
const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
Definition: MSVehicle.cpp:787
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:1011
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
#define SUMOReal
Definition: config.h:213
void switchOffSignal(int signal)
Switches the given signal off.
Definition: MSVehicle.h:1003
void switchOnSignal(int signal)
Switches the given signal on.
Definition: MSVehicle.h:995
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
const MSEdgeVector & getSuccessors() const
Returns the following edges.
Definition: MSEdge.h:349
#define VAR_SPEED_WITHOUT_TRACI
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:350
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
#define NUMERICAL_EPS
Definition: config.h:160
void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)
Performs a rerouting using the given router.
#define VAR_LANECHANGE_MODE
int getSpeedMode() const
return the current speed mode
Definition: MSVehicle.cpp:259
#define VAR_MAXSPEED
bool retrieveExistingEffort(const MSEdge *const e, const SUMOReal t, SUMOReal &value) const
Returns an effort for an edge and time if stored.
void setLaneTimeLine(const std::vector< std::pair< SUMOTime, int > > &laneTimeLine)
Sets a new lane timeline.
Definition: MSVehicle.cpp:253
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
The vehicle was teleported out of the net.
#define VAR_DECEL
#define VAR_ROUTE_VALID
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
#define VAR_PARAMETER
#define ID_COUNT
#define VAR_LANE_INDEX
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
#define VAR_LANE_ID
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:453
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:455
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:447
The edge is an internal edge.
Definition: MSEdge.h:97
static const std::map< std::string, std::vector< MSLane * > > & getOrBuildVTDMap()
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
Tag for the last element in the enum for safe int casting.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
DepartPosDefinition
Possible ways to choose the departure position.
#define RTYPE_ERR
#define TYPE_INTEGER
#define VAR_MINGAP
#define ID_LIST
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
#define ADD_FULL
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
bool addTraciStop(MSLane *const lane, const SUMOReal startPos, const SUMOReal endPos, const SUMOTime duration, const SUMOTime until, const bool parking, const bool triggered, const bool containerTriggered, std::string &errorMsg)
Definition: MSVehicle.cpp:3322
SUMOReal startPos
The stopping position start.
Definition: MSVehicle.h:732
MSStoppingPlace * busstop
(Optional) bus stop if one is assigned to the stop
Definition: MSVehicle.h:726
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle&#39;s internal edge travel times/efforts container.
Definition: MSVehicle.cpp:684
bool retrieveExistingTravelTime(const MSEdge *const e, const SUMOReal t, SUMOReal &value) const
Returns a travel time for an edge and time if stored.
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:722
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
DepartDefinition
Possible ways to depart.
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error)
Validates a given depart value.
#define VAR_DISTANCE
bool readTypeCheckingByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and a byte, verifying the type.
#define VAR_HCEMISSION
void setConsiderMaxAcceleration(bool value)
Sets whether the maximum acceleration shall be regarded.
Definition: MSVehicle.cpp:400
static const SUMOReal INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:59
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:78
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
std::string id
The vehicle&#39;s id.
bool parking
whether the vehicle is removed from the net while stopping
Definition: MSVehicle.h:744
The vehicle is being teleported.
#define VAR_WIDTH
SUMOReal getAngle() const
Returns the vehicle&#39;s direction in degrees.
Definition: MSVehicle.h:520
const MSEdgeVector & getEdges() const
Returns loaded edges.
const std::string & getID() const
Returns the name of the vehicle.
static bool vtdMap_matchingRoutePosition(const Position &pos, const std::string &origID, MSVehicle &v, SUMOReal &bestDistance, MSLane **lane, SUMOReal &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:122
static bool parseDepartLane(const std::string &val, const std::string &element, const std::string &id, int &lane, DepartLaneDefinition &dld, std::string &error)
Validates a given departLane value.