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-sim.org/
14 // Copyright (C) 2001-2014 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>
40 #include <microsim/MSPModel.h>
41 #include <microsim/MSGlobals.h>
43 #include "MSXMLRawOut.h"
44 
45 #ifdef HAVE_INTERNAL
46 #include <mesosim/MELoop.h>
47 #include <mesosim/MESegment.h>
48 #endif
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) {
61  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
62  const std::vector<MSEdge*>& edges = ec.getEdges();
63  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
64  writeEdge(of, **e, timestep);
65  }
66  of.closeTag();
67 }
68 
69 
70 void
71 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
72  //en
74  if (!dump) {
75 #ifdef HAVE_INTERNAL
77  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
78  while (seg != 0) {
79  if (seg->getCarNumber() != 0) {
80  dump = true;
81  break;
82  }
83  seg = seg->getNextSegment();
84  }
85  } else {
86 #endif
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 #ifdef HAVE_INTERNAL
95  }
96 #endif
97  }
98  //en
99  const std::vector<MSPerson*>& persons = edge.getSortedPersons(timestep);
100  if (dump || persons.size() > 0) {
101  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
102  if (dump) {
103 #ifdef HAVE_INTERNAL
105  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
106  while (seg != 0) {
107  seg->writeVehicles(of);
108  seg = seg->getNextSegment();
109  }
110  } else {
111 #endif
112  const std::vector<MSLane*>& lanes = edge.getLanes();
113  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
114  writeLane(of, **lane);
115  }
116 #ifdef HAVE_INTERNAL
117  }
118 #endif
119  }
120  // write persons
121  for (std::vector<MSPerson*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
123  of.writeAttr(SUMO_ATTR_ID, (*it_p)->getID());
124  of.writeAttr(SUMO_ATTR_POSITION, (*it_p)->getEdgePos());
125  of.writeAttr(SUMO_ATTR_ANGLE, (*it_p)->getAngle());
126  of.writeAttr("stage", (*it_p)->getCurrentStageDescription());
127  of.closeTag();
128  }
129  of.closeTag();
130  }
131 }
132 
133 
134 void
136  of.openTag("lane") << " id=\"" << lane.myID << "\"";
137  if (lane.getVehicleNumber() != 0) {
138  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
139  veh != lane.myVehBuffer.end(); ++veh) {
140  writeVehicle(of, **veh);
141  }
142  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
143  veh != lane.myVehicles.end(); ++veh) {
144  writeVehicle(of, **veh);
145  }
146  }
147  of.closeTag();
148 }
149 
150 
151 void
153  if (veh.isOnRoad()) {
154  of.openTag("vehicle") << " id=\"" << veh.getID() << "\" pos=\""
155  << veh.getPositionOnLane() << "\" speed=\"" << veh.getSpeed() << "\"";
156  of.closeTag();
157  }
158 }
159 
160 
161 /****************************************************************************/
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:780
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:173
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)
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:58
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:74
std::vector< MSVehicle * > myVehBuffer
Definition: MSLane.h:800
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
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:71
const std::vector< MSEdge * > & getEdges() const
Returns loaded edges.
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:99
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:596
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static void write(OutputDevice &of, const MSEdgeControl &ec, SUMOTime timestep)
Writes the complete network state of the given edges into the given device.
Definition: MSXMLRawOut.cpp:59
const std::string & getID() const
Returns the name of the vehicle.