SUMO - Simulation of Urban MObility
emissionsMap_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-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 /****************************************************************************/
18 // Main for an emissions map writer
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 
52 // ===========================================================================
53 // functions
54 // ===========================================================================
55 
56 
57 /* -------------------------------------------------------------------------
58  * main
59  * ----------------------------------------------------------------------- */
60 void single(const std::string& of, const std::string& className, SUMOEmissionClass c,
61  double vMin, double vMax, double vStep,
62  double aMin, double aMax, double aStep,
63  double sMin, double sMax, double sStep,
64  bool verbose) {
65  if (verbose) {
66  WRITE_MESSAGE("Writing map of '" + className + "' into '" + of + "'.");
67  }
68  std::ofstream o(of.c_str());
69  for (double v = vMin; v <= vMax; v += vStep) {
70  for (double a = aMin; a <= aMax; a += aStep) {
71  for (double s = sMin; s <= sMax; s += sStep) {
73  o << v << ";" << a << ";" << s << ";" << "CO" << ";" << result.CO << std::endl;
74  o << v << ";" << a << ";" << s << ";" << "CO2" << ";" << result.CO2 << std::endl;
75  o << v << ";" << a << ";" << s << ";" << "HC" << ";" << result.HC << std::endl;
76  o << v << ";" << a << ";" << s << ";" << "PMx" << ";" << result.PMx << std::endl;
77  o << v << ";" << a << ";" << s << ";" << "NOx" << ";" << result.NOx << std::endl;
78  o << v << ";" << a << ";" << s << ";" << "fuel" << ";" << result.fuel << std::endl;
79  o << v << ";" << a << ";" << s << ";" << "electricity" << ";" << result.electricity << std::endl;
80  }
81  }
82  }
83 }
84 
85 
86 
87 
88 int
89 main(int argc, char** argv) {
90  // build options
92  // give some application descriptions
93  oc.setApplicationDescription("Builds and writes an emissions map.");
94  oc.setApplicationName("emissionsMap", "SUMO emissionsMap Version " VERSION_STRING);
95  // add options
97  oc.addOptionSubTopic("Processing");
98  oc.doRegister("iterate", 'i', new Option_Bool(false));
99  oc.addDescription("iterate", "Processing", "If set, maps for all available emissions are written.");
100 
101  oc.doRegister("emission-class", 'e', new Option_String());
102  oc.addDescription("emission-class", "Processing", "Defines the name of the emission class to generate the map for.");
103 
104  oc.doRegister("v-min", new Option_Float(0.));
105  oc.addDescription("v-min", "Processing", "Defines the minimum velocity boundary of the map to generate (in m/s).");
106  oc.doRegister("v-max", new Option_Float(50.));
107  oc.addDescription("v-max", "Processing", "Defines the maximum velocity boundary of the map to generate (in m/s).");
108  oc.doRegister("v-step", new Option_Float(2.));
109  oc.addDescription("v-step", "Processing", "Defines the velocity step size (in m/s).");
110  oc.doRegister("a-min", new Option_Float(-4.));
111  oc.addDescription("a-min", "Processing", "Defines the minimum acceleration boundary of the map to generate (in m/s^2).");
112  oc.doRegister("a-max", new Option_Float(4.));
113  oc.addDescription("a-max", "Processing", "Defines the maximum acceleration boundary of the map to generate (in m/s^2).");
114  oc.doRegister("a-step", new Option_Float(.5));
115  oc.addDescription("a-step", "Processing", "Defines the acceleration step size (in m/s^2).");
116  oc.doRegister("s-min", new Option_Float(-10.));
117  oc.addDescription("s-min", "Processing", "Defines the minimum slope boundary of the map to generate (in deg).");
118  oc.doRegister("s-max", new Option_Float(10.));
119  oc.addDescription("s-max", "Processing", "Defines the maximum slope boundary of the map to generate (in deg).");
120  oc.doRegister("s-step", new Option_Float(1.));
121  oc.addDescription("s-step", "Processing", "Defines the slope step size (in deg).");
122 
123  oc.addOptionSubTopic("Output");
124  oc.doRegister("output-file", 'o', new Option_String());
125  oc.addSynonyme("output", "output-file");
126  oc.addDescription("output", "Output", "Defines the file (or the path if --iterate was set) to write the map(s) into.");
127 
128  oc.addOptionSubTopic("Emissions");
129  oc.doRegister("phemlight-path", new Option_FileName("./PHEMlight/"));
130  oc.addDescription("phemlight-path", "Emissions", "Determines where to load PHEMlight definitions from.");
131 
133 
134  // run
135  int ret = 0;
136  try {
137  // initialise the application system (messaging, xml, options)
138  XMLSubSys::init();
139  OptionsIO::setArgs(argc, argv);
142  if (oc.processMetaOptions(argc < 2)) {
144  return 0;
145  }
146 
147  double vMin = oc.getFloat("v-min");
148  double vMax = oc.getFloat("v-max");
149  double vStep = oc.getFloat("v-step");
150  double aMin = oc.getFloat("a-min");
151  double aMax = oc.getFloat("a-max");
152  double aStep = oc.getFloat("a-step");
153  double sMin = oc.getFloat("s-min");
154  double sMax = oc.getFloat("s-max");
155  double sStep = oc.getFloat("s-step");
156  if (!oc.getBool("iterate")) {
157  if (!oc.isSet("emission-class")) {
158  throw ProcessError("The emission class (-e) must be given.");
159  }
160  if (!oc.isSet("output-file")) {
161  throw ProcessError("The output file (-o) must be given.");
162  }
163  const SUMOEmissionClass c = PollutantsInterface::getClassByName(oc.getString("emission-class"));
164  single(oc.getString("output-file"), oc.getString("emission-class"),
165  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
166  } else {
167  if (!oc.isSet("output-file")) {
168  oc.set("output-file", "./");
169  }
170  const std::vector<SUMOEmissionClass> classes = PollutantsInterface::getAllClasses();
171  for (std::vector<SUMOEmissionClass>::const_iterator ci = classes.begin(); ci != classes.end(); ++ci) {
172  SUMOEmissionClass c = *ci;
174  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
175  }
176  }
177  } catch (InvalidArgument& e) {
179  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
180  ret = 1;
181  } catch (ProcessError& e) {
182  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
184  }
185  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
186  ret = 1;
187 #ifndef _DEBUG
188  } catch (...) {
189  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
190  ret = 1;
191 #endif
192  }
194  if (ret == 0) {
195  std::cout << "Success." << std::endl;
196  }
197  return ret;
198 }
199 
200 
201 
202 /****************************************************************************/
203 
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:81
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:53
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:75
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:71
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:46
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:61
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
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:84
A storage for options typed value containers)
Definition: OptionsCont.h:98
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:200
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.