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 /****************************************************************************/
18 // Realises dumping the complete network state
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <utils/geom/GeomHelper.h>
28 #include <microsim/MSEdgeControl.h>
29 #include <microsim/MSEdge.h>
30 #include <microsim/MSLane.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSVehicle.h>
35 #include <microsim/MSGlobals.h>
36 #include <microsim/MSContainer.h>
38 #include "MSXMLRawOut.h"
39 
40 #include <mesosim/MELoop.h>
41 #include <mesosim/MESegment.h>
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 void
49  SUMOTime timestep, int precision) {
50  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
51  of.setPrecision(precision);
52  const MSEdgeVector& edges = ec.getEdges();
53  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
54  writeEdge(of, **e, timestep);
55  }
57  of.closeTag();
58 }
59 
60 
61 void
62 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
63  //en
65  if (!dump) {
68  while (seg != nullptr) {
69  if (seg->getCarNumber() != 0) {
70  dump = true;
71  break;
72  }
73  seg = seg->getNextSegment();
74  }
75  } else {
76  const std::vector<MSLane*>& lanes = edge.getLanes();
77  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
78  if (((**lane).getVehicleNumber() != 0)) {
79  dump = true;
80  break;
81  }
82  }
83  }
84  }
85  //en
86  const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
87  const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
88  if (dump || persons.size() > 0 || containers.size() > 0) {
89  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
90  if (dump) {
93  while (seg != nullptr) {
94  seg->writeVehicles(of);
95  seg = seg->getNextSegment();
96  }
97  } else {
98  const std::vector<MSLane*>& lanes = edge.getLanes();
99  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
100  writeLane(of, **lane);
101  }
102  }
103  }
104  // write persons
105  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
107  }
108  // write containers
109  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
111  }
112  of.closeTag();
113  }
114 }
115 
116 
117 void
119  of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID());
120  for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) {
121  writeVehicle(of, *veh);
122  }
123  lane.releaseVehicles();
124  of.closeTag();
125 }
126 
127 
128 void
130  if (veh.isOnRoad()) {
131  of.openTag("vehicle");
132  of.writeAttr(SUMO_ATTR_ID, veh.getID());
135  // TODO: activate action step length output, if required
136  //of.writeAttr(SUMO_ATTR_ACTIONSTEPLENGTH, veh.getActionStepLength());
137  if (!MSGlobals::gUseMesoSim) {
138  const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
139  // microsim-specific stuff
141  const double posLat = microVeh.getLateralPositionOnLane();
142  of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
143  of.writeAttr("speedLat", microVeh.getLaneChangeModel().getSpeedLat());
144  }
145  const int personNumber = microVeh.getPersonNumber();
146  if (personNumber > 0) {
147  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
148  }
149  const int containerNumber = microVeh.getContainerNumber();
150  if (containerNumber > 0) {
151  of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
152  }
153  const std::vector<MSTransportable*>& persons = microVeh.getPersons();
154  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
156  }
157  const std::vector<MSTransportable*>& containers = microVeh.getContainers();
158  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
160  }
161  }
162  of.closeTag();
163  }
164 }
165 
166 
167 void
169  of.openTag(tag);
170  of.writeAttr(SUMO_ATTR_ID, p->getID());
173  of.writeAttr("stage", p->getCurrentStageDescription());
174  of.closeTag();
175 }
176 
177 /****************************************************************************/
MSLane::releaseVehicles
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition: MSLane.h:457
SUMO_ATTR_ANGLE
@ SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:794
MSLane::getVehiclesSecure
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition: MSLane.h:427
MSBaseVehicle::getContainerNumber
int getContainerNumber() const
Returns the number of containers.
Definition: MSBaseVehicle.cpp:633
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSEdge::getSortedPersons
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's persons sorted by pos.
Definition: MSEdge.cpp:907
MSXMLRawOut::write
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:48
MESegment
A single mesoscopic segment (cell)
Definition: MESegment.h:49
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
SUMO_TAG_PERSON
@ SUMO_TAG_PERSON
Definition: SUMOXMLDefinitions.h:295
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:193
MSAbstractLaneChangeModel::getSpeedLat
double getSpeedLat() const
return the lateral speed of the current lane change maneuver
Definition: MSAbstractLaneChangeModel.h:544
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:90
SUMO_ATTR_SPEED
@ SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:384
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
MSEdge.h
MSTransportable
Definition: MSTransportable.h:58
SUMO_TAG_CONTAINER
@ SUMO_TAG_CONTAINER
Definition: SUMOXMLDefinitions.h:316
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:41
MSVehicle::getLaneChangeModel
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4680
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MSVehicle::getLateralPositionOnLane
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition: MSVehicle.h:429
MESegment.h
SUMO_ATTR_PERSON_NUMBER
@ SUMO_ATTR_PERSON_NUMBER
Definition: SUMOXMLDefinitions.h:651
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
MSBaseVehicle::getContainers
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
Definition: MSBaseVehicle.cpp:662
MSXMLRawOut::writeEdge
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:62
MELoop::getSegmentForEdge
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:292
OutputDevice.h
SUMO_ATTR_CONTAINER_NUMBER
@ SUMO_ATTR_CONTAINER_NUMBER
Definition: SUMOXMLDefinitions.h:652
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSGlobals.h
MESegment::getNextSegment
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:151
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MSBaseVehicle::isOnRoad
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSBaseVehicle.h:160
MSContainer.h
MSAbstractLaneChangeModel::haveLateralDynamics
static bool haveLateralDynamics()
whether any kind of lateral dynamics is active
Definition: MSAbstractLaneChangeModel.h:141
SUMO_ATTR_POSITION
@ SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:660
MSTransportable::getEdgePos
virtual double getEdgePos() const
Return the position on the edge.
Definition: MSTransportable.cpp:714
MSXMLRawOut::writeLane
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the dump of the given lane into the given device.
Definition: MSXMLRawOut.cpp:118
MSEdgeControl.h
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
MSGlobals::gMesoNet
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:105
MSXMLRawOut::writeTransportable
static void writeTransportable(OutputDevice &of, const MSTransportable *p, SumoXMLTag tag)
write transportable
Definition: MSXMLRawOut.cpp:168
MSXMLRawOut.h
MSBaseVehicle::getPersons
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
Definition: MSBaseVehicle.cpp:652
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:74
MSBaseVehicle::getPersonNumber
int getPersonNumber() const
Returns the number of persons.
Definition: MSBaseVehicle.cpp:617
MSPModel.h
SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_POSITION_LAT
Definition: SUMOXMLDefinitions.h:661
MSTransportable::getID
const std::string & getID() const
returns the id of the transportable
Definition: MSTransportable.cpp:699
MSBaseVehicle
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:51
MSBaseVehicle::getID
const std::string & getID() const
Returns the name of the vehicle.
Definition: MSBaseVehicle.cpp:138
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:167
config.h
MSEdgeControl
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:74
GeomHelper.h
gPrecision
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:26
MELoop.h
MESegment::writeVehicles
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:319
MSLane.h
SUMOTrafficObject::getPositionOnLane
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
MSGlobals::gOmitEmptyEdgesOnDump
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:51
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSTransportable::getAngle
virtual double getAngle() const
return the current angle of the transportable
Definition: MSTransportable.cpp:724
MSXMLRawOut::writeVehicle
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
Definition: MSXMLRawOut.cpp:129
MSEdgeControl::getEdges
const MSEdgeVector & getEdges() const
Returns loaded edges.
Definition: MSEdgeControl.h:169
MESegment::getCarNumber
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:123
SUMOTrafficObject::getSpeed
virtual double getSpeed() const =0
Returns the vehicle's current speed.
MSAbstractLaneChangeModel.h
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
MSTransportable::getCurrentStageDescription
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
Definition: MSTransportable.h:672
MSEdge::getSortedContainers
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's containers sorted by pos.
Definition: MSEdge.cpp:925