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
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 
62 double
64  throw ProcessError("getPreviousSpeed() is not available for non-MSVehicles.");
65 }
66 
67 
69  MSVehicleType* type, const double speedFactor) :
70  myParameter(pars),
71  myRoute(route),
72  myType(type),
73  myCurrEdge(route->begin()),
74  myChosenSpeedFactor(speedFactor),
75  myMoveReminders(0),
76  myPersonDevice(nullptr),
77  myContainerDevice(nullptr),
79  myDepartPos(-1),
80  myArrivalPos(-1),
81  myArrivalLane(-1),
84 #ifdef _DEBUG
85  , myTraceMoveReminders(myShallTraceMoveReminders.count(pars->id) > 0)
86 #endif
87 {
88  if ((*myRoute->begin())->isTazConnector() || myRoute->getLastEdge()->isTazConnector()) {
90  }
91  // init devices
93  //
94  for (MSVehicleDevice* dev : myDevices) {
95  myMoveReminders.push_back(std::make_pair(dev, 0.));
96  }
98  if (!pars->wasSet(VEHPARS_FORCE_REROUTE)) {
101  std::string msg;
102  if (!hasValidRoute(msg)) {
103  throw ProcessError("Vehicle '" + pars->id + "' has no valid route. " + msg);
104  }
105  }
106  }
107 }
108 
109 
111  myRoute->release();
112  if (myParameter->repetitionNumber == 0) {
114  }
115  for (MSVehicleDevice* dev : myDevices) {
116  delete dev;
117  }
118  delete myParameter;
119 }
120 
121 
122 const std::string&
124  return myParameter->id;
125 }
126 
127 
130  return *myParameter;
131 }
132 
133 void
135  delete myParameter;
136  myParameter = newParameter;
137 }
138 
139 double
141  return myType->getMaxSpeed();
142 }
143 
144 
145 const MSEdge*
146 MSBaseVehicle::succEdge(int nSuccs) const {
147  if (myCurrEdge + nSuccs < myRoute->end() && std::distance(myCurrEdge, myRoute->begin()) <= nSuccs) {
148  return *(myCurrEdge + nSuccs);
149  } else {
150  return nullptr;
151  }
152 }
153 
154 
155 const MSEdge*
157  return *myCurrEdge;
158 }
159 
160 
161 void
162 MSBaseVehicle::reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit, const bool withTaz) {
163  // check whether to reroute
164  const MSEdge* source = withTaz && onInit ? MSEdge::dictionary(myParameter->fromTaz + "-source") : getRerouteOrigin();
165  if (source == nullptr) {
166  source = getRerouteOrigin();
167  }
168  const MSEdge* sink = withTaz ? MSEdge::dictionary(myParameter->toTaz + "-sink") : myRoute->getLastEdge();
169  if (sink == nullptr) {
170  sink = myRoute->getLastEdge();
171  }
172  ConstMSEdgeVector oldEdgesRemaining(source == *myCurrEdge ? myCurrEdge : myCurrEdge + 1, myRoute->end());
173  ConstMSEdgeVector edges;
174  ConstMSEdgeVector stops;
175  if (myParameter->via.size() == 0) {
176  stops = getStopEdges();
177  } else {
178  // via takes precedence over stop edges
179  // XXX check for inconsistencies #2275
180  for (std::vector<std::string>::const_iterator it = myParameter->via.begin(); it != myParameter->via.end(); ++it) {
181  MSEdge* viaEdge = MSEdge::dictionary(*it);
182  assert(viaEdge != 0);
183  if (!viaEdge->isTazConnector() && viaEdge->allowedLanes(getVClass()) == nullptr) {
184  throw ProcessError("Vehicle '" + getID() + "' is not allowed on any lane of via edge '" + viaEdge->getID() + "'.");
185  }
186  stops.push_back(viaEdge);
187  }
188  }
189 
190  for (MSRouteIterator s = stops.begin(); s != stops.end(); ++s) {
191  if (*s != source) {
192  // !!! need to adapt t here
193  ConstMSEdgeVector into;
194  router.compute(source, *s, this, t, into);
195  if (into.size() > 0) {
196  into.pop_back();
197  edges.insert(edges.end(), into.begin(), into.end());
198  if ((*s)->isTazConnector()) {
199  source = into.back();
200  edges.pop_back();
201  } else {
202  source = *s;
203  }
204  } else {
205  std::string error = "Vehicle '" + getID() + "' has no valid route from edge '" + source->getID() + "' to stop edge '" + (*s)->getID() + "'.";
207  throw ProcessError(error);
208  } else {
209  WRITE_WARNING(error);
210  edges.push_back(source);
211  }
212  source = *s;
213  }
214  }
215  }
216  router.compute(source, sink, this, t, edges);
217  if (!edges.empty() && edges.front()->isTazConnector()) {
218  edges.erase(edges.begin());
219  }
220  if (!edges.empty() && edges.back()->isTazConnector()) {
221  edges.pop_back();
222  }
223  const double routeCost = router.recomputeCosts(edges, this, t);
224  const double previousCost = onInit ? routeCost : router.recomputeCosts(oldEdgesRemaining, this, t);
225  const double savings = previousCost - routeCost;
226  //if (getID() == "43") std::cout << SIMTIME << " pCost=" << previousCost << " cost=" << routeCost
227  // << " onInit=" << onInit
228  // << " prevEdges=" << toString(oldEdgesRemaining)
229  // << " newEdges=" << toString(edges)
230  // << "\n";
231  replaceRouteEdges(edges, routeCost, savings, info, onInit);
232  // this must be called even if the route could not be replaced
233  if (onInit) {
234  if (edges.empty()) {
236  throw ProcessError("Vehicle '" + getID() + "' has no valid route.");
237  } else if (source->isTazConnector()) {
238  WRITE_WARNING("Removing vehicle '" + getID() + "' which has no valid route.");
240  return;
241  }
242  }
244  }
245 }
246 
247 
248 bool
249 MSBaseVehicle::replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit, bool check, bool removeStops) {
250  if (edges.empty()) {
251  WRITE_WARNING("No route for vehicle '" + getID() + "' found.");
252  return false;
253  }
254  // build a new id, first
255  std::string id = getID();
256  if (id[0] != '!') {
257  id = "!" + id;
258  }
259  if (myRoute->getID().find("!var#") != std::string::npos) {
260  id = myRoute->getID().substr(0, myRoute->getID().rfind("!var#") + 5) + toString(getNumberReroutes() + 1);
261  } else {
262  id = id + "!var#1";
263  }
264  int oldSize = (int)edges.size();
265  if (!onInit) {
266  const MSEdge* const origin = getRerouteOrigin();
267  if (origin != *myCurrEdge && edges.front() == origin) {
268  edges.insert(edges.begin(), *myCurrEdge);
269  oldSize = (int)edges.size();
270  }
271  edges.insert(edges.begin(), myRoute->begin(), myCurrEdge);
272  }
273  if (edges == myRoute->getEdges()) {
274  return true;
275  }
276  const RGBColor& c = myRoute->getColor();
277  MSRoute* newRoute = new MSRoute(id, edges, false, &c == &RGBColor::DEFAULT_COLOR ? nullptr : new RGBColor(c), std::vector<SUMOVehicleParameter::Stop>());
278  newRoute->setCosts(cost);
279  newRoute->setSavings(savings);
280  if (!MSRoute::dictionary(id, newRoute)) {
281  delete newRoute;
282  return false;
283  }
284 
285  std::string msg;
286  if (check && !hasValidRoute(msg, newRoute)) {
287  WRITE_WARNING("Invalid route replacement for vehicle '" + getID() + "'. " + msg);
289  newRoute->addReference();
290  newRoute->release();
291  return false;
292  }
293  }
294  if (!replaceRoute(newRoute, info, onInit, (int)edges.size() - oldSize, false, removeStops)) {
295  newRoute->addReference();
296  newRoute->release();
297  return false;
298  }
299  return true;
300 }
301 
302 
303 double
305  return 0;
306 }
307 
308 
309 double
311  return 0;
312 }
313 
314 
315 void
320 }
321 
322 
323 bool
325  return myDeparture != NOT_YET_DEPARTED;
326 }
327 
328 
329 bool
331  return succEdge(1) == nullptr;
332 }
333 
334 void
336  if (myPersonDevice == nullptr) {
338  myMoveReminders.push_back(std::make_pair(myPersonDevice, 0.));
341  }
342  }
344 }
345 
346 void
348  if (myContainerDevice == nullptr) {
350  myMoveReminders.push_back(std::make_pair(myContainerDevice, 0.));
353  }
354  }
356 }
357 
358 bool
359 MSBaseVehicle::hasValidRoute(std::string& msg, const MSRoute* route) const {
360  MSRouteIterator start = myCurrEdge;
361  if (route == nullptr) {
362  route = myRoute;
363  } else {
364  start = route->begin();
365  }
366  MSRouteIterator last = route->end() - 1;
367  // check connectivity, first
368  for (MSRouteIterator e = start; e != last; ++e) {
369  if ((*e)->allowedLanes(**(e + 1), myType->getVehicleClass()) == nullptr) {
370  msg = "No connection between edge '" + (*e)->getID() + "' and edge '" + (*(e + 1))->getID() + "'.";
371  return false;
372  }
373  }
374  last = route->end();
375  // check usable lanes, then
376  for (MSRouteIterator e = start; e != last; ++e) {
377  if ((*e)->prohibits(this)) {
378  msg = "Edge '" + (*e)->getID() + "' prohibits.";
379  return false;
380  }
381  }
382  return true;
383 }
384 
385 
386 void
388 #ifdef _DEBUG
389  if (myTraceMoveReminders) {
390  traceMoveReminder("add", rem, 0, true);
391  }
392 #endif
393  myMoveReminders.push_back(std::make_pair(rem, 0.));
394 }
395 
396 
397 void
399  for (MoveReminderCont::iterator r = myMoveReminders.begin(); r != myMoveReminders.end(); ++r) {
400  if (r->first == rem) {
401 #ifdef _DEBUG
402  if (myTraceMoveReminders) {
403  traceMoveReminder("remove", rem, 0, false);
404  }
405 #endif
406  myMoveReminders.erase(r);
407  return;
408  }
409  }
410 }
411 
412 
413 void
415  for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
416  if (rem->first->notifyEnter(*this, reason, enteredLane)) {
417 #ifdef _DEBUG
418  if (myTraceMoveReminders) {
419  traceMoveReminder("notifyEnter", rem->first, rem->second, true);
420  }
421 #endif
422  ++rem;
423  } else {
424 #ifdef _DEBUG
425  if (myTraceMoveReminders) {
426  traceMoveReminder("notifyEnter", rem->first, rem->second, false);
427  }
428 #endif
429  rem = myMoveReminders.erase(rem);
430  }
431  }
432 }
433 
434 
435 void
437  if (myRoute->getLastEdge()->isTazConnector()) {
438  return;
439  }
440  const std::vector<MSLane*>& lanes = myRoute->getLastEdge()->getLanes();
441  const double lastLaneLength = lanes[0]->getLength();
442  switch (myParameter->arrivalPosProcedure) {
443  case ARRIVAL_POS_GIVEN:
444  if (fabs(myParameter->arrivalPos) > lastLaneLength) {
445  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive at the given position!");
446  }
447  // Maybe we should warn the user about invalid inputs!
448  myArrivalPos = MIN2(myParameter->arrivalPos, lastLaneLength);
449  if (myArrivalPos < 0) {
450  myArrivalPos = MAX2(myArrivalPos + lastLaneLength, 0.);
451  }
452  break;
453  case ARRIVAL_POS_RANDOM:
454  myArrivalPos = RandHelper::rand(lastLaneLength);
455  break;
456  case ARRIVAL_POS_CENTER:
457  myArrivalPos = lastLaneLength / 2.;
458  break;
459  default:
460  myArrivalPos = lastLaneLength;
461  break;
462  }
464  if (myParameter->arrivalLane >= (int)lanes.size() || !lanes[myParameter->arrivalLane]->allowsVehicleClass(myType->getVehicleClass())) {
465  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive at the given lane '" + myRoute->getLastEdge()->getID() + "_" + toString(myParameter->arrivalLane) + "'!");
466  }
467  myArrivalLane = MIN2(myParameter->arrivalLane, (int)(lanes.size() - 1));
468  }
470  for (std::vector<MSLane*>::const_iterator l = lanes.begin(); l != lanes.end(); ++l) {
471  if (myParameter->arrivalSpeed <= (*l)->getVehicleMaxSpeed(this)) {
472  return;
473  }
474  }
475  WRITE_WARNING("Vehicle '" + getID() + "' will not be able to arrive with the given speed!");
476  }
477 }
478 
479 
480 double
482  return MAX2(0., MIN2(1., getVehicleType().getImpatience() +
484 }
485 
486 
488 MSBaseVehicle::getDevice(const std::type_info& type) const {
489  for (MSVehicleDevice* const dev : myDevices) {
490  if (typeid(*dev) == type) {
491  return dev;
492  }
493  }
494  return nullptr;
495 }
496 
497 
498 void
500  // this saves lots of departParameters which are only needed for vehicles that did not yet depart
501  // the parameters may hold the name of a vTypeDistribution but we are interested in the actual type
503  // params and stops must be written in child classes since they may wish to add additional attributes first
507  out.writeAttr(SUMO_ATTR_REROUTE, true);
508  }
509  // here starts the vehicle internal part (see loading)
510  // @note: remember to close the vehicle tag when calling this in a subclass!
511 }
512 
513 
514 void
515 MSBaseVehicle::addStops(const bool ignoreStopErrors) {
516  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator i = myRoute->getStops().begin(); i != myRoute->getStops().end(); ++i) {
517  std::string errorMsg;
518  if (!addStop(*i, errorMsg, myParameter->depart) && !ignoreStopErrors) {
519  throw ProcessError(errorMsg);
520  }
521  if (errorMsg != "") {
522  WRITE_WARNING(errorMsg);
523  }
524  }
526  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator i = myParameter->stops.begin(); i != myParameter->stops.end(); ++i) {
527  std::string errorMsg;
528  if (!addStop(*i, errorMsg, untilOffset) && !ignoreStopErrors) {
529  throw ProcessError(errorMsg);
530  }
531  if (errorMsg != "") {
532  WRITE_WARNING(errorMsg);
533  }
534  }
535 }
536 
537 
538 int
540  int boarded = myPersonDevice == nullptr ? 0 : myPersonDevice->size();
541  return boarded + myParameter->personNumber;
542 }
543 
544 std::vector<std::string>
546  std::vector<std::string> ret;
547  const std::vector<MSTransportable*>& persons = getPersons();
548  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
549  ret.push_back((*it_p)->getID());
550  }
551  return ret;
552 }
553 
554 int
556  int loaded = myContainerDevice == nullptr ? 0 : myContainerDevice->size();
557  return loaded + myParameter->containerNumber;
558 }
559 
560 
561 void
563  const bool isPerson = dynamic_cast<MSPerson*>(t) != nullptr;
565  if (device != nullptr) {
566  device->removeTransportable(t);
567  }
568 }
569 
570 
571 const std::vector<MSTransportable*>&
573  if (myPersonDevice == nullptr) {
575  } else {
577  }
578 }
579 
580 
581 const std::vector<MSTransportable*>&
583  if (myContainerDevice == nullptr) {
585  } else {
587  }
588 }
589 
590 
591 
592 bool
593 MSBaseVehicle::hasDevice(const std::string& deviceName) const {
594  for (MSDevice* const dev : myDevices) {
595  if (dev->deviceName() == deviceName) {
596  return true;
597  }
598  }
599  return false;
600 }
601 
602 
603 void
604 MSBaseVehicle::createDevice(const std::string& deviceName) {
605  if (!hasDevice(deviceName)) {
606  if (deviceName == "rerouting") {
607  ((SUMOVehicleParameter*)myParameter)->setParameter("has." + deviceName + ".device", "true");
609  if (hasDeparted()) {
610  // vehicle already departed: disable pre-insertion rerouting and enable regular routing behavior
611  MSDevice_Routing* routingDevice = static_cast<MSDevice_Routing*>(getDevice(typeid(MSDevice_Routing)));
612  assert(routingDevice != 0);
613  routingDevice->notifyEnter(*this, MSMoveReminder::NOTIFICATION_DEPARTED);
614  }
615  } else {
616  throw InvalidArgument("Creating device of type '" + deviceName + "' is not supported");
617  }
618  }
619 }
620 
621 
622 std::string
623 MSBaseVehicle::getDeviceParameter(const std::string& deviceName, const std::string& key) const {
624  for (MSVehicleDevice* const dev : myDevices) {
625  if (dev->deviceName() == deviceName) {
626  return dev->getParameter(key);
627  }
628  }
629  throw InvalidArgument("No device of type '" + deviceName + "' exists");
630 }
631 
632 
633 void
634 MSBaseVehicle::setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value) {
635  for (MSVehicleDevice* const dev : myDevices) {
636  if (dev->deviceName() == deviceName) {
637  dev->setParameter(key, value);
638  return;
639  }
640  }
641  throw InvalidArgument("No device of type '" + deviceName + "' exists");
642 }
643 
644 
645 void
647  assert(type != nullptr);
648  if (myType->isVehicleSpecific() && type != myType) {
650  }
651  myType = type;
652 }
653 
654 
657  if (myType->isVehicleSpecific()) {
658  return *myType;
659  }
660  MSVehicleType* type = myType->buildSingularType(myType->getID() + "@" + getID());
661  replaceVehicleType(type);
662  return *type;
663 }
664 
665 
666 #ifdef _DEBUG
667 void
668 MSBaseVehicle::initMoveReminderOutput(const OptionsCont& oc) {
669  if (oc.isSet("movereminder-output.vehicles")) {
670  const std::vector<std::string> vehicles = oc.getStringVector("movereminder-output.vehicles");
671  myShallTraceMoveReminders.insert(vehicles.begin(), vehicles.end());
672  }
673 }
674 
675 
676 void
677 MSBaseVehicle::traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const {
678  OutputDevice& od = OutputDevice::getDeviceByOption("movereminder-output");
679  od.openTag("movereminder");
680  od.writeAttr(SUMO_ATTR_TIME, STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()));
681  od.writeAttr("veh", getID());
683  od.writeAttr("type", type);
684  od.writeAttr("pos", toString(pos));
685  od.writeAttr("keep", toString(keep));
686  od.closeTag();
687 }
688 #endif
689 
690 /****************************************************************************/
691 
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.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice.cpp:90
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:101
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...
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:357
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:390
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:165
T MAX2(T a, T b)
Definition: StdDefs.h:76
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:788
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:88
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:78
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:241
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.
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.
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...
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:198
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
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:263
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:70
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 / in-person device.
Definition: MSDevice.h:63
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:37
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
bool isTazConnector() const
Definition: MSEdge.h:248
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:369
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
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: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:95
Abstract in-vehicle device.
int myNumberReroutes
The number of reroutings.
virtual SUMOTime getWaitingTime() const =0
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.
const NumericalID myNumericalID
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:70
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.
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:62
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:78
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:366
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.
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.