9 #include <boost/tokenizer.hpp>
10 #include <boost/program_options.hpp>
12 #include <stdair/stdair_basic_types.hpp>
13 #include <stdair/basic/BasConst_General.hpp>
14 #include <stdair/basic/BasLogParams.hpp>
15 #include <stdair/basic/BasDBParams.hpp>
16 #include <stdair/basic/DemandGenerationMethod.hpp>
17 #include <stdair/service/Logger.hpp>
19 #include <simfqt/SIMFQT_Types.hpp>
22 #include <tvlsim/config/tvlsim-paths.hpp>
46 "/rds01/schedule.csv");
92 stdair::DEFAULT_RANDOM_SEED;
128 typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T;
131 const boost::char_separator<char> lSepatorList(
" .,;:|+-*/_=!@#$%`~^&(){}[]?'<>\"");
134 Tokeniser_T lTokens (iPhrase, lSepatorList);
135 for (Tokeniser_T::const_iterator tok_iter = lTokens.begin();
136 tok_iter != lTokens.end(); ++tok_iter) {
137 const std::string& lTerm = *tok_iter;
138 ioWordList.push_back (lTerm);
145 std::ostringstream oStr;
147 unsigned short idx = iWordList.size();
148 for (WordList_T::const_iterator itWord = iWordList.begin();
149 itWord != iWordList.end(); ++itWord, --idx) {
150 const std::string& lWord = *itWord;
163 template<
class T> std::ostream&
operator<< (std::ostream& os,
164 const std::vector<T>& v) {
165 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout,
" "));
174 bool& ioIsBuiltin, stdair::RandomSeed_T& ioRandomSeed,
175 NbOfRuns_T& ioRandomRuns, std::string& ioQueryString,
176 stdair::Filename_T& ioScheduleInputFilename,
177 stdair::Filename_T& ioOnDInputFilename,
178 stdair::Filename_T& ioFRAT5Filename,
179 stdair::Filename_T& ioFFDisutilityFilename,
180 stdair::Filename_T& ioYieldInputFilename,
181 stdair::Filename_T& ioFareInputFilename,
182 stdair::Filename_T& ioDemandInputFilename,
183 std::string& ioLogFilename,
184 stdair::DemandGenerationMethod& ioDemandGenerationMethod,
185 std::string& ioDBUser, std::string& ioDBPasswd,
186 std::string& ioDBHost, std::string& ioDBPort,
187 std::string& ioDBDBName) {
190 char lDemandGenerationMethodChar;
196 if (ioQueryString.empty() ==
true) {
205 boost::program_options::options_description
generic (
"Generic options");
206 generic.add_options()
207 (
"prefix",
"print installation prefix")
208 (
"version,v",
"print version string")
209 (
"help,h",
"produce help message");
213 boost::program_options::options_description config (
"Configuration");
216 "The sample BOM tree can be either built-in or parsed from input files. In that latter case, the input files must be specified as well (e.g., -d/--demand, -s/--schedule, -o/--ond, -f/--fare, -y/--yield)")
219 "Seed for the random generation")
222 "Number of simulation runs")
225 "(CSV) input file for the schedules")
228 "(CSV) input file for the O&D definitions")
231 "(CSV) input file for the FRAT5 Curve")
234 "(CSV) input file for the FF disutility Curve")
237 "(CSV) input file for the yields")
240 "(CSV) input file for the fares")
243 "(CSV) input file for the demand distributions")
246 "Filepath for the logs")
247 (
"demandgeneration,G",
249 "Method used to generate the demand (i.e., booking requests): Poisson Process (e.g., P) or Statistics Order (e.g., S)")
252 "SQL database hostname (e.g., tvlsim)")
255 "SQL database hostname (e.g., tvlsim)")
258 "SQL database hostname (e.g., localhost)")
261 "SQL database port (e.g., 3306)")
264 "SQL database name (e.g., tvlsim)")
266 boost::program_options::value< WordList_T >(&lWordList)->multitoken(),
272 boost::program_options::options_description hidden (
"Hidden options");
275 boost::program_options::value< std::vector<std::string> >(),
276 "Show the copyright (license)");
278 boost::program_options::options_description cmdline_options;
279 cmdline_options.add(
generic).add(config).add(hidden);
281 boost::program_options::options_description config_file_options;
282 config_file_options.add(config).add(hidden);
284 boost::program_options::options_description visible (
"Allowed options");
285 visible.add(
generic).add(config);
287 boost::program_options::positional_options_description p;
288 p.add (
"copyright", -1);
290 boost::program_options::variables_map vm;
291 boost::program_options::
292 store (boost::program_options::command_line_parser (argc, argv).
293 options (cmdline_options).positional(p).run(), vm);
295 std::ifstream ifs (
"simulate.cfg");
296 boost::program_options::store (parse_config_file (ifs, config_file_options),
298 boost::program_options::notify (vm);
300 if (vm.count (
"help")) {
301 std::cout << visible << std::endl;
305 if (vm.count (
"version")) {
310 if (vm.count (
"prefix")) {
311 std::cout <<
"Installation prefix: " <<
PREFIXDIR << std::endl;
315 if (vm.count (
"builtin")) {
318 const std::string isBuiltinStr = (ioIsBuiltin ==
true)?
"yes":
"no";
319 std::cout <<
"The BOM should be built-in? " << isBuiltinStr << std::endl;
322 std::ostringstream oErrorMessageStr;
323 oErrorMessageStr <<
"Either the -b/--builtin option, or the combination of "
324 <<
"the -d/--demand, -s/--schedule, -o/--ond, -f/--fare "
325 <<
"and -y/--yield options must be specified";
327 if (ioIsBuiltin ==
false) {
328 if (vm.count (
"schedule")) {
329 ioScheduleInputFilename = vm[
"schedule"].as< std::string >();
330 std::cout <<
"Schedule input filename is: " << ioScheduleInputFilename
336 std::cerr << oErrorMessageStr.str() << std::endl;
339 if (vm.count (
"ond")) {
340 ioOnDInputFilename = vm[
"ond"].as< std::string >();
341 std::cout <<
"O&D input filename is: " << ioOnDInputFilename << std::endl;
346 std::cerr << oErrorMessageStr.str() << std::endl;
349 if (vm.count (
"frat5")) {
350 ioFRAT5Filename = vm[
"frat5"].as< std::string >();
351 std::cout <<
"FRAT5 input filename is: " << ioFRAT5Filename << std::endl;
356 std::cerr << oErrorMessageStr.str() << std::endl;
359 if (vm.count (
"ff_disutility")) {
360 ioFFDisutilityFilename = vm[
"ff_disutility"].as< std::string >();
361 std::cout <<
"FF disutility input filename is: "
362 << ioFFDisutilityFilename << std::endl;
367 std::cerr << oErrorMessageStr.str() << std::endl;
370 if (vm.count (
"yield")) {
371 ioYieldInputFilename = vm[
"yield"].as< std::string >();
372 std::cout <<
"Yield input filename is: " << ioYieldInputFilename << std::endl;
377 std::cerr << oErrorMessageStr.str() << std::endl;
380 if (vm.count (
"fare")) {
381 ioFareInputFilename = vm[
"fare"].as< std::string >();
382 std::cout <<
"Fare input filename is: " << ioFareInputFilename << std::endl;
387 std::cerr << oErrorMessageStr.str() << std::endl;
390 if (vm.count (
"demand")) {
391 ioDemandInputFilename = vm[
"demand"].as< std::string >();
392 std::cout <<
"Demand input filename is: " << ioDemandInputFilename
397 std::cerr << oErrorMessageStr.str() << std::endl;
401 if (vm.count (
"log")) {
402 ioLogFilename = vm[
"log"].as< std::string >();
403 std::cout <<
"Log filename is: " << ioLogFilename << std::endl;
407 if (vm.count (
"demandgeneration")) {
408 ioDemandGenerationMethod =
409 stdair::DemandGenerationMethod (lDemandGenerationMethodChar);
410 std::cout <<
"Demand generation method is: "
411 << ioDemandGenerationMethod.describe() << std::endl;
415 std::cout <<
"The random generation seed is: " << ioRandomSeed << std::endl;
418 std::cout <<
"The number of simulation runs is: " << ioRandomRuns
422 if (vm.count (
"user")) {
423 ioDBUser = vm[
"user"].as< std::string >();
424 std::cout <<
"SQL database user name is: " << ioDBUser << std::endl;
427 if (vm.count (
"passwd")) {
428 ioDBPasswd = vm[
"passwd"].as< std::string >();
432 if (vm.count (
"host")) {
433 ioDBHost = vm[
"host"].as< std::string >();
434 std::cout <<
"SQL database host name is: " << ioDBHost << std::endl;
437 if (vm.count (
"port")) {
438 ioDBPort = vm[
"port"].as< std::string >();
439 std::cout <<
"SQL database port number is: " << ioDBPort << std::endl;
442 if (vm.count (
"dbname")) {
443 ioDBDBName = vm[
"dbname"].as< std::string >();
444 std::cout <<
"SQL database name is: " << ioDBDBName << std::endl;
449 std::cout <<
"The query string is: " << ioQueryString << std::endl;
455 int main (
int argc,
char* argv[]) {
462 stdair::RandomSeed_T lRandomSeed;
471 stdair::Date_T lStartDate (2009, boost::gregorian::Feb, 01);
474 stdair::Date_T lEndDate (2012, boost::gregorian::Mar, 02);
477 stdair::Filename_T lScheduleInputFilename;
480 std::string lOnDInputFilename;
483 std::string lFRAT5InputFilename;
486 std::string lFFDisutilityInputFilename;
489 std::string lYieldInputFilename;
492 std::string lFareInputFilename;
495 stdair::Filename_T lDemandInputFilename;
498 std::string lLogFilename;
501 stdair::DemandGenerationMethod
506 std::string lDBPasswd;
509 std::string lDBDBName;
512 const int lOptionParserStatus =
514 lScheduleInputFilename, lOnDInputFilename,
515 lFRAT5InputFilename, lFFDisutilityInputFilename,
516 lYieldInputFilename, lFareInputFilename,
517 lDemandInputFilename, lLogFilename,
518 lDemandGenerationMethod,
519 lDBUser, lDBPasswd, lDBHost, lDBPort, lDBDBName);
526 stdair::BasDBParams lDBParams (lDBUser, lDBPasswd, lDBHost, lDBPort,
530 std::ofstream logOutputFile;
532 logOutputFile.open (lLogFilename.c_str());
533 logOutputFile.clear();
536 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
538 lRandomSeed, lDemandGenerationMethod,
542 if (isBuiltin ==
true) {
548 stdair::ScheduleFilePath lScheduleFilePath (lScheduleInputFilename);
549 stdair::ODFilePath lODFilePath (lOnDInputFilename);
550 stdair::FRAT5FilePath lFRAT5FilePath (lFRAT5InputFilename);
551 stdair::FFDisutilityFilePath lFFDisutilityFilePath (lFFDisutilityInputFilename);
552 const SIMFQT::FareFilePath lFareFilePath (lFareInputFilename);
553 const AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
554 const TRADEMGEN::DemandFilePath lDemandFilePath (lDemandInputFilename);
556 lFRAT5FilePath, lFFDisutilityFilePath,
557 lYieldFilePath, lFareFilePath,