SUMO - Simulation of Urban MObility
TraCI_Vehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // C++ Vehicle API
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <utils/geom/GeomHelper.h>
38 #include <microsim/MSVehicle.h>
39 #include <microsim/MSVehicleType.h>
40 #include <microsim/MSNet.h>
41 #include <microsim/MSEdge.h>
42 #include <microsim/MSLane.h>
43 #include <traci-server/TraCIDefs.h>
45 #include "TraCI.h"
46 #include "TraCI_Vehicle.h"
47 
48 
49 // ===========================================================================
50 // member definitions
51 // ===========================================================================
52 
53 MSVehicle*
54 TraCI_Vehicle::getVehicle(const std::string& id) {
56  if (sumoVehicle == 0) {
57  throw TraCIException("Vehicle '" + id + "' is not known");
58  }
59  MSVehicle* v = dynamic_cast<MSVehicle*>(sumoVehicle);
60  if (v == 0) {
61  throw TraCIException("Vehicle '" + id + "' is not a micro-simulation vehicle");
62  }
63  return v;
64 }
65 
66 
67 bool
69  return veh->isOnRoad() || veh->isParking() || veh->wasRemoteControlled();
70 }
71 
72 
73 bool
74 TraCI_Vehicle::onInit(const std::string& vehicleID) {
75  SUMOVehicle* sumoVehicle = MSNet::getInstance()->getVehicleControl().getVehicle(vehicleID);
76  return sumoVehicle == 0 || sumoVehicle->getLane() == 0;
77 }
78 
79 std::vector<std::string>
81  std::vector<std::string> ids;
83  for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
84  if ((*i).second->isOnRoad() || (*i).second->isParking()) {
85  ids.push_back((*i).first);
86  }
87  }
88  return ids;
89 }
90 
91 int
93  return (int)getIDList().size();
94 }
95 
96 double
97 TraCI_Vehicle::getSpeed(const std::string& vehicleID) {
98  MSVehicle* veh = getVehicle(vehicleID);
99  return isVisible(veh) ? veh->getSpeed() : INVALID_DOUBLE_VALUE;
100 }
101 
102 
103 double
104 TraCI_Vehicle::getSpeedWithoutTraCI(const std::string& vehicleID) {
105  MSVehicle* veh = getVehicle(vehicleID);
107 }
108 
109 
111 TraCI_Vehicle::getPosition(const std::string& vehicleID) {
112  MSVehicle* veh = getVehicle(vehicleID);
113  if (isVisible(veh)) {
114  return TraCI::makeTraCIPosition(veh->getPosition());
115  } else {
116  TraCIPosition result;
117  result.x = INVALID_DOUBLE_VALUE;
118  result.y = INVALID_DOUBLE_VALUE;
119  result.z = INVALID_DOUBLE_VALUE;
120  return result;
121  }
122 }
123 
124 
125 double
126 TraCI_Vehicle::getAngle(const std::string& vehicleID) {
127  MSVehicle* veh = getVehicle(vehicleID);
129 }
130 
131 
132 double
133 TraCI_Vehicle::getSlope(const std::string& vehicleID) {
134  MSVehicle* veh = getVehicle(vehicleID);
135  return veh->isOnRoad() ? veh->getSlope() : INVALID_DOUBLE_VALUE;
136 }
137 
138 
139 std::string
140 TraCI_Vehicle::getRoadID(const std::string& vehicleID) {
141  MSVehicle* veh = getVehicle(vehicleID);
142  return isVisible(veh) ? veh->getLane()->getEdge().getID() : "";
143 }
144 
145 
146 std::string
147 TraCI_Vehicle::getLaneID(const std::string& vehicleID) {
148  MSVehicle* veh = getVehicle(vehicleID);
149  return veh->isOnRoad() ? veh->getLane()->getID() : "";
150 }
151 
152 
153 int
154 TraCI_Vehicle::getLaneIndex(const std::string& vehicleID) {
155  MSVehicle* veh = getVehicle(vehicleID);
156  return veh->isOnRoad() ? veh->getLane()->getIndex() : INVALID_INT_VALUE;
157 }
158 
159 std::string
160 TraCI_Vehicle::getTypeID(const std::string& vehicleID) {
161  return getVehicle(vehicleID)->getVehicleType().getID();
162 }
163 
164 std::string
165 TraCI_Vehicle::getRouteID(const std::string& vehicleID) {
166  return getVehicle(vehicleID)->getRoute().getID();
167 }
168 
169 int
170 TraCI_Vehicle::getRouteIndex(const std::string& vehicleID) {
171  MSVehicle* veh = getVehicle(vehicleID);
172  return veh->hasDeparted() ? veh->getRoutePosition() : INVALID_INT_VALUE;
173 }
174 
176 TraCI_Vehicle::getColor(const std::string& vehicleID) {
177  return TraCI::makeTraCIColor(getVehicle(vehicleID)->getParameter().color);
178 }
179 
180 double
181 TraCI_Vehicle::getLanePosition(const std::string& vehicleID) {
182  MSVehicle* veh = getVehicle(vehicleID);
183  return veh->isOnRoad() ? veh->getPositionOnLane() : INVALID_DOUBLE_VALUE;
184 }
185 
186 double
187 TraCI_Vehicle::getLateralLanePosition(const std::string& vehicleID) {
188  MSVehicle* veh = getVehicle(vehicleID);
189  return veh->isOnRoad() ? veh->getLateralPositionOnLane() : INVALID_DOUBLE_VALUE;
190 }
191 
192 double
193 TraCI_Vehicle::getCO2Emission(const std::string& vehicleID) {
194  MSVehicle* veh = getVehicle(vehicleID);
195  return isVisible(veh) ? veh->getCO2Emissions() : INVALID_DOUBLE_VALUE;
196 }
197 
198 double
199 TraCI_Vehicle::getCOEmission(const std::string& vehicleID) {
200  MSVehicle* veh = getVehicle(vehicleID);
201  return isVisible(veh) ? veh->getCOEmissions() : INVALID_DOUBLE_VALUE;
202 }
203 
204 double
205 TraCI_Vehicle::getHCEmission(const std::string& vehicleID) {
206  MSVehicle* veh = getVehicle(vehicleID);
207  return isVisible(veh) ? veh->getHCEmissions() : INVALID_DOUBLE_VALUE;
208 }
209 
210 double
211 TraCI_Vehicle::getPMxEmission(const std::string& vehicleID) {
212  MSVehicle* veh = getVehicle(vehicleID);
213  return isVisible(veh) ? veh->getPMxEmissions() : INVALID_DOUBLE_VALUE;
214 }
215 
216 double
217 TraCI_Vehicle::getNOxEmission(const std::string& vehicleID) {
218  MSVehicle* veh = getVehicle(vehicleID);
219  return isVisible(veh) ? veh->getNOxEmissions() : INVALID_DOUBLE_VALUE;
220 }
221 
222 double
223 TraCI_Vehicle::getFuelConsumption(const std::string& vehicleID) {
224  MSVehicle* veh = getVehicle(vehicleID);
225  return isVisible(veh) ? veh->getFuelConsumption() : INVALID_DOUBLE_VALUE;
226 }
227 
228 double
229 TraCI_Vehicle::getNoiseEmission(const std::string& vehicleID) {
230  MSVehicle* veh = getVehicle(vehicleID);
232 }
233 
234 double
235 TraCI_Vehicle::getElectricityConsumption(const std::string& vehicleID) {
236  MSVehicle* veh = getVehicle(vehicleID);
238 }
239 
240 int
241 TraCI_Vehicle::getPersonNumber(const std::string& vehicleID) {
242  return getVehicle(vehicleID)->getPersonNumber();
243 }
244 
245 
246 std::pair<std::string, double>
247 TraCI_Vehicle::getLeader(const std::string& vehicleID, double dist) {
248  MSVehicle* veh = getVehicle(vehicleID);
249  if (veh->isOnRoad()) {
250  std::pair<const MSVehicle* const, double> leaderInfo = veh->getLeader(dist);
251  return std::make_pair(
252  leaderInfo.first != 0 ? leaderInfo.first->getID() : "",
253  leaderInfo.second);
254  } else {
255  return std::make_pair("", -1);
256  }
257 }
258 
259 
260 double
261 TraCI_Vehicle::getWaitingTime(const std::string& vehicleID) {
262  return getVehicle(vehicleID)->getWaitingSeconds();
263 }
264 
265 
266 double
267 TraCI_Vehicle::getAdaptedTraveltime(const std::string& vehicleID, const std::string& edgeID, int time) {
268  MSVehicle* veh = getVehicle(vehicleID);
269  MSEdge* edge = TraCI::getEdge(edgeID);
270  double value = INVALID_DOUBLE_VALUE;;
271  veh->getWeightsStorage().retrieveExistingTravelTime(edge, time, value);
272  return value;
273 }
274 
275 
276 double
277 TraCI_Vehicle::getEffort(const std::string& vehicleID, const std::string& edgeID, int time) {
278  MSVehicle* veh = getVehicle(vehicleID);
279  MSEdge* edge = TraCI::getEdge(edgeID);
280  double value = INVALID_DOUBLE_VALUE;;
281  veh->getWeightsStorage().retrieveExistingEffort(edge, time, value);
282  return value;
283 }
284 
285 
286 bool
287 TraCI_Vehicle::isRouteValid(const std::string& vehicleID) {
288  std::string msg;
289  return getVehicle(vehicleID)->hasValidRoute(msg);
290 }
291 
292 std::vector<std::string>
293 TraCI_Vehicle::getEdges(const std::string& vehicleID) {
294  std::vector<std::string> result;
295  MSVehicle* veh = getVehicle(vehicleID);
296  const MSRoute& r = veh->getRoute();
297  for (MSRouteIterator i = r.begin(); i != r.end(); ++i) {
298  result.push_back((*i)->getID());
299  }
300  return result;
301 }
302 
303 
304 int
305 TraCI_Vehicle::getSignalStates(const std::string& vehicleID) {
306  return getVehicle(vehicleID)->getSignals();
307 }
308 
309 std::vector<TraCI_Vehicle::BestLanesData>
310 TraCI_Vehicle::getBestLanes(const std::string& vehicleID) {
311  std::vector<BestLanesData> result;
312  MSVehicle* veh = getVehicle(vehicleID);
313  if (veh->isOnRoad()) {
314  const std::vector<MSVehicle::LaneQ>& bestLanes = veh->getBestLanes();
315  for (std::vector<MSVehicle::LaneQ>::const_iterator i = bestLanes.begin(); i != bestLanes.end(); ++i) {
316  BestLanesData bld;
317  const MSVehicle::LaneQ& lq = *i;
318  bld.laneID = lq.lane->getID();
319  bld.length = lq.length;
323  for (std::vector<MSLane*>::const_iterator j = lq.bestContinuations.begin(); j != lq.bestContinuations.end(); ++j) {
324  if ((*j) != 0) {
325  bld.continuationLanes.push_back((*j)->getID());
326  }
327  }
328  result.push_back(bld);
329  }
330  }
331  return result;
332 }
333 
334 
335 std::vector<TraCI_Vehicle::NextTLSData>
336 TraCI_Vehicle::getNextTLS(const std::string& vehicleID) {
337  std::vector<NextTLSData> result;
338  MSVehicle* veh = getVehicle(vehicleID);
339  if (veh->isOnRoad()) {
340  const MSLane* lane = veh->getLane();
341  const std::vector<MSLane*>& bestLaneConts = veh->getBestLanesContinuation(lane);
342  double seen = veh->getLane()->getLength() - veh->getPositionOnLane();
343  int view = 1;
344  MSLinkCont::const_iterator link = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
345  while (!lane->isLinkEnd(link)) {
346  if (!lane->getEdge().isInternal()) {
347  if ((*link)->isTLSControlled()) {
348  NextTLSData ntd;
349  ntd.id = (*link)->getTLLogic()->getID();
350  ntd.tlIndex = (*link)->getTLIndex();
351  ntd.dist = seen;
352  ntd.state = (char)(*link)->getState();
353  result.push_back(ntd);
354  }
355  }
356  lane = (*link)->getViaLaneOrLane();
357  if (!lane->getEdge().isInternal()) {
358  view++;
359  }
360  seen += lane->getLength();
361  link = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
362  }
363  }
364  return result;
365 }
366 
367 int
368 TraCI_Vehicle::getStopState(const std::string& vehicleID) {
369  MSVehicle* veh = getVehicle(vehicleID);
370  int result = 0;
371  if (veh->isStopped()) {
372  const MSVehicle::Stop& stop = veh->getNextStop();
373  result = (1 + (stop.parking ? 2 : 0) +
374  (stop.triggered ? 4 : 0) +
375  (stop.containerTriggered ? 8 : 0) +
376  (stop.busstop != 0 ? 16 : 0) +
377  (stop.containerstop != 0 ? 32 : 0) +
378  (stop.chargingStation != 0 ? 64 : 0) +
379  (stop.parkingarea != 0 ? 128 : 0));
380  }
381  return result;
382 }
383 
384 double
385 TraCI_Vehicle::getDistance(const std::string& vehicleID) {
386  MSVehicle* veh = getVehicle(vehicleID);
387  if (veh->isOnRoad()) {
388  double distance = veh->getRoute().getDistanceBetween(veh->getDepartPos(), veh->getPositionOnLane(), veh->getRoute().getEdges()[0], &veh->getLane()->getEdge());
389  if (distance == std::numeric_limits<double>::max()) {
390  return INVALID_DOUBLE_VALUE;
391  } else {
392  return distance;
393  }
394  } else {
395  return INVALID_DOUBLE_VALUE;
396  }
397 }
398 
399 
400 double
401 TraCI_Vehicle::getDrivingDistance(const std::string& vehicleID, const std::string& edgeID, double position, int /* laneIndex */) {
402  MSVehicle* veh = getVehicle(vehicleID);
403  if (veh->isOnRoad()) {
404  double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), position,
405  veh->getEdge(), TraCI::getEdge(edgeID));
406  if (distance == std::numeric_limits<double>::max()) {
407  return INVALID_DOUBLE_VALUE;
408  }
409  return distance;
410  } else {
411  return INVALID_DOUBLE_VALUE;
412  }
413 }
414 
415 
416 double
417 TraCI_Vehicle::getDrivingDistance2D(const std::string& vehicleID, double x, double y) {
418  MSVehicle* veh = getVehicle(vehicleID);
419  if (veh->isOnRoad()) {
420  std::pair<MSLane*, double> roadPos = TraCI::convertCartesianToRoadMap(Position(x, y));
421  double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), roadPos.second,
422  veh->getEdge(), &roadPos.first->getEdge());
423  if (distance == std::numeric_limits<double>::max()) {
424  return INVALID_DOUBLE_VALUE;
425  }
426  return distance;
427  } else {
428  return INVALID_DOUBLE_VALUE;
429  }
430 }
431 
432 
433 
434 double
435 TraCI_Vehicle::getAllowedSpeed(const std::string& vehicleID) {
436  MSVehicle* veh = getVehicle(vehicleID);
437  if (veh->isOnRoad()) {
438  return veh->getLane()->getVehicleMaxSpeed(veh);
439  } else {
440  return INVALID_DOUBLE_VALUE;
441  }
442 }
443 
444 double
445 TraCI_Vehicle::getSpeedFactor(const std::string& vehicleID) {
446  return getVehicle(vehicleID)->getChosenSpeedFactor();
447 }
448 
449 
450 int
451 TraCI_Vehicle::getSpeedMode(const std::string& vehicleID) {
452  return getVehicle(vehicleID)->getInfluencer().getSpeedMode();
453 }
454 
455 std::string
456 TraCI_Vehicle::getLine(const std::string& vehicleID) {
457  return getVehicle(vehicleID)->getParameter().line;
458 }
459 
460 std::vector<std::string>
461 TraCI_Vehicle::getVia(const std::string& vehicleID) {
462  return getVehicle(vehicleID)->getParameter().via;
463 }
464 
465 
466 std::pair<int, int>
467 TraCI_Vehicle::getLaneChangeState(const std::string& vehicleID, int direction) {
468  MSVehicle* veh = getVehicle(vehicleID);
469  if (veh->isOnRoad()) {
470  return veh->getLaneChangeModel().getSavedState(direction);
471  } else {
472  return std::make_pair((int)LCA_UNKNOWN, (int)LCA_UNKNOWN);
473  }
474 }
475 
476 
477 std::string
478 TraCI_Vehicle::getParameter(const std::string& vehicleID, const std::string& key) {
479  MSVehicle* veh = getVehicle(vehicleID);
480  if (StringUtils::startsWith(key, "device.")) {
481  StringTokenizer tok(key, ".");
482  if (tok.size() < 3) {
483  throw TraCIException("Invalid device parameter '" + key + "' for vehicle '" + vehicleID + "'");
484  }
485  try {
486  return veh->getDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2));
487  } catch (InvalidArgument& e) {
488  throw TraCIException("Vehicle '" + vehicleID + "' does not support device parameter '" + key + "' (" + e.what() + ").");
489  }
490  } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
491  const std::string attrName = key.substr(16);
492  try {
493  return veh->getLaneChangeModel().getParameter(attrName);
494  } catch (InvalidArgument& e) {
495  throw TraCIException("Vehicle '" + vehicleID + "' does not support laneChangeModel parameter '" + key + "' (" + e.what() + ").");
496  }
497  } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
498  StringTokenizer tok(key, ".");
499  if (tok.size() != 3) {
500  throw TraCIException("Invalid check for device. Expected format is 'has.DEVICENAME.device'");
501  }
502  return veh->hasDevice(tok.get(1)) ? "true" : "false";
503  } else {
504  return veh->getParameter().getParameter(key, "");
505  }
506 }
507 
508 
509 const MSVehicleType&
510 TraCI_Vehicle::getVehicleType(const std::string& vehicleID) {
511  return getVehicle(vehicleID)->getVehicleType();
512 }
513 
514 
515 
516 /*
517 std::string
518 TraCI_Vehicle::getEmissionClass(const std::string& vehicleID) {
519 }
520 
521 std::string
522 TraCI_Vehicle::getShapeClass(const std::string& vehicleID) {
523 }
524 
525 
526 
527 double
528 TraCI_Vehicle::getLength(const std::string& vehicleID) {
529 }
530 
531 double
532 TraCI_Vehicle::getAccel(const std::string& vehicleID) {
533 }
534 
535 double
536 TraCI_Vehicle::getDecel(const std::string& vehicleID) {
537 }
538 
539 double
540 TraCI_Vehicle::getTau(const std::string& vehicleID) {
541 }
542 
543 double
544 TraCI_Vehicle::getImperfection(const std::string& vehicleID) {
545 }
546 
547 double
548 TraCI_Vehicle::getSpeedDeviation(const std::string& vehicleID) {
549 }
550 
551 std::string
552 TraCI_Vehicle::getVClass(const std::string& vehicleID) {
553 }
554 
555 double
556 TraCI_Vehicle::getMinGap(const std::string& vehicleID) {
557 }
558 
559 double
560 TraCI_Vehicle::getMaxSpeed(const std::string& vehicleID) {
561 }
562 
563 
564 double
565 TraCI_Vehicle::getWidth(const std::string& vehicleID) {
566 }
567 */
568 
569 
570 void
571 TraCI_Vehicle::setStop(const std::string& vehicleID,
572  const std::string& edgeID,
573  double endPos,
574  int laneIndex,
575  SUMOTime duration,
576  int flags,
577  double startPos,
578  SUMOTime until) {
579  MSVehicle* veh = getVehicle(vehicleID);
580  // optional stop flags
581  bool parking = false;
582  bool triggered = false;
583  bool containerTriggered = false;
584  SumoXMLTag stoppingPlaceType = SUMO_TAG_NOTHING;
585 
586  parking = ((flags & 1) != 0);
587  triggered = ((flags & 2) != 0);
588  containerTriggered = ((flags & 4) != 0);
589  if ((flags & 8) != 0) {
590  stoppingPlaceType = SUMO_TAG_BUS_STOP;
591  }
592  if ((flags & 16) != 0) {
593  stoppingPlaceType = SUMO_TAG_BUS_STOP;
594  }
595  if ((flags & 32) != 0) {
596  stoppingPlaceType = SUMO_TAG_CHARGING_STATION;
597  }
598  if ((flags & 64) != 0) {
599  stoppingPlaceType = SUMO_TAG_PARKING_AREA;
600  }
601 
602  std::string error;
603  if (stoppingPlaceType != SUMO_TAG_NOTHING) {
604  // Forward command to vehicle
605  if (!veh->addTraciStopAtStoppingPlace(edgeID, duration, until, parking, triggered, containerTriggered, stoppingPlaceType, error)) {
606  throw TraCIException(error);
607  }
608  } else {
609  // check
610  if (startPos < 0) {
611  throw TraCIException("Position on lane must not be negative.");
612  }
613  if (endPos < startPos) {
614  throw TraCIException("End position on lane must be after start position.");
615  }
616  // get the actual lane that is referenced by laneIndex
617  MSEdge* road = MSEdge::dictionary(edgeID);
618  if (road == 0) {
619  throw TraCIException("Unable to retrieve road with given id.");
620  }
621  const std::vector<MSLane*>& allLanes = road->getLanes();
622  if ((laneIndex < 0) || laneIndex >= (int)(allLanes.size())) {
623  throw TraCIException("No lane with index '" + toString(laneIndex) + "' on road '" + edgeID + "'.");
624  }
625  // Forward command to vehicle
626  if (!veh->addTraciStop(allLanes[laneIndex], startPos, endPos, duration, until, parking, triggered, containerTriggered, error)) {
627  throw TraCIException(error);
628  }
629  }
630 }
631 
632 
633 void
634 TraCI_Vehicle::resume(const std::string& vehicleID) {
635  MSVehicle* veh = getVehicle(vehicleID);
636  if (!veh->hasStops()) {
637  throw TraCIException("Failed to resume vehicle '" + veh->getID() + "', it has no stops.");
638  }
639  if (!veh->resumeFromStopping()) {
640  MSVehicle::Stop& sto = veh->getNextStop();
641  std::ostringstream strs;
642  strs << "reached: " << sto.reached;
643  strs << ", duration:" << sto.duration;
644  strs << ", edge:" << (*sto.edge)->getID();
645  strs << ", startPos: " << sto.startPos;
646  std::string posStr = strs.str();
647  throw TraCIException("Failed to resume from stoppingfor vehicle '" + veh->getID() + "', " + posStr);
648  }
649 }
650 
651 
652 void
653 TraCI_Vehicle::changeLane(const std::string& vehID, int laneIndex, SUMOTime duration) {
654 }
655 
656 
657 void
658 TraCI_Vehicle::add(const std::string& vehicleID,
659  const std::string& routeID,
660  const std::string& typeID,
661  std::string depart,
662  const std::string& departLane,
663  const std::string& departPos,
664  const std::string& departSpeed,
665  const std::string& arrivalLane,
666  const std::string& arrivalPos,
667  const std::string& arrivalSpeed,
668  const std::string& fromTaz,
669  const std::string& toTaz,
670  const std::string& line,
671  int personCapacity,
672  int personNumber) {
673  MSVehicle* veh = getVehicle(vehicleID);
674  if (veh != 0) {
675  throw TraCIException("The vehicle " + vehicleID + " to add already exists.");
676  }
677 }
678 
679 void
680 TraCI_Vehicle::moveTo(const std::string& vehicleID, const std::string& laneID, double position) {
681 }
682 
683 void
684 TraCI_Vehicle::moveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) {
685 }
686 
687 void
688 TraCI_Vehicle::slowDown(const std::string& vehicleID, double speed, int duration) {
689 }
690 
691 void
692 TraCI_Vehicle::setSpeed(const std::string& vehicleID, double speed) {
693 }
694 
695 void
696 TraCI_Vehicle::setMaxSpeed(const std::string& vehicleID, double speed) {
697 }
698 
699 void
700 TraCI_Vehicle::remove(const std::string& vehicleID, char reason) {
701 }
702 
703 void
704 TraCI_Vehicle::setColor(const std::string& vehicleID, const TraCIColor& c) {
705 }
706 
707 void
708 TraCI_Vehicle::setLine(const std::string& vehicleID, const std::string& line) {
709 }
710 
711 void
712 TraCI_Vehicle::setVia(const std::string& vehicleID, const std::vector<std::string>& via) {
713 }
714 
715 void
716 TraCI_Vehicle::setShapeClass(const std::string& vehicleID, const std::string& clazz) {
717 }
718 
719 void
720 TraCI_Vehicle::setEmissionClass(const std::string& vehicleID, const std::string& clazz) {
721 }
722 
723 
724 void
725 TraCI_Vehicle::setParameter(const std::string& vehicleID, const std::string& key, const std::string& value) {
726  MSVehicle* veh = getVehicle(vehicleID);
727  if (StringUtils::startsWith(key, "device.")) {
728  StringTokenizer tok(key, ".");
729  if (tok.size() < 3) {
730  throw TraCIException("Invalid device parameter '" + key + "' for vehicle '" + vehicleID + "'");
731  }
732  try {
733  veh->setDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2), value);
734  } catch (InvalidArgument& e) {
735  throw TraCIException("Vehicle '" + vehicleID + "' does not support device parameter '" + key + "' (" + e.what() + ").");
736  }
737  } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
738  const std::string attrName = key.substr(16);
739  try {
740  veh->getLaneChangeModel().setParameter(attrName, value);
741  } catch (InvalidArgument& e) {
742  throw TraCIException("Vehicle '" + vehicleID + "' does not support laneChangeModel parameter '" + key + "' (" + e.what() + ").");
743  }
744  } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
745  StringTokenizer tok(key, ".");
746  if (tok.size() != 3) {
747  throw TraCIException("Invalid request for device status change. Expected format is 'has.DEVICENAME.device'");
748  }
749  const std::string deviceName = tok.get(1);
750  bool create;
751  try {
752  create = TplConvert::_2bool(value.c_str());
753  } catch (BoolFormatException) {
754  throw TraCIException("Changing device status requires a 'true' or 'false'");
755  }
756  if (!create) {
757  throw TraCIException("Device removal is not supported for device of type '" + deviceName + "'");
758  }
759  try {
760  veh->createDevice(deviceName);
761  } catch (InvalidArgument& e) {
762  throw TraCIException("Cannot create vehicle device (" + std::string(e.what()) + ").");
763  }
764  } else {
765  ((SUMOVehicleParameter&) veh->getParameter()).addParameter(key, value);
766  }
767 }
768 
769 
770 /****************************************************************************/
int getRoutePosition() const
Definition: MSVehicle.cpp:678
double x
Definition: TraCIDefs.h:72
double getFuelConsumption() const
Returns fuel consumption of the current state.
Definition: MSVehicle.cpp:3418
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:462
SumoXMLTag
Numbers representing SUMO-XML - element names.
double getNOxEmissions() const
Returns NOx emission of the current state.
Definition: MSVehicle.cpp:3406
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCI_Vehicle.h:82
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:582
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
double getElectricityConsumption() const
Returns electricity consumption of the current state.
Definition: MSVehicle.cpp:3424
double getAngle() const
Returns the vehicle&#39;s direction in radians.
Definition: MSVehicle.h:594
static int getPersonNumber(const std::string &vehicleID)
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:128
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:570
double nextOccupation
The traffic density along length.
Definition: TraCI_Vehicle.h:76
bool hasDeparted() const
Returns whether this vehicle has already departed.
Stop & getNextStop()
Definition: MSVehicle.cpp:3987
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
static TraCIColor getColor(const std::string &vehicleID)
bool resumeFromStopping()
Definition: MSVehicle.cpp:3940
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:488
void setDeviceParameter(const std::string &deviceName, const std::string &key, const std::string &value)
try to set the given parameter from any of the vehicles devices, raise InvalidArgument if no device p...
static bool _2bool(const E *const data)
converts a 0-terminated char-type array into the boolean value described by it
Definition: TplConvert.h:371
static std::string getLaneID(const std::string &vehicleID)
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive...
Definition: MSVehicle.h:714
static void setLine(const std::string &vehicleID, const std::string &line)
static double getPMxEmission(const std::string &vehicleID)
int getPersonNumber() const
Returns the number of persons.
Definition: MSVehicle.cpp:3508
std::pair< const MSVehicle *const, double > getLeader(double dist=0) const
Returns the leader of the vehicle looking for a fixed distance.
Definition: MSVehicle.cpp:3348
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: TraCI.cpp:128
static double getAllowedSpeed(const std::string &vehicleID)
static double getDistance(const std::string &vehicleID)
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:375
static MSEdge * getEdge(const std::string &edgeID)
Definition: TraCI.cpp:160
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCI_Vehicle.h:78
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
static double getNOxEmission(const std::string &vehicleID)
static std::vector< std::string > getVia(const std::string &vehicleID)
static double getWaitingTime(const std::string &vehicleID)
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:281
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
std::string get(int pos) const
bool addTraciStopAtStoppingPlace(const std::string &stopId, const SUMOTime duration, const SUMOTime until, const bool parking, const bool triggered, const bool containerTriggered, const SumoXMLTag stoppingPlaceType, std::string &errorMsg)
Definition: MSVehicle.cpp:3850
bool reached
Information whether the stop has been reached.
Definition: MSVehicle.h:848
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
static bool isVisible(const MSVehicle *veh)
static void add(const std::string &vehicleID, const std::string &routeID, const std::string &typeID="DEFAULT_VEHTYPE", std::string depart="-1", const std::string &departLane="first", const std::string &departPos="base", const std::string &departSpeed="0", const std::string &arrivalLane="current", const std::string &arrivalPos="max", const std::string &arrivalSpeed="current", const std::string &fromTaz="", const std::string &toTaz="", const std::string &line="", int personCapacity=0, int personNumber=0)
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:484
bool isLinkEnd(MSLinkCont::const_iterator &i) const
Definition: MSLane.cpp:1481
virtual std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this laneChangeModel. Throw exception for unsupported key ...
const MSRoute & getRoute() const
Returns the current route.
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:728
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:777
Definition of vehicle stop (position and duration)
Definition: MSVehicle.h:820
static void setParameter(const std::string &vehicleID, const std::string &key, const std::string &value)
static MSVehicle * getVehicle(const std::string &id)
std::string laneID
The id of the lane.
Definition: TraCI_Vehicle.h:72
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:1140
static int getRouteIndex(const std::string &vehicleID)
const std::string & getID() const
Returns the id.
Definition: Named.h:66
static std::pair< int, int > getLaneChangeState(const std::string &vehicleID, int direction)
int getSpeedMode() const
return the current speed mode
Definition: MSVehicle.cpp:273
double nextOccupation
As occupation, but without the first lane.
Definition: MSVehicle.h:712
double length
The overall length which may be driven when using this lane without a lane change.
Definition: MSVehicle.h:706
static std::string getRouteID(const std::string &vehicleID)
static std::vector< std::string > getIDList()
bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const
Returns the information whether the vehicle is fully controlled via TraCI within the lookBack time...
Definition: MSVehicle.cpp:4043
static double getCO2Emission(const std::string &vehicleID)
double dist
The distance to the tls.
Definition: TraCI_Vehicle.h:63
static int getStopState(const std::string &vehicleID)
static double getSpeedWithoutTraCI(const std::string &vehicleID)
The car-following model and parameter.
Definition: MSVehicleType.h:74
bool triggered
whether an arriving person lets the vehicle continue
Definition: MSVehicle.h:842
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:2921
static void setColor(const std::string &vehicleID, const TraCIColor &c)
double getDepartPos() const
Returns this vehicle&#39;s real departure position.
std::string getDeviceParameter(const std::string &deviceName, const std::string &key) const
try to retrieve the given parameter from any of the vehicles devices, raise InvalidArgument if no dev...
MSChargingStation * chargingStation
(Optional) charging station if one is assigned to the stop
Definition: MSVehicle.h:832
static std::vector< BestLanesData > getBestLanes(const std::string &vehicleID)
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
double z
Definition: TraCIDefs.h:72
static std::string getLine(const std::string &vehicleID)
static TraCIPosition getPosition(const std::string &vehicleID)
A road/street connecting two junctions.
Definition: MSEdge.h:80
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:510
static double getAdaptedTraveltime(const std::string &vehicleID, const std::string &edgeID, int time)
static void slowDown(const std::string &vehicleID, double speed, int duration)
MSLane * lane
The described lane.
Definition: MSVehicle.h:704
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:187
The action has not been determined.
static void setMaxSpeed(const std::string &vehicleID, double speed)
double getCO2Emissions() const
Returns CO2 emission of the current state.
Definition: MSVehicle.cpp:3388
int getIndex() const
Returns the lane&#39;s index.
Definition: MSLane.h:507
#define max(a, b)
Definition: polyfonts.c:65
static double getNoiseEmission(const std::string &vehicleID)
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static void setEmissionClass(const std::string &vehicleID, const std::string &clazz)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void createDevice(const std::string &deviceName)
create device of the given type
static double getFuelConsumption(const std::string &vehicleID)
Representation of a vehicle.
Definition: SUMOVehicle.h:67
MSStoppingPlace * containerstop
(Optional) container stop if one is assigned to the stop
Definition: MSVehicle.h:828
static double getDrivingDistance2D(const std::string &vehicleID, double x, double y)
static bool isRouteValid(const std::string &vehicleID)
int tlIndex
The tls index of the controlled link.
Definition: TraCI_Vehicle.h:61
A 3D-position.
Definition: TraCIDefs.h:71
static double getElectricityConsumption(const std::string &vehicleID)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
virtual void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key ...
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
Definition: MSVehicle.cpp:3276
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:310
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
static double getAngle(const std::string &vehicleID)
static int getSignalStates(const std::string &vehicleID)
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
Definition: MSVehicle.h:887
SUMOTime duration
The stopping duration.
Definition: MSVehicle.h:838
double getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
Definition: MSVehicle.cpp:3430
char state
The current state of the tls.
Definition: TraCI_Vehicle.h:65
static void remove(const std::string &vehicleID, char reason=REMOVE_VAPORIZED)
A structure representing the best lanes for continuing the current route starting at &#39;lane&#39;...
Definition: MSVehicle.h:702
static void moveTo(const std::string &vehicleID, const std::string &laneID, double position)
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCI_Vehicle.h:80
static void setStop(const std::string &vehicleID, const std::string &edgeID, double endPos=1., int laneIndex=0, SUMOTime duration=4294967295u, int flags=STOP_DEFAULT, double startPos=INVALID_DOUBLE_VALUE, SUMOTime until=-1)
MSParkingArea * parkingarea
(Optional) parkingArea if one is assigned to the stop
Definition: MSVehicle.h:830
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:254
static MSLinkCont::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane *> &conts)
Definition: MSLane.cpp:1548
bool allowsContinuation
Whether this lane allows to continue the drive.
Definition: MSVehicle.h:716
double length
The length than can be driven from that lane without lane change.
Definition: TraCI_Vehicle.h:74
std::string line
The vehicle&#39;s line (mainly for public transport)
#define INVALID_DOUBLE_VALUE
static double getHCEmission(const std::string &vehicleID)
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:407
static double getCOEmission(const std::string &vehicleID)
static int getIDCount()
double getCOEmissions() const
Returns CO emission of the current state.
Definition: MSVehicle.cpp:3394
static std::pair< MSLane *, double > convertCartesianToRoadMap(Position pos)
Definition: TraCI.cpp:185
std::vector< std::string > via
List of the via-edges the vehicle must visit.
static std::string getParameter(const std::string &vehicleID, const std::string &key)
static double getSlope(const std::string &vehicleID)
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
bool addTraciStop(MSLane *const lane, const double startPos, const double endPos, const SUMOTime duration, const SUMOTime until, const bool parking, const bool triggered, const bool containerTriggered, std::string &errorMsg)
Definition: MSVehicle.cpp:3814
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:3993
Structure representing possible vehicle parameter.
#define INVALID_INT_VALUE
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
bool containerTriggered
whether an arriving container lets the vehicle continue
Definition: MSVehicle.h:844
static void moveToXY(const std::string &vehicleID, const std::string &edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute)
static const MSVehicleType & getVehicleType(const std::string &vehicleID)
std::vector< MSLane * > bestContinuations
Definition: MSVehicle.h:722
static void changeLane(const std::string &vehID, int laneIndex, SUMOTime duration)
static double getSpeedFactor(const std::string &vehicleID)
const std::string & getID() const
Returns the name of the vehicle type.
static void setVia(const std::string &vehicleID, const std::vector< std::string > &via)
double getPMxEmissions() const
Returns PMx emission of the current state.
Definition: MSVehicle.cpp:3412
MSRouteIterator edge
The edge in the route to stop at.
Definition: MSVehicle.h:822
static std::string getRoadID(const std::string &vehicleID)
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
static double getDrivingDistance(const std::string &vehicleID, const std::string &edgeID, double position, int laneIndex)
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle&#39;s internal edge travel times/efforts container.
Definition: MSVehicle.cpp:693
static double getLateralLanePosition(const std::string &vehicleID)
static int getSpeedMode(const std::string &vehicleID)
static TraCIPosition makeTraCIPosition(const Position &position)
Definition: TraCI.cpp:144
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:766
static std::string getTypeID(const std::string &vehicleID)
static int getLaneIndex(const std::string &vehicleID)
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
long long int SUMOTime
Definition: TraCIDefs.h:52
double y
Definition: TraCIDefs.h:72
double getHCEmissions() const
Returns HC emission of the current state.
Definition: MSVehicle.cpp:3400
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MSVehicle.cpp:1115
The class responsible for building and deletion of vehicles.
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
Definition: MSVehicle.cpp:2933
static void resume(const std::string &vehicleID)
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:1127
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:442
static double getSpeed(const std::string &vehicleID)
static double getLanePosition(const std::string &vehicleID)
const std::string & getID() const
Returns the name of the vehicle.
MSStoppingPlace * busstop
(Optional) bus stop if one is assigned to the stop
Definition: MSVehicle.h:826
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
std::string id
The id of the next tls.
Definition: TraCI_Vehicle.h:59
static std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist)
static std::vector< NextTLSData > getNextTLS(const std::string &vehicleID)
static std::vector< std::string > getEdges(const std::string &vehicleID)
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
static bool onInit(const std::string &vehicleID)
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
static void setSpeed(const std::string &vehicleID, double speed)
double startPos
The stopping position start.
Definition: MSVehicle.h:834
bool parking
whether the vehicle is removed from the net while stopping
Definition: MSVehicle.h:846
static void setShapeClass(const std::string &vehicleID, const std::string &clazz)
double getSpeedWithoutTraciInfluence() const
Returns the uninfluenced velocity.
Definition: MSVehicle.cpp:4008
static double getEffort(const std::string &vehicleID, const std::string &edgeID, int time)
const std::pair< int, int > & getSavedState(const int dir) const