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-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 // Dumping a hugh List of Parameters available in the Simulation
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
30 #include <utils/geom/GeomHelper.h>
31 #include <microsim/MSEdge.h>
32 #include <microsim/MSEdgeControl.h>
33 #include <microsim/MSNet.h>
34 #include <microsim/MSVehicle.h>
38 #include "MSFullExport.h"
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 void
46  of.openTag("data") << " timestep=\"" << time2string(timestep) << "\"";
47  //Vehicles
48  writeVehicles(of);
49  //Edges
50  writeEdge(of);
51  //TrafficLights
52  writeTLS(of, timestep);
53  of.closeTag();
54 }
55 
56 
57 void
59  of.openTag("vehicles");
61  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
62  const SUMOVehicle* veh = it->second;
63  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
64  if (veh->isOnRoad()) {
65  std::string fclass = veh->getVehicleType().getID();
66  fclass = fclass.substr(0, fclass.find_first_of("@"));
68  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
69  of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx);
70  of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity);
72  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass);
73  if (microVeh != nullptr) {
74  of.writeAttr("waiting", microVeh->getWaitingSeconds());
75  of.writeAttr("lane", microVeh->getLane()->getID());
76  }
77  of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
78  of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y());
79  of.closeTag();
80  }
81  }
82  of.closeTag();
83 }
84 
85 void
87  of.openTag("edges");
89  const MSEdgeVector& edges = ec.getEdges();
90  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
91  MSEdge& edge = **e;
92  of.openTag("edge").writeAttr("id", edge.getID()).writeAttr("traveltime", edge.getCurrentTravelTime());
93  const std::vector<MSLane*>& lanes = edge.getLanes();
94  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
95  writeLane(of, **lane);
96  }
97  of.closeTag();
98  }
99  of.closeTag();
100 }
101 
102 
103 void
105 
106  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("CO", lane.getCOEmissions()).writeAttr("CO2", lane.getCO2Emissions());
107  of.writeAttr("NOx", lane.getNOxEmissions()).writeAttr("PMx", lane.getPMxEmissions()).writeAttr("HC", lane.getHCEmissions());
108  of.writeAttr("noise", lane.getHarmonoise_NoiseEmissions()).writeAttr("fuel", lane.getFuelConsumption());
109  of.writeAttr("electricity", lane.getElectricityConsumption()).writeAttr("maxspeed", lane.getSpeedLimit());
110  of.writeAttr("meanspeed", lane.getMeanSpeed()).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber());
111  of.closeTag();
112 }
113 
114 
115 void
117  of.openTag("tls");
119  std::vector<std::string> ids = vc.getAllTLIds();
120  for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) {
123 
124  std::vector<std::string> laneIDs;
125  for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
126  const MSTrafficLightLogic::LaneVector& llanes = (*i);
127  for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) {
128  laneIDs.push_back((*j)->getID());
129  }
130  }
131 
132  std::string lane_output = "";
133  for (int i1 = 0; i1 < (int)laneIDs.size(); ++i1) {
134  lane_output += laneIDs[i1] + " ";
135  }
136 
137  std::string state = vars.getActive()->getCurrentPhaseDef().getState();
138  of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag();
139  }
140  of.closeTag();
141 }
142 
MSEdge::getCurrentTravelTime
double getCurrentTravelTime(const double minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:787
MSFullExport::write
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
Definition: MSFullExport.cpp:45
MSVehicleType::getEmissionClass
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Definition: MSVehicleType.h:194
SUMOTrafficObject::getPosition
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
MSLane::getCOEmissions
double getCOEmissions() const
Returns the sum of last step CO emissions.
Definition: MSLane.cpp:2737
SUMOVehicle::getAngle
virtual double getAngle() const =0
Get the vehicle's angle.
MSTLLogicControl.h
MSNet.h
PollutantsInterface::Emissions::PMx
double PMx
Definition: PollutantsInterface.h:68
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
SUMOTrafficObject::getAcceleration
virtual double getAcceleration() const =0
Returns the vehicle's acceleration.
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
PollutantsInterface::Emissions::CO
double CO
Definition: PollutantsInterface.h:64
MSTLLogicControl::getAllTLIds
std::vector< std::string > getAllTLIds() const
Definition: MSTLLogicControl.cpp:604
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:194
SUMOVehicle::isOnRoad
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
MSLane::getHarmonoise_NoiseEmissions
double getHarmonoise_NoiseEmissions() const
Returns the sum of last step noise emissions.
Definition: MSLane.cpp:2809
MSLane::getHCEmissions
double getHCEmissions() const
Returns the sum of last step HC emissions.
Definition: MSLane.cpp:2773
MSEdge.h
PollutantsInterface::getName
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:100
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:75
MSTLLogicControl::TLSLogicVariants::getActive
MSTrafficLightLogic * getActive() const
Definition: MSTLLogicControl.cpp:197
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
HelpersHarmonoise.h
MSLane::getVehicleNumber
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition: MSLane.h:401
MSTrafficLightLogic.h
SUMOVehicle::getRoute
virtual const MSRoute & getRoute() const =0
Returns the current route.
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
MSLane::getCO2Emissions
double getCO2Emissions() const
Returns the sum of last step CO2 emissions.
Definition: MSLane.cpp:2725
MSTrafficLightLogic::LaneVector
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
Definition: MSTrafficLightLogic.h:71
MSLane::getElectricityConsumption
double getElectricityConsumption() const
Returns the sum of last step electricity consumption.
Definition: MSLane.cpp:2797
HelpersHarmonoise::computeNoise
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.
Definition: HelpersHarmonoise.cpp:97
MSTLLogicControl::get
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
Definition: MSTLLogicControl.cpp:584
PollutantsInterface::Emissions::CO2
double CO2
Definition: PollutantsInterface.h:63
PollutantsInterface.h
MSPhaseDefinition::getState
const std::string & getState() const
Returns the state within this phase.
Definition: MSPhaseDefinition.h:200
MSFullExport::writeEdge
static void writeEdge(OutputDevice &of)
Writes the XML Nodes for the edges (e.g. traveltime)
Definition: MSFullExport.cpp:86
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:186
MSFullExport::writeLane
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the XML Nodes for the lanes (e.g. emissions, occupancy)
Definition: MSFullExport.cpp:104
MSLane::getNOxEmissions
double getNOxEmissions() const
Returns the sum of last step NOx emissions.
Definition: MSLane.cpp:2761
MSFullExport::writeTLS
static void writeTLS(OutputDevice &of, SUMOTime timestep)
Writes the XML Nodes for the traffic lights (e.g. actual state)
Definition: MSFullExport.cpp:116
OutputDevice.h
SUMOTrafficObject::getSlope
virtual double getSlope() const =0
Returns the slope of the road at vehicle's position.
MSLane::getMeanSpeed
double getMeanSpeed() const
Returns the mean speed on this lane.
Definition: MSLane.cpp:2709
PollutantsInterface::computeAll
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...
Definition: PollutantsInterface.cpp:155
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
MSLane::getNettoOccupancy
double getNettoOccupancy() const
Returns the netto (excluding minGaps) occupancy of this lane during the last step (including minGaps)
Definition: MSLane.cpp:2681
MSFullExport.h
MSLane::getPMxEmissions
double getPMxEmissions() const
Returns the sum of last step PMx emissions.
Definition: MSLane.cpp:2749
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
MSTrafficLightLogic::getLaneVectors
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
Definition: MSTrafficLightLogic.h:180
PollutantsInterface::Emissions::electricity
double electricity
Definition: PollutantsInterface.h:69
MSEdgeControl.h
MSNet::getTLSControl
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:410
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
PollutantsInterface::Emissions::NOx
double NOx
Definition: PollutantsInterface.h:67
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
PollutantsInterface::Emissions
Storage for collected values of all emission types.
Definition: PollutantsInterface.h:62
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
MSFullExport::writeVehicles
static void writeVehicles(OutputDevice &of)
Writes the XML Nodes for the vehicles (e.g. speed, position, emissions)
Definition: MSFullExport.cpp:58
PollutantsInterface::Emissions::HC
double HC
Definition: PollutantsInterface.h:65
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:165
MSTLLogicControl::TLSLogicVariants
Storage for all programs of a single tls.
Definition: MSTLLogicControl.h:86
MSTrafficLightLogic::LaneVectorVector
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
Definition: MSTrafficLightLogic.h:74
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:72
MSEdgeControl
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
GeomHelper.h
MSTLLogicControl
A class that stores and controls tls and switching of their programs.
Definition: MSTLLogicControl.h:60
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:178
PollutantsInterface::Emissions::fuel
double fuel
Definition: PollutantsInterface.h:66
SUMOTrafficObject::getPositionOnLane
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
MSLane::getSpeedLimit
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition: MSLane.h:533
MSNet::getEdgeControl
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:380
MSLane::getFuelConsumption
double getFuelConsumption() const
Returns the sum of last step fuel consumption.
Definition: MSLane.cpp:2785
MSVehicleControl.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
MSEdgeControl::getEdges
const MSEdgeVector & getEdges() const
Returns loaded edges.
Definition: MSEdgeControl.h:168
SUMOTrafficObject::getSpeed
virtual double getSpeed() const =0
Returns the vehicle's current speed.
MSTrafficLightLogic::getCurrentPhaseDef
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
MSVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:657
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80