SUMO - Simulation of Urban MObility
MSXMLRawOut.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // Realises dumping the complete network state
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <utils/geom/GeomHelper.h>
29 #include <microsim/MSEdgeControl.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSNet.h>
33 #include <microsim/MSVehicle.h>
36 #include <microsim/MSGlobals.h>
37 #include <microsim/MSContainer.h>
39 #include "MSXMLRawOut.h"
40 
41 #include <mesosim/MELoop.h>
42 #include <mesosim/MESegment.h>
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 void
50  SUMOTime timestep, int precision) {
51  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
52  of.setPrecision(precision);
53  const MSEdgeVector& edges = ec.getEdges();
54  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
55  writeEdge(of, **e, timestep);
56  }
58  of.closeTag();
59 }
60 
61 
62 void
63 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
64  //en
66  if (!dump) {
69  while (seg != nullptr) {
70  if (seg->getCarNumber() != 0) {
71  dump = true;
72  break;
73  }
74  seg = seg->getNextSegment();
75  }
76  } else {
77  const std::vector<MSLane*>& lanes = edge.getLanes();
78  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
79  if (((**lane).getVehicleNumber() != 0)) {
80  dump = true;
81  break;
82  }
83  }
84  }
85  }
86  //en
87  const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
88  const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
89  if (dump || persons.size() > 0 || containers.size() > 0) {
90  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
91  if (dump) {
94  while (seg != nullptr) {
95  seg->writeVehicles(of);
96  seg = seg->getNextSegment();
97  }
98  } else {
99  const std::vector<MSLane*>& lanes = edge.getLanes();
100  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
101  writeLane(of, **lane);
102  }
103  }
104  }
105  // write persons
106  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
108  }
109  // write containers
110  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
112  }
113  of.closeTag();
114  }
115 }
116 
117 
118 void
120  of.openTag("lane") << " id=\"" << lane.myID << "\"";
121  if (lane.getVehicleNumber() != 0) {
122  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
123  veh != lane.myVehBuffer.end(); ++veh) {
124  writeVehicle(of, **veh);
125  }
126  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
127  veh != lane.myVehicles.end(); ++veh) {
128  writeVehicle(of, **veh);
129  }
130  }
131  of.closeTag();
132 }
133 
134 
135 void
137  if (veh.isOnRoad()) {
138  of.openTag("vehicle");
139  of.writeAttr(SUMO_ATTR_ID, veh.getID());
142  // TODO: activate action step length output, if required
143  //of.writeAttr(SUMO_ATTR_ACTIONSTEPLENGTH, veh.getActionStepLength());
144  if (!MSGlobals::gUseMesoSim) {
145  const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
146  // microsim-specific stuff
148  const double posLat = microVeh.getLateralPositionOnLane();
149  of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
150  }
151  const int personNumber = microVeh.getPersonNumber();
152  if (personNumber > 0) {
153  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
154  }
155  const int containerNumber = microVeh.getContainerNumber();
156  if (containerNumber > 0) {
157  of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
158  }
159  const std::vector<MSTransportable*>& persons = microVeh.getPersons();
160  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
162  }
163  const std::vector<MSTransportable*>& containers = microVeh.getContainers();
164  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
166  }
167  }
168  of.closeTag();
169  }
170 }
171 
172 
173 void
175  of.openTag(tag);
176  of.writeAttr(SUMO_ATTR_ID, p->getID());
179  of.writeAttr("stage", p->getCurrentStageDescription());
180  of.closeTag();
181 }
182 
183 /****************************************************************************/
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.
Definition: MSXMLRawOut.cpp:49
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:52
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:152
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
int getContainerNumber() const
Returns the number of containers.
VehCont myVehicles
The lane&#39;s vehicles. This container holds all vehicles that have their front (longitudinally) and the...
Definition: MSLane.h:1220
SumoXMLTag
Numbers representing SUMO-XML - element names.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
static void writeTransportable(OutputDevice &of, const MSTransportable *p, SumoXMLTag tag)
write transportable
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:283
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:124
virtual double getEdgePos() const
Return the position on the edge.
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:27
static bool haveLateralDynamics()
whether any kind of lateral dynamics is active
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:162
const std::string & getID() const
Returns the id.
Definition: Named.h:78
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge&#39;s persons sorted by pos.
Definition: MSEdge.cpp:929
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:320
A road/street connecting two junctions.
Definition: MSEdge.h:75
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:180
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
virtual double getAngle() const
return the current angle of the transportable
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition: MSLane.h:379
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the dump of the given lane into the given device.
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:67
const std::string & getID() const
returns the id of the transportable
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:440
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
std::string myID
The name of the object.
Definition: Named.h:130
int getPersonNumber() const
Returns the number of persons.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
A single mesoscopic segment (cell)
Definition: MESegment.h:50
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:63
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:106
const MSEdgeVector & getEdges() const
Returns loaded edges.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:71
VehCont myVehBuffer
Buffer for vehicles that moved from their previous lane onto this one. Integrated after all vehicles ...
Definition: MSLane.h:1240
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
const std::string & getID() const
Returns the name of the vehicle.
static bool gUseMesoSim
Definition: MSGlobals.h:91
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep, bool includeRiding=false) const
Returns this edge&#39;s containers sorted by pos.
Definition: MSEdge.cpp:947
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.