Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Main for an emissions map writer
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #ifdef HAVE_VERSION_H
26 #include <version.h>
27 #endif
28 
30 #include <iostream>
31 #include <string>
32 #include <ctime>
34 #include <utils/options/Option.h>
40 #include <utils/common/ToString.h>
41 #include <utils/xml/XMLSubSys.h>
44 
45 
46 // ===========================================================================
47 // functions
48 // ===========================================================================
49 
50 
51 /* -------------------------------------------------------------------------
52  * main
53  * ----------------------------------------------------------------------- */
54 void single(const std::string& of, const std::string& className, SUMOEmissionClass c,
55  double vMin, double vMax, double vStep,
56  double aMin, double aMax, double aStep,
57  double sMin, double sMax, double sStep,
58  bool verbose) {
59  if (verbose) {
60  WRITE_MESSAGE("Writing map of '" + className + "' into '" + of + "'.");
61  }
62  std::ofstream o(of.c_str());
63  for (double v = vMin; v <= vMax; v += vStep) {
64  for (double a = aMin; a <= aMax; a += aStep) {
65  for (double s = sMin; s <= sMax; s += sStep) {
67  o << v << ";" << a << ";" << s << ";" << "CO" << ";" << result.CO << std::endl;
68  o << v << ";" << a << ";" << s << ";" << "CO2" << ";" << result.CO2 << std::endl;
69  o << v << ";" << a << ";" << s << ";" << "HC" << ";" << result.HC << std::endl;
70  o << v << ";" << a << ";" << s << ";" << "PMx" << ";" << result.PMx << std::endl;
71  o << v << ";" << a << ";" << s << ";" << "NOx" << ";" << result.NOx << std::endl;
72  o << v << ";" << a << ";" << s << ";" << "fuel" << ";" << result.fuel << std::endl;
73  o << v << ";" << a << ";" << s << ";" << "electricity" << ";" << result.electricity << std::endl;
74  }
75  }
76  }
77 }
78 
79 
80 
81 
82 int
83 main(int argc, char** argv) {
84  // build options
86  // give some application descriptions
87  oc.setApplicationDescription("Builds and writes an emissions map for SUMO's emission models.");
88  oc.setApplicationName("emissionsMap", "Eclipse SUMO emissionsMap Version " VERSION_STRING);
89  // add options
91  oc.addOptionSubTopic("Processing");
92  oc.doRegister("iterate", 'i', new Option_Bool(false));
93  oc.addDescription("iterate", "Processing", "If set, maps for all available emissions are written.");
94 
95  oc.doRegister("emission-class", 'e', new Option_String());
96  oc.addDescription("emission-class", "Processing", "Defines the name of the emission class to generate the map for.");
97 
98  oc.doRegister("v-min", new Option_Float(0.));
99  oc.addDescription("v-min", "Processing", "Defines the minimum velocity boundary of the map to generate (in m/s).");
100  oc.doRegister("v-max", new Option_Float(50.));
101  oc.addDescription("v-max", "Processing", "Defines the maximum velocity boundary of the map to generate (in m/s).");
102  oc.doRegister("v-step", new Option_Float(2.));
103  oc.addDescription("v-step", "Processing", "Defines the velocity step size (in m/s).");
104  oc.doRegister("a-min", new Option_Float(-4.));
105  oc.addDescription("a-min", "Processing", "Defines the minimum acceleration boundary of the map to generate (in m/s^2).");
106  oc.doRegister("a-max", new Option_Float(4.));
107  oc.addDescription("a-max", "Processing", "Defines the maximum acceleration boundary of the map to generate (in m/s^2).");
108  oc.doRegister("a-step", new Option_Float(.5));
109  oc.addDescription("a-step", "Processing", "Defines the acceleration step size (in m/s^2).");
110  oc.doRegister("s-min", new Option_Float(-10.));
111  oc.addDescription("s-min", "Processing", "Defines the minimum slope boundary of the map to generate (in deg).");
112  oc.doRegister("s-max", new Option_Float(10.));
113  oc.addDescription("s-max", "Processing", "Defines the maximum slope boundary of the map to generate (in deg).");
114  oc.doRegister("s-step", new Option_Float(1.));
115  oc.addDescription("s-step", "Processing", "Defines the slope step size (in deg).");
116 
117  oc.addOptionSubTopic("Output");
118  oc.doRegister("output-file", 'o', new Option_String());
119  oc.addSynonyme("output", "output-file");
120  oc.addDescription("output", "Output", "Defines the file (or the path if --iterate was set) to write the map(s) into.");
121 
122  oc.addOptionSubTopic("Emissions");
123  oc.doRegister("phemlight-path", new Option_FileName("./PHEMlight/"));
124  oc.addDescription("phemlight-path", "Emissions", "Determines where to load PHEMlight definitions from.");
125 
127 
128  // run
129  int ret = 0;
130  try {
131  // initialise the application system (messaging, xml, options)
132  XMLSubSys::init();
133  OptionsIO::setArgs(argc, argv);
136  if (oc.processMetaOptions(argc < 2)) {
138  return 0;
139  }
140 
141  double vMin = oc.getFloat("v-min");
142  double vMax = oc.getFloat("v-max");
143  double vStep = oc.getFloat("v-step");
144  double aMin = oc.getFloat("a-min");
145  double aMax = oc.getFloat("a-max");
146  double aStep = oc.getFloat("a-step");
147  double sMin = oc.getFloat("s-min");
148  double sMax = oc.getFloat("s-max");
149  double sStep = oc.getFloat("s-step");
150  if (!oc.getBool("iterate")) {
151  if (!oc.isSet("emission-class")) {
152  throw ProcessError("The emission class (-e) must be given.");
153  }
154  if (!oc.isSet("output-file")) {
155  throw ProcessError("The output file (-o) must be given.");
156  }
157  const SUMOEmissionClass c = PollutantsInterface::getClassByName(oc.getString("emission-class"));
158  single(oc.getString("output-file"), oc.getString("emission-class"),
159  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
160  } else {
161  if (!oc.isSet("output-file")) {
162  oc.set("output-file", "./");
163  }
164  const std::vector<SUMOEmissionClass> classes = PollutantsInterface::getAllClasses();
165  for (std::vector<SUMOEmissionClass>::const_iterator ci = classes.begin(); ci != classes.end(); ++ci) {
166  SUMOEmissionClass c = *ci;
168  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
169  }
170  }
171  } catch (InvalidArgument& e) {
173  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
174  ret = 1;
175  } catch (ProcessError& e) {
176  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
178  }
179  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
180  ret = 1;
181 #ifndef _DEBUG
182  } catch (...) {
183  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
184  ret = 1;
185 #endif
186  }
188  if (ret == 0) {
189  std::cout << "Success." << std::endl;
190  }
191  return ret;
192 }
193 
194 
195 
196 /****************************************************************************/
197 
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:136
OptionsCont::processMetaOptions
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
Definition: OptionsCont.cpp:561
ToString.h
SystemFrame::addConfigurationOptions
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:40
SystemFrame::close
static void close()
Closes all of an applications subsystems.
Definition: SystemFrame.cpp:131
PollutantsInterface::Emissions::PMx
double PMx
Definition: PollutantsInterface.h:68
Option_Bool
Definition: Option.h:540
OptionsCont.h
OptionsCont::set
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
Definition: OptionsCont.cpp:244
PollutantsInterface::Emissions::CO
double CO
Definition: PollutantsInterface.h:64
MsgHandler.h
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:202
FileHelpers.h
MsgHandler::inform
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:223
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
SUMOEmissionClass
int SUMOEmissionClass
Definition: SUMOVehicleClass.h:232
main
int main(int argc, char **argv)
Definition: emissionsMap_main.cpp:83
PollutantsInterface::getName
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:100
SystemFrame::addReportOptions
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:65
OptionsCont::addDescription
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
Definition: OptionsCont.cpp:473
OptionsCont::setApplicationName
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
Definition: OptionsCont.cpp:485
PollutantsInterface::Emissions::CO2
double CO2
Definition: PollutantsInterface.h:63
PollutantsInterface.h
SystemFrame.h
PollutantsInterface::getAllClasses
static const std::vector< SUMOEmissionClass > getAllClasses()
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:73
OptionsCont::addSynonyme
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
Definition: OptionsCont.cpp:96
OutputDevice.h
OptionsCont::doRegister
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
ProcessError
Definition: UtilExceptions.h:40
PollutantsInterface::computeAll
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...
Definition: PollutantsInterface.cpp:155
Option_String
Definition: Option.h:401
UtilExceptions.h
XMLSubSys::init
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
OptionsCont::addOptionSubTopic
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
Definition: OptionsCont.cpp:523
PollutantsInterface::Emissions::electricity
double electricity
Definition: PollutantsInterface.h:69
PollutantsInterface::getClassByName
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:54
OptionsIO::getOptions
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:76
OptionsCont::setApplicationDescription
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Definition: OptionsCont.cpp:493
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:209
StringUtils.h
PollutantsInterface::Emissions::NOx
double NOx
Definition: PollutantsInterface.h:67
Option.h
PollutantsInterface::Emissions
Storage for collected values of all emission types.
Definition: PollutantsInterface.h:62
InvalidArgument
Definition: UtilExceptions.h:57
Option_Float
Definition: Option.h:472
PollutantsInterface::Emissions::HC
double HC
Definition: PollutantsInterface.h:65
OptionsIO::setArgs
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:55
config.h
Option_FileName
Definition: Option.h:651
single
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)
Definition: emissionsMap_main.cpp:54
MsgHandler::getErrorInstance
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
PollutantsInterface::Emissions::fuel
double fuel
Definition: PollutantsInterface.h:66
VERSION_STRING
#define VERSION_STRING
Definition: config.h:207
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:240
OptionsIO.h
XMLSubSys.h