31#if __cplusplus >= 201703L
32#if __has_include(<filesystem>)
34namespace fs = std::filesystem;
35#elif __has_include(<experimental/filesystem>)
36#include <experimental/filesystem>
37namespace fs = std::experimental::filesystem;
60 double vMin,
double vMax,
double vStep,
61 double aMin,
double aMax,
double aStep,
62 double sMin,
double sMax,
double sStep,
67 std::ofstream o(of.c_str());
72 std::unique_ptr<EnergyParams> energyParams;
73 std::map<std::string, SUMOVTypeParameter*> vTypes;
74 if (oc.
isSet(
"vtype") || oc.
isSet(
"additional-files")) {
75 if (!oc.
isSet(
"additional-files")) {
76 throw ProcessError(
TL(
"Option --vtype requires option --additional-files for loading vehicle types"));
81 for (
const std::string& file : oc.
getStringVector(
"additional-files")) {
87 if (!oc.
isSet(
"vtype") && vTypes.size() != 1) {
90 const auto vTypeIt = oc.
isSet(
"vtype") ? vTypes.find(oc.
getString(
"vtype")) : vTypes.begin();
91 if (vTypeIt == vTypes.end()) {
95 c = vTypeIt->second->emissionClass;
97 energyParams = std::unique_ptr<EnergyParams>(
new EnergyParams(vTypeIt->second));
99 energyParams = std::unique_ptr<EnergyParams>(
new EnergyParams());
101 for (
double v = vMin; v <= vMax; v += vStep) {
102 for (
double a = aMin; a <= aMax; a += aStep) {
103 for (
double s = sMin; s <= sMax; s += sStep) {
105 o << v <<
";" << a <<
";" << s <<
";" <<
"CO" <<
";" << result.
CO << std::endl;
106 o << v <<
";" << a <<
";" << s <<
";" <<
"CO2" <<
";" << result.
CO2 << std::endl;
107 o << v <<
";" << a <<
";" << s <<
";" <<
"HC" <<
";" << result.
HC << std::endl;
108 o << v <<
";" << a <<
";" << s <<
";" <<
"PMx" <<
";" << result.
PMx << std::endl;
109 o << v <<
";" << a <<
";" << s <<
";" <<
"NOx" <<
";" << result.
NOx << std::endl;
110 o << v <<
";" << a <<
";" << s <<
";" <<
"fuel" <<
";" << result.
fuel << std::endl;
111 o << v <<
";" << a <<
";" << s <<
";" <<
"electricity" <<
";" << result.
electricity << std::endl;
130 oc.
addDescription(
"iterate",
"Processing",
TL(
"If set, maps for all available emissions are written."));
133 oc.
addDescription(
"emission-class",
"Processing",
TL(
"Defines the name of the emission class to generate the map for."));
136 oc.
addDescription(
"additional-files",
"Input",
TL(
"Load emission parameters (vTypes) from FILE(s)"));
139 oc.
addDescription(
"vtype",
"Input",
TL(
"Defines the vehicle type to use for emission parameters."));
142 oc.
addDescription(
"v-min",
"Processing",
TL(
"Defines the minimum velocity boundary of the map to generate (in m/s)."));
144 oc.
addDescription(
"v-max",
"Processing",
TL(
"Defines the maximum velocity boundary of the map to generate (in m/s)."));
146 oc.
addDescription(
"v-step",
"Processing",
TL(
"Defines the velocity step size (in m/s)."));
148 oc.
addDescription(
"a-min",
"Processing",
TL(
"Defines the minimum acceleration boundary of the map to generate (in m/s^2)."));
150 oc.
addDescription(
"a-max",
"Processing",
TL(
"Defines the maximum acceleration boundary of the map to generate (in m/s^2)."));
152 oc.
addDescription(
"a-step",
"Processing",
TL(
"Defines the acceleration step size (in m/s^2)."));
154 oc.
addDescription(
"s-min",
"Processing",
TL(
"Defines the minimum slope boundary of the map to generate (in deg)."));
156 oc.
addDescription(
"s-max",
"Processing",
TL(
"Defines the maximum slope boundary of the map to generate (in deg)."));
158 oc.
addDescription(
"s-step",
"Processing",
TL(
"Defines the slope step size (in deg)."));
163 oc.
addDescription(
"output",
"Output",
TL(
"Defines the file (or the path if --iterate was set) to write the map(s) into."));
167 oc.
addDescription(
"emissions.volumetric-fuel",
"Emissions",
TL(
"Return fuel consumption values in (legacy) unit l instead of mg"));
170 oc.
addDescription(
"phemlight-path",
"Emissions",
TL(
"Determines where to load PHEMlight definitions from"));
173 oc.
addDescription(
"phemlight-year",
"Emissions",
TL(
"Enable fleet age modelling with the given reference year in PHEMlight5"));
176 oc.
addDescription(
"phemlight-temperature",
"Emissions",
TL(
"Set ambient temperature to correct NOx emissions in PHEMlight5"));
194 double vStep = oc.
getFloat(
"v-step");
197 double aStep = oc.
getFloat(
"a-step");
200 double sStep = oc.
getFloat(
"s-step");
202 if (!oc.
isSet(
"emission-class")) {
205 if (!oc.
isSet(
"output-file")) {
210 c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.
getBool(
"verbose"));
212 if (!oc.
isSet(
"output-file")) {
213 oc.
set(
"output-file",
"./");
215#if __cplusplus >= 201703L
216 std::vector<std::string> phemPath;
218 if (getenv(
"PHEMLIGHT_PATH") !=
nullptr) {
219 phemPath.push_back(std::string(getenv(
"PHEMLIGHT_PATH")) +
"/");
221 if (getenv(
"SUMO_HOME") !=
nullptr) {
222 phemPath.push_back(std::string(getenv(
"SUMO_HOME")) +
"/data/emissions/PHEMlight/");
223 phemPath.push_back(std::string(getenv(
"SUMO_HOME")) +
"/data/emissions/PHEMlight5/");
225 for (
const std::string& p : phemPath) {
227 for (
const auto& entry : fs::directory_iterator(p, ec)) {
228 if (entry.path().extension() ==
".veh") {
229 if (entry.path().parent_path().filename().string().back() ==
'5') {
239 for (std::vector<SUMOEmissionClass>::const_iterator ci = classes.begin(); ci != classes.end(); ++ci) {
243 c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.
getBool(
"verbose"));
251 if (std::string(e.what()) != std::string(
"Process Error") && std::string(e.what()) != std::string(
"")) {
264 std::cout <<
"Success." << std::endl;
#define WRITE_MESSAGEF(...)
std::vector< std::string > StringVector
Definition of a vector of strings.
const double INVALID_DOUBLE
invalid double
An upper class for objects with additional parameters.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
A storage for options typed value containers)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
bool set(const std::string &name, const std::string &value, const bool append=false)
Sets the given value for the named option.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file)
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
static const std::vector< SUMOEmissionClass > getAllClasses()
Checks whether the string describes a known vehicle class.
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams *param)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
static void close()
Closes all of an applications subsystems.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
An XML-Handler for amitran and netstate trajectories.
static void init()
Initialises the xml-subsystem.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.
int main(int argc, char **argv)
void single(const OptionsCont &oc, 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)
Storage for collected values of all emission types.