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