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-2024 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>
45#include <microsim/MSEdge.h>
46#include <microsim/MSLane.h>
47#include <microsim/MSLink.h>
48#include <microsim/MSGlobals.h>
49#include <microsim/MSNet.h>
53#include <microsim/MSRoute.h>
56#include <netload/NLHandler.h>
57#include "MSStateHandler.h"
58
59#include <mesosim/MESegment.h>
60#include <mesosim/MELoop.h>
61
62
63// ===========================================================================
64// MSStateTimeHandler method definitions
65// ===========================================================================
66
68MSStateHandler::MSStateTimeHandler::getTime(const std::string& fileName) {
69 // build handler and parser
70 MSStateTimeHandler handler;
71 handler.setFileName(fileName);
72 handler.myTime = -1;
73 SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler);
74 try {
75 if (!parser->parseFirst(fileName)) {
76 delete parser;
77 throw ProcessError(TLF("Can not read XML-file '%'.", fileName));
78 }
79 } catch (ProcessError&) {
80 delete parser;
81 throw;
82 }
83 // parse
84 while (parser->parseNext() && handler.myTime != -1);
85 // clean up
86 if (handler.myTime == -1) {
87 delete parser;
88 throw ProcessError(TLF("Could not parse time from state file '%'", fileName));
89 }
90 delete parser;
91 return handler.myTime;
92}
93
94void
100
101// ===========================================================================
102// method definitions
103// ===========================================================================
104MSStateHandler::MSStateHandler(const std::string& file, const SUMOTime offset) :
105 MSRouteHandler(file, true),
106 myOffset(offset),
107 mySegment(nullptr),
108 myCurrentLane(nullptr),
109 myCurrentLink(nullptr),
110 myAttrs(nullptr),
111 myVCAttrs(nullptr),
112 myLastParameterised(nullptr),
113 myRemoved(0),
114 myConstrainedSignal(nullptr) {
115 myAmLoadingState = true;
116 const std::vector<std::string> vehIDs = OptionsCont::getOptions().getStringVector("load-state.remove-vehicles");
117 myVehiclesToRemove.insert(vehIDs.begin(), vehIDs.end());
119}
120
121
125
126
127void
128MSStateHandler::saveState(const std::string& file, SUMOTime step, bool usePrefix) {
129 OutputDevice& out = OutputDevice::getDevice(file, usePrefix);
130 out.setPrecision(OptionsCont::getOptions().getInt("save-state.precision"));
132 out.writeAttr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").writeAttr("xsi:noNamespaceSchemaLocation", "http://sumo.dlr.de/xsd/state_file.xsd");
133 out.writeAttr(SUMO_ATTR_VERSION, VERSION_STRING);
135 out.writeAttr(SUMO_ATTR_TYPE, MSGlobals::gUseMesoSim ? "meso" : "micro");
136 if (OptionsCont::getOptions().getBool("save-state.constraints")) {
138 }
140 out.writeAttr(SUMO_ATTR_RAIL, true);
141 }
142 if (OptionsCont::getOptions().getBool("save-state.rng")) {
143 saveRNGs(out);
146 }
147 }
151 if (OptionsCont::getOptions().getBool("save-state.transportables")) {
152 if (MSNet::getInstance()->hasPersons()) {
155 out.closeTag();
156 }
157 if (MSNet::getInstance()->hasContainers()) {
160 out.closeTag();
161 }
162 }
164 for (MSEdge* const edge : MSEdge::getAllEdges()) {
166 for (MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*edge); s != nullptr; s = s->getNextSegment()) {
167 s->saveState(out);
168 }
169 } else {
170 for (MSLane* const lane : edge->getLanes()) {
171 lane->saveState(out);
172 }
173 }
174 }
176 out.close();
177}
178
179
180void
182 MSRouteHandler::myStartElement(element, attrs);
184 switch (element) {
185 case SUMO_TAG_SNAPSHOT: {
187 const std::string& version = attrs.getString(SUMO_ATTR_VERSION);
188 if (version != VERSION_STRING) {
189 WRITE_WARNINGF(TL("State was written with sumo version % (present: %)!"), version, VERSION_STRING);
190 }
191 bool ok;
192 if (attrs.getOpt<bool>(SUMO_ATTR_CONSTRAINTS, nullptr, ok, false)) {
194 }
195 if (attrs.getOpt<bool>(SUMO_ATTR_RAIL, nullptr, ok, false)) {
196 // init before loading any vehicles to ensure that driveways are built early
198 }
199 break;
200 }
201 case SUMO_TAG_RNGSTATE: {
202 if (attrs.hasAttribute(SUMO_ATTR_DEFAULT)) {
204 }
207 }
210 }
213 }
216 }
219 }
222 }
223 break;
224 }
225 case SUMO_TAG_RNGLANE: {
226 const int index = attrs.getInt(SUMO_ATTR_INDEX);
227 const std::string state = attrs.getString(SUMO_ATTR_STATE);
228 MSLane::loadRNGState(index, state);
229 break;
230 }
232 bool ok;
233 std::list<MSLane*> activeLanes;
234 const std::vector<std::string>& laneIDs = attrs.get<std::vector<std::string> >(SUMO_ATTR_LANES, nullptr, ok, false);
235 for (const std::string& laneID : laneIDs) {
236 MSLane* lane = MSLane::dictionary(laneID);
237 if (lane == nullptr) {
238 throw ProcessError(TLF("Unknown lane '%' in loaded state.", laneID));
239 }
240 activeLanes.push_back(lane);
241 }
243 break;
244 }
245 case SUMO_TAG_DELAY: {
246 if (myVCAttrs != nullptr) {
247 delete myVCAttrs;
248 }
249 myVCAttrs = attrs.clone();
250 break;
251 }
252 case SUMO_TAG_FLOWSTATE: {
253 bool ok;
255 pars->repetitionsDone = attrs.get<int>(SUMO_ATTR_DONE, pars->id.c_str(), ok);
256 pars->repetitionTotalOffset = attrs.getOptSUMOTimeReporting(SUMO_ATTR_NEXT, pars->id.c_str(), ok, 0);
257 int index = attrs.getInt(SUMO_ATTR_INDEX);
259 break;
260 }
261 case SUMO_TAG_VTYPE: {
263 break;
264 }
265 case SUMO_TAG_VEHICLE: {
267 myAttrs = attrs.clone();
268 break;
269 }
270 case SUMO_TAG_DEVICE: {
271 myDeviceAttrs.push_back(attrs.clone());
272 break;
273 }
276 break;
277 }
278 case SUMO_TAG_SEGMENT: {
279 const std::string& segmentID = attrs.getString(SUMO_ATTR_ID);
280 const MSEdge* const edge = MSEdge::dictionary(segmentID.substr(0, segmentID.rfind(":")));
281 int idx = StringUtils::toInt(segmentID.substr(segmentID.rfind(":") + 1));
283 while (idx-- > 0) {
285 }
286 myQueIndex = 0;
287 break;
288 }
289 case SUMO_TAG_LANE: {
290 bool ok;
291 const std::string laneID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
293 if (myCurrentLane == nullptr) {
294 throw ProcessError(TLF("Unknown lane '%' in loaded state.", laneID));
295 }
296 break;
297 }
299 bool ok;
300 const std::vector<std::string>& vehIDs = attrs.get<std::vector<std::string> >(SUMO_ATTR_VALUE, nullptr, ok, false);
303 } else {
305 }
306 myQueIndex++;
307 break;
308 }
309 case SUMO_TAG_LINK: {
310 bool ok;
311 myCurrentLink = nullptr;
312 const std::string toLaneID = attrs.get<std::string>(SUMO_ATTR_TO, nullptr, ok);
313 for (MSLink* link : myCurrentLane->getLinkCont()) {
314 if (link->getViaLaneOrLane()->getID() == toLaneID) {
315 myCurrentLink = link;
316 }
317 }
318 if (myCurrentLink == nullptr) {
319 throw ProcessError("Unknown link from lane '" + myCurrentLane->getID() + "' to lane '" + toLaneID + "' in loaded state");
320 }
321 break;
322 }
324 bool ok;
325 const std::string vehID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
326 const SUMOTime arrivalTime = attrs.get<SUMOTime>(SUMO_ATTR_ARRIVALTIME, nullptr, ok);
327 const double arrivalSpeed = attrs.get<double>(SUMO_ATTR_ARRIVALSPEED, nullptr, ok);
328 const double leaveSpeed = attrs.get<double>(SUMO_ATTR_DEPARTSPEED, nullptr, ok);
329 const bool setRequest = attrs.get<bool>(SUMO_ATTR_REQUEST, nullptr, ok);
330 const double arrivalSpeedBraking = attrs.get<double>(SUMO_ATTR_ARRIVALSPEEDBRAKING, nullptr, ok);
331 const SUMOTime waitingTime = attrs.get<SUMOTime>(SUMO_ATTR_WAITINGTIME, nullptr, ok);
332 const double dist = attrs.get<double>(SUMO_ATTR_DISTANCE, nullptr, ok);
333 const double latOffset = attrs.getOpt<double>(SUMO_ATTR_POSITION_LAT, nullptr, ok, 0);
334 SUMOVehicle* veh = vc.getVehicle(vehID);
335 myCurrentLink->setApproaching(veh, arrivalTime, arrivalSpeed, leaveSpeed, setRequest, arrivalSpeedBraking, waitingTime, dist, latOffset);
337 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
338 microVeh->loadPreviousApproaching(myCurrentLink, setRequest, arrivalTime, arrivalSpeed, arrivalSpeedBraking, dist, leaveSpeed);
339 }
340 break;
341 }
344 break;
345 }
346 case SUMO_TAG_DRIVEWAY:
347 case SUMO_TAG_SUBDRIVEWAY: {
348 MSDriveWay::loadState(attrs, element);
349 break;
350 }
351 case SUMO_TAG_PARAM: {
352 bool ok;
353 const std::string key = attrs.get<std::string>(SUMO_ATTR_KEY, nullptr, ok);
354 // circumventing empty string test
355 const std::string val = attrs.hasAttribute(SUMO_ATTR_VALUE) ? attrs.getString(SUMO_ATTR_VALUE) : "";
356 assert(myLastParameterised != 0);
357 if (myLastParameterised != nullptr) {
359 }
360 break;
361 }
363 if (attrs.getString(SUMO_ATTR_TYPE) == "person") {
365 }
366 if (attrs.getString(SUMO_ATTR_TYPE) == "container") {
368 }
369 break;
370 case SUMO_TAG_PERSON:
372 myAttrs = attrs.clone();
373 break;
375 bool ok = true;
376 const std::string signalID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
377 if (!MSNet::getInstance()->getTLSControl().knows(signalID)) {
378 throw InvalidArgument("Rail signal '" + signalID + "' in railSignalConstraints loaded from state is not known");
379 }
381 if (myConstrainedSignal == nullptr) {
382 throw InvalidArgument("Traffic light '" + signalID + "' is not a rail signal");
383 }
384 break;
385 }
386 case SUMO_TAG_PREDECESSOR: // intended fall-through
387 case SUMO_TAG_INSERTION_PREDECESSOR: // intended fall-through
388 case SUMO_TAG_FOE_INSERTION: // intended fall-through
389 case SUMO_TAG_INSERTION_ORDER: // intended fall-through
392 break;
393 case SUMO_TAG_TLLOGIC: {
394 bool ok;
395 const std::string tlID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
396 const std::string programID = attrs.get<std::string>(SUMO_ATTR_PROGRAMID, tlID.c_str(), ok);
397 const int phase = attrs.get<int>(SUMO_ATTR_PHASE, tlID.c_str(), ok);
398 const SUMOTime spentDuration = attrs.get<SUMOTime>(SUMO_ATTR_DURATION, tlID.c_str(), ok);
400 MSTrafficLightLogic* tl = tlc.get(tlID, programID);
401 if (tl == nullptr) {
402 if (programID == "online") {
403 WRITE_WARNINGF(TL("Ignoring program '%' for traffic light '%' in loaded state"), programID, tlID);
404 return;
405 } else {
406 throw ProcessError("Unknown program '" + programID + "' for traffic light '" + tlID + "'");
407 }
408 }
409 if (phase >= tl->getPhaseNumber()) {
410 throw ProcessError("Invalid phase '" + toString(phase) + "' for traffic light '" + tlID + "'");
411 }
412 // might not be set if the phase happens to match and there are multiple programs
413 tl->loadState(tlc, myTime, phase, spentDuration);
414 break;
415 }
416 default:
417 break;
418 }
419}
420
421
422void
425 switch (element) {
426 case SUMO_TAG_PERSON:
427 case SUMO_TAG_CONTAINER: {
429 MSTransportable* transportable = tc.get(myAttrs->getString(SUMO_ATTR_ID));
430 transportable->loadState(myAttrs->getString(SUMO_ATTR_STATE));
431 tc.fixLoadCount(transportable);
432 delete myAttrs;
433 myAttrs = nullptr;
434 break;
435 }
436 case SUMO_TAG_SNAPSHOT: {
437 if (myVCAttrs == nullptr) {
438 throw ProcessError(TL("Could not load vehicle control state"));
439 }
446 if (myRemoved > 0) {
447 WRITE_MESSAGEF(TL("Removed % vehicles while loading state."), toString(myRemoved));
449 }
450 break;
451 }
452 default:
453 break;
454 }
455 if (element != SUMO_TAG_PARAM && myVehicleParameter == nullptr && myCurrentVType == nullptr) {
456 myLastParameterised = nullptr;
457 }
458}
459
460
461void
463 assert(myVehicleParameter != nullptr);
465 // the vehicle was already counted in MSVehicleControl::setState
467 // make a copy because myVehicleParameter is reset in closeVehicle()
468 const std::string vehID = myVehicleParameter->id;
469 if (myVehiclesToRemove.count(vehID) == 0) {
471 SUMOVehicle* v = vc.getVehicle(vehID);
472 if (v == nullptr) {
473 throw ProcessError(TLF("Could not load vehicle '%' from state", vehID));
474 }
477
478 if (v->hasDeparted()) {
479 // vehicle already departed: disable pre-insertion rerouting and enable regular routing behavior
480 MSDevice_Routing* routingDevice = static_cast<MSDevice_Routing*>(v->getDevice(typeid(MSDevice_Routing)));
481 if (routingDevice != nullptr) {
483 }
486 // register route for deadlock prevention (vehicleStateChanged would not be called otherwise)
488 }
489 vc.handleTriggeredDepart(v, false);
490 if (v->hasArrived()) {
491 // state was created with active option --keep-after-arrival
492 vc.deleteKeptVehicle(v);
493 }
494 }
495 while (!myDeviceAttrs.empty()) {
496 const std::string attrID = myDeviceAttrs.back()->getString(SUMO_ATTR_ID);
497 for (MSVehicleDevice* const dev : v->getDevices()) {
498 if (dev->getID() == attrID) {
499 dev->loadState(*myDeviceAttrs.back());
500 }
501 }
502 delete myDeviceAttrs.back();
503 myDeviceAttrs.pop_back();
504 }
505 } else {
506 delete myVehicleParameter;
507 myVehicleParameter = nullptr;
508 myRemoved++;
509 }
510 delete myAttrs;
511}
512
513
514void
528
529
530/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define WRITE_MESSAGEF(...)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
@ 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_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_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_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_DRIVEWAY
Saved driveway information.
@ SUMO_TAG_PREDECESSOR
Predecessor constraint on switching a rail signal.
@ SUMO_ATTR_DONE
@ 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_BEGIN
weights: time range begin
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_PHASE
@ SUMO_ATTR_LANES
@ SUMO_ATTR_DEFAULT
@ SUMO_ATTR_ARRIVALSPEEDBRAKING
@ SUMO_ATTR_NEXT
succesor phase index
@ SUMO_ATTR_RNG_DEVICE_TOC
@ SUMO_ATTR_INDEX
@ 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_TYPE
@ SUMO_ATTR_VERSION
@ SUMO_ATTR_ID
@ SUMO_ATTR_RAIL
@ SUMO_ATTR_PROGRAMID
@ SUMO_ATTR_RNG_ROUTEHANDLER
@ SUMO_ATTR_DURATION
@ SUMO_ATTR_RNG_DEVICE
@ SUMO_ATTR_REQUEST
@ SUMO_ATTR_KEY
@ SUMO_ATTR_STATE
The state of a link.
@ SUMO_ATTR_TIME
trigger: the time of the step
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void setFileName(const std::string &name)
Sets the current file name.
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:340
A single mesoscopic segment (cell)
Definition MESegment.h:49
void loadState(const std::vector< std::string > &vehIDs, MSVehicleControl &vc, const SUMOTime blockTime, 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:234
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 SumoRNG * getResponseTimeRNG()
static SumoRNG * getEquipmentRNG()
Definition MSDevice.h:89
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:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition MSEdge.cpp:1086
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:1047
static bool gUseMesoSim
Definition MSGlobals.h:106
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition MSGlobals.h:112
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
static void saveRNGStates(OutputDevice &out)
save random number generator states to the given output device
Definition MSLane.cpp:4546
static void loadRNGState(int index, const std::string &state)
load random number generator state for the given rng index
Definition MSLane.cpp:4556
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2415
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:724
void loadState(const std::vector< std::string > &vehIDs, MSVehicleControl &vc)
Loads the state of this segment with the given parameters.
Definition MSLane.cpp:3683
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NEWROUTE
The vehicle got a new route.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition MSNet.h:451
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1199
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:431
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:378
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1190
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition MSNet.h:421
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.
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;.
static SumoRNG * getParsingRNG()
get parsing RNG
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:261
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
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;.
std::vector< SUMOSAXAttributes * > myDeviceAttrs
cached device attrs (used when loading vehicles)
SUMOSAXAttributes * myVCAttrs
cached attrs for delayed loading of MSVehicleControl state
void myEndElement(int element)
Called when a closing tag occurs.
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.
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)
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 setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime)
Sets the current state variables as loaded from the stream.
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
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.
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
void loadPreviousApproaching(MSLink *link, bool setRequest, SUMOTime arrivalTime, double arrivalSpeed, double arrivalSpeedBraking, double dist, double leaveSpeed)
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 descriptionn.
static Parameterised * addPredecessorConstraint(int element, const SUMOSAXAttributes &attrs, MSRailSignal *rs)
const std::string & getID() const
Returns the id.
Definition Named.h:74
static SumoRNG * getRNG()
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
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.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
bool writeHeader(const SumoXMLTag &rootElement)
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
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:226
static std::string saveState(SumoRNG *rng=nullptr)
save rng state to string
Definition RandHelper.h:212
bool myAllowInternalRoutes
whether references to internal routes are allowed in this context
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
SUMOVTypeParameter * myCurrentVType
The currently parsed vehicle type.
virtual void myEndElement(int element)
Called when a closing tag occurs.
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 MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual bool hasArrived() const =0
Returns whether this object has arrived.
Representation of a vehicle.
Definition SUMOVehicle.h:62
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.
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.