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-2017 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 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 void
56  SUMOTime timestep, int precision) {
57  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
58  of.setPrecision(precision);
59  const MSEdgeVector& edges = ec.getEdges();
60  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
61  writeEdge(of, **e, timestep);
62  }
64  of.closeTag();
65 }
66 
67 
68 void
69 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
70  //en
72  if (!dump) {
75  while (seg != 0) {
76  if (seg->getCarNumber() != 0) {
77  dump = true;
78  break;
79  }
80  seg = seg->getNextSegment();
81  }
82  } else {
83  const std::vector<MSLane*>& lanes = edge.getLanes();
84  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
85  if (((**lane).getVehicleNumber() != 0)) {
86  dump = true;
87  break;
88  }
89  }
90  }
91  }
92  //en
93  const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
94  const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
95  if (dump || persons.size() > 0 || containers.size() > 0) {
96  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
97  if (dump) {
100  while (seg != 0) {
101  seg->writeVehicles(of);
102  seg = seg->getNextSegment();
103  }
104  } else {
105  const std::vector<MSLane*>& lanes = edge.getLanes();
106  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
107  writeLane(of, **lane);
108  }
109  }
110  }
111  // write persons
112  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
114  }
115  // write containers
116  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
118  }
119  of.closeTag();
120  }
121 }
122 
123 
124 void
126  of.openTag("lane") << " id=\"" << lane.myID << "\"";
127  if (lane.getVehicleNumber() != 0) {
128  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
129  veh != lane.myVehBuffer.end(); ++veh) {
130  writeVehicle(of, **veh);
131  }
132  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
133  veh != lane.myVehicles.end(); ++veh) {
134  writeVehicle(of, **veh);
135  }
136  }
137  of.closeTag();
138 }
139 
140 
141 void
143  if (veh.isOnRoad()) {
144  of.openTag("vehicle");
145  of.writeAttr(SUMO_ATTR_ID, veh.getID());
148  if (!MSGlobals::gUseMesoSim) {
149  const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
150  // microsim-specific stuff
152  const double posLat = microVeh.getLateralPositionOnLane();
153  of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
154  }
155  const int personNumber = microVeh.getPersonNumber();
156  if (personNumber > 0) {
157  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
158  }
159  const 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:55
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:59
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:157
static double gLateralResolution
Definition: MSGlobals.h:92
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
VehCont myVehicles
The lane&#39;s vehicles. This container holds all vehicles that have their front (longitudinally) and the...
Definition: MSLane.h:1090
SumoXMLTag
Numbers representing SUMO-XML - element names.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
static void writeTransportable(OutputDevice &of, const MSTransportable *p, SumoXMLTag tag)
write transportable
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:289
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.cpp:303
virtual double getEdgePos() const
Return the position on the edge.
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:30
int getPersonNumber() const
Returns the number of persons.
Definition: MSVehicle.cpp:3508
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
const std::string & getID() const
Returns the id.
Definition: Named.h:66
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:56
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge&#39;s persons sorted by pos.
Definition: MSEdge.cpp:854
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:339
A road/street connecting two junctions.
Definition: MSEdge.h:80
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:187
virtual double getAngle() const
return the current angle of the transportable
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition: MSLane.h:352
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::string & getID() const
returns the id of the transportable
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:407
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
std::string myID
The name of the object.
Definition: Named.h:136
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
A single mesoscopic segment (cell)
Definition: MESegment.h:57
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:69
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:113
int getContainerNumber() const
Returns the number of containers.
Definition: MSVehicle.cpp:3514
const MSEdgeVector & 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.
long long int SUMOTime
Definition: TraCIDefs.h:52
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
Definition: MSVehicle.cpp:3488
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
Definition: MSVehicle.cpp:3498
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
VehCont myVehBuffer
Buffer for vehicles that moved from their previous lane onto this one. Integrated after all vehicles ...
Definition: MSLane.h:1110
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
const std::string & getID() const
Returns the name of the vehicle.
static bool gUseMesoSim
Definition: MSGlobals.h:98
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep, bool includeRiding=false) const
Returns this edge&#39;s containers sorted by pos.
Definition: MSEdge.cpp:872
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.