Eclipse SUMO - Simulation of Urban MObility
MSBaseVehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 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 /****************************************************************************/
17 // A base class for vehicle implementations
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <iostream>
27 #include <cassert>
28 #include <utils/common/StdDefs.h>
33 #include "MSGlobals.h"
34 #include "MSTransportable.h"
35 #include "MSVehicleControl.h"
36 #include "MSVehicleType.h"
37 #include "MSEdge.h"
38 #include "MSLane.h"
39 #include "MSMoveReminder.h"
40 #include "MSBaseVehicle.h"
41 #include "MSNet.h"
42 #include "devices/MSDevice.h"
45 #include "MSInsertionControl.h"
46 
47 //#define DEBUG_REROUTE
48 //#define DEBUG_COND (getID() == "follower")
49 //#define DEBUG_COND (true)
50 #define DEBUG_COND (isSelected())
51 
52 // ===========================================================================
53 // static members
54 // ===========================================================================
56 std::vector<MSTransportable*> MSBaseVehicle::myEmptyTransportableVector;
57 #ifdef _DEBUG
58 std::set<std::string> MSBaseVehicle::myShallTraceMoveReminders;
59 #endif
61 
62 
63 // ===========================================================================
64 // method definitions
65 // ===========================================================================
66 
67 double
69  throw ProcessError("getPreviousSpeed() is not available for non-MSVehicles.");
70 }
71 
72 
74  MSVehicleType* type, const double speedFactor) :
75  myParameter(pars),
76  myRoute(route),
77  myType(type),
78  myCurrEdge(route->begin()),
79  myChosenSpeedFactor(speedFactor),
80  myMoveReminders(0),
81  myPersonDevice(nullptr),
82  myContainerDevice(nullptr),
84  myDepartPos(-1),
85  myArrivalPos(-1),
86  myArrivalLane(-1),
89 #ifdef _DEBUG
90  , myTraceMoveReminders(myShallTraceMoveReminders.count(pars->id) > 0)
91 #endif
92 {
93  if ((*myRoute->begin())->isTazConnector() || myRoute->getLastEdge()->isTazConnector()) {
95  }
96  if (!pars->wasSet(VEHPARS_FORCE_REROUTE)) {
99  std::string msg;
100  if (!hasValidRoute(msg)) {
101  msg = "Vehicle '" + pars->id + "' has no valid route. " + msg;
102  delete myParameter;
103  throw ProcessError(msg);
104  }
105  }
106  }
107  // init devices
108  try {
110  } catch (ProcessError&) {
111  for (MSVehicleDevice* dev : myDevices) {
112  delete dev;
113  }
114  delete myParameter;
115  throw;
116  }
118  for (MSVehicleDevice* dev : myDevices) {
119  myMoveReminders.push_back(std::make_pair(dev, 0.));
120  }
121 }
122 
123 
125  myRoute->release();
126  if (myParameter->repetitionNumber == 0) {
128  }
129  for (MSVehicleDevice* dev : myDevices) {
130  delete dev;
131  }
132  delete myParameter;
133 }
134 
135 
136 const std::string&
138  return myParameter->id;
139 }
140 
141 
144  return *myParameter;
145 }
146 
147 void
149  delete myParameter;
150  myParameter = newParameter;
151 }
152 
153 double
155  return myType->getMaxSpeed();
156 }
157 
158 
159 const MSEdge*
160 MSBaseVehicle::succEdge(int nSuccs) const {
161  if (myCurrEdge + nSuccs < myRoute->end() && std::distance(myCurrEdge, myRoute->begin()) <= nSuccs) {
162  return *(myCurrEdge + nSuccs);
163  } else {
164  return nullptr;
165  }
166 }
167 
168 
169 const MSEdge*
171  return *myCurrEdge;
172 }
173 
174 
175 void
176 MSBaseVehicle::reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit, const bool withTaz, const bool silent) {
177  // check whether to reroute
178  const MSEdge* source = withTaz && onInit ? MSEdge::dictionary(myParameter->fromTaz + "-source") : getRerouteOrigin();
179  if (source == nullptr) {
180  source = getRerouteOrigin();
181  }
182  const MSEdge* sink = withTaz ? MSEdge::dictionary(myParameter->toTaz + "-sink") : myRoute->getLastEdge();
183  if (sink == nullptr) {
184  sink = myRoute->getLastEdge();
185  }
186  ConstMSEdgeVector oldEdgesRemaining(source == *myCurrEdge ? myCurrEdge : myCurrEdge + 1, myRoute->end());
187  ConstMSEdgeVector edges;
188  ConstMSEdgeVector stops;
189  if (myParameter->via.size() == 0) {
190  double firstPos = -1;
191  double lastPos = -1;
192  stops = getStopEdges(firstPos, lastPos);
193  if (stops.size() > 0) {
194  const double sourcePos = onInit ? 0 : getPositionOnLane();
195  // avoid superfluous waypoints for first and last edge
196  const bool skipFirst = stops.front() == source && sourcePos < firstPos;
197  const bool skipLast = stops.back() == sink && myArrivalPos > lastPos;
198 #ifdef DEBUG_REROUTE
199  if (DEBUG_COND) {
200  std::cout << SIMTIME << " reroute " << info << " veh=" << getID() << " lane=" << getLane()->getID()
201  << " source=" << source->getID() << " sourcePos=" << sourcePos << " firstPos=" << firstPos << " arrivalPos=" << myArrivalPos << " lastPos=" << lastPos
202  << " route=" << toString(myRoute->getEdges()) << " stopEdges=" << toString(stops) << " skipFirst=" << skipFirst << " skipLast=" << skipLast << "\n";
203  }
204 #endif
205  if (stops.size() == 1 && (skipFirst || skipLast)) {
206  stops.clear();
207  } else {
208  if (skipFirst) {
209  stops.erase(stops.begin());
210  }
211  if (skipLast) {
212  stops.erase(stops.end() - 1);
213  }
214  }
215  }
216  } else {
217  // via takes precedence over stop edges
218  // XXX check for inconsistencies #2275
219  for (std::vector<std::string>::const_iterator it = myParameter->via.begin(); it != myParameter->via.end(); ++it) {
220  MSEdge* viaEdge = MSEdge::dictionary(*it);
221  if (viaEdge == source || viaEdge == sink) {
222  continue;
223  }
224  assert(viaEdge != 0);
225  if (!viaEdge->isTazConnector() && viaEdge->allowedLanes(getVClass()) == nullptr) {
226  throw ProcessError("Vehicle '" + getID() + "' is not allowed on any lane of via edge '" + viaEdge->getID() + "'.");
227  }
228  stops.push_back(viaEdge);
229  }
230  }
231 
232  for (MSRouteIterator s = stops.begin(); s != stops.end(); ++s) {
233  // !!! need to adapt t here
234  ConstMSEdgeVector into;
235  router.computeLooped(source, *s, this, t, into, silent);
236  if (into.size() > 0) {
237  into.pop_back();
238  edges.insert(edges.end(), into.begin(), into.end());
239  if ((*s)->isTazConnector()) {
240  source = into.back();
241  edges.pop_back();
242  } else {
243  source = *s;
244  }
245  } else {
246  std::string error = "Vehicle '" + getID() + "' has no valid route from edge '" + source->getID() + "' to stop edge '" + (*s)->getID() + "'.";
247  if (MSGlobals::gCheckRoutes || silent) {
248  throw ProcessError(error);
249  } else {
250  WRITE_WARNING(error);
251  edges.push_back(source);
252  }
253  source = *s;
254  }
255  }
256  router.compute(source, sink, this, t, edges, silent);
257  if (edges.empty() && silent) {
258  return;
259  }
260  if (!edges.empty() && edges.front()->isTazConnector()) {
261  edges.erase(edges.begin());
262  }
263  if (!edges.empty() && edges.back()->isTazConnector()) {
264  edges.pop_back();
265  }
266  const double routeCost = router.recomputeCosts(edges, this, t);
267  const double previousCost = onInit ? routeCost : router.recomputeCosts(oldEdgesRemaining, this, t);
268  const double savings = previousCost - routeCost;
269  //if (getID() == "43") std::cout << SIMTIME << " pCost=" << previousCost << " cost=" << routeCost
270  // << " onInit=" << onInit
271  // << " prevEdges=" << toString(oldEdgesRemaining)
272  // << " newEdges=" << toString(edges)
273  // << "\n";
274  replaceRouteEdges(edges, routeCost, savings, info, onInit);
275  // this must be called even if the route could not be replaced
276  if (onInit) {
277  if (edges.empty()) {
279  throw ProcessError("Vehicle '" + getID() + "' has no valid route.");
280  } else if (source->isTazConnector()) {
281  WRITE_WARNING("Removing vehicle '" + getID() + "' which has no valid route.");
283  return;
284  }
285  }
287  }
288 }
289 
290 
291 bool
292 MSBaseVehicle::replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit, bool check, bool removeStops) {
293  if (edges.empty()) {
294  WRITE_WARNING("No route for vehicle '" + getID() + "' found.");
295  return false;
296  }
297  // build a new id, first
298  std::string id = getID();
299  if (id[0] != '!') {
300  id = "!" + id;
301  }
302  if (myRoute->getID().find("!var#") != std::string::npos) {
303  id = myRoute->getID().substr(0, myRoute->getID().rfind("!var#") + 5) + toString(getNumberReroutes() + 1);
304  } else {
305  id = id + "!var#1";
306  }
307  int oldSize = (int)edges.size();
308  if (!onInit) {
309  const MSEdge* const origin = getRerouteOrigin();
310  if (origin != *myCurrEdge && edges.front() == origin) {
311  edges.insert(edges.begin(), *myCurrEdge);
312  oldSize = (int)edges.size();
313  }
314  edges.insert(edges.begin(), myRoute->begin(), myCurrEdge);
315  }
317  // re-assign stop iterators when rerouting to a new parkingArea
318  return true;
319  }
320  const RGBColor& c = myRoute->getColor();
321  MSRoute* newRoute = new MSRoute(id, edges, false, &c == &RGBColor::DEFAULT_COLOR ? nullptr : new RGBColor(c), std::vector<SUMOVehicleParameter::Stop>());
322  newRoute->setCosts(cost);
323  newRoute->setSavings(savings);
324  if (!MSRoute::dictionary(id, newRoute)) {
325  delete newRoute;
326  return false;
327  }
328 
329  std::string msg;
330  if (check && !hasValidRoute(msg, newRoute)) {
331  WRITE_WARNING("Invalid route replacement for vehicle '" + getID() + "'. " + msg);
333  newRoute->addReference();
334  newRoute->release();
335  return false;
336  }
337  }
338  if (!replaceRoute(newRoute, info, onInit, (int)edges.size() - oldSize, false, removeStops)) {
339  newRoute->addReference();
340  newRoute->release();
341  return false;
342  }
343  return true;
344 }
345 
346 
347 double
349  return 0;
350 }
351 
352 
353 double
355  return 0;
356 }
357 
358 
359 void
364 }
365 
366 
367 bool
369  return myDeparture != NOT_YET_DEPARTED;
370 }
371 
372 
373 bool
375  return succEdge(1) == nullptr;
376 }
377 
378 void
380  if (myPersonDevice == nullptr) {
382  myMoveReminders.push_back(std::make_pair(myPersonDevice, 0.));
385  }
386  }
388 }
389 
390 void
392  if (myContainerDevice == nullptr) {
394  myMoveReminders.push_back(std::make_pair(myContainerDevice, 0.));
397  }
398  }
400 }
401 
402 bool
403 MSBaseVehicle::hasValidRoute(std::string& msg, const MSRoute* route) const {
404  MSRouteIterator start = myCurrEdge;
405  if (route == nullptr) {
406  route = myRoute;
407  } else {
408  start = route->begin();
409  }
410  MSRouteIterator last = route->end() - 1;
411  // check connectivity, first
412  for (MSRouteIterator e = start; e != last; ++e) {
413  if ((*e)->allowedLanes(**(e + 1), myType->getVehicleClass()) == nullptr) {
414  msg = "No connection between edge '" + (*e)->getID() + "' and edge '" + (*(e + 1))->getID() + "'.";
415  return false;
416  }
417  }
418  last = route->end();
419  // check usable lanes, then
420  for (MSRouteIterator e = start; e != last; ++e) {
421  if ((*e)->prohibits(this)) {
422  msg = "Edge '" + (*e)->getID() + "' prohibits.";
423  return false;
424  }
425  }
426  return true;
427 }
428 
429 
430 void
432 #ifdef _DEBUG
433  if (myTraceMoveReminders) {
434  traceMoveReminder("add", rem, 0, true);
435  }
436 #endif
437  myMoveReminders.push_back(std::make_pair(rem, 0.));
438 }
439 
440 
441 void
443  for (MoveReminderCont::iterator r = myMoveReminders.begin(); r != myMoveReminders.end(); ++r) {
444  if (r->first == rem) {
445 #ifdef _DEBUG
446  if (myTraceMoveReminders) {
447  traceMoveReminder("remove", rem, 0, false);
448  }
449 #endif
450  myMoveReminders.erase(r);
451  return;
452  }
453  }
454 }
455 
456 
457 void
459  for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
460  if (rem->first->notifyEnter(*this, reason, enteredLane)) {
461 #ifdef _DEBUG
462  if (myTraceMoveReminders) {
463  traceMoveReminder("notifyEnter", rem->first, rem->second, true);
464  }
465 #endif
466  ++rem;
467  } else {
468 #ifdef _DEBUG
469  if (myTraceMoveReminders) {
470  traceMoveReminder("notifyEnter", rem->first, rem->second, false);
471  }
472 #endif
473  rem = myMoveReminders.erase(rem);
474  }
475  }
476 }
477 
478 
479 void
481  if (myRoute->getLastEdge()->isTazConnector()) {
482  return;
483  }
484  const std::vector<MSLane*>& lanes = myRoute->getLastEdge()->getLanes();
485  const double lastLaneLength = lanes[0]->getLength();
486  switch (myParameter->arrivalPosProcedure) {
487  case ARRIVAL_POS_GIVEN:
488  if (fabs(myParameter->arrivalPos) > lastLaneLength) {
489  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive at the given position!");
490  }
491  // Maybe we should warn the user about invalid inputs!
492  myArrivalPos = MIN2(myParameter->arrivalPos, lastLaneLength);
493  if (myArrivalPos < 0) {
494  myArrivalPos = MAX2(myArrivalPos + lastLaneLength, 0.);
495  }
496  break;
497  case ARRIVAL_POS_RANDOM:
498  myArrivalPos = RandHelper::rand(lastLaneLength);
499  break;
500  case ARRIVAL_POS_CENTER:
501  myArrivalPos = lastLaneLength / 2.;
502  break;
503  default:
504  myArrivalPos = lastLaneLength;
505  break;
506  }
508  if (myParameter->arrivalLane >= (int)lanes.size() || !lanes[myParameter->arrivalLane]->allowsVehicleClass(myType->getVehicleClass())) {
509  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive at the given lane '" + myRoute->getLastEdge()->getID() + "_" + toString(myParameter->arrivalLane) + "'!");
510  }
511  myArrivalLane = MIN2(myParameter->arrivalLane, (int)(lanes.size() - 1));
512  }
514  for (std::vector<MSLane*>::const_iterator l = lanes.begin(); l != lanes.end(); ++l) {
515  if (myParameter->arrivalSpeed <= (*l)->getVehicleMaxSpeed(this)) {
516  return;
517  }
518  }
519  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive with the given speed!");
520  }
521 }
522 
523 
524 double
526  return MAX2(0., MIN2(1., getVehicleType().getImpatience() +
528 }
529 
530 
532 MSBaseVehicle::getDevice(const std::type_info& type) const {
533  for (MSVehicleDevice* const dev : myDevices) {
534  if (typeid(*dev) == type) {
535  return dev;
536  }
537  }
538  return nullptr;
539 }
540 
541 
542 void
544  // this saves lots of departParameters which are only needed for vehicles that did not yet depart
545  // the parameters may hold the name of a vTypeDistribution but we are interested in the actual type
547  // params and stops must be written in child classes since they may wish to add additional attributes first
551  out.writeAttr(SUMO_ATTR_REROUTE, true);
552  }
553  // here starts the vehicle internal part (see loading)
554  // @note: remember to close the vehicle tag when calling this in a subclass!
555 }
556 
557 
558 void
559 MSBaseVehicle::addStops(const bool ignoreStopErrors) {
560  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator i = myRoute->getStops().begin(); i != myRoute->getStops().end(); ++i) {
561  std::string errorMsg;
562  if (!addStop(*i, errorMsg, myParameter->depart) && !ignoreStopErrors) {
563  throw ProcessError(errorMsg);
564  }
565  if (errorMsg != "") {
566  WRITE_WARNING(errorMsg);
567  }
568  }
570  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator i = myParameter->stops.begin(); i != myParameter->stops.end(); ++i) {
571  std::string errorMsg;
572  if (!addStop(*i, errorMsg, untilOffset) && !ignoreStopErrors) {
573  throw ProcessError(errorMsg);
574  }
575  if (errorMsg != "") {
576  WRITE_WARNING(errorMsg);
577  }
578  }
579 }
580 
581 
582 int
584  int boarded = myPersonDevice == nullptr ? 0 : myPersonDevice->size();
585  return boarded + myParameter->personNumber;
586 }
587 
588 std::vector<std::string>
590  std::vector<std::string> ret;
591  const std::vector<MSTransportable*>& persons = getPersons();
592  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
593  ret.push_back((*it_p)->getID());
594  }
595  return ret;
596 }
597 
598 int
600  int loaded = myContainerDevice == nullptr ? 0 : myContainerDevice->size();
601  return loaded + myParameter->containerNumber;
602 }
603 
604 
605 void
607  // this might be called from the MSTransportable destructor so we cannot do a dynamic cast to determine the type
608  if (myPersonDevice != nullptr) {
610  }
611  if (myContainerDevice != nullptr) {
613  }
614 }
615 
616 
617 const std::vector<MSTransportable*>&
619  if (myPersonDevice == nullptr) {
621  } else {
623  }
624 }
625 
626 
627 const std::vector<MSTransportable*>&
629  if (myContainerDevice == nullptr) {
631  } else {
633  }
634 }
635 
636 
637 
638 bool
639 MSBaseVehicle::hasDevice(const std::string& deviceName) const {
640  for (MSDevice* const dev : myDevices) {
641  if (dev->deviceName() == deviceName) {
642  return true;
643  }
644  }
645  return false;
646 }
647 
648 
649 void
650 MSBaseVehicle::createDevice(const std::string& deviceName) {
651  if (!hasDevice(deviceName)) {
652  if (deviceName == "rerouting") {
653  ((SUMOVehicleParameter*)myParameter)->setParameter("has." + deviceName + ".device", "true");
655  if (hasDeparted()) {
656  // vehicle already departed: disable pre-insertion rerouting and enable regular routing behavior
657  MSDevice_Routing* routingDevice = static_cast<MSDevice_Routing*>(getDevice(typeid(MSDevice_Routing)));
658  assert(routingDevice != 0);
659  routingDevice->notifyEnter(*this, MSMoveReminder::NOTIFICATION_DEPARTED);
660  }
661  } else {
662  throw InvalidArgument("Creating device of type '" + deviceName + "' is not supported");
663  }
664  }
665 }
666 
667 
668 std::string
669 MSBaseVehicle::getDeviceParameter(const std::string& deviceName, const std::string& key) const {
670  for (MSVehicleDevice* const dev : myDevices) {
671  if (dev->deviceName() == deviceName) {
672  return dev->getParameter(key);
673  }
674  }
675  throw InvalidArgument("No device of type '" + deviceName + "' exists");
676 }
677 
678 
679 void
680 MSBaseVehicle::setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value) {
681  for (MSVehicleDevice* const dev : myDevices) {
682  if (dev->deviceName() == deviceName) {
683  dev->setParameter(key, value);
684  return;
685  }
686  }
687  throw InvalidArgument("No device of type '" + deviceName + "' exists");
688 }
689 
690 
691 void
693  assert(type != nullptr);
694  if (myType->isVehicleSpecific() && type != myType) {
696  }
697  myType = type;
698 }
699 
700 
703  if (myType->isVehicleSpecific()) {
704  return *myType;
705  }
706  MSVehicleType* type = myType->buildSingularType(myType->getID() + "@" + getID());
707  replaceVehicleType(type);
708  return *type;
709 }
710 
711 std::mt19937*
713  const MSLane* lane = getLane();
714  if (lane == nullptr) {
715  return getEdge()->getLanes()[0]->getRNG();
716  } else {
717  return lane->getRNG();
718  }
719 }
720 
721 #ifdef _DEBUG
722 void
723 MSBaseVehicle::initMoveReminderOutput(const OptionsCont& oc) {
724  if (oc.isSet("movereminder-output.vehicles")) {
725  const std::vector<std::string> vehicles = oc.getStringVector("movereminder-output.vehicles");
726  myShallTraceMoveReminders.insert(vehicles.begin(), vehicles.end());
727  }
728 }
729 
730 
731 void
732 MSBaseVehicle::traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const {
733  OutputDevice& od = OutputDevice::getDeviceByOption("movereminder-output");
734  od.openTag("movereminder");
735  od.writeAttr(SUMO_ATTR_TIME, STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()));
736  od.writeAttr("veh", getID());
738  od.writeAttr("type", type);
739  od.writeAttr("pos", toString(pos));
740  od.writeAttr("keep", toString(keep));
741  od.closeTag();
742 }
743 #endif
744 
745 /****************************************************************************/
746 
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
The departure is person triggered.
virtual bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, bool collision=false, ConstMSEdgeVector::const_iterator *searchStart=0)=0
Adds a stop.
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
const std::vector< MSTransportable * > & getTransportables() const
Returns the list of transportables using this vehicle.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
int getContainerNumber() const
Returns the number of containers.
void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false)
Performs a rerouting using the given router.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice.cpp:94
long long int SUMOTime
Definition: SUMOTime.h:35
const int VEHPARS_FORCE_REROUTE
int size() const
Return the number of passengers / containers.
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
MoveReminderCont myMoveReminders
Currently relevant move reminders.
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:121
void replaceParameter(const SUMOVehicleParameter *newParameter)
replace the vehicle parameter (deleting the old one)
bool hasDeparted() const
Returns whether this vehicle has already departed.
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:101
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
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.
The speed is given.
std::mt19937 * getRNG() const
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:60
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
double myArrivalPos
The position on the destination lane where the vehicle stops.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
Notification
Definition of a vehicle state.
A device that performs vehicle rerouting based on current edge speeds.
int repetitionsDone
The number of times the vehicle was already inserted.
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:366
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
Definition: MSEdge.cpp:398
virtual bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)=0
Replaces the current route by the given one.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:165
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
T MAX2(T a, T b)
Definition: StdDefs.h:80
virtual ~MSBaseVehicle()
Destructor.
MSBaseVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
const MSRoute * myRoute
This vehicle&#39;s route.
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:804
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:88
virtual const ConstMSEdgeVector getStopEdges(double &firstPos, double &lastPos) const =0
Returns the list of still pending stop edges.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle&#39;s end speed shall be chosen.
int myArrivalLane
The destination lane where the vehicle stops.
#define DEBUG_COND
const SUMOVehicleParameter * myParameter
This vehicle&#39;s parameter.
const std::string & getID() const
Returns the id.
Definition: Named.h:77
The arrival position is given.
void setCosts(double costs)
Sets the costs of the route.
Definition: MSRoute.h:176
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:82
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
The car-following model and parameter.
Definition: MSVehicleType.h:66
virtual void saveState(OutputDevice &out)
Saves the (common) state of a vehicle.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
#define SIMTIME
Definition: SUMOTime.h:64
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...
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
double getMaxSpeed() const
Returns the maximum speed.
void calculateArrivalParams()
(Re-)Calculates the arrival position and lane from the vehicle parameters
std::mt19937 * getRNG() const
return the associated RNG
Definition: MSLane.h:223
A road/street connecting two junctions.
Definition: MSEdge.h:76
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static SUMOTime gTimeToImpatience
Definition: MSGlobals.h:66
virtual void addPerson(MSTransportable *person)
Adds a person to this vehicle.
Half the road length.
virtual const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
double myDepartPos
The real depart position.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
void createDevice(const std::string &deviceName)
create device of the given type
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
std::string routeid
The vehicle&#39;s route id.
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 bool gCheckRoutes
Definition: MSGlobals.h:79
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
double recomputeCosts(const std::vector< const E *> &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:204
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:58
void removeVType(const MSVehicleType *vehType)
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:284
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
void write(OutputDevice &dev, const OptionsCont &oc, const SumoXMLTag tag=SUMO_TAG_VEHICLE, const std::string &typeID="") const
Writes the parameters as a beginning element.
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
T MIN2(T a, T b)
Definition: StdDefs.h:74
std::string fromTaz
The vehicle&#39;s origin zone (district)
double getImpatience() const
Returns this vehicles impatience.
void addTransportable(MSTransportable *transportable)
Add a passenger.
Something on a lane to be noticed about vehicle movement.
bool computeLooped(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into, bool silent=false)
Builds the route between the given edges using the minimum effort at the given time if from == to...
int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons) ...
std::vector< std::string > getPersonIDList() const
Returns the list of persons.
double arrivalPos
(optional) The position the vehicle shall arrive on
std::vector< std::string > via
List of the via-edges the vehicle must visit.
Abstract in-vehicle / in-person device.
Definition: MSDevice.h:64
entry for an alternative parking zone
trigger: the time of the step
SUMOVehicleClass getVClass() const
Returns the vehicle&#39;s access class.
The vehicle has departed (was inserted into the network)
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
int getPersonNumber() const
Returns the number of persons.
void setSavings(double savings)
Sets the savings of the route.
Definition: MSRoute.h:183
Structure representing possible vehicle parameter.
#define SUMOTime_MAX
Definition: SUMOTime.h:36
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
bool isTazConnector() const
Definition: MSEdge.h:256
virtual bool hasArrived() const
Returns whether this vehicle has already arived (by default this is true if the vehicle has reached i...
virtual double getAcceleration() const
Returns the vehicle&#39;s acceleration.
const std::string & getDescription() const
void removeTransportable(MSTransportable *t)
removes a person or container
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:390
MSVehicleType * myType
This vehicle&#39;s type.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
static std::vector< MSTransportable * > myEmptyTransportableVector
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
void onDepart()
Called when the vehicle is inserted into the network.
virtual double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
A storage for options typed value containers)
Definition: OptionsCont.h:90
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
The arrival lane is given.
int containerNumber
The static number of containers in the vehicle when it departs.
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:95
Abstract in-vehicle device.
int myNumberReroutes
The number of reroutings.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
const NumericalID myNumericalID
bool wasSet(int what) const
Returns whether the given parameter was set.
description of a vehicle
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
MSRouteIterator myCurrEdge
Iterator to current route-edge.
MSDevice_Transportable * myContainerDevice
The containers this vehicle may have.
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:70
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle&#39;s departure.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
long long int NumericalID
Definition: SUMOVehicle.h:63
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
void removeTransportable(MSTransportable *transportable)
Remove a passenger (TraCI)
const std::string & getID() const
Returns the name of the vehicle.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
virtual void addContainer(MSTransportable *container)
Adds a container to this vehicle.
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:186
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:375
static MSDevice_Transportable * buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into, const bool isContainer)
Build devices for the given vehicle, if needed.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:76
void descheduleDeparture(const SUMOVehicle *veh)
stops trying to emit the given vehicle (and delete it)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
double getPreviousSpeed() const
Returns the vehicle&#39;s previous speed.
SUMOTime myDeparture
The real departure time.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
static const SUMOTime NOT_YET_DEPARTED
std::string id
The vehicle&#39;s id.
virtual SUMOTime getWaitingTime() const =0
static NumericalID myCurrentNumericalIndex
double myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:114
The arrival position is chosen randomly.