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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // Realises dumping the complete network state
23 /****************************************************************************/
24 #include <config.h>
25 
26 #include <utils/geom/GeomHelper.h>
27 #include <microsim/MSEdgeControl.h>
28 #include <microsim/MSEdge.h>
29 #include <microsim/MSLane.h>
30 #include <microsim/MSNet.h>
31 #include <microsim/MSVehicle.h>
34 #include <microsim/MSGlobals.h>
37 #include "MSXMLRawOut.h"
38 
39 #include <mesosim/MELoop.h>
40 #include <mesosim/MESegment.h>
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 void
48  SUMOTime timestep, int precision) {
49  of.openTag("timestep") << " time=\"" << time2string(timestep) << "\"";
50  of.setPrecision(precision);
51  const MSEdgeVector& edges = ec.getEdges();
52  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
53  writeEdge(of, **e, timestep);
54  }
56  of.closeTag();
57 }
58 
59 
60 void
61 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) {
62  if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) {
63  return;
64  }
65  //en
67  if (!dump) {
70  while (seg != nullptr) {
71  if (seg->getCarNumber() != 0) {
72  dump = true;
73  break;
74  }
75  seg = seg->getNextSegment();
76  }
77  } else {
78  const std::vector<MSLane*>& lanes = edge.getLanes();
79  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
80  if (((**lane).getVehicleNumber() != 0)) {
81  dump = true;
82  break;
83  }
84  }
85  }
86  }
87  //en
88  const std::vector<MSTransportable*>& persons = edge.getSortedPersons(timestep);
89  const std::vector<MSTransportable*>& containers = edge.getSortedContainers(timestep);
90  if (dump || persons.size() > 0 || containers.size() > 0) {
91  of.openTag("edge") << " id=\"" << edge.getID() << "\"";
92  if (dump) {
95  while (seg != nullptr) {
96  seg->writeVehicles(of);
97  seg = seg->getNextSegment();
98  }
99  } else {
100  const std::vector<MSLane*>& lanes = edge.getLanes();
101  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
102  writeLane(of, **lane);
103  }
104  }
105  }
106  // write persons
107  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
109  }
110  // write containers
111  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
113  }
114  of.closeTag();
115  }
116 }
117 
118 
119 void
121  of.openTag("lane").writeAttr(SUMO_ATTR_ID, lane.getID());
122  for (const MSBaseVehicle* const veh : lane.getVehiclesSecure()) {
123  writeVehicle(of, *veh);
124  }
125  lane.releaseVehicles();
126  of.closeTag();
127 }
128 
129 
130 void
132  if (veh.isOnRoad()) {
133  of.openTag("vehicle");
134  of.writeAttr(SUMO_ATTR_ID, veh.getID());
137  // TODO: activate action step length output, if required
138  //of.writeAttr(SUMO_ATTR_ACTIONSTEPLENGTH, veh.getActionStepLength());
139  if (!MSGlobals::gUseMesoSim) {
140  const MSVehicle& microVeh = static_cast<const MSVehicle&>(veh);
141  // microsim-specific stuff
143  const double posLat = microVeh.getLateralPositionOnLane();
144  of.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
145  of.writeAttr("speedLat", microVeh.getLaneChangeModel().getSpeedLat());
146  }
147  const int personNumber = microVeh.getPersonNumber();
148  if (personNumber > 0) {
149  of.writeAttr(SUMO_ATTR_PERSON_NUMBER, personNumber);
150  }
151  const int containerNumber = microVeh.getContainerNumber();
152  if (containerNumber > 0) {
153  of.writeAttr(SUMO_ATTR_CONTAINER_NUMBER, containerNumber);
154  }
155  const std::vector<MSTransportable*>& persons = microVeh.getPersons();
156  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
158  }
159  const std::vector<MSTransportable*>& containers = microVeh.getContainers();
160  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
162  }
163  }
164  of.closeTag();
165  }
166 }
167 
168 
169 void
171  of.openTag(tag);
172  of.writeAttr(SUMO_ATTR_ID, p->getID());
175  of.writeAttr("stage", p->getCurrentStageDescription());
176  of.closeTag();
177 }
178 
179 
180 /****************************************************************************/
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CONTAINER
@ SUMO_TAG_PERSON
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_CONTAINER_NUMBER
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_PERSON_NUMBER
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:25
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:192
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:302
A single mesoscopic segment (cell)
Definition: MESegment.h:47
void writeVehicles(OutputDevice &of) const
Definition: MESegment.cpp:375
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition: MESegment.h:208
int getCarNumber() const
Returns the total number of cars on the segment.
Definition: MESegment.h:180
static bool haveLateralDynamics()
whether any kind of lateral dynamics is active
double getSpeedLat() const
return the lateral speed of the current lane change maneuver
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:51
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
int getPersonNumber() const
Returns the number of persons.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
int getContainerNumber() const
Returns the number of containers.
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:81
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
Definition: MSEdge.h:77
bool isNormal() const
return whether this edge is an internal edge
Definition: MSEdge.h:251
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's persons sorted by pos.
Definition: MSEdge.cpp:961
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:166
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep, bool includeRiding=false) const
Returns this edge's containers sorted by pos.
Definition: MSEdge.cpp:979
static bool gUseMesoSim
Definition: MSGlobals.h:88
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:94
static bool gOmitEmptyEdgesOnDump
Information whether empty edges shall be written on dump.
Definition: MSGlobals.h:49
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:66
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition: MSLane.h:426
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition: MSLane.h:456
virtual double getEdgePos() const
Return the position on the edge.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
virtual double getAngle() const
return the current angle of the transportable
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4699
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition: MSVehicle.h:411
static void writeTransportable(OutputDevice &of, const MSTransportable *p, SumoXMLTag tag)
write transportable
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
static void writeEdge(OutputDevice &of, const MSEdge &edge, SUMOTime timestep)
Writes the dump of the given edge into the given device.
Definition: MSXMLRawOut.cpp:61
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the dump of the given lane into the given device.
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:47
const std::string & getID() const
Returns the id.
Definition: Named.h:73
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:239
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.