Eclipse SUMO - Simulation of Urban MObility
MSStateHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
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>
44 #include <microsim/MSEdge.h>
45 #include <microsim/MSLane.h>
46 #include <microsim/MSLink.h>
47 #include <microsim/MSGlobals.h>
48 #include <microsim/MSNet.h>
51 #include <microsim/MSRoute.h>
53 #include <microsim/MSDriverState.h>
54 #include <netload/NLHandler.h>
55 #include "MSStateHandler.h"
56 
57 #include <mesosim/MESegment.h>
58 #include <mesosim/MELoop.h>
59 
60 
61 // ===========================================================================
62 // MSStateTimeHandler method definitions
63 // ===========================================================================
64 
66 MSStateHandler::MSStateTimeHandler::getTime(const std::string& fileName) {
67  // build handler and parser
68  MSStateTimeHandler handler;
69  handler.setFileName(fileName);
70  handler.myTime = -1;
71  SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler);
72  if (!parser->parseFirst(fileName)) {
73  delete parser;
74  throw ProcessError("Can not read XML-file '" + fileName + "'.");
75  }
76  // parse
77  while (parser->parseNext() && handler.myTime != -1);
78  // clean up
79  if (handler.myTime == -1) {
80  delete parser;
81  throw ProcessError("Could not parse time from state file '" + fileName + "'");
82  }
83  delete parser;
84  return handler.myTime;
85 }
86 
87 void
89  if (element == SUMO_TAG_SNAPSHOT) {
91  }
92 }
93 
94 // ===========================================================================
95 // method definitions
96 // ===========================================================================
97 MSStateHandler::MSStateHandler(const std::string& file, const SUMOTime offset) :
98  MSRouteHandler(file, true),
99  myOffset(offset),
100  mySegment(nullptr),
101  myCurrentLane(nullptr),
102  myCurrentLink(nullptr),
103  myAttrs(nullptr),
104  myVCAttrs(nullptr),
105  myLastParameterised(nullptr),
106  myRemoved(0),
107  myConstrainedSignal(nullptr) {
108  myAmLoadingState = true;
109  const std::vector<std::string> vehIDs = OptionsCont::getOptions().getStringVector("load-state.remove-vehicles");
110  myVehiclesToRemove.insert(vehIDs.begin(), vehIDs.end());
111 }
112 
113 
115  delete myVCAttrs;
116 }
117 
118 
119 void
120 MSStateHandler::saveState(const std::string& file, SUMOTime step) {
122  out.setPrecision(OptionsCont::getOptions().getInt("save-state.precision"));
124  out.writeAttr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").writeAttr("xsi:noNamespaceSchemaLocation", "http://sumo.dlr.de/xsd/state_file.xsd");
125  out.writeAttr(SUMO_ATTR_VERSION, VERSION_STRING);
127  out.writeAttr(SUMO_ATTR_TYPE, MSGlobals::gUseMesoSim ? "meso" : "micro");
128  if (OptionsCont::getOptions().getBool("save-state.constraints")) {
129  out.writeAttr(SUMO_ATTR_CONSTRAINTS, true);
130  }
131  if (OptionsCont::getOptions().getBool("save-state.rng")) {
132  saveRNGs(out);
133  }
137  if (OptionsCont::getOptions().getBool("save-state.transportables")) {
138  if (MSNet::getInstance()->hasPersons()) {
141  out.closeTag();
142  }
143  if (MSNet::getInstance()->hasContainers()) {
146  out.closeTag();
147  }
148  }
151  for (int i = 0; i < MSEdge::dictSize(); i++) {
152  for (MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*MSEdge::getAllEdges()[i]); s != nullptr; s = s->getNextSegment()) {
153  s->saveState(out);
154  }
155  }
156  } else {
157  for (int i = 0; i < MSEdge::dictSize(); i++) {
158  const std::vector<MSLane*>& lanes = MSEdge::getAllEdges()[i]->getLanes();
159  for (std::vector<MSLane*>::const_iterator it = lanes.begin(); it != lanes.end(); ++it) {
160  (*it)->saveState(out);
161  }
162  }
163  }
165  out.close();
166 }
167 
168 
169 void
171  MSRouteHandler::myStartElement(element, attrs);
173  switch (element) {
174  case SUMO_TAG_SNAPSHOT: {
176  const std::string& version = attrs.getString(SUMO_ATTR_VERSION);
177  if (version != VERSION_STRING) {
178  WRITE_WARNING("State was written with sumo version " + version + " (present: " + VERSION_STRING + ")!");
179  }
180  bool ok;
181  if (attrs.getOpt<bool>(SUMO_ATTR_CONSTRAINTS, nullptr, ok, false)) {
183  }
184  break;
185  }
186  case SUMO_TAG_RNGSTATE: {
187  if (attrs.hasAttribute(SUMO_ATTR_DEFAULT)) {
189  }
192  }
195  }
196  if (attrs.hasAttribute(SUMO_ATTR_RNG_DEVICE)) {
198  }
201  }
204  }
207  }
208  break;
209  }
210  case SUMO_TAG_RNGLANE: {
211  const int index = attrs.getInt(SUMO_ATTR_INDEX);
212  const std::string state = attrs.getString(SUMO_ATTR_STATE);
213  MSLane::loadRNGState(index, state);
214  break;
215  }
216  case SUMO_TAG_DELAY: {
217  if (myVCAttrs != nullptr) {
218  delete myVCAttrs;
219  }
220  myVCAttrs = attrs.clone();
221  break;
222  }
223  case SUMO_TAG_FLOWSTATE: {
225  pars->id = attrs.getString(SUMO_ATTR_ID);
226  bool ok;
227  if (attrs.getOpt<bool>(SUMO_ATTR_REROUTE, nullptr, ok, false)) {
229  }
231  attrs.getInt(SUMO_ATTR_INDEX));
232  break;
233  }
234  case SUMO_TAG_VTYPE: {
236  break;
237  }
238  case SUMO_TAG_VEHICLE: {
240  myAttrs = attrs.clone();
241  break;
242  }
243  case SUMO_TAG_DEVICE: {
244  myDeviceAttrs.push_back(attrs.clone());
245  break;
246  }
249  break;
250  }
251  case SUMO_TAG_SEGMENT: {
252  const std::string& segmentID = attrs.getString(SUMO_ATTR_ID);
253  const MSEdge* const edge = MSEdge::dictionary(segmentID.substr(0, segmentID.rfind(":")));
254  int idx = StringUtils::toInt(segmentID.substr(segmentID.rfind(":") + 1));
256  while (idx-- > 0) {
258  }
259  myQueIndex = 0;
260  break;
261  }
262  case SUMO_TAG_LANE: {
263  bool ok;
264  const std::string laneID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
266  if (myCurrentLane == nullptr) {
267  throw ProcessError("Unknown lane '" + laneID + "' in loaded state.");
268  }
269  break;
270  }
272  try {
273  const std::vector<std::string>& vehIDs = attrs.getStringVector(SUMO_ATTR_VALUE);
276  } else {
277  myCurrentLane->loadState(vehIDs, MSNet::getInstance()->getVehicleControl());
278  }
279  } catch (EmptyData&) {} // attr may be empty
280  myQueIndex++;
281  break;
282  }
283  case SUMO_TAG_LINK: {
284  bool ok;
285  myCurrentLink = nullptr;
286  const std::string toLaneID = attrs.get<std::string>(SUMO_ATTR_TO, nullptr, ok);
287  for (MSLink* link : myCurrentLane->getLinkCont()) {
288  if (link->getViaLaneOrLane()->getID() == toLaneID) {
289  myCurrentLink = link;
290  }
291  }
292  if (myCurrentLink == nullptr) {
293  throw ProcessError("Unknown link from lane '" + myCurrentLane->getID() + "' to lane '" + toLaneID + "' in loaded state");
294  }
295  break;
296  }
297  case SUMO_TAG_APPROACHING: {
298  bool ok;
299  const std::string vehID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
300  const SUMOTime arrivalTime = attrs.get<SUMOTime>(SUMO_ATTR_ARRIVALTIME, nullptr, ok);
301  const double arrivalSpeed = attrs.get<double>(SUMO_ATTR_ARRIVALSPEED, nullptr, ok);
302  const double leaveSpeed = attrs.get<double>(SUMO_ATTR_DEPARTSPEED, nullptr, ok);
303  const bool setRequest = attrs.get<bool>(SUMO_ATTR_REQUEST, nullptr, ok);
304  const SUMOTime arrivalTimeBraking = attrs.get<SUMOTime>(SUMO_ATTR_ARRIVALTIMEBRAKING, nullptr, ok);
305  const double arrivalSpeedBraking = attrs.get<double>(SUMO_ATTR_ARRIVALSPEEDBRAKING, nullptr, ok);
306  const SUMOTime waitingTime = attrs.get<SUMOTime>(SUMO_ATTR_WAITINGTIME, nullptr, ok);
307  const double dist = attrs.get<double>(SUMO_ATTR_DISTANCE, nullptr, ok);
308  const double latOffset = attrs.getOpt<double>(SUMO_ATTR_POSITION_LAT, nullptr, ok, 0);
309  SUMOVehicle* veh = vc.getVehicle(vehID);
310  myCurrentLink->setApproaching(veh, arrivalTime, arrivalSpeed, leaveSpeed, setRequest, arrivalTimeBraking, arrivalSpeedBraking, waitingTime, dist, latOffset);
311  if (!MSGlobals::gUseMesoSim) {
312  MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
313  microVeh->loadPreviousApproaching(myCurrentLink, setRequest, arrivalTime, arrivalSpeed, arrivalTimeBraking, arrivalSpeedBraking, dist, leaveSpeed);
314  }
315  break;
316  }
319  break;
320  }
321  case SUMO_TAG_PARAM: {
322  bool ok;
323  const std::string key = attrs.get<std::string>(SUMO_ATTR_KEY, nullptr, ok);
324  // circumventing empty string test
325  const std::string val = attrs.hasAttribute(SUMO_ATTR_VALUE) ? attrs.getString(SUMO_ATTR_VALUE) : "";
326  assert(myLastParameterised != 0);
327  if (myLastParameterised != nullptr) {
329  }
330  break;
331  }
333  if (attrs.getString(SUMO_ATTR_TYPE) == "person") {
335  }
336  if (attrs.getString(SUMO_ATTR_TYPE) == "container") {
338  }
339  break;
340  case SUMO_TAG_PERSON:
341  case SUMO_TAG_CONTAINER:
342  myAttrs = attrs.clone();
343  break;
345  bool ok = true;
346  const std::string signalID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
347  if (!MSNet::getInstance()->getTLSControl().knows(signalID)) {
348  throw InvalidArgument("Rail signal '" + signalID + "' in railSignalConstraints loaded from state is not known");
349  }
351  if (myConstrainedSignal == nullptr) {
352  throw InvalidArgument("Traffic light '" + signalID + "' is not a rail signal");
353  }
354  break;
355  }
356  case SUMO_TAG_PREDECESSOR: // intended fall-through
359  break;
360  case SUMO_TAG_TLLOGIC: {
361  bool ok;
362  const std::string tlID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
363  const std::string programID = attrs.get<std::string>(SUMO_ATTR_PROGRAMID, tlID.c_str(), ok);
364  const int phase = attrs.get<int>(SUMO_ATTR_PHASE, tlID.c_str(), ok);
365  const SUMOTime spentDuration = attrs.get<SUMOTime>(SUMO_ATTR_DURATION, tlID.c_str(), ok);
367  MSTrafficLightLogic* tl = tlc.get(tlID, programID);
368  if (tl == nullptr) {
369  if (programID == "online") {
370  WRITE_WARNING("Ignoring program '" + programID + "' for traffic light '" + tlID + "' in loaded state");
371  return;
372  } else {
373  throw ProcessError("Unknown program '" + programID + "' for traffic light '" + tlID + "'");
374  }
375  }
376  if (phase >= tl->getPhaseNumber()) {
377  throw ProcessError("Invalid phase '" + toString(phase) + "' for traffic light '" + tlID + "'");
378  }
379  const SUMOTime remaining = tl->getPhase(phase).duration - spentDuration;
380  tl->changeStepAndDuration(tlc, myTime, phase, remaining);
381  // might not be set if the phase happens to match and there are multiple programs
382  tl->setTrafficLightSignals(myTime - spentDuration);
383  break;
384  }
385  default:
386  break;
387  }
388 }
389 
390 
391 void
394  switch (element) {
395  case SUMO_TAG_PERSON:
396  case SUMO_TAG_CONTAINER: {
399  tc.fixLoadCount();
400  delete myAttrs;
401  myAttrs = nullptr;
402  break;
403  }
404  case SUMO_TAG_SNAPSHOT: {
405  if (myVCAttrs == nullptr) {
406  throw ProcessError("Could not load vehicle control state");
407  }
414  if (myRemoved > 0) {
415  WRITE_MESSAGE("Removed " + toString(myRemoved) + " vehicles while loading state.");
417  }
418  break;
419  }
420  default:
421  break;
422  }
423  if (element != SUMO_TAG_PARAM && myVehicleParameter == nullptr && myCurrentVType == nullptr) {
424  myLastParameterised = nullptr;
425  }
426 }
427 
428 
429 void
431  assert(myVehicleParameter != nullptr);
433  // the vehicle was already counted in MSVehicleControl::setState
435  // make a copy because myVehicleParameter is reset in closeVehicle()
436  const std::string vehID = myVehicleParameter->id;
437  if (myVehiclesToRemove.count(vehID) == 0) {
439  SUMOVehicle* v = vc.getVehicle(vehID);
440  if (v == nullptr) {
441  throw ProcessError("Could not load vehicle '" + vehID + "' from state");
442  }
444  v->loadState(*myAttrs, myOffset);
445  if (v->hasDeparted()) {
446  // vehicle already departed: disable pre-insertion rerouting and enable regular routing behavior
447  MSDevice_Routing* routingDevice = static_cast<MSDevice_Routing*>(v->getDevice(typeid(MSDevice_Routing)));
448  if (routingDevice != nullptr) {
450  }
453  // register route for deadlock prevention (vehicleStateChanged would not be called otherwise)
455  }
456  }
457  while (!myDeviceAttrs.empty()) {
458  const std::string attrID = myDeviceAttrs.back()->getString(SUMO_ATTR_ID);
459  for (MSVehicleDevice* const dev : v->getDevices()) {
460  if (dev->getID() == attrID) {
461  dev->loadState(*myDeviceAttrs.back());
462  }
463  }
464  delete myDeviceAttrs.back();
465  myDeviceAttrs.pop_back();
466  }
467  } else {
468  delete myVehicleParameter;
469  myVehicleParameter = nullptr;
470  myRemoved++;
471  }
472  delete myAttrs;
473 }
474 
475 
476 void
481  out.writeAttr(SUMO_ATTR_RNG_INSERTIONCONTROL, RandHelper::saveState(MSNet::getInstance()->getInsertionControl().getFlowRNG()));
487  out.closeTag();
488 
489 }
490 
491 
492 /****************************************************************************/
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:282
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
long long int SUMOTime
Definition: SUMOTime.h:32
const int VEHPARS_FORCE_REROUTE
@ SUMO_TAG_RAILSIGNAL_CONSTRAINTS
Constraints on switching a rail signal.
@ 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_RNGLANE
@ 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_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_PERSON
@ SUMO_TAG_VEHICLETRANSFER
@ SUMO_TAG_PREDECESSOR
Predecessor constraint on switching a rail signal.
@ 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_DEFAULT
@ SUMO_ATTR_ARRIVALSPEEDBRAKING
@ SUMO_ATTR_REROUTE
@ 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_ARRIVALTIMEBRAKING
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_SPEEDFACTOR
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_VERSION
@ SUMO_ATTR_ID
@ 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:314
A single mesoscopic segment (cell)
Definition: MESegment.h:49
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:227
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.
Definition: MESegment.cpp:755
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()
Definition: MSDevice_ToC.h:176
static SumoRNG * getEquipmentRNG()
Definition: MSDevice.h:88
A road/street connecting two junctions.
Definition: MSEdge.h:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:918
static int dictSize()
Returns the number of edges.
Definition: MSEdge.cpp:912
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition: MSEdge.cpp:885
static bool gUseMesoSim
Definition: MSGlobals.h:94
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:100
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.
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.h:641
static void saveRNGStates(OutputDevice &out)
save random number generator states to the given output device
Definition: MSLane.cpp:4032
static void loadRNGState(int index, const std::string &state)
load random number generator state for the given rng index
Definition: MSLane.cpp:4042
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1991
void loadState(const std::vector< std::string > &vehIDs, MSVehicleControl &vc)
Loads the state of this segment with the given parameters.
Definition: MSLane.cpp:3235
@ 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:174
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:449
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1068
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:376
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:429
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1059
SUMOTime duration
The duration of the phase.
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.
Definition: MSRailSignal.h:46
Parser and container for routes during their loading.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static SumoRNG * getParsingRNG()
get parsing RNG
bool myAmLoadingState
whether a state file is being loaded
virtual void closeVehicle()
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:257
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)
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 const MSPhaseDefinition & getPhase(int givenstep) const =0
Returns the definition of the phase from the given position within the plan.
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration)=0
Changes the current phase and her duration.
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
void loadState(const std::string &state)
Reconstruct the current state.
void fixLoadCount()
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.
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 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:75
void loadPreviousApproaching(MSLink *link, bool setRequest, SUMOTime arrivalTime, double arrivalSpeed, SUMOTime arrivalTimeBraking, double arrivalSpeedBraking, double dist, double leaveSpeed)
Definition: MSVehicle.cpp:6738
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 void addPredecessorConstraint(int element, const SUMOSAXAttributes &attrs, MSRailSignal *rs)
Definition: NLHandler.cpp:1625
const std::string & getID() const
Returns the id.
Definition: Named.h:74
static SumoRNG * getRNG()
Definition: MSDriverState.h:78
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.
Definition: OptionsCont.cpp:58
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
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)
Definition: OutputDevice.h:193
static OutputDevice & getDevice(const std::string &name)
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:228
static std::string saveState(SumoRNG *rng=nullptr)
save rng state to string
Definition: RandHelper.h:214
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 int getInt(int id) const =0
Returns the int-value of the named (by its enum-value) attribute.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, 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
const std::vector< std::string > getStringVector(int attr) const
Tries to read given attribute assuming it is a string vector.
virtual double getFloat(int id) const =0
Returns the double-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.
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:52
bool parseFirst(std::string systemID)
Representation of a vehicle.
Definition: SUMOVehicle.h:60
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
virtual void setChosenSpeedFactor(const double factor)=0
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.
virtual const std::vector< MSVehicleDevice * > & getDevices() const =0
Returns this vehicle's devices.
Structure representing possible vehicle parameter.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
std::string id
The vehicle's id.
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.
Definition: XMLSubSys.cpp:133