86 if (handler.
myTime == -1) {
88 throw ProcessError(
TLF(
"Could not parse time from state file '%'", fileName));
132 out.
writeAttr(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").
writeAttr(
"xsi:noNamespaceSchemaLocation",
"http://sumo.dlr.de/xsd/state_file.xsd");
170 for (
MSLane*
const lane : edge->getLanes()) {
171 lane->saveState(out);
188 if (version != VERSION_STRING) {
189 WRITE_WARNINGF(
TL(
"State was written with sumo version % (present: %)!"), version, VERSION_STRING);
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) {
237 if (lane ==
nullptr) {
240 activeLanes.push_back(lane);
291 const std::string laneID = attrs.
get<std::string>(
SUMO_ATTR_ID,
nullptr, ok);
300 const std::vector<std::string>& vehIDs = attrs.
get<std::vector<std::string> >(
SUMO_ATTR_VALUE,
nullptr, ok,
false);
312 const std::string toLaneID = attrs.
get<std::string>(
SUMO_ATTR_TO,
nullptr, ok);
314 if (link->getViaLaneOrLane()->getID() == toLaneID) {
325 const std::string vehID = attrs.
get<std::string>(
SUMO_ATTR_ID,
nullptr, ok);
335 myCurrentLink->
setApproaching(veh, arrivalTime, arrivalSpeed, leaveSpeed, setRequest, arrivalSpeedBraking, waitingTime, dist, latOffset);
376 const std::string signalID = attrs.
get<std::string>(
SUMO_ATTR_ID,
nullptr, ok);
378 throw InvalidArgument(
"Rail signal '" + signalID +
"' in railSignalConstraints loaded from state is not known");
382 throw InvalidArgument(
"Traffic light '" + signalID +
"' is not a rail signal");
395 const std::string tlID = attrs.
get<std::string>(
SUMO_ATTR_ID,
nullptr, ok);
402 if (programID ==
"online") {
403 WRITE_WARNINGF(
TL(
"Ignoring program '%' for traffic light '%' in loaded state"), programID, tlID);
406 throw ProcessError(
"Unknown program '" + programID +
"' for traffic light '" + tlID +
"'");
473 throw ProcessError(
TLF(
"Could not load vehicle '%' from state", vehID));
481 if (routingDevice !=
nullptr) {
498 if (dev->getID() == attrID) {
#define WRITE_WARNINGF(...)
#define WRITE_MESSAGEF(...)
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
@ 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_VTYPE
description of a vehicle/person/container type
@ 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_TLLOGIC
a traffic light logic
@ SUMO_TAG_FOE_INSERTION
Predecessor constraint on switching a rail signal.
@ SUMO_TAG_VIEWSETTINGS_VEHICLES
@ 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_VEHICLETRANSFER
@ SUMO_TAG_DRIVEWAY
Saved driveway information.
@ SUMO_TAG_PREDECESSOR
Predecessor constraint on switching a rail signal.
@ SUMO_ATTR_RNG_INSERTIONCONTROL
@ SUMO_ATTR_RNG_DRIVERSTATE
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_ARRIVALSPEEDBRAKING
@ SUMO_ATTR_NEXT
succesor phase index
@ SUMO_ATTR_RNG_DEVICE_TOC
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_RNG_DEVICE_BT
@ SUMO_ATTR_RNG_ROUTEHANDLER
@ 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)
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.
A single mesoscopic segment (cell)
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).
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()
static bool haveDriveWays()
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.
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
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....
static MELoop * gMesoNet
mesoscopic simulation infrastructure
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.
static void saveRNGStates(OutputDevice &out)
save random number generator states to the given output device
static void loadRNGState(int index, const std::string &state)
load random number generator state for the given rng index
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
void loadState(const std::vector< std::string > &vehIDs, MSVehicleControl &vc)
Loads the state of this segment with the given parameters.
void setApproaching(const SUMOVehicle *approaching, const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const bool setRequest, const double arrivalSpeedBraking, const SUMOTime waitingTime, double dist, double latOffset)
Sets the information about an approaching vehicle.
@ 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).
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
virtual MSTransportableControl & getContainerControl()
Returns the container control.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
MSEdgeControl & getEdgeControl()
Returns the edge control.
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 bool hasInstance()
static MSRailSignalControl & getInstance()
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.
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.
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.
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.
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
static std::string saveState(SumoRNG *rng=nullptr)
save rng state to string
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.
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.