SUMO - Simulation of Urban MObility
MSEmissionExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Realises dumping Emission Data
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2012-2017 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/MSNet.h>
39 #include <microsim/MSVehicle.h>
40 #include "MSEmissionExport.h"
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 void
51 MSEmissionExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
52  of.openTag("timestep").writeAttr("time", time2string(timestep));
53  of.setPrecision(precision);
55  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
56  const SUMOVehicle* veh = it->second;
57  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
58  if (veh->isOnRoad()) {
59  std::string fclass = veh->getVehicleType().getID();
60  fclass = fclass.substr(0, fclass.find_first_of("@"));
62  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
63  of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx);
64  of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity);
66  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass);
67  if (microVeh != 0) {
68  of.writeAttr("waiting", microVeh->getWaitingSeconds());
69  of.writeAttr("lane", microVeh->getLane()->getID());
70  }
71  of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
72  of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y());
73  of.closeTag();
74  }
75  }
77  of.closeTag();
78 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
virtual Position getPosition(const SUMOReal offset=0) const =0
Return current position (x/y, cartesian)
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
long long int SUMOTime
Definition: SUMOTime.h:43
virtual SUMOReal getAngle() const =0
Get the vehicle&#39;s angle.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:34
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...
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
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:159
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
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. ...
const std::string & getID() const
Returns the id.
Definition: Named.h:66
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:308
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
static SUMOReal naviDegree(const SUMOReal angle)
Definition: GeomHelper.cpp:191
virtual const MSRoute & getRoute() const =0
Returns the current route.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
const std::string & getID() const
Returns the name of the vehicle type.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:570
virtual SUMOReal getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
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:71
bool closeTag()
Closes the most recently opened tag.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
The class responsible for building and deletion of vehicles.
virtual SUMOReal getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:488
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.