SUMO - Simulation of Urban MObility
MSEmissionExport.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Realises dumping Emission Data
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
36 #include <utils/geom/GeomHelper.h>
37 #include <microsim/MSNet.h>
38 #include <microsim/MSVehicle.h>
40 #include "MSEmissionExport.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 void
47 MSEmissionExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
48  of.openTag("timestep").writeAttr("time", time2string(timestep));
49  of.setPrecision(precision);
51  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
52  const SUMOVehicle* veh = it->second;
53  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
54  if (veh->isOnRoad()) {
55  std::string fclass = veh->getVehicleType().getID();
56  fclass = fclass.substr(0, fclass.find_first_of("@"));
58  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
59  of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx);
60  of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity);
62  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass);
63  if (microVeh != 0) {
64  of.writeAttr("waiting", microVeh->getWaitingSeconds());
65  of.writeAttr("lane", microVeh->getLane()->getID());
66  }
67  of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
68  of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y());
69  of.closeTag();
70  }
71  }
73  of.closeTag();
74 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
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...
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:660
virtual const MSRoute & getRoute() const =0
Returns the current route.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:564
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:29
double y() const
Returns the y-position.
Definition: Position.h:67
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
double x() const
Returns the x-position.
Definition: Position.h:62
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Storage for collected values of all emission types.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
virtual double getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
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. ...
const std::string & getID() const
Returns the id.
Definition: Named.h:65
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:186
Representation of a vehicle.
Definition: SUMOVehicle.h:66
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
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.
virtual double getAngle() const =0
Get the vehicle&#39;s angle.
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
const std::string & getID() const
Returns the name of the vehicle type.
virtual Position getPosition(const double 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.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:51
The class responsible for building and deletion of vehicles.
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
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 double getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.