Eclipse SUMO - Simulation of Urban MObility
MSXMLRawOut.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // Realises dumping the complete network state
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <utils/geom/GeomHelper.h>
29 #include <microsim/MSEdgeControl.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSNet.h>
33 #include <microsim/MSVehicle.h>
36 #include <microsim/MSGlobals.h>
37 #include <microsim/MSContainer.h>
39 #include "MSXMLRawOut.h"
40 
41 #include <mesosim/MELoop.h>
42 #include <mesosim/MESegment.h>
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 void
50  SUMOTime timestep, int precision) {
51  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
52  of.setPrecision(precision);
53  const MSEdgeVector& edges = ec.getEdges();
54  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
55  writeEdge(of, **e, timestep);
56  }
58  of.closeTag();
59 }
60 
61 
62 void
63 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
64  //en
66  if (!dump) {
69  while (seg != nullptr) {
70  if (seg->getCarNumber() != 0) {
71  dump = true;
72  break;
73  }
74  seg = seg->getNextSegment();
75  }
76  } else {
77  const std::vector<MSLane*>& lanes = edge.getLanes();
78  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
79  if (((**lane).getVehicleNumber() != 0)) {
80  dump = true;
81  break;
82  }
83  }
84  }
85  }
86  //en
87  const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
88  const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
89  if (dump || persons.size() > 0 || containers.size() > 0) {
90  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
91  if (dump) {
94  while (seg != nullptr) {
95  seg->writeVehicles(of);
96  seg = seg->getNextSegment();
97  }
98  } else {
99  const std::vector<MSLane*>& lanes = edge.getLanes();
100  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
101  writeLane(of, **lane);
102  }
103  }
104  }
105  // write persons
106  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
108  }
109  // write containers
110  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
112  }
113  of.closeTag();
114  }
115 }
116 
117 
118 void
120  of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID());
121  for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) {
122  writeVehicle(of, *veh);
123  }
124  lane.releaseVehicles();
125  of.closeTag();
126 }
127 
128 
129 void
131  if (veh.isOnRoad()) {
132  of.openTag("vehicle");
133  of.writeAttr(SUMO_ATTR_ID, veh.getID());
136  // TODO: activate action step length output, if required
137  //of.writeAttr(SUMO_ATTR_ACTIONSTEPLENGTH, veh.getActionStepLength());
138  if (!MSGlobals::gUseMesoSim) {
139  const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
140  // microsim-specific stuff
142  const double posLat = microVeh.getLateralPositionOnLane();
143  of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
144  of.writeAttr("speedLat", microVeh.getLaneChangeModel().getSpeedLat());
145  }
146  const int personNumber = microVeh.getPersonNumber();
147  if (personNumber > 0) {
148  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
149  }
150  const int containerNumber = microVeh.getContainerNumber();
151  if (containerNumber > 0) {
152  of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
153  }
154  const std::vector<MSTransportable*>& persons = microVeh.getPersons();
155  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
157  }
158  const std::vector<MSTransportable*>& containers = microVeh.getContainers();
159  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
161  }
162  }
163  of.closeTag();
164  }
165 }
166 
167 
168 void
170  of.openTag(tag);
171  of.writeAttr(SUMO_ATTR_ID, p->getID());
174  of.writeAttr("stage", p->getCurrentStageDescription());
175  of.closeTag();
176 }
177 
178 /****************************************************************************/
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:49
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:52
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:152
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
int getContainerNumber() const
Returns the number of containers.
SumoXMLTag
Numbers representing SUMO-XML - element names.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
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:293
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:124
virtual double getEdgePos() const
Return the position on the edge.
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:27
static bool haveLateralDynamics()
whether any kind of lateral dynamics is active
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
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:165
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition: MSLane.h:428
const std::string & getID() const
Returns the id.
Definition: Named.h:77
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge&#39;s persons sorted by pos.
Definition: MSEdge.cpp:946
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4609
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:320
A road/street connecting two junctions.
Definition: MSEdge.h:76
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:194
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
virtual double getAngle() const
return the current angle of the transportable
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
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:434
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
int getPersonNumber() const
Returns the number of persons.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
A single mesoscopic segment (cell)
Definition: MESegment.h:50
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:63
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:106
const MSEdgeVector & getEdges() const
Returns loaded edges.
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition: MSLane.h:458
const std::string & getID() const
Returns the name of the vehicle.
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
static bool gUseMesoSim
Definition: MSGlobals.h:91
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep, bool includeRiding=false) const
Returns this edge&#39;s containers sorted by pos.
Definition: MSEdge.cpp:964
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
double getSpeedLat() const
return the lateral speed of the current lane change maneuver
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.