SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
emissionsMap_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Main for an emissions map writer
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2013-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifdef HAVE_VERSION_H
33 #include <version.h>
34 #endif
35 
37 #include <iostream>
38 #include <string>
39 #include <ctime>
41 #include <utils/options/Option.h>
47 #include <utils/common/ToString.h>
48 #include <utils/xml/XMLSubSys.h>
51 
52 #ifdef CHECK_MEMORY_LEAKS
53 #include <foreign/nvwa/debug_new.h>
54 #endif // CHECK_MEMORY_LEAKS
55 
56 
57 // ===========================================================================
58 // functions
59 // ===========================================================================
60 
61 
62 /* -------------------------------------------------------------------------
63  * main
64  * ----------------------------------------------------------------------- */
65 void single(const std::string& of, const std::string& className, SUMOEmissionClass c,
66  SUMOReal vMin, SUMOReal vMax, SUMOReal vStep,
67  SUMOReal aMin, SUMOReal aMax, SUMOReal aStep,
68  SUMOReal sMin, SUMOReal sMax, SUMOReal sStep,
69  bool verbose) {
70  if (verbose) {
71  WRITE_MESSAGE("Writing map of '" + className + "' into '" + of + "'.");
72  }
73  std::ofstream o(of.c_str());
74  for (SUMOReal v = vMin; v <= vMax; v += vStep) {
75  for (SUMOReal a = aMin; a <= aMax; a += aStep) {
76  for (SUMOReal s = sMin; s <= sMax; s += sStep) {
78  o << v << ";" << a << ";" << s << ";" << "CO" << ";" << result.CO << std::endl;
79  o << v << ";" << a << ";" << s << ";" << "CO2" << ";" << result.CO2 << std::endl;
80  o << v << ";" << a << ";" << s << ";" << "HC" << ";" << result.HC << std::endl;
81  o << v << ";" << a << ";" << s << ";" << "PMx" << ";" << result.PMx << std::endl;
82  o << v << ";" << a << ";" << s << ";" << "NOx" << ";" << result.NOx << std::endl;
83  o << v << ";" << a << ";" << s << ";" << "fuel" << ";" << result.fuel << std::endl;
84  o << v << ";" << a << ";" << s << ";" << "electricity" << ";" << result.electricity << std::endl;
85  }
86  }
87  }
88 }
89 
90 
91 
92 
93 int
94 main(int argc, char** argv) {
95  // build options
97  // give some application descriptions
98  oc.setApplicationDescription("Builds and writes an emissions map.");
99  oc.setApplicationName("emissionsMap", "SUMO emissionsMap Version " VERSION_STRING);
100  // add options
102  oc.addOptionSubTopic("Processing");
103  oc.doRegister("iterate", 'i', new Option_Bool(false));
104  oc.addDescription("iterate", "Processing", "If set, maps for all available emissions are written.");
105 
106  oc.doRegister("emission-class", 'e', new Option_String());
107  oc.addDescription("emission-class", "Processing", "Defines the name of the emission class to generate the map for.");
108 
109  oc.doRegister("v-min", new Option_Float(0.));
110  oc.addDescription("v-min", "Processing", "Defines the minimum velocity boundary of the map to generate (in m/s).");
111  oc.doRegister("v-max", new Option_Float(50.));
112  oc.addDescription("v-max", "Processing", "Defines the maximum velocity boundary of the map to generate (in m/s).");
113  oc.doRegister("v-step", new Option_Float(2.));
114  oc.addDescription("v-step", "Processing", "Defines the velocity step size (in m/s).");
115  oc.doRegister("a-min", new Option_Float(-4.));
116  oc.addDescription("a-min", "Processing", "Defines the minimum acceleration boundary of the map to generate (in m/s^2).");
117  oc.doRegister("a-max", new Option_Float(4.));
118  oc.addDescription("a-max", "Processing", "Defines the maximum acceleration boundary of the map to generate (in m/s^2).");
119  oc.doRegister("a-step", new Option_Float(.5));
120  oc.addDescription("a-step", "Processing", "Defines the acceleration step size (in m/s^2).");
121  oc.doRegister("s-min", new Option_Float(-10.));
122  oc.addDescription("s-min", "Processing", "Defines the minimum slope boundary of the map to generate (in deg).");
123  oc.doRegister("s-max", new Option_Float(10.));
124  oc.addDescription("s-max", "Processing", "Defines the maximum slope boundary of the map to generate (in deg).");
125  oc.doRegister("s-step", new Option_Float(1.));
126  oc.addDescription("s-step", "Processing", "Defines the slope step size (in deg).");
127 
128  oc.addOptionSubTopic("Output");
129  oc.doRegister("output-file", 'o', new Option_String());
130  oc.addSynonyme("output", "output-file");
131  oc.addDescription("output", "Output", "Defines the file (or the path if --iterate was set) to write the map(s) into.");
132 
133  oc.addOptionSubTopic("Emissions");
134  oc.doRegister("phemlight-path", new Option_FileName("./PHEMlight/"));
135  oc.addDescription("phemlight-path", "Emissions", "Determines where to load PHEMlight definitions from.");
136 
138 
139  // run
140  int ret = 0;
141  try {
142  // initialise the application system (messaging, xml, options)
143  XMLSubSys::init();
144  OptionsIO::setArgs(argc, argv);
147  if (oc.processMetaOptions(argc < 2)) {
149  return 0;
150  }
151 
152  SUMOReal vMin = oc.getFloat("v-min");
153  SUMOReal vMax = oc.getFloat("v-max");
154  SUMOReal vStep = oc.getFloat("v-step");
155  SUMOReal aMin = oc.getFloat("a-min");
156  SUMOReal aMax = oc.getFloat("a-max");
157  SUMOReal aStep = oc.getFloat("a-step");
158  SUMOReal sMin = oc.getFloat("s-min");
159  SUMOReal sMax = oc.getFloat("s-max");
160  SUMOReal sStep = oc.getFloat("s-step");
161  if (!oc.getBool("iterate")) {
162  if (!oc.isSet("emission-class")) {
163  throw ProcessError("The emission class (-e) must be given.");
164  }
165  if (!oc.isSet("output-file")) {
166  throw ProcessError("The output file (-o) must be given.");
167  }
168  const SUMOEmissionClass c = PollutantsInterface::getClassByName(oc.getString("emission-class"));
169  single(oc.getString("output-file"), oc.getString("emission-class"),
170  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
171  } else {
172  if (!oc.isSet("output-file")) {
173  oc.set("output-file", "./");
174  }
175  const std::vector<SUMOEmissionClass> classes = PollutantsInterface::getAllClasses();
176  for (std::vector<SUMOEmissionClass>::const_iterator ci = classes.begin(); ci != classes.end(); ++ci) {
177  SUMOEmissionClass c = *ci;
179  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
180  }
181  }
182  } catch (InvalidArgument& e) {
184  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
185  ret = 1;
186  } catch (ProcessError& e) {
187  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
189  }
190  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
191  ret = 1;
192 #ifndef _DEBUG
193  } catch (...) {
194  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
195  ret = 1;
196 #endif
197  }
199  if (ret == 0) {
200  std::cout << "Success." << std::endl;
201  }
202  return ret;
203 }
204 
205 
206 
207 /****************************************************************************/
208 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:86
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
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:72
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:75
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...
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)
Storage for collected values of all emission types.
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 void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:50
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:65
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
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)
int SUMOEmissionClass
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static const std::vector< SUMOEmissionClass > getAllClasses()
Checks whether the string describes a known vehicle class.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
#define VERSION_STRING
Definition: config.h:226
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
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:99
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:214
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:201
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.