SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
emissionsDrivingCycle_main.cpp
Go to the documentation of this file.
1
/****************************************************************************/
8
// Main for an emissions calculator
9
/****************************************************************************/
10
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11
// Copyright (C) 2013-2014 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
36
#include <
utils/common/TplConvert.h
>
37
#include <iostream>
38
#include <string>
39
#include <ctime>
40
#include <
utils/common/MsgHandler.h
>
41
#include <
utils/options/Option.h
>
42
#include <
utils/options/OptionsCont.h
>
43
#include <
utils/options/OptionsIO.h
>
44
#include <
utils/common/UtilExceptions.h
>
45
#include <
utils/common/SystemFrame.h
>
46
#include <
utils/common/ToString.h
>
47
#include <
utils/xml/XMLSubSys.h
>
48
#include <
utils/common/FileHelpers.h
>
49
#include <
utils/common/TplConvert.h
>
50
#include <
utils/common/StringTokenizer.h
>
51
#include <
utils/common/StringUtils.h
>
52
#include <
utils/emissions/PollutantsInterface.h
>
53
#include <
utils/iodevices/OutputDevice.h
>
54
#include <
utils/importio/LineReader.h
>
55
#include "
TrajectoriesHandler.h
"
56
57
#ifdef CHECK_MEMORY_LEAKS
58
#include <
foreign/nvwa/debug_new.h
>
59
#endif // CHECK_MEMORY_LEAKS
60
61
62
// ===========================================================================
63
// functions
64
// ===========================================================================
65
66
67
/* -------------------------------------------------------------------------
68
* main
69
* ----------------------------------------------------------------------- */
70
int
71
main
(
int
argc,
char
** argv) {
72
// build options
73
OptionsCont
& oc =
OptionsCont::getOptions
();
74
// give some application descriptions
75
oc.
setApplicationDescription
(
"Computes emissions by driving a time line."
);
76
oc.
setApplicationName
(
"emissionsDrivingCycle"
,
"SUMO emissionsDrivingCycle Version "
+ (std::string)
VERSION_STRING
);
77
// add options
78
79
SystemFrame::addConfigurationOptions
(oc);
80
oc.
addOptionSubTopic
(
"Input"
);
81
oc.
doRegister
(
"timeline-file"
,
't'
,
new
Option_FileName
());
82
oc.
addSynonyme
(
"timeline"
,
"timeline-file"
);
83
oc.
addDescription
(
"timeline-file"
,
"Input"
,
"Defines the file to read the driving cycle from."
);
84
85
oc.
doRegister
(
"netstate-file"
,
'n'
,
new
Option_FileName
());
86
oc.
addSynonyme
(
"netstate"
,
"netstate-file"
);
87
oc.
addSynonyme
(
"amitran"
,
"netstate-file"
);
88
oc.
addDescription
(
"netstate-file"
,
"Input"
,
"Defines the netstate, route and trajectory files to read the driving cycles from."
);
89
90
oc.
doRegister
(
"emission-class"
,
'e'
,
new
Option_String
(
"unknown"
));
91
oc.
addDescription
(
"emission-class"
,
"Input"
,
"Defines for which emission class the emissions shall be generated. "
);
92
93
94
oc.
addOptionSubTopic
(
"Processing"
);
95
oc.
doRegister
(
"compute-a"
,
'a'
,
new
Option_Bool
(
false
));
96
oc.
addDescription
(
"compute-a"
,
"Processing"
,
"If set, the acceleration is computed instead of being read from the file. "
);
97
98
oc.
doRegister
(
"skip-first"
,
's'
,
new
Option_Bool
(
false
));
99
oc.
addDescription
(
"skip-first"
,
"Processing"
,
"If set, the first line of the read file is skipped."
);
100
101
oc.
doRegister
(
"kmh"
,
new
Option_Bool
(
false
));
102
oc.
addDescription
(
"kmh"
,
"Processing"
,
"If set, the given speed is interpreted as being given in km/h."
);
103
104
oc.
doRegister
(
"have-slope"
,
new
Option_Bool
(
false
));
105
oc.
addDescription
(
"have-slope"
,
"Processing"
,
"If set, the fourth column is read and used as slope (in deg)."
);
106
107
oc.
doRegister
(
"slope"
,
new
Option_Float
(0));
108
oc.
addDescription
(
"slope"
,
"Processing"
,
"Sets a global slope (in deg) that is used if the file does not contain slope information."
);
109
110
oc.
addOptionSubTopic
(
"Output"
);
111
oc.
doRegister
(
"output-file"
,
'o'
,
new
Option_String
());
112
oc.
addSynonyme
(
"output"
,
"output-file"
);
113
oc.
addDescription
(
"output"
,
"Output"
,
"Defines the file to write the emission cycle results into. "
);
114
115
oc.
doRegister
(
"emission-output"
,
new
Option_FileName
());
116
oc.
addDescription
(
"emission-output"
,
"Output"
,
"Save the emission values of each vehicle in XML"
);
117
118
oc.
addOptionSubTopic
(
"Emissions"
);
119
oc.
doRegister
(
"phemlight-path"
,
new
Option_FileName
(
"./PHEMlight/"
));
120
oc.
addDescription
(
"phemlight-path"
,
"Emissions"
,
"Determines where to load PHEMlight definitions from."
);
121
122
SystemFrame::addReportOptions
(oc);
123
oc.
doRegister
(
"quiet"
,
'q'
,
new
Option_Bool
(
false
));
124
oc.
addDescription
(
"quiet"
,
"Report"
,
"Not writing anything."
);
125
126
// run
127
int
ret = 0;
128
bool
quiet =
false
;
129
try
{
130
// initialise the application system (messaging, xml, options)
131
XMLSubSys::init
();
132
OptionsIO::getOptions
(
true
, argc, argv);
133
OptionsCont
& oc =
OptionsCont::getOptions
();
134
if
(oc.
processMetaOptions
(argc < 2)) {
135
SystemFrame::close
();
136
return
0;
137
}
138
139
quiet = oc.
getBool
(
"quiet"
);
140
if
(!oc.
isSet
(
"timeline-file"
) && !oc.
isSet
(
"netstate-file"
)) {
141
throw
ProcessError
(
"Either a timeline or a netstate / amitran file must be given."
);
142
}
143
if
(!oc.
isSet
(
"output-file"
) && (oc.
isSet
(
"timeline-file"
) || !oc.
isSet
(
"emission-output"
))) {
144
throw
ProcessError
(
"The output file must be given."
);
145
}
146
std::ofstream o(oc.
getString
(
"output-file"
).c_str());
147
OutputDevice::createDeviceByOption
(
"emission-output"
,
"emission-export"
,
"emission_file.xsd"
);
148
OutputDevice
* xmlOut = 0;
149
if
(oc.
isSet
(
"emission-output"
)) {
150
xmlOut = &
OutputDevice::getDeviceByOption
(
"emission-output"
);
151
}
152
153
const
SUMOEmissionClass
defaultClass =
PollutantsInterface::getClassByName
(oc.
getString
(
"emission-class"
));
154
TrajectoriesHandler
handler(oc.
getBool
(
"compute-a"
), defaultClass, oc.
getFloat
(
"slope"
), xmlOut);
155
156
if
(oc.
isSet
(
"timeline-file"
)) {
157
bool
skipFirst = oc.
getBool
(
"skip-first"
);
158
const
bool
computeA = oc.
getBool
(
"compute-a"
);
159
const
bool
inKMH = oc.
getBool
(
"kmh"
);
160
const
bool
haveSlope = oc.
getBool
(
"have-slope"
);
161
SUMOReal
l = 0;
162
163
LineReader
lr(oc.
getString
(
"timeline-file"
));
164
while
(lr.hasMore()) {
165
std::string line = lr.
readLine
();
166
if
(skipFirst) {
167
skipFirst =
false
;
168
continue
;
169
}
170
StringTokenizer
st(
StringUtils::prune
(line),
";"
);
171
if
(st.
size
() < 2) {
172
throw
ProcessError
(
"Each line must at least include the time and the speed."
);
173
}
174
try
{
175
const
SUMOReal
t = TplConvert::_2SUMOReal<char>(st.
next
().c_str());
176
SUMOReal
v = TplConvert::_2SUMOReal<char>(st.
next
().c_str());
177
if
(inKMH) {
178
v /= 3.6;
179
}
180
l += v;
181
const
SUMOReal
a = !computeA && st.
hasNext
() ? TplConvert::_2SUMOReal<char>(st.
next
().c_str()) :
TrajectoriesHandler::INVALID_VALUE
;
182
const
SUMOReal
s = haveSlope ? TplConvert::_2SUMOReal<char>(st.
next
().c_str()) :
TrajectoriesHandler::INVALID_VALUE
;
183
handler.writeEmissions(o,
""
, defaultClass, t, v, a, s);
184
}
catch
(
EmptyData
&) {
185
throw
ProcessError
(
"Missing an entry in line '"
+ line +
"'."
);
186
}
catch
(
NumberFormatException
&) {
187
throw
ProcessError
(
"Not numeric entry in line '"
+ line +
"'."
);
188
}
189
}
190
if
(!quiet) {
191
std::cout <<
"sums"
<< std::endl
192
<<
"length:"
<< l << std::endl;
193
handler.writeSums(std::cout,
""
);
194
}
195
}
196
if
(oc.
isSet
(
"netstate-file"
)) {
197
XMLSubSys::runParser
(handler, oc.
getString
(
"netstate-file"
));
198
}
199
}
catch
(
InvalidArgument
& e) {
200
MsgHandler::getErrorInstance
()->
inform
(e.what());
201
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on error)."
,
false
);
202
ret = 1;
203
}
catch
(
ProcessError
& e) {
204
if
(std::string(e.what()) != std::string(
"Process Error"
) && std::string(e.what()) != std::string(
""
)) {
205
MsgHandler::getErrorInstance
()->
inform
(e.what());
206
}
207
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on error)."
,
false
);
208
ret = 1;
209
#ifndef _DEBUG
210
}
catch
(...) {
211
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on unknown error)."
,
false
);
212
ret = 1;
213
#endif
214
}
215
SystemFrame::close
();
216
if
(ret == 0 && !quiet) {
217
std::cout <<
"Success."
<< std::endl;
218
}
219
return
ret;
220
}
221
222
223
224
/****************************************************************************/
225
tmp
buildd
sumo-0.21.0+dfsg
src
tools
emissionsDrivingCycle_main.cpp
Generated on Thu Nov 20 2014 19:49:52 for SUMO - Simulation of Urban MObility by
1.8.1.2