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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // Realises dumping the complete network state
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <utils/geom/GeomHelper.h>
35 #include <microsim/MSEdgeControl.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSLane.h>
38 #include <microsim/MSNet.h>
39 #include <microsim/MSVehicle.h>
41 #include <microsim/MSGlobals.h>
42 #include <microsim/MSContainer.h>
44 #include "MSXMLRawOut.h"
45 
46 #include <mesosim/MELoop.h>
47 #include <mesosim/MESegment.h>
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 void
55  SUMOTime timestep, int precision) {
56  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
57  of.setPrecision(precision);
58  const MSEdgeVector& edges = ec.getEdges();
59  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
60  writeEdge(of, **e, timestep);
61  }
63  of.closeTag();
64 }
65 
66 
67 void
68 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
69  //en
71  if (!dump) {
74  while (seg != 0) {
75  if (seg->getCarNumber() != 0) {
76  dump = true;
77  break;
78  }
79  seg = seg->getNextSegment();
80  }
81  } else {
82  const std::vector<MSLane*>& lanes = edge.getLanes();
83  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
84  if (((**lane).getVehicleNumber() != 0)) {
85  dump = true;
86  break;
87  }
88  }
89  }
90  }
91  //en
92  const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
93  const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
94  if (dump || persons.size() > 0 || containers.size() > 0) {
95  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
96  if (dump) {
99  while (seg != 0) {
100  seg->writeVehicles(of);
101  seg = seg->getNextSegment();
102  }
103  } else {
104  const std::vector<MSLane*>& lanes = edge.getLanes();
105  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
106  writeLane(of, **lane);
107  }
108  }
109  }
110  // write persons
111  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
113  }
114  // write containers
115  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
117  }
118  of.closeTag();
119  }
120 }
121 
122 
123 void
125  of.openTag("lane") << " id=\"" << lane.myID << "\"";
126  if (lane.getVehicleNumber() != 0) {
127  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
128  veh != lane.myVehBuffer.end(); ++veh) {
129  writeVehicle(of, **veh);
130  }
131  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
132  veh != lane.myVehicles.end(); ++veh) {
133  writeVehicle(of, **veh);
134  }
135  }
136  of.closeTag();
137 }
138 
139 
140 void
142  if (veh.isOnRoad()) {
143  of.openTag("vehicle");
144  of.writeAttr(SUMO_ATTR_ID, veh.getID());
147  // TODO: activate action step length output, if required
148  //of.writeAttr(SUMO_ATTR_ACTIONSTEPLENGTH, veh.getActionStepLength());
149  if (!MSGlobals::gUseMesoSim) {
150  const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
151  // microsim-specific stuff
153  const double posLat = microVeh.getLateralPositionOnLane();
154  of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
155  }
156  const int personNumber = microVeh.getPersonNumber();
157  if (personNumber > 0) {
158  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
159  }
160  const int containerNumber = microVeh.getContainerNumber();
161  if (containerNumber > 0) {
162  of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
163  }
164  const std::vector<MSTransportable*>& persons = microVeh.getPersons();
165  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
167  }
168  const std::vector<MSTransportable*>& containers = microVeh.getContainers();
169  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
171  }
172  }
173  of.closeTag();
174  }
175 }
176 
177 
178 void
180  of.openTag(tag);
181  of.writeAttr(SUMO_ATTR_ID, p->getID());
184  of.writeAttr("stage", p->getCurrentStageDescription());
185  of.closeTag();
186 }
187 
188 /****************************************************************************/
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:54
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:58
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:156
static double gLateralResolution
Definition: MSGlobals.h:91
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
VehCont myVehicles
The lane&#39;s vehicles. This container holds all vehicles that have their front (longitudinally) and the...
Definition: MSLane.h:1156
SumoXMLTag
Numbers representing SUMO-XML - element names.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
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:289
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:302
virtual double getEdgePos() const
Return the position on the edge.
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:29
int getPersonNumber() const
Returns the number of persons.
Definition: MSVehicle.cpp:4247
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
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:167
const std::string & getID() const
Returns the id.
Definition: Named.h:74
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:55
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge&#39;s persons sorted by pos.
Definition: MSEdge.cpp:876
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:338
A road/street connecting two junctions.
Definition: MSEdge.h:80
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:186
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:365
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:73
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:439
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
std::string myID
The name of the object.
Definition: Named.h:126
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:56
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:68
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:112
int getContainerNumber() const
Returns the number of containers.
Definition: MSVehicle.cpp:4253
const MSEdgeVector & getEdges() const
Returns loaded edges.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:51
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
Definition: MSVehicle.cpp:4227
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
Definition: MSVehicle.cpp:4237
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
VehCont myVehBuffer
Buffer for vehicles that moved from their previous lane onto this one. Integrated after all vehicles ...
Definition: MSLane.h:1176
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
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:97
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep, bool includeRiding=false) const
Returns this edge&#39;s containers sorted by pos.
Definition: MSEdge.cpp:894
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.