SUMO - Simulation of Urban MObility
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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // C++ Vehicle API
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <utils/geom/GeomHelper.h>
33 #include <microsim/MSVehicle.h>
35 #include <microsim/MSVehicleType.h>
37 #include <microsim/MSNet.h>
38 #include <microsim/MSEdge.h>
39 #include <microsim/MSLane.h>
40 #include <microsim/MSParkingArea.h>
41 #include <libsumo/TraCIDefs.h>
43 #include "Helper.h"
44 #include "Route.h"
45 #include "Vehicle.h"
46 
47 
48 namespace libsumo {
49 // ===========================================================================
50 // static member initializations
51 // ===========================================================================
54 
55 
56 // ===========================================================================
57 // static member definitions
58 // ===========================================================================
59 MSVehicle*
60 Vehicle::getVehicle(const std::string& id) {
62  if (sumoVehicle == nullptr) {
63  throw TraCIException("Vehicle '" + id + "' is not known");
64  }
65  MSVehicle* v = dynamic_cast<MSVehicle*>(sumoVehicle);
66  if (v == nullptr) {
67  throw TraCIException("Vehicle '" + id + "' is not a micro-simulation vehicle");
68  }
69  return v;
70 }
71 
72 
73 bool
75  return veh->isOnRoad() || veh->isParking() || veh->wasRemoteControlled();
76 }
77 
78 
79 bool
80 Vehicle::isOnInit(const std::string& vehicleID) {
81  SUMOVehicle* sumoVehicle = MSNet::getInstance()->getVehicleControl().getVehicle(vehicleID);
82  return sumoVehicle == nullptr || sumoVehicle->getLane() == nullptr;
83 }
84 
85 std::vector<std::string>
87  std::vector<std::string> ids;
89  for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
90  if (isVisible((*i).second)) {
91  ids.push_back((*i).first);
92  }
93  }
94  return ids;
95 }
96 
97 int
99  return (int)getIDList().size();
100 }
101 
102 
103 double
104 Vehicle::getSpeed(const std::string& vehicleID) {
105  MSVehicle* veh = getVehicle(vehicleID);
106  return isVisible(veh) ? veh->getSpeed() : INVALID_DOUBLE_VALUE;
107 }
108 
109 
110 double
111 Vehicle::getAcceleration(const std::string& vehicleID) {
112  MSVehicle* veh = getVehicle(vehicleID);
113  return isVisible(veh) ? veh->getAcceleration() : INVALID_DOUBLE_VALUE;
114 }
115 
116 
117 double
118 Vehicle::getSpeedWithoutTraCI(const std::string& vehicleID) {
119  MSVehicle* veh = getVehicle(vehicleID);
121 }
122 
123 
125 Vehicle::getPosition(const std::string& vehicleID, const bool includeZ) {
126  MSVehicle* veh = getVehicle(vehicleID);
127  if (isVisible(veh)) {
128  return Helper::makeTraCIPosition(veh->getPosition(), includeZ);
129  }
130  TraCIPosition pos;
131  pos.x = INVALID_DOUBLE_VALUE;
132  pos.y = INVALID_DOUBLE_VALUE;
133  pos.z = INVALID_DOUBLE_VALUE;
134  return pos;
135 }
136 
137 
139 Vehicle::getPosition3D(const std::string& vehicleID) {
140  return getPosition(vehicleID, true);
141 }
142 
143 
144 double
145 Vehicle::getAngle(const std::string& vehicleID) {
146  MSVehicle* veh = getVehicle(vehicleID);
148 }
149 
150 
151 double
152 Vehicle::getSlope(const std::string& vehicleID) {
153  MSVehicle* veh = getVehicle(vehicleID);
154  return veh->isOnRoad() ? veh->getSlope() : INVALID_DOUBLE_VALUE;
155 }
156 
157 
158 std::string
159 Vehicle::getRoadID(const std::string& vehicleID) {
160  MSVehicle* veh = getVehicle(vehicleID);
161  return isVisible(veh) ? veh->getLane()->getEdge().getID() : "";
162 }
163 
164 
165 std::string
166 Vehicle::getLaneID(const std::string& vehicleID) {
167  MSVehicle* veh = getVehicle(vehicleID);
168  return veh->isOnRoad() ? veh->getLane()->getID() : "";
169 }
170 
171 
172 int
173 Vehicle::getLaneIndex(const std::string& vehicleID) {
174  MSVehicle* veh = getVehicle(vehicleID);
175  return veh->isOnRoad() ? veh->getLane()->getIndex() : INVALID_INT_VALUE;
176 }
177 
178 
179 std::string
180 Vehicle::getTypeID(const std::string& vehicleID) {
181  return getVehicle(vehicleID)->getVehicleType().getID();
182 }
183 
184 
185 std::string
186 Vehicle::getRouteID(const std::string& vehicleID) {
187  return getVehicle(vehicleID)->getRoute().getID();
188 }
189 
190 
191 int
192 Vehicle::getRouteIndex(const std::string& vehicleID) {
193  MSVehicle* veh = getVehicle(vehicleID);
194  return veh->hasDeparted() ? veh->getRoutePosition() : INVALID_INT_VALUE;
195 }
196 
197 
199 Vehicle::getColor(const std::string& vehicleID) {
200  return Helper::makeTraCIColor(getVehicle(vehicleID)->getParameter().color);
201 }
202 
203 double
204 Vehicle::getLanePosition(const std::string& vehicleID) {
205  MSVehicle* veh = getVehicle(vehicleID);
206  return veh->isOnRoad() ? veh->getPositionOnLane() : INVALID_DOUBLE_VALUE;
207 }
208 
209 double
210 Vehicle::getLateralLanePosition(const std::string& vehicleID) {
211  MSVehicle* veh = getVehicle(vehicleID);
212  return veh->isOnRoad() ? veh->getLateralPositionOnLane() : INVALID_DOUBLE_VALUE;
213 }
214 
215 double
216 Vehicle::getCO2Emission(const std::string& vehicleID) {
217  MSVehicle* veh = getVehicle(vehicleID);
218  return isVisible(veh) ? veh->getCO2Emissions() : INVALID_DOUBLE_VALUE;
219 }
220 
221 double
222 Vehicle::getCOEmission(const std::string& vehicleID) {
223  MSVehicle* veh = getVehicle(vehicleID);
224  return isVisible(veh) ? veh->getCOEmissions() : INVALID_DOUBLE_VALUE;
225 }
226 
227 double
228 Vehicle::getHCEmission(const std::string& vehicleID) {
229  MSVehicle* veh = getVehicle(vehicleID);
230  return isVisible(veh) ? veh->getHCEmissions() : INVALID_DOUBLE_VALUE;
231 }
232 
233 double
234 Vehicle::getPMxEmission(const std::string& vehicleID) {
235  MSVehicle* veh = getVehicle(vehicleID);
236  return isVisible(veh) ? veh->getPMxEmissions() : INVALID_DOUBLE_VALUE;
237 }
238 
239 double
240 Vehicle::getNOxEmission(const std::string& vehicleID) {
241  MSVehicle* veh = getVehicle(vehicleID);
242  return isVisible(veh) ? veh->getNOxEmissions() : INVALID_DOUBLE_VALUE;
243 }
244 
245 double
246 Vehicle::getFuelConsumption(const std::string& vehicleID) {
247  MSVehicle* veh = getVehicle(vehicleID);
248  return isVisible(veh) ? veh->getFuelConsumption() : INVALID_DOUBLE_VALUE;
249 }
250 
251 double
252 Vehicle::getNoiseEmission(const std::string& vehicleID) {
253  MSVehicle* veh = getVehicle(vehicleID);
255 }
256 
257 double
258 Vehicle::getElectricityConsumption(const std::string& vehicleID) {
259  MSVehicle* veh = getVehicle(vehicleID);
261 }
262 
263 int
264 Vehicle::getPersonNumber(const std::string& vehicleID) {
265  return getVehicle(vehicleID)->getPersonNumber();
266 }
267 
268 std::vector<std::string>
269 Vehicle::getPersonIDList(const std::string& vehicleID) {
270  return getVehicle(vehicleID)->getPersonIDList();
271 }
272 
273 std::pair<std::string, double>
274 Vehicle::getLeader(const std::string& vehicleID, double dist) {
275  MSVehicle* veh = getVehicle(vehicleID);
276  if (veh->isOnRoad()) {
277  std::pair<const MSVehicle* const, double> leaderInfo = veh->getLeader(dist);
278  return std::make_pair(
279  leaderInfo.first != nullptr ? leaderInfo.first->getID() : "",
280  leaderInfo.second);
281  } else {
282  return std::make_pair("", -1);
283  }
284 }
285 
286 
287 double
288 Vehicle::getWaitingTime(const std::string& vehicleID) {
289  return getVehicle(vehicleID)->getWaitingSeconds();
290 }
291 
292 
293 double
294 Vehicle::getAccumulatedWaitingTime(const std::string& vehicleID) {
295  return getVehicle(vehicleID)->getAccumulatedWaitingSeconds();
296 }
297 
298 
299 double
300 Vehicle::getAdaptedTraveltime(const std::string& vehicleID, double time, const std::string& edgeID) {
301  MSEdge* edge = Helper::getEdge(edgeID);
302  double value = INVALID_DOUBLE_VALUE;
303  getVehicle(vehicleID)->getWeightsStorage().retrieveExistingTravelTime(edge, time, value);
304  return value;
305 }
306 
307 
308 double
309 Vehicle::getEffort(const std::string& vehicleID, double time, const std::string& edgeID) {
310  MSEdge* edge = Helper::getEdge(edgeID);
311  double value = INVALID_DOUBLE_VALUE;
312  getVehicle(vehicleID)->getWeightsStorage().retrieveExistingEffort(edge, time, value);
313  return value;
314 }
315 
316 
317 bool
318 Vehicle::isRouteValid(const std::string& vehicleID) {
319  std::string msg;
320  return getVehicle(vehicleID)->hasValidRoute(msg);
321 }
322 
323 
324 std::vector<std::string>
325 Vehicle::getRoute(const std::string& vehicleID) {
326  std::vector<std::string> result;
327  MSVehicle* veh = getVehicle(vehicleID);
328  const MSRoute& r = veh->getRoute();
329  for (MSRouteIterator i = r.begin(); i != r.end(); ++i) {
330  result.push_back((*i)->getID());
331  }
332  return result;
333 }
334 
335 
336 int
337 Vehicle::getSignals(const std::string& vehicleID) {
338  return getVehicle(vehicleID)->getSignals();
339 }
340 
341 
342 std::vector<TraCIBestLanesData>
343 Vehicle::getBestLanes(const std::string& vehicleID) {
344  std::vector<TraCIBestLanesData> result;
345  MSVehicle* veh = getVehicle(vehicleID);
346  if (veh->isOnRoad()) {
347  const std::vector<MSVehicle::LaneQ>& bestLanes = veh->getBestLanes();
348  for (std::vector<MSVehicle::LaneQ>::const_iterator i = bestLanes.begin(); i != bestLanes.end(); ++i) {
349  TraCIBestLanesData bld;
350  const MSVehicle::LaneQ& lq = *i;
351  bld.laneID = lq.lane->getID();
352  bld.length = lq.length;
353  bld.occupation = lq.nextOccupation;
356  for (std::vector<MSLane*>::const_iterator j = lq.bestContinuations.begin(); j != lq.bestContinuations.end(); ++j) {
357  if ((*j) != nullptr) {
358  bld.continuationLanes.push_back((*j)->getID());
359  }
360  }
361  result.push_back(bld);
362  }
363  }
364  return result;
365 }
366 
367 
368 std::vector<TraCINextTLSData>
369 Vehicle::getNextTLS(const std::string& vehicleID) {
370  std::vector<TraCINextTLSData> result;
371  MSVehicle* veh = getVehicle(vehicleID);
372  if (veh->isOnRoad()) {
373  const MSLane* lane = veh->getLane();
374  const std::vector<MSLane*>& bestLaneConts = veh->getBestLanesContinuation(lane);
375  double seen = veh->getLane()->getLength() - veh->getPositionOnLane();
376  int view = 1;
377  MSLinkCont::const_iterator link = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
378  while (!lane->isLinkEnd(link)) {
379  if (!lane->getEdge().isInternal()) {
380  if ((*link)->isTLSControlled()) {
381  TraCINextTLSData ntd;
382  ntd.id = (*link)->getTLLogic()->getID();
383  ntd.tlIndex = (*link)->getTLIndex();
384  ntd.dist = seen;
385  ntd.state = (char)(*link)->getState();
386  result.push_back(ntd);
387  }
388  }
389  lane = (*link)->getViaLaneOrLane();
390  if (!lane->getEdge().isInternal()) {
391  view++;
392  }
393  seen += lane->getLength();
394  link = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
395  }
396  }
397  return result;
398 }
399 
400 
401 std::vector<TraCINextStopData>
402 Vehicle::getNextStops(const std::string& vehicleID) {
403  std::vector<TraCINextStopData> result;
404  MSVehicle* veh = getVehicle(vehicleID);
405  std::list<MSVehicle::Stop> stops = veh->getMyStops();
406  for (std::list<MSVehicle::Stop>::iterator it = stops.begin(); it != stops.end(); ++it) {
407  if (!it->reached && !it->collision) {
408  TraCINextStopData nsd;
409  nsd.lane = it->lane->getID();
410  nsd.endPos = it->getEndPos(*veh);
411  // all optionals, only one can be set
412  if (it->busstop != nullptr) {
413  nsd.stoppingPlaceID = it->busstop->getID();
414  }
415  if (it->containerstop != nullptr) {
416  nsd.stoppingPlaceID = it->containerstop->getID();
417  }
418  if (it->parkingarea != nullptr) {
419  nsd.stoppingPlaceID = it->parkingarea->getID();
420  }
421  if (it->chargingStation != nullptr) {
422  nsd.stoppingPlaceID = it->chargingStation->getID();
423  }
424  nsd.stopFlags = (1 +
425  (it->pars.parking ? 2 : 0) +
426  (it->pars.triggered ? 4 : 0) +
427  (it->pars.containerTriggered ? 8 : 0) +
428  (it->busstop != nullptr ? 16 : 0) +
429  (it->containerstop != nullptr ? 32 : 0) +
430  (it->chargingStation != nullptr ? 64 : 0) +
431  (it->parkingarea != nullptr ? 128 : 0));
432  nsd.duration = STEPS2TIME(it->pars.duration);
433  nsd.until = STEPS2TIME(it->pars.until);
434  result.push_back(nsd);
435  }
436  }
437  return result;
438 }
439 
440 
441 int
442 Vehicle::getStopState(const std::string& vehicleID) {
443  MSVehicle* veh = getVehicle(vehicleID);
444  int result = 0;
445  if (veh->isStopped()) {
446  const MSVehicle::Stop& stop = veh->getNextStop();
447  result = (1 + (stop.pars.parking ? 2 : 0) +
448  (stop.pars.triggered ? 4 : 0) +
449  (stop.pars.containerTriggered ? 8 : 0) +
450  (stop.busstop != nullptr ? 16 : 0) +
451  (stop.containerstop != nullptr ? 32 : 0) +
452  (stop.chargingStation != nullptr ? 64 : 0) +
453  (stop.parkingarea != nullptr ? 128 : 0));
454  }
455  return result;
456 }
457 
458 double
459 Vehicle::getDistance(const std::string& vehicleID) {
460  MSVehicle* veh = getVehicle(vehicleID);
461  if (veh->isOnRoad()) {
462  double distance;
463  if (veh->getLane()->isInternal()) {
464  // route edge still points to the edge before the intersection
465  const double normalEnd = (*veh->getCurrentRouteEdge())->getLength();
466  distance = (veh->getRoute().getDistanceBetween(veh->getDepartPos(), normalEnd,
467  veh->getRoute().begin(), veh->getCurrentRouteEdge())
468  + veh->getRoute().getDistanceBetween(normalEnd, veh->getPositionOnLane(),
469  *veh->getCurrentRouteEdge(), &veh->getLane()->getEdge()));
470  } else {
471  distance = veh->getRoute().getDistanceBetween(veh->getDepartPos(), veh->getPositionOnLane(),
472  veh->getRoute().begin(), veh->getCurrentRouteEdge());
473  }
474  if (distance == std::numeric_limits<double>::max()) {
475  return INVALID_DOUBLE_VALUE;
476  } else {
477  return distance;
478  }
479  } else {
480  return INVALID_DOUBLE_VALUE;
481  }
482 }
483 
484 
485 double
486 Vehicle::getDrivingDistance(const std::string& vehicleID, const std::string& edgeID, double position, int /* laneIndex */) {
487  MSVehicle* veh = getVehicle(vehicleID);
488  if (veh->isOnRoad()) {
489  double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), position,
490  &veh->getLane()->getEdge(), Helper::getEdge(edgeID), true, veh->getRoutePosition());
491  if (distance == std::numeric_limits<double>::max()) {
492  return INVALID_DOUBLE_VALUE;
493  }
494  return distance;
495  } else {
496  return INVALID_DOUBLE_VALUE;
497  }
498 }
499 
500 
501 double
502 Vehicle::getDrivingDistance2D(const std::string& vehicleID, double x, double y) {
503  MSVehicle* veh = getVehicle(vehicleID);
504  if (veh->isOnRoad()) {
505  std::pair<MSLane*, double> roadPos = Helper::convertCartesianToRoadMap(Position(x, y));
506  double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), roadPos.second,
507  veh->getEdge(), &roadPos.first->getEdge(), true, veh->getRoutePosition());
508  if (distance == std::numeric_limits<double>::max()) {
509  return INVALID_DOUBLE_VALUE;
510  }
511  return distance;
512  } else {
513  return INVALID_DOUBLE_VALUE;
514  }
515 }
516 
517 
518 
519 double
520 Vehicle::getAllowedSpeed(const std::string& vehicleID) {
521  MSVehicle* veh = getVehicle(vehicleID);
522  if (veh->isOnRoad()) {
523  return veh->getLane()->getVehicleMaxSpeed(veh);
524  } else {
525  return INVALID_DOUBLE_VALUE;
526  }
527 }
528 
529 
530 double
531 Vehicle::getSpeedFactor(const std::string& vehicleID) {
532  return getVehicle(vehicleID)->getChosenSpeedFactor();
533 }
534 
535 
536 int
537 Vehicle::getSpeedMode(const std::string& vehicleID) {
538  return getVehicle(vehicleID)->getInfluencer().getSpeedMode();
539 }
540 
541 int
542 Vehicle::getLaneChangeMode(const std::string& vehicleID) {
543  return getVehicle(vehicleID)->getInfluencer().getLaneChangeMode();
544 }
545 
546 int
547 Vehicle::getRoutingMode(const std::string& vehicleID) {
548  return getVehicle(vehicleID)->getInfluencer().getRoutingMode();
549 }
550 
551 std::string
552 Vehicle::getLine(const std::string& vehicleID) {
553  return getVehicle(vehicleID)->getParameter().line;
554 }
555 
556 std::vector<std::string>
557 Vehicle::getVia(const std::string& vehicleID) {
558  return getVehicle(vehicleID)->getParameter().via;
559 }
560 
561 
562 std::pair<int, int>
563 Vehicle::getLaneChangeState(const std::string& vehicleID, int direction) {
564  MSVehicle* veh = getVehicle(vehicleID);
565  if (veh->isOnRoad() && veh->getLaneChangeModel().hasSavedState(direction)) {
566  return veh->getLaneChangeModel().getSavedState(direction);
567  } else {
568  return std::make_pair((int)LCA_UNKNOWN, (int)LCA_UNKNOWN);
569  }
570 }
571 
572 
573 std::string
574 Vehicle::getParameter(const std::string& vehicleID, const std::string& key) {
575  MSVehicle* veh = getVehicle(vehicleID);
576  if (StringUtils::startsWith(key, "device.")) {
577  StringTokenizer tok(key, ".");
578  if (tok.size() < 3) {
579  throw TraCIException("Invalid device parameter '" + key + "' for vehicle '" + vehicleID + "'");
580  }
581  try {
582  return veh->getDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2));
583  } catch (InvalidArgument& e) {
584  throw TraCIException("Vehicle '" + vehicleID + "' does not support device parameter '" + key + "' (" + e.what() + ").");
585  }
586  } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
587  const std::string attrName = key.substr(16);
588  try {
589  return veh->getLaneChangeModel().getParameter(attrName);
590  } catch (InvalidArgument& e) {
591  throw TraCIException("Vehicle '" + vehicleID + "' does not support laneChangeModel parameter '" + key + "' (" + e.what() + ").");
592  }
593  } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
594  StringTokenizer tok(key, ".");
595  if (tok.size() != 3) {
596  throw TraCIException("Invalid check for device. Expected format is 'has.DEVICENAME.device'");
597  }
598  return veh->hasDevice(tok.get(1)) ? "true" : "false";
599  } else {
600  return veh->getParameter().getParameter(key, "");
601  }
602 }
603 
604 
605 const MSVehicleType&
606 Vehicle::getVehicleType(const std::string& vehicleID) {
607  return getVehicle(vehicleID)->getVehicleType();
608 }
609 
610 
611 std::string
612 Vehicle::getEmissionClass(const std::string& vehicleID) {
613  return PollutantsInterface::getName(getVehicleType(vehicleID).getEmissionClass());
614 }
615 
616 std::string
617 Vehicle::getShapeClass(const std::string& vehicleID) {
618  return getVehicleShapeName(getVehicleType(vehicleID).getGuiShape());
619 }
620 
621 
622 double
623 Vehicle::getLength(const std::string& vehicleID) {
624  return getVehicleType(vehicleID).getLength();
625 }
626 
627 
628 double
629 Vehicle::getAccel(const std::string& vehicleID) {
630  return getVehicleType(vehicleID).getCarFollowModel().getMaxAccel();
631 }
632 
633 
634 double
635 Vehicle::getDecel(const std::string& vehicleID) {
636  return getVehicleType(vehicleID).getCarFollowModel().getMaxDecel();
637 }
638 
639 
640 double Vehicle::getEmergencyDecel(const std::string& vehicleID) {
641  return getVehicleType(vehicleID).getCarFollowModel().getEmergencyDecel();
642 }
643 
644 
645 double Vehicle::getApparentDecel(const std::string& vehicleID) {
646  return getVehicleType(vehicleID).getCarFollowModel().getApparentDecel();
647 }
648 
649 
650 double Vehicle::getActionStepLength(const std::string& vehicleID) {
651  return getVehicleType(vehicleID).getActionStepLengthSecs();
652 }
653 
654 
655 double Vehicle::getLastActionTime(const std::string& vehicleID) {
656  return STEPS2TIME(getVehicle(vehicleID)->getLastActionTime());
657 }
658 
659 
660 double
661 Vehicle::getTau(const std::string& vehicleID) {
662  return getVehicleType(vehicleID).getCarFollowModel().getHeadwayTime();
663 }
664 
665 
666 double
667 Vehicle::getImperfection(const std::string& vehicleID) {
668  return getVehicleType(vehicleID).getCarFollowModel().getImperfection();
669 }
670 
671 
672 double
673 Vehicle::getSpeedDeviation(const std::string& vehicleID) {
674  return getVehicleType(vehicleID).getSpeedFactor().getParameter()[1];
675 }
676 
677 
678 std::string
679 Vehicle::getVehicleClass(const std::string& vehicleID) {
680  return toString(getVehicleType(vehicleID).getVehicleClass());
681 }
682 
683 
684 double
685 Vehicle::getMinGap(const std::string& vehicleID) {
686  return getVehicleType(vehicleID).getMinGap();
687 }
688 
689 
690 double
691 Vehicle::getMinGapLat(const std::string& vehicleID) {
692  return getVehicleType(vehicleID).getMinGapLat();
693 }
694 
695 
696 double
697 Vehicle::getMaxSpeed(const std::string& vehicleID) {
698  return getVehicleType(vehicleID).getMaxSpeed();
699 }
700 
701 
702 double
703 Vehicle::getMaxSpeedLat(const std::string& vehicleID) {
704  return getVehicleType(vehicleID).getMaxSpeedLat();
705 }
706 
707 
708 std::string
709 Vehicle::getLateralAlignment(const std::string& vehicleID) {
710  return toString(getVehicleType(vehicleID).getPreferredLateralAlignment());
711 }
712 
713 
714 double
715 Vehicle::getWidth(const std::string& vehicleID) {
716  return getVehicleType(vehicleID).getWidth();
717 }
718 
719 
720 double
721 Vehicle::getHeight(const std::string& vehicleID) {
722  return getVehicleType(vehicleID).getHeight();
723 }
724 
725 
726 void
727 Vehicle::setStop(const std::string& vehicleID,
728  const std::string& edgeID,
729  double pos,
730  int laneIndex,
731  double duration,
732  int flags,
733  double startPos,
734  double until) {
735  MSVehicle* veh = getVehicle(vehicleID);
736  // optional stop flags
737  bool parking = false;
738  bool triggered = false;
739  bool containerTriggered = false;
740  SumoXMLTag stoppingPlaceType = SUMO_TAG_NOTHING;
741 
742  parking = ((flags & 1) != 0);
743  triggered = ((flags & 2) != 0);
744  containerTriggered = ((flags & 4) != 0);
745  if ((flags & 8) != 0) {
746  stoppingPlaceType = SUMO_TAG_BUS_STOP;
747  }
748  if ((flags & 16) != 0) {
749  stoppingPlaceType = SUMO_TAG_CONTAINER_STOP;
750  }
751  if ((flags & 32) != 0) {
752  stoppingPlaceType = SUMO_TAG_CHARGING_STATION;
753  }
754  if ((flags & 64) != 0) {
755  stoppingPlaceType = SUMO_TAG_PARKING_AREA;
756  }
757  const SUMOTime durationSteps = duration == INVALID_DOUBLE_VALUE ? SUMOTime_MAX : TIME2STEPS(duration);
758  const SUMOTime untilStep = until == INVALID_DOUBLE_VALUE ? -1 : TIME2STEPS(until);
759 
760  std::string error;
761  if (stoppingPlaceType != SUMO_TAG_NOTHING) {
762  // Forward command to vehicle
763  if (!veh->addTraciStopAtStoppingPlace(edgeID, durationSteps, untilStep, parking, triggered, containerTriggered, stoppingPlaceType, error)) {
764  throw TraCIException(error);
765  }
766  } else {
767  // check
768  if (startPos == INVALID_DOUBLE_VALUE) {
769  startPos = pos - POSITION_EPS;
770  }
771  if (startPos < 0.) {
772  throw TraCIException("Position on lane must not be negative.");
773  }
774  if (pos < startPos) {
775  throw TraCIException("End position on lane must be after start position.");
776  }
777  // get the actual lane that is referenced by laneIndex
778  MSEdge* road = MSEdge::dictionary(edgeID);
779  if (road == nullptr) {
780  throw TraCIException("Unable to retrieve road with given id.");
781  }
782  const std::vector<MSLane*>& allLanes = road->getLanes();
783  if ((laneIndex < 0) || laneIndex >= (int)(allLanes.size())) {
784  throw TraCIException("No lane with index '" + toString(laneIndex) + "' on road '" + edgeID + "'.");
785  }
786  // Forward command to vehicle
787  if (!veh->addTraciStop(allLanes[laneIndex], startPos, pos, durationSteps, untilStep, parking, triggered, containerTriggered, error)) {
788  throw TraCIException(error);
789  }
790  }
791 }
792 
793 void
794 Vehicle::rerouteParkingArea(const std::string& vehicleID, const std::string& parkingAreaID) {
795  MSVehicle* veh = getVehicle(vehicleID);
796  std::string error;
797  // Forward command to vehicle
798  if (!veh->rerouteParkingArea(parkingAreaID, error)) {
799  throw TraCIException(error);
800  }
801 }
802 
803 void
804 Vehicle::resume(const std::string& vehicleID) {
805  MSVehicle* veh = getVehicle(vehicleID);
806  if (!veh->hasStops()) {
807  throw TraCIException("Failed to resume vehicle '" + veh->getID() + "', it has no stops.");
808  }
809  if (!veh->resumeFromStopping()) {
810  MSVehicle::Stop& sto = veh->getNextStop();
811  std::ostringstream strs;
812  strs << "reached: " << sto.reached;
813  strs << ", duration:" << sto.duration;
814  strs << ", edge:" << (*sto.edge)->getID();
815  strs << ", startPos: " << sto.pars.startPos;
816  std::string posStr = strs.str();
817  throw TraCIException("Failed to resume from stoppingfor vehicle '" + veh->getID() + "', " + posStr);
818  }
819 }
820 
821 
822 void
823 Vehicle::changeTarget(const std::string& vehicleID, const std::string& edgeID) {
824  MSVehicle* veh = getVehicle(vehicleID);
825  const MSEdge* destEdge = MSEdge::dictionary(edgeID);
826  const bool onInit = isOnInit(vehicleID);
827  if (destEdge == nullptr) {
828  throw TraCIException("Can not retrieve road with ID " + edgeID);
829  }
830  // build a new route between the vehicle's current edge and destination edge
831  ConstMSEdgeVector newRoute;
832  const MSEdge* currentEdge = veh->getRerouteOrigin();
834  currentEdge, destEdge, (const MSVehicle * const)veh, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
835  // replace the vehicle's route by the new one (cost is updated by call to reroute())
836  if (!veh->replaceRouteEdges(newRoute, -1, 0, "traci:changeTarget", onInit)) {
837  throw TraCIException("Route replacement failed for " + veh->getID());
838  }
839  // route again to ensure usage of via/stops
840  try {
841  veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:changeTarget", veh->getInfluencer().getRouterTT(), onInit);
842  } catch (ProcessError& e) {
843  throw TraCIException(e.what());
844  }
845 }
846 
847 
848 void
849 Vehicle::changeLane(const std::string& vehicleID, int laneIndex, double duration) {
850  std::vector<std::pair<SUMOTime, int> > laneTimeLine;
851  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
852  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), laneIndex));
853  getVehicle(vehicleID)->getInfluencer().setLaneTimeLine(laneTimeLine);
854 }
855 
856 void
857 Vehicle::changeLaneRelative(const std::string& vehicleID, int laneChange, double duration) {
858  std::vector<std::pair<SUMOTime, int> > laneTimeLine;
859  int laneIndex;
860  // Check in which direction the lane change should be performed 0: for right, >0 to left
861  if (laneChange > 0) {
862  laneIndex = getVehicle(vehicleID)->getLaneIndex() + laneChange;
863  } else {
864  laneIndex = getVehicle(vehicleID)->getLaneIndex() - 1;
865  }
866  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
867  laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), laneIndex));
868  getVehicle(vehicleID)->getInfluencer().setLaneTimeLine(laneTimeLine);
869 }
870 
871 
872 void
873 Vehicle::changeSublane(const std::string& vehicleID, double latDist) {
874  getVehicle(vehicleID)->getInfluencer().setSublaneChange(latDist);
875 }
876 
877 
878 void
879 Vehicle::add(const std::string& vehicleID,
880  const std::string& routeID,
881  const std::string& typeID,
882  const std::string& depart,
883  const std::string& departLane,
884  const std::string& departPos,
885  const std::string& departSpeed,
886  const std::string& arrivalLane,
887  const std::string& arrivalPos,
888  const std::string& arrivalSpeed,
889  const std::string& fromTaz,
890  const std::string& toTaz,
891  const std::string& line,
892  int /*personCapacity*/,
893  int personNumber) {
895  if (veh != nullptr) {
896  throw TraCIException("The vehicle " + vehicleID + " to add already exists.");
897  }
898 
899  SUMOVehicleParameter vehicleParams;
900  vehicleParams.id = vehicleID;
901  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
902  if (!vehicleType) {
903  throw TraCIException("Invalid type '" + typeID + "' for vehicle '" + vehicleID + "'");
904  }
905  const MSRoute* route = MSRoute::dictionary(routeID);
906  if (!route) {
907  if (routeID == "") {
908  // assume, route was intentionally left blank because the caller
909  // intends to control the vehicle remotely
910  SUMOVehicleClass vclass = vehicleType->getVehicleClass();
911  const std::string dummyRouteID = "DUMMY_ROUTE_" + SumoVehicleClassStrings.getString(vclass);
912  route = MSRoute::dictionary(dummyRouteID);
913  if (route == nullptr) {
914  for (MSEdge* e : MSEdge::getAllEdges()) {
915  if (e->getFunction() == EDGEFUNC_NORMAL && (e->getPermissions() & vclass) == vclass) {
916  std::vector<std::string> edges;
917  edges.push_back(e->getID());
918  libsumo::Route::add(dummyRouteID, edges);
919  break;
920  }
921  }
922  }
923  route = MSRoute::dictionary(dummyRouteID);
924  if (!route) {
925  throw TraCIException("Could not build dummy route for vehicle class: '" + SumoVehicleClassStrings.getString(vehicleType->getVehicleClass()) + "'");
926  }
927  } else {
928  throw TraCIException("Invalid route '" + routeID + "' for vehicle: '" + vehicleID + "'");
929  }
930  }
931  // check if the route implies a trip
932  if (route->getEdges().size() == 2) {
933  const MSEdgeVector& succ = route->getEdges().front()->getSuccessors();
934  if (std::find(succ.begin(), succ.end(), route->getEdges().back()) == succ.end()) {
935  vehicleParams.parametersSet |= VEHPARS_FORCE_REROUTE;
936  }
937  }
938  if (fromTaz != "" || toTaz != "") {
939  vehicleParams.parametersSet |= VEHPARS_FORCE_REROUTE;
940  }
941  std::string error;
942  if (!SUMOVehicleParameter::parseDepart(depart, "vehicle", vehicleID, vehicleParams.depart, vehicleParams.departProcedure, error)) {
943  throw TraCIException(error);
944  }
945  if (vehicleParams.departProcedure == DEPART_GIVEN && vehicleParams.depart < MSNet::getInstance()->getCurrentTimeStep()) {
946  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
947  WRITE_WARNING("Departure time for vehicle '" + vehicleID + "' is in the past; using current time instead.");
948  } else if (vehicleParams.departProcedure == DEPART_NOW) {
949  vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
950  }
951  if (!SUMOVehicleParameter::parseDepartLane(departLane, "vehicle", vehicleID, vehicleParams.departLane, vehicleParams.departLaneProcedure, error)) {
952  throw TraCIException(error);
953  }
954  if (!SUMOVehicleParameter::parseDepartPos(departPos, "vehicle", vehicleID, vehicleParams.departPos, vehicleParams.departPosProcedure, error)) {
955  throw TraCIException(error);
956  }
957  if (!SUMOVehicleParameter::parseDepartSpeed(departSpeed, "vehicle", vehicleID, vehicleParams.departSpeed, vehicleParams.departSpeedProcedure, error)) {
958  throw TraCIException(error);
959  }
960  if (!SUMOVehicleParameter::parseArrivalLane(arrivalLane, "vehicle", vehicleID, vehicleParams.arrivalLane, vehicleParams.arrivalLaneProcedure, error)) {
961  throw TraCIException(error);
962  }
963  if (!SUMOVehicleParameter::parseArrivalPos(arrivalPos, "vehicle", vehicleID, vehicleParams.arrivalPos, vehicleParams.arrivalPosProcedure, error)) {
964  throw TraCIException(error);
965  }
966  if (!SUMOVehicleParameter::parseArrivalSpeed(arrivalSpeed, "vehicle", vehicleID, vehicleParams.arrivalSpeed, vehicleParams.arrivalSpeedProcedure, error)) {
967  throw TraCIException(error);
968  }
969  vehicleParams.fromTaz = fromTaz;
970  vehicleParams.toTaz = toTaz;
971  vehicleParams.line = line;
972  //vehicleParams.personCapacity = personCapacity;
973  vehicleParams.personNumber = personNumber;
974 
975  SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
976  try {
977  SUMOVehicle* vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(params, route, vehicleType, true, false);
978  MSNet::getInstance()->getVehicleControl().addVehicle(vehicleParams.id, vehicle);
980  } catch (ProcessError& e) {
981  throw TraCIException(e.what());
982  }
983 }
984 
985 
986 void
987 Vehicle::moveToXY(const std::string& vehicleID, const std::string& edgeID, const int laneIndex, const double x, const double y, double angle, const int keepRoute) {
988  MSVehicle* veh = getVehicle(vehicleID);
989  const bool doKeepRoute = (keepRoute == 1) && veh->getID() != "VTD_EGO";
990  const bool mayLeaveNetwork = (keepRoute == 2);
991  // process
992  const std::string origID = edgeID + "_" + toString(laneIndex);
993  // @todo add an interpretation layer for OSM derived origID values (without lane index)
994  Position pos(x, y);
995 #ifdef DEBUG_MOVEXY
996  const double origAngle = angle;
997 #endif
998  // angle must be in [0,360] because it will be compared against those returned by naviDegree()
999  // angle set to INVALID_DOUBLE_VALUE is ignored in the evaluated and later set to the angle of the matched lane
1000  if (angle != INVALID_DOUBLE_VALUE) {
1001  while (angle >= 360.) {
1002  angle -= 360.;
1003  }
1004  while (angle < 0.) {
1005  angle += 360.;
1006  }
1007  }
1008 
1009  Position vehPos = veh->getPosition();
1010 #ifdef DEBUG_MOVEXY
1011  std::cout << std::endl << "begin vehicle " << veh->getID() << " vehPos:" << vehPos << " lane:" << Named::getIDSecure(veh->getLane()) << std::endl;
1012  std::cout << " want pos:" << pos << " origID:" << origID << " laneIndex:" << laneIndex << " origAngle:" << origAngle << " angle:" << angle << " keepRoute:" << keepRoute << std::endl;
1013 #endif
1014 
1015  ConstMSEdgeVector edges;
1016  MSLane* lane = nullptr;
1017  double lanePos;
1018  double lanePosLat = 0;
1019  double bestDistance = std::numeric_limits<double>::max();
1020  int routeOffset = 0;
1021  bool found;
1022  double maxRouteDistance = 100;
1023  /* EGO vehicle is known to have a fixed route. @todo make this into a parameter of the TraCI call */
1024  if (doKeepRoute) {
1025  // case a): vehicle is on its earlier route
1026  // we additionally assume it is moving forward (SUMO-limit);
1027  // note that the route ("edges") is not changed in this case
1028 
1029  found = Helper::moveToXYMap_matchingRoutePosition(pos, origID,
1030  veh->getRoute().getEdges(), (int)(veh->getCurrentRouteEdge() - veh->getRoute().begin()),
1031  bestDistance, &lane, lanePos, routeOffset);
1032  // @note silenty ignoring mapping failure
1033  } else {
1034  double speed = pos.distanceTo2D(veh->getPosition()); // !!!veh->getSpeed();
1035  found = Helper::moveToXYMap(pos, maxRouteDistance, mayLeaveNetwork, origID, angle,
1036  speed, veh->getRoute().getEdges(), veh->getRoutePosition(), veh->getLane(), veh->getPositionOnLane(), veh->isOnRoad(),
1037  bestDistance, &lane, lanePos, routeOffset, edges);
1038  }
1039  if ((found && bestDistance <= maxRouteDistance) || mayLeaveNetwork) {
1040  // optionally compute lateral offset
1041  if (found && (MSGlobals::gLateralResolution > 0 || mayLeaveNetwork)) {
1042  const double perpDist = lane->getShape().distance2D(pos, false);
1043  if (perpDist != GeomHelper::INVALID_OFFSET) {
1044  lanePosLat = perpDist;
1045  if (!mayLeaveNetwork) {
1046  lanePosLat = MIN2(lanePosLat, 0.5 * (lane->getWidth() + veh->getVehicleType().getWidth() - MSGlobals::gLateralResolution));
1047  }
1048  // figure out whether the offset is to the left or to the right
1049  PositionVector tmp = lane->getShape();
1050  try {
1051  tmp.move2side(-lanePosLat); // moved to left
1052  } catch (ProcessError&) {
1053  WRITE_WARNING("Could not determine position on lane '" + lane->getID() + " at lateral position " + toString(-lanePosLat) + ".");
1054  }
1055  //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
1056  if (tmp.distance2D(pos) > perpDist) {
1057  lanePosLat = -lanePosLat;
1058  }
1059  }
1060  }
1061  if (found && !mayLeaveNetwork && MSGlobals::gLateralResolution < 0) {
1062  // mapped position may differ from pos
1063  pos = lane->geometryPositionAtOffset(lanePos, -lanePosLat);
1064  }
1065  assert((found && lane != 0) || (!found && lane == 0));
1066  if (angle == INVALID_DOUBLE_VALUE) {
1067  if (lane != nullptr) {
1068  angle = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(lanePos));
1069  } else {
1070  // compute angle outside road network from old and new position
1071  angle = GeomHelper::naviDegree(veh->getPosition().angleTo2D(pos));
1072  }
1073  }
1074  // use the best we have
1075  Helper::setRemoteControlled(veh, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
1076  if (!veh->isOnRoad()) {
1078  }
1079  } else {
1080  if (lane == nullptr) {
1081  throw TraCIException("Could not map vehicle '" + vehicleID + "' no road found within " + toString(maxRouteDistance) + "m.");
1082  } else {
1083  throw TraCIException("Could not map vehicle '" + vehicleID + "' distance to road is " + toString(bestDistance) + ".");
1084  }
1085  }
1086 }
1087 
1088 void
1089 Vehicle::slowDown(const std::string& vehicleID, double speed, double duration) {
1090  MSVehicle* veh = getVehicle(vehicleID);
1091  std::vector<std::pair<SUMOTime, double> > speedTimeLine;
1092  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), veh->getSpeed()));
1093  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), speed));
1094  veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
1095 }
1096 
1097 void
1098 Vehicle::openGap(const std::string& vehicleID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel) {
1099  MSVehicle* veh = getVehicle(vehicleID);
1100  const double originalTau = veh->getVehicleType().getCarFollowModel().getHeadwayTime();
1101  if (newTimeHeadway == -1) {
1102  newTimeHeadway = originalTau;
1103  }
1104  if (originalTau > newTimeHeadway) {
1105  WRITE_WARNING("Ignoring openGap(). New time headway must not be smaller than the original.");
1106  return;
1107  }
1108  veh->getInfluencer().activateGapController(originalTau, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel);
1109 }
1110 
1111 void
1112 Vehicle::deactivateGapControl(const std::string& vehicleID) {
1113  MSVehicle* veh = getVehicle(vehicleID);
1114  if (veh->hasInfluencer()) {
1116  }
1117 }
1118 
1119 void
1120 Vehicle::setSpeed(const std::string& vehicleID, double speed) {
1121  MSVehicle* veh = getVehicle(vehicleID);
1122  std::vector<std::pair<SUMOTime, double> > speedTimeLine;
1123  if (speed >= 0) {
1124  speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), speed));
1125  speedTimeLine.push_back(std::make_pair(SUMOTime_MAX - DELTA_T, speed));
1126  }
1127  veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
1128 }
1129 
1130 void
1131 Vehicle::setSpeedMode(const std::string& vehicleID, int speedMode) {
1132  getVehicle(vehicleID)->getInfluencer().setSpeedMode(speedMode);
1133 }
1134 
1135 void
1136 Vehicle::setLaneChangeMode(const std::string& vehicleID, int laneChangeMode) {
1137  getVehicle(vehicleID)->getInfluencer().setLaneChangeMode(laneChangeMode);
1138 }
1139 
1140 void
1141 Vehicle::setRoutingMode(const std::string& vehicleID, int routingMode) {
1142  getVehicle(vehicleID)->getInfluencer().setRoutingMode(routingMode);
1143 }
1144 
1145 void
1146 Vehicle::setType(const std::string& vehicleID, const std::string& typeID) {
1147  MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
1148  if (vehicleType == nullptr) {
1149  throw TraCIException("Vehicle type '" + typeID + "' is not known");
1150  }
1151  getVehicle(vehicleID)->replaceVehicleType(vehicleType);
1152 }
1153 
1154 void
1155 Vehicle::setRouteID(const std::string& vehicleID, const std::string& routeID) {
1156  MSVehicle* veh = getVehicle(vehicleID);
1157  const MSRoute* r = MSRoute::dictionary(routeID);
1158  if (r == nullptr) {
1159  throw TraCIException("The route '" + routeID + "' is not known.");
1160  }
1161  std::string msg;
1162  if (!veh->hasValidRoute(msg, r)) {
1163  WRITE_WARNING("Invalid route replacement for vehicle '" + veh->getID() + "'. " + msg);
1165  throw TraCIException("Route replacement failed for " + veh->getID());
1166  }
1167  }
1168 
1169  if (!veh->replaceRoute(r, "traci:setRouteID", veh->getLane() == nullptr)) {
1170  throw TraCIException("Route replacement failed for " + veh->getID());
1171  }
1172 }
1173 
1174 void
1175 Vehicle::setRoute(const std::string& vehicleID, const std::vector<std::string>& edgeIDs) {
1176  MSVehicle* veh = getVehicle(vehicleID);
1177  ConstMSEdgeVector edges;
1178  try {
1179  MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
1180  } catch (ProcessError& e) {
1181  throw TraCIException("Invalid edge list for vehicle '" + veh->getID() + "' (" + e.what() + ")");
1182  }
1183  if (!veh->replaceRouteEdges(edges, -1, 0, "traci:setRoute", veh->getLane() == nullptr, true)) {
1184  throw TraCIException("Route replacement failed for " + veh->getID());
1185  }
1186 }
1187 
1188 void
1189 Vehicle::updateBestLanes(const std::string& vehicleID) {
1190  MSVehicle* veh = getVehicle(vehicleID);
1191  veh->updateBestLanes(true);
1192 }
1193 
1194 
1195 void
1196 Vehicle::setAdaptedTraveltime(const std::string& vehicleID, const std::string& edgeID,
1197  double time, double begSeconds, double endSeconds) {
1198  MSVehicle* veh = getVehicle(vehicleID);
1199  MSEdge* edge = MSEdge::dictionary(edgeID);
1200  if (edge == nullptr) {
1201  throw TraCIException("Referended edge '" + edgeID + "' is not known.");
1202  }
1203  if (time != INVALID_DOUBLE_VALUE) {
1204  // add time
1205  if (begSeconds == 0 && endSeconds == std::numeric_limits<double>::max()) {
1206  // clean up old values before setting whole range
1207  while (veh->getWeightsStorage().knowsTravelTime(edge)) {
1208  veh->getWeightsStorage().removeTravelTime(edge);
1209  }
1210  }
1211  veh->getWeightsStorage().addTravelTime(edge, begSeconds, endSeconds, time);
1212  } else {
1213  // remove time
1214  while (veh->getWeightsStorage().knowsTravelTime(edge)) {
1215  veh->getWeightsStorage().removeTravelTime(edge);
1216  }
1217  }
1218 }
1219 
1220 
1221 void
1222 Vehicle::setEffort(const std::string& vehicleID, const std::string& edgeID,
1223  double effort, double begSeconds, double endSeconds) {
1224  MSVehicle* veh = getVehicle(vehicleID);
1225  MSEdge* edge = MSEdge::dictionary(edgeID);
1226  if (edge == nullptr) {
1227  throw TraCIException("Referended edge '" + edgeID + "' is not known.");
1228  }
1229  if (effort != INVALID_DOUBLE_VALUE) {
1230  // add effort
1231  if (begSeconds == 0 && endSeconds == std::numeric_limits<double>::max()) {
1232  // clean up old values before setting whole range
1233  while (veh->getWeightsStorage().knowsEffort(edge)) {
1234  veh->getWeightsStorage().removeEffort(edge);
1235  }
1236  }
1237  veh->getWeightsStorage().addEffort(edge, begSeconds, endSeconds, effort);
1238  } else {
1239  // remove effort
1240  while (veh->getWeightsStorage().knowsEffort(edge)) {
1241  veh->getWeightsStorage().removeEffort(edge);
1242  }
1243  }
1244 }
1245 
1246 
1247 void
1248 Vehicle::rerouteTraveltime(const std::string& vehicleID) {
1249  MSVehicle* veh = getVehicle(vehicleID);
1250  veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:rerouteTraveltime",
1251  veh->getInfluencer().getRouterTT(), isOnInit(vehicleID));
1252 }
1253 
1254 
1255 void
1256 Vehicle::rerouteEffort(const std::string& vehicleID) {
1257  MSVehicle* veh = getVehicle(vehicleID);
1258  veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:rerouteEffort", MSNet::getInstance()->getRouterEffort(), isOnInit(vehicleID));
1259 }
1260 
1261 
1262 void
1263 Vehicle::setSignals(const std::string& vehicleID, int signals) {
1264  MSVehicle* veh = getVehicle(vehicleID);
1265  // set influencer to make the change persistent
1266  veh->getInfluencer().setSignals(signals);
1267  // set them now so that getSignals returns the correct value
1268  veh->switchOffSignal(0x0fffffff);
1269  if (signals >= 0) {
1270  veh->switchOnSignal(signals);
1271  }
1272 }
1273 
1274 
1275 void
1276 Vehicle::moveTo(const std::string& vehicleID, const std::string& laneID, double position) {
1277  MSVehicle* veh = getVehicle(vehicleID);
1278  MSLane* l = MSLane::dictionary(laneID);
1279  if (l == nullptr) {
1280  throw TraCIException("Unknown lane '" + laneID + "'.");
1281  }
1282  MSEdge& destinationEdge = l->getEdge();
1283  if (!veh->willPass(&destinationEdge)) {
1284  throw TraCIException("Vehicle '" + laneID + "' may be set onto an edge to pass only.");
1285  }
1287  if (veh->getLane() != nullptr) {
1289  } else {
1290  veh->setTentativeLaneAndPosition(l, position);
1291  }
1292  while (veh->getEdge() != &destinationEdge) {
1293  const MSEdge* nextEdge = veh->succEdge(1);
1294  // let the vehicle move to the next edge
1295  if (veh->enterLaneAtMove(nextEdge->getLanes()[0], true)) {
1297  continue;
1298  }
1299  }
1300  if (!veh->isOnRoad()) {
1302 
1303  }
1304  l->forceVehicleInsertion(veh, position,
1306 }
1307 
1308 
1309 void
1310 Vehicle::setActionStepLength(const std::string& vehicleID, double actionStepLength, bool resetActionOffset) {
1311  if (actionStepLength < 0.0) {
1312  WRITE_ERROR("Invalid action step length (<0). Ignoring command setActionStepLength().");
1313  return;
1314  }
1315  MSVehicle* veh = getVehicle(vehicleID);
1316  if (actionStepLength == 0.) {
1317  veh->resetActionOffset();
1318  return;
1319  }
1320  SUMOTime actionStepLengthMillisecs = SUMOVehicleParserHelper::processActionStepLength(actionStepLength);
1321  SUMOTime previousActionStepLength = veh->getActionStepLength();
1322  veh->getSingularType().setActionStepLength(actionStepLengthMillisecs, resetActionOffset);
1323  if (resetActionOffset) {
1324  veh->resetActionOffset();
1325  } else {
1326  veh->updateActionOffset(previousActionStepLength, actionStepLengthMillisecs);
1327  }
1328 }
1329 
1330 
1331 void
1332 Vehicle::remove(const std::string& vehicleID, char reason) {
1333  MSVehicle* veh = getVehicle(vehicleID);
1335  switch (reason) {
1336  case REMOVE_TELEPORT:
1337  // XXX semantics unclear
1338  // n = MSMoveReminder::NOTIFICATION_TELEPORT;
1340  break;
1341  case REMOVE_PARKING:
1342  // XXX semantics unclear
1343  // n = MSMoveReminder::NOTIFICATION_PARKING;
1345  break;
1346  case REMOVE_ARRIVED:
1348  break;
1349  case REMOVE_VAPORIZED:
1351  break;
1354  break;
1355  default:
1356  throw TraCIException("Unknown removal status.");
1357  }
1358  if (veh->hasDeparted()) {
1359  veh->onRemovalFromNet(n);
1360  if (veh->getLane() != nullptr) {
1361  veh->getLane()->removeVehicle(veh, n);
1362  }
1364  } else {
1367  }
1368 }
1369 
1370 
1371 void
1372 Vehicle::setColor(const std::string& vehicleID, const TraCIColor& col) {
1373  const SUMOVehicleParameter& p = getVehicle(vehicleID)->getParameter();
1374  p.color.set(col.r, col.g, col.b, col.a);
1376 }
1377 
1378 
1379 void
1380 Vehicle::setSpeedFactor(const std::string& vehicleID, double factor) {
1381  getVehicle(vehicleID)->setChosenSpeedFactor(factor);
1382 }
1383 
1384 
1385 void
1386 Vehicle::setLine(const std::string& vehicleID, const std::string& line) {
1387  getVehicle(vehicleID)->getParameter().line = line;
1388 }
1389 
1390 
1391 void
1392 Vehicle::setVia(const std::string& vehicleID, const std::vector<std::string>& via) {
1393  MSVehicle* veh = getVehicle(vehicleID);
1394  try {
1395  // ensure edges exist
1396  ConstMSEdgeVector edges;
1397  MSEdge::parseEdgesList(via, edges, "<via-edges>");
1398  } catch (ProcessError& e) {
1399  throw TraCIException(e.what());
1400  }
1401  veh->getParameter().via = via;
1402 }
1403 
1404 
1405 void
1406 Vehicle::setLength(const std::string& vehicleID, double length) {
1407  getVehicle(vehicleID)->getSingularType().setLength(length);
1408 }
1409 
1410 
1411 void
1412 Vehicle::setMaxSpeed(const std::string& vehicleID, double speed) {
1413  getVehicle(vehicleID)->getSingularType().setMaxSpeed(speed);
1414 }
1415 
1416 
1417 void
1418 Vehicle::setVehicleClass(const std::string& vehicleID, const std::string& clazz) {
1419  getVehicle(vehicleID)->getSingularType().setVClass(getVehicleClassID(clazz));
1420 }
1421 
1422 
1423 void
1424 Vehicle::setShapeClass(const std::string& vehicleID, const std::string& clazz) {
1425  getVehicle(vehicleID)->getSingularType().setShape(getVehicleShapeID(clazz));
1426 }
1427 
1428 
1429 void
1430 Vehicle::setEmissionClass(const std::string& vehicleID, const std::string& clazz) {
1432 }
1433 
1434 
1435 void
1436 Vehicle::setWidth(const std::string& vehicleID, double width) {
1437  getVehicle(vehicleID)->getSingularType().setWidth(width);
1438 }
1439 
1440 
1441 void
1442 Vehicle::setHeight(const std::string& vehicleID, double height) {
1443  getVehicle(vehicleID)->getSingularType().setHeight(height);
1444 }
1445 
1446 
1447 void
1448 Vehicle::setMinGap(const std::string& vehicleID, double minGap) {
1449  getVehicle(vehicleID)->getSingularType().setMinGap(minGap);
1450 }
1451 
1452 
1453 void
1454 Vehicle::setAccel(const std::string& vehicleID, double accel) {
1455  getVehicle(vehicleID)->getSingularType().setAccel(accel);
1456 }
1457 
1458 
1459 void
1460 Vehicle::setDecel(const std::string& vehicleID, double decel) {
1461  VehicleType::setDecel(getVehicle(vehicleID)->getSingularType().getID(), decel);
1462 }
1463 
1464 
1465 void
1466 Vehicle::setEmergencyDecel(const std::string& vehicleID, double decel) {
1467  VehicleType::setEmergencyDecel(getVehicle(vehicleID)->getSingularType().getID(), decel);
1468 }
1469 
1470 
1471 void
1472 Vehicle::setApparentDecel(const std::string& vehicleID, double decel) {
1473  getVehicle(vehicleID)->getSingularType().setApparentDecel(decel);
1474 }
1475 
1476 
1477 void
1478 Vehicle::setImperfection(const std::string& vehicleID, double imperfection) {
1479  getVehicle(vehicleID)->getSingularType().setImperfection(imperfection);
1480 }
1481 
1482 
1483 void
1484 Vehicle::setTau(const std::string& vehicleID, double tau) {
1485  getVehicle(vehicleID)->getSingularType().setTau(tau);
1486 }
1487 
1488 
1489 void
1490 Vehicle::setMinGapLat(const std::string& vehicleID, double minGapLat) {
1491  getVehicle(vehicleID)->getSingularType().setMinGapLat(minGapLat);
1492 }
1493 
1494 
1495 void
1496 Vehicle::setMaxSpeedLat(const std::string& vehicleID, double speed) {
1497  getVehicle(vehicleID)->getSingularType().setMaxSpeedLat(speed);
1498 }
1499 
1500 
1501 void
1502 Vehicle::setLateralAlignment(const std::string& vehicleID, const std::string& latAlignment) {
1504 }
1505 
1506 
1507 void
1508 Vehicle::setParameter(const std::string& vehicleID, const std::string& key, const std::string& value) {
1509  MSVehicle* veh = getVehicle(vehicleID);
1510  if (StringUtils::startsWith(key, "device.")) {
1511  StringTokenizer tok(key, ".");
1512  if (tok.size() < 3) {
1513  throw TraCIException("Invalid device parameter '" + key + "' for vehicle '" + vehicleID + "'");
1514  }
1515  try {
1516  veh->setDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2), value);
1517  } catch (InvalidArgument& e) {
1518  throw TraCIException("Vehicle '" + vehicleID + "' does not support device parameter '" + key + "' (" + e.what() + ").");
1519  }
1520  } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
1521  const std::string attrName = key.substr(16);
1522  try {
1523  veh->getLaneChangeModel().setParameter(attrName, value);
1524  } catch (InvalidArgument& e) {
1525  throw TraCIException("Vehicle '" + vehicleID + "' does not support laneChangeModel parameter '" + key + "' (" + e.what() + ").");
1526  }
1527  } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
1528  StringTokenizer tok(key, ".");
1529  if (tok.size() != 3) {
1530  throw TraCIException("Invalid request for device status change. Expected format is 'has.DEVICENAME.device'");
1531  }
1532  const std::string deviceName = tok.get(1);
1533  bool create;
1534  try {
1535  create = StringUtils::toBool(value);
1536  } catch (BoolFormatException&) {
1537  throw TraCIException("Changing device status requires a 'true' or 'false'");
1538  }
1539  if (!create) {
1540  throw TraCIException("Device removal is not supported for device of type '" + deviceName + "'");
1541  }
1542  try {
1543  veh->createDevice(deviceName);
1544  } catch (InvalidArgument& e) {
1545  throw TraCIException("Cannot create vehicle device (" + std::string(e.what()) + ").");
1546  }
1547  } else {
1548  ((SUMOVehicleParameter&)veh->getParameter()).setParameter(key, value);
1549  }
1550 }
1551 
1552 
1554 
1555 
1556 void
1557 Vehicle::storeShape(const std::string& id, PositionVector& shape) {
1558  shape.push_back(getVehicle(id)->getPosition());
1559 }
1560 
1561 
1562 std::shared_ptr<VariableWrapper>
1564  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
1565 }
1566 
1567 
1568 bool
1569 Vehicle::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
1570  switch (variable) {
1571  case TRACI_ID_LIST:
1572  return wrapper->wrapStringList(objID, variable, getIDList());
1573  case ID_COUNT:
1574  return wrapper->wrapInt(objID, variable, getIDCount());
1575  case VAR_POSITION:
1576  return wrapper->wrapPosition(objID, variable, getPosition(objID));
1577  case VAR_POSITION3D:
1578  return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
1579  case VAR_ANGLE:
1580  return wrapper->wrapDouble(objID, variable, getAngle(objID));
1581  case VAR_SPEED:
1582  return wrapper->wrapDouble(objID, variable, getSpeed(objID));
1583  case VAR_ROAD_ID:
1584  return wrapper->wrapString(objID, variable, getRoadID(objID));
1586  return wrapper->wrapDouble(objID, variable, getSpeedWithoutTraCI(objID));
1587  case VAR_SLOPE:
1588  return wrapper->wrapDouble(objID, variable, getSlope(objID));
1589  case VAR_LANE_ID:
1590  return wrapper->wrapString(objID, variable, getLaneID(objID));
1591  case VAR_LANE_INDEX:
1592  return wrapper->wrapInt(objID, variable, getLaneIndex(objID));
1593  case VAR_TYPE:
1594  return wrapper->wrapString(objID, variable, getTypeID(objID));
1595  case VAR_ROUTE_ID:
1596  return wrapper->wrapString(objID, variable, getRouteID(objID));
1597  case VAR_ROUTE_INDEX:
1598  return wrapper->wrapInt(objID, variable, getRouteIndex(objID));
1599  case VAR_COLOR:
1600  return wrapper->wrapColor(objID, variable, getColor(objID));
1601  case VAR_LANEPOSITION:
1602  return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
1603  case VAR_LANEPOSITION_LAT:
1604  return wrapper->wrapDouble(objID, variable, getLateralLanePosition(objID));
1605  case VAR_CO2EMISSION:
1606  return wrapper->wrapDouble(objID, variable, getCO2Emission(objID));
1607  case VAR_COEMISSION:
1608  return wrapper->wrapDouble(objID, variable, getCOEmission(objID));
1609  case VAR_HCEMISSION:
1610  return wrapper->wrapDouble(objID, variable, getHCEmission(objID));
1611  case VAR_PMXEMISSION:
1612  return wrapper->wrapDouble(objID, variable, getPMxEmission(objID));
1613  case VAR_NOXEMISSION:
1614  return wrapper->wrapDouble(objID, variable, getNOxEmission(objID));
1615  case VAR_FUELCONSUMPTION:
1616  return wrapper->wrapDouble(objID, variable, getFuelConsumption(objID));
1617  case VAR_NOISEEMISSION:
1618  return wrapper->wrapDouble(objID, variable, getNoiseEmission(objID));
1620  return wrapper->wrapDouble(objID, variable, getElectricityConsumption(objID));
1621  case VAR_PERSON_NUMBER:
1622  return wrapper->wrapInt(objID, variable, getPersonNumber(objID));
1624  return wrapper->wrapStringList(objID, variable, getPersonIDList(objID));
1625  case VAR_WAITING_TIME:
1626  return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
1628  return wrapper->wrapDouble(objID, variable, getAccumulatedWaitingTime(objID));
1629  case VAR_ROUTE_VALID:
1630  return wrapper->wrapInt(objID, variable, isRouteValid(objID));
1631  case VAR_EDGES:
1632  return wrapper->wrapStringList(objID, variable, getRoute(objID));
1633  case VAR_SIGNALS:
1634  return wrapper->wrapInt(objID, variable, getSignals(objID));
1635  case VAR_STOPSTATE:
1636  return wrapper->wrapInt(objID, variable, getStopState(objID));
1637  case VAR_DISTANCE:
1638  return wrapper->wrapDouble(objID, variable, getDistance(objID));
1639  case VAR_ALLOWED_SPEED:
1640  return wrapper->wrapDouble(objID, variable, getAllowedSpeed(objID));
1641  case VAR_SPEED_FACTOR:
1642  return wrapper->wrapDouble(objID, variable, getSpeedFactor(objID));
1643  case VAR_SPEEDSETMODE:
1644  return wrapper->wrapInt(objID, variable, getSpeedMode(objID));
1645  case VAR_LANECHANGE_MODE:
1646  return wrapper->wrapInt(objID, variable, getLaneChangeMode(objID));
1647  case VAR_ROUTING_MODE:
1648  return wrapper->wrapInt(objID, variable, getRoutingMode(objID));
1649  case VAR_LINE:
1650  return wrapper->wrapString(objID, variable, getLine(objID));
1651  case VAR_VIA:
1652  return wrapper->wrapStringList(objID, variable, getVia(objID));
1653  case VAR_ACCELERATION:
1654  return wrapper->wrapDouble(objID, variable, getAcceleration(objID));
1655  case VAR_LASTACTIONTIME:
1656  return wrapper->wrapDouble(objID, variable, getLastActionTime(objID));
1657  default:
1658  return false;
1659  }
1660 }
1661 
1662 
1663 }
1664 
1665 /****************************************************************************/
#define VAR_ROAD_ID
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
int getRoutePosition() const
Definition: MSVehicle.cpp:1027
unsigned char g
Definition: TraCIDefs.h:139
static std::string getLaneID(const std::string &vehicleID)
Definition: Vehicle.cpp:166
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:234
static std::vector< TraCIBestLanesData > getBestLanes(const std::string &vehicleID)
Definition: Vehicle.cpp:343
#define REMOVE_PARKING
void setMinGap(const double &minGap)
Set a new value for this type&#39;s minimum gap.
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:199
static double gLateralResolution
Definition: MSGlobals.h:85
double getFuelConsumption() const
Returns fuel consumption of the current state.
Definition: MSVehicle.cpp:4811
std::string id
The id of the next tls.
Definition: TraCIDefs.h:288
int stopFlags
Stop flags.
Definition: TraCIDefs.h:306
double getAccumulatedWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s) within the last millisecs...
Definition: MSVehicle.h:671
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:492
SumoXMLTag
Numbers representing SUMO-XML - element names.
bool hasSavedState(const int dir) const
double getNOxEmissions() const
Returns NOx emission of the current state.
Definition: MSVehicle.cpp:4799
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:4098
static void setStop(const std::string &vehicleID, const std::string &edgeID, double pos=1., int laneIndex=0, double duration=INVALID_DOUBLE_VALUE, int flags=STOP_DEFAULT, double startPos=INVALID_DOUBLE_VALUE, double until=INVALID_DOUBLE_VALUE)
Definition: Vehicle.cpp:727
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT() const
Definition: MSVehicle.cpp:773
RGBColor color
The vehicle&#39;s color, TraCI may change this.
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:640
static void setEffort(const std::string &vehicleID, const std::string &edgeID, double effort=INVALID_DOUBLE_VALUE, double begSeconds=0, double endSeconds=std::numeric_limits< double >::max())
Definition: Vehicle.cpp:1222
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
virtual bool wrapInt(const std::string &objID, const int variable, const int value)=0
long long int SUMOTime
Definition: SUMOTime.h:36
const int VEHPARS_FORCE_REROUTE
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
#define VAR_VIA
#define VAR_CO2EMISSION
double getElectricityConsumption() const
Returns electricity consumption of the current state.
Definition: MSVehicle.cpp:4817
#define VAR_ACCELERATION
static void setLine(const std::string &vehicleID, const std::string &line)
Definition: Vehicle.cpp:1386
double dist
The distance to the tls.
Definition: TraCIDefs.h:292
double getAngle() const
Returns the vehicle&#39;s direction in radians.
Definition: MSVehicle.h:685
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:324
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
The time is given.
static std::pair< MSLane *, double > convertCartesianToRoadMap(Position pos)
Definition: Helper.cpp:290
static void updateBestLanes(const std::string &vehicleID)
Definition: Vehicle.cpp:1189
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:121
double until
The time at which the vehicle may continue its journey.
Definition: TraCIDefs.h:310
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: Helper.cpp:230
The vehicle is discarded if emission fails (not fully implemented yet)
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:661
static double getSpeedWithoutTraCI(const std::string &vehicleID)
Definition: Vehicle.cpp:118
static std::string getRoadID(const std::string &vehicleID)
Definition: Vehicle.cpp:159
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector) ...
#define VAR_ACCUMULATED_WAITING_TIME
bool parking
whether the vehicle is removed from the net while stopping
static void setRoute(const std::string &vehicleID, const std::vector< std::string > &edgeIDs)
Definition: Vehicle.cpp:1175
bool hasDeparted() const
Returns whether this vehicle has already departed.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
static int getPersonNumber(const std::string &vehicleID)
Definition: Vehicle.cpp:264
Stop & getNextStop()
Definition: MSVehicle.cpp:5478
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
#define VAR_POSITION
bool resumeFromStopping()
Definition: MSVehicle.cpp:5427
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:565
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...
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
void setTau(double tau)
Set a new value for this type&#39;s headway.
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive...
Definition: MSVehicle.h:820
void setShape(SUMOVehicleShape shape)
Set a new value for this type&#39;s shape.
static MSEdge * getEdge(const std::string &edgeID)
Definition: Helper.cpp:263
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
#define VAR_SPEEDSETMODE
static double getAcceleration(const std::string &vehicleID)
Definition: Vehicle.cpp:111
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:4740
static void deactivateGapControl(const std::string &vehicleID)
Definition: Vehicle.cpp:1112
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition: MSVehicle.h:935
SUMOTime duration
The stopping duration.
Definition: MSVehicle.h:937
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:247
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
static void setParameter(const std::string &vehicleID, const std::string &key, const std::string &value)
Definition: Vehicle.cpp:1508
virtual double getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:251
std::list< Stop > getMyStops()
Definition: MSVehicle.cpp:5483
#define VAR_ALLOWED_SPEED
std::vector< double > & getParameter()
Returns the parameters of this distribution.
MSParkingArea * parkingarea
(Optional) parkingArea if one is assigned to the stop
Definition: MSVehicle.h:931
static double getSlope(const std::string &vehicleID)
Definition: Vehicle.cpp:152
MSStoppingPlace * busstop
(Optional) bus stop if one is assigned to the stop
Definition: MSVehicle.h:927
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:403
#define VAR_WAITING_TIME
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
#define VAR_SIGNALS
#define VAR_TYPE
static std::string getTypeID(const std::string &vehicleID)
Definition: Vehicle.cpp:180
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
bool reached
Information whether the stop has been reached.
Definition: MSVehicle.h:943
#define VAR_ROUTE_ID
Notification
Definition of a vehicle state.
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:2045
static void setRoutingMode(const std::string &vehicleID, int routingMode)
Definition: Vehicle.cpp:1141
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...
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
#define VAR_SPEED_FACTOR
#define VAR_COLOR
std::string get(int pos) const
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
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:5347
static SUMOTime processActionStepLength(double given)
Checks and converts given value for the action step length from seconds to miliseconds assuring it be...
double occupation
The traffic density along length.
Definition: TraCIDefs.h:320
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:162
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position ...
Definition: Position.h:254
static double getCOEmission(const std::string &vehicleID)
Definition: Vehicle.cpp:222
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
static void add(const std::string &routeID, const std::vector< std::string > &edgeIDs)
Definition: Route.cpp:85
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:316
static void setSpeedMode(const std::string &vehicleID, int speedMode)
Definition: Vehicle.cpp:1131
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:514
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:456
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition: Named.h:71
bool isLinkEnd(MSLinkCont::const_iterator &i) const
Definition: MSLane.cpp:1859
#define VAR_ROUTING_MODE
static std::vector< std::string > getVia(const std::string &vehicleID)
Definition: Vehicle.cpp:557
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.
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
The vehicle got vaporized.
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:788
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:1126
static void rerouteParkingArea(const std::string &vehicleID, const std::string &parkingAreaID)
Definition: Vehicle.cpp:794
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
void setApparentDecel(double apparentDecel)
Set a new value for this type&#39;s apparent deceleration.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:200
static TraCIPosition getPosition3D(const std::string &vehicleID)
Definition: Vehicle.cpp:139
void setLength(const double &length)
Set a new value for this type&#39;s length.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle&#39;s end speed shall be chosen.
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:1246
static void setRouteID(const std::string &vehicleID, const std::string &routeID)
Definition: Vehicle.cpp:1155
int getLaneChangeMode() const
return the current lane change mode
Definition: MSVehicle.cpp:346
const std::string & getID() const
Returns the id.
Definition: Named.h:78
virtual bool wrapString(const std::string &objID, const int variable, const std::string &value)=0
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
static double getAngle(const std::string &vehicleID)
Definition: Vehicle.cpp:145
int getSpeedMode() const
return the current speed mode
Definition: MSVehicle.cpp:336
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: Vehicle.cpp:1563
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:818
static ContextSubscriptionResults myContextSubscriptionResults
Definition: Vehicle.h:202
double length
The overall length which may be driven when using this lane without a lane change.
Definition: MSVehicle.h:812
void setImperfection(double imperfection)
Set a new value for this type&#39;s imperfection.
static std::string getLine(const std::string &vehicleID)
Definition: Vehicle.cpp:552
bool rerouteParkingArea(const std::string &parkingAreaID, std::string &errorMsg)
Definition: MSVehicle.cpp:5224
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
#define VAR_NOISEEMISSION
#define VAR_FUELCONSUMPTION
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:530
static double getDistance(const std::string &vehicleID)
Definition: Vehicle.cpp:459
static double getNoiseEmission(const std::string &vehicleID)
Definition: Vehicle.cpp:252
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
#define VAR_POSITION3D
The car-following model and parameter.
Definition: MSVehicleType.h:66
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4307
double getDepartPos() const
Returns this vehicle&#39;s real departure position.
std::string toTaz
The vehicle&#39;s destination zone (district)
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...
int getLaneIndex() const
Definition: MSVehicle.cpp:4914
static std::pair< int, int > getLaneChangeState(const std::string &vehicleID, int direction)
Definition: Vehicle.cpp:563
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
static double getNOxEmission(const std::string &vehicleID)
Definition: Vehicle.cpp:240
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter ...
static void rerouteTraveltime(const std::string &vehicleID)
Definition: Vehicle.cpp:1248
static double getEffort(const std::string &vehicleID, double time, const std::string &edgeID)
Definition: Vehicle.cpp:309
#define VAR_NOXEMISSION
LIBSUMO_VEHICLE_TYPE_SETTER static LIBSUMO_SUBSCRIPTION_API void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: Vehicle.cpp:1557
bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)
Replaces the current route by the given one.
Definition: MSVehicle.cpp:957
static std::vector< std::string > getPersonIDList(const std::string &vehicleID)
Definition: Vehicle.cpp:269
static double getWaitingTime(const std::string &vehicleID)
Definition: Vehicle.cpp:288
static double getLastActionTime(const std::string &vehicleID)
Definition: Vehicle.cpp:655
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:210
static SubscriptionResults mySubscriptionResults
Definition: Vehicle.h:201
static double getCO2Emission(const std::string &vehicleID)
Definition: Vehicle.cpp:216
void setMinGapLat(const double &minGapLat)
Set a new value for this type&#39;s minimum lataral gap.
static const MSVehicleType & getVehicleType(const std::string &vehicleID)
Definition: Vehicle.cpp:606
bool isInternal() const
Definition: MSLane.cpp:1875
#define VAR_ANGLE
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:322
unsigned char b
Definition: TraCIDefs.h:139
double departSpeed
(optional) The initial speed of the vehicle
A road/street connecting two junctions.
Definition: MSEdge.h:75
static void resume(const std::string &vehicleID)
Definition: Vehicle.cpp:804
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:587
#define INVALID_DOUBLE_VALUE
Definition: TraCIDefs.h:42
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
Definition: MSVehicle.cpp:305
MSLane * lane
The described lane.
Definition: MSVehicle.h:810
void setSpeedMode(int speedMode)
Sets speed-constraining behaviors.
Definition: MSVehicle.cpp:643
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:180
#define VAR_PERSON_NUMBER
The action has not been determined.
double getCO2Emissions() const
Returns CO2 emission of the current state.
Definition: MSVehicle.cpp:4781
int getIndex() const
Returns the lane&#39;s index.
Definition: MSLane.h:537
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle&#39;s initial speed shall be chosen.
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
#define REMOVE_ARRIVED
void setSublaneChange(double latDist)
Sets a new sublane-change request.
Definition: MSVehicle.cpp:331
#define TRACI_ID_LIST
static std::vector< TraCINextTLSData > getNextTLS(const std::string &vehicleID)
Definition: Vehicle.cpp:369
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
static int getSpeedMode(const std::string &vehicleID)
Definition: Vehicle.cpp:537
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void createDevice(const std::string &deviceName)
create device of the given type
static int getRouteIndex(const std::string &vehicleID)
Definition: Vehicle.cpp:192
void setAccel(double accel)
Set a new value for this type&#39;s acceleration.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
static void setLaneChangeMode(const std::string &vehicleID, int laneChangeMode)
Definition: Vehicle.cpp:1136
static void setVia(const std::string &vehicleID, const std::vector< std::string > &via)
Definition: Vehicle.cpp:1392
static bool gCheckRoutes
Definition: MSGlobals.h:79
double startPos
The stopping position start.
static double getLateralLanePosition(const std::string &vehicleID)
Definition: Vehicle.cpp:210
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
#define REMOVE_TELEPORT_ARRIVED
static double getHCEmission(const std::string &vehicleID)
Definition: Vehicle.cpp:228
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
SUMOTime getActionStepLength() const
Returns the vehicle&#39;s action step length in millisecs, i.e. the interval between two action points...
Definition: MSVehicle.h:509
MSRouteIterator edge
The edge in the route to stop at.
Definition: MSVehicle.h:923
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:80
#define VAR_LANEPOSITION
std::string stoppingPlaceID
Id assigned to the stop.
Definition: TraCIDefs.h:304
A list of positions.
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
Definition: MSVehicle.cpp:4325
int getRoutingMode() const
return the current routing mode
Definition: MSVehicle.h:1429
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
Definition: MSVehicle.cpp:4668
static bool isOnInit(const std::string &vehicleID)
Definition: Vehicle.cpp:80
double getEmergencyDecel() const
Get the vehicle type&#39;s maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:226
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
void setHeight(const double &height)
Set a new value for this type&#39;s height.
static void add(const std::string &vehicleID, const std::string &routeID, const std::string &typeID="DEFAULT_VEHTYPE", const std::string &depart="now", 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=4, int personNumber=0)
Definition: Vehicle.cpp:879
static double getFuelConsumption(const std::string &vehicleID)
Definition: Vehicle.cpp:246
#define REMOVE_TELEPORT
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.
#define VAR_LASTACTIONTIME
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:58
static double getLanePosition(const std::string &vehicleID)
Definition: Vehicle.cpp:204
static std::vector< std::string > getRoute(const std::string &vehicleID)
Definition: Vehicle.cpp:325
The vehicle arrived at its destination (is deleted)
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
unsigned char a
Definition: TraCIDefs.h:139
SUMOTime depart
The vehicle&#39;s departure time.
#define VAR_PMXEMISSION
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
Definition: MSVehicle.h:994
void forceVehicleInsertion(MSVehicle *veh, double pos, MSMoveReminder::Notification notification, double posLat=0)
Inserts the given vehicle at the given position.
Definition: MSLane.cpp:964
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:263
static void moveTo(const std::string &vehicleID, const std::string &laneID, double position)
Definition: Vehicle.cpp:1276
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
double getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
Definition: MSVehicle.cpp:4823
T MIN2(T a, T b)
Definition: StdDefs.h:70
void resetActionOffset(const SUMOTime timeUntilNextAction=0)
Resets the action offset for the vehicle.
Definition: MSVehicle.cpp:1884
#define POSITION_EPS
Definition: config.h:172
std::string fromTaz
The vehicle&#39;s origin zone (district)
A structure representing the best lanes for continuing the current route starting at &#39;lane&#39;...
Definition: MSVehicle.h:808
static void changeLane(const std::string &vehicleID, int laneIndex, double duration)
Definition: Vehicle.cpp:849
#define VAR_EDGES
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:934
bool hasInfluencer() const
Definition: MSVehicle.h:1640
unsigned char r
Definition: TraCIDefs.h:139
virtual bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const =0
Returns the information whether the vehicle is fully controlled via TraCI.
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type&#39;s emission class.
static std::vector< std::string > getIDList()
Definition: Vehicle.cpp:86
double getMinGap() const
Get the free space in front of vehicles of this class.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:218
double endPos
The stopping position end.
Definition: TraCIDefs.h:302
static double getAccumulatedWaitingTime(const std::string &vehicleID)
Definition: Vehicle.cpp:294
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:52
#define VAR_STOPSTATE
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: Vehicle.cpp:1569
void setChosenSpeedFactor(const double factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:52
#define VAR_SLOPE
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:225
const int VEHPARS_COLOR_SET
static void setSpeed(const std::string &vehicleID, double speed)
Definition: Vehicle.cpp:1120
int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons) ...
static std::string getRouteID(const std::string &vehicleID)
Definition: Vehicle.cpp:186
static TraCIPosition getPosition(const std::string &vehicleID, const bool includeZ=false)
Definition: Vehicle.cpp:125
bool containerTriggered
whether an arriving container lets the vehicle continue
void move2side(double amount)
move position vector to side using certain ammount
static MSLinkCont::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane *> &conts)
Definition: MSLane.cpp:1926
std::vector< std::string > getPersonIDList() const
Returns the list of persons.
bool allowsContinuation
Whether this lane allows to continue the drive.
Definition: MSVehicle.h:822
static int getLaneChangeMode(const std::string &vehicleID)
Definition: Vehicle.cpp:542
Definition: Edge.cpp:30
static double getAdaptedTraveltime(const std::string &vehicleID, double time, const std::string &edgeID)
Definition: Vehicle.cpp:300
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
std::string line
The vehicle&#39;s line (mainly for public transport)
double arrivalPos
(optional) The position the vehicle shall arrive on
#define VAR_SPEED
void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset)
Set a new value for this type&#39;s action step length.
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:440
void setRoutingMode(int value)
Sets routing behavior.
Definition: MSVehicle.h:1514
virtual bool wrapDouble(const std::string &objID, const int variable, const double value)=0
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
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.
double getCOEmissions() const
Returns CO emission of the current state.
Definition: MSVehicle.cpp:4787
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)
Definition: Vehicle.cpp:574
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
virtual bool wrapPosition(const std::string &objID, const int variable, const TraCIPosition &value)=0
double getMaxSpeedLat() const
Get vehicle&#39;s maximum lateral speed [m/s].
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition: Helper.cpp:739
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
static int getLaneIndex(const std::string &vehicleID)
Definition: Vehicle.cpp:173
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
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:5299
static int getIDCount()
Definition: Vehicle.cpp:98
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
double departPos
(optional) The position the vehicle shall depart from
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1730
#define VAR_COEMISSION
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
static void changeTarget(const std::string &vehicleID, const std::string &edgeID)
Definition: Vehicle.cpp:823
The vehicle has departed (was inserted into the network)
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:5488
int getPersonNumber() const
Returns the number of persons.
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
void activateGapController(double originalTau, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel)
Activates the gap control with the given parameters,.
Definition: MSVehicle.cpp:311
Structure representing possible vehicle parameter.
#define INVALID_INT_VALUE
#define VAR_LANEPOSITION_LAT
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
static double getAllowedSpeed(const std::string &vehicleID)
Definition: Vehicle.cpp:520
static double getPMxEmission(const std::string &vehicleID)
Definition: Vehicle.cpp:234
#define SUMOTime_MAX
Definition: SUMOTime.h:37
static void setSignals(const std::string &vehicleID, int signals)
Definition: Vehicle.cpp:1263
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
static bool isRouteValid(const std::string &vehicleID)
Definition: Vehicle.cpp:318
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:4921
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:369
virtual bool wrapColor(const std::string &objID, const int variable, const TraCIColor &value)=0
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:259
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:821
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
static void moveToXY(const std::string &vehicleID, const std::string &edgeID, const int laneIndex, const double x, const double y, double angle=INVALID_DOUBLE_VALUE, const int keepRoute=1)
Definition: Vehicle.cpp:987
static double getDrivingDistance2D(const std::string &vehicleID, double x, double y)
Definition: Vehicle.cpp:502
std::vector< MSLane * > bestContinuations
Definition: MSVehicle.h:828
MSStoppingPlace * chargingStation
(Optional) charging station if one is assigned to the stop
Definition: MSVehicle.h:933
char state
The current state of the tls.
Definition: TraCIDefs.h:294
static bool parseArrivalSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, ArrivalSpeedDefinition &asd, std::string &error)
Validates a given arrivalSpeed value.
#define VAR_ELECTRICITYCONSUMPTION
#define VAR_ROUTE_INDEX
double getAcceleration() const
Returns the vehicle&#39;s acceleration in m/s (this is computed as the last step&#39;s mean acceleration in c...
Definition: MSVehicle.h:500
MSStoppingPlace * containerstop
(Optional) container stop if one is assigned to the stop
Definition: MSVehicle.h:929
static std::pair< std::string, double > getLeader(const std::string &vehicleID, double dist=0.)
Definition: Vehicle.cpp:274
const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
Definition: MSVehicle.cpp:1242
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
double getPMxEmissions() const
Returns PMx emission of the current state.
Definition: MSVehicle.cpp:4805
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
void setWidth(const double &width)
Set a new value for this type&#39;s width.
double getActionStepLengthSecs() const
Returns this type&#39;s default action step length in seconds.
static int getRoutingMode(const std::string &vehicleID)
Definition: Vehicle.cpp:547
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:478
static void slowDown(const std::string &vehicleID, double speed, double duration)
Definition: Vehicle.cpp:1089
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:1889
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
double getLength() const
Get vehicle&#39;s length [m].
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
void setLaneChangeMode(int value)
Sets lane changing behavior.
Definition: MSVehicle.cpp:653
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type&#39;s vehicle class.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
#define REMOVE_VAPORIZED
void setSignals(int signals)
Definition: MSVehicle.h:1541
static void setAdaptedTraveltime(const std::string &vehicleID, const std::string &edgeID, double time=INVALID_DOUBLE_VALUE, double begSeconds=0, double endSeconds=std::numeric_limits< double >::max())
Definition: Vehicle.cpp:1196
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle&#39;s internal edge travel times/efforts container.
Definition: MSVehicle.cpp:1042
static void changeLaneRelative(const std::string &vehicleID, int laneChange, double duration)
Definition: Vehicle.cpp:857
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
void switchOffSignal(int signal)
Switches the given signal off.
Definition: MSVehicle.h:1238
void switchOnSignal(int signal)
Switches the given signal on.
Definition: MSVehicle.h:1230
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:1115
#define LAST_STEP_PERSON_ID_LIST
static void remove(const std::string &vehicleID, char reason=REMOVE_VAPORIZED)
Definition: Vehicle.cpp:1332
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
#define VAR_SPEED_WITHOUT_TRACI
static MSVehicle * getVehicle(const std::string &id)
Definition: Vehicle.cpp:60
double length
The length than can be driven from that lane without lane change.
Definition: TraCIDefs.h:318
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
#define VAR_LANECHANGE_MODE
void setLaneTimeLine(const std::vector< std::pair< SUMOTime, int > > &laneTimeLine)
Sets a new lane timeline.
Definition: MSVehicle.cpp:326
double getHCEmissions() const
Returns HC emission of the current state.
Definition: MSVehicle.cpp:4793
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:70
The vehicle was teleported out of the net.
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MSVehicle.cpp:1585
void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)
Performs a rerouting using the given router.
#define VAR_ROUTE_VALID
The class responsible for building and deletion of vehicles.
bool willPass(const MSEdge *const edge) const
Returns whether the vehicle wil pass the given edge.
Definition: MSVehicle.cpp:1021
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:71
static double getElectricityConsumption(const std::string &vehicleID)
Definition: Vehicle.cpp:258
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
#define ID_COUNT
#define VAR_LANE_INDEX
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
Definition: MSVehicle.cpp:4319
static void setType(const std::string &vehicleID, const std::string &typeID)
Definition: Vehicle.cpp:1146
#define VAR_LANE_ID
#define VAR_LINE
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:483
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
void setMaxSpeedLat(const double &maxSpeedLat)
Set a new value for this type&#39;s maximum lateral speed.
void setPreferredLateralAlignment(LateralAlignment latAlignment)
Set vehicle&#39;s preferred lateral alignment.
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
static double getDrivingDistance(const std::string &vehicleID, const std::string &edgeID, double position, int laneIndex=0)
Definition: Vehicle.cpp:486
static bool moveToXYMap_matchingRoutePosition(const Position &pos, const std::string &origID, const ConstMSEdgeVector &currentRoute, int routeIndex, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset)
Definition: Helper.cpp:986
A 3D-position.
Definition: TraCIDefs.h:107
static int getSignals(const std::string &vehicleID)
Definition: Vehicle.cpp:337
const std::string & getID() const
Returns the name of the vehicle.
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
static void changeSublane(const std::string &vehicleID, double latDist)
Definition: Vehicle.cpp:873
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
void deactivateGapController()
Deactivates the gap control.
Definition: MSVehicle.cpp:319
int tlIndex
The tls index of the controlled link.
Definition: TraCIDefs.h:290
static double getSpeed(const std::string &vehicleID)
Definition: Vehicle.cpp:104
static int getStopState(const std::string &vehicleID)
Definition: Vehicle.cpp:442
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
static bool isVisible(const SUMOVehicle *veh)
Definition: Vehicle.cpp:74
const Distribution_Parameterized & getSpeedFactor() const
Returns this type&#39;s speed factor.
static std::vector< TraCINextStopData > getNextStops(const std::string &vehicleID)
Definition: Vehicle.cpp:402
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:76
static void openGap(const std::string &vehicleID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel)
Definition: Vehicle.cpp:1098
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:845
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error)
Validates a given depart value.
#define VAR_DISTANCE
double duration
The stopping duration.
Definition: TraCIDefs.h:308
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:326
#define VAR_HCEMISSION
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
std::string id
The vehicle&#39;s id.
double getSpeedWithoutTraciInfluence() const
Returns the uninfluenced velocity.
Definition: MSVehicle.cpp:5503
The vehicle is being teleported.
static void rerouteEffort(const std::string &vehicleID)
Definition: Vehicle.cpp:1256
Definition of vehicle stop (position and duration)
Definition: MSVehicle.h:919
std::string lane
The lane to stop at.
Definition: TraCIDefs.h:300
const std::pair< int, int > & getSavedState(const int dir) const
void addEffort(const MSEdge *const e, double begin, double end, double value)
Adds an effort information for an edge and a time span.
static bool moveToXYMap(const Position &pos, double maxRouteDistance, bool mayLeaveNetwork, const std::string &origID, const double angle, double speed, const ConstMSEdgeVector &currentRoute, const int routePosition, MSLane *currentLane, double currentLanePos, bool onRoad, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
Definition: Helper.cpp:775
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:114
static bool parseDepartLane(const std::string &val, const std::string &element, const std::string &id, int &lane, DepartLaneDefinition &dld, std::string &error)
Validates a given departLane value.
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:277