SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
14 // Copyright (C) 2001-2013 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/MSGlobals.h>
42 #include "MSXMLRawOut.h"
43 
44 #ifdef HAVE_INTERNAL
45 #include <mesosim/MELoop.h>
46 #include <mesosim/MESegment.h>
47 #endif
48 
49 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 void
59  SUMOTime timestep) {
60  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
61  const std::vector<MSEdge*>& edges = ec.getEdges();
62  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
63  writeEdge(of, **e);
64  }
65  of.closeTag();
66 }
67 
68 
69 void
71  //en
73  if (!dump) {
74 #ifdef HAVE_INTERNAL
76  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
77  while (seg != 0) {
78  if (seg->getCarNumber() != 0) {
79  dump = true;
80  break;
81  }
82  seg = seg->getNextSegment();
83  }
84  } else {
85 #endif
86  const std::vector<MSLane*>& lanes = edge.getLanes();
87  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
88  if (((**lane).getVehicleNumber() != 0)) {
89  dump = true;
90  break;
91  }
92  }
93 #ifdef HAVE_INTERNAL
94  }
95 #endif
96  }
97  //en
98  if (dump) {
99  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
100 #ifdef HAVE_INTERNAL
102  MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
103  while (seg != 0) {
104  seg->writeVehicles(of);
105  seg = seg->getNextSegment();
106  }
107  } else {
108 #endif
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 #ifdef HAVE_INTERNAL
114  }
115 #endif
116  of.closeTag();
117  }
118 }
119 
120 
121 void
123  of.openTag("lane") << " id=\"" << lane.myID << "\"";
124  if (lane.getVehicleNumber() != 0) {
125  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
126  veh != lane.myVehBuffer.end(); ++veh) {
127  writeVehicle(of, **veh);
128  }
129  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
130  veh != lane.myVehicles.end(); ++veh) {
131  writeVehicle(of, **veh);
132  }
133  }
134  of.closeTag();
135 }
136 
137 
138 void
140  if (veh.isOnRoad()) {
141  of.openTag("vehicle") << " id=\"" << veh.getID() << "\" pos=\""
142  << veh.getPositionOnLane() << "\" speed=\"" << veh.getSpeed() << "\"";
143  of.closeTag();
144  }
145 }
146 
147 
148 /****************************************************************************/
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:60
VehCont myVehicles
The lane&#39;s vehicles. The entering vehicles are inserted at the front of this container and the leavin...
Definition: MSLane.h:761
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:168
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)
static void writeEdge(OutputDevice &of, const MSEdge &edge)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:70
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:57
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:73
std::vector< MSVehicle * > myVehBuffer
Definition: MSLane.h:781
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:121
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
const std::vector< MSEdge * > & 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.
static const bool gUseMesoSim
Definition: MSGlobals.h:98
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
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:58
const std::string & getID() const
Returns the name of the vehicle.