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-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 /****************************************************************************/
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 // ===========================================================================
48 // static members
49 // ===========================================================================
51 std::vector<MSTransportable*> MSBaseVehicle::myEmptyTransportableVector;
52 #ifdef _DEBUG
53 std::set<std::string> MSBaseVehicle::myShallTraceMoveReminders;
54 #endif
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 
60 double
62  throw ProcessError("getPreviousSpeed() is not available for non-MSVehicles.");
63 }
64 
65 
67  MSVehicleType* type, const double speedFactor) :
68  myParameter(pars),
69  myRoute(route),
70  myType(type),
71  myCurrEdge(route->begin()),
72  myChosenSpeedFactor(speedFactor),
73  myMoveReminders(0),
74  myPersonDevice(0),
77  myDepartPos(-1),
78  myArrivalPos(-1),
79  myArrivalLane(-1),
81 #ifdef _DEBUG
82  , myTraceMoveReminders(myShallTraceMoveReminders.count(pars->id) > 0)
83 #endif
84 {
85  if ((*myRoute->begin())->isTazConnector() || myRoute->getLastEdge()->isTazConnector()) {
87  }
88  // init devices
90  //
91  for (std::vector< MSDevice* >::iterator dev = myDevices.begin(); dev != myDevices.end(); ++dev) {
92  myMoveReminders.push_back(std::make_pair(*dev, 0.));
93  }
95  if (!pars->wasSet(VEHPARS_FORCE_REROUTE)) {
98  std::string msg;
99  if (!hasValidRoute(msg)) {
100  throw ProcessError("Vehicle '" + pars->id + "' has no valid route. " + msg);
101  }
102  }
103  }
104 }
105 
106 
108  myRoute->release();
109  if (myParameter->repetitionNumber == 0) {
111  }
112  for (std::vector< MSDevice* >::iterator dev = myDevices.begin(); dev != myDevices.end(); ++dev) {
113  delete *dev;
114  }
115  delete myParameter;
116 }
117 
118 
119 const std::string&
121  return myParameter->id;
122 }
123 
124 
127  return *myParameter;
128 }
129 
130 void
132  delete myParameter;
133  myParameter = newParameter;
134 }
135 
136 double
138  return myType->getMaxSpeed();
139 }
140 
141 
142 const MSEdge*
143 MSBaseVehicle::succEdge(int nSuccs) const {
144  if (myCurrEdge + nSuccs < myRoute->end() && std::distance(myCurrEdge, myRoute->begin()) <= nSuccs) {
145  return *(myCurrEdge + nSuccs);
146  } else {
147  return 0;
148  }
149 }
150 
151 
152 const MSEdge*
154  return *myCurrEdge;
155 }
156 
157 
158 void
159 MSBaseVehicle::reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit, const bool withTaz) {
160  // check whether to reroute
161  const MSEdge* source = withTaz && onInit ? MSEdge::dictionary(myParameter->fromTaz + "-source") : getRerouteOrigin();
162  if (source == 0) {
163  source = getRerouteOrigin();
164  }
165  const MSEdge* sink = withTaz ? MSEdge::dictionary(myParameter->toTaz + "-sink") : myRoute->getLastEdge();
166  if (sink == 0) {
167  sink = myRoute->getLastEdge();
168  }
169  ConstMSEdgeVector edges;
170  ConstMSEdgeVector stops;
171  if (myParameter->via.size() == 0) {
172  stops = getStopEdges();
173  } else {
174  // via takes precedence over stop edges
175  // XXX check for inconsistencies #2275
176  for (std::vector<std::string>::const_iterator it = myParameter->via.begin(); it != myParameter->via.end(); ++it) {
177  MSEdge* viaEdge = MSEdge::dictionary(*it);
178  assert(viaEdge != 0);
179  if (viaEdge->allowedLanes(getVClass()) == 0) {
180  throw ProcessError("Vehicle '" + getID() + "' is not allowed on any lane of via edge '" + viaEdge->getID() + "'.");
181  }
182  stops.push_back(viaEdge);
183  }
184  }
185 
186  for (MSRouteIterator s = stops.begin(); s != stops.end(); ++s) {
187  if (*s != source) {
188  // !!! need to adapt t here
189  ConstMSEdgeVector into;
190  router.compute(source, *s, this, t, into);
191  if (into.size() > 0) {
192  into.pop_back();
193  edges.insert(edges.end(), into.begin(), into.end());
194  } else {
195  std::string error = "Vehicle '" + getID() + "' has no valid route from edge '" + source->getID() + "' to stop edge '" + (*s)->getID() + "'.";
197  throw ProcessError(error);
198  } else {
199  WRITE_WARNING(error);
200  edges.push_back(source);
201  }
202  }
203  source = *s;
204  }
205  }
206  router.compute(source, sink, this, t, edges);
207  if (!edges.empty() && edges.front()->isTazConnector()) {
208  edges.erase(edges.begin());
209  }
210  if (!edges.empty() && edges.back()->isTazConnector()) {
211  edges.pop_back();
212  }
213  replaceRouteEdges(edges, info, onInit);
214  const double routeCost = router.recomputeCosts(edges, this, t);
215  const_cast<MSRoute*>(myRoute)->setCosts(routeCost);
216  // this must be called even if the route could not be replaced
217  if (onInit) {
218  if (edges.empty()) {
220  throw ProcessError("Vehicle '" + getID() + "' has no valid route.");
221  } else if (source->isTazConnector()) {
222  WRITE_WARNING("Removing vehicle '" + getID() + "' which has no valid route.");
224  return;
225  }
226  }
228  }
229 }
230 
231 
232 bool
233 MSBaseVehicle::replaceRouteEdges(ConstMSEdgeVector& edges, const std::string& info, bool onInit, bool check, bool removeStops) {
234  if (edges.empty()) {
235  WRITE_WARNING("No route for vehicle '" + getID() + "' found.");
236  return false;
237  }
238  // build a new id, first
239  std::string id = getID();
240  if (id[0] != '!') {
241  id = "!" + id;
242  }
243  if (myRoute->getID().find("!var#") != std::string::npos) {
244  id = myRoute->getID().substr(0, myRoute->getID().rfind("!var#") + 5) + toString(getNumberReroutes() + 1);
245  } else {
246  id = id + "!var#1";
247  }
248  int oldSize = (int)edges.size();
249  if (!onInit) {
250  const MSEdge* const origin = getRerouteOrigin();
251  if (origin != *myCurrEdge && edges.front() == origin) {
252  edges.insert(edges.begin(), *myCurrEdge);
253  oldSize = (int)edges.size();
254  }
255  edges.insert(edges.begin(), myRoute->begin(), myCurrEdge);
256  }
257  if (edges == myRoute->getEdges()) {
258  return true;
259  }
260  const RGBColor& c = myRoute->getColor();
261  MSRoute* newRoute = new MSRoute(id, edges, false, &c == &RGBColor::DEFAULT_COLOR ? 0 : new RGBColor(c), std::vector<SUMOVehicleParameter::Stop>());
262  if (!MSRoute::dictionary(id, newRoute)) {
263  delete newRoute;
264  return false;
265  }
266 
267  std::string msg;
268  if (check && !hasValidRoute(msg, newRoute)) {
269  WRITE_WARNING("Invalid route replacement for vehicle '" + getID() + "'. " + msg);
271  newRoute->addReference();
272  newRoute->release();
273  return false;
274  }
275  }
276  if (!replaceRoute(newRoute, info, onInit, (int)edges.size() - oldSize, false, removeStops)) {
277  newRoute->addReference();
278  newRoute->release();
279  return false;
280  }
281  return true;
282 }
283 
284 
285 double
287  return 0;
288 }
289 
290 
291 double
293  return 0;
294 }
295 
296 
297 void
302 }
303 
304 
305 bool
307  return myDeparture != NOT_YET_DEPARTED;
308 }
309 
310 
311 bool
313  return succEdge(1) == 0;
314 }
315 
316 void
318  if (myPersonDevice == 0) {
320  myMoveReminders.push_back(std::make_pair(myPersonDevice, 0.));
323  }
324  }
326 }
327 
328 void
330  if (myContainerDevice == 0) {
332  myMoveReminders.push_back(std::make_pair(myContainerDevice, 0.));
335  }
336  }
338 }
339 
340 bool
341 MSBaseVehicle::hasValidRoute(std::string& msg, const MSRoute* route) const {
342  MSRouteIterator start = myCurrEdge;
343  if (route == 0) {
344  route = myRoute;
345  } else {
346  start = route->begin();
347  }
348  MSRouteIterator last = route->end() - 1;
349  // check connectivity, first
350  for (MSRouteIterator e = start; e != last; ++e) {
351  if ((*e)->allowedLanes(**(e + 1), myType->getVehicleClass()) == 0) {
352  msg = "No connection between edge '" + (*e)->getID() + "' and edge '" + (*(e + 1))->getID() + "'.";
353  return false;
354  }
355  }
356  last = route->end();
357  // check usable lanes, then
358  for (MSRouteIterator e = start; e != last; ++e) {
359  if ((*e)->prohibits(this)) {
360  msg = "Edge '" + (*e)->getID() + "' prohibits.";
361  return false;
362  }
363  }
364  return true;
365 }
366 
367 
368 void
370 #ifdef _DEBUG
371  if (myTraceMoveReminders) {
372  traceMoveReminder("add", rem, 0, true);
373  }
374 #endif
375  myMoveReminders.push_back(std::make_pair(rem, 0.));
376 }
377 
378 
379 void
381  for (MoveReminderCont::iterator r = myMoveReminders.begin(); r != myMoveReminders.end(); ++r) {
382  if (r->first == rem) {
383 #ifdef _DEBUG
384  if (myTraceMoveReminders) {
385  traceMoveReminder("remove", rem, 0, false);
386  }
387 #endif
388  myMoveReminders.erase(r);
389  return;
390  }
391  }
392 }
393 
394 
395 void
397  for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
398  if (rem->first->notifyEnter(*this, reason, enteredLane)) {
399 #ifdef _DEBUG
400  if (myTraceMoveReminders) {
401  traceMoveReminder("notifyEnter", rem->first, rem->second, true);
402  }
403 #endif
404  ++rem;
405  } else {
406 #ifdef _DEBUG
407  if (myTraceMoveReminders) {
408  traceMoveReminder("notifyEnter", rem->first, rem->second, false);
409  }
410 #endif
411  rem = myMoveReminders.erase(rem);
412  }
413  }
414 }
415 
416 
417 void
419  if (myRoute->getLastEdge()->isTazConnector()) {
420  return;
421  }
422  const std::vector<MSLane*>& lanes = myRoute->getLastEdge()->getLanes();
423  const double lastLaneLength = lanes[0]->getLength();
424  switch (myParameter->arrivalPosProcedure) {
425  case ARRIVAL_POS_GIVEN:
426  if (fabs(myParameter->arrivalPos) > lastLaneLength) {
427  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive at the given position!");
428  }
429  // Maybe we should warn the user about invalid inputs!
430  myArrivalPos = MIN2(myParameter->arrivalPos, lastLaneLength);
431  if (myArrivalPos < 0) {
432  myArrivalPos = MAX2(myArrivalPos + lastLaneLength, 0.);
433  }
434  break;
435  case ARRIVAL_POS_RANDOM:
436  myArrivalPos = RandHelper::rand(lastLaneLength);
437  break;
438  case ARRIVAL_POS_CENTER:
439  myArrivalPos = lastLaneLength / 2.;
440  break;
441  default:
442  myArrivalPos = lastLaneLength;
443  break;
444  }
446  if (myParameter->arrivalLane >= (int)lanes.size() || !lanes[myParameter->arrivalLane]->allowsVehicleClass(myType->getVehicleClass())) {
447  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive at the given lane '" + myRoute->getLastEdge()->getID() + "_" + toString(myParameter->arrivalLane) + "'!");
448  }
449  myArrivalLane = MIN2(myParameter->arrivalLane, (int)(lanes.size() - 1));
450  }
452  for (std::vector<MSLane*>::const_iterator l = lanes.begin(); l != lanes.end(); ++l) {
453  if (myParameter->arrivalSpeed <= (*l)->getVehicleMaxSpeed(this)) {
454  return;
455  }
456  }
457  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive with the given speed!");
458  }
459 }
460 
461 
462 double
464  return MAX2(0., MIN2(1., getVehicleType().getImpatience() +
466 }
467 
468 
469 MSDevice*
470 MSBaseVehicle::getDevice(const std::type_info& type) const {
471  for (std::vector<MSDevice*>::const_iterator dev = myDevices.begin(); dev != myDevices.end(); ++dev) {
472  if (typeid(**dev) == type) {
473  return *dev;
474  }
475  }
476  return 0;
477 }
478 
479 
480 void
482  // this saves lots of departParameters which are only needed for vehicles that did not yet depart
483  // the parameters may hold the name of a vTypeDistribution but we are interested in the actual type
485  // params and stops must be written in child classes since they may wish to add additional attributes first
489  out.writeAttr(SUMO_ATTR_REROUTE, true);
490  }
491  // here starts the vehicle internal part (see loading)
492  // @note: remember to close the vehicle tag when calling this in a subclass!
493 }
494 
495 
496 void
497 MSBaseVehicle::addStops(const bool ignoreStopErrors) {
498  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator i = myRoute->getStops().begin(); i != myRoute->getStops().end(); ++i) {
499  std::string errorMsg;
500  if (!addStop(*i, errorMsg, myParameter->depart) && !ignoreStopErrors) {
501  throw ProcessError(errorMsg);
502  }
503  if (errorMsg != "") {
504  WRITE_WARNING(errorMsg);
505  }
506  }
508  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator i = myParameter->stops.begin(); i != myParameter->stops.end(); ++i) {
509  std::string errorMsg;
510  if (!addStop(*i, errorMsg, untilOffset) && !ignoreStopErrors) {
511  throw ProcessError(errorMsg);
512  }
513  if (errorMsg != "") {
514  WRITE_WARNING(errorMsg);
515  }
516  }
517 }
518 
519 
520 int
522  int boarded = myPersonDevice == 0 ? 0 : myPersonDevice->size();
523  return boarded + myParameter->personNumber;
524 }
525 
526 std::vector<std::string>
528  std::vector<std::string> ret;
529  const std::vector<MSTransportable*>& persons = getPersons();
530  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
531  ret.push_back((*it_p)->getID());
532  }
533  return ret;
534 }
535 
536 int
538  int loaded = myContainerDevice == 0 ? 0 : myContainerDevice->size();
539  return loaded + myParameter->containerNumber;
540 }
541 
542 
543 void
545  const bool isPerson = dynamic_cast<MSPerson*>(t) != 0;
547  if (device != 0) {
548  device->removeTransportable(t);
549  }
550 }
551 
552 
553 const std::vector<MSTransportable*>&
555  if (myPersonDevice == 0) {
557  } else {
559  }
560 }
561 
562 
563 const std::vector<MSTransportable*>&
565  if (myContainerDevice == 0) {
567  } else {
569  }
570 }
571 
572 
573 
574 bool
575 MSBaseVehicle::hasDevice(const std::string& deviceName) const {
576  for (std::vector<MSDevice* >::const_iterator dev = myDevices.begin(); dev != myDevices.end(); ++dev) {
577  if ((*dev)->deviceName() == deviceName) {
578  return true;
579  }
580  }
581  return false;
582 }
583 
584 
585 void
586 MSBaseVehicle::createDevice(const std::string& deviceName) {
587  if (!hasDevice(deviceName)) {
588  if (deviceName == "rerouting") {
589  ((SUMOVehicleParameter*)myParameter)->setParameter("has." + deviceName + ".device", "true");
591  if (hasDeparted()) {
592  // vehicle already departed: disable pre-insertion rerouting and enable regular routing behavior
593  MSDevice_Routing* routingDevice = static_cast<MSDevice_Routing*>(getDevice(typeid(MSDevice_Routing)));
594  assert(routingDevice != 0);
595  routingDevice->notifyEnter(*this, MSMoveReminder::NOTIFICATION_DEPARTED);
596  }
597  } else {
598  throw InvalidArgument("Creating device of type '" + deviceName + "' is not supported");
599  }
600  }
601 }
602 
603 
604 std::string
605 MSBaseVehicle::getDeviceParameter(const std::string& deviceName, const std::string& key) const {
606  for (std::vector<MSDevice* >::const_iterator dev = myDevices.begin(); dev != myDevices.end(); ++dev) {
607  if ((*dev)->deviceName() == deviceName) {
608  return (*dev)->getParameter(key);
609  }
610  }
611  throw InvalidArgument("No device of type '" + deviceName + "' exists");
612 }
613 
614 
615 void
616 MSBaseVehicle::setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value) {
617  for (std::vector<MSDevice* >::iterator dev = myDevices.begin(); dev != myDevices.end(); ++dev) {
618  if ((*dev)->deviceName() == deviceName) {
619  (*dev)->setParameter(key, value);
620  return;
621  }
622  }
623  throw InvalidArgument("No device of type '" + deviceName + "' exists");
624 }
625 
626 
627 void
629  if (myType->isVehicleSpecific()) {
631  }
632  myType = type;
633 }
634 
635 
638  if (myType->isVehicleSpecific()) {
639  return *myType;
640  }
641  MSVehicleType* type = myType->buildSingularType(myType->getID() + "@" + getID());
642  replaceVehicleType(type);
643  return *type;
644 }
645 
646 
647 #ifdef _DEBUG
648 void
649 MSBaseVehicle::initMoveReminderOutput(const OptionsCont& oc) {
650  if (oc.isSet("movereminder-output.vehicles")) {
651  const std::vector<std::string> vehicles = oc.getStringVector("movereminder-output.vehicles");
652  myShallTraceMoveReminders.insert(vehicles.begin(), vehicles.end());
653  }
654 }
655 
656 
657 void
658 MSBaseVehicle::traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const {
659  OutputDevice& od = OutputDevice::getDeviceByOption("movereminder-output");
660  od.openTag("movereminder");
661  od.writeAttr(SUMO_ATTR_TIME, STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()));
662  od.writeAttr("veh", getID());
664  od.writeAttr("type", type);
665  od.writeAttr("pos", toString(pos));
666  od.writeAttr("keep", toString(keep));
667  od.closeTag();
668 }
669 #endif
670 
671 /****************************************************************************/
672 
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.
long long int SUMOTime
Definition: SUMOTime.h:36
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)
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
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:98
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.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
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 bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
static MSDevice_Transportable * buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into, const bool isContainer)
Build devices for the given vehicle, if needed.
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:351
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:290
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:162
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
T MAX2(T a, T b)
Definition: StdDefs.h:68
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:740
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:85
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle&#39;s end speed shall be chosen.
int myArrivalLane
The destination lane where the vehicle stops.
const SUMOVehicleParameter * myParameter
This vehicle&#39;s parameter.
const std::string & getID() const
Returns the id.
Definition: Named.h:69
The arrival position is given.
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:79
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
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
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.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice.cpp:88
bool replaceRouteEdges(ConstMSEdgeVector &edges, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
double getMaxSpeed() const
Returns the maximum speed.
void calculateArrivalParams()
(Re-)Calculates the arrival position and lane from the vehicle parameters
A road/street connecting two junctions.
Definition: MSEdge.h:75
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.
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
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
std::string routeid
The vehicle&#39;s route id.
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...
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:185
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:309
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:58
void removeVType(const MSVehicleType *vehType)
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
SUMOTime depart
The vehicle&#39;s departure time.
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
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:256
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:62
std::string fromTaz
The vehicle&#39;s origin zone (district)
double getImpatience() const
Returns this vehicles impatience.
void addTransportable(MSTransportable *transportable)
Add a passenger.
virtual const ConstMSEdgeVector getStopEdges() const =0
Returns the list of still pending stop edges.
Something on a lane to be noticed about vehicle movement.
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 device.
Definition: MSDevice.h:65
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.
Structure representing possible vehicle parameter.
#define SUMOTime_MAX
Definition: SUMOTime.h:37
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
bool isTazConnector() const
Definition: MSEdge.h:247
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:362
MSVehicleType * myType
This vehicle&#39;s type.
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
static std::vector< MSTransportable * > myEmptyTransportableVector
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:92
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:92
int myNumberReroutes
The number of reroutings.
virtual SUMOTime getWaitingTime() const =0
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
bool wasSet(int what) const
Returns whether the given parameter was set.
description of a vehicle
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
double recomputeCosts(const std::vector< const E *> &edges, const V *const v, SUMOTime msTime) const
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:67
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle&#39;s departure.
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.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
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:71
std::vector< MSDevice * > myDevices
The devices this vehicle has.
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:183
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:360
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:73
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.
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:111
The arrival position is chosen randomly.