SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TraCIServerAPI_Vehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // APIs for getting/setting vehicle values via TraCI
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
14 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #ifndef NO_TRACI
36 
37 #include <microsim/MSNet.h>
39 #include <microsim/MSVehicle.h>
40 #include <microsim/MSLane.h>
41 #include <microsim/MSEdge.h>
50 #include "TraCIConstants.h"
52 #include "TraCIServerAPI_Vehicle.h"
54 
55 #ifdef CHECK_MEMORY_LEAKS
56 #include <foreign/nvwa/debug_new.h>
57 #endif // CHECK_MEMORY_LEAKS
58 
59 
60 // ===========================================================================
61 // static member variables
62 // ===========================================================================
63 std::map<std::string, std::vector<MSLane*> > TraCIServerAPI_Vehicle::gVTDMap;
64 
65 
66 // ===========================================================================
67 // method definitions
68 // ===========================================================================
69 bool
71  tcpip::Storage& outputStorage) {
72  // variable & id
73  int variable = inputStorage.readUnsignedByte();
74  std::string id = inputStorage.readString();
75  // check variable
76  if (variable != ID_LIST && variable != VAR_SPEED && variable != VAR_SPEED_WITHOUT_TRACI
77  && variable != VAR_POSITION && variable != VAR_ANGLE
78  && variable != VAR_ROAD_ID && variable != VAR_LANE_ID && variable != VAR_LANE_INDEX
79  && variable != VAR_TYPE && variable != VAR_ROUTE_ID && variable != VAR_COLOR
80  && variable != VAR_LANEPOSITION
81  && variable != VAR_CO2EMISSION && variable != VAR_COEMISSION
82  && variable != VAR_HCEMISSION && variable != VAR_PMXEMISSION
83  && variable != VAR_NOXEMISSION && variable != VAR_FUELCONSUMPTION && variable != VAR_NOISEEMISSION
84  && variable != VAR_PERSON_NUMBER && variable != VAR_LEADER
85  && variable != VAR_EDGE_TRAVELTIME && variable != VAR_EDGE_EFFORT
86  && variable != VAR_ROUTE_VALID && variable != VAR_EDGES
87  && variable != VAR_SIGNALS && variable != VAR_DISTANCE
88  && variable != VAR_LENGTH && variable != VAR_MAXSPEED && variable != VAR_VEHICLECLASS
89  && variable != VAR_SPEED_FACTOR && variable != VAR_SPEED_DEVIATION
90  && variable != VAR_ALLOWED_SPEED && variable != VAR_EMISSIONCLASS
91  && variable != VAR_WIDTH && variable != VAR_MINGAP && variable != VAR_SHAPECLASS
92  && variable != VAR_ACCEL && variable != VAR_DECEL && variable != VAR_IMPERFECTION
93  && variable != VAR_TAU && variable != VAR_BEST_LANES && variable != DISTANCE_REQUEST
94  && variable != ID_COUNT && variable != VAR_STOPSTATE && variable != VAR_WAITING_TIME
95  ) {
96  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Get Vehicle Variable: unsupported variable specified", outputStorage);
97  }
98  // begin response building
99  tcpip::Storage tempMsg;
100  // response-code, variableID, objectID
102  tempMsg.writeUnsignedByte(variable);
103  tempMsg.writeString(id);
104  // process request
105  if (variable == ID_LIST || variable == ID_COUNT) {
106  std::vector<std::string> ids;
108  for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
109  if ((*i).second->isOnRoad()) {
110  ids.push_back((*i).first);
111  }
112  }
113  if (variable == ID_LIST) {
115  tempMsg.writeStringList(ids);
116  } else {
118  tempMsg.writeInt((int) ids.size());
119  }
120  } else {
122  if (sumoVehicle == 0) {
123  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not known", outputStorage);
124  }
125  MSVehicle* v = dynamic_cast<MSVehicle*>(sumoVehicle);
126  if (v == 0) {
127  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not a micro-simulation vehicle", outputStorage);
128  }
129  const bool onRoad = v->isOnRoad();
130  switch (variable) {
131  case VAR_SPEED:
133  tempMsg.writeDouble(onRoad ? v->getSpeed() : INVALID_DOUBLE_VALUE);
134  break;
138  break;
139  case VAR_POSITION:
141  tempMsg.writeDouble(onRoad ? v->getPosition().x() : INVALID_DOUBLE_VALUE);
142  tempMsg.writeDouble(onRoad ? v->getPosition().y() : INVALID_DOUBLE_VALUE);
143  break;
144  case VAR_ANGLE:
146  tempMsg.writeDouble(onRoad ? v->getAngle() : INVALID_DOUBLE_VALUE);
147  break;
148  case VAR_ROAD_ID:
150  tempMsg.writeString(onRoad ? v->getLane()->getEdge().getID() : "");
151  break;
152  case VAR_LANE_ID:
154  tempMsg.writeString(onRoad ? v->getLane()->getID() : "");
155  break;
156  case VAR_LANE_INDEX:
158  if (onRoad) {
159  const std::vector<MSLane*>& lanes = v->getLane()->getEdge().getLanes();
160  tempMsg.writeInt((int)std::distance(lanes.begin(), std::find(lanes.begin(), lanes.end(), v->getLane())));
161  } else {
162  tempMsg.writeInt(INVALID_INT_VALUE);
163  }
164  break;
165  case VAR_TYPE:
167  tempMsg.writeString(v->getVehicleType().getID());
168  break;
169  case VAR_ROUTE_ID:
171  tempMsg.writeString(v->getRoute().getID());
172  break;
173  case VAR_COLOR:
174  tempMsg.writeUnsignedByte(TYPE_COLOR);
175  tempMsg.writeUnsignedByte(v->getParameter().color.red());
176  tempMsg.writeUnsignedByte(v->getParameter().color.green());
177  tempMsg.writeUnsignedByte(v->getParameter().color.blue());
178  tempMsg.writeUnsignedByte(v->getParameter().color.alpha());
179  break;
180  case VAR_LANEPOSITION:
182  tempMsg.writeDouble(onRoad ? v->getPositionOnLane() : INVALID_DOUBLE_VALUE);
183  break;
184  case VAR_CO2EMISSION:
186  tempMsg.writeDouble(onRoad ? v->getCO2Emissions() : INVALID_DOUBLE_VALUE);
187  break;
188  case VAR_COEMISSION:
190  tempMsg.writeDouble(onRoad ? v->getCOEmissions() : INVALID_DOUBLE_VALUE);
191  break;
192  case VAR_HCEMISSION:
194  tempMsg.writeDouble(onRoad ? v->getHCEmissions() : INVALID_DOUBLE_VALUE);
195  break;
196  case VAR_PMXEMISSION:
198  tempMsg.writeDouble(onRoad ? v->getPMxEmissions() : INVALID_DOUBLE_VALUE);
199  break;
200  case VAR_NOXEMISSION:
202  tempMsg.writeDouble(onRoad ? v->getNOxEmissions() : INVALID_DOUBLE_VALUE);
203  break;
204  case VAR_FUELCONSUMPTION:
206  tempMsg.writeDouble(onRoad ? v->getFuelConsumption() : INVALID_DOUBLE_VALUE);
207  break;
208  case VAR_NOISEEMISSION:
211  break;
212  case VAR_PERSON_NUMBER:
214  tempMsg.writeInt(v->getPersonNumber());
215  break;
216  case VAR_LEADER: {
217  double dist = 0;
218  if (!server.readTypeCheckingDouble(inputStorage, dist)) {
219  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Leader retrieval requires a double.", outputStorage);
220  }
221  std::pair<const MSVehicle* const, SUMOReal> leaderInfo = v->getLeader(dist);
223  tempMsg.writeInt(2);
225  tempMsg.writeString(leaderInfo.first != 0 ? leaderInfo.first->getID() : "");
227  tempMsg.writeDouble(leaderInfo.second);
228  }
229  break;
230  case VAR_WAITING_TIME:
232  tempMsg.writeDouble(v->getWaitingSeconds());
233  break;
234  case VAR_EDGE_TRAVELTIME: {
235  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
236  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires a compound object.", outputStorage);
237  }
238  if (inputStorage.readInt() != 2) {
239  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires time, and edge as parameter.", outputStorage);
240  }
241  // time
242  SUMOTime time = 0;
243  if (!server.readTypeCheckingInt(inputStorage, time)) {
244  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires the referenced time as first parameter.", outputStorage);
245  }
246  // edge
247  std::string edgeID;
248  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
249  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires the referenced edge as second parameter.", outputStorage);
250  }
251  MSEdge* edge = MSEdge::dictionary(edgeID);
252  if (edge == 0) {
253  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
254  }
255  // retrieve
257  SUMOReal value;
258  if (!v->getWeightsStorage().retrieveExistingTravelTime(edge, 0, time, value)) {
260  } else {
261  tempMsg.writeDouble(value);
262  }
263 
264  }
265  break;
266  case VAR_EDGE_EFFORT: {
267  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
268  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires a compound object.", outputStorage);
269  }
270  if (inputStorage.readInt() != 2) {
271  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires time, and edge as parameter.", outputStorage);
272  }
273  // time
274  SUMOTime time = 0;
275  if (!server.readTypeCheckingInt(inputStorage, time)) {
276  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of effort requires the referenced time as first parameter.", outputStorage);
277  }
278  // edge
279  std::string edgeID;
280  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
281  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of effort requires the referenced edge as second parameter.", outputStorage);
282  }
283  MSEdge* edge = MSEdge::dictionary(edgeID);
284  if (edge == 0) {
285  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
286  }
287  // retrieve
289  SUMOReal value;
290  if (!v->getWeightsStorage().retrieveExistingEffort(edge, 0, time, value)) {
292  } else {
293  tempMsg.writeDouble(value);
294  }
295 
296  }
297  break;
298  case VAR_ROUTE_VALID: {
299  std::string msg;
300  tempMsg.writeUnsignedByte(TYPE_UBYTE);
301  tempMsg.writeUnsignedByte(v->hasValidRoute(msg));
302  }
303  break;
304  case VAR_EDGES: {
305  const MSRoute& r = v->getRoute();
307  tempMsg.writeInt(r.size());
308  for (MSRouteIterator i = r.begin(); i != r.end(); ++i) {
309  tempMsg.writeString((*i)->getID());
310  }
311  }
312  break;
313  case VAR_SIGNALS:
315  tempMsg.writeInt(v->getSignals());
316  break;
317  case VAR_BEST_LANES: {
319  tcpip::Storage tempContent;
320  unsigned int cnt = 0;
321  tempContent.writeUnsignedByte(TYPE_INTEGER);
322  const std::vector<MSVehicle::LaneQ>& bestLanes = onRoad ? v->getBestLanes() : std::vector<MSVehicle::LaneQ>();
323  tempContent.writeInt((int) bestLanes.size());
324  ++cnt;
325  for (std::vector<MSVehicle::LaneQ>::const_iterator i = bestLanes.begin(); i != bestLanes.end(); ++i) {
326  const MSVehicle::LaneQ& lq = *i;
327  tempContent.writeUnsignedByte(TYPE_STRING);
328  tempContent.writeString(lq.lane->getID());
329  ++cnt;
330  tempContent.writeUnsignedByte(TYPE_DOUBLE);
331  tempContent.writeDouble(lq.length);
332  ++cnt;
333  tempContent.writeUnsignedByte(TYPE_DOUBLE);
334  tempContent.writeDouble(lq.nextOccupation);
335  ++cnt;
336  tempContent.writeUnsignedByte(TYPE_BYTE);
337  tempContent.writeByte(lq.bestLaneOffset);
338  ++cnt;
339  tempContent.writeUnsignedByte(TYPE_UBYTE);
340  lq.allowsContinuation ? tempContent.writeUnsignedByte(1) : tempContent.writeUnsignedByte(0);
341  ++cnt;
342  std::vector<std::string> bestContIDs;
343  for (std::vector<MSLane*>::const_iterator j = lq.bestContinuations.begin(); j != lq.bestContinuations.end(); ++j) {
344  bestContIDs.push_back((*j)->getID());
345  }
346  tempContent.writeUnsignedByte(TYPE_STRINGLIST);
347  tempContent.writeStringList(bestContIDs);
348  ++cnt;
349  }
350  tempMsg.writeInt((int) cnt);
351  tempMsg.writeStorage(tempContent);
352  }
353  break;
354  case VAR_STOPSTATE: {
355  char b = (
356  1 * (v->isStopped() ? 1 : 0) +
357  2 * (v->isParking() ? 1 : 0) +
358  4 * (v->isStoppedTriggered() ? 1 : 0));
359  tempMsg.writeUnsignedByte(TYPE_UBYTE);
360  tempMsg.writeUnsignedByte(b);
361  }
362  break;
363  case VAR_DISTANCE: {
365  SUMOReal distance = onRoad ? v->getRoute().getDistanceBetween(0, v->getPositionOnLane(), v->getRoute().getEdges()[0], &v->getLane()->getEdge()) : INVALID_DOUBLE_VALUE;
366  if (distance == std::numeric_limits<SUMOReal>::max()) {
367  distance = INVALID_DOUBLE_VALUE;
368  }
369  tempMsg.writeDouble(distance);
370  }
371  break;
372  case DISTANCE_REQUEST:
373  if (!commandDistanceRequest(server, inputStorage, tempMsg, v)) {
374  return false;
375  }
376  break;
377  case VAR_ALLOWED_SPEED:
379  tempMsg.writeDouble(onRoad ? v->getLane()->getVehicleMaxSpeed(v) : INVALID_DOUBLE_VALUE);
380  break;
381  case VAR_SPEED_FACTOR:
383  tempMsg.writeDouble(v->getChosenSpeedFactor());
384  break;
385  default:
387  break;
388  }
389  }
390  server.writeStatusCmd(CMD_GET_VEHICLE_VARIABLE, RTYPE_OK, "", outputStorage);
391  server.writeResponseWithLength(outputStorage, tempMsg);
392  return true;
393 }
394 
395 
396 bool
398  tcpip::Storage& outputStorage) {
399  std::string warning = ""; // additional description for response
400  // variable
401  int variable = inputStorage.readUnsignedByte();
402  if (variable != CMD_STOP && variable != CMD_CHANGELANE
403  && variable != CMD_SLOWDOWN && variable != CMD_CHANGETARGET && variable != CMD_RESUME
404  && variable != VAR_TYPE && variable != VAR_ROUTE_ID && variable != VAR_ROUTE
405  && variable != VAR_EDGE_TRAVELTIME && variable != VAR_EDGE_EFFORT
406  && variable != CMD_REROUTE_TRAVELTIME && variable != CMD_REROUTE_EFFORT
407  && variable != VAR_SIGNALS && variable != VAR_MOVE_TO
408  && variable != VAR_LENGTH && variable != VAR_MAXSPEED && variable != VAR_VEHICLECLASS
409  && variable != VAR_SPEED_FACTOR && variable != VAR_EMISSIONCLASS
410  && variable != VAR_WIDTH && variable != VAR_MINGAP && variable != VAR_SHAPECLASS
411  && variable != VAR_ACCEL && variable != VAR_DECEL && variable != VAR_IMPERFECTION
412  && variable != VAR_TAU && variable != VAR_LANECHANGE_MODE
413  && variable != VAR_SPEED && variable != VAR_SPEEDSETMODE && variable != VAR_COLOR
414  && variable != ADD && variable != ADD_FULL && variable != REMOVE
415  && variable != VAR_MOVE_TO_VTD
416  ) {
417  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Change Vehicle State: unsupported variable specified", outputStorage);
418  }
419  // id
420  std::string id = inputStorage.readString();
421  const bool shouldExist = variable != ADD && variable != ADD_FULL;
423  if (sumoVehicle == 0) {
424  if (shouldExist) {
425  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not known", outputStorage);
426  }
427  }
428  MSVehicle* v = dynamic_cast<MSVehicle*>(sumoVehicle);
429  if (v == 0 && shouldExist) {
430  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not a micro-simulation vehicle", outputStorage);
431  }
432  switch (variable) {
433  case CMD_STOP: {
434  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
435  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description.", outputStorage);
436  }
437  int compoundSize = inputStorage.readInt();
438  if (compoundSize != 4 && compoundSize != 5) {
439  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description of four of five items.", outputStorage);
440  }
441  // read road map position
442  std::string roadId;
443  if (!server.readTypeCheckingString(inputStorage, roadId)) {
444  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first stop parameter must be the edge id given as a string.", outputStorage);
445  }
446  double pos = 0;
447  if (!server.readTypeCheckingDouble(inputStorage, pos)) {
448  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second stop parameter must be the position along the edge given as a double.", outputStorage);
449  }
450  int laneIndex = 0;
451  if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
452  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The third stop parameter must be the lane index given as a byte.", outputStorage);
453  }
454  // waitTime
455  SUMOTime waitTime = 0;
456  if (!server.readTypeCheckingInt(inputStorage, waitTime)) {
457  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "The fourth stop parameter must be the waiting time given as an integer.", outputStorage);
458  }
459  // optional stop flags
460  bool parking = false;
461  bool triggered = false;
462  if (compoundSize == 5) {
463  int stopFlags;
464  if (!server.readTypeCheckingByte(inputStorage, stopFlags)) {
465  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The fifth stop parameter must be a byte indicating its parking/triggered status.", outputStorage);
466  }
467  parking = ((stopFlags & 1) != 0);
468  triggered = ((stopFlags & 2) != 0);
469  }
470  // check
471  if (pos < 0) {
472  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Position on lane must not be negative.", outputStorage);
473  }
474  // get the actual lane that is referenced by laneIndex
475  MSEdge* road = MSEdge::dictionary(roadId);
476  if (road == 0) {
477  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Unable to retrieve road with given id.", outputStorage);
478  }
479  const std::vector<MSLane*>& allLanes = road->getLanes();
480  if ((laneIndex < 0) || laneIndex >= (int)(allLanes.size())) {
481  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "No lane with index '" + toString(laneIndex) + "' on road '" + roadId + "'.", outputStorage);
482  }
483  // Forward command to vehicle
484  if (!v->addTraciStop(allLanes[laneIndex], pos, 0, waitTime, parking, triggered)) {
485  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Vehicle is too close or behind the stop on '" + allLanes[laneIndex]->getID() + "'.", outputStorage);
486  }
487  }
488  break;
489  case CMD_RESUME: {
490  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
491  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_ERR, "Resuming requires a compound object.", outputStorage);
492  return false;
493  }
494  if (inputStorage.readInt() != 0) {
495  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_ERR, "Resuming should obtain an empty compound object.", outputStorage);
496  return false;
497  }
498  if (!static_cast<MSVehicle*>(v)->resumeFromStopping()) {
499  MSVehicle::Stop& sto = (static_cast<MSVehicle*>(v))->getNextStop();
500  std::ostringstream strs;
501  strs << "reached: " << sto.reached;
502  strs << ", duration:" << sto.duration;
503  strs << ", edge:" << (*sto.edge)->getID();
504  strs << ", startPos: " << sto.startPos;
505  std::string posStr = strs.str();
506  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_ERR, "Failed to resume a non parking vehicle: " + v->getID() + ", " + posStr, outputStorage);
507  return false;
508  }
509  }
510  break;
511  case CMD_CHANGELANE: {
512  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
513  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description.", outputStorage);
514  }
515  if (inputStorage.readInt() != 2) {
516  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description of two items.", outputStorage);
517  }
518  // Lane ID
519  int laneIndex = 0;
520  if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
521  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first lane change parameter must be the lane index given as a byte.", outputStorage);
522  }
523  // stickyTime
524  SUMOTime stickyTime = 0;
525  if (!server.readTypeCheckingInt(inputStorage, stickyTime)) {
526  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second lane change parameter must be the duration given as an integer.", outputStorage);
527  }
528  if ((laneIndex < 0) || (laneIndex >= (int)(v->getEdge()->getLanes().size()))) {
529  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "No lane with index '" + toString(laneIndex) + "' on road '" + v->getEdge()->getID() + "'.", outputStorage);
530  }
531  // Forward command to vehicle
532  std::vector<std::pair<SUMOTime, unsigned int> > laneTimeLine;
533  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
534  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + stickyTime, laneIndex));
535  v->getInfluencer().setLaneTimeLine(laneTimeLine);
536  }
537  break;
538  case CMD_SLOWDOWN: {
539  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
540  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description.", outputStorage);
541  }
542  if (inputStorage.readInt() != 2) {
543  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description of two items.", outputStorage);
544  }
545  double newSpeed = 0;
546  if (!server.readTypeCheckingDouble(inputStorage, newSpeed)) {
547  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first slow down parameter must be the speed given as a double.", outputStorage);
548  }
549  if (newSpeed < 0) {
550  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Speed must not be negative", outputStorage);
551  }
552  SUMOTime duration = 0;
553  if (!server.readTypeCheckingInt(inputStorage, duration)) {
554  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second slow down parameter must be the duration given as an integer.", outputStorage);
555  }
556  if (duration < 0) {
557  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid time interval", outputStorage);
558  }
559  std::vector<std::pair<SUMOTime, SUMOReal> > speedTimeLine;
560  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), v->getSpeed()));
561  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + duration, newSpeed));
562  v->getInfluencer().setSpeedTimeLine(speedTimeLine);
563  }
564  break;
565  case CMD_CHANGETARGET: {
566  std::string edgeID;
567  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
568  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Change target requires a string containing the id of the new destination edge as parameter.", outputStorage);
569  }
570  const MSEdge* destEdge = MSEdge::dictionary(edgeID);
571  if (destEdge == 0) {
572  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Can not retrieve road with ID " + edgeID, outputStorage);
573  }
574  // build a new route between the vehicle's current edge and destination edge
575  MSEdgeVector newRoute;
576  const MSEdge* currentEdge = v->getRerouteOrigin();
578  currentEdge, destEdge, (const MSVehicle * const) v, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
579  // replace the vehicle's route by the new one
580  if (!v->replaceRouteEdges(newRoute, v->getLane() == 0)) {
581  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Route replacement failed for " + v->getID(), outputStorage);
582  }
583  }
584  break;
585  case VAR_TYPE: {
586  std::string vTypeID;
587  if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
588  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle type id must be given as a string.", outputStorage);
589  }
590  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(vTypeID);
591  if (vehicleType == 0) {
592  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle type '" + vTypeID + "' is not known.", outputStorage);
593  }
594  v->replaceVehicleType(vehicleType);
595  }
596  break;
597  case VAR_ROUTE_ID: {
598  std::string rid;
599  if (!server.readTypeCheckingString(inputStorage, rid)) {
600  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The route id must be given as a string.", outputStorage);
601  }
602  const MSRoute* r = MSRoute::dictionary(rid);
603  if (r == 0) {
604  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The route '" + rid + "' is not known.", outputStorage);
605  }
606  if (!v->replaceRoute(r, v->getLane() == 0)) {
607  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Route replacement failed for " + v->getID(), outputStorage);
608  }
609  }
610  break;
611  case VAR_ROUTE: {
612  std::vector<std::string> edgeIDs;
613  if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
614  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "A route must be defined as a list of edge ids.", outputStorage);
615  }
616  std::vector<const MSEdge*> edges;
617  MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
618  if (!v->replaceRouteEdges(edges, v->getLane() == 0)) {
619  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Route replacement failed for " + v->getID(), outputStorage);
620  }
621  }
622  break;
623  case VAR_EDGE_TRAVELTIME: {
624  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
625  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires a compound object.", outputStorage);
626  }
627  int parameterCount = inputStorage.readInt();
628  if (parameterCount == 4) {
629  // begin time
630  SUMOTime begTime = 0, endTime = 0;
631  if (!server.readTypeCheckingInt(inputStorage, begTime)) {
632  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the begin time as first parameter.", outputStorage);
633  }
634  // begin time
635  if (!server.readTypeCheckingInt(inputStorage, endTime)) {
636  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the end time as second parameter.", outputStorage);
637  }
638  // edge
639  std::string edgeID;
640  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
641  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the referenced edge as third parameter.", outputStorage);
642  }
643  MSEdge* edge = MSEdge::dictionary(edgeID);
644  if (edge == 0) {
645  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
646  }
647  // value
648  double value = 0;
649  if (!server.readTypeCheckingDouble(inputStorage, value)) {
650  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the travel time as double as fourth parameter.", outputStorage);
651  }
652  // retrieve
653  v->getWeightsStorage().addTravelTime(edge, begTime, endTime, value);
654  } else if (parameterCount == 2) {
655  // edge
656  std::string edgeID;
657  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
658  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the referenced edge as first parameter.", outputStorage);
659  }
660  MSEdge* edge = MSEdge::dictionary(edgeID);
661  if (edge == 0) {
662  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
663  }
664  // value
665  double value = 0;
666  if (!server.readTypeCheckingDouble(inputStorage, value)) {
667  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the travel time as second parameter.", outputStorage);
668  }
669  // retrieve
670  while (v->getWeightsStorage().knowsTravelTime(edge)) {
672  }
673  v->getWeightsStorage().addTravelTime(edge, 0, SUMOTime_MAX, value);
674  } else if (parameterCount == 1) {
675  // edge
676  std::string edgeID;
677  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
678  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 1 parameter requires the referenced edge as first parameter.", outputStorage);
679  }
680  MSEdge* edge = MSEdge::dictionary(edgeID);
681  if (edge == 0) {
682  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
683  }
684  // retrieve
685  while (v->getWeightsStorage().knowsTravelTime(edge)) {
687  }
688  } else {
689  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires 1, 2, or 4 parameters.", outputStorage);
690  }
691  }
692  break;
693  case VAR_EDGE_EFFORT: {
694  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
695  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort requires a compound object.", outputStorage);
696  }
697  int parameterCount = inputStorage.readInt();
698  if (parameterCount == 4) {
699  // begin time
700  SUMOTime begTime = 0, endTime = 0;
701  if (!server.readTypeCheckingInt(inputStorage, begTime)) {
702  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the begin time as first parameter.", outputStorage);
703  }
704  // begin time
705  if (!server.readTypeCheckingInt(inputStorage, endTime)) {
706  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the end time as second parameter.", outputStorage);
707  }
708  // edge
709  std::string edgeID;
710  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
711  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the referenced edge as third parameter.", outputStorage);
712  }
713  MSEdge* edge = MSEdge::dictionary(edgeID);
714  if (edge == 0) {
715  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
716  }
717  // value
718  double value = 0;
719  if (!server.readTypeCheckingDouble(inputStorage, value)) {
720  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the travel time as fourth parameter.", outputStorage);
721  }
722  // retrieve
723  v->getWeightsStorage().addEffort(edge, begTime, endTime, value);
724  } else if (parameterCount == 2) {
725  // edge
726  std::string edgeID;
727  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
728  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the referenced edge as first parameter.", outputStorage);
729  }
730  MSEdge* edge = MSEdge::dictionary(edgeID);
731  if (edge == 0) {
732  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
733  }
734  // value
735  double value = 0;
736  if (!server.readTypeCheckingDouble(inputStorage, value)) {
737  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the travel time as second parameter.", outputStorage);
738  }
739  // retrieve
740  while (v->getWeightsStorage().knowsEffort(edge)) {
741  v->getWeightsStorage().removeEffort(edge);
742  }
743  v->getWeightsStorage().addEffort(edge, 0, SUMOTime_MAX, value);
744  } else if (parameterCount == 1) {
745  // edge
746  std::string edgeID;
747  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
748  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort using 1 parameter requires the referenced edge as first parameter.", outputStorage);
749  }
750  MSEdge* edge = MSEdge::dictionary(edgeID);
751  if (edge == 0) {
752  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Referenced edge '" + edgeID + "' is not known.", outputStorage);
753  }
754  // retrieve
755  while (v->getWeightsStorage().knowsEffort(edge)) {
756  v->getWeightsStorage().removeEffort(edge);
757  }
758  } else {
759  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort requires 1, 2, or 4 parameters.", outputStorage);
760  }
761  }
762  break;
763  case CMD_REROUTE_TRAVELTIME: {
764  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
765  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);
766  }
767  if (inputStorage.readInt() != 0) {
768  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
769  }
770  v->reroute(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getRouterTT());
771  }
772  break;
773  case CMD_REROUTE_EFFORT: {
774  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
775  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);
776  }
777  if (inputStorage.readInt() != 0) {
778  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
779  }
780  v->reroute(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getRouterEffort());
781  }
782  break;
783  case VAR_SIGNALS: {
784  int signals = 0;
785  if (!server.readTypeCheckingInt(inputStorage, signals)) {
786  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting signals requires an integer.", outputStorage);
787  }
788  v->switchOffSignal(0x0fffffff);
789  v->switchOnSignal(signals);
790  }
791  break;
792  case VAR_MOVE_TO: {
793  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
794  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting position requires a compound object.", outputStorage);
795  }
796  if (inputStorage.readInt() != 2) {
797  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting position should obtain the lane id and the position.", outputStorage);
798  }
799  // lane ID
800  std::string laneID;
801  if (!server.readTypeCheckingString(inputStorage, laneID)) {
802  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first parameter for setting a position must be the lane ID given as a string.", outputStorage);
803  }
804  // position on lane
805  double position = 0;
806  if (!server.readTypeCheckingDouble(inputStorage, position)) {
807  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second parameter for setting a position must be the position given as a double.", outputStorage);
808  }
809  // process
810  MSLane* l = MSLane::dictionary(laneID);
811  if (l == 0) {
812  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Unknown lane '" + laneID + "'.", outputStorage);
813  }
814  MSEdge& destinationEdge = l->getEdge();
815  if (!v->willPass(&destinationEdge)) {
816  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Vehicle '" + laneID + "' may be set onto an edge to pass only.", outputStorage);
817  }
820  while (v->getEdge() != &destinationEdge) {
821  const MSEdge* nextEdge = v->succEdge(1);
822  // let the vehicle move to the next edge
823  if (v->enterLaneAtMove(nextEdge->getLanes()[0], true)) {
825  continue;
826  }
827  }
828  l->forceVehicleInsertion(v, position);
829  }
830  break;
831  case VAR_SPEED: {
832  double speed = 0;
833  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
834  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting speed requires a double.", outputStorage);
835  }
836  std::vector<std::pair<SUMOTime, SUMOReal> > speedTimeLine;
837  if (speed >= 0) {
838  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), speed));
839  speedTimeLine.push_back(std::make_pair(SUMOTime_MAX, speed));
840  }
841  v->getInfluencer().setSpeedTimeLine(speedTimeLine);
842  }
843  break;
844  case VAR_SPEEDSETMODE: {
845  int speedMode = 0;
846  if (!server.readTypeCheckingInt(inputStorage, speedMode)) {
847  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting speed mode requires an integer.", outputStorage);
848  }
849  v->getInfluencer().setConsiderSafeVelocity((speedMode & 1) != 0);
850  v->getInfluencer().setConsiderMaxAcceleration((speedMode & 2) != 0);
851  v->getInfluencer().setConsiderMaxDeceleration((speedMode & 4) != 0);
852  v->getInfluencer().setRespectJunctionPriority((speedMode & 8) != 0);
853  v->getInfluencer().setEmergencyBrakeRedLight((speedMode & 16) != 0);
854  }
855  break;
856  case VAR_LANECHANGE_MODE: {
857  int laneChangeMode = 0;
858  if (!server.readTypeCheckingInt(inputStorage, laneChangeMode)) {
859  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting lane change mode requires an integer.", outputStorage);
860  }
861  v->getInfluencer().setLaneChangeMode(laneChangeMode);
862  }
863  break;
864  case VAR_COLOR: {
865  RGBColor col;
866  if (!server.readTypeCheckingColor(inputStorage, col)) {
867  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The color must be given using the according type.", outputStorage);
868  }
869  v->getParameter().color.set(col.red(), col.green(), col.blue(), col.alpha());
871  }
872  break;
873  case ADD: {
874  if (v != 0) {
875  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle " + id + " to add already exists.", outputStorage);
876  }
877  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
878  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);
879  }
880  if (inputStorage.readInt() != 6) {
881  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle needs six parameters.", outputStorage);
882  }
883  SUMOVehicleParameter vehicleParams;
884  vehicleParams.id = id;
885 
886  std::string vTypeID;
887  if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
888  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);
889  }
890  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(vTypeID);
891  if (!vehicleType) {
892  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid type '" + vTypeID + "' for vehicle '" + id + "'", outputStorage);
893  }
894 
895  std::string routeID;
896  if (!server.readTypeCheckingString(inputStorage, routeID)) {
897  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);
898  }
899  const MSRoute* route = MSRoute::dictionary(routeID);
900  if (!route) {
901  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid route '" + routeID + "' for vehicle: '" + id + "'", outputStorage);
902  }
903 
904  if (!server.readTypeCheckingInt(inputStorage, vehicleParams.depart)) {
905  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Third parameter (depart) requires an integer.", outputStorage);
906  }
907  if (vehicleParams.depart < 0) {
908  const int proc = static_cast<int>(-vehicleParams.depart);
909  if (proc >= static_cast<int>(DEPART_DEF_MAX)) {
910  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid departure time.", outputStorage);
911  }
912  vehicleParams.departProcedure = (DepartDefinition)proc;
913  } else if (vehicleParams.depart < MSNet::getInstance()->getCurrentTimeStep()) {
914  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Departure time in the past.", outputStorage);
915  }
916 
917  double pos;
918  if (!server.readTypeCheckingDouble(inputStorage, pos)) {
919  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (position) requires a double.", outputStorage);
920  }
921  vehicleParams.departPos = pos;
922  if (vehicleParams.departPos < 0) {
923  const int proc = static_cast<int>(-vehicleParams.departPos);
924  if (proc >= static_cast<int>(DEPART_POS_DEF_MAX)) {
925  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid departure position.", outputStorage);
926  }
927  vehicleParams.departPosProcedure = (DepartPosDefinition)proc;
928  } else {
929  vehicleParams.departPosProcedure = DEPART_POS_GIVEN;
930  }
931 
932  double speed;
933  if (!server.readTypeCheckingDouble(inputStorage, speed)) {
934  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (speed) requires a double.", outputStorage);
935  }
936  vehicleParams.departSpeed = speed;
937  if (vehicleParams.departSpeed < 0) {
938  const int proc = static_cast<int>(-vehicleParams.departSpeed);
939  if (proc >= static_cast<int>(DEPART_SPEED_DEF_MAX)) {
940  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid departure speed.", outputStorage);
941  }
942  vehicleParams.departSpeedProcedure = (DepartSpeedDefinition)proc;
943  } else {
945  }
946 
947  if (!server.readTypeCheckingByte(inputStorage, vehicleParams.departLane)) {
948  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (lane) requires a byte.", outputStorage);
949  }
950 
951  if (vehicleParams.departLane < 0) {
952  const int proc = static_cast<int>(-vehicleParams.departLane);
953  if (proc >= static_cast<int>(DEPART_LANE_DEF_MAX)) {
954  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid departure lane.", outputStorage);
955  }
956  vehicleParams.departLaneProcedure = (DepartLaneDefinition)proc;
957  } else {
958  vehicleParams.departLaneProcedure = DEPART_LANE_GIVEN;
959  }
960 
961  SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
962  try {
963  SUMOVehicle* vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(params, route, vehicleType);
964  MSNet::getInstance()->getVehicleControl().addVehicle(vehicleParams.id, vehicle);
966  } catch (ProcessError& e) {
967  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
968  }
969  }
970  break;
971  case ADD_FULL: {
972  if (v != 0) {
973  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The vehicle " + id + " to add already exists.", outputStorage);
974  }
975  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
976  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);
977  }
978  if (inputStorage.readInt() != 14) {
979  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Adding a fully specified vehicle needs fourteen parameters.", outputStorage);
980  }
981  SUMOVehicleParameter vehicleParams;
982  vehicleParams.id = id;
983 
984  std::string routeID;
985  if (!server.readTypeCheckingString(inputStorage, routeID)) {
986  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);
987  }
988  const MSRoute* route = MSRoute::dictionary(routeID);
989  if (!route) {
990  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid route '" + routeID + "' for vehicle: '" + id + "'", outputStorage);
991  }
992 
993  std::string vTypeID;
994  if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
995  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);
996  }
997  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(vTypeID);
998  if (!vehicleType) {
999  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Invalid type '" + vTypeID + "' for vehicle '" + id + "'", outputStorage);
1000  }
1001 
1002  std::string helper;
1003  std::string error;
1004  if (!server.readTypeCheckingString(inputStorage, helper)) {
1005  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Third parameter (depart) requires an string.", outputStorage);
1006  }
1007  if (!SUMOVehicleParameter::parseDepart(helper, "vehicle", id, vehicleParams.depart, vehicleParams.departProcedure, error)) {
1008  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1009  }
1010  if (vehicleParams.departProcedure == DEPART_GIVEN && vehicleParams.depart < MSNet::getInstance()->getCurrentTimeStep()) {
1011  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Departure time in the past.", outputStorage);
1012  }
1013 
1014  if (!server.readTypeCheckingString(inputStorage, helper)) {
1015  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (depart lane) requires a string.", outputStorage);
1016  }
1017  if (!SUMOVehicleParameter::parseDepartLane(helper, "vehicle", id, vehicleParams.departLane, vehicleParams.departLaneProcedure, error)) {
1018  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1019  }
1020  if (!server.readTypeCheckingString(inputStorage, helper)) {
1021  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (depart position) requires a string.", outputStorage);
1022  }
1023  if (!SUMOVehicleParameter::parseDepartPos(helper, "vehicle", id, vehicleParams.departPos, vehicleParams.departPosProcedure, error)) {
1024  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1025  }
1026  if (!server.readTypeCheckingString(inputStorage, helper)) {
1027  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (depart speed) requires a string.", outputStorage);
1028  }
1029  if (!SUMOVehicleParameter::parseDepartSpeed(helper, "vehicle", id, vehicleParams.departSpeed, vehicleParams.departSpeedProcedure, error)) {
1030  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1031  }
1032 
1033  if (!server.readTypeCheckingString(inputStorage, helper)) {
1034  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Seventh parameter (arrival lane) requires a string.", outputStorage);
1035  }
1036  if (!SUMOVehicleParameter::parseArrivalLane(helper, "vehicle", id, vehicleParams.arrivalLane, vehicleParams.arrivalLaneProcedure, error)) {
1037  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1038  }
1039  if (!server.readTypeCheckingString(inputStorage, helper)) {
1040  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Eighth parameter (arrival position) requires a string.", outputStorage);
1041  }
1042  if (!SUMOVehicleParameter::parseArrivalPos(helper, "vehicle", id, vehicleParams.arrivalPos, vehicleParams.arrivalPosProcedure, error)) {
1043  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1044  }
1045  if (!server.readTypeCheckingString(inputStorage, helper)) {
1046  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Ninth parameter (arrival speed) requires a string.", outputStorage);
1047  }
1048  if (!SUMOVehicleParameter::parseArrivalSpeed(helper, "vehicle", id, vehicleParams.arrivalSpeed, vehicleParams.arrivalSpeedProcedure, error)) {
1049  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, error, outputStorage);
1050  }
1051 
1052  if (!server.readTypeCheckingString(inputStorage, vehicleParams.fromTaz)) {
1053  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Tenth parameter (from taz) requires a string.", outputStorage);
1054  }
1055  if (!server.readTypeCheckingString(inputStorage, vehicleParams.toTaz)) {
1056  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Eleventh parameter (to taz) requires a string.", outputStorage);
1057  }
1058  if (!server.readTypeCheckingString(inputStorage, vehicleParams.line)) {
1059  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Twelth parameter (line) requires a string.", outputStorage);
1060  }
1061 
1062  int num;
1063  if (!server.readTypeCheckingInt(inputStorage, num)) {
1064  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "13th parameter (person capacity) requires an int.", outputStorage);
1065  }
1066  vehicleParams.personCapacity = num;
1067  if (!server.readTypeCheckingInt(inputStorage, num)) {
1068  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "14th parameter (person number) requires an int.", outputStorage);
1069  }
1070  vehicleParams.personNumber = num;
1071 
1072  SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
1073  try {
1074  SUMOVehicle* vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(params, route, vehicleType);
1075  MSNet::getInstance()->getVehicleControl().addVehicle(vehicleParams.id, vehicle);
1077  } catch (ProcessError& e) {
1078  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1079  }
1080  }
1081  break;
1082  case REMOVE: {
1083  int why = 0;
1084  if (!server.readTypeCheckingByte(inputStorage, why)) {
1085  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Removing a vehicle requires a byte.", outputStorage);
1086  }
1088  switch (why) {
1089  case REMOVE_TELEPORT:
1090  // XXX semantics unclear
1091  // n = MSMoveReminder::NOTIFICATION_TELEPORT;
1093  break;
1094  case REMOVE_PARKING:
1095  // XXX semantics unclear
1096  // n = MSMoveReminder::NOTIFICATION_PARKING;
1098  break;
1099  case REMOVE_ARRIVED:
1101  break;
1102  case REMOVE_VAPORIZED:
1104  break;
1107  break;
1108  default:
1109  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Unknown removal status.", outputStorage);
1110  }
1111  if (v->hasDeparted()) {
1112  v->onRemovalFromNet(n);
1113  if (v->getLane() != 0) {
1114  v->getLane()->removeVehicle(v, n);
1115  }
1117  }
1118  }
1119  break;
1120  case VAR_MOVE_TO_VTD: {
1121  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
1122  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting VTD vehicle requires a compound object.", outputStorage);
1123  }
1124  if (inputStorage.readInt() != 4) {
1125  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting VTD vehicle should obtain: edgeID, lane, x, y.", outputStorage);
1126  }
1127  // edge ID
1128  std::string edgeID;
1129  if (!server.readTypeCheckingString(inputStorage, edgeID)) {
1130  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The first parameter for setting a VTD vehicle must be the edge ID given as a string.", outputStorage);
1131  }
1132  // lane index
1133  int laneNum = 0;
1134  if (!server.readTypeCheckingInt(inputStorage, laneNum)) {
1135  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The second parameter for setting a VTD vehicle must be lane given as an int.", outputStorage);
1136  }
1137  // x
1138  double x = 0, y = 0;
1139  if (!server.readTypeCheckingDouble(inputStorage, x)) {
1140  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The third parameter for setting a VTD vehicle must be the x-position given as a double.", outputStorage);
1141  }
1142  // y
1143  if (!server.readTypeCheckingDouble(inputStorage, y)) {
1144  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for setting a VTD vehicle must be the y-position given as a double.", outputStorage);
1145  }
1146  // process
1147  if (!v->isOnRoad()) {
1148  break;
1149  }
1150  std::string origID = edgeID + " " + toString(laneNum);
1151  if (laneNum < 0) {
1152  edgeID = '-' + edgeID;
1153  laneNum = -laneNum;
1154  }
1155  Position pos(x, y);
1156 
1157  Position vehPos = v->getPosition();
1158  v->getBestLanes();
1159  bool report = server.vtdDebug();
1160  if (report) {
1161  std::cout << std::endl << "begin vehicle " << v->getID() << " vehPos:" << vehPos << " lane:" << v->getLane()->getID() << std::endl;
1162  }
1163  if (report) {
1164  std::cout << " want pos:" << pos << " edge:" << edgeID << " laneNum:" << laneNum << std::endl;
1165  }
1166 
1167  MSEdgeVector edgesA, edgesB, edgesC;
1168  MSLane* laneA, *laneB, *laneC;
1169  laneA = laneB = laneC = 0;
1170  SUMOReal lanePosA, lanePosB, lanePosC;
1171  SUMOReal bestDistanceA, bestDistanceB, bestDistanceC;
1172  bestDistanceA = bestDistanceB = bestDistanceC = 1000.;//pos.distanceSquaredTo2D(vehPos);
1173  int routeOffsetA, routeOffsetB, routeOffsetC;
1174  routeOffsetA = routeOffsetB = routeOffsetC = 0;
1175  // case a): edge/lane is known and matches route
1176  bool aFound = vtdMap_matchingEdgeLane(pos, origID, *v, server.vtdDebug(), bestDistanceA, &laneA, lanePosA, routeOffsetA, edgesA);
1177  // case b): position is at route, should be somewhere near to it
1178  bool bFound = vtdMap_matchingRoutePosition(pos, origID, *v, server.vtdDebug(), bestDistanceB, &laneB, lanePosB, routeOffsetB, edgesB);
1179  // case c) nearest matching lane
1180  bool cFound = vtdMap_matchingNearest(pos, origID, *v, server, server.vtdDebug(), bestDistanceC, &laneC, lanePosC, routeOffsetC, edgesC);
1181  //
1182  SUMOReal maxRouteDistance = 50;
1183  if (cFound && (bestDistanceA > maxRouteDistance && bestDistanceC > maxRouteDistance)) {
1184  // both route-based approach yield in a position too far away from the submitted --> new route!?
1185  server.setVTDControlled(v, laneC, lanePosC, routeOffsetC, edgesC);
1186  } else {
1187  // use the best we have
1188  if (bFound) {
1189  server.setVTDControlled(v, laneB, lanePosB, routeOffsetB, edgesB);
1190  } else if (aFound) {
1191  server.setVTDControlled(v, laneA, lanePosA, routeOffsetA, edgesA);
1192  } else if (cFound) {
1193  server.setVTDControlled(v, laneC, lanePosC, routeOffsetC, edgesC);
1194  } else {
1195  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Could not map vehicle.", outputStorage);
1196  }
1197  }
1198  }
1199  break;
1200  case VAR_SPEED_FACTOR: {
1201  double factor = 0;
1202  if (!server.readTypeCheckingDouble(inputStorage, factor)) {
1203  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting speed factor requires a double.", outputStorage);
1204  }
1205  v->setChosenSpeedFactor(factor);
1206  }
1207  break;
1208  default:
1209  try {
1210  if (!TraCIServerAPI_VehicleType::setVariable(CMD_SET_VEHICLE_VARIABLE, variable, getSingularType(v), server, inputStorage, outputStorage)) {
1211  return false;
1212  }
1213  } catch (ProcessError& e) {
1214  return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1215  }
1216  break;
1217  }
1218  server.writeStatusCmd(CMD_SET_VEHICLE_VARIABLE, RTYPE_OK, warning, outputStorage);
1219  return true;
1220 }
1221 
1222 
1223 bool
1224 TraCIServerAPI_Vehicle::vtdMap_matchingEdgeLane(const Position& pos, const std::string& origID, MSVehicle& v, bool report,
1225  SUMOReal& bestDistance, MSLane** lane, SUMOReal& lanePos, int& routeOffset, MSEdgeVector& edges) {
1226  UNUSED_PARAMETER(edges);
1227  const std::map<std::string, std::vector<MSLane*> >& vtdMap = getOrBuildVTDMap();
1228  if (vtdMap.find(origID) == vtdMap.end()) {
1229  if (report) {
1230  std::cout << " a failed - lane not in map" << std::endl;
1231  }
1232  return false;
1233  }
1234  const std::vector<MSLane*>& lanes = vtdMap.find(origID)->second;
1235  for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end() && bestDistance > POSITION_EPS; ++i) {
1236  MSLane* l = *i;
1237  SUMOReal dist = l->getShape().distance(pos);
1238  if (report) {
1239  std::cout << " a at lane " << l->getID() << " dist:" << dist << " best:" << bestDistance << std::endl;
1240  }
1241  if (dist < bestDistance) {
1242  bestDistance = dist;
1243  *lane = l;
1244  }
1245  }
1246  MSLane* pni = *lane;
1247  while (pni != 0 && pni->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL && pni->getIncomingLanes().size() != 0) {
1248  pni = pni->getIncomingLanes()[0].lane;
1249  }
1250  if (pni == 0 || pni->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
1251  // not found
1252  if (report) {
1253  std::cout << " a failed - no incoming lane" << std::endl;
1254  }
1255  return false;
1256  }
1257  const MSEdgeVector& tedges = v.getRoute().getEdges();
1258  MSEdgeVector::const_iterator p = std::find(tedges.begin() + v.getRoutePosition(), tedges.end(), &pni->getEdge());
1259  if (p != tedges.end()) {
1260  lanePos = MAX2(SUMOReal(0), MIN2(SUMOReal((*lane)->getLength() - POSITION_EPS), (*lane)->getShape().nearest_offset_to_point2D(pos, false)));
1261  routeOffset = (int)(std::distance(tedges.begin(), p) - v.getRoutePosition());
1262  if (report) {
1263  std::cout << " a ok lane:" << (*lane)->getID() << " lanePos:" << lanePos << " routeOffset:" << routeOffset << std::endl;
1264  }
1265  return true;
1266  }
1267  if (report) {
1268  std::cout << " a failed - route position beyond route length" << std::endl;
1269  }
1270  return false;
1271 }
1272 
1273 
1274 bool
1275 TraCIServerAPI_Vehicle::vtdMap_matchingRoutePosition(const Position& pos, const std::string& origID, MSVehicle& v, bool report,
1276  SUMOReal& bestDistance, MSLane** lane, SUMOReal& lanePos, int& routeOffset, MSEdgeVector& edges) {
1277  UNUSED_PARAMETER(edges);
1278  UNUSED_PARAMETER(origID);
1279  int lastBestRouteEdge = 0;
1280  int lastRouteEdge = 0;
1281  MSLane* bestRouteLane = 0;
1282  const std::vector<MSLane*>& bestLaneConts = v.getBestLanesContinuation(v.getLane());
1283  for (std::vector<MSLane*>::const_iterator i = bestLaneConts.begin(); i != bestLaneConts.end() && bestDistance > POSITION_EPS; ++i) {
1284  MSEdge& e = (*i)->getEdge();
1285  if (i != bestLaneConts.begin() && e.getPurpose() != MSEdge::EDGEFUNCTION_INTERNAL) {
1286  ++lastRouteEdge;
1287  }
1288  const std::vector<MSLane*>& lanes = e.getLanes();
1289  for (std::vector<MSLane*>::const_iterator k = lanes.begin(); k != lanes.end() && bestDistance > POSITION_EPS; ++k) {
1290  MSLane* cl = *k;
1291  SUMOReal dist = cl->getShape().distance(pos);
1292  if (report) {
1293  std::cout << " b at lane " << cl->getID() << " dist:" << dist << " best:" << bestDistance << std::endl;
1294  }
1295  if (dist < bestDistance) {
1296  bestDistance = dist;
1297  *lane = cl;
1298  lastBestRouteEdge = lastRouteEdge;
1300  bestRouteLane = *i;
1301  } else {
1302  bestRouteLane = *lane;
1303  }
1304  }
1305  }
1306  }
1307  if (bestRouteLane == 0) {
1308  if (report) {
1309  std::cout << " b failed - no best route lane" << std::endl;
1310  }
1311  return false;
1312  }
1313  lanePos = MAX2(SUMOReal(0), MIN2(SUMOReal(bestRouteLane->getLength() - POSITION_EPS), bestRouteLane->getShape().nearest_offset_to_point2D(pos, false)));
1314  routeOffset = lastBestRouteEdge;
1315  if (report) {
1316  std::cout << " b ok lane " << bestRouteLane->getID() << " lanePos:" << lanePos << " best:" << lastBestRouteEdge << std::endl;
1317  }
1318  return true;
1319 }
1320 
1321 
1322 bool
1323 TraCIServerAPI_Vehicle::vtdMap_matchingNearest(const Position& pos, const std::string& origID, MSVehicle& v, TraCIServer& server, bool report,
1324  SUMOReal& bestDistance, MSLane** lane, SUMOReal& lanePos, int& routeOffset, MSEdgeVector& edges) {
1325  UNUSED_PARAMETER(bestDistance);
1326  unsigned int r = 0;
1327  SUMOReal minDist = 1 << (11);
1328  MSLane* minDistLane = 0;
1329  MSLane* nameMatchingLane = 0;
1330  SUMOReal minDistNameMatchingLane = 1 << (11);
1331  for (; minDistLane == 0 && r < 10 && nameMatchingLane == 0; ++r) {
1332  std::set<std::string> into;
1333  PositionVector shape;
1334  shape.push_back(pos);
1335  server.collectObjectsInRange(CMD_GET_EDGE_VARIABLE, shape, 1 << r, into);
1336  for (std::set<std::string>::const_iterator j = into.begin(); j != into.end(); ++j) {
1337  MSEdge* e = MSEdge::dictionary(*j);
1338  const std::vector<MSLane*>& lanes = e->getLanes();
1339  for (std::vector<MSLane*>::const_iterator k = lanes.begin(); k != lanes.end(); ++k) {
1340  MSLane* lane = *k;
1341  SUMOReal dist = lane->getShape().distance(pos);
1342  if (lane->knowsParameter("origId")) {
1343  if (lane->getParameter("origId", "") == origID) {
1344  if (dist < minDistNameMatchingLane) {
1345  minDistNameMatchingLane = dist;
1346  nameMatchingLane = lane;
1347  }
1348  }
1349  }
1350  if (dist < minDist) {
1351  minDist = dist;
1352  minDistLane = lane;
1353  }
1354  }
1355  }
1356  }
1357  *lane = nameMatchingLane != 0 ? nameMatchingLane : minDistLane;
1358  if (lane == 0) {
1359  if (report) {
1360  std::cout << " c failed - no matching lane" << std::endl;
1361  }
1362  return false;
1363  }
1364  lanePos = (*lane)->interpolateGeometryPosToLanePos((*lane)->getShape().nearest_offset_to_point2D(pos, false));
1365  if (*lane == v.getLane()) {
1366  routeOffset = 0;
1367  if (report) {
1368  std::cout << " c ok, on same lane" << std::endl;
1369  }
1370  return true;
1371  }
1372  MSEdge& destinationEdge = (*lane)->getEdge();
1373  MSEdge* routePos = &destinationEdge;
1374  while (routePos->getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
1375  routePos = &routePos->getLanes()[0]->getLogicalPredecessorLane()->getEdge();
1376  }
1377  r = 0;
1378  const MSRoute& route = v.getRoute();
1379  unsigned int c = v.getRoutePosition();
1380  unsigned int l = (int)route.getEdges().size();
1381  unsigned int rindex = 0;
1382  bool found = false;
1383  while (!found && ((int)(c - r) >= 0 || c + r < l)) {
1384  if ((int)(c - r) >= 0 && route[c - r] == routePos) {
1385  rindex = c - r;
1386  found = true;
1387  }
1388  if (c + r < l && route[c + r] == routePos) {
1389  rindex = c + r;
1390  found = true;
1391  }
1392  ++r;
1393  }
1394  if (found) {
1395  // the matching lane is part of the route
1396  routeOffset = rindex - v.getRoutePosition();
1397  if (report) {
1398  std::cout << " c ok, on a different edge of same route" << std::endl;
1399  }
1400  return true;
1401  }
1402  // build new route
1403  MSLane* firstLane = *lane;
1404  if (destinationEdge.getPurpose() != MSEdge::EDGEFUNCTION_INTERNAL) {
1405  edges.push_back(&destinationEdge);
1406  } else {
1407  firstLane = (*lane)->getLogicalPredecessorLane();
1408  edges.push_back(&firstLane->getEdge());
1409  }
1410  const MSLinkCont& lc = firstLane->getLinkCont();
1411  if (lc.size() != 0 && lc[0]->getLane() != 0) {
1412  edges.push_back(&lc[0]->getLane()->getEdge());
1413  }
1414  if (report) {
1415  std::cout << " c ok, on a different route" << std::endl;
1416  }
1417  return true;
1418 }
1419 
1420 
1421 bool
1423  tcpip::Storage& outputStorage, const MSVehicle* v) {
1424  if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
1425  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of distance requires a compound object.", outputStorage);
1426  }
1427  if (inputStorage.readInt() != 2) {
1428  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Retrieval of distance requires position and distance type as parameter.", outputStorage);
1429  }
1430 
1431  Position pos;
1432  std::pair<const MSLane*, SUMOReal> roadPos;
1433 
1434  // read position
1435  int posType = inputStorage.readUnsignedByte();
1436  switch (posType) {
1437  case POSITION_ROADMAP:
1438  try {
1439  std::string roadID = inputStorage.readString();
1440  roadPos.second = inputStorage.readDouble();
1441  roadPos.first = TraCIServerAPI_Simulation::getLaneChecking(roadID, inputStorage.readUnsignedByte(), roadPos.second);
1442  pos = roadPos.first->getShape().positionAtOffset(roadPos.second);
1443  } catch (TraCIException& e) {
1444  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, e.what(), outputStorage);
1445  }
1446  break;
1447  case POSITION_2D:
1448  case POSITION_3D: {
1449  const double p1x = inputStorage.readDouble();
1450  const double p1y = inputStorage.readDouble();
1451  pos.set(p1x, p1y);
1452  }
1453  if (posType == POSITION_3D) {
1454  inputStorage.readDouble(); // z value is ignored
1455  }
1457  break;
1458  default:
1459  return server.writeErrorStatusCmd(CMD_GET_VEHICLE_VARIABLE, "Unknown position format used for distance request", outputStorage);
1460  }
1461 
1462  // read distance type
1463  int distType = inputStorage.readUnsignedByte();
1464 
1465  SUMOReal distance = INVALID_DOUBLE_VALUE;
1466  if (v->isOnRoad()) {
1467  if (distType == REQUEST_DRIVINGDIST) {
1468  distance = v->getRoute().getDistanceBetween(v->getPositionOnLane(), roadPos.second,
1469  v->getEdge(), &roadPos.first->getEdge());
1470  if (distance == std::numeric_limits<SUMOReal>::max()) {
1471  distance = INVALID_DOUBLE_VALUE;
1472  }
1473  } else {
1474  // compute air distance (default)
1475  distance = v->getPosition().distanceTo(pos);
1476  }
1477  }
1478  // write response command
1479  outputStorage.writeUnsignedByte(TYPE_DOUBLE);
1480  outputStorage.writeDouble(distance);
1481  return true;
1482 }
1483 
1484 
1485 // ------ helper functions ------
1486 bool
1487 TraCIServerAPI_Vehicle::getPosition(const std::string& id, Position& p) {
1488  MSVehicle* v = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(id));
1489  if (v == 0) {
1490  return false;
1491  }
1492  p = v->getPosition();
1493  return true;
1494 }
1495 
1496 
1499  const MSVehicleType& oType = veh->getVehicleType();
1500  std::string newID = oType.getID().find('@') == std::string::npos ? oType.getID() + "@" + veh->getID() : oType.getID();
1501  MSVehicleType* type = MSVehicleType::build(newID, &oType);
1502  static_cast<MSVehicle*>(veh)->replaceVehicleType(type);
1503  return *type;
1504 }
1505 
1506 
1507 #include <microsim/MSEdgeControl.h>
1508 
1509 const std::map<std::string, std::vector<MSLane*> >&
1511  if (gVTDMap.size() == 0) {
1512  const std::vector<MSEdge*>& edges = MSNet::getInstance()->getEdgeControl().getEdges();
1513  for (std::vector<MSEdge*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
1514  const std::vector<MSLane*>& lanes = (*i)->getLanes();
1515  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1516  if ((*j)->knowsParameter("origId")) {
1517  std::string origID = (*j)->getParameter("origId", "");
1518  if (gVTDMap.find(origID) == gVTDMap.end()) {
1519  gVTDMap[origID] = std::vector<MSLane*>();
1520  }
1521  gVTDMap[origID].push_back(*j);
1522  }
1523  }
1524  }
1525  if (gVTDMap.size() == 0) {
1526  gVTDMap["unknown"] = std::vector<MSLane*>();
1527  }
1528  }
1529  return gVTDMap;
1530 }
1531 
1532 
1533 #endif
1534 
1535 
1536 /****************************************************************************/
1537 
#define VAR_ROAD_ID
void forceVehicleInsertion(MSVehicle *veh, SUMOReal pos)
Inserts the given vehicle at the given position.
Definition: MSLane.cpp:606
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.
void setChosenSpeedFactor(SUMOReal factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
#define REMOVE_PARKING
virtual const std::vector< LaneQ > & getBestLanes(bool forceRebuild=false, MSLane *startLane=0) const
Returns the description of best lanes to use in order to continue the route.
Definition: MSVehicle.cpp:1752
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
Definition: MSVehicle.cpp:2232
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:1593
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:452
RGBColor color
The vehicle's color.
static bool commandDistanceRequest(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, const MSVehicle *v)
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
#define VAR_EMISSIONCLASS
void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, bool withTaz=false)
Performs a rerouting using the given router.
static bool vtdMap_matchingRoutePosition(const Position &pos, const std::string &origID, MSVehicle &v, bool report, SUMOReal &bestDistance, MSLane **lane, SUMOReal &lanePos, int &routeOffset, MSEdgeVector &edges)
#define VAR_CO2EMISSION
#define REQUEST_DRIVINGDIST
#define VAR_LENGTH
void collectObjectsInRange(int domain, const PositionVector &shape, SUMOReal range, std::set< std::string > &into)
The time is given.
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, SUMOReal &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
#define RESPONSE_GET_VEHICLE_VARIABLE
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
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.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
#define CMD_RESUME
#define POSITION_2D
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc4: Change Vehicle State)
#define VAR_POSITION
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
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:464
#define VAR_ROUTE
#define CMD_CHANGELANE
bool readTypeCheckingColor(tcpip::Storage &inputStorage, RGBColor &into)
Reads the value type and a color, verifying the type.
#define VAR_SPEEDSETMODE
#define VAR_TAU
MSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:59
SUMOReal getSpeedWithoutTraciInfluence() const
Returns the uninfluenced velocity.
Definition: MSVehicle.cpp:2302
void setRespectJunctionPriority(bool value)
Sets whether junction priority rules shall be respected.
Definition: MSVehicle.cpp:323
bool retrieveExistingTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t, SUMOReal &value) const
Returns a travel time for an edge and time if stored.
#define CMD_STOP
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
SUMOReal getLength() const
Returns the lane's length.
Definition: MSLane.h:370
Position getPosition(const SUMOReal offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:612
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
unsigned int personCapacity
The vehicle's capacity (persons)
#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()
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID)
Returns the named vehicle type or a sample from the named distribution.
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:1011
#define VAR_VEHICLECLASS
bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0)
Replaces the current route by the given one.
Definition: MSVehicle.cpp:465
const MSEdgeVector & getEdges() const
Definition: MSRoute.h:122
#define VAR_SPEED_FACTOR
#define VAR_COLOR
SUMOReal getHCEmissions() const
Returns HC emission of the current state.
Definition: MSVehicle.cpp:2141
static bool getPosition(const std::string &id, Position &p)
Returns the named vehicle's position.
bool reached
Information whether the stop has been reached.
Definition: MSVehicle.h:571
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:154
T MAX2(T a, T b)
Definition: StdDefs.h:71
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:86
unsigned int getPersonNumber() const
Returns the number of persons.
Definition: MSVehicle.cpp:2194
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
#define TYPE_COLOR
#define TYPE_STRINGLIST
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
bool hasDeparted() const
Returns whether this vehicle has already departed.
The vehicle got vaporized.
#define POSITION_3D
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary...
Definition: MSEdge.cpp:465
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:551
#define VAR_BEST_LANES
SUMOReal getCO2Emissions() const
Returns CO2 emission of the current state.
Definition: MSVehicle.cpp:2129
unsigned int personNumber
The number of persons in the vehicle.
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:2095
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:219
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:283
virtual void writeUnsignedByte(int)
SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSEdge *fromEdge, const MSEdge *toEdge) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:264
bool retrieveExistingEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t, SUMOReal &value) const
Returns an effort for an edge and time if stored.
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:210
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
#define VAR_SPEED_DEVIATION
SUMOReal length
The overall length which may be driven when using this lane without a lane change.
Definition: MSVehicle.h:458
#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.
const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
Definition: MSVehicle.h:346
virtual void writeInt(int)
The speed is given.
The car-following model and parameter.
Definition: MSVehicleType.h:74
#define TYPE_STRING
virtual int readUnsignedByte()
std::string toTaz
The vehicle's destination zone (district)
The lane is given.
void addTravelTime(const MSEdge *const e, SUMOReal begin, SUMOReal end, SUMOReal value)
Adds a travel time information for an edge and a time span.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa4: Get Vehicle Variable)
SUMOReal nextOccupation
As occupation, but without the first lane.
Definition: MSVehicle.h:462
#define VAR_NOXEMISSION
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type)
Builds a vehicle, increases the number of built vehicles.
#define VAR_ANGLE
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:73
static void parseEdgesList(const std::string &desc, std::vector< const MSEdge * > &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:528
MSLane * lane
The described lane.
Definition: MSVehicle.h:456
#define VAR_PERSON_NUMBER
#define CMD_SLOWDOWN
MSLane * getLogicalPredecessorLane() const
Definition: MSLane.cpp:1224
#define VAR_SHAPECLASS
#define max(a, b)
Definition: polyfonts.c:61
void setEmergencyBrakeRedLight(bool value)
Sets whether red lights shall be a reason to brake.
Definition: MSVehicle.cpp:329
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
#define REMOVE_ARRIVED
DepartLaneDefinition
Possible ways to choose a lane on depart.
#define VAR_ACCEL
bool addTraciStop(MSLane *lane, SUMOReal pos, SUMOReal radius, SUMOTime duration, bool parking, bool triggered)
Definition: MSVehicle.cpp:2248
#define CMD_CHANGETARGET
Representation of a vehicle.
Definition: SUMOVehicle.h:63
virtual int readInt()
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
#define REMOVE_TELEPORT_ARRIVED
std::vector< const MSEdge * > MSEdgeVector
Definition: MSPerson.h:53
void setLaneTimeLine(const std::vector< std::pair< SUMOTime, unsigned int > > &laneTimeLine)
Sets a new lane timeline.
Definition: MSVehicle.cpp:176
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the subpart of best lanes that describes the vehicle's current lane and their successors...
Definition: MSVehicle.cpp:2025
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:85
bool willPass(const MSEdge *const edge) const
Returns whether the vehicle wil pass the given edge.
Definition: MSVehicle.cpp:514
#define VAR_LANEPOSITION
A list of positions.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:263
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:99
virtual void writeByte(int)
#define REMOVE_TELEPORT
const MSEdge * succEdge(unsigned int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
The vehicle arrived at its destination (is deleted)
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MSVehicle.cpp:751
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
SUMOReal distance(const Position &p) const
virtual void writeStringList(const std::vector< std::string > &s)
SUMOTime depart
The vehicle's departure time.
#define VAR_PMXEMISSION
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime duration
The stopping duration.
Definition: MSVehicle.h:563
#define CMD_SET_VEHICLE_VARIABLE
T MIN2(T a, T b)
Definition: StdDefs.h:65
#define VAR_IMPERFECTION
#define POSITION_EPS
Definition: config.h:186
std::string fromTaz
The vehicle's origin zone (district)
virtual std::string readString()
void setVTDControlled(MSVehicle *v, MSLane *l, SUMOReal pos, int edgeOffset, MSEdgeVector route)
#define CMD_GET_EDGE_VARIABLE
Tag for the last element in the enum for safe int casting.
A structure representing the best lanes for continuing the route.
Definition: MSVehicle.h:454
#define VAR_EDGES
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:446
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
#define VAR_EDGE_EFFORT
#define CMD_REROUTE_EFFORT
#define VAR_STOPSTATE
#define ADD
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:52
#define REMOVE
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:74
const int VEHPARS_COLOR_SET
virtual void writeStorage(tcpip::Storage &store)
#define VAR_LEADER
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:757
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.
bool allowsContinuation
Whether this lane allows to continue the drive.
Definition: MSVehicle.h:466
SUMOReal getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
Definition: MSVehicle.cpp:2165
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
std::string line
The vehicle's line (mainly for public transport)
#define INVALID_DOUBLE_VALUE
#define VAR_SPEED
DepartSpeedDefinition
Possible ways to choose the departure speed.
SUMOReal getNOxEmissions() const
Returns NOx emission of the current state.
Definition: MSVehicle.cpp:2147
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
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:2153
SUMOReal getCOEmissions() const
Returns CO emission of the current state.
Definition: MSVehicle.cpp:2135
#define VAR_EDGE_TRAVELTIME
void push_back(const PositionVector &p)
Appends all positions from the given vector.
static bool vtdMap_matchingNearest(const Position &pos, const std::string &origID, MSVehicle &v, TraCIServer &server, bool report, SUMOReal &bestDistance, MSLane **lane, SUMOReal &lanePos, int &routeOffset, MSEdgeVector &edges)
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:829
#define VAR_COEMISSION
bool replaceRouteEdges(MSEdgeVector &edges, bool onInit=false)
Replaces the current route by the given edges.
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, SUMOReal > > &speedTimeLine)
Sets a new velocity timeline.
Definition: MSVehicle.cpp:169
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:204
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:2293
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
Structure representing possible vehicle parameter.
#define INVALID_INT_VALUE
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
#define VAR_MOVE_TO
#define SUMOTime_MAX
Definition: SUMOTime.h:44
#define TYPE_DOUBLE
void setConsiderMaxDeceleration(bool value)
Sets whether the maximum deceleration shall be regarded.
Definition: MSVehicle.cpp:317
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:294
int setParameter
Information for the router which parameter were set.
#define CMD_REROUTE_TRAVELTIME
std::vector< MSLane * > bestContinuations
Consecutive lane that can be followed without a lane change (contribute to length and occupation) ...
Definition: MSVehicle.h:468
#define TYPE_BYTE
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
SUMOReal getFuelConsumption() const
Returns fuel consumption of the current state.
Definition: MSVehicle.cpp:2159
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:94
void set(SUMOReal x, SUMOReal y)
Definition: Position.h:78
void setConsiderSafeVelocity(bool value)
Sets whether the safe velocity shall be regarded.
Definition: MSVehicle.cpp:305
MSRouteIterator edge
The edge in the route to stop at.
Definition: MSVehicle.h:553
SUMOReal getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
const std::string & getID() const
Returns the name of the vehicle type.
static bool vtdMap_matchingEdgeLane(const Position &pos, const std::string &origID, MSVehicle &v, bool report, SUMOReal &bestDistance, MSLane **lane, SUMOReal &lanePos, int &routeOffset, MSEdgeVector &edges)
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
Definition: MSNet.cpp:712
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:291
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
SUMOReal departPos
(optional) The position the vehicle shall depart from
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void setLaneChangeMode(int value)
Sets lane changing behavior.
Definition: MSVehicle.cpp:335
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:373
virtual void writeDouble(double)
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MSVehicle.cpp:763
#define REMOVE_VAPORIZED
unsigned size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:86
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:323
#define VAR_MOVE_TO_VTD
const std::vector< MSEdge * > & getEdges() const
Returns loaded edges.
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
bool hasValidRoute(std::string &msg) const
Validates the current route.
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:791
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
#define SUMOReal
Definition: config.h:215
void switchOffSignal(int signal)
Switches the given signal off.
Definition: MSVehicle.h:783
void switchOnSignal(int signal)
Switches the given signal on.
Definition: MSVehicle.h:775
virtual void 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...
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
#define VAR_SPEED_WITHOUT_TRACI
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:284
#define VAR_LANECHANGE_MODE
#define VAR_MAXSPEED
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
The vehicle was teleported out of the net.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:998
#define VAR_DECEL
#define VAR_ROUTE_VALID
The class responsible for building and deletion of vehicles.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
#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.
bool vtdDebug() const
#define VAR_LANE_ID
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition: MSLane.h:354
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:336
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:328
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:579
The edge is an internal edge.
Definition: MSEdge.h:90
static const std::map< std::string, std::vector< MSLane * > > & getOrBuildVTDMap()
SUMOReal interpolateGeometryPosToLanePos(SUMOReal geometryPos) const
Definition: MSLane.h:346
Tag for the last element in the enum for safe int casting.
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.
SUMOReal startPos
The stopping position start.
Definition: MSVehicle.h:559
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle's internal edge travel times/efforts container.
Definition: MSVehicle.cpp:535
unsigned int getRoutePosition() const
Definition: MSVehicle.cpp:520
virtual const std::string & getID() const =0
Get the vehicle's ID.
DepartDefinition
Possible ways to depart.
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error)
Validates a given depart value.
#define VAR_DISTANCE
bool readTypeCheckingByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and a byte, verifying the type.
#define VAR_HCEMISSION
void setConsiderMaxAcceleration(bool value)
Sets whether the maximum acceleration shall be regarded.
Definition: MSVehicle.cpp:311
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
std::string id
The vehicle's id.
The vehicle is being teleported.
#define VAR_WIDTH
SUMOReal getAngle() const
Returns the vehicle's direction in degrees.
Definition: MSVehicle.cpp:639
const std::string & getID() const
Returns the name of the vehicle.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:115
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.