SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
emissionsMap_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Main for an emissions map writer
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #ifdef HAVE_VERSION_H
32 #include <version.h>
33 #endif
34 
36 #include <iostream>
37 #include <string>
38 #include <ctime>
40 #include <utils/options/Option.h>
46 #include <utils/common/ToString.h>
47 #include <utils/xml/XMLSubSys.h>
50 
51 #ifdef CHECK_MEMORY_LEAKS
52 #include <foreign/nvwa/debug_new.h>
53 #endif // CHECK_MEMORY_LEAKS
54 
55 
56 // ===========================================================================
57 // functions
58 // ===========================================================================
59 
60 
61 /* -------------------------------------------------------------------------
62  * main
63  * ----------------------------------------------------------------------- */
64 void single(const std::string& of, const std::string& className, SUMOEmissionClass c,
65  SUMOReal vMin, SUMOReal vMax, SUMOReal vStep,
66  SUMOReal aMin, SUMOReal aMax, SUMOReal aStep,
67  SUMOReal sMin, SUMOReal sMax, SUMOReal sStep,
68  bool verbose) {
69  if (verbose) {
70  WRITE_MESSAGE("Writing map of '" + className + "' into '" + of + "'.");
71  }
72  std::ofstream o(of.c_str());
73  for (SUMOReal v = vMin; v <= vMax; v += vStep) {
74  for (SUMOReal a = aMin; a <= aMax; a += aStep) {
75  for (SUMOReal s = sMin; s <= sMax; s += sStep) {
76  o << v << ";" << a << ";" << s << ";" << "CO" << ";" << PollutantsInterface::computeCO(c, v, a, s) << std::endl;
77  o << v << ";" << a << ";" << s << ";" << "CO2" << ";" << PollutantsInterface::computeCO2(c, v, a, s) << std::endl;
78  o << v << ";" << a << ";" << s << ";" << "HC" << ";" << PollutantsInterface::computeHC(c, v, a, s) << std::endl;
79  o << v << ";" << a << ";" << s << ";" << "PMx" << ";" << PollutantsInterface::computePMx(c, v, a, s) << std::endl;
80  o << v << ";" << a << ";" << s << ";" << "NOx" << ";" << PollutantsInterface::computeNOx(c, v, a, s) << std::endl;
81  o << v << ";" << a << ";" << s << ";" << "fuel" << ";" << PollutantsInterface::computeFuel(c, v, a, s) << std::endl;
82  }
83  }
84  }
85 }
86 
87 
88 
89 
90 int
91 main(int argc, char** argv) {
92  // build options
94  // give some application descriptions
95  oc.setApplicationDescription("Builds and writes an emissions map.");
96  oc.setApplicationName("emissionsMap", "SUMO emissionsMap Version " + (std::string)VERSION_STRING);
97  // add options
98  oc.addOptionSubTopic("Processing");
99  oc.doRegister("iterate", 'i', new Option_Bool(false));
100  oc.addDescription("iterate", "Processing", "If set, maps for all available emissions are written.");
101 
102  oc.doRegister("emission-class", 'e', new Option_String());
103  oc.addDescription("emission-class", "Processing", "Defines the name of the emission class to generate the map for.");
104 
105  oc.doRegister("v-min", new Option_Float(0.));
106  oc.addDescription("v-min", "Processing", "Defines the minimum velocity boundary of the map to generate (in [m/s]).");
107  oc.doRegister("v-max", new Option_Float(50.));
108  oc.addDescription("v-max", "Processing", "Defines the maximum velocity boundary of the map to generate (in [m/s]).");
109  oc.doRegister("v-step", new Option_Float(2.));
110  oc.addDescription("v-step", "Processing", "Defines the velocity step size (in [m/s]).");
111  oc.doRegister("a-min", new Option_Float(-4.));
112  oc.addDescription("a-min", "Processing", "Defines the minimum acceleration boundary of the map to generate (in [m/s^2]).");
113  oc.doRegister("a-max", new Option_Float(4.));
114  oc.addDescription("a-max", "Processing", "Defines the maximum acceleration boundary of the map to generate (in [m/s^2]).");
115  oc.doRegister("a-step", new Option_Float(.5));
116  oc.addDescription("a-step", "Processing", "Defines the acceleration step size (in [m/s^2]).");
117  oc.doRegister("s-min", new Option_Float(-10.));
118  oc.addDescription("s-min", "Processing", "Defines the minimum slope boundary of the map to generate (in [°]).");
119  oc.doRegister("s-max", new Option_Float(10.));
120  oc.addDescription("s-max", "Processing", "Defines the maximum slope boundary of the map to generate (in [°]).");
121  oc.doRegister("s-step", new Option_Float(1.));
122  oc.addDescription("s-step", "Processing", "Defines the slope step size (in [°]).");
123 
124  oc.addOptionSubTopic("Output");
125  oc.doRegister("output-file", 'o', new Option_String());
126  oc.addSynonyme("output", "output-file");
127  oc.addDescription("emission-class", "Output", "Defines the file (or the path if --iterate was set) to write the map(s) into.");
128 
129  oc.addOptionSubTopic("Emissions");
130  oc.doRegister("phemlight-path", 'p', new Option_FileName("./PHEMlight/"));
131  oc.addDescription("phemlight-path", "Emissions", "Determines where to load PHEMlight definitions from.");
132 
133  oc.addOptionSubTopic("Report");
134  oc.doRegister("verbose", 'v', new Option_Bool(false));
135  oc.addDescription("verbose", "Report", "Switches to verbose output.");
136  oc.doRegister("help", '?', new Option_Bool(false));
137  oc.addDescription("help", "Report", "Prints a help screen.");
138 
139  // run
140  int ret = 0;
141  try {
142  // initialise the application system (messaging, xml, options)
143  XMLSubSys::init();
144  OptionsIO::getOptions(true, argc, argv);
146  if (oc.processMetaOptions(argc < 2)) {
148  return 0;
149  }
150 
151  SUMOReal vMin = oc.getFloat("v-min");
152  SUMOReal vMax = oc.getFloat("v-max");
153  SUMOReal vStep = oc.getFloat("v-step");
154  SUMOReal aMin = oc.getFloat("a-min");
155  SUMOReal aMax = oc.getFloat("a-max");
156  SUMOReal aStep = oc.getFloat("a-step");
157  SUMOReal sMin = oc.getFloat("s-min");
158  SUMOReal sMax = oc.getFloat("s-max");
159  SUMOReal sStep = oc.getFloat("s-step");
160  if (!oc.getBool("iterate")) {
161  if (!oc.isSet("emission-class")) {
162  throw ProcessError("The emission class (-e) must be given.");
163  }
164  if (!oc.isSet("output-file")) {
165  throw ProcessError("The output file (-o) must be given.");
166  }
167  SUMOEmissionClass c = getVehicleEmissionTypeID(oc.getString("emission-class"));
168  single(oc.getString("output-file"), oc.getString("emission-class"),
169  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
170  } else {
171  if (!oc.isSet("output-file")) {
172  oc.set("output-file", "./");
173  }
174  // let's assume it's an old, plain enum
175  for (int ci = SVE_UNKNOWN; ci != SVE_META_PHEMLIGHT_END; ++ci) {
177  if (SumoEmissionClassStrings.has(c)) {
178  single(oc.getString("output-file") + getVehicleEmissionTypeName(c) + ".csv", getVehicleEmissionTypeName(c),
179  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
180  }
181  }
182  }
183  } catch (InvalidArgument& e) {
185  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
186  ret = 1;
187  } catch (ProcessError& e) {
188  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
190  }
191  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
192  ret = 1;
193 #ifndef _DEBUG
194  } catch (...) {
195  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
196  ret = 1;
197 #endif
198  }
200  if (ret == 0) {
201  std::cout << "Success." << std::endl;
202  }
203  return ret;
204 }
205 
206 
207 
208 /****************************************************************************/
209 
SUMOEmissionClass getVehicleEmissionTypeID(const std::string &name)
Returns the class id of the emission class given by its name.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:84
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:58
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
std::string getVehicleEmissionTypeName(SUMOEmissionClass id)
Returns the class name of the emission class given by its id.
static void getOptions(bool loadConfig, int argc=0, char **argv=0)
Parses the command line arguments and loads the configuration optionally.
Definition: OptionsIO.cpp:64
StringBijection< SUMOEmissionClass > SumoEmissionClassStrings(SumoEmissionClassStringInitializer, SVE_Solo_LKW_D_EU6_II)
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static void close()
Closes all of an applications subsystems.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
static SUMOReal computeFuel(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of consumed fuel given the vehicle type and state (in ml/s)
SUMOEmissionClass
Definition of vehicle emission classes.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
int main(int argc, char **argv)
static SUMOReal computeCO2(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted CO2 given the vehicle type and state (in mg/s)
static SUMOReal computeNOx(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted NOx given the vehicle type and state (in mg/s)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static SUMOReal computeHC(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted HC given the vehicle type and state (in mg/s)
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
#define VERSION_STRING
Definition: config.h:227
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
static SUMOReal computeCO(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted CO given the vehicle type and state (in mg/s)
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
A storage for options typed value containers)
Definition: OptionsCont.h:108
void single(const std::string &of, const std::string &className, SUMOEmissionClass c, SUMOReal vMin, SUMOReal vMax, SUMOReal vStep, SUMOReal aMin, SUMOReal aMax, SUMOReal aStep, SUMOReal sMin, SUMOReal sMax, SUMOReal sStep, bool verbose)
#define SUMOReal
Definition: config.h:215
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:197
static SUMOReal computePMx(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted PMx given the vehicle type and state (in mg/s)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.