SUMO - Simulation of Urban MObility
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 
53 // ===========================================================================
54 // functions
55 // ===========================================================================
56 
57 
58 /* -------------------------------------------------------------------------
59  * main
60  * ----------------------------------------------------------------------- */
61 void single(const std::string& of, const std::string& className, SUMOEmissionClass c,
62  double vMin, double vMax, double vStep,
63  double aMin, double aMax, double aStep,
64  double sMin, double sMax, double sStep,
65  bool verbose) {
66  if (verbose) {
67  WRITE_MESSAGE("Writing map of '" + className + "' into '" + of + "'.");
68  }
69  std::ofstream o(of.c_str());
70  for (double v = vMin; v <= vMax; v += vStep) {
71  for (double a = aMin; a <= aMax; a += aStep) {
72  for (double s = sMin; s <= sMax; s += sStep) {
74  o << v << ";" << a << ";" << s << ";" << "CO" << ";" << result.CO << std::endl;
75  o << v << ";" << a << ";" << s << ";" << "CO2" << ";" << result.CO2 << std::endl;
76  o << v << ";" << a << ";" << s << ";" << "HC" << ";" << result.HC << std::endl;
77  o << v << ";" << a << ";" << s << ";" << "PMx" << ";" << result.PMx << std::endl;
78  o << v << ";" << a << ";" << s << ";" << "NOx" << ";" << result.NOx << std::endl;
79  o << v << ";" << a << ";" << s << ";" << "fuel" << ";" << result.fuel << std::endl;
80  o << v << ";" << a << ";" << s << ";" << "electricity" << ";" << result.electricity << std::endl;
81  }
82  }
83  }
84 }
85 
86 
87 
88 
89 int
90 main(int argc, char** argv) {
91  // build options
93  // give some application descriptions
94  oc.setApplicationDescription("Builds and writes an emissions map.");
95  oc.setApplicationName("emissionsMap", "SUMO emissionsMap Version " VERSION_STRING);
96  // 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 deg).");
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 deg).");
121  oc.doRegister("s-step", new Option_Float(1.));
122  oc.addDescription("s-step", "Processing", "Defines the slope step size (in deg).");
123 
124  oc.addOptionSubTopic("Output");
125  oc.doRegister("output-file", 'o', new Option_String());
126  oc.addSynonyme("output", "output-file");
127  oc.addDescription("output", "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", new Option_FileName("./PHEMlight/"));
131  oc.addDescription("phemlight-path", "Emissions", "Determines where to load PHEMlight definitions from.");
132 
134 
135  // run
136  int ret = 0;
137  try {
138  // initialise the application system (messaging, xml, options)
139  XMLSubSys::init();
140  OptionsIO::setArgs(argc, argv);
143  if (oc.processMetaOptions(argc < 2)) {
145  return 0;
146  }
147 
148  double vMin = oc.getFloat("v-min");
149  double vMax = oc.getFloat("v-max");
150  double vStep = oc.getFloat("v-step");
151  double aMin = oc.getFloat("a-min");
152  double aMax = oc.getFloat("a-max");
153  double aStep = oc.getFloat("a-step");
154  double sMin = oc.getFloat("s-min");
155  double sMax = oc.getFloat("s-max");
156  double sStep = oc.getFloat("s-step");
157  if (!oc.getBool("iterate")) {
158  if (!oc.isSet("emission-class")) {
159  throw ProcessError("The emission class (-e) must be given.");
160  }
161  if (!oc.isSet("output-file")) {
162  throw ProcessError("The output file (-o) must be given.");
163  }
164  const SUMOEmissionClass c = PollutantsInterface::getClassByName(oc.getString("emission-class"));
165  single(oc.getString("output-file"), oc.getString("emission-class"),
166  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
167  } else {
168  if (!oc.isSet("output-file")) {
169  oc.set("output-file", "./");
170  }
171  const std::vector<SUMOEmissionClass> classes = PollutantsInterface::getAllClasses();
172  for (std::vector<SUMOEmissionClass>::const_iterator ci = classes.begin(); ci != classes.end(); ++ci) {
173  SUMOEmissionClass c = *ci;
175  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
176  }
177  }
178  } catch (InvalidArgument& e) {
180  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
181  ret = 1;
182  } catch (ProcessError& e) {
183  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
185  }
186  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
187  ret = 1;
188 #ifndef _DEBUG
189  } catch (...) {
190  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
191  ret = 1;
192 #endif
193  }
195  if (ret == 0) {
196  std::cout << "Success." << std::endl;
197  }
198  return ret;
199 }
200 
201 
202 
203 /****************************************************************************/
204 
void single(const std::string &of, const std::string &className, SUMOEmissionClass c, double vMin, double vMax, double vStep, double aMin, double aMax, double aStep, double sMin, double sMax, double sStep, bool verbose)
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:82
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...
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:54
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:82
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:72
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Storage for collected values of all emission types.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void close()
Closes all of an applications subsystems.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:47
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:62
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
int main(int argc, char **argv)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
int SUMOEmissionClass
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
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.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
#define VERSION_STRING
Definition: config.h:210
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:85
A storage for options typed value containers)
Definition: OptionsCont.h:99
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
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.