SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSFullExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
6 // Dumping a hugh List of Parameters available in the Simulation
7 /****************************************************************************/
8 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
9 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
10 /****************************************************************************/
11 //
12 // This file is part of SUMO.
13 // SUMO is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <microsim/MSEdgeControl.h>
32 #include <microsim/MSEdge.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSGlobals.h>
36 #include "MSFullExport.h"
37 #include <microsim/MSNet.h>
38 #include <microsim/MSVehicle.h>
40 
41 #ifdef HAVE_MESOSIM
42 #include <mesosim/MELoop.h>
43 #include <mesosim/MESegment.h>
44 #endif
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");
73  for (; it != end; ++it) {
74  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
75  if (veh->isOnRoad()) {
76  std::string fclass = veh->getVehicleType().getID();
77  fclass = fclass.substr(0, fclass.find_first_of("@"));
79  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", toString(veh->getVehicleType().getEmissionClass()));
80  of.writeAttr("co2", veh->getHBEFA_CO2Emissions()).writeAttr("co", veh->getHBEFA_COEmissions()).writeAttr("hc", veh->getHBEFA_HCEmissions());
81  of.writeAttr("nox", veh->getHBEFA_NOxEmissions()).writeAttr("pmx", veh->getHBEFA_PMxEmissions()).writeAttr("noise", veh->getHarmonoise_NoiseEmissions());
82  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass).writeAttr("waiting", veh->getWaitingSeconds());
83  of.writeAttr("lane", veh->getLane()->getID()).writeAttr("pos_lane", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed() * 3.6);
84  of.writeAttr("angle", veh->getAngle()).writeAttr("x", pos.x()).writeAttr("y", pos.y());
85  of.closeTag();
86  }
87  }
88  of.closeTag();
89 }
90 
91 void
93  of.openTag("edges");
95  const std::vector<MSEdge*>& edges = ec.getEdges();
96  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
97  MSEdge& edge = **e;
98  of.openTag("edge").writeAttr("id", edge.getID()).writeAttr("traveltime", edge.getCurrentTravelTime());
99  const std::vector<MSLane*>& lanes = edge.getLanes();
100  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
101  writeLane(of, **lane);
102  }
103  of.closeTag();
104  }
105  of.closeTag();
106 }
107 
108 
109 void
111 
112  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("co", lane.getHBEFA_COEmissions()).writeAttr("co2", lane.getHBEFA_CO2Emissions());
113  of.writeAttr("nox", lane.getHBEFA_NOxEmissions()).writeAttr("pmx", lane.getHBEFA_PMxEmissions()).writeAttr("hc", lane.getHBEFA_HCEmissions());
114  of.writeAttr("noise", lane.getHarmonoise_NoiseEmissions()).writeAttr("fuel", lane.getHBEFA_FuelConsumption()).writeAttr("maxspeed", lane.getSpeedLimit() * 3.6); // @todo: use m/s for speed
115  of.writeAttr("meanspeed", lane.getMeanSpeed() * 3.6).writeAttr("occupancy", lane.getOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber());
116  of.closeTag();
117 }
118 
119 
120 void
122  of.openTag("tls");
124  std::vector<std::string> ids = vc.getAllTLIds();
125  for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) {
128 
129  std::vector<std::string> laneIDs;
130  for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
131  const MSTrafficLightLogic::LaneVector& llanes = (*i);
132  for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) {
133  laneIDs.push_back((*j)->getID());
134  }
135  }
136 
137  std::string lane_output = "";
138  for (unsigned int i1 = 0; i1 < laneIDs.size(); ++i1) {
139  lane_output += laneIDs[i1] + " ";
140  }
141 
142  std::string state = vars.getActive()->getCurrentPhaseDef().getState();
143  of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag();
144  }
145  of.closeTag();
146 }
147 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
const std::string & getState() const
Returns the state within this phase.
SUMOReal getHBEFA_HCEmissions() const
Returns HC emission of the current state.
Definition: MSVehicle.cpp:1844
Storage for all programs of a single tls.
Position positionAtOffset(SUMOReal pos) const
Returns the position at the given length.
static void writeEdge(OutputDevice &of)
Writes the XML Nodes for the edges (e.g. traveltime)
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
SUMOReal getHBEFA_NOxEmissions() const
Returns NOx emission of the current state.
Definition: MSVehicle.cpp:1850
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=0.00001) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:433
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:150
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:86
std::vector< std::string > getAllTLIds() const
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
SUMOReal getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:284
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
A class that stores and controls tls and switching of their programs.
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:73
SUMOReal getHBEFA_HCEmissions() const
Returns the sum of last step HC emissions.
Definition: MSLane.cpp:1292
SUMOReal getHBEFA_COEmissions() const
Returns CO emission of the current state.
Definition: MSVehicle.cpp:1838
MSTrafficLightLogic * getActive() const
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:299
SUMOReal getHBEFA_COEmissions() const
Returns the sum of last step CO emissions.
Definition: MSLane.cpp:1256
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:248
SUMOReal getMeanSpeed() const
Returns the mean speed on this lane.
Definition: MSLane.cpp:1228
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
SUMOReal getHBEFA_PMxEmissions() const
Returns PMx emission of the current state.
Definition: MSVehicle.cpp:1856
SUMOReal getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:352
SUMOReal getHBEFA_PMxEmissions() const
Returns the sum of last step PMx emissions.
Definition: MSLane.cpp:1268
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:51
SUMOReal getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
Definition: MSVehicle.cpp:1868
unsigned int getVehicleNumber() const
Returns the number of vehicles on this lane.
Definition: MSLane.h:280
const LaneVectorVector & getLanes() const
Returns the list of lists of all lanes controlled by this tls.
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.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:94
const std::string & getID() const
Returns the name of the vehicle type.
SUMOReal getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:292
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:353
SUMOReal getHBEFA_FuelConsumption() const
Returns the sum of last step fuel consumption.
Definition: MSLane.cpp:1304
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the XML Nodes for the lanes (e.g. emissions, occupancy)
SUMOReal getHBEFA_NOxEmissions() const
Returns the sum of last step NOx emissions.
Definition: MSLane.cpp:1280
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:318
const std::vector< MSEdge * > & getEdges() const
Returns loaded edges.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
SUMOReal getHBEFA_CO2Emissions() const
Returns the sum of last step CO2 emissions.
Definition: MSLane.cpp:1244
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:269
The class responsible for building and deletion of vehicles.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:331
SUMOReal getHarmonoise_NoiseEmissions() const
Returns the sum of last step noise emissions.
Definition: MSLane.cpp:1316
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:323
SUMOReal getHBEFA_CO2Emissions() const
Returns CO2 emission of the current state.
Definition: MSVehicle.cpp:1832
Representation of a lane in the micro simulation.
Definition: MSLane.h:73
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SUMOReal getAngle() const
Returns the vehicle&#39;s direction in degrees.
Definition: MSVehicle.cpp:504
const std::string & getID() const
Returns the name of the vehicle.
SUMOReal getOccupancy() const
Returns the occupancy of this lane during the last step.
Definition: MSLane.cpp:1216