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 /****************************************************************************/
10 // Dumping a hugh List of Parameters available in the Simulation
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2012-2014 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 
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSEdgeControl.h>
38 #include <microsim/MSNet.h>
39 #include <microsim/MSVehicle.h>
41 #include "MSFullExport.h"
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 void
53  of.openTag("data") << " timestep=\"" << time2string(timestep) << "\"";
54  //Vehicles
55  writeVehicles(of);
56  //Edges
57  writeEdge(of);
58  //TrafficLights
59  writeTLS(of, timestep);
60  of.closeTag();
61 }
62 
63 
64 void
66  of.openTag("vehicles");
70  for (; it != end; ++it) {
71  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
72  if (veh->isOnRoad()) {
73  std::string fclass = veh->getVehicleType().getID();
74  fclass = fclass.substr(0, fclass.find_first_of("@"));
76  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
77  of.writeAttr("CO2", veh->getCO2Emissions()).writeAttr("CO", veh->getCOEmissions()).writeAttr("HC", veh->getHCEmissions());
78  of.writeAttr("NOx", veh->getNOxEmissions()).writeAttr("PMx", veh->getPMxEmissions()).writeAttr("noise", veh->getHarmonoise_NoiseEmissions());
79  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass).writeAttr("waiting", veh->getWaitingSeconds());
80  of.writeAttr("lane", veh->getLane()->getID()).writeAttr("pos_lane", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
81  of.writeAttr("angle", veh->getAngle()).writeAttr("x", pos.x()).writeAttr("y", pos.y());
82  // !!! fuel is missing here
83  of.closeTag();
84  }
85  }
86  of.closeTag();
87 }
88 
89 void
91  of.openTag("edges");
93  const std::vector<MSEdge*>& edges = ec.getEdges();
94  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
95  MSEdge& edge = **e;
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()).writeAttr("maxspeed", lane.getSpeedLimit());
113  of.writeAttr("meanspeed", lane.getMeanSpeed() * 3.6).writeAttr("occupancy", lane.getNettoOccupancy()).writeAttr("vehicle_count", lane.getVehicleNumber());
114  of.closeTag();
115 }
116 
117 
118 void
120  of.openTag("tls");
122  std::vector<std::string> ids = vc.getAllTLIds();
123  for (std::vector<std::string>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) {
126 
127  std::vector<std::string> laneIDs;
128  for (MSTrafficLightLogic::LaneVectorVector::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
129  const MSTrafficLightLogic::LaneVector& llanes = (*i);
130  for (MSTrafficLightLogic::LaneVector::const_iterator j = llanes.begin(); j != llanes.end(); ++j) {
131  laneIDs.push_back((*j)->getID());
132  }
133  }
134 
135  std::string lane_output = "";
136  for (unsigned int i1 = 0; i1 < laneIDs.size(); ++i1) {
137  lane_output += laneIDs[i1] + " ";
138  }
139 
140  std::string state = vars.getActive()->getCurrentPhaseDef().getState();
141  of.openTag("trafficlight").writeAttr("id", *id_it).writeAttr("state", state).closeTag();
142  }
143  of.closeTag();
144 }
145 
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.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
const std::string & getState() const
Returns the state within this phase.
Storage for all programs of a single tls.
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's lanes.
Definition: MSEdge.h:173
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
SUMOReal getFuelConsumption() const
Returns the sum of last step fuel consumption.
Definition: MSLane.cpp:1426
SUMOReal getHCEmissions() const
Returns HC emission of the current state.
Definition: MSVehicle.cpp:2159
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=0.00001) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:445
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
SUMOReal getNettoOccupancy() const
Returns the netto (excluding minGaps) occupancy of this lane during the last step (including minGaps)...
Definition: MSLane.cpp:1316
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:87
std::vector< std::string > getAllTLIds() const
SUMOReal getCO2Emissions() const
Returns CO2 emission of the current state.
Definition: MSVehicle.cpp:2147
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:283
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
SUMOReal getHCEmissions() const
Returns the sum of last step HC emissions.
Definition: MSLane.cpp:1414
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:74
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:320
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:269
SUMOReal getMeanSpeed() const
Returns the mean speed on this lane.
Definition: MSLane.cpp:1350
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
SUMOReal getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition: MSLane.h:362
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
SUMOReal getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
Definition: MSVehicle.cpp:2183
SUMOReal getNOxEmissions() const
Returns NOx emission of the current state.
Definition: MSVehicle.cpp:2165
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
unsigned int getVehicleNumber() const
Returns the number of vehicles on this lane.
Definition: MSLane.h:285
SUMOReal getPMxEmissions() const
Returns PMx emission of the current state.
Definition: MSVehicle.cpp:2171
SUMOReal getCOEmissions() const
Returns CO emission of the current state.
Definition: MSVehicle.cpp:2153
SUMOReal getNOxEmissions() const
Returns the sum of last step NOx emissions.
Definition: MSLane.cpp:1402
SUMOReal getPMxEmissions() const
Returns the sum of last step PMx emissions.
Definition: MSLane.cpp:1390
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 getCO2Emissions() const
Returns the sum of last step CO2 emissions.
Definition: MSLane.cpp:1366
SUMOReal getCOEmissions() const
Returns the sum of last step CO emissions.
Definition: MSLane.cpp:1378
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:95
const std::string & getID() const
Returns the name of the vehicle type.
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:291
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:373
static void writeLane(OutputDevice &of, const MSLane &lane)
Writes the XML Nodes for the lanes (e.g. emissions, occupancy)
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:323
const std::vector< MSEdge * > & getEdges() const
Returns loaded edges.
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:290
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:336
SUMOReal getHarmonoise_NoiseEmissions() const
Returns the sum of last step noise emissions.
Definition: MSLane.cpp:1438
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:328
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SUMOReal getAngle() const
Returns the vehicle's direction in degrees.
Definition: MSVehicle.cpp:643
const std::string & getID() const
Returns the name of the vehicle.