SUMO - Simulation of Urban MObility
MSFullExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Dumping a hugh List of Parameters available in the Simulation
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2012-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
37 #include <utils/geom/GeomHelper.h>
38 #include <microsim/MSEdge.h>
39 #include <microsim/MSEdgeControl.h>
40 #include <microsim/MSNet.h>
41 #include <microsim/MSVehicle.h>
44 #include "MSFullExport.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 void
56  of.openTag("data") << " timestep=\"" << time2string(timestep) << "\"";
57  //Vehicles
58  writeVehicles(of);
59  //Edges
60  writeEdge(of);
61  //TrafficLights
62  writeTLS(of, timestep);
63  of.closeTag();
64 }
65 
66 
67 void
69  of.openTag("vehicles");
71  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
72  const SUMOVehicle* veh = it->second;
73  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
74  if (veh->isOnRoad()) {
75  std::string fclass = veh->getVehicleType().getID();
76  fclass = fclass.substr(0, fclass.find_first_of("@"));
78  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
79  of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx);
80  of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity);
82  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass);
83  if (microVeh != 0) {
84  of.writeAttr("waiting", microVeh->getWaitingSeconds());
85  of.writeAttr("lane", microVeh->getLane()->getID());
86  }
87  of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
88  of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y());
89  of.closeTag();
90  }
91  }
92  of.closeTag();
93 }
94 
95 void
97  of.openTag("edges");
99  const MSEdgeVector& edges = ec.getEdges();
100  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
101  MSEdge& edge = **e;
102  of.openTag("edge").writeAttr("id", edge.getID()).writeAttr("traveltime", edge.getCurrentTravelTime());
103  const std::vector<MSLane*>& lanes = edge.getLanes();
104  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
105  writeLane(of, **lane);
106  }
107  of.closeTag();
108  }
109  of.closeTag();
110 }
111 
112 
113 void
115 
116  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("CO", lane.getCOEmissions()).writeAttr("CO2", lane.getCO2Emissions());
117  of.writeAttr("NOx", lane.getNOxEmissions()).writeAttr("PMx", lane.getPMxEmissions()).writeAttr("HC", lane.getHCEmissions());
118  of.writeAttr("noise", lane.getHarmonoise_NoiseEmissions()).writeAttr("fuel", lane.getFuelConsumption());
119  of.writeAttr("electricity", lane.getElectricityConsumption()).writeAttr("maxspeed", lane.getSpeedLimit());
120  of.writeAttr("meanspeed", lane.getMeanSpeed() * 3.6).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber());
121  of.closeTag();
122 }
123 
124 
125 void
127  of.openTag("tls");
129  std::vector<std::string> ids = vc.getAllTLIds();
130  for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) {
133 
134  std::vector<std::string> laneIDs;
135  for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
136  const MSTrafficLightLogic::LaneVector& llanes = (*i);
137  for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) {
138  laneIDs.push_back((*j)->getID());
139  }
140  }
141 
142  std::string lane_output = "";
143  for (int i1 = 0; i1 < (int)laneIDs.size(); ++i1) {
144  lane_output += laneIDs[i1] + " ";
145  }
146 
147  std::string state = vars.getActive()->getCurrentPhaseDef().getState();
148  of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag();
149  }
150  of.closeTag();
151 }
152 
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:656
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
static void writeVehicles(OutputDevice &of)
Writes the XML Nodes for the vehicles (e.g. speed, position, emissions)
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
const std::string & getState() const
Returns the state within this phase.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getPMxEmissions() const
Returns the sum of last step PMx emissions.
Definition: MSLane.cpp:2124
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Storage for all programs of a single tls.
static void writeEdge(OutputDevice &of)
Writes the XML Nodes for the edges (e.g. traveltime)
virtual const MSRoute & getRoute() const =0
Returns the current route.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:487
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
virtual SUMOReal getAngle() const =0
Get the vehicle&#39;s angle.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
Storage for collected values of all emission types.
SUMOReal getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:472
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A class that stores and controls tls and switching of their programs.
static SUMOReal computeNoise(SUMOEmissionClass c, double v, double a)
Returns the noise produced by the a vehicle of the given type at the given speed. ...
A road/street connecting two junctions.
Definition: MSEdge.h:80
SUMOReal getNettoOccupancy() const
Returns the netto (excluding minGaps) occupancy of this lane during the last step (including minGaps)...
Definition: MSLane.cpp:2056
SUMOReal getNOxEmissions() const
Returns the sum of last step NOx emissions.
Definition: MSLane.cpp:2136
SUMOReal getFuelConsumption() const
Returns the sum of last step fuel consumption.
Definition: MSLane.cpp:2160
Representation of a vehicle.
Definition: SUMOVehicle.h:66
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:556
SUMOReal getHCEmissions() const
Returns the sum of last step HC emissions.
Definition: MSLane.cpp:2148
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:380
SUMOReal getHarmonoise_NoiseEmissions() const
Returns the sum of last step noise emissions.
Definition: MSLane.cpp:2184
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition: MSLane.h:353
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:74
SUMOReal getElectricityConsumption() const
Returns the sum of last step electricity consumption.
Definition: MSLane.cpp:2172
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
static SUMOReal naviDegree(const SUMOReal angle)
Definition: GeomHelper.cpp:191
SUMOReal getMeanSpeed() const
Returns the mean speed on this lane.
Definition: MSLane.cpp:2084
std::vector< MSLane * > LaneVector
Definition of the list of links that participate in this tl-light.
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of links that do have the same attribute.
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
SUMOReal getCO2Emissions() const
Returns the sum of last step CO2 emissions.
Definition: MSLane.cpp:2100
SUMOReal getCOEmissions() const
Returns the sum of last step CO emissions.
Definition: MSLane.cpp:2112
virtual SUMOReal getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
const std::string & getID() const
Returns the name of the vehicle type.
virtual Position getPosition(const SUMOReal offset=0) const =0
Return current position (x/y, cartesian)
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
const MSEdgeVector & getEdges() const
Returns loaded edges.
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the XML Nodes for the lanes (e.g. emissions, occupancy)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
static void writeTLS(OutputDevice &of, SUMOTime timestep)
Writes the XML Nodes for the traffic lights (e.g. actual state)
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:350
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
virtual SUMOReal getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
MSTrafficLightLogic * getActive() const
std::vector< std::string > getAllTLIds() const
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.