Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSXMLRawOut.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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/****************************************************************************/
22// Realises dumping the complete network state
23/****************************************************************************/
24#include <config.h>
25
28#include <microsim/MSEdge.h>
29#include <microsim/MSLane.h>
30#include <microsim/MSNet.h>
31#include <microsim/MSVehicle.h>
34#include <microsim/MSGlobals.h>
37#include "MSXMLRawOut.h"
38
39#include <mesosim/MELoop.h>
40#include <mesosim/MESegment.h>
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46void
48 SUMOTime timestep, int precision) {
49 of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
50 of.setPrecision(precision);
51 const MSEdgeVector& edges = ec.getEdges();
52 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
53 writeEdge(of, **e, timestep);
54 }
56 of.closeTag();
57}
58
59
60void
63 return;
64 }
65 //en
67 if (!dump) {
70 while (seg != nullptr) {
71 if (seg->getCarNumber() != 0) {
72 dump = true;
73 break;
74 }
75 seg = seg->getNextSegment();
76 }
77 } else {
78 const std::vector<MSLane*>& lanes = edge.getLanes();
79 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
80 if (((**lane).getVehicleNumber() != 0)) {
81 dump = true;
82 break;
83 }
84 }
85 }
86 }
87 //en
88 const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
89 const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
90 if (dump || persons.size() > 0 || containers.size() > 0) {
91 of.openTag("edge") << " id=\"" << edge.getID() << "\"";
92 if (dump) {
95 while (seg != nullptr) {
96 seg->writeVehicles(of);
97 seg = seg->getNextSegment();
98 }
99 } else {
100 const std::vector<MSLane*>& lanes = edge.getLanes();
101 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
102 writeLane(of, **lane);
103 }
104 }
105 }
106 // write persons
107 for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
109 }
110 // write containers
111 for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
113 }
114 of.closeTag();
115 }
116}
117
118
119void
121 of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID());
122 for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) {
123 writeVehicle(of, *veh);
124 }
125 lane.releaseVehicles();
126 of.closeTag();
127}
128
129
130void
132 if (veh.isOnRoad()) {
133 of.openTag("vehicle");
134 of.writeAttr(SUMO_ATTR_ID, veh.getID());
137 // TODO: activate action step length output, if required
138 //of.writeAttr(SUMO_ATTR_ACTIONSTEPLENGTH, veh.getActionStepLength());
140 const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
141 // microsim-specific stuff
143 const double posLat = microVeh.getLateralPositionOnLane();
146 }
147 const int personNumber = microVeh.getPersonNumber();
148 if (personNumber > 0) {
149 of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
150 }
151 const int containerNumber = microVeh.getContainerNumber();
152 if (containerNumber > 0) {
153 of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
154 }
155 const std::vector<MSTransportable*>& persons = microVeh.getPersons();
156 for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
158 }
159 const std::vector<MSTransportable*>& containers = microVeh.getContainers();
160 for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
162 }
163 }
164 of.closeTag();
165 }
166}
167
168
169void
178
179
180/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CONTAINER
@ SUMO_TAG_PERSON
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_CONTAINER_NUMBER
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_PERSON_NUMBER
@ SUMO_ATTR_ID
@ SUMO_ATTR_SPEED_LAT
@ SUMO_ATTR_POSITION
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:26
static double naviDegree(const double angle)
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 writeVehicles(OutputDevice &of) const
int getCarNumber() const
Returns the total number of cars on the segment.
Definition MESegment.h:206
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition MESegment.h:234
double getSpeedLat() const
return the lateral speed of the current lane change maneuver
The base class for microscopic and mesoscopic vehicles.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
int getPersonNumber() const
Returns the number of persons.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
int getContainerNumber() const
Returns the number of containers.
Stores edges and lanes, performs moving of vehicle.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
Definition MSEdge.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
bool isNormal() const
return whether this edge is an internal edge
Definition MSEdge.h:263
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's persons sorted by pos.
Definition MSEdge.cpp:1206
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's containers sorted by pos.
Definition MSEdge.cpp:1224
static bool gUseMesoSim
Definition MSGlobals.h:106
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition MSGlobals.h:112
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition MSGlobals.h:49
static bool gSublane
whether sublane simulation is enabled (sublane model or continuous lanechanging)
Definition MSGlobals.h:165
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:81
Representation of a lane in the micro simulation.
Definition MSLane.h:84
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition MSLane.h:483
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition MSLane.h:513
virtual double getEdgePos() const
Return the position on the edge.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
virtual double getAngle() const
return the current angle of the transportable
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
MSAbstractLaneChangeModel & getLaneChangeModel()
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition MSVehicle.h:413
static void writeTransportable(OutputDevice &of, const MSTransportable *p, SumoXMLTag tag)
write transportable
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the dump of the given lane into the given device.
static void write(OutputDevice &of, const MSEdgeControl &ec, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
const std::string & getID() const
Returns the id.
Definition Named.h:74
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.