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-2015 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 #ifdef HAVE_INTERNAL
48 #include <mesosim/MELoop.h>
49 #include <mesosim/MESegment.h>
50 #endif
51 
52 #ifdef CHECK_MEMORY_LEAKS
53 #include <foreign/nvwa/debug_new.h>
54 #endif // CHECK_MEMORY_LEAKS
55 
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 void
62  SUMOTime timestep, int precision) {
63  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
64  of.setPrecision(precision);
65  const MSEdgeVector& edges = ec.getEdges();
66  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
67  writeEdge(of, **e, timestep);
68  }
70  of.closeTag();
71 }
72 
73 
74 void
75 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
76  //en
78  if (!dump) {
79 #ifdef HAVE_INTERNAL
81  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
82  while (seg != 0) {
83  if (seg->getCarNumber() != 0) {
84  dump = true;
85  break;
86  }
87  seg = seg->getNextSegment();
88  }
89  } else {
90 #endif
91  const std::vector<MSLane*>& lanes = edge.getLanes();
92  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
93  if (((**lane).getVehicleNumber() != 0)) {
94  dump = true;
95  break;
96  }
97  }
98 #ifdef HAVE_INTERNAL
99  }
100 #endif
101  }
102  //en
103  const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
104  const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
105  if (dump || persons.size() > 0 || containers.size() > 0) {
106  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
107  if (dump) {
108 #ifdef HAVE_INTERNAL
110  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
111  while (seg != 0) {
112  seg->writeVehicles(of);
113  seg = seg->getNextSegment();
114  }
115  } else {
116 #endif
117  const std::vector<MSLane*>& lanes = edge.getLanes();
118  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
119  writeLane(of, **lane);
120  }
121 #ifdef HAVE_INTERNAL
122  }
123 #endif
124  }
125  // write persons
126  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
128  of.writeAttr(SUMO_ATTR_ID, (*it_p)->getID());
129  of.writeAttr(SUMO_ATTR_POSITION, (*it_p)->getEdgePos());
130  of.writeAttr(SUMO_ATTR_ANGLE, GeomHelper::naviDegree((*it_p)->getAngle()));
131  of.writeAttr("stage", (*it_p)->getCurrentStageDescription());
132  of.closeTag();
133  }
134  // write containers
135  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
137  of.writeAttr(SUMO_ATTR_ID, (*it_c)->getID());
138  of.writeAttr(SUMO_ATTR_POSITION, (*it_c)->getEdgePos());
139  of.writeAttr(SUMO_ATTR_ANGLE, GeomHelper::naviDegree((*it_c)->getAngle()));
140  of.writeAttr("stage", (*it_c)->getCurrentStageDescription());
141  of.closeTag();
142  }
143  of.closeTag();
144  }
145 }
146 
147 
148 void
150  of.openTag("lane") << " id=\"" << lane.myID << "\"";
151  if (lane.getVehicleNumber() != 0) {
152  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
153  veh != lane.myVehBuffer.end(); ++veh) {
154  writeVehicle(of, **veh);
155  }
156  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
157  veh != lane.myVehicles.end(); ++veh) {
158  writeVehicle(of, **veh);
159  }
160  }
161  of.closeTag();
162 }
163 
164 
165 void
167  if (veh.isOnRoad()) {
168  of.openTag("vehicle");
169  of.writeAttr(SUMO_ATTR_ID, veh.getID());
172  if (!MSGlobals::gUseMesoSim) {
173  // microsim-specific stuff
174  const unsigned int personNumber = static_cast<const MSVehicle&>(veh).getPersonNumber();
175  if (personNumber > 0) {
176  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
177  }
178  const unsigned int containerNumber = static_cast<const MSVehicle&>(veh).getContainerNumber();
179  if (containerNumber > 0) {
180  of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
181  }
182  }
183  of.closeTag();
184  }
185 }
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:61
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:61
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:840
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:43
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:186
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
#define OUTPUT_ACCURACY
Definition: config.h:164
const std::string & getID() const
Returns the id.
Definition: Named.h:65
A road/street connecting two junctions.
Definition: MSEdge.h:81
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
std::vector< MSVehicle * > myVehBuffer
Definition: MSLane.h:860
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
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:704
unsigned int getVehicleNumber() const
Returns the number of vehicles on this lane.
Definition: MSLane.h:285
std::string myID
The name of the object.
Definition: Named.h:133
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:75
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
static const bool gUseMesoSim
Definition: MSGlobals.h:102
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
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:696
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.