Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSStateHandler.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-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/****************************************************************************/
20// Parser and output filter for routes and vehicles state saving and loading
21/****************************************************************************/
22#include <config.h>
23
24#ifdef HAVE_VERSION_H
25#include <version.h>
26#endif
27
28#include <sstream>
34#include <utils/xml/XMLSubSys.h>
48#include <microsim/MSEdge.h>
49#include <microsim/MSLane.h>
50#include <microsim/MSLink.h>
51#include <microsim/MSGlobals.h>
52#include <microsim/MSNet.h>
56#include <microsim/MSRoute.h>
59#include <netload/NLHandler.h>
60#include "MSStateHandler.h"
61
62#include <mesosim/MESegment.h>
63#include <mesosim/MELoop.h>
64
65// ===========================================================================
66// MSStateTimeHandler method definitions
67// ===========================================================================
68
70MSStateHandler::MSStateTimeHandler::getTime(const std::string& fileName) {
71 // build handler and parser
72 MSStateTimeHandler handler;
73 handler.setFileName(fileName);
74 handler.myTime = -1;
75 SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler);
76 try {
77 if (!parser->parseFirst(fileName)) {
78 delete parser;
79 throw ProcessError(TLF("Can not read XML-file '%'.", fileName));
80 }
81 } catch (ProcessError&) {
82 delete parser;
83 throw;
84 }
85 // parse
86 while (parser->parseNext() && handler.myTime != -1);
87 // clean up
88 if (handler.myTime == -1) {
89 delete parser;
90 throw ProcessError(TLF("Could not parse time from state file '%'", fileName));
91 }
92 delete parser;
93 return handler.myTime;
94}
95
96void
102
103// ===========================================================================
104// method definitions
105// ===========================================================================
106MSStateHandler::MSStateHandler(const std::string& file, const SUMOTime offset) :
107 MSRouteHandler(file, true),
108 myOffset(offset),
109 mySegment(nullptr),
110 myCurrentLane(nullptr),
111 myCurrentLink(nullptr),
112 myAttrs(nullptr),
113 myVCAttrs(nullptr),
114 myCFMAttrs(nullptr),
115 myLastParameterised(nullptr),
116 myRemoved(0),
118 myFlowIndex(-1),
119 myConstrainedSignal(nullptr) {
120 myAmLoadingState = true;
121 const std::vector<std::string> vehIDs = OptionsCont::getOptions().getStringVector("load-state.remove-vehicles");
122 myVehiclesToRemove.insert(vehIDs.begin(), vehIDs.end());
124}
125
126
130
131
132void
133MSStateHandler::saveState(const std::string& file, SUMOTime step, bool usePrefix) {
134 OutputDevice& out = OutputDevice::getDevice(file, usePrefix);
135 const int statePrecision = OptionsCont::getOptions().getInt("save-state.precision");
136 out.setPrecision(statePrecision);
137 const int defaultPrecision = gPrecision;
138 gPrecision = statePrecision;
139 std::map<SumoXMLAttr, std::string> attrs;
140 attrs[SUMO_ATTR_VERSION] = VERSION_STRING;
141 attrs[SUMO_ATTR_TIME] = time2string(step);
142 attrs[SUMO_ATTR_TYPE] = MSGlobals::gUseMesoSim ? "meso" : "micro";
145 }
146 if (OptionsCont::getOptions().getBool("save-state.constraints")) {
147 attrs[SUMO_ATTR_CONSTRAINTS] = "1";
148 }
150 attrs[SUMO_ATTR_RAIL] = "1";
151 }
152 out.writeXMLHeader("snapshot", "state_file.xsd", attrs);
153 if (OptionsCont::getOptions().getBool("save-state.rng")) {
154 saveRNGs(out);
157 }
158 }
160 if (dispatcher != nullptr) {
161 // save early to pre-empty initialization from loaded persons
163 }
167 if (OptionsCont::getOptions().getBool("save-state.transportables")) {
168 if (MSNet::getInstance()->hasPersons()) {
171 out.closeTag();
172 }
173 if (MSNet::getInstance()->hasContainers()) {
176 out.closeTag();
177 }
178 }
180 for (MSEdge* const edge : MSEdge::getAllEdges()) {
182 for (MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*edge); s != nullptr; s = s->getNextSegment()) {
183 s->saveState(out);
184 }
185 } else {
186 for (MSLane* const lane : edge->getLanes()) {
187 lane->saveState(out);
188 }
189 }
190 }
194 out.close();
195 gPrecision = defaultPrecision;
196}
197
198
199void
201 MSRouteHandler::myStartElement(element, attrs);
203 switch (element) {
204 case SUMO_TAG_SNAPSHOT: {
206 const std::string& version = attrs.getString(SUMO_ATTR_VERSION);
207 if (version != VERSION_STRING) {
208 WRITE_WARNINGF(TL("State was written with sumo version % (present: %)!"), version, VERSION_STRING);
209 }
210 bool ok;
211 if (attrs.getOpt<bool>(SUMO_ATTR_CONSTRAINTS, nullptr, ok, false)) {
213 }
214 if (attrs.getOpt<bool>(SUMO_ATTR_RAIL, nullptr, ok, false)) {
215 // init before loading any vehicles to ensure that driveways are built early
217 }
218 myMesoEventCounter = attrs.getOpt<long long int>(SUMO_ATTR_COUNT, nullptr, ok, -1);
219 break;
220 }
221 case SUMO_TAG_RNGSTATE: {
222 if (attrs.hasAttribute(SUMO_ATTR_DEFAULT)) {
224 }
227 }
230 }
233 }
236 }
239 }
242 }
243 break;
244 }
245 case SUMO_TAG_RNGLANE: {
246 const int index = attrs.getInt(SUMO_ATTR_INDEX);
247 const std::string state = attrs.getString(SUMO_ATTR_STATE);
248 MSLane::loadRNGState(index, state);
249 break;
250 }
252 bool ok;
253 std::list<MSLane*> activeLanes;
254 const std::vector<std::string>& laneIDs = attrs.get<std::vector<std::string> >(SUMO_ATTR_LANES, nullptr, ok, false);
255 for (const std::string& laneID : laneIDs) {
256 MSLane* lane = MSLane::dictionary(laneID);
257 if (lane == nullptr) {
258 throw ProcessError(TLF("Unknown lane '%' in loaded state.", laneID));
259 }
260 activeLanes.push_back(lane);
261 }
263 break;
264 }
266 bool ok = true;
267 const SUMOTime lastAdaptation = attrs.get<SUMOTime>(SUMO_ATTR_LAST, nullptr, ok);
268 const int index = attrs.get<int>(SUMO_ATTR_INDEX, nullptr, ok);
269 if (lastAdaptation >= 0) {
270 MSRoutingEngine::initWeightUpdate(lastAdaptation);
271 }
272 MSRoutingEngine::initEdgeWeights(SVC_PASSENGER, lastAdaptation, index);
273 if (OptionsCont::getOptions().getBool("device.rerouting.bike-speeds")) {
275 }
277 for (const MSEdge* e : MSEdge::getAllEdges()) {
278 for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*e); segment != nullptr; segment = segment->getNextSegment()) {
279 segment->resetCachedSpeeds();
280 }
281 }
282 }
283 break;
284 }
285 case SUMO_TAG_EDGE: {
286#ifdef HAVE_FOX
288#endif
289 break;
290 }
291 case SUMO_TAG_CCH_METRIC: {
292#ifdef HAVE_FOX
294#endif
295 break;
296 }
297 case SUMO_TAG_DELAY: {
298 if (myVCAttrs != nullptr) {
299 delete myVCAttrs;
300 }
301 bool ok;
303 myVCAttrs = attrs.clone();
304 break;
305 }
306 case SUMO_TAG_FLOWSTATE: {
307 bool ok;
309 pars->repetitionsDone = attrs.get<int>(SUMO_ATTR_DONE, pars->id.c_str(), ok);
310 pars->repetitionTotalOffset = attrs.getOptSUMOTimeReporting(SUMO_ATTR_NEXT, pars->id.c_str(), ok, 0);
312 myVehicleParameter = pars;
313 break;
314 }
315 case SUMO_TAG_VTYPE: {
317 break;
318 }
319 case SUMO_TAG_VEHICLE: {
321 myAttrs = attrs.clone();
322 break;
323 }
324 case SUMO_TAG_DEVICE: {
325 myDeviceAttrs.push_back(attrs.clone());
326 break;
327 }
329 myCFMAttrs = attrs.clone();
330 break;
331 }
332 case SUMO_TAG_REMINDER: {
333 myReminderAttrs.push_back(attrs.clone());
334 break;
335 }
338 break;
339 }
340 case SUMO_TAG_SEGMENT: {
341 const std::string& segmentID = attrs.getString(SUMO_ATTR_ID);
342 const MSEdge* const edge = MSEdge::dictionary(segmentID.substr(0, segmentID.rfind(":")));
343 int idx = StringUtils::toInt(segmentID.substr(segmentID.rfind(":") + 1));
345 while (idx-- > 0 && mySegment != nullptr) {
347 }
348 if (mySegment == nullptr) {
349 throw ProcessError(TLF("Unknown segment '%' in loaded state.", segmentID));
350 }
351 myQueIndex = 0;
352 break;
353 }
354 case SUMO_TAG_LANE: {
355 bool ok;
356 const std::string laneID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
358 if (myCurrentLane == nullptr) {
359 throw ProcessError(TLF("Unknown lane '%' in loaded state.", laneID));
360 }
361 break;
362 }
364 bool ok;
365 const std::vector<std::string>& vehIDs = attrs.get<std::vector<std::string> >(SUMO_ATTR_VALUE, nullptr, ok, false);
366 std::vector<SUMOVehicle*> vehs;
367 for (const std::string& id : vehIDs) {
368 SUMOVehicle* v = vc.getVehicle(id);
369 // vehicle could be removed due to options
370 if (v != nullptr) {
371 vehs.push_back(v);
372 myArrived.erase(v);
373 }
374 }
376 if (myQueIndex >= mySegment->numQueues()) {
377 throw ProcessError(TLF("Invalid queue index '%' on segment '%'. Check for consistency of lane numbers and queue options.", myQueIndex, mySegment->getID()));
378 }
379 const SUMOTime blockTime = StringUtils::toLong(attrs.getString(SUMO_ATTR_TIME));
380 const SUMOTime entryBlockTime = StringUtils::toLong(attrs.getString(SUMO_ATTR_BLOCKTIME));
381 mySegment->loadState(vehs, blockTime - myOffset, entryBlockTime - myOffset, myQueIndex);
382 if (attrs.hasAttribute(SUMO_ATTR_STATE)) {
384 }
385 myQueIndex++;
386 } else {
388 }
389 break;
390 }
391 case SUMO_TAG_LINK: {
392 bool ok;
393 myCurrentLink = nullptr;
394 const std::string toLaneID = attrs.get<std::string>(SUMO_ATTR_TO, nullptr, ok);
395 for (MSLink* link : myCurrentLane->getLinkCont()) {
396 if (link->getViaLaneOrLane()->getID() == toLaneID) {
397 myCurrentLink = link;
398 }
399 }
400 if (myCurrentLink == nullptr) {
401 throw ProcessError("Unknown link from lane '" + myCurrentLane->getID() + "' to lane '" + toLaneID + "' in loaded state");
402 }
403 break;
404 }
406 bool ok;
407 const std::string vehID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
408 const SUMOTime arrivalTime = attrs.get<SUMOTime>(SUMO_ATTR_ARRIVALTIME, nullptr, ok);
409 const double arrivalSpeed = attrs.get<double>(SUMO_ATTR_ARRIVALSPEED, nullptr, ok);
410 const double leaveSpeed = attrs.get<double>(SUMO_ATTR_DEPARTSPEED, nullptr, ok);
411 const bool setRequest = attrs.get<bool>(SUMO_ATTR_REQUEST, nullptr, ok);
412 const double arrivalSpeedBraking = attrs.get<double>(SUMO_ATTR_ARRIVALSPEEDBRAKING, nullptr, ok);
413 const SUMOTime waitingTime = attrs.get<SUMOTime>(SUMO_ATTR_WAITINGTIME, nullptr, ok);
414 const double dist = attrs.get<double>(SUMO_ATTR_DISTANCE, nullptr, ok);
415 const double latOffset = attrs.getOpt<double>(SUMO_ATTR_POSITION_LAT, nullptr, ok, 0);
416 SUMOVehicle* veh = vc.getVehicle(vehID);
417 myCurrentLink->setApproaching(veh, arrivalTime, arrivalSpeed, leaveSpeed, setRequest, arrivalSpeedBraking, waitingTime, dist, latOffset);
419 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
420 microVeh->loadPreviousApproaching(myCurrentLink, setRequest, arrivalTime, arrivalSpeed, arrivalSpeedBraking, dist, leaveSpeed);
421 }
422 break;
423 }
426 break;
427 }
430 MSDriveWay::loadState(attrs, element);
431 break;
432 }
433 case SUMO_TAG_PARAM: {
434 bool ok;
435 const std::string key = attrs.get<std::string>(SUMO_ATTR_KEY, nullptr, ok);
436 // circumventing empty string test
437 const std::string val = attrs.hasAttribute(SUMO_ATTR_VALUE) ? attrs.getString(SUMO_ATTR_VALUE) : "";
438 assert(myLastParameterised != 0);
439 if (myLastParameterised != nullptr) {
441 }
442 break;
443 }
445 if (attrs.getString(SUMO_ATTR_TYPE) == "person") {
447 }
448 if (attrs.getString(SUMO_ATTR_TYPE) == "container") {
450 }
451 break;
452 case SUMO_TAG_PERSON:
454 myAttrs = attrs.clone();
455 break;
457 bool ok = true;
458 const std::string signalID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
459 if (!MSNet::getInstance()->getTLSControl().knows(signalID)) {
460 throw InvalidArgument("Rail signal '" + signalID + "' in railSignalConstraints loaded from state is not known");
461 }
463 if (myConstrainedSignal == nullptr) {
464 throw InvalidArgument("Traffic light '" + signalID + "' is not a rail signal");
465 }
466 break;
467 }
468 case SUMO_TAG_PREDECESSOR: // intended fall-through
469 case SUMO_TAG_INSERTION_PREDECESSOR: // intended fall-through
470 case SUMO_TAG_FOE_INSERTION: // intended fall-through
471 case SUMO_TAG_INSERTION_ORDER: // intended fall-through
474 break;
475 case SUMO_TAG_TLLOGIC: {
476 bool ok;
477 const std::string tlID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
478 const std::string programID = attrs.get<std::string>(SUMO_ATTR_PROGRAMID, tlID.c_str(), ok);
479 const int phase = attrs.get<int>(SUMO_ATTR_PHASE, tlID.c_str(), ok);
480 const SUMOTime spentDuration = attrs.get<SUMOTime>(SUMO_ATTR_DURATION, tlID.c_str(), ok);
481 const SUMOTime nextSwitch = attrs.get<SUMOTime>(SUMO_ATTR_UNTIL, tlID.c_str(), ok);
482 const SUMOTime timeInCycle = attrs.get<SUMOTime>(SUMO_ATTR_CYCLETIME, tlID.c_str(), ok);
483 const bool active = attrs.get<bool>(SUMO_ATTR_ACTIVE, tlID.c_str(), ok);
485 MSTrafficLightLogic* tl = tlc.get(tlID, programID);
486 if (tl == nullptr) {
487 if (programID == "online") {
488 WRITE_WARNINGF(TL("Ignoring program '%' for traffic light '%' in loaded state"), programID, tlID);
489 return;
490 } else {
491 throw ProcessError("Unknown program '" + programID + "' for traffic light '" + tlID + "'");
492 }
493 }
494 if (phase >= tl->getPhaseNumber()) {
495 throw ProcessError("Invalid phase '" + toString(phase) + "' for traffic light '" + tlID + "'");
496 }
497 // might not be set if the phase happens to match and there are multiple programs
498 tl->loadState(tlc, myTime, phase, spentDuration, nextSwitch, timeInCycle, active);
499 break;
500 }
503 break;
506 // the detector may belong to an output which is not loaded
507 if (det != nullptr) {
508 det->loadState(attrs, myOffset);
509 }
510 break;
511 }
512 case SUMO_TAG_DISPATCHER: {
513 bool ok = true;
514 SUMOTime next = attrs.get<SUMOTime>(SUMO_ATTR_NEXT, "dispatcher", ok);
517 break;
518 }
519 default:
520 break;
521 }
522}
523
524
525void
528 switch (element) {
529 case SUMO_TAG_PERSON:
530 case SUMO_TAG_CONTAINER: {
532 MSTransportable* transportable = tc.get(myAttrs->getString(SUMO_ATTR_ID));
533 transportable->loadState(myAttrs->getString(SUMO_ATTR_STATE));
534 tc.fixLoadCount(transportable);
535 delete myAttrs;
536 myAttrs = nullptr;
537 break;
538 }
539 case SUMO_TAG_FLOWSTATE: {
541 myVehicleParameter = nullptr;
542 break;
543 }
544 case SUMO_TAG_SNAPSHOT: {
545 if (myVCAttrs == nullptr) {
546 throw ProcessError(TL("Could not load vehicle control state"));
547 }
556 if (myRemoved > 0) {
557 WRITE_MESSAGEF(TL("Removed % vehicles while loading state."), toString(myRemoved));
559 }
560 for (SUMOVehicle* v : myArrived) {
561 // state was created with active option --keep-after-arrival
562 vc.deleteKeptVehicle(v);
563 }
565 for (MSVehicleControl::constVehIt i = vc.loadedVehBegin(); i != vc.loadedVehEnd(); ++i) {
566 MSVehicle* microVeh = dynamic_cast<MSVehicle*>((*i).second);
567 if (microVeh->hasDeparted() && microVeh->getLane() != nullptr) {
568 // occupancy update must happen after all lane states have been loaded
569 microVeh->updateBestLanes();
570 }
571 }
572 }
575 }
577 break;
578 }
579 default:
580 break;
581 }
582 if (element != SUMO_TAG_PARAM && myVehicleParameter == nullptr && myCurrentVType == nullptr) {
583 myLastParameterised = nullptr;
584 }
585}
586
587
588void
590 assert(myVehicleParameter != nullptr);
592 // the vehicle was already counted in MSVehicleControl::setState
594 // make a copy because myVehicleParameter is reset in closeVehicle()
595 const std::string vehID = myVehicleParameter->id;
596 if (myVehiclesToRemove.count(vehID) == 0) {
597
598 // devices that influence simulation behavior must replicate stochastic assignment
599 // also, setting the parameter avoids extra calls to MSDevice::myEquipmentRNG (which would pollute replication)
600 std::vector<std::string> deviceNames;
601 for (auto attrs : myDeviceAttrs) {
602 deviceNames.push_back(MSDevice::getDeviceName(attrs->getString(SUMO_ATTR_ID)));
603 }
606 SUMOVehicle* v = vc.getVehicle(vehID);
607 // special case: transportable devices are not assigned by options
608 if (std::find(deviceNames.begin(), deviceNames.end(), "person") != deviceNames.end()) {
609 dynamic_cast<MSBaseVehicle*>(v)->initTransportableDevice(true);
610 }
611 if (std::find(deviceNames.begin(), deviceNames.end(), "container") != deviceNames.end()) {
612 dynamic_cast<MSBaseVehicle*>(v)->initTransportableDevice(false);
613 }
614 // clean up added param after initializing devices in closeVehicle
616 if (v == nullptr) {
617 throw ProcessError(TLF("Could not load vehicle '%' from state", vehID));
618 }
621
622 if (v->hasDeparted()) {
623 // vehicle already departed: disable pre-insertion rerouting and enable regular routing behavior
624 MSDevice_Routing* routingDevice = static_cast<MSDevice_Routing*>(v->getDevice(typeid(MSDevice_Routing)));
625 if (routingDevice != nullptr) {
627 }
630 // register route for deadlock prevention (vehicleStateChanged would not be called otherwise)
632 }
633 vc.handleTriggeredDepart(v, false);
634 if (v->hasArrived()) {
635 myArrived.insert(v);
636 }
637 }
638 while (!myDeviceAttrs.empty()) {
639 const std::string attrID = myDeviceAttrs.back()->getString(SUMO_ATTR_ID);
640 for (MSVehicleDevice* const dev : v->getDevices()) {
641 if (dev->getID() == attrID) {
642 dev->loadState(*myDeviceAttrs.back());
643 }
644 }
645 delete myDeviceAttrs.back();
646 myDeviceAttrs.pop_back();
647 }
648 bool ok = true;
649 while (!myReminderAttrs.empty()) {
650 const std::string attrID = myReminderAttrs.back()->getString(SUMO_ATTR_ID);
651 const SUMOTime time = myReminderAttrs.back()->get<SUMOTime>(SUMO_ATTR_TIME, nullptr, ok, false);
652 const double pos = myReminderAttrs.back()->get<double>(SUMO_ATTR_POSITION, nullptr, ok, false);
653 const auto& remDict = MSNet::getInstance()->getDetectorControl().getAllReminders();
654 auto it = remDict.find(attrID);
655 if (it != remDict.end()) {
656 it->second->loadReminderState(v->getNumericalID(), time, pos);
657 } else {
658 // reminders of vehicle devices (e.g. tripinfo in meso)
659 for (MSVehicleDevice* const dev : v->getDevices()) {
660 if (dev->getDescription() == attrID) {
661 dev->loadReminderState(v->getNumericalID(), time, pos);
662 }
663 }
664 }
665 delete myReminderAttrs.back();
666 myReminderAttrs.pop_back();
667 }
668 if (myCFMAttrs != nullptr) {
669 assert(!MSGlobals::gUseMesoSim);
670 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(v);
671 const MSCFModel::VehicleVariables* vars = microVeh->getCarFollowVariables();
672 if (vars != nullptr) {
673 const_cast<MSCFModel::VehicleVariables*>(vars)->loadState(*myCFMAttrs);
674 }
675 delete myCFMAttrs;
676 myCFMAttrs = nullptr;
677 }
678 } else {
679 const std::string embeddedRouteID = "!" + myVehicleParameter->id;
680 if (MSRoute::hasRoute(embeddedRouteID)) {
681 ConstMSRoutePtr embedded = MSRoute::dictionary(embeddedRouteID);
682 embedded->checkRemoval();
683 }
684 delete myVehicleParameter;
685
686 myVehicleParameter = nullptr;
687 myRemoved++;
688 while (!myDeviceAttrs.empty()) {
689 delete myDeviceAttrs.back();
690 myDeviceAttrs.pop_back();
691 }
692 while (!myReminderAttrs.empty()) {
693 delete myReminderAttrs.back();
694 myReminderAttrs.pop_back();
695 }
696 }
697 delete myAttrs;
698}
699
700
701void
715
716
717/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_MESSAGEF(...)
Definition MsgHandler.h:301
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:47
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SUMO_TAG_RAILSIGNAL_CONSTRAINTS
Constraints on switching a rail signal.
@ SUMO_TAG_BIDI_PREDECESSOR
Predecessor constraint for rail signal before bidirectional section.
@ SUMO_TAG_LINK
Link information for state-saving.
@ SUMO_TAG_TRANSPORTABLES
@ SUMO_TAG_APPROACHING
Link-approaching vehicle information for state-saving.
@ SUMO_TAG_INSERTION_PREDECESSOR
Predecessor constraint on insertion before rail signal.
@ SUMO_TAG_WAUT_SWITCH
@ SUMO_TAG_DEVICE
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_SUBDRIVEWAY
@ SUMO_TAG_RNGLANE
@ SUMO_TAG_EDGECONTROL
the internal state for edge control
@ SUMO_TAG_FLOWSTATE
a flow state definition (used when saving and loading simulatino state)
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_RAILSIGNAL_CONSTRAINT_TRACKER
Saved state for constraint tracker.
@ SUMO_TAG_RNGSTATE
@ SUMO_TAG_REMINDER
@ SUMO_TAG_DISPATCHER
Dispatcher state for saving.
@ SUMO_TAG_CCH_METRIC
the arcs of a CCH metric that lag behind the edge speeds
@ SUMO_TAG_CFM_VARIABLES
@ SUMO_TAG_DELAY
@ SUMO_TAG_TLLOGIC
a traffic light logic
@ SUMO_TAG_FOE_INSERTION
Predecessor constraint on switching a rail signal.
@ SUMO_TAG_CONTAINER
@ SUMO_TAG_VIEWSETTINGS_VEHICLES
@ SUMO_TAG_ROUTINGENGINE
the internal state for MSRoutingEngine
@ SUMO_TAG_SNAPSHOT
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_SEGMENT
segment of a lane
@ SUMO_TAG_PARAM
parameter associated to a certain key
@ SUMO_TAG_INSERTION_ORDER
Predecessor constraint on insertion before rail signal.
@ SUMO_TAG_PERSON
@ SUMO_TAG_VEHICLETRANSFER
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
@ SUMO_TAG_DRIVEWAY
Saved driveway information.
@ SUMO_TAG_PREDECESSOR
Predecessor constraint on switching a rail signal.
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_DONE
@ SUMO_ATTR_LAST
@ SUMO_ATTR_NUMBER
@ SUMO_ATTR_ARRIVALSPEED
@ SUMO_ATTR_CONSTRAINTS
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_RNG_INSERTIONCONTROL
@ SUMO_ATTR_ARRIVALTIME
@ SUMO_ATTR_WAITINGTIME
@ SUMO_ATTR_VALUE
@ SUMO_ATTR_RNG_DRIVERSTATE
@ SUMO_ATTR_WAUT_ID
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_PHASE
@ SUMO_ATTR_LANES
@ SUMO_ATTR_DEFAULT
@ SUMO_ATTR_ARRIVALSPEEDBRAKING
@ SUMO_ATTR_DECEL
@ SUMO_ATTR_NEXT
succesor phase index
@ SUMO_ATTR_RNG_DEVICE_TOC
@ SUMO_ATTR_INDEX
@ SUMO_ATTR_BLOCKTIME
@ SUMO_ATTR_DEPARTSPEED
@ SUMO_ATTR_TO
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_RNG_DEVICE_BT
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_SPEEDFACTOR
@ SUMO_ATTR_JUNCTION_ID
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_VERSION
@ SUMO_ATTR_ID
@ SUMO_ATTR_UNTIL
@ SUMO_ATTR_RAIL
@ SUMO_ATTR_LOADERTIME
@ SUMO_ATTR_PROGRAMID
@ SUMO_ATTR_RNG_ROUTEHANDLER
@ SUMO_ATTR_DURATION
@ SUMO_ATTR_RNG_DEVICE
@ SUMO_ATTR_REQUEST
@ SUMO_ATTR_COUNT
@ SUMO_ATTR_KEY
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_CYCLETIME
@ SUMO_ATTR_STATE
The state of a link.
@ SUMO_ATTR_TIME
trigger: the time of the step
@ SUMO_ATTR_ACTIVE
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:27
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
void setFileName(const std::string &name)
Sets the current file name.
static void setEventCounter(long long int counter)
Definition MELoop.h:114
static long long int getEventCounter()
the number of leader events so far (for saving and loading state)
Definition MELoop.h:110
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:435
A single mesoscopic segment (cell)
Definition MESegment.h:50
int numQueues() const
return the number of queues
Definition MESegment.h:238
virtual void loadQueueExtraState(int, const std::string &, SUMOTime)
Definition MESegment.h:219
void loadState(const std::vector< SUMOVehicle * > &vehs, const SUMOTime blockTime, const SUMOTime entryBlockTime, const int queIdx)
Loads the state of this segment with the given parameters.
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition MESegment.h:274
The base class for microscopic and mesoscopic vehicles.
bool hasDeparted() const
Returns whether this vehicle has already departed.
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
const std::map< std::string, MSMoveReminder * > & getAllReminders()
retrieve reminders of all detectors (for loading state)
void saveState(OutputDevice &out) const
Saves the state of all detectors.
Base of value-generating classes (detectors)
virtual void loadState(const SUMOSAXAttributes &, const SUMOTime)
Loads the state, shifting all times by the given offset.
static SumoRNG * getRNG()
A device that performs vehicle rerouting based on current edge speeds.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
static SUMOTime getNextDispatchTime()
static void finalizeLoadState()
call during state loading after all transportables are loaded
static void initDispatch(SUMOTime next=-1)
initialize the dispatch algorithm
static MSDispatch * getDispatchAlgorithm()
static SumoRNG * getResponseTimeRNG()
static const std::string LOADSTATE_DEVICENAMES
Definition MSDevice.h:102
static SumoRNG * getEquipmentRNG()
Definition MSDevice.h:92
static std::string getDeviceName(const std::string &id)
extracts the deviceName from the id (which includes holder id) and is subject to special cases
Definition MSDevice.cpp:197
An algorithm that performs distpach for a taxi fleet.
Definition MSDispatch.h:114
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
virtual void saveState(OutputDevice &out, SUMOTime nextDispatch) const
Saves the state of the device.
static bool haveDriveWays()
Definition MSDriveWay.h:72
static void loadState(const SUMOSAXAttributes &attrs, int tag)
void setActiveLanes(std::list< MSLane * > lanes)
Reconstruct the current state.
void saveState(OutputDevice &out)
Saves the current state into the given stream.
A road/street connecting two junctions.
Definition MSEdge.h:78
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition MSEdge.cpp:1157
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:1117
static bool gUseMesoSim
Definition MSGlobals.h:106
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition MSGlobals.h:115
bool addFlow(SUMOVehicleParameter *const pars, int index=-1)
Adds parameter for a vehicle flow for departure.
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
SumoRNG * getFlowRNG()
retrieve internal RNG
void saveState(OutputDevice &out)
Saves the current state into the given stream.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
void loadState(const std::vector< SUMOVehicle * > &vehs)
Loads the state of this segment with the given parameters.
Definition MSLane.cpp:3820
static void saveRNGStates(OutputDevice &out)
save random number generator states to the given output device
Definition MSLane.cpp:4763
static void loadRNGState(int index, const std::string &state)
load random number generator state for the given rng index
Definition MSLane.cpp:4773
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2538
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:750
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NEWROUTE
The vehicle got a new route.
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition MSNet.h:466
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition MSNet.h:476
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1326
void setLoaderTime(SUMOTime time)
Definition MSNet.cpp:1158
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:456
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1317
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition MSNet.h:446
static void loadState(const SUMOSAXAttributes &attrs)
loads the constraint state from the given attrs
static void clearAll()
Remove all constraints before quick-loading state.
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
static MSRailSignalControl & getInstance()
A signal for rails.
Parser and container for routes during their loading.
void myEndElement(int element) override
Called when a closing tag occurs.
bool myAmLoadingState
whether a state file is being loaded
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
virtual void closeVehicle() override
Ends the processing of a vehicle (note: is virtual because is reimplemented in MSStateHandler)
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition MSRoute.cpp:273
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
Definition MSRoute.cpp:159
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:116
static void saveState(OutputDevice &out)
Saves the state (i.e. recorded speeds)
static void initEdgeWeights(SUMOVehicleClass svc, SUMOTime lastAdaption=-1, int index=-1)
initialize the edge weights if not done before
static void loadCCHMetric(const SUMOSAXAttributes &attrs)
Loads the arcs of a CCH metric that lag behind the speeds.
static void initWeightUpdate(SUMOTime lastAdaption=- 1)
intialize period edge weight update
static void loadState(const SUMOSAXAttributes &attrs)
Loads the state.
handler to read only the simulation time from a state
static SUMOTime getTime(const std::string &fileName)
parse time from state file
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Callback method for an opening tag to implement by derived classes.
MSRailSignal * myConstrainedSignal
rail signal for which constraints are being loaded
SUMOSAXAttributes * myAttrs
cached attrs (used when loading vehicles or transportables)
MSStateHandler(const std::string &file, const SUMOTime offset)
standard constructor
long long int myMesoEventCounter
the loaded counter of meso leader events (-1 if not given)
static void saveState(const std::string &file, SUMOTime step, bool usePrefix=true)
Saves the current state.
int myQueIndex
que index
SUMOTime myTime
time
std::set< std::string > myVehiclesToRemove
vehicles that shall be removed when loading state
int myRemoved
vehicles that were removed when loading state
MSLink * myCurrentLink
current link being loaded
MESegment * mySegment
segment
MSLane * myCurrentLane
current lane being loaded
static void saveRNGs(OutputDevice &out)
save the state of random number generators
const SUMOTime myOffset
offset
Parameterised * myLastParameterised
the last object that potentially carries parameters
void closeVehicle()
Ends the processing of a vehicle.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
SUMOSAXAttributes * myCFMAttrs
std::vector< SUMOSAXAttributes * > myDeviceAttrs
cached device and reminder attrs (used when loading vehicles)
std::vector< SUMOSAXAttributes * > myReminderAttrs
SUMOSAXAttributes * myVCAttrs
cached attrs for delayed loading of MSVehicleControl state
std::set< SUMOVehicle * > myArrived
vehicles that have arrived
void myEndElement(int element)
Called when a closing tag occurs.
int myFlowIndex
index of the currently parse flowState
virtual ~MSStateHandler()
standard destructor
MSTrafficLightLogic * getDefault() const
return the default program (that last used program except TRACI_PROGRAM)
A class that stores and controls tls and switching of their programs.
bool knows(const std::string &id) const
Returns the information whether the named tls is stored.
void saveState(OutputDevice &out)
Saves the current tls states into the given stream.
void loadWAUTSwitch(const std::string &wautID, const std::string &junctionID, const std::string &to)
Restores a WAUT switch that waited for its switching point when the state was saved.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
The parent class for traffic light logics.
virtual int getPhaseNumber() const =0
Returns the number of phases.
virtual void loadState(MSTLLogicControl &tlcontrol, SUMOTime t, int step, SUMOTime spentDuration, SUMOTime nextSwitch, SUMOTime timeInCycle, bool active)
restores the tls state
void loadState(const std::string &state)
Reconstruct the current state.
void fixLoadCount(const MSTransportable *transportable)
decrement counter to avoid double counting transportables loaded from state
void saveState(OutputDevice &out)
Saves the current state into the given stream.
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
void loadState(const std::string &state)
Reconstructs the current state.
The class responsible for building and deletion of vehicles.
void discountStateRemoved(int n)
discount vehicles that were removed during state loading
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void deleteKeptVehicle(SUMOVehicle *veh)
when a vehicle is kept after arrival, schedule later deletion
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
void handleTriggeredDepart(SUMOVehicle *v, bool add)
register / unregister depart-triggered vehicles with edges
void saveState(OutputDevice &out)
Saves the current state into the given stream.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime, double maxSpeedFactor, double minDecel)
Sets the current state variables as loaded from the stream.
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
void loadPreviousApproaching(MSLink *link, bool setRequest, SUMOTime arrivalTime, double arrivalSpeed, double arrivalSpeedBraking, double dist, double leaveSpeed)
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
Definition MSVehicle.h:994
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
void saveState(OutputDevice &out)
Saves the current state into the given stream.
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset, MSVehicleControl &vc)
Loads one transfer vehicle state from the given description.
static Parameterised * addPredecessorConstraint(int element, const SUMOSAXAttributes &attrs, MSRailSignal *rs)
const std::string & getID() const
Returns the id.
Definition Named.h:73
T get(const std::string &id) const
Retrieves an item.
static SumoRNG * getRNG()
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
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 OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
static void loadState(const std::string &state, SumoRNG *rng=nullptr)
load rng state from string
Definition RandHelper.h:232
static std::string saveState(SumoRNG *rng=nullptr)
save rng state to string
Definition RandHelper.h:219
bool myAllowInternalRoutes
whether references to internal routes are allowed in this context
static SumoRNG * getParsingRNG()
get parsing RNG
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
SUMOVTypeParameter * myCurrentVType
The currently parsed vehicle type.
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 getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual SUMOSAXAttributes * clone() const =0
return a new deep-copy attributes object
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
int getInt(int id) const
Returns the int-value of the named (by its enum-value) attribute.
double getFloat(int id) const
Returns the double-value of the named (by its enum-value) attribute.
SAX-reader encapsulation containing binary reader.
bool parseFirst(std::string systemID)
Start parsing the given file using parseFirst of myXMLReader.
bool parseNext()
Continue a progressive parse started by parseFirst.
virtual NumericalID getNumericalID() const =0
return the numerical ID which is only for internal usage
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual bool hasArrived() const =0
Returns whether this object has arrived.
Representation of a vehicle.
Definition SUMOVehicle.h:63
virtual void setChosenSpeedFactor(const double factor)=0
virtual const std::vector< MSVehicleDevice * > & getDevices() const =0
Returns this vehicle's devices.
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)=0
Loads the state of this vehicle from the given description.
Structure representing possible vehicle parameter.
long long int repetitionsDone
The number of times the vehicle was already inserted.
SUMOTime repetitionTotalOffset
The offset between depart and the time for the next vehicle insertions.
std::string id
The vehicle's id.
static SUMOVehicleParameter * parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs, const bool hardFail, const bool needID, const SUMOTime beginDefault, const SUMOTime endDefault, const bool allowInternalRoutes=false)
Parses a flow's attributes.
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,...
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler, const bool isNet=false, const bool isRoute=false)
Builds a reader and assigns the handler to it.