Eclipse SUMO - Simulation of Urban MObility
MSDevice_Vehroutes.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2009-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // A device which collects info on the vehicle trip
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <microsim/MSGlobals.h>
26 #include <microsim/MSNet.h>
27 #include <microsim/MSLane.h>
28 #include <microsim/MSEdge.h>
29 #include <microsim/MSRoute.h>
30 #include <microsim/MSVehicle.h>
31 #include <microsim/MSVehicleType.h>
37 #include "MSDevice_Vehroutes.h"
38 
39 
40 // ===========================================================================
41 // static member variables
42 // ===========================================================================
47 bool MSDevice_Vehroutes::mySorted = false;
54 std::map<const SUMOTime, int> MSDevice_Vehroutes::myDepartureCounts;
55 std::map<const SUMOTime, std::map<const std::string, std::string> > MSDevice_Vehroutes::myRouteInfos;
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 // ---------------------------------------------------------------------------
62 // static initialisation methods
63 // ---------------------------------------------------------------------------
64 void
67  if (oc.isSet("vehroute-output")) {
68  OutputDevice::createDeviceByOption("vehroute-output", "routes", "routes_file.xsd");
69  mySaveExits = oc.getBool("vehroute-output.exit-times");
70  myLastRouteOnly = oc.getBool("vehroute-output.last-route");
71  myDUAStyle = oc.getBool("vehroute-output.dua");
72  myWriteCosts = oc.getBool("vehroute-output.cost");
73  mySorted = myDUAStyle || oc.getBool("vehroute-output.sorted");
74  myIntendedDepart = oc.getBool("vehroute-output.intended-depart");
75  myRouteLength = oc.getBool("vehroute-output.route-length");
76  mySkipPTLines = oc.getBool("vehroute-output.skip-ptlines");
77  myIncludeIncomplete = oc.getBool("vehroute-output.incomplete");
78  myWriteStopPriorEdges = oc.getBool("vehroute-output.stop-edges");
80  }
81 }
82 
83 void
85  oc.addOptionSubTopic("Vehroutes Device");
86  insertDefaultAssignmentOptions("vehroute", "Vehroutes Device", oc);
87 }
88 
89 
90 
92 MSDevice_Vehroutes::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, int maxRoutes) {
93  if (maxRoutes < std::numeric_limits<int>::max()) {
94  return new MSDevice_Vehroutes(v, "vehroute_" + v.getID(), maxRoutes);
95  }
96  if (mySkipPTLines && v.getParameter().line != "") {
97  return nullptr;
98  }
100  if (equippedByDefaultAssignmentOptions(oc, "vehroute", v, oc.isSet("vehroute-output"))) {
101  if (myLastRouteOnly) {
102  maxRoutes = 0;
103  }
104  myStateListener.myDevices[&v] = new MSDevice_Vehroutes(v, "vehroute_" + v.getID(), maxRoutes);
105  into.push_back(myStateListener.myDevices[&v]);
106  return myStateListener.myDevices[&v];
107  }
108  return nullptr;
109 }
110 
111 
112 // ---------------------------------------------------------------------------
113 // MSDevice_Vehroutes::StateListener-methods
114 // ---------------------------------------------------------------------------
115 void
117  if (to == MSNet::VehicleState::NEWROUTE) {
118  const auto& deviceEntry = myDevices.find(vehicle);
119  if (deviceEntry != myDevices.end()) {
120  deviceEntry->second->addRoute(info);
121  }
122  }
123 }
124 
125 
126 // ---------------------------------------------------------------------------
127 // MSDevice_Vehroutes-methods
128 // ---------------------------------------------------------------------------
129 MSDevice_Vehroutes::MSDevice_Vehroutes(SUMOVehicle& holder, const std::string& id, int maxRoutes) :
130  MSVehicleDevice(holder, id),
131  myCurrentRoute(&holder.getRoute()),
132  myMaxRoutes(maxRoutes),
133  myLastSavedAt(nullptr),
134  myLastRouteIndex(-1),
135  myDepartLane(-1),
136  myDepartPos(-1),
137  myDepartSpeed(-1),
138  myDepartPosLat(0),
139  myStopOut(2) {
141 }
142 
143 
145  for (const RouteReplaceInfo& rri : myReplacedRoutes) {
146  rri.route->release();
147  }
150 }
151 
152 
153 bool
156  if (mySorted && myStateListener.myDevices[static_cast<SUMOVehicle*>(&veh)] == this) {
158  myDepartureCounts[departure]++;
159  }
160  if (!MSGlobals::gUseMesoSim) {
161  const MSVehicle& vehicle = static_cast<MSVehicle&>(veh);
162  myDepartLane = vehicle.getLane()->getIndex();
164  }
165  myDepartSpeed = veh.getSpeed();
167  }
168  if (myWriteStopPriorEdges) {
169  myPriorEdges.push_back(&enteredLane->getEdge());
170  }
172  return true;
173 }
174 
175 
176 bool
177 MSDevice_Vehroutes::notifyLeave(SUMOTrafficObject& veh, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
178  if (mySaveExits && reason != NOTIFICATION_LANE_CHANGE && reason != NOTIFICATION_PARKING) {
179  if (reason != NOTIFICATION_TELEPORT && myLastSavedAt == veh.getEdge()) { // need to check this for internal lanes
181  } else if (myLastSavedAt != veh.getEdge()) {
182  myExits.push_back(MSNet::getInstance()->getCurrentTimeStep());
183  myLastSavedAt = veh.getEdge();
184  }
185  }
186  return true;
187 }
188 
189 
190 void
192  const bool closeLater = myWriteStopPriorEdges || mySaveExits;
193  stop.write(myStopOut, !closeLater);
194  if (myWriteStopPriorEdges) {
195  // calculate length
196  double priorEdgesLength = 0;
197  for (int i = 0; i < (int)myPriorEdges.size(); i++) {
198  if (i == 0) {
199  priorEdgesLength += myPriorEdges.at(i)->getLength();
200  } else if (myPriorEdges.at(i)->getID() != myPriorEdges.at(i - 1)->getID()) {
201  priorEdgesLength += myPriorEdges.at(i)->getLength();
202  }
203  }
204  myStopOut.writeAttr("priorEdges", myPriorEdges);
205  myPriorEdges.clear();
206  myStopOut.writeAttr("priorEdgesLength", priorEdgesLength);
207  }
208  if (mySaveExits) {
210  myStopOut.writeAttr(SUMO_ATTR_ENDED, stop.ended < 0 ? "-1" : time2string(stop.ended));
211  }
212  if (closeLater) {
214  }
215 }
216 
217 
218 void
220  if (index == 0 && !myIncludeIncomplete && myReplacedRoutes[index].route->size() == 2 &&
221  myReplacedRoutes[index].route->getEdges().front()->isTazConnector() &&
222  myReplacedRoutes[index].route->getEdges().back()->isTazConnector()) {
223  return;
224  }
225  // check if a previous route shall be written
226  //std::cout << " writeXMLRoute index=" << index << " numReroutes=" << myHolder.getNumberReroutes() << "\n";
227  const int routesToSkip = myHolder.getParameter().wasSet(VEHPARS_FORCE_REROUTE) ? 1 : 0;
229  if (index >= 0) {
230  assert((int)myReplacedRoutes.size() > index);
231  if (myDUAStyle || myWriteCosts) {
232  os.writeAttr(SUMO_ATTR_COST, myReplacedRoutes[index].route->getCosts());
233  }
234  if (myWriteCosts) {
235  os.writeAttr(SUMO_ATTR_SAVINGS, myReplacedRoutes[index].route->getSavings());
236  }
237  // write edge on which the vehicle was when the route was valid
238  os.writeAttr("replacedOnEdge", (myReplacedRoutes[index].edge ?
239  myReplacedRoutes[index].edge->getID() : ""));
240  // write the reason for replacement
241  os.writeAttr("reason", myReplacedRoutes[index].info);
242 
243  // write the time at which the route was replaced
244  os.writeAttr("replacedAtTime", time2string(myReplacedRoutes[index].time));
245  os.writeAttr(SUMO_ATTR_PROB, "0");
246  OutputDevice_String edgesD;
247  // always write the part that was actually driven and the rest of the current route that wasn't yet driven
248  int start = 0;
249  for (int i = routesToSkip; i < index; i++) {
250  if (myReplacedRoutes[i].edge != nullptr) {
251  int end = myReplacedRoutes[i].lastRouteIndex;
252  myReplacedRoutes[i].route->writeEdgeIDs(edgesD, start, end);
253  }
254  start = myReplacedRoutes[i].newRouteIndex;
255  }
256  myReplacedRoutes[index].route->writeEdgeIDs(edgesD, start, -1);
257  std::string edgesS = edgesD.getString();
258  edgesS.pop_back(); // remove last ' '
259  os.writeAttr(SUMO_ATTR_EDGES, edgesS);
260  if (myRouteLength) {
261  const bool includeInternalLengths = MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks();
262  const MSRoute* route = myReplacedRoutes[index].route;
263  const double routeLength = route->getDistanceBetween(myHolder.getDepartPos(), route->getEdges().back()->getLength(),
264  route->begin(), route->end(), includeInternalLengths);
265  os.writeAttr("routeLength", routeLength);
266  }
267  } else {
268  if (myDUAStyle || myWriteCosts) {
270  }
271  if (myWriteCosts) {
273  }
274  OutputDevice_String edgesD;
275  int numWritten = 0;
276  int start = 0;
277  if (myHolder.getNumberReroutes() > 0) {
278  assert((int)myReplacedRoutes.size() <= myHolder.getNumberReroutes());
279  for (int i = routesToSkip; i < (int)myReplacedRoutes.size(); i++) {
280  if (myReplacedRoutes[i].edge != nullptr) {
281  int end = myReplacedRoutes[i].lastRouteIndex;
282  numWritten += myReplacedRoutes[i].route->writeEdgeIDs(edgesD, start, end);
283  }
284  start = myReplacedRoutes[i].newRouteIndex;
285  }
286  }
287  numWritten += myCurrentRoute->writeEdgeIDs(edgesD, start, -1);
288  std::string edgesS = edgesD.getString();
289  edgesS.pop_back(); // remove last ' '
290  os.writeAttr(SUMO_ATTR_EDGES, edgesS);
291 
292  if (mySaveExits) {
293  std::vector<std::string> exits;
294  for (SUMOTime t : myExits) {
295  exits.push_back(time2string(t));
296  }
297  assert(numWritten >= (int)myExits.size());
298  std::vector<std::string> missing(numWritten - (int)myExits.size(), "-1");
299  exits.insert(exits.end(), missing.begin(), missing.end());
300  os.writeAttr(SUMO_ATTR_EXITTIMES, exits);
301  }
302  }
303  os.closeTag();
304 }
305 
306 
307 void
309  writeOutput(true);
310 }
311 
312 
313 void
314 MSDevice_Vehroutes::writeOutput(const bool hasArrived) const {
315  const OptionsCont& oc = OptionsCont::getOptions();
316  OutputDevice& routeOut = OutputDevice::getDeviceByOption("vehroute-output");
317  OutputDevice_String od(1);
320  if (!MSGlobals::gUseMesoSim) {
321  if (tmp.wasSet(VEHPARS_DEPARTLANE_SET)) {
323  tmp.departLane = myDepartLane;
324  }
325  if (tmp.wasSet(VEHPARS_DEPARTPOSLAT_SET)) {
328  }
329  }
330  if (tmp.wasSet(VEHPARS_DEPARTPOS_SET)) {
332  tmp.departPos = myDepartPos;
333  }
334  if (tmp.wasSet(VEHPARS_DEPARTSPEED_SET)) {
337  }
338  if (oc.getBool("vehroute-output.speedfactor") ||
339  (oc.isDefault("vehroute-output.speedfactor") && tmp.wasSet(VEHPARS_DEPARTSPEED_SET))) {
342  }
343 
344  const std::string typeID = myHolder.getVehicleType().getID() != DEFAULT_VTYPE_ID ? myHolder.getVehicleType().getID() : "";
345  tmp.write(od, oc, SUMO_TAG_VEHICLE, typeID);
346  if (hasArrived) {
347  od.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
348  }
349  if (myRouteLength) {
350  const bool includeInternalLengths = MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks();
351  const double finalPos = hasArrived ? myHolder.getArrivalPos() : myHolder.getPositionOnLane();
352  const double routeLength = myHolder.getRoute().getDistanceBetween(myHolder.getDepartPos(), finalPos,
353  myHolder.getRoute().begin(), myHolder.getCurrentRouteEdge(), includeInternalLengths);
354  od.writeAttr("routeLength", routeLength);
355  }
356  if (myDUAStyle) {
358  if (routeDist != nullptr) {
359  const std::vector<const MSRoute*>& routes = routeDist->getVals();
360  unsigned index = 0;
361  while (index < routes.size() && routes[index] != myCurrentRoute) {
362  ++index;
363  }
365  const std::vector<double>& probs = routeDist->getProbs();
366  for (int i = 0; i < (int)routes.size(); ++i) {
367  od.setPrecision();
369  od.writeAttr(SUMO_ATTR_COST, routes[i]->getCosts());
370  if (myWriteCosts) {
371  od.writeAttr(SUMO_ATTR_SAVINGS, routes[i]->getSavings());
372  }
373  od.setPrecision(8);
374  od.writeAttr(SUMO_ATTR_PROB, probs[i]);
375  od.setPrecision();
376  OutputDevice_String edgesD;
377  routes[i]->writeEdgeIDs(edgesD);
378  std::string edgesS = edgesD.getString();
379  edgesS.pop_back(); // remove last ' '
380  od.writeAttr(SUMO_ATTR_EDGES, edgesS);
381  od.closeTag();
382  }
383  od.closeTag();
384  } else {
385  writeXMLRoute(od);
386  }
387  } else {
388  const int routesToSkip = myHolder.getParameter().wasSet(VEHPARS_FORCE_REROUTE) && !myIncludeIncomplete ? 1 : 0;
389  if ((int)myReplacedRoutes.size() > routesToSkip) {
391  for (int i = routesToSkip; i < (int)myReplacedRoutes.size(); ++i) {
392  writeXMLRoute(od, i);
393  }
394  writeXMLRoute(od);
395  od.closeTag();
396  } else {
397  writeXMLRoute(od);
398  }
399  }
400  od << myStopOut.getString();
402  od.closeTag();
403  od.lf();
404  if (mySorted) {
405  writeSortedOutput(routeOut, tmp.depart, myHolder.getID(), od.getString());
406  } else {
407  routeOut << od.getString();
408  }
409 }
410 
411 
412 const MSRoute*
414  if (index < (int)myReplacedRoutes.size()) {
415  return myReplacedRoutes[index].route;
416  } else {
417  return nullptr;
418  }
419 }
420 
421 
422 void
423 MSDevice_Vehroutes::addRoute(const std::string& info) {
424  if (myMaxRoutes > 0) {
425  //std::cout << SIMTIME << " " << getID() << " departed=" << myHolder.hasDeparted() << " lastIndex=" << myLastRouteIndex << " start=" << myHolder.getRoutePosition() << "\n";
427  myHolder.hasDeparted() ? myHolder.getEdge() : nullptr,
431  if ((int)myReplacedRoutes.size() > myMaxRoutes) {
432  myReplacedRoutes.front().route->release();
433  myReplacedRoutes.erase(myReplacedRoutes.begin());
434  }
435  } else {
437  }
440 }
441 
442 
443 void
445  for (const auto& it : myStateListener.myDevices) {
446  if (it.first->hasDeparted()) {
447  it.second->writeOutput(false);
448  }
449  }
450  // unfinished persons
451  MSNet* net = MSNet::getInstance();
452  if (net->hasPersons()) {
454  while (pc.loadedBegin() != pc.loadedEnd()) {
455  pc.erase(pc.loadedBegin()->second);
456  }
457  }
458 }
459 
460 
461 void
463  myDepartureCounts[depart]++;
464 }
465 
466 
467 void
468 MSDevice_Vehroutes::writeSortedOutput(OutputDevice& routeOut, SUMOTime depart, const std::string& id, const std::string& xmlOutput) {
469  myRouteInfos[depart][id] = xmlOutput;
470  myDepartureCounts[depart]--;
471  std::map<const SUMOTime, int>::iterator it = myDepartureCounts.begin();
472  while (it != myDepartureCounts.end() && it->second == 0) {
473  std::map<const std::string, std::string>& infos = myRouteInfos[it->first];
474  for (std::map<const std::string, std::string>::const_iterator it2 = infos.begin(); it2 != infos.end(); ++it2) {
475  routeOut << it2->second;
476  }
477  myRouteInfos.erase(it->first);
478  myDepartureCounts.erase(it);
479  it = myDepartureCounts.begin();
480  }
481 }
482 
483 void
486  out.writeAttr(SUMO_ATTR_ID, getID());
487  std::vector<std::string> internals;
488  if (!MSGlobals::gUseMesoSim) {
489  internals.push_back(toString(myDepartLane));
490  internals.push_back(toString(myDepartPosLat));
491  }
492  internals.push_back(toString(myDepartSpeed));
493  internals.push_back(toString(myDepartPos));
494  internals.push_back(toString(myReplacedRoutes.size()));
495  for (int i = 0; i < (int)myReplacedRoutes.size(); ++i) {
496  const std::string replacedOnEdge = myReplacedRoutes[i].edge == nullptr ? "!NULL" : myReplacedRoutes[i].edge->getID();
497  internals.push_back(replacedOnEdge);
498  internals.push_back(toString(myReplacedRoutes[i].time));
499  internals.push_back(myReplacedRoutes[i].route->getID());
500  internals.push_back(myReplacedRoutes[i].info);
501  internals.push_back(toString(myReplacedRoutes[i].lastRouteIndex));
502  internals.push_back(toString(myReplacedRoutes[i].newRouteIndex));
503  }
504  out.writeAttr(SUMO_ATTR_STATE, toString(internals));
505  if (mySaveExits && myExits.size() > 0) {
507  }
508  out.closeTag();
509 }
510 
511 
512 void
514  std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
515  if (!MSGlobals::gUseMesoSim) {
516  bis >> myDepartLane;
517  bis >> myDepartPosLat;
518  }
519  bis >> myDepartSpeed;
520  bis >> myDepartPos;
521  int size;
522  bis >> size;
523  for (int i = 0; i < size; ++i) {
524  std::string edgeID;
525  SUMOTime time;
526  std::string routeID;
527  std::string info;
528  int lastIndex;
529  int newIndex;
530  bis >> edgeID;
531  bis >> time;
532  bis >> routeID;
533  bis >> info;
534  bis >> lastIndex;
535  bis >> newIndex;
536 
537  const MSRoute* route = MSRoute::dictionary(routeID);
538  if (route != nullptr) {
539  route->addReference();
540  myReplacedRoutes.push_back(RouteReplaceInfo(MSEdge::dictionary(edgeID), time, route, info, lastIndex, newIndex));
541  }
542  }
544  for (const std::string& t : attrs.getStringVector(SUMO_ATTR_EXITTIMES)) {
545  myExits.push_back(StringUtils::toLong(t));
546  }
547  }
548 }
549 
550 
551 /****************************************************************************/
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:32
const std::string DEFAULT_VTYPE_ID
@ GIVEN
The lane is given.
@ GIVEN
The position is given.
@ GIVEN
The position is given.
const int VEHPARS_SPEEDFACTOR_SET
const int VEHPARS_DEPARTPOS_SET
@ GIVEN
The speed is given.
const int VEHPARS_DEPARTLANE_SET
const int VEHPARS_FORCE_REROUTE
const int VEHPARS_DEPARTSPEED_SET
const int VEHPARS_DEPARTPOSLAT_SET
@ SUMO_TAG_DEVICE
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_ATTR_LAST
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_EXITTIMES
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_COST
@ SUMO_ATTR_PROB
@ SUMO_ATTR_SAVINGS
@ SUMO_ATTR_ID
@ SUMO_ATTR_STATE
The state of a link.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
Information about a replaced route.
A class that is notified about reroutings.
std::map< const SUMOVehicle *, MSDevice_Vehroutes *, ComparatorNumericalIdLess > myDevices
A map for internal notification.
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
A device which collects info on the vehicle trip (mainly on departure and arrival)
static bool myWriteCosts
A shortcut for the Option "vehroute-output.costs".
static void init()
Static intialization.
std::vector< SUMOTime > myExits
The times the vehicle exites an edge.
static bool mySorted
A shortcut for the Option "vehroute-output.sorted".
static bool myIntendedDepart
A shortcut for the Option "vehroute-output.intended-depart".
static std::map< const SUMOTime, std::map< const std::string, std::string > > myRouteInfos
void addRoute(const std::string &info)
Called on route change.
int myLastRouteIndex
The route index of the last edge that the vehicle left.
static bool myIncludeIncomplete
A shortcut for the Option "vehroute-output.incomplete".
void stopEnded(const SUMOVehicleParameter::Stop &stop)
MSDevice_Vehroutes(SUMOVehicle &holder, const std::string &id, int maxRoutes)
Constructor.
static bool myRouteLength
A shortcut for the Option "vehroute-output.route-length".
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
void writeXMLRoute(OutputDevice &os, int index=-1) const
Called on route output.
static std::map< const SUMOTime, int > myDepartureCounts
Map needed to sort vehicles by departure time.
static MSDevice_Vehroutes * buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into, int maxRoutes=std::numeric_limits< int >::max())
Build devices for the given vehicle, if needed.
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
std::vector< RouteReplaceInfo > myReplacedRoutes
Prior routes.
std::vector< const MSEdge * > myPriorEdges
the edges that were passed before the current stop
const int myMaxRoutes
The maximum number of routes to report.
static bool myWriteStopPriorEdges
A shortcut for the Option "vehroute-output.stop-edges".
double myDepartPosLat
The lateral depart position.
const MSEdge * myLastSavedAt
The last edge the exit time was saved for.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
OutputDevice_String myStopOut
double myDepartPos
The lane the vehicle departed at.
const MSRoute * getRoute(int index) const
Called on route retrieval.
static bool myLastRouteOnly
A shortcut for the Option "vehroute-output.last-route".
double myDepartSpeed
The speed on departure.
static void writeSortedOutput(OutputDevice &routeOut, SUMOTime depart, const std::string &id, const std::string &xmlOutput)
int myDepartLane
The lane the vehicle departed at.
void writeOutput(const bool hasArrived) const
Called on writing vehroutes output.
~MSDevice_Vehroutes()
Destructor.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Saves exit times if needed.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Does nothing, returns true only if exit times should be collected.
static bool mySkipPTLines
A shortcut for the Option "vehroute-output.skip-ptlines".
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing vehroutes output.
const MSRoute * myCurrentRoute
The currently used route.
static bool myDUAStyle
A shortcut for the Option "vehroute-output.dua".
static bool mySaveExits
A shortcut for the Option "vehroute-output.exit-times".
static void registerTransportableDepart(SUMOTime depart)
void saveState(OutputDevice &out) const
Saves the state of the device.
static StateListener myStateListener
A class that is notified about reroutings.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:137
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.h:205
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition: MSEdge.cpp:885
static bool gUseMesoSim
Definition: MSGlobals.h:94
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:72
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
int getIndex() const
Returns the lane's index.
Definition: MSLane.h:563
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:674
Notification
Definition of a vehicle state.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_LANE_CHANGE
The vehicle changes lanes (micro only)
@ NOTIFICATION_PARKING
The vehicle starts or ends parking.
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
The simulated network and simulation perfomer.
Definition: MSNet.h:88
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:594
@ NEWROUTE
The vehicle got a new route.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:318
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:1127
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:393
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1059
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:768
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:94
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:75
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:113
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition: MSRoute.h:172
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:100
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:165
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes....
Definition: MSRoute.cpp:291
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:69
int writeEdgeIDs(OutputDevice &os, int firstIndex=0, int lastIndex=-1) const
Output the edge ids up to but not including the id of the given edge.
Definition: MSRoute.cpp:226
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:120
double getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:164
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
virtual void erase(MSTransportable *transportable)
removes a single transportable
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:75
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition: MSVehicle.h:411
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:552
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
An output device that encapsulates an ofstream.
std::string getString() const
Returns the current content as a string.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:236
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
const std::vector< T > & getVals() const
Returns the members of the distribution.
Encapsulated SAX-Attributes.
const std::vector< std::string > getStringVector(int attr) const
Tries to read given attribute assuming it is a string vector.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
Representation of a vehicle, person, or container.
virtual double getChosenSpeedFactor() const =0
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
virtual const MSRoute & getRoute() const =0
Returns the current route.
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual int getNumberReroutes() const =0
Returns the number of new routes this vehicle got.
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual double getArrivalPos() const =0
Returns this vehicle's desired arrivalPos for its current route (may change on reroute)
virtual double getDepartPos() const =0
Returns this vehicle's real departure position.
virtual int getRoutePosition() const =0
return index of edge within route
Definition of vehicle stop (position and duration)
SUMOTime started
the time at which this stop was reached
void write(OutputDevice &dev, const bool close=true, const bool writeTagAndParents=true) const
Writes the stop as XML.
SUMOTime ended
the time at which this stop was ended
Structure representing possible vehicle parameter.
double departPosLat
(optional) The lateral position the vehicle shall depart from
int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
double departSpeed
(optional) The initial speed of the vehicle
double speedFactor
individual speedFactor (overriding distribution from vType)
void write(OutputDevice &dev, const OptionsCont &oc, const SumoXMLTag altTag=SUMO_TAG_VEHICLE, const std::string &typeID="") const
Writes the parameters as a beginning element.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
DepartPosLatDefinition departPosLatProcedure
Information how the vehicle shall choose the lateral departure position.
double departPos
(optional) The position the vehicle shall depart from
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
bool wasSet(int what) const
Returns whether the given parameter was set.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
std::string line
The vehicle's line (mainly for public transport)
static long long int toLong(const std::string &sData)
converts a string into the long value described by it by calling the char-type converter,...