SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <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 #ifdef HAVE_INTERNAL
47 #include <mesosim/MELoop.h>
48 #include <mesosim/MESegment.h>
49 #endif
50 
51 #ifdef CHECK_MEMORY_LEAKS
52 #include <foreign/nvwa/debug_new.h>
53 #endif // CHECK_MEMORY_LEAKS
54 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 void
61  SUMOTime timestep, int precision) {
62  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
63  of.setPrecision(precision);
64  const MSEdgeVector& edges = ec.getEdges();
65  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
66  writeEdge(of, **e, timestep);
67  }
69  of.closeTag();
70 }
71 
72 
73 void
74 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
75  //en
77  if (!dump) {
78 #ifdef HAVE_INTERNAL
80  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
81  while (seg != 0) {
82  if (seg->getCarNumber() != 0) {
83  dump = true;
84  break;
85  }
86  seg = seg->getNextSegment();
87  }
88  } else {
89 #endif
90  const std::vector<MSLane*>& lanes = edge.getLanes();
91  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
92  if (((**lane).getVehicleNumber() != 0)) {
93  dump = true;
94  break;
95  }
96  }
97 #ifdef HAVE_INTERNAL
98  }
99 #endif
100  }
101  //en
102  const std::vector<MSPerson*>& persons = edge.getSortedPersons(timestep);
103  const std::vector<MSContainer*>& containers = edge.getSortedContainers(timestep);
104  if (dump || persons.size() > 0 || containers.size() > 0) {
105  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
106  if (dump) {
107 #ifdef HAVE_INTERNAL
109  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
110  while (seg != 0) {
111  seg->writeVehicles(of);
112  seg = seg->getNextSegment();
113  }
114  } else {
115 #endif
116  const std::vector<MSLane*>& lanes = edge.getLanes();
117  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
118  writeLane(of, **lane);
119  }
120 #ifdef HAVE_INTERNAL
121  }
122 #endif
123  }
124  // write persons
125  for (std::vector<MSPerson*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
127  of.writeAttr(SUMO_ATTR_ID, (*it_p)->getID());
128  of.writeAttr(SUMO_ATTR_POSITION, (*it_p)->getEdgePos());
129  of.writeAttr(SUMO_ATTR_ANGLE, (*it_p)->getAngle());
130  of.writeAttr("stage", (*it_p)->getCurrentStageDescription());
131  of.closeTag();
132  }
133  // write containers
134  for (std::vector<MSContainer*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
136  of.writeAttr(SUMO_ATTR_ID, (*it_c)->getID());
137  of.writeAttr(SUMO_ATTR_POSITION, (*it_c)->getEdgePos());
138  of.writeAttr(SUMO_ATTR_ANGLE, (*it_c)->getAngle());
139  of.writeAttr("stage", (*it_c)->getCurrentStageDescription());
140  of.closeTag();
141  }
142  of.closeTag();
143  }
144 }
145 
146 
147 void
149  of.openTag("lane") << " id=\"" << lane.myID << "\"";
150  if (lane.getVehicleNumber() != 0) {
151  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
152  veh != lane.myVehBuffer.end(); ++veh) {
153  writeVehicle(of, **veh);
154  }
155  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
156  veh != lane.myVehicles.end(); ++veh) {
157  writeVehicle(of, **veh);
158  }
159  }
160  of.closeTag();
161 }
162 
163 
164 void
166  if (veh.isOnRoad()) {
167  of.openTag("vehicle");
168  of.writeAttr(SUMO_ATTR_ID, veh.getID());
171  if (!MSGlobals::gUseMesoSim) {
172  // microsim-specific stuff
173  const unsigned int personNumber = static_cast<const MSVehicle&>(veh).getPersonNumber();
174  if (personNumber > 0) {
175  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
176  }
177  const unsigned int containerNumber = static_cast<const MSVehicle&>(veh).getContainerNumber();
178  if (containerNumber > 0) {
179  of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
180  }
181  }
182  of.closeTag();
183  }
184 }
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:60
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's vehicles. The entering vehicles are inserted at the front of this container and the leavin...
Definition: MSLane.h:809
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:186
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle'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)
std::vector< MSContainer * > getSortedContainers(SUMOTime timestep) const
Returns this edge's containers sorted by pos.
Definition: MSEdge.cpp:656
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
#define OUTPUT_ACCURACY
Definition: config.h:165
const std::string & getID() const
Returns the id.
Definition: Named.h:60
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:829
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
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:128
virtual SUMOReal getSpeed() const =0
Returns the vehicle'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:74
int SUMOTime
Definition: SUMOTime.h:43
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.
std::vector< MSPerson * > getSortedPersons(SUMOTime timestep) const
Returns this edge's persons sorted by pos.
Definition: MSEdge.cpp:648
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
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.