Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSFullExport.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2025 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/****************************************************************************/
21// Dumping a hugh List of Parameters available in the Simulation
22/****************************************************************************/
23#include <config.h>
24
29#include <microsim/MSEdge.h>
31#include <microsim/MSLane.h>
32#include <microsim/MSNet.h>
33#include <microsim/MSVehicle.h>
39#include "MSFullExport.h"
40
41
42// ===========================================================================
43// method definitions
44// ===========================================================================
45void
47 of.openTag("data") << " timestep=\"" << time2string(timestep) << "\"";
48 writeVehicles(of);
49 if (MSNet::getInstance()->hasPersons()) {
50 writePersons(of);
51 }
52 writeEdge(of);
53 writeTLS(of, timestep);
54 of.closeTag();
55}
56
57
58void
60 of.openTag("vehicles");
62 const bool hasEle = MSNet::getInstance()->hasElevation();
63 for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
64 const SUMOVehicle* veh = it->second;
65 const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
66 if (veh->isOnRoad()) {
67 std::string fclass = veh->getVehicleType().getID();
68 fclass = fclass.substr(0, fclass.find_first_of("@"));
71 veh->getAcceleration(), veh->getSlope(),
74 of.writeAttr(SUMO_ATTR_ID, veh->getID());
76 of.writeAttr(SUMO_ATTR_CO2, emiss.CO2);
77 of.writeAttr(SUMO_ATTR_CO, emiss.CO);
78 of.writeAttr(SUMO_ATTR_HC, emiss.HC);
79 of.writeAttr(SUMO_ATTR_NOX, emiss.NOx);
80 of.writeAttr(SUMO_ATTR_PMX, emiss.PMx);
81 of.writeAttr(SUMO_ATTR_FUEL, emiss.fuel);
85 of.writeAttr(SUMO_ATTR_TYPE, fclass);
86 if (microVeh != nullptr) {
88 of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
89 }
93 const Position pos = veh->getPosition();
94 of.writeAttr(SUMO_ATTR_X, pos.x());
95 of.writeAttr(SUMO_ATTR_Y, pos.y());
96 if (hasEle) {
97 of.writeAttr(SUMO_ATTR_Z, pos.z());
99 }
100 of.closeTag();
101 }
102 }
103 of.closeTag();
104}
105
106void
109 const bool hasEle = MSNet::getInstance()->hasElevation();
110 of.openTag("persons");
111 for (auto it = tc.loadedBegin(); it != tc.loadedEnd(); ++it) {
112 const MSTransportable* p = it->second;
114 const MSEdge* e = p->getEdge();
115 const SUMOVehicle* v = p->getVehicle();
116 Position pos = p->getPosition();
118 of.writeAttr(SUMO_ATTR_ID, p->getID());
119 of.writeAttr(SUMO_ATTR_X, pos.x());
120 of.writeAttr(SUMO_ATTR_Y, pos.y());
121 if (hasEle) {
122 of.writeAttr("z", pos.z());
123 }
128 of.writeAttr(SUMO_ATTR_SLOPE, e->getLanes()[0]->getShape().slopeDegreeAtOffset(p->getEdgePos()));
129 of.writeAttr(SUMO_ATTR_VEHICLE, v == nullptr ? "" : v->getID());
131 of.writeAttr("stage", (int)p->getCurrentStageType());
132 of.closeTag();
133 }
134 }
135 of.closeTag();
136}
137
138void
140 of.openTag("edges");
142 const MSEdgeVector& edges = ec.getEdges();
143 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
144 MSEdge& edge = **e;
146 continue;
147 }
148 of.openTag("edge").writeAttr("id", edge.getID()).writeAttr("traveltime", edge.getCurrentTravelTime());
149 const std::vector<MSLane*>& lanes = edge.getLanes();
150 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
151 writeLane(of, **lane);
152 }
153 of.closeTag();
154 }
155 of.closeTag();
156}
157
158
159void
164 of.writeAttr("electricity", lane.getEmissions<PollutantsInterface::ELEC>()).writeAttr("maxspeed", lane.getSpeedLimit());
165 of.writeAttr("meanspeed", lane.getMeanSpeed()).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber());
166 of.closeTag();
167}
168
169
170void
172 of.openTag("tls");
174 std::vector<std::string> ids = vc.getAllTLIds();
175 for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) {
178
179 std::vector<std::string> laneIDs;
180 for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
181 const MSTrafficLightLogic::LaneVector& llanes = (*i);
182 for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) {
183 laneIDs.push_back((*j)->getID());
184 }
185 }
186
187 std::string lane_output = "";
188 for (int i1 = 0; i1 < (int)laneIDs.size(); ++i1) {
189 lane_output += laneIDs[i1] + " ";
190 }
191
192 std::string state = vars.getActive()->getCurrentPhaseDef().getState();
193 of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag();
194 }
195 of.closeTag();
196}
197
198
199/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_PERSON
@ SUMO_ATTR_LANE
@ SUMO_ATTR_NOISE
MSMeanData_Harmonoise.
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_PMX
@ SUMO_ATTR_Y
@ SUMO_ATTR_Z
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_WAITING
@ SUMO_ATTR_X
@ SUMO_ATTR_HC
@ SUMO_ATTR_FUEL
@ SUMO_ATTR_ELECTRICITY
@ SUMO_ATTR_CO
@ SUMO_ATTR_SLOPE
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_VEHICLE
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_CO2
@ SUMO_ATTR_ID
@ SUMO_ATTR_ECLASS
@ SUMO_ATTR_NOX
@ SUMO_ATTR_POSITION
static double naviDegree(const double angle)
static double computeNoise(SUMOEmissionClass c, double v, double a)
Returns the noise produced by the a vehicle of the given type at the given speed.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Stores edges and lanes, performs moving of vehicle.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
Definition MSEdge.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
bool isNormal() const
return whether this edge is an internal edge
Definition MSEdge.h:263
double getCurrentTravelTime(const double minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition MSEdge.cpp:1037
static void writeVehicles(OutputDevice &of)
Writes the XML Nodes for the vehicles (e.g. speed, position, emissions)
static void writeTLS(OutputDevice &of, SUMOTime timestep)
Writes the XML Nodes for the traffic lights (e.g. actual state)
static void writePersons(OutputDevice &of)
Writes the XML Nodes for the persons (e.g. speed, position)
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
static void writeEdge(OutputDevice &of)
Writes the XML Nodes for the edges (e.g. traveltime)
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the XML Nodes for the lanes (e.g. emissions, occupancy)
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:81
Representation of a lane in the micro simulation.
Definition MSLane.h:84
double getNettoOccupancy() const
Returns the netto (excluding minGaps) occupancy of this lane during the last step (including minGaps)
Definition MSLane.cpp:3400
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition MSLane.h:456
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition MSLane.h:597
double getHarmonoise_NoiseEmissions() const
Returns the sum of last step noise emissions.
Definition MSLane.cpp:3474
double getEmissions() const
Returns the sum of last step emissions The value is always per 1s, so multiply by step length if nece...
Definition MSLane.h:1174
double getMeanSpeed() const
Returns the mean speed on this lane.
Definition MSLane.cpp:3428
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition MSNet.h:457
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:384
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1200
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition MSNet.h:427
bool hasElevation() const
return whether the network contains elevation data
Definition MSNet.h:796
const std::string & getState() const
Returns the state within this phase.
Storage for all programs of a single tls.
MSTrafficLightLogic * getActive() const
A class that stores and controls tls and switching of their programs.
std::vector< std::string > getAllTLIds() const
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
virtual double getEdgePos() const
Return the position on the edge.
virtual double getAngle() const
return the current angle of the transportable
virtual double getSpeed() const
the current speed of the transportable
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
Position getPosition(const double) const
Return current position (x/y, cartesian)
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
MSStageType getCurrentStageType() const
the current stage type of the transportable
const MSEdge * getEdge() const
Returns the current edge.
The class responsible for building and deletion of vehicles.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
const std::string & getID() const
Returns the name of the vehicle type.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
const std::string & getID() const
Returns the id.
Definition Named.h:74
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams *param)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:52
double z() const
Returns the z-position.
Definition Position.h:62
double y() const
Returns the y-position.
Definition Position.h:57
virtual double getAcceleration() const =0
Returns the object's acceleration.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getSlope() const =0
Returns the slope of the road at object's position in degrees.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition SUMOVehicle.h:62
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual EnergyParams * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
virtual double getAngle() const =0
Get the vehicle's angle.
virtual const MSRoute & getRoute() const =0
Returns the current route.
Storage for collected values of all emission types.