Eclipse SUMO - Simulation of Urban MObility
MSFullExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-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 /****************************************************************************/
21 // Dumping a hugh List of Parameters available in the Simulation
22 /****************************************************************************/
23 #include <config.h>
24 
28 #include <utils/geom/GeomHelper.h>
29 #include <microsim/MSEdge.h>
30 #include <microsim/MSEdgeControl.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSVehicle.h>
36 #include "MSFullExport.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 void
44  of.openTag("data") << " timestep=\"" << time2string(timestep) << "\"";
45  //Vehicles
46  writeVehicles(of);
47  //Edges
48  writeEdge(of);
49  //TrafficLights
50  writeTLS(of, timestep);
51  of.closeTag();
52 }
53 
54 
55 void
57  of.openTag("vehicles");
59  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
60  const SUMOVehicle* veh = it->second;
61  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
62  if (veh->isOnRoad()) {
63  std::string fclass = veh->getVehicleType().getID();
64  fclass = fclass.substr(0, fclass.find_first_of("@"));
66  veh->getVehicleType().getEmissionClass(), veh->getSpeed(),
67  veh->getAcceleration(), veh->getSlope(),
68  veh->getEmissionParameters());
69  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
70  of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx);
71  of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity);
73  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass);
74  if (microVeh != nullptr) {
75  of.writeAttr("waiting", microVeh->getWaitingSeconds());
76  of.writeAttr("lane", microVeh->getLane()->getID());
77  }
78  of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
79  of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y());
80  of.closeTag();
81  }
82  }
83  of.closeTag();
84 }
85 
86 void
88  of.openTag("edges");
90  const MSEdgeVector& edges = ec.getEdges();
91  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
92  MSEdge& edge = **e;
93  if (!MSGlobals::gUsingInternalLanes && !edge.isNormal()) {
94  continue;
95  }
96  of.openTag("edge").writeAttr("id", edge.getID()).writeAttr("traveltime", edge.getCurrentTravelTime());
97  const std::vector<MSLane*>& lanes = edge.getLanes();
98  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
99  writeLane(of, **lane);
100  }
101  of.closeTag();
102  }
103  of.closeTag();
104 }
105 
106 
107 void
109 
110  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("CO", lane.getCOEmissions()).writeAttr("CO2", lane.getCO2Emissions());
111  of.writeAttr("NOx", lane.getNOxEmissions()).writeAttr("PMx", lane.getPMxEmissions()).writeAttr("HC", lane.getHCEmissions());
112  of.writeAttr("noise", lane.getHarmonoise_NoiseEmissions()).writeAttr("fuel", lane.getFuelConsumption());
113  of.writeAttr("electricity", lane.getElectricityConsumption()).writeAttr("maxspeed", lane.getSpeedLimit());
114  of.writeAttr("meanspeed", lane.getMeanSpeed()).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber());
115  of.closeTag();
116 }
117 
118 
119 void
121  of.openTag("tls");
123  std::vector<std::string> ids = vc.getAllTLIds();
124  for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) {
127 
128  std::vector<std::string> laneIDs;
129  for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
130  const MSTrafficLightLogic::LaneVector& llanes = (*i);
131  for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) {
132  laneIDs.push_back((*j)->getID());
133  }
134  }
135 
136  std::string lane_output = "";
137  for (int i1 = 0; i1 < (int)laneIDs.size(); ++i1) {
138  lane_output += laneIDs[i1] + " ";
139  }
140 
141  std::string state = vars.getActive()->getCurrentPhaseDef().getState();
142  of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag();
143  }
144  of.closeTag();
145 }
146 
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
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:192
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.
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
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:166
double getCurrentTravelTime(const double minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:798
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 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:66
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
double getPMxEmissions() const
Returns the sum of last step PMx emissions.
Definition: MSLane.cpp:2801
double getNOxEmissions() const
Returns the sum of last step NOx emissions.
Definition: MSLane.cpp:2813
double getNettoOccupancy() const
Returns the netto (excluding minGaps) occupancy of this lane during the last step (including minGaps)
Definition: MSLane.cpp:2708
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition: MSLane.h:399
double getCO2Emissions() const
Returns the sum of last step CO2 emissions.
Definition: MSLane.cpp:2777
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition: MSLane.h:531
double getFuelConsumption() const
Returns the sum of last step fuel consumption.
Definition: MSLane.cpp:2837
double getElectricityConsumption() const
Returns the sum of last step electricity consumption.
Definition: MSLane.cpp:2849
double getHarmonoise_NoiseEmissions() const
Returns the sum of last step noise emissions.
Definition: MSLane.cpp:2861
double getCOEmissions() const
Returns the sum of last step CO emissions.
Definition: MSLane.cpp:2789
double getMeanSpeed() const
Returns the mean speed on this lane.
Definition: MSLane.cpp:2736
double getHCEmissions() const
Returns the sum of last step HC emissions.
Definition: MSLane.cpp:2825
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:444
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:371
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:414
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.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
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.
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
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:669
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:550
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
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.
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map< int, double > *param=0)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
virtual double getAcceleration() const =0
Returns the object's acceleration.
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 const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
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:58
virtual const std::map< int, double > * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
virtual const MSRoute & getRoute() const =0
Returns the current route.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual double getAngle() const =0
Get the vehicle's angle.
Storage for collected values of all emission types.