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 /****************************************************************************/
MSLane::releaseVehicles
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition: MSLane.h:458
SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:791
MSLane::getVehiclesSecure
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition: MSLane.h:428
MSBaseVehicle::getContainerNumber
int getContainerNumber() const
Returns the number of containers.
Definition: MSBaseVehicle.cpp:599
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MSEdge::getSortedPersons
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's persons sorted by pos.
Definition: MSEdge.cpp:946
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:49
MESegment
A single mesoscopic segment (cell)
Definition: MESegment.h:50
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:222
SUMO_TAG_PERSON
Definition: SUMOXMLDefinitions.h:296
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:194
MSAbstractLaneChangeModel::getSpeedLat
double getSpeedLat() const
return the lateral speed of the current lane change maneuver
Definition: MSAbstractLaneChangeModel.h:566
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:91
SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:385
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
MSEdge.h
MSTransportable
Definition: MSTransportable.h:59
SUMO_TAG_CONTAINER
Definition: SUMOXMLDefinitions.h:317
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:42
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:254
MSVehicle::getLateralPositionOnLane
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition: MSVehicle.h:434
MESegment.h
SUMO_ATTR_PERSON_NUMBER
Definition: SUMOXMLDefinitions.h:649
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
MSBaseVehicle::getContainers
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
Definition: MSBaseVehicle.cpp:628
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:63
MELoop::getSegmentForEdge
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:293
OutputDevice.h
MSVehicle::getLaneChangeModel
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4609
SUMO_ATTR_CONTAINER_NUMBER
Definition: SUMOXMLDefinitions.h:650
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
MSGlobals.h
MESegment::getNextSegment
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:152
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
MSBaseVehicle::isOnRoad
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSBaseVehicle.h:155
MSContainer.h
MSAbstractLaneChangeModel::haveLateralDynamics
static bool haveLateralDynamics()
whether any kind of lateral dynamics is active
Definition: MSAbstractLaneChangeModel.h:142
SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:658
MSTransportable::getEdgePos
virtual double getEdgePos() const
Return the position on the edge.
Definition: MSTransportable.cpp:709
MSXMLRawOut::writeLane
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the dump of the given lane into the given device.
Definition: MSXMLRawOut.cpp:119
MSEdgeControl.h
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
MSGlobals::gMesoNet
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:106
MSXMLRawOut::writeTransportable
static void writeTransportable(OutputDevice &of, const MSTransportable *p, SumoXMLTag tag)
write transportable
Definition: MSXMLRawOut.cpp:169
MSXMLRawOut.h
MSBaseVehicle::getPersons
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
Definition: MSBaseVehicle.cpp:618
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
MSBaseVehicle::getPersonNumber
int getPersonNumber() const
Returns the number of persons.
Definition: MSBaseVehicle.cpp:583
MSPModel.h
SUMO_ATTR_POSITION_LAT
Definition: SUMOXMLDefinitions.h:659
MSTransportable::getID
const std::string & getID() const
returns the id of the transportable
Definition: MSTransportable.cpp:694
MSBaseVehicle
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
MSBaseVehicle::getID
const std::string & getID() const
Returns the name of the vehicle.
Definition: MSBaseVehicle.cpp:137
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:165
config.h
MSEdgeControl
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
GeomHelper.h
gPrecision
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:27
MELoop.h
MESegment::writeVehicles
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:320
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:52
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
MSTransportable::getAngle
virtual double getAngle() const
return the current angle of the transportable
Definition: MSTransportable.cpp:719
MSXMLRawOut::writeVehicle
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
Definition: MSXMLRawOut.cpp:130
MSEdgeControl::getEdges
const MSEdgeVector & getEdges() const
Returns loaded edges.
Definition: MSEdgeControl.h:168
MESegment::getCarNumber
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:124
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:80
MSTransportable::getCurrentStageDescription
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
Definition: MSTransportable.h:673
MSEdge::getSortedContainers
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's containers sorted by pos.
Definition: MSEdge.cpp:964