SUMO - Simulation of Urban MObility
MSXMLRawOut.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // Realises dumping the complete network state
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <utils/geom/GeomHelper.h>
36 #include <microsim/MSEdgeControl.h>
37 #include <microsim/MSEdge.h>
38 #include <microsim/MSLane.h>
39 #include <microsim/MSNet.h>
40 #include <microsim/MSVehicle.h>
42 #include <microsim/MSGlobals.h>
43 #include <microsim/MSContainer.h>
45 #include "MSXMLRawOut.h"
46 
47 #include <mesosim/MELoop.h>
48 #include <mesosim/MESegment.h>
49 
50 #ifdef CHECK_MEMORY_LEAKS
51 #include <foreign/nvwa/debug_new.h>
52 #endif // CHECK_MEMORY_LEAKS
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 void
60  SUMOTime timestep, int precision) {
61  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
62  of.setPrecision(precision);
63  const MSEdgeVector& edges = ec.getEdges();
64  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
65  writeEdge(of, **e, timestep);
66  }
68  of.closeTag();
69 }
70 
71 
72 void
73 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
74  //en
76  if (!dump) {
79  while (seg != 0) {
80  if (seg->getCarNumber() != 0) {
81  dump = true;
82  break;
83  }
84  seg = seg->getNextSegment();
85  }
86  } else {
87  const std::vector<MSLane*>& lanes = edge.getLanes();
88  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
89  if (((**lane).getVehicleNumber() != 0)) {
90  dump = true;
91  break;
92  }
93  }
94  }
95  }
96  //en
97  const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
98  const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
99  if (dump || persons.size() > 0 || containers.size() > 0) {
100  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
101  if (dump) {
104  while (seg != 0) {
105  seg->writeVehicles(of);
106  seg = seg->getNextSegment();
107  }
108  } else {
109  const std::vector<MSLane*>& lanes = edge.getLanes();
110  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
111  writeLane(of, **lane);
112  }
113  }
114  }
115  // write persons
116  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
118  }
119  // write containers
120  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
122  }
123  of.closeTag();
124  }
125 }
126 
127 
128 void
130  of.openTag("lane") << " id=\"" << lane.myID << "\"";
131  if (lane.getVehicleNumber() != 0) {
132  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
133  veh != lane.myVehBuffer.end(); ++veh) {
134  writeVehicle(of, **veh);
135  }
136  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
137  veh != lane.myVehicles.end(); ++veh) {
138  writeVehicle(of, **veh);
139  }
140  }
141  of.closeTag();
142 }
143 
144 
145 void
147  if (veh.isOnRoad()) {
148  of.openTag("vehicle");
149  of.writeAttr(SUMO_ATTR_ID, veh.getID());
152  if (!MSGlobals::gUseMesoSim) {
153  const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
154  // microsim-specific stuff
155  const unsigned int personNumber = microVeh.getPersonNumber();
156  if (personNumber > 0) {
157  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
158  }
159  const unsigned int containerNumber = microVeh.getContainerNumber();
160  if (containerNumber > 0) {
161  of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
162  }
163  const std::vector<MSTransportable*>& persons = microVeh.getPersons();
164  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
166  }
167  const std::vector<MSTransportable*>& containers = microVeh.getContainers();
168  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
170  }
171  }
172  of.closeTag();
173  }
174 }
175 
176 
177 void
179  of.openTag(tag);
180  of.writeAttr(SUMO_ATTR_ID, p->getID());
183  of.writeAttr("stage", p->getCurrentStageDescription());
184  of.closeTag();
185 }
186 
187 /****************************************************************************/
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:59
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:59
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
VehCont myVehicles
The lane&#39;s vehicles. The entering vehicles are inserted at the front of this container and the leavin...
Definition: MSLane.h:854
SumoXMLTag
Numbers representing SUMO-XML - element names.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:43
static void writeTransportable(OutputDevice &of, const MSTransportable *p, SumoXMLTag tag)
write transportable
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:185
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
unsigned int getPersonNumber() const
Returns the number of persons.
Definition: MSVehicle.cpp:2562
const std::string & getID() const
returns the id of the transportable
virtual SUMOReal getEdgePos() const
Return the position on the edge.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
virtual SUMOReal getAngle() const
return the current angle of the transportable
#define OUTPUT_ACCURACY
Definition: config.h:163
const std::string & getID() const
Returns the id.
Definition: Named.h:65
A road/street connecting two junctions.
Definition: MSEdge.h:80
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
unsigned int getContainerNumber() const
Returns the number of containers.
Definition: MSVehicle.cpp:2568
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:158
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:289
std::vector< MSVehicle * > myVehBuffer
Definition: MSLane.h:874
size_t getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:253
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:74
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
Definition: MSVehicle.cpp:2552
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
Definition: MSVehicle.cpp:2542
static SUMOReal naviDegree(const SUMOReal angle)
Definition: GeomHelper.cpp:191
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep) const
Returns this edge&#39;s containers sorted by pos.
Definition: MSEdge.cpp:707
unsigned int getVehicleNumber() const
Returns the number of vehicles on this lane.
Definition: MSLane.h:284
std::string myID
The name of the object.
Definition: Named.h:133
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
A single mesoscopic segment (cell)
Definition: MESegment.h:57
MESegment * getSegmentForEdge(const MSEdge &e, SUMOReal pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:288
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:73
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:99
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
static bool gUseMesoSim
Definition: MSGlobals.h:87
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep) const
Returns this edge&#39;s persons sorted by pos.
Definition: MSEdge.cpp:699
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const MSEdgeVector & getEdges() const
Returns loaded edges.
const std::string & getID() const
Returns the name of the vehicle.