Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_Vehroutes.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2009-2026 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/MSStop.h>
31#include <microsim/MSVehicle.h>
38#include "MSDevice_Vehroutes.h"
39
40
41// ===========================================================================
42// static member variables
43// ===========================================================================
57
58
59// ===========================================================================
60// method definitions
61// ===========================================================================
62// ---------------------------------------------------------------------------
63// static initialisation methods
64// ---------------------------------------------------------------------------
65void
68 if (oc.isSet("vehroute-output")) {
69 OutputDevice::createDeviceByOption("vehroute-output", "routes", "routes_file.xsd");
70 OutputDevice& od = OutputDevice::getDeviceByOption("vehroute-output");
71 if (!od.isXML()) {
72 WRITE_WARNING("Vehroute output does not fully support tabular formats. Sorting and stop output will not work.");
73 }
74 mySaveExits = oc.getBool("vehroute-output.exit-times");
75 myLastRouteOnly = oc.getBool("vehroute-output.last-route");
76 myDUAStyle = oc.getBool("vehroute-output.dua");
77 myWriteCosts = oc.getBool("vehroute-output.cost");
78 mySorted = myDUAStyle || oc.getBool("vehroute-output.sorted");
79 myIntendedDepart = oc.getBool("vehroute-output.intended-depart");
80 myRouteLength = oc.getBool("vehroute-output.route-length");
81 mySkipPTLines = oc.getBool("vehroute-output.skip-ptlines");
82 myIncludeIncomplete = oc.getBool("vehroute-output.incomplete");
83 myWriteStopPriorEdges = oc.getBool("vehroute-output.stop-edges");
84 myWriteInternal = oc.getBool("vehroute-output.internal");
87 }
88}
89
90
91void
93 oc.addOptionSubTopic("Vehroutes Device");
94 insertDefaultAssignmentOptions("vehroute", "Vehroutes Device", oc);
95}
96
97
99MSDevice_Vehroutes::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, int maxRoutes) {
100 if (maxRoutes < std::numeric_limits<int>::max()) {
101 return new MSDevice_Vehroutes(v, "vehroute_" + v.getID(), maxRoutes);
102 }
103 if (mySkipPTLines && v.getParameter().line != "") {
104 return nullptr;
105 }
107 if (equippedByDefaultAssignmentOptions(oc, "vehroute", v, oc.isSet("vehroute-output"))) {
108 if (myLastRouteOnly) {
109 maxRoutes = 0;
110 }
111 myStateListener.myDevices[&v] = new MSDevice_Vehroutes(v, "vehroute_" + v.getID(), maxRoutes);
112 into.push_back(myStateListener.myDevices[&v]);
113 return myStateListener.myDevices[&v];
114 }
115 return nullptr;
116}
117
118
119// ---------------------------------------------------------------------------
120// MSDevice_Vehroutes::StateListener-methods
121// ---------------------------------------------------------------------------
122void
125 const auto& deviceEntry = myDevices.find(vehicle);
126 if (deviceEntry != myDevices.end()) {
127 deviceEntry->second->addRoute(info);
128 }
129 }
130}
131
132
133// ---------------------------------------------------------------------------
134// MSDevice_Vehroutes-methods
135// ---------------------------------------------------------------------------
136MSDevice_Vehroutes::MSDevice_Vehroutes(SUMOVehicle& holder, const std::string& id, int maxRoutes) :
137 MSVehicleDevice(holder, id),
138 myCurrentRoute(holder.getRoutePtr()),
139 myMaxRoutes(maxRoutes),
140 myLastSavedAt(nullptr),
142 myDepartLane(-1),
143 myDepartPos(-1),
144 myDepartSpeed(-1),
146 myStopOut(2) {
147}
148
149
153
154
155bool
158 if (mySorted && myStateListener.myDevices.count(static_cast<SUMOVehicle*>(&veh)) != 0
159 && myStateListener.myDevices[static_cast<SUMOVehicle*>(&veh)] == this) {
161 myRouteInfos.departureCounts[departure]++;
162 }
164 const MSVehicle& vehicle = static_cast<MSVehicle&>(veh);
165 myDepartLane = vehicle.getLane()->getIndex();
167 }
168 myDepartSpeed = veh.getSpeed();
170 }
173 const MSEdge* e = veh.getEdge();
174 if (myPriorEdges.empty() || myPriorEdges.back() != e) {
175 myPriorEdges.push_back(e);
176 }
177 } else {
178 myPriorEdges.push_back(&enteredLane->getEdge());
179 }
180 }
182 return true;
183}
184
185
186bool
187MSDevice_Vehroutes::notifyLeave(SUMOTrafficObject& veh, double /*lastPos*/, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
188 if (mySaveExits && reason != NOTIFICATION_LANE_CHANGE && reason != NOTIFICATION_PARKING && reason != NOTIFICATION_SEGMENT) {
189 const MSEdge* edge = myWriteInternal ? dynamic_cast<MSBaseVehicle&>(veh).getCurrentEdge() : veh.getEdge();
190 if (myLastSavedAt != edge) {
191 myExits.push_back(MSNet::getInstance()->getCurrentTimeStep());
192 myLastSavedAt = edge;
193 }
194 }
195 return true;
196}
197
198
199void
201 SUMOVehicleParameter::Stop stop = myHolder.getStops().front().pars;
202 const bool closeLater = myWriteStopPriorEdges || mySaveExits;
203 if (mySaveExits) {
204 // prevent duplicate output
206 }
207 stop.write(myStopOut, !closeLater);
209 // calculate length
210 double priorEdgesLength = 0;
211 for (int i = 0; i < (int)myPriorEdges.size(); i++) {
212 if (i == 0) {
213 priorEdgesLength += myPriorEdges.at(i)->getLength();
214 } else if (myPriorEdges.at(i)->getID() != myPriorEdges.at(i - 1)->getID()) {
215 priorEdgesLength += myPriorEdges.at(i)->getLength();
216 }
217 }
218 myStopOut.writeAttr("priorEdges", myPriorEdges);
219 myPriorEdges.clear();
220 myStopOut.writeAttr("priorEdgesLength", priorEdgesLength);
221 }
222 if (mySaveExits) {
224 myStopOut.writeAttr(SUMO_ATTR_ENDED, stop.ended < 0 ? "-1" : time2string(stop.ended));
225 }
226 if (closeLater) {
228 }
229}
230
231
232void
234 if (index == 0 && !myIncludeIncomplete && myReplacedRoutes[index].route->size() == 2 &&
235 myReplacedRoutes[index].route->getEdges().front()->isTazConnector() &&
236 myReplacedRoutes[index].route->getEdges().back()->isTazConnector()) {
237 return;
238 }
239 // check if a previous route shall be written
240 //std::cout << " writeXMLRoute index=" << index << " numReroutes=" << myHolder.getNumberReroutes() << "\n";
241 const int routesToSkip = myHolder.getParameter().wasSet(VEHPARS_FORCE_REROUTE) ? 1 : 0;
243 if (index >= 0) {
244 assert((int)myReplacedRoutes.size() > index);
245 if (myDUAStyle || myWriteCosts) {
246 os.writeAttr(SUMO_ATTR_COST, myReplacedRoutes[index].route->getCosts());
247 }
248 if (myWriteCosts) {
249 os.writeAttr(SUMO_ATTR_SAVINGS, myReplacedRoutes[index].route->getSavings());
250 }
251 // write edge on which the vehicle was when the route was valid
252 os.writeAttr("replacedOnEdge", (myReplacedRoutes[index].edge ?
253 myReplacedRoutes[index].edge->getID() : ""));
254 if (myReplacedRoutes[index].lastRouteIndex > 0) {
255 // do not write the default
256 os.writeAttr(SUMO_ATTR_REPLACED_ON_INDEX, myReplacedRoutes[index].lastRouteIndex);
257 }
258 // write the reason for replacement
259 os.writeAttr("reason", myReplacedRoutes[index].info);
260
261 // write the time at which the route was replaced
263 os.writeAttr(SUMO_ATTR_PROB, "0");
264 OutputDevice_String edgesD;
265 // always write the part that was actually driven and the rest of the current route that wasn't yet driven
266 int start = 0;
267 for (int i = routesToSkip; i < index; i++) {
268 if (myReplacedRoutes[i].edge != nullptr) {
269 int end = myReplacedRoutes[i].lastRouteIndex;
270 myReplacedRoutes[i].route->writeEdgeIDs(edgesD, start, end, myWriteInternal, myHolder.getVClass());
271 }
272 start = myReplacedRoutes[i].newRouteIndex;
273 }
274 myReplacedRoutes[index].route->writeEdgeIDs(edgesD, start, -1, myWriteInternal, myHolder.getVClass());
275 std::string edgesS = edgesD.getString();
276 edgesS.pop_back(); // remove last ' '
277 os.writeAttr(SUMO_ATTR_EDGES, edgesS);
278 if (myRouteLength) {
279 const bool includeInternalLengths = MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks();
280 ConstMSRoutePtr route = myReplacedRoutes[index].route;
281 const double routeLength = route->getDistanceBetween(myHolder.getDepartPos(), route->getEdges().back()->getLength(),
282 route->begin(), route->end(), includeInternalLengths);
283 os.writeAttr("routeLength", routeLength);
284 }
285 } else {
286 if (myDUAStyle || myWriteCosts) {
288 }
289 if (myWriteCosts) {
291 }
292 OutputDevice_String edgesD;
293 int numWritten = 0;
294 int start = 0;
295 if (myHolder.getNumberReroutes() > 0) {
296 assert((int)myReplacedRoutes.size() <= myHolder.getNumberReroutes());
297 for (int i = routesToSkip; i < (int)myReplacedRoutes.size(); i++) {
298 if (myReplacedRoutes[i].edge != nullptr) {
299 int end = myReplacedRoutes[i].lastRouteIndex;
300 numWritten += myReplacedRoutes[i].route->writeEdgeIDs(edgesD, start, end, myWriteInternal, myHolder.getVClass());
301 }
302 start = myReplacedRoutes[i].newRouteIndex;
303 }
304 }
305 numWritten += myCurrentRoute->writeEdgeIDs(edgesD, start, -1, myWriteInternal, myHolder.getVClass());
306 std::string edgesS = edgesD.getString();
307 edgesS.pop_back(); // remove last ' '
308 os.writeAttr(SUMO_ATTR_EDGES, edgesS);
309
310 if (mySaveExits) {
311 std::vector<std::string> exits;
312 for (SUMOTime t : myExits) {
313 exits.push_back(time2string(t));
314 }
315 assert(numWritten >= (int)myExits.size());
316 std::vector<std::string> missing(numWritten - (int)myExits.size(), "-1");
317 exits.insert(exits.end(), missing.begin(), missing.end());
319 }
320 }
321 os.closeTag();
322}
323
324
325void
327 writeOutput(true);
328}
329
330
331void
332MSDevice_Vehroutes::writeOutput(const bool hasArrived) const {
334 OutputDevice& routeOut = OutputDevice::getDeviceByOption("vehroute-output");
335 OutputDevice_String stringOut(1);
336 OutputDevice& od = mySorted && routeOut.isXML() ? stringOut : routeOut;
343 }
349 }
350 }
351 if (tmp.wasSet(VEHPARS_DEPARTPOS_SET)) {
357 }
364 }
365 if (oc.getBool("vehroute-output.speedfactor") ||
366 (oc.isDefault("vehroute-output.speedfactor") && tmp.wasSet(VEHPARS_DEPARTSPEED_SET))) {
369 }
370
371 const std::string typeID = myHolder.getVehicleType().getID() != DEFAULT_VTYPE_ID ? myHolder.getVehicleType().getID() : "";
372 tmp.write(od, oc, SUMO_TAG_VEHICLE, typeID);
373 if (hasArrived) {
375 }
376 if (myRouteLength) {
377 const bool includeInternalLengths = MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks();
378 const double finalPos = hasArrived ? myHolder.getArrivalPos() : myHolder.getPositionOnLane();
379 const double routeLength = myHolder.getRoute().getDistanceBetween(myHolder.getDepartPos(), finalPos,
380 myHolder.getRoute().begin(), myHolder.getCurrentRouteEdge(), includeInternalLengths);
381 od.writeAttr("routeLength", routeLength);
382 }
383 if (myDUAStyle) {
385 if (routeDist != nullptr) {
386 const std::vector<ConstMSRoutePtr>& routes = routeDist->getVals();
387 unsigned index = 0;
388 while (index < routes.size() && routes[index] != myCurrentRoute) {
389 ++index;
390 }
392 const std::vector<double>& probs = routeDist->getProbs();
393 for (int i = 0; i < (int)routes.size(); ++i) {
394 od.setPrecision();
396 od.writeAttr(SUMO_ATTR_COST, routes[i]->getCosts());
397 if (myWriteCosts) {
398 od.writeAttr(SUMO_ATTR_SAVINGS, routes[i]->getSavings());
399 }
400 od.setPrecision(8);
401 od.writeAttr(SUMO_ATTR_PROB, probs[i]);
402 od.setPrecision();
403 OutputDevice_String edgesD;
404 routes[i]->writeEdgeIDs(edgesD, 0, -1, myWriteInternal, myHolder.getVClass());
405 std::string edgesS = edgesD.getString();
406 edgesS.pop_back(); // remove last ' '
407 od.writeAttr(SUMO_ATTR_EDGES, edgesS);
408 od.closeTag();
409 }
410 od.closeTag();
411 } else {
412 writeXMLRoute(od);
413 }
414 } else {
415 std::string dummyMsg;
416 const int routesToSkip = (myHolder.getParameter().wasSet(VEHPARS_FORCE_REROUTE)
418 && myReplacedRoutes.size() > 0
419 && !myHolder.hasValidRoute(dummyMsg, myReplacedRoutes[0].route) ? 1 : 0);
420 if ((int)myReplacedRoutes.size() > routesToSkip) {
422 for (int i = routesToSkip; i < (int)myReplacedRoutes.size(); ++i) {
423 writeXMLRoute(od, i);
424 }
425 writeXMLRoute(od);
426 od.closeTag();
427 } else {
428 writeXMLRoute(od);
429 }
430 }
431 if (routeOut.isXML()) {
432 od << myStopOut.getString();
433 }
435 od.closeTag();
436 od.lf();
437 if (mySorted && routeOut.isXML()) {
438 // numerical id reflects loading order
440 }
441}
442
443
446 if (index < (int)myReplacedRoutes.size()) {
447 return myReplacedRoutes[index].route;
448 } else {
449 return nullptr;
450 }
451}
452
453
454void
455MSDevice_Vehroutes::addRoute(const std::string& info) {
456 if (myMaxRoutes > 0) {
457 //std::cout << SIMTIME << " " << getID() << " departed=" << myHolder.hasDeparted() << " lastIndex=" << myLastRouteIndex << " start=" << myHolder.getRoutePosition() << "\n";
459 myHolder.hasDeparted() ? myHolder.getEdge() : nullptr,
463 if ((int)myReplacedRoutes.size() > myMaxRoutes) {
464 myReplacedRoutes.erase(myReplacedRoutes.begin());
465 }
466 }
468}
469
470
471void
472MSDevice_Vehroutes::writePendingOutput(const bool includeUnfinished) {
473 MSNet* const net = MSNet::getInstance();
474
475 if (!includeUnfinished) {
476 if (mySorted) {
477 for (const auto& routeInfo : myRouteInfos.routeXML) {
478 for (const auto& rouXML : routeInfo.second) {
479 (*myRouteInfos.routeOut) << rouXML.second;
480 }
481 }
482 if (net->hasPersons()) {
483 const SortedRouteInfo& personRouteInfos = net->getPersonControl().getRouteInfo();
484 if (personRouteInfos.routeOut != myRouteInfos.routeOut) {
485 for (const auto& routeInfo : personRouteInfos.routeXML) {
486 for (const auto& rouXML : routeInfo.second) {
487 (*personRouteInfos.routeOut) << rouXML.second;
488 }
489 }
490 }
491 }
492 }
493 return;
494 }
495 for (const auto& it : myStateListener.myDevices) {
496 if (it.first->hasDeparted()) {
497 if (it.first->isStopped()) {
498 it.second->notifyStopEnded();
499 }
500 it.second->writeOutput(false);
501 }
502 }
503 // unfinished persons
504 if (net->hasPersons()) {
506 while (pc.loadedBegin() != pc.loadedEnd()) {
507 pc.erase(pc.loadedBegin()->second);
508 }
509 }
510 // Flush any remaining sorted outputs that may still be buffered
511 if (mySorted) {
512 for (const auto& routeInfo : myRouteInfos.routeXML) {
513 for (const auto& rouXML : routeInfo.second) {
514 (*myRouteInfos.routeOut) << rouXML.second;
515 }
516 }
517 if (net->hasPersons()) {
518 const SortedRouteInfo& personRouteInfos = net->getPersonControl().getRouteInfo();
519 if (personRouteInfos.routeOut != myRouteInfos.routeOut) {
520 for (const auto& routeInfo : personRouteInfos.routeXML) {
521 for (const auto& rouXML : routeInfo.second) {
522 (*personRouteInfos.routeOut) << rouXML.second;
523 }
524 }
525 }
526 }
527 }
528}
529
530
531void
535
536
537void
539 if (routeInfo->routeOut == myRouteInfos.routeOut) {
540 routeInfo = &myRouteInfos;
541 }
542 routeInfo->routeXML[depart][id] = xmlOutput;
543 routeInfo->departureCounts[depart]--;
544 std::map<const SUMOTime, int>::iterator it = routeInfo->departureCounts.begin();
545 while (it != routeInfo->departureCounts.end() && it->second == 0) {
546 for (const auto& rouXML : routeInfo->routeXML[it->first]) {
547 (*routeInfo->routeOut) << rouXML.second;
548 }
549 routeInfo->routeXML.erase(it->first);
550 it = routeInfo->departureCounts.erase(it);
551 }
552}
553
554
555void
559 std::vector<std::string> internals;
561 internals.push_back(toString(myDepartLane));
562 internals.push_back(toString(myDepartPosLat));
563 }
564 internals.push_back(toString(myDepartSpeed));
565 internals.push_back(toString(myDepartPos));
566 internals.push_back(toString(myReplacedRoutes.size()));
567 for (int i = 0; i < (int)myReplacedRoutes.size(); ++i) {
568 const std::string replacedOnEdge = myReplacedRoutes[i].edge == nullptr ? "!NULL" : myReplacedRoutes[i].edge->getID();
569 internals.push_back(replacedOnEdge);
570 internals.push_back(toString(myReplacedRoutes[i].time));
571 internals.push_back(myReplacedRoutes[i].route->getID());
572 internals.push_back(myReplacedRoutes[i].info);
573 internals.push_back(toString(myReplacedRoutes[i].lastRouteIndex));
574 internals.push_back(toString(myReplacedRoutes[i].newRouteIndex));
575 }
576 out.writeAttr(SUMO_ATTR_STATE, toString(internals));
577 if (mySaveExits && myExits.size() > 0) {
580 }
581 out.closeTag();
582}
583
584
585void
587 std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
589 bis >> myDepartLane;
590 bis >> myDepartPosLat;
591 }
592 bis >> myDepartSpeed;
593 bis >> myDepartPos;
594 int size;
595 bis >> size;
596 for (int i = 0; i < size; ++i) {
597 std::string edgeID;
598 SUMOTime time;
599 std::string routeID;
600 std::string info;
601 int lastIndex;
602 int newIndex;
603 bis >> edgeID;
604 bis >> time;
605 bis >> routeID;
606 bis >> info;
607 bis >> lastIndex;
608 bis >> newIndex;
609
610 ConstMSRoutePtr route = MSRoute::dictionary(routeID);
611 if (route != nullptr) {
612 myReplacedRoutes.push_back(RouteReplaceInfo(MSEdge::dictionary(edgeID), time, route, info, lastIndex, newIndex));
613 }
614 }
616 bool ok = true;
617 for (const std::string& t : attrs.get<std::vector<std::string> >(SUMO_ATTR_EXITTIMES, nullptr, ok)) {
618 myExits.push_back(StringUtils::toLong(t));
619 }
620 if (attrs.hasAttribute(SUMO_ATTR_EDGE)) {
622 }
623 }
624 if (myHolder.hasDeparted()) {
626 }
627}
628
629
630/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
const std::string DEFAULT_VTYPE_ID
const long long int VEHPARS_DEPARTPOSLAT_SET
const long long int VEHPARS_DEPARTSPEED_SET
const long long int VEHPARS_FORCE_REROUTE
@ GIVEN
The lane is given.
@ RANDOM
The lateral position is chosen randomly.
@ GIVEN
The position is given.
@ GIVEN_VEHROUTE
The position is set by the vehroute device.
@ GIVEN
The position is given.
@ GIVEN_VEHROUTE
The position is set by the vehroute device.
@ STOP
depart position is endPos of first stop
@ GIVEN
The speed is given.
@ GIVEN_VEHROUTE
The speed is set by the vehroute device.
@ LIMIT
The maximum lane speed is used (speedLimit)
const long long int VEHPARS_DEPARTLANE_SET
const long long int VEHPARS_DEPARTPOS_SET
const int STOP_ENDED_SET
const long long int VEHPARS_SPEEDFACTOR_SET
const int STOP_STARTED_SET
@ SUMO_TAG_DEVICE
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_ROUTE
description of a route
@ SUMO_ATTR_LAST
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_REPLACED_AT_TIME
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_EXITTIMES
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_COST
@ SUMO_ATTR_REPLACED_ON_INDEX
@ 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:49
The base class for microscopic and mesoscopic vehicles.
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 at which the vehicle exits 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".
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".
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.
ConstMSRoutePtr getRoute(int index) const
Called on route retrieval.
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.
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.
static void writePendingOutput(const bool includeUnfinished)
generate vehroute output for pending vehicles at sim end, either due to sorting or because they are s...
static bool myLastRouteOnly
A shortcut for the Option "vehroute-output.last-route".
ConstMSRoutePtr myCurrentRoute
The currently used route.
double myDepartSpeed
The speed on departure.
static void writeSortedOutput(SortedRouteInfo *routeInfo, SUMOTime depart, const SUMOTrafficObject::NumericalID id, const std::string &xmlOutput)
int myDepartLane
The lane the vehicle departed at.
static SortedRouteInfo myRouteInfos
Information needed to sort vehicles by departure time.
void writeOutput(const bool hasArrived) const
Called on writing vehroutes output.
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 myWriteInternal
A shortcut for the Option "vehroute-output.internal".
static bool mySkipPTLines
A shortcut for the Option "vehroute-output.skip-ptlines".
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing vehroutes output.
void notifyStopEnded()
called to update state for stopped vehicles
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:157
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:200
A road/street connecting two junctions.
Definition MSEdge.h:77
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:1081
static bool gUseMesoSim
Definition MSGlobals.h:106
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:81
Representation of a lane in the micro simulation.
Definition MSLane.h:84
int getIndex() const
Returns the lane's index.
Definition MSLane.h:653
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:775
Notification
Definition of a vehicle state.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_SEGMENT
The vehicle changes the segment (meso only)
@ NOTIFICATION_LANE_CHANGE
The vehicle changes lanes (micro only)
@ NOTIFICATION_PARKING
The vehicle starts or ends parking.
The simulated network and simulation perfomer.
Definition MSNet.h:89
VehicleState
Definition of a vehicle state.
Definition MSNet.h:636
@ NEWROUTE
The vehicle got a new route.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:199
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:334
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition MSNet.cpp:1354
bool hasPersons() const
Returns whether persons are simulated.
Definition MSNet.h:419
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1286
bool hasInternalLinks() const
return whether the network contains internal links
Definition MSNet.h:811
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition MSRoute.h:186
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:116
static RandomDistributor< ConstMSRoutePtr > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition MSRoute.cpp:168
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition MSRoute.cpp:73
double getDistanceBetween(double fromPos, double toPos, const MSLane *fromLane, const MSLane *toLane, int routePosition=0) const
Compute the distance between 2 given edges on this route, optionally including the length of internal...
Definition MSRoute.cpp:318
double getCosts() const
Returns the costs of the route.
Definition MSRoute.h:178
const MSDevice_Vehroutes::SortedRouteInfo & getRouteInfo()
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:77
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition MSVehicle.h:413
const std::string & getID() const
Returns the name of the vehicle type.
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.
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.
void lf()
writes a line feed if applicable
bool isXML() const
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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.
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="", const int maximumDepth=2)
Creates the device using the output definition stored in the named option.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
Represents a generic random distribution.
const std::vector< T > & getVals() const
Returns the members of the distribution.
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
Representation of a vehicle, person, or container.
virtual NumericalID getNumericalID() const =0
return the numerical ID which is only for internal usage
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getChosenSpeedFactor() const =0
long long int NumericalID
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual int getRoutePosition() const =0
return index of edge within route
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:63
virtual const std::list< MSStop > & getStops() const =0
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 double getArrivalPos() const =0
Returns this vehicle's desired arrivalPos for its current route (may change on reroute)
virtual ConstMSRoutePtr getRoutePtr() const =0
Returns the current route.
virtual bool hasValidRoute(std::string &msg, ConstMSRoutePtr route=0) const =0
Validates the current or given route.
virtual double getDepartPos() const =0
Returns this vehicle's real departure position.
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual const MSRoute & getRoute() const =0
Returns the current route.
Definition of vehicle stop (position and duration)
SUMOTime started
the time at which this stop was reached
int parametersSet
Information for the output which parameter were set.
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 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)
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
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.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double departPos
(optional) The position the vehicle shall depart from
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
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,...
Information needed to sort vehicle / transportable output by departure time.
std::map< const SUMOTime, int > departureCounts
Map needed to sort vehicles by departure time.
std::map< const SUMOTime, std::map< const SUMOTrafficObject::NumericalID, std::string > > routeXML
pregenerated route output sorted by time and creation
OutputDevice * routeOut
route output device