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