SUMO - Simulation of Urban MObility
TraCI_Vehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // C++ Vehicle API
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <utils/geom/GeomHelper.h>
39 #include <microsim/MSVehicle.h>
41 #include <microsim/MSVehicleType.h>
43 #include <microsim/MSNet.h>
44 #include <microsim/MSEdge.h>
45 #include <microsim/MSLane.h>
46 #include <traci-server/TraCIDefs.h>
48 #include "TraCI.h"
49 #include "TraCI_Vehicle.h"
50 
51 
52 // ===========================================================================
53 // member definitions
54 // ===========================================================================
55 
56 MSVehicle*
57 TraCI_Vehicle::getVehicle(const std::string& id) {
59  if (sumoVehicle == 0) {
60  throw TraCIException("Vehicle '" + id + "' is not known");
61  }
62  MSVehicle* v = dynamic_cast<MSVehicle*>(sumoVehicle);
63  if (v == 0) {
64  throw TraCIException("Vehicle '" + id + "' is not a micro-simulation vehicle");
65  }
66  return v;
67 }
68 
69 
70 bool
72  return veh->isOnRoad() || veh->isParking() || veh->wasRemoteControlled();
73 }
74 
75 
76 bool
77 TraCI_Vehicle::isOnInit(const std::string& vehicleID) {
78  SUMOVehicle* sumoVehicle = MSNet::getInstance()->getVehicleControl().getVehicle(vehicleID);
79  return sumoVehicle == 0 || sumoVehicle->getLane() == 0;
80 }
81 
82 std::vector<std::string>
84  std::vector<std::string> ids;
86  for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
87  if ((*i).second->isOnRoad() || (*i).second->isParking()) {
88  ids.push_back((*i).first);
89  }
90  }
91  return ids;
92 }
93 
94 int
96  return (int)getIDList().size();
97 }
98 
99 double
100 TraCI_Vehicle::getSpeed(const std::string& vehicleID) {
101  MSVehicle* veh = getVehicle(vehicleID);
102  return isVisible(veh) ? veh->getSpeed() : INVALID_DOUBLE_VALUE;
103 }
104 
105 
106 double
107 TraCI_Vehicle::getSpeedWithoutTraCI(const std::string& vehicleID) {
108  MSVehicle* veh = getVehicle(vehicleID);
110 }
111 
112 
114 TraCI_Vehicle::getPosition(const std::string& vehicleID) {
115  MSVehicle* veh = getVehicle(vehicleID);
116  if (isVisible(veh)) {
117  return TraCI::makeTraCIPosition(veh->getPosition());
118  } else {
119  TraCIPosition result;
120  result.x = INVALID_DOUBLE_VALUE;
121  result.y = INVALID_DOUBLE_VALUE;
122  result.z = INVALID_DOUBLE_VALUE;
123  return result;
124  }
125 }
126 
127 
128 double
129 TraCI_Vehicle::getAngle(const std::string& vehicleID) {
130  MSVehicle* veh = getVehicle(vehicleID);
132 }
133 
134 
135 double
136 TraCI_Vehicle::getSlope(const std::string& vehicleID) {
137  MSVehicle* veh = getVehicle(vehicleID);
138  return veh->isOnRoad() ? veh->getSlope() : INVALID_DOUBLE_VALUE;
139 }
140 
141 
142 std::string
143 TraCI_Vehicle::getRoadID(const std::string& vehicleID) {
144  MSVehicle* veh = getVehicle(vehicleID);
145  return isVisible(veh) ? veh->getLane()->getEdge().getID() : "";
146 }
147 
148 
149 std::string
150 TraCI_Vehicle::getLaneID(const std::string& vehicleID) {
151  MSVehicle* veh = getVehicle(vehicleID);
152  return veh->isOnRoad() ? veh->getLane()->getID() : "";
153 }
154 
155 
156 int
157 TraCI_Vehicle::getLaneIndex(const std::string& vehicleID) {
158  MSVehicle* veh = getVehicle(vehicleID);
159  return veh->isOnRoad() ? veh->getLane()->getIndex() : INVALID_INT_VALUE;
160 }
161 
162 std::string
163 TraCI_Vehicle::getTypeID(const std::string& vehicleID) {
164  return getVehicle(vehicleID)->getVehicleType().getID();
165 }
166 
167 std::string
168 TraCI_Vehicle::getRouteID(const std::string& vehicleID) {
169  return getVehicle(vehicleID)->getRoute().getID();
170 }
171 
172 int
173 TraCI_Vehicle::getRouteIndex(const std::string& vehicleID) {
174  MSVehicle* veh = getVehicle(vehicleID);
175  return veh->hasDeparted() ? veh->getRoutePosition() : INVALID_INT_VALUE;
176 }
177 
179 TraCI_Vehicle::getColor(const std::string& vehicleID) {
180  return TraCI::makeTraCIColor(getVehicle(vehicleID)->getParameter().color);
181 }
182 
183 double
184 TraCI_Vehicle::getLanePosition(const std::string& vehicleID) {
185  MSVehicle* veh = getVehicle(vehicleID);
186  return veh->isOnRoad() ? veh->getPositionOnLane() : INVALID_DOUBLE_VALUE;
187 }
188 
189 double
190 TraCI_Vehicle::getLateralLanePosition(const std::string& vehicleID) {
191  MSVehicle* veh = getVehicle(vehicleID);
192  return veh->isOnRoad() ? veh->getLateralPositionOnLane() : INVALID_DOUBLE_VALUE;
193 }
194 
195 double
196 TraCI_Vehicle::getCO2Emission(const std::string& vehicleID) {
197  MSVehicle* veh = getVehicle(vehicleID);
198  return isVisible(veh) ? veh->getCO2Emissions() : INVALID_DOUBLE_VALUE;
199 }
200 
201 double
202 TraCI_Vehicle::getCOEmission(const std::string& vehicleID) {
203  MSVehicle* veh = getVehicle(vehicleID);
204  return isVisible(veh) ? veh->getCOEmissions() : INVALID_DOUBLE_VALUE;
205 }
206 
207 double
208 TraCI_Vehicle::getHCEmission(const std::string& vehicleID) {
209  MSVehicle* veh = getVehicle(vehicleID);
210  return isVisible(veh) ? veh->getHCEmissions() : INVALID_DOUBLE_VALUE;
211 }
212 
213 double
214 TraCI_Vehicle::getPMxEmission(const std::string& vehicleID) {
215  MSVehicle* veh = getVehicle(vehicleID);
216  return isVisible(veh) ? veh->getPMxEmissions() : INVALID_DOUBLE_VALUE;
217 }
218 
219 double
220 TraCI_Vehicle::getNOxEmission(const std::string& vehicleID) {
221  MSVehicle* veh = getVehicle(vehicleID);
222  return isVisible(veh) ? veh->getNOxEmissions() : INVALID_DOUBLE_VALUE;
223 }
224 
225 double
226 TraCI_Vehicle::getFuelConsumption(const std::string& vehicleID) {
227  MSVehicle* veh = getVehicle(vehicleID);
228  return isVisible(veh) ? veh->getFuelConsumption() : INVALID_DOUBLE_VALUE;
229 }
230 
231 double
232 TraCI_Vehicle::getNoiseEmission(const std::string& vehicleID) {
233  MSVehicle* veh = getVehicle(vehicleID);
235 }
236 
237 double
238 TraCI_Vehicle::getElectricityConsumption(const std::string& vehicleID) {
239  MSVehicle* veh = getVehicle(vehicleID);
241 }
242 
243 int
244 TraCI_Vehicle::getPersonNumber(const std::string& vehicleID) {
245  return getVehicle(vehicleID)->getPersonNumber();
246 }
247 
248 
249 std::pair<std::string, double>
250 TraCI_Vehicle::getLeader(const std::string& vehicleID, double dist) {
251  MSVehicle* veh = getVehicle(vehicleID);
252  if (veh->isOnRoad()) {
253  std::pair<const MSVehicle* const, double> leaderInfo = veh->getLeader(dist);
254  return std::make_pair(
255  leaderInfo.first != 0 ? leaderInfo.first->getID() : "",
256  leaderInfo.second);
257  } else {
258  return std::make_pair("", -1);
259  }
260 }
261 
262 
263 double
264 TraCI_Vehicle::getWaitingTime(const std::string& vehicleID) {
265  return getVehicle(vehicleID)->getWaitingSeconds();
266 }
267 
268 
269 double
270 TraCI_Vehicle::getAccumulatedWaitingTime(const std::string& vehicleID) {
271  return getVehicle(vehicleID)->getAccumulatedWaitingSeconds();
272 }
273 
274 
275 double
276 TraCI_Vehicle::getAdaptedTraveltime(const std::string& vehicleID, const std::string& edgeID, int time) {
277  MSVehicle* veh = getVehicle(vehicleID);
278  MSEdge* edge = TraCI::getEdge(edgeID);
279  double value = INVALID_DOUBLE_VALUE;;
280  veh->getWeightsStorage().retrieveExistingTravelTime(edge, time, value);
281  return value;
282 }
283 
284 
285 double
286 TraCI_Vehicle::getEffort(const std::string& vehicleID, const std::string& edgeID, int time) {
287  MSVehicle* veh = getVehicle(vehicleID);
288  MSEdge* edge = TraCI::getEdge(edgeID);
289  double value = INVALID_DOUBLE_VALUE;;
290  veh->getWeightsStorage().retrieveExistingEffort(edge, time, value);
291  return value;
292 }
293 
294 
295 bool
296 TraCI_Vehicle::isRouteValid(const std::string& vehicleID) {
297  std::string msg;
298  return getVehicle(vehicleID)->hasValidRoute(msg);
299 }
300 
301 std::vector<std::string>
302 TraCI_Vehicle::getEdges(const std::string& vehicleID) {
303  std::vector<std::string> result;
304  MSVehicle* veh = getVehicle(vehicleID);
305  const MSRoute& r = veh->getRoute();
306  for (MSRouteIterator i = r.begin(); i != r.end(); ++i) {
307  result.push_back((*i)->getID());
308  }
309  return result;
310 }
311 
312 
313 int
314 TraCI_Vehicle::getSignalStates(const std::string& vehicleID) {
315  return getVehicle(vehicleID)->getSignals();
316 }
317 
318 std::vector<TraCIBestLanesData>
319 TraCI_Vehicle::getBestLanes(const std::string& vehicleID) {
320  std::vector<TraCIBestLanesData> result;
321  MSVehicle* veh = getVehicle(vehicleID);
322  if (veh->isOnRoad()) {
323  const std::vector<MSVehicle::LaneQ>& bestLanes = veh->getBestLanes();
324  for (std::vector<MSVehicle::LaneQ>::const_iterator i = bestLanes.begin(); i != bestLanes.end(); ++i) {
325  TraCIBestLanesData bld;
326  const MSVehicle::LaneQ& lq = *i;
327  bld.laneID = lq.lane->getID();
328  bld.length = lq.length;
329  bld.occupation = lq.nextOccupation;
332  for (std::vector<MSLane*>::const_iterator j = lq.bestContinuations.begin(); j != lq.bestContinuations.end(); ++j) {
333  if ((*j) != 0) {
334  bld.continuationLanes.push_back((*j)->getID());
335  }
336  }
337  result.push_back(bld);
338  }
339  }
340  return result;
341 }
342 
343 
344 std::vector<TraCINextTLSData>
345 TraCI_Vehicle::getNextTLS(const std::string& vehicleID) {
346  std::vector<TraCINextTLSData> result;
347  MSVehicle* veh = getVehicle(vehicleID);
348  if (veh->isOnRoad()) {
349  const MSLane* lane = veh->getLane();
350  const std::vector<MSLane*>& bestLaneConts = veh->getBestLanesContinuation(lane);
351  double seen = veh->getLane()->getLength() - veh->getPositionOnLane();
352  int view = 1;
353  MSLinkCont::const_iterator link = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
354  while (!lane->isLinkEnd(link)) {
355  if (!lane->getEdge().isInternal()) {
356  if ((*link)->isTLSControlled()) {
357  TraCINextTLSData ntd;
358  ntd.id = (*link)->getTLLogic()->getID();
359  ntd.tlIndex = (*link)->getTLIndex();
360  ntd.dist = seen;
361  ntd.state = (char)(*link)->getState();
362  result.push_back(ntd);
363  }
364  }
365  lane = (*link)->getViaLaneOrLane();
366  if (!lane->getEdge().isInternal()) {
367  view++;
368  }
369  seen += lane->getLength();
370  link = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
371  }
372  }
373  return result;
374 }
375 
376 int
377 TraCI_Vehicle::getStopState(const std::string& vehicleID) {
378  MSVehicle* veh = getVehicle(vehicleID);
379  int result = 0;
380  if (veh->isStopped()) {
381  const MSVehicle::Stop& stop = veh->getNextStop();
382  result = (1 + (stop.pars.parking ? 2 : 0) +
383  (stop.pars.triggered ? 4 : 0) +
384  (stop.pars.containerTriggered ? 8 : 0) +
385  (stop.busstop != 0 ? 16 : 0) +
386  (stop.containerstop != 0 ? 32 : 0) +
387  (stop.chargingStation != 0 ? 64 : 0) +
388  (stop.parkingarea != 0 ? 128 : 0));
389  }
390  return result;
391 }
392 
393 double
394 TraCI_Vehicle::getDistance(const std::string& vehicleID) {
395  MSVehicle* veh = getVehicle(vehicleID);
396  if (veh->isOnRoad()) {
397  double distance;
398  if (veh->getLane()->isInternal()) {
399  // route edge still points to the edge before the intersection
400  const double normalEnd = (*veh->getCurrentRouteEdge())->getLength();
401  distance = (veh->getRoute().getDistanceBetween(veh->getDepartPos(), normalEnd,
402  veh->getRoute().begin(), veh->getCurrentRouteEdge())
403  + veh->getRoute().getDistanceBetween(normalEnd, veh->getPositionOnLane(),
404  *veh->getCurrentRouteEdge(), &veh->getLane()->getEdge()));
405  } else {
406  distance = veh->getRoute().getDistanceBetween(veh->getDepartPos(), veh->getPositionOnLane(),
407  veh->getRoute().begin(), veh->getCurrentRouteEdge());
408  }
409  if (distance == std::numeric_limits<double>::max()) {
410  return INVALID_DOUBLE_VALUE;
411  } else {
412  return distance;
413  }
414  } else {
415  return INVALID_DOUBLE_VALUE;
416  }
417 }
418 
419 
420 double
421 TraCI_Vehicle::getDrivingDistance(const std::string& vehicleID, const std::string& edgeID, double position, int /* laneIndex */) {
422  MSVehicle* veh = getVehicle(vehicleID);
423  if (veh->isOnRoad()) {
424  double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), position,
425  &veh->getLane()->getEdge(), TraCI::getEdge(edgeID));
426  if (distance == std::numeric_limits<double>::max()) {
427  return INVALID_DOUBLE_VALUE;
428  }
429  return distance;
430  } else {
431  return INVALID_DOUBLE_VALUE;
432  }
433 }
434 
435 
436 double
437 TraCI_Vehicle::getDrivingDistance2D(const std::string& vehicleID, double x, double y) {
438  MSVehicle* veh = getVehicle(vehicleID);
439  if (veh->isOnRoad()) {
440  std::pair<MSLane*, double> roadPos = TraCI::convertCartesianToRoadMap(Position(x, y));
441  double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), roadPos.second,
442  veh->getEdge(), &roadPos.first->getEdge());
443  if (distance == std::numeric_limits<double>::max()) {
444  return INVALID_DOUBLE_VALUE;
445  }
446  return distance;
447  } else {
448  return INVALID_DOUBLE_VALUE;
449  }
450 }
451 
452 
453 
454 double
455 TraCI_Vehicle::getAllowedSpeed(const std::string& vehicleID) {
456  MSVehicle* veh = getVehicle(vehicleID);
457  if (veh->isOnRoad()) {
458  return veh->getLane()->getVehicleMaxSpeed(veh);
459  } else {
460  return INVALID_DOUBLE_VALUE;
461  }
462 }
463 
464 double
465 TraCI_Vehicle::getSpeedFactor(const std::string& vehicleID) {
466  return getVehicle(vehicleID)->getChosenSpeedFactor();
467 }
468 
469 
470 int
471 TraCI_Vehicle::getSpeedMode(const std::string& vehicleID) {
472  return getVehicle(vehicleID)->getInfluencer().getSpeedMode();
473 }
474 
475 int
476 TraCI_Vehicle::getLanechangeMode(const std::string& vehicleID) {
477  return getVehicle(vehicleID)->getInfluencer().getLanechangeMode();
478 }
479 
480 int
481 TraCI_Vehicle::getRoutingMode(const std::string& vehicleID) {
482  return getVehicle(vehicleID)->getInfluencer().getRoutingMode();
483 }
484 
485 std::string
486 TraCI_Vehicle::getLine(const std::string& vehicleID) {
487  return getVehicle(vehicleID)->getParameter().line;
488 }
489 
490 std::vector<std::string>
491 TraCI_Vehicle::getVia(const std::string& vehicleID) {
492  return getVehicle(vehicleID)->getParameter().via;
493 }
494 
495 
496 std::pair<int, int>
497 TraCI_Vehicle::getLaneChangeState(const std::string& vehicleID, int direction) {
498  MSVehicle* veh = getVehicle(vehicleID);
499  if (veh->isOnRoad()) {
500  return veh->getLaneChangeModel().getSavedState(direction);
501  } else {
502  return std::make_pair((int)LCA_UNKNOWN, (int)LCA_UNKNOWN);
503  }
504 }
505 
506 
507 std::string
508 TraCI_Vehicle::getParameter(const std::string& vehicleID, const std::string& key) {
509  MSVehicle* veh = getVehicle(vehicleID);
510  if (StringUtils::startsWith(key, "device.")) {
511  StringTokenizer tok(key, ".");
512  if (tok.size() < 3) {
513  throw TraCIException("Invalid device parameter '" + key + "' for vehicle '" + vehicleID + "'");
514  }
515  try {
516  return veh->getDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2));
517  } catch (InvalidArgument& e) {
518  throw TraCIException("Vehicle '" + vehicleID + "' does not support device parameter '" + key + "' (" + e.what() + ").");
519  }
520  } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
521  const std::string attrName = key.substr(16);
522  try {
523  return veh->getLaneChangeModel().getParameter(attrName);
524  } catch (InvalidArgument& e) {
525  throw TraCIException("Vehicle '" + vehicleID + "' does not support laneChangeModel parameter '" + key + "' (" + e.what() + ").");
526  }
527  } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
528  StringTokenizer tok(key, ".");
529  if (tok.size() != 3) {
530  throw TraCIException("Invalid check for device. Expected format is 'has.DEVICENAME.device'");
531  }
532  return veh->hasDevice(tok.get(1)) ? "true" : "false";
533  } else {
534  return veh->getParameter().getParameter(key, "");
535  }
536 }
537 
538 
539 const MSVehicleType&
540 TraCI_Vehicle::getVehicleType(const std::string& vehicleID) {
541  return getVehicle(vehicleID)->getVehicleType();
542 }
543 
544 
545 std::string
546 TraCI_Vehicle::getEmissionClass(const std::string& vehicleID) {
548 }
549 
550 std::string
551 TraCI_Vehicle::getShapeClass(const std::string& vehicleID) {
552  return getVehicleShapeName(getVehicleType(vehicleID).getGuiShape());
553 }
554 
555 
556 double
557 TraCI_Vehicle::getLength(const std::string& vehicleID) {
558  return getVehicleType(vehicleID).getLength();
559 }
560 
561 
562 double
563 TraCI_Vehicle::getAccel(const std::string& vehicleID) {
564  return getVehicleType(vehicleID).getLength();
565 }
566 
567 
568 double
569 TraCI_Vehicle::getDecel(const std::string& vehicleID) {
570  return getVehicleType(vehicleID).getCarFollowModel().getMaxDecel();
571 }
572 
573 
574 double TraCI_Vehicle::getEmergencyDecel(const std::string& vehicleID) {
575  return getVehicleType(vehicleID).getCarFollowModel().getEmergencyDecel();
576 }
577 double TraCI_Vehicle::getApparentDecel(const std::string& vehicleID) {
578  return getVehicleType(vehicleID).getCarFollowModel().getApparentDecel();
579 }
580 double TraCI_Vehicle::getActionStepLength(const std::string& vehicleID) {
581  return getVehicleType(vehicleID).getActionStepLengthSecs();
582 }
583 double TraCI_Vehicle::getLastActionTime(const std::string& vehicleID) {
584  return STEPS2TIME(getVehicle(vehicleID)->getLastActionTime());
585 }
586 
587 double
588 TraCI_Vehicle::getTau(const std::string& vehicleID) {
589  return getVehicleType(vehicleID).getCarFollowModel().getHeadwayTime();
590 }
591 
592 
593 double
594 TraCI_Vehicle::getImperfection(const std::string& vehicleID) {
595  return getVehicleType(vehicleID).getCarFollowModel().getImperfection();
596 }
597 
598 
599 double
600 TraCI_Vehicle::getSpeedDeviation(const std::string& vehicleID) {
601  return getVehicleType(vehicleID).getSpeedFactor().getParameter()[1];
602 }
603 
604 
605 std::string
606 TraCI_Vehicle::getVClass(const std::string& vehicleID) {
607  return toString(getVehicleType(vehicleID).getVehicleClass());
608 }
609 
610 
611 double
612 TraCI_Vehicle::getMinGap(const std::string& vehicleID) {
613  return getVehicleType(vehicleID).getMinGap();
614 }
615 
616 
617 double
618 TraCI_Vehicle::getMaxSpeed(const std::string& vehicleID) {
619  return getVehicleType(vehicleID).getMaxSpeed();
620 }
621 
622 
623 double
624 TraCI_Vehicle::getWidth(const std::string& vehicleID) {
625  return getVehicleType(vehicleID).getWidth();
626 }
627 
628 
629 void
630 TraCI_Vehicle::setStop(const std::string& vehicleID,
631  const std::string& edgeID,
632  double endPos,
633  int laneIndex,
634  SUMOTime duration,
635  int flags,
636  double startPos,
637  SUMOTime until) {
638  MSVehicle* veh = getVehicle(vehicleID);
639  // optional stop flags
640  bool parking = false;
641  bool triggered = false;
642  bool containerTriggered = false;
643  SumoXMLTag stoppingPlaceType = SUMO_TAG_NOTHING;
644 
645  parking = ((flags & 1) != 0);
646  triggered = ((flags & 2) != 0);
647  containerTriggered = ((flags & 4) != 0);
648  if ((flags & 8) != 0) {
649  stoppingPlaceType = SUMO_TAG_BUS_STOP;
650  }
651  if ((flags & 16) != 0) {
652  stoppingPlaceType = SUMO_TAG_CONTAINER_STOP;
653  }
654  if ((flags & 32) != 0) {
655  stoppingPlaceType = SUMO_TAG_CHARGING_STATION;
656  }
657  if ((flags & 64) != 0) {
658  stoppingPlaceType = SUMO_TAG_PARKING_AREA;
659  }
660 
661  std::string error;
662  if (stoppingPlaceType != SUMO_TAG_NOTHING) {
663  // Forward command to vehicle
664  if (!veh->addTraciStopAtStoppingPlace(edgeID, duration, until, parking, triggered, containerTriggered, stoppingPlaceType, error)) {
665  throw TraCIException(error);
666  }
667  } else {
668  // check
669  if (startPos < 0) {
670  throw TraCIException("Position on lane must not be negative.");
671  }
672  if (endPos < startPos) {
673  throw TraCIException("End position on lane must be after start position.");
674  }
675  // get the actual lane that is referenced by laneIndex
676  MSEdge* road = MSEdge::dictionary(edgeID);
677  if (road == 0) {
678  throw TraCIException("Unable to retrieve road with given id.");
679  }
680  const std::vector<MSLane*>& allLanes = road->getLanes();
681  if ((laneIndex < 0) || laneIndex >= (int)(allLanes.size())) {
682  throw TraCIException("No lane with index '" + toString(laneIndex) + "' on road '" + edgeID + "'.");
683  }
684  // Forward command to vehicle
685  if (!veh->addTraciStop(allLanes[laneIndex], startPos, endPos, duration, until, parking, triggered, containerTriggered, error)) {
686  throw TraCIException(error);
687  }
688  }
689 }
690 
691 
692 void
693 TraCI_Vehicle::resume(const std::string& vehicleID) {
694  MSVehicle* veh = getVehicle(vehicleID);
695  if (!veh->hasStops()) {
696  throw TraCIException("Failed to resume vehicle '" + veh->getID() + "', it has no stops.");
697  }
698  if (!veh->resumeFromStopping()) {
699  MSVehicle::Stop& sto = veh->getNextStop();
700  std::ostringstream strs;
701  strs << "reached: " << sto.reached;
702  strs << ", duration:" << sto.duration;
703  strs << ", edge:" << (*sto.edge)->getID();
704  strs << ", startPos: " << sto.pars.startPos;
705  std::string posStr = strs.str();
706  throw TraCIException("Failed to resume from stoppingfor vehicle '" + veh->getID() + "', " + posStr);
707  }
708 }
709 
710 
711 void
712 TraCI_Vehicle::changeTarget(const std::string& vehicleID, const std::string& edgeID) {
713  MSVehicle* veh = getVehicle(vehicleID);
714  const MSEdge* destEdge = MSEdge::dictionary(edgeID);
715  const bool onInit = isOnInit(vehicleID);
716  if (destEdge == 0) {
717  throw TraCIException("Can not retrieve road with ID " + edgeID);
718  }
719  // build a new route between the vehicle's current edge and destination edge
720  ConstMSEdgeVector newRoute;
721  const MSEdge* currentEdge = veh->getRerouteOrigin();
723  currentEdge, destEdge, (const MSVehicle * const) veh, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
724  // replace the vehicle's route by the new one
725  if (!veh->replaceRouteEdges(newRoute, onInit)) {
726  throw TraCIException("Route replacement failed for " + veh->getID());
727  }
728  // route again to ensure usage of via/stops
729  try {
730  veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getRouterTT(), onInit);
731  } catch (ProcessError& e) {
732  throw TraCIException(e.what());
733  }
734 }
735 
736 
737 void
738 TraCI_Vehicle::changeLane(const std::string& vehicleID, int laneIndex, SUMOTime duration) {
739  std::vector<std::pair<SUMOTime, int> > laneTimeLine;
740  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
741  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + duration, laneIndex));
742  getVehicle(vehicleID)->getInfluencer().setLaneTimeLine(laneTimeLine);
743 }
744 
745 
746 void
747 TraCI_Vehicle::changeSublane(const std::string& vehicleID, double latDist) {
748  getVehicle(vehicleID)->getInfluencer().setSublaneChange(latDist);
749 }
750 
751 
752 void
753 TraCI_Vehicle::add(const std::string& vehicleID,
754  const std::string& routeID,
755  const std::string& typeID,
756  std::string depart,
757  const std::string& departLane,
758  const std::string& departPos,
759  const std::string& departSpeed,
760  const std::string& arrivalLane,
761  const std::string& arrivalPos,
762  const std::string& arrivalSpeed,
763  const std::string& fromTaz,
764  const std::string& toTaz,
765  const std::string& line,
766  int personCapacity,
767  int personNumber) {
768  MSVehicle* veh = getVehicle(vehicleID);
769  if (veh != 0) {
770  throw TraCIException("The vehicle " + vehicleID + " to add already exists.");
771  }
772  UNUSED_PARAMETER(routeID);
773  UNUSED_PARAMETER(typeID);
774  UNUSED_PARAMETER(depart);
775  UNUSED_PARAMETER(departLane);
776  UNUSED_PARAMETER(departPos);
777  UNUSED_PARAMETER(departSpeed);
778  UNUSED_PARAMETER(arrivalLane);
779  UNUSED_PARAMETER(arrivalPos);
780  UNUSED_PARAMETER(arrivalSpeed);
781  UNUSED_PARAMETER(fromTaz);
782  UNUSED_PARAMETER(toTaz);
783  UNUSED_PARAMETER(line);
784  UNUSED_PARAMETER(personCapacity);
785  UNUSED_PARAMETER(personNumber);
786 }
787 
788 
789 void
790 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) {
791  getVehicle(vehicleID);
792  UNUSED_PARAMETER(edgeID);
793  UNUSED_PARAMETER(lane);
794  UNUSED_PARAMETER(x);
795  UNUSED_PARAMETER(y);
796  UNUSED_PARAMETER(angle);
797  UNUSED_PARAMETER(keepRoute);
798 }
799 
800 void
801 TraCI_Vehicle::slowDown(const std::string& vehicleID, double speed, SUMOTime duration) {
802  MSVehicle* veh = getVehicle(vehicleID);
803  std::vector<std::pair<SUMOTime, double> > speedTimeLine;
804  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), veh->getSpeed()));
805  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + duration, speed));
806  veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
807 }
808 
809 void
810 TraCI_Vehicle::setSpeed(const std::string& vehicleID, double speed) {
811  getVehicle(vehicleID);
812  UNUSED_PARAMETER(speed);
813 }
814 
815 void
816 TraCI_Vehicle::setType(const std::string& vehicleID, const std::string& typeID) {
817  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
818  if (vehicleType == 0) {
819  throw TraCIException("Vehicle type '" + vehicleID + "' is not known");
820  }
821  getVehicle(vehicleID)->replaceVehicleType(vehicleType);
822 }
823 
824 void
825 TraCI_Vehicle::setRouteID(const std::string& vehicleID, const std::string& routeID) {
826  MSVehicle* veh = getVehicle(vehicleID);
827  const MSRoute* r = MSRoute::dictionary(routeID);
828  if (r == 0) {
829  throw TraCIException("The route '" + routeID + "' is not known.");
830  }
831  std::string msg;
832  if (!veh->hasValidRoute(msg, r)) {
833  WRITE_WARNING("Invalid route replacement for vehicle '" + veh->getID() + "'. " + msg);
835  throw TraCIException("Route replacement failed for " + veh->getID());
836  }
837  }
838 
839  if (!veh->replaceRoute(r, veh->getLane() == 0)) {
840  throw TraCIException("Route replacement failed for " + veh->getID());
841  }
842 }
843 
844 
845 void
846 TraCI_Vehicle::setRoute(const std::string& vehicleID, const std::vector<std::string>& edgeIDs) {
847  MSVehicle* veh = getVehicle(vehicleID);
848  ConstMSEdgeVector edges;
849  try {
850  MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
851  } catch (ProcessError& e) {
852  throw TraCIException("Invalid edge list for vehicle '" + veh->getID() + "' (" + e.what() + ")");
853  }
854  if (!veh->replaceRouteEdges(edges, veh->getLane() == 0, true)) {
855  throw TraCIException("Route replacement failed for " + veh->getID());
856  }
857 }
858 
859 void
860 TraCI_Vehicle::setAdaptedTraveltime(const std::string& vehicleID, const std::string& edgeID,
861  double time, SUMOTime begTime, SUMOTime endTime) {
862  MSVehicle* veh = getVehicle(vehicleID);
863  MSEdge* edge = MSEdge::dictionary(edgeID);
864  if (edge == 0) {
865  throw TraCIException("Referended edge '" + edgeID + "' is not known.");
866  }
867  if (time != INVALID_DOUBLE_VALUE) {
868  // add time
869  if (begTime == 0 && endTime == SUMOTime_MAX) {
870  // clean up old values before setting whole range
871  while (veh->getWeightsStorage().knowsTravelTime(edge)) {
872  veh->getWeightsStorage().removeTravelTime(edge);
873  }
874  }
875  veh->getWeightsStorage().addTravelTime(edge, STEPS2TIME(begTime), STEPS2TIME(endTime), time);
876  } else {
877  // remove time
878  while (veh->getWeightsStorage().knowsTravelTime(edge)) {
879  veh->getWeightsStorage().removeTravelTime(edge);
880  }
881  }
882 }
883 
884 
885 void
886 TraCI_Vehicle::setEffort(const std::string& vehicleID, const std::string& edgeID,
887  double effort, SUMOTime begTime, SUMOTime endTime) {
888  MSVehicle* veh = getVehicle(vehicleID);
889  MSEdge* edge = MSEdge::dictionary(edgeID);
890  if (edge == 0) {
891  throw TraCIException("Referended edge '" + edgeID + "' is not known.");
892  }
893  if (effort != INVALID_DOUBLE_VALUE) {
894  // add effort
895  if (begTime == 0 && endTime == SUMOTime_MAX) {
896  // clean up old values before setting whole range
897  while (veh->getWeightsStorage().knowsEffort(edge)) {
898  veh->getWeightsStorage().removeEffort(edge);
899  }
900  }
901  veh->getWeightsStorage().addEffort(edge, STEPS2TIME(begTime), STEPS2TIME(endTime), effort);
902  } else {
903  // remove effort
904  while (veh->getWeightsStorage().knowsEffort(edge)) {
905  veh->getWeightsStorage().removeEffort(edge);
906  }
907  }
908 }
909 
910 
911 void
912 TraCI_Vehicle::rerouteTraveltime(const std::string& vehicleID) {
913  MSVehicle* veh = getVehicle(vehicleID);
914  veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getRouterTT(), isOnInit(vehicleID));
915 }
916 
917 
918 void
919 TraCI_Vehicle::rerouteEffort(const std::string& vehicleID) {
920  MSVehicle* veh = getVehicle(vehicleID);
921  veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), MSNet::getInstance()->getRouterEffort(), isOnInit(vehicleID));
922 }
923 
924 
925 void
926 TraCI_Vehicle::setSignals(const std::string& vehicleID, int signals) {
927  MSVehicle* veh = getVehicle(vehicleID);
928  // set influencer to make the change persistent
929  veh->getInfluencer().setSignals(signals);
930  // set them now so that getSignals returns the correct value
931  veh->switchOffSignal(0x0fffffff);
932  if (signals >= 0) {
933  veh->switchOnSignal(signals);
934  }
935 }
936 
937 
938 void
939 TraCI_Vehicle::moveTo(const std::string& vehicleID, const std::string& laneID, double position) {
940  MSVehicle* veh = getVehicle(vehicleID);
941  MSLane* l = MSLane::dictionary(laneID);
942  if (l == 0) {
943  throw TraCIException("Unknown lane '" + laneID + "'.");
944  }
945  MSEdge& destinationEdge = l->getEdge();
946  if (!veh->willPass(&destinationEdge)) {
947  throw TraCIException("Vehicle '" + laneID + "' may be set onto an edge to pass only.");
948  }
950  if (veh->getLane() != 0) {
952  } else {
953  veh->setTentativeLaneAndPosition(l, position);
954  }
955  while (veh->getEdge() != &destinationEdge) {
956  const MSEdge* nextEdge = veh->succEdge(1);
957  // let the vehicle move to the next edge
958  if (veh->enterLaneAtMove(nextEdge->getLanes()[0], true)) {
960  continue;
961  }
962  }
963  if (!veh->isOnRoad()) {
965 
966  }
967  l->forceVehicleInsertion(veh, position,
969 }
970 
971 
972 void
973 TraCI_Vehicle::setMaxSpeed(const std::string& vehicleID, double speed) {
974  getVehicle(vehicleID)->getSingularType().setMaxSpeed(speed);
975 }
976 
977 void
978 TraCI_Vehicle::setActionStepLength(const std::string& vehicleID, double actionStepLength, bool resetActionOffset) {
979  if (actionStepLength < 0.0) {
980  WRITE_ERROR("Invalid action step length (<0). Ignoring command setActionStepLength().");
981  return;
982  }
983  MSVehicle* veh = getVehicle(vehicleID);
984  if(actionStepLength==0.) {
985  veh->resetActionOffset();
986  return;
987  }
988  SUMOTime actionStepLengthMillisecs = SUMOVehicleParserHelper::processActionStepLength(actionStepLength);
989  SUMOTime previousActionStepLength = veh->getActionStepLength();
990  veh->getSingularType().setActionStepLength(actionStepLengthMillisecs, resetActionOffset);
991  if(resetActionOffset) {
992  veh->resetActionOffset();
993  } else {
994  veh->updateActionOffset(previousActionStepLength, actionStepLengthMillisecs);
995  }
996 }
997 
998 void
999 TraCI_Vehicle::remove(const std::string& vehicleID, char reason) {
1000  getVehicle(vehicleID);
1001  UNUSED_PARAMETER(reason);
1002 }
1003 
1004 
1005 void
1006 TraCI_Vehicle::setColor(const std::string& vehicleID, const TraCIColor& col) {
1007  const SUMOVehicleParameter& p = getVehicle(vehicleID)->getParameter();
1008  p.color.set(col.r, col.g, col.b, col.a);
1010 }
1011 
1012 
1013 void
1014 TraCI_Vehicle::setLine(const std::string& vehicleID, const std::string& line) {
1015  getVehicle(vehicleID)->getParameter().line = line;
1016 }
1017 
1018 void
1019 TraCI_Vehicle::setVia(const std::string& vehicleID, const std::vector<std::string>& via) {
1020  getVehicle(vehicleID);
1021  UNUSED_PARAMETER(via);
1022 }
1023 
1024 void
1025 TraCI_Vehicle::setShapeClass(const std::string& vehicleID, const std::string& clazz) {
1026  getVehicle(vehicleID)->getSingularType().setShape(getVehicleShapeID(clazz));
1027 }
1028 
1029 void
1030 TraCI_Vehicle::setEmissionClass(const std::string& vehicleID, const std::string& clazz) {
1031  getVehicle(vehicleID);
1032  UNUSED_PARAMETER(clazz);
1033 }
1034 
1035 
1036 void
1037 TraCI_Vehicle::setParameter(const std::string& vehicleID, const std::string& key, const std::string& value) {
1038  MSVehicle* veh = getVehicle(vehicleID);
1039  if (StringUtils::startsWith(key, "device.")) {
1040  StringTokenizer tok(key, ".");
1041  if (tok.size() < 3) {
1042  throw TraCIException("Invalid device parameter '" + key + "' for vehicle '" + vehicleID + "'");
1043  }
1044  try {
1045  veh->setDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2), value);
1046  } catch (InvalidArgument& e) {
1047  throw TraCIException("Vehicle '" + vehicleID + "' does not support device parameter '" + key + "' (" + e.what() + ").");
1048  }
1049  } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
1050  const std::string attrName = key.substr(16);
1051  try {
1052  veh->getLaneChangeModel().setParameter(attrName, value);
1053  } catch (InvalidArgument& e) {
1054  throw TraCIException("Vehicle '" + vehicleID + "' does not support laneChangeModel parameter '" + key + "' (" + e.what() + ").");
1055  }
1056  } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
1057  StringTokenizer tok(key, ".");
1058  if (tok.size() != 3) {
1059  throw TraCIException("Invalid request for device status change. Expected format is 'has.DEVICENAME.device'");
1060  }
1061  const std::string deviceName = tok.get(1);
1062  bool create;
1063  try {
1064  create = TplConvert::_2bool(value.c_str());
1065  } catch (BoolFormatException) {
1066  throw TraCIException("Changing device status requires a 'true' or 'false'");
1067  }
1068  if (!create) {
1069  throw TraCIException("Device removal is not supported for device of type '" + deviceName + "'");
1070  }
1071  try {
1072  veh->createDevice(deviceName);
1073  } catch (InvalidArgument& e) {
1074  throw TraCIException("Cannot create vehicle device (" + std::string(e.what()) + ").");
1075  }
1076  } else {
1077  ((SUMOVehicleParameter&) veh->getParameter()).setParameter(key, value);
1078  }
1079 }
1080 
1081 
1082 /****************************************************************************/
static void setSignals(const std::string &vehicleID, int signals)
double x
Definition: TraCIDefs.h:71
double getMinGap() const
Get the free space in front of vehicles of this class.
static double getMinGap(const std::string &vehicleID)
static bool isOnInit(const std::string &vehicleID)
SumoXMLTag
Numbers representing SUMO-XML - element names.
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:3445
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:583
RGBColor color
The vehicle&#39;s color, TraCI may change this.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
bool isLinkEnd(MSLinkCont::const_iterator &i) const
Definition: MSLane.cpp:1671
static double getLength(const std::string &vehicleID)
static MSLinkCont::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
Definition: MSLane.cpp:1738
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
static int getPersonNumber(const std::string &vehicleID)
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:200
static void setRouteID(const std::string &vehicleID, const std::string &routeID)
bool parking
whether the vehicle is removed from the net while stopping
static std::vector< TraCINextTLSData > getNextTLS(const std::string &vehicleID)
Stop & getNextStop()
Definition: MSVehicle.cpp:4697
static double getAccel(const std::string &vehicleID)
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)
static double getApparentDecel(const std::string &vehicleID)
bool resumeFromStopping()
Definition: MSVehicle.cpp:4646
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...
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
static bool _2bool(const E *const data)
converts a 0-terminated char-type array into the boolean value described by it
Definition: TplConvert.h:388
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:798
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
void setShape(SUMOVehicleShape shape)
Set a new value for this type&#39;s shape.
int getLanechangeMode() const
return the current lane change mode
Definition: MSVehicle.cpp:292
static void setLine(const std::string &vehicleID, const std::string &line)
static double getAccumulatedWaitingTime(const std::string &vehicleID)
static double getPMxEmission(const std::string &vehicleID)
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition: MSVehicle.h:904
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: TraCI.cpp:139
SUMOTime duration
The stopping duration.
Definition: MSVehicle.h:906
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
static double getAllowedSpeed(const std::string &vehicleID)
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static double getDistance(const std::string &vehicleID)
MSParkingArea * parkingarea
(Optional) parkingArea if one is assigned to the stop
Definition: MSVehicle.h:900
MSStoppingPlace * busstop
(Optional) bus stop if one is assigned to the stop
Definition: MSVehicle.h:896
static void setRoute(const std::string &vehicleID, const std::vector< std::string > &edgeIDs)
static MSEdge * getEdge(const std::string &edgeID)
Definition: TraCI.cpp:171
static void setColor(const std::string &vehicleID, const TraCIColor &col)
static void changeSublane(const std::string &vehicleID, double latDist)
int parametersSet
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
static double getNOxEmission(const std::string &vehicleID)
static std::vector< std::string > getVia(const std::string &vehicleID)
bool reached
Information whether the stop has been reached.
Definition: MSVehicle.h:912
static double getWaitingTime(const std::string &vehicleID)
unsigned char g
Definition: TraCIDefs.h:78
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:1857
double getCO2Emissions() const
Returns CO2 emission of the current state.
Definition: MSVehicle.cpp:4104
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
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:4566
static SUMOTime processActionStepLength(double given)
Checks and converts given value for the action step length from seconds to miliseconds assuring it be...
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:246
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:483
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
const std::pair< int, int > & getSavedState(const int dir) const
static bool isVisible(const MSVehicle *veh)
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
const MSRoute & getRoute() const
Returns the current route.
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
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)
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:896
double getHCEmissions() const
Returns HC emission of the current state.
Definition: MSVehicle.cpp:4116
bool hasDeparted() const
Returns whether this vehicle has already departed.
unsigned char r
Definition: TraCIDefs.h:78
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:744
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:401
static std::string getEmissionClass(const std::string &vehicleID)
static void setParameter(const std::string &vehicleID, const std::string &key, const std::string &value)
static MSVehicle * getVehicle(const std::string &id)
double getAngle() const
Returns the vehicle&#39;s direction in radians.
Definition: MSVehicle.h:671
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
bool isInternal() const
Definition: MSLane.cpp:1687
static int getRouteIndex(const std::string &vehicleID)
static std::pair< int, int > getLaneChangeState(const std::string &vehicleID, int direction)
void setMaxSpeed(const double &maxSpeed)
Set a new value for this type&#39;s maximum speed.
double nextOccupation
As occupation, but without the first lane.
Definition: MSVehicle.h:796
double length
The overall length which may be driven when using this lane without a lane change.
Definition: MSVehicle.h:790
static std::string getRouteID(const std::string &vehicleID)
unsigned char a
Definition: TraCIDefs.h:78
static std::vector< std::string > getIDList()
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
Definition: MSVehicle.h:960
static double getCO2Emission(const std::string &vehicleID)
static double getSpeedDeviation(const std::string &vehicleID)
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
static int getStopState(const std::string &vehicleID)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static double getSpeedWithoutTraCI(const std::string &vehicleID)
The car-following model and parameter.
Definition: MSVehicleType.h:72
double getEmergencyDecel() const
Get the vehicle type&#39;s maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:219
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3640
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
static double getActionStepLength(const std::string &vehicleID)
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
static double getTau(const std::string &vehicleID)
double getSpeedWithoutTraciInfluence() const
Returns the uninfluenced velocity.
Definition: MSVehicle.cpp:4718
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:885
double z
Definition: TraCIDefs.h:71
static std::string getLine(const std::string &vehicleID)
static TraCIPosition getPosition(const std::string &vehicleID)
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...
const std::string & getID() const
Returns the id.
Definition: Named.h:65
A road/street connecting two junctions.
Definition: MSEdge.h:80
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
Definition: MSVehicle.cpp:265
static double getAdaptedTraveltime(const std::string &vehicleID, const std::string &edgeID, int time)
double getElectricityConsumption() const
Returns electricity consumption of the current state.
Definition: MSVehicle.cpp:4140
MSLane * lane
The described lane.
Definition: MSVehicle.h:788
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:186
The action has not been determined.
static void changeLane(const std::string &vehicleID, int laneIndex, SUMOTime duration)
static void setMaxSpeed(const std::string &vehicleID, double speed)
static double getLastActionTime(const std::string &vehicleID)
static double getEmergencyDecel(const std::string &vehicleID)
static double getWidth(const std::string &vehicleID)
static void setActionStepLength(const std::string &vehicleID, double actionStepLength, bool resetActionOffset=true)
static double getNoiseEmission(const std::string &vehicleID)
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
void setSublaneChange(double latDist)
Sets a new sublane-change request.
Definition: MSVehicle.cpp:277
static void setEmissionClass(const std::string &vehicleID, const std::string &clazz)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
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:66
static double getDrivingDistance2D(const std::string &vehicleID, double x, double y)
static bool isRouteValid(const std::string &vehicleID)
static bool gCheckRoutes
Definition: MSGlobals.h:85
double startPos
The stopping position start.
A 3D-position.
Definition: TraCIDefs.h:70
virtual double getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:238
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:211
static double getElectricityConsumption(const std::string &vehicleID)
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
Definition: MSVehicle.cpp:3992
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
MSRouteIterator edge
The edge in the route to stop at.
Definition: MSVehicle.h:892
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 ...
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition: RGBColor.cpp:82
bool willPass(const MSEdge *const edge) const
Returns whether the vehicle wil pass the given edge.
Definition: MSVehicle.cpp:791
#define SUMOTime_MAX
Definition: TraCIDefs.h:52
bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)
Replaces the current route by the given one.
Definition: MSVehicle.cpp:727
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
static int getRoutingMode(const std::string &vehicleID)
static void setType(const std::string &vehicleID, const std::string &typeID)
bool triggered
whether an arriving person lets the vehicle continue
void addTravelTime(const MSEdge *const e, double begin, double end, double value)
Adds a travel time information for an edge and a time span.
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:64
static double getAngle(const std::string &vehicleID)
static int getSignalStates(const std::string &vehicleID)
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MSVehicle.cpp:1327
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:182
void forceVehicleInsertion(MSVehicle *veh, double pos, MSMoveReminder::Notification notification, double posLat=0)
Inserts the given vehicle at the given position.
Definition: MSLane.cpp:909
double getPMxEmissions() const
Returns PMx emission of the current state.
Definition: MSVehicle.cpp:4128
void resetActionOffset(const SUMOTime timeUntilNextAction=0)
Resets the action offset for the vehicle.
Definition: MSVehicle.cpp:1608
bool replaceRouteEdges(ConstMSEdgeVector &edges, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
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:786
static double getImperfection(const std::string &vehicleID)
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:704
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
int getRoutingMode() const
return the current routing mode
Definition: MSVehicle.h:1349
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
static void moveTo(const std::string &vehicleID, const std::string &laneID, double position)
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)
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getActionStepLengthSecs() const
Returns this type&#39;s default action step length in seconds.
static void setEffort(const std::string &vehicleID, const std::string &edgeID, double effort=INVALID_DOUBLE_VALUE, SUMOTime begTime=0, SUMOTime endTime=SUMOTime_MAX)
int getIndex() const
Returns the lane&#39;s index.
Definition: MSLane.h:506
const int VEHPARS_COLOR_SET
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:229
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:647
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:1353
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
Definition: MSVehicle.cpp:3652
int getRoutePosition() const
Definition: MSVehicle.cpp:797
bool containerTriggered
whether an arriving container lets the vehicle continue
double dist
The distance to the tls.
Definition: TraCIDefs.h:184
int getPersonNumber() const
Returns the number of persons.
Definition: MSVehicle.cpp:4213
bool allowsContinuation
Whether this lane allows to continue the drive.
Definition: MSVehicle.h:800
double getNOxEmissions() const
Returns NOx emission of the current state.
Definition: MSVehicle.cpp:4122
std::string line
The vehicle&#39;s line (mainly for public transport)
#define INVALID_DOUBLE_VALUE
void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset)
Set a new value for this type&#39;s action step length.
static double getHCEmission(const std::string &vehicleID)
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
static double getCOEmission(const std::string &vehicleID)
static int getIDCount()
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:894
static std::pair< MSLane *, double > convertCartesianToRoadMap(Position pos)
Definition: TraCI.cpp:196
std::string id
The id of the next tls.
Definition: TraCIDefs.h:180
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)
virtual std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this laneChangeModel. Throw exception for unsupported key ...
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:4753
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
static double getSlope(const std::string &vehicleID)
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:4522
double getLength() const
Get vehicle&#39;s length [m].
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1561
const Distribution_Parameterized & getSpeedFactor() const
Returns this type&#39;s speed factor.
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
The vehicle has departed (was inserted into the network)
static std::string getVClass(const std::string &vehicleID)
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:4703
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
Structure representing possible vehicle parameter.
#define INVALID_INT_VALUE
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:79
static void changeTarget(const std::string &vehicleID, const std::string &edgeID)
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:192
void setTentativeLaneAndPosition(MSLane *lane, double pos, double posLat=0)
set tentative lane and position during insertion to ensure that all cfmodels work (some of them requi...
Definition: MSVehicle.cpp:4287
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:359
static std::string getShapeClass(const std::string &vehicleID)
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:806
MSStoppingPlace * chargingStation
(Optional) charging station if one is assigned to the stop
Definition: MSVehicle.h:902
A color.
Definition: TraCIDefs.h:77
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:4064
static double getSpeedFactor(const std::string &vehicleID)
MSStoppingPlace * containerstop
(Optional) container stop if one is assigned to the stop
Definition: MSVehicle.h:898
std::string get(int pos) const
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
static void setVia(const std::string &vehicleID, const std::vector< std::string > &via)
double length
The length than can be driven from that lane without lane change.
Definition: TraCIDefs.h:194
SUMOTime getActionStepLength() const
Returns the vehicle&#39;s action step length in millisecs, i.e. the interval between two action points...
Definition: MSVehicle.h:495
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:198
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:202
double occupation
The traffic density along length.
Definition: TraCIDefs.h:196
const std::string & getID() const
Returns the name of the vehicle type.
void updateActionOffset(const SUMOTime oldActionStepLength, const SUMOTime newActionStepLength)
Process an updated action step length value (only affects the vehicle&#39;s action offset, The actionStepLength is stored in the (singular) vtype)
Definition: MSVehicle.cpp:1613
static std::string getRoadID(const std::string &vehicleID)
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:433
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
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:461
char state
The current state of the tls.
Definition: TraCIDefs.h:186
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
static void rerouteTraveltime(const std::string &vehicleID)
double getAccumulatedWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s) within the last millisecs...
Definition: MSVehicle.h:657
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:280
void setSignals(int signals)
Definition: MSVehicle.h:1438
static double getDrivingDistance(const std::string &vehicleID, const std::string &edgeID, double position, int laneIndex)
static double getLateralLanePosition(const std::string &vehicleID)
unsigned char b
Definition: TraCIDefs.h:78
static void slowDown(const std::string &vehicleID, double speed, SUMOTime duration)
const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
Definition: MSVehicle.cpp:1006
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
static int getSpeedMode(const std::string &vehicleID)
static TraCIPosition makeTraCIPosition(const Position &position)
Definition: TraCI.cpp:155
static double getMaxSpeed(const std::string &vehicleID)
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:1218
static int getLanechangeMode(const std::string &vehicleID)
void switchOffSignal(int signal)
Switches the given signal off.
Definition: MSVehicle.h:1210
void switchOnSignal(int signal)
Switches the given signal on.
Definition: MSVehicle.h:1202
double getFuelConsumption() const
Returns fuel consumption of the current state.
Definition: MSVehicle.cpp:4134
double getCOEmissions() const
Returns CO emission of the current state.
Definition: MSVehicle.cpp:4110
static std::string getTypeID(const std::string &vehicleID)
static int getLaneIndex(const std::string &vehicleID)
long long int SUMOTime
Definition: TraCIDefs.h:51
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
double y
Definition: TraCIDefs.h:71
void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)
Performs a rerouting using the given router.
int getSpeedMode() const
return the current speed mode
Definition: MSVehicle.cpp:282
void setLaneTimeLine(const std::vector< std::pair< SUMOTime, int > > &laneTimeLine)
Sets a new lane timeline.
Definition: MSVehicle.cpp:272
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
The class responsible for building and deletion of vehicles.
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:227
static void resume(const std::string &vehicleID)
double getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
Definition: MSVehicle.cpp:4146
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:573
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
static double getSpeed(const std::string &vehicleID)
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:551
static void rerouteEffort(const std::string &vehicleID)
static double getLanePosition(const std::string &vehicleID)
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle&#39;s internal edge travel times/efforts container.
Definition: MSVehicle.cpp:812
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
static std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist)
static std::vector< std::string > getEdges(const std::string &vehicleID)
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:801
static std::vector< TraCIBestLanesData > getBestLanes(const std::string &vehicleID)
static void setAdaptedTraveltime(const std::string &vehicleID, const std::string &edgeID, double time=INVALID_DOUBLE_VALUE, SUMOTime begTime=0, SUMOTime endTime=SUMOTime_MAX)
double getDepartPos() const
Returns this vehicle&#39;s real departure position.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:73
static void setSpeed(const std::string &vehicleID, double speed)
static void setShapeClass(const std::string &vehicleID, const std::string &clazz)
The vehicle is being teleported.
static double getEffort(const std::string &vehicleID, const std::string &edgeID, int time)
Definition of vehicle stop (position and duration)
Definition: MSVehicle.h:888
const std::string & getID() const
Returns the name of the vehicle.
void addEffort(const MSEdge *const e, double begin, double end, double value)
Adds an effort information for an edge and a time span.
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:469
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:117
static double getDecel(const std::string &vehicleID)