6 #include <boost/program_options.hpp>
8 #include <stdair/stdair_basic_types.hpp>
9 #include <stdair/basic/BasLogParams.hpp>
10 #include <stdair/basic/BasDBParams.hpp>
11 #include <stdair/basic/BasFileMgr.hpp>
12 #include <stdair/bom/TravelSolutionStruct.hpp>
13 #include <stdair/bom/BookingRequestStruct.hpp>
14 #include <stdair/service/Logger.hpp>
16 #include <simfqt/SIMFQT_Types.hpp>
19 #include <simcrs/config/simcrs-paths.hpp>
80 template<
class T> std::ostream&
operator<< (std::ostream& os,
81 const std::vector<T>& v) {
82 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout,
" "));
92 stdair::Filename_T& ioScheduleInputFilename,
93 stdair::Filename_T& ioOnDInputFilename,
94 stdair::Filename_T& ioFRAT5Filename,
95 stdair::Filename_T& ioFFDisutilityFilename,
96 stdair::Filename_T& ioYieldInputFilename,
97 stdair::Filename_T& ioFareInputFilename,
98 stdair::Filename_T& ioLogFilename,
99 std::string& ioDBUser, std::string& ioDBPasswd,
100 std::string& ioDBHost, std::string& ioDBPort,
101 std::string& ioDBDBName) {
106 boost::program_options::options_description
generic (
"Generic options");
107 generic.add_options()
108 (
"prefix",
"print installation prefix")
109 (
"version,v",
"print version string")
110 (
"help,h",
"produce help message");
114 boost::program_options::options_description config (
"Configuration");
117 "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., -s/--schedule, -o/--ond, -f/--fare, -y/--yield)")
120 "(CVS) input file for the schedules")
123 "(CVS) input file for the O&D definitions")
126 "(CSV) input file for the FRAT5 Curve")
129 "(CSV) input file for the FF disutility Curve")
132 "(CVS) input file for the yields")
135 "(CVS) input file for the fares")
138 "Filepath for the logs")
141 "SQL database username")
144 "SQL database password")
147 "SQL database hostname")
158 boost::program_options::options_description hidden (
"Hidden options");
161 boost::program_options::value< std::vector<std::string> >(),
162 "Show the copyright (license)");
164 boost::program_options::options_description cmdline_options;
165 cmdline_options.add(
generic).add(config).add(hidden);
167 boost::program_options::options_description config_file_options;
168 config_file_options.add(config).add(hidden);
170 boost::program_options::options_description visible (
"Allowed options");
171 visible.add(
generic).add(config);
173 boost::program_options::positional_options_description p;
174 p.add (
"copyright", -1);
176 boost::program_options::variables_map vm;
177 boost::program_options::
178 store (boost::program_options::command_line_parser (argc, argv).
179 options (cmdline_options).positional(p).run(), vm);
181 std::ifstream ifs (
"simcrs.cfg");
182 boost::program_options::store (parse_config_file (ifs, config_file_options),
184 boost::program_options::notify (vm);
186 if (vm.count (
"help")) {
187 std::cout << visible << std::endl;
191 if (vm.count (
"version")) {
196 if (vm.count (
"prefix")) {
197 std::cout <<
"Installation prefix: " <<
PREFIXDIR << std::endl;
201 if (vm.count (
"builtin")) {
204 const std::string isBuiltinStr = (ioIsBuiltin ==
true)?
"yes":
"no";
205 std::cout <<
"The BOM should be built-in? " << isBuiltinStr << std::endl;
208 std::ostringstream oErrorMessageStr;
209 oErrorMessageStr <<
"Either the -b/--builtin option, or the combination of "
210 <<
"the -s/--schedule, -o/--ond, -f/--fare and -y/--yield "
211 <<
"options must be specified";
213 if (ioIsBuiltin ==
false) {
214 if (vm.count (
"schedule")) {
215 ioScheduleInputFilename = vm[
"schedule"].as< std::string >();
216 std::cout <<
"Schedule input filename is: " << ioScheduleInputFilename
222 std::cerr << oErrorMessageStr.str() << std::endl;
225 if (vm.count (
"ond")) {
226 ioOnDInputFilename = vm[
"ond"].as< std::string >();
227 std::cout <<
"O&D input filename is: " << ioOnDInputFilename << std::endl;
232 std::cerr << oErrorMessageStr.str() << std::endl;
235 if (vm.count (
"frat5")) {
236 ioFRAT5Filename = vm[
"frat5"].as< std::string >();
237 std::cout <<
"FRAT5 input filename is: " << ioFRAT5Filename << std::endl;
242 std::cerr << oErrorMessageStr.str() << std::endl;
245 if (vm.count (
"ff_disutility")) {
246 ioFFDisutilityFilename = vm[
"ff_disutility"].as< std::string >();
247 std::cout <<
"FF disutility input filename is: "
248 << ioFFDisutilityFilename << std::endl;
253 std::cerr << oErrorMessageStr.str() << std::endl;
256 if (vm.count (
"yield")) {
257 ioYieldInputFilename = vm[
"yield"].as< std::string >();
258 std::cout <<
"Yield input filename is: " << ioYieldInputFilename
264 std::cerr << oErrorMessageStr.str() << std::endl;
267 if (vm.count (
"fare")) {
268 ioFareInputFilename = vm[
"fare"].as< std::string >();
269 std::cout <<
"Fare input filename is: " << ioFareInputFilename
275 std::cerr << oErrorMessageStr.str() << std::endl;
279 if (vm.count (
"log")) {
280 ioLogFilename = vm[
"log"].as< std::string >();
281 std::cout <<
"Log filename is: " << ioLogFilename << std::endl;
284 if (vm.count (
"user")) {
285 ioDBUser = vm[
"user"].as< std::string >();
286 std::cout <<
"SQL database user name is: " << ioDBUser << std::endl;
289 if (vm.count (
"passwd")) {
290 ioDBPasswd = vm[
"passwd"].as< std::string >();
294 if (vm.count (
"host")) {
295 ioDBHost = vm[
"host"].as< std::string >();
296 std::cout <<
"SQL database host name is: " << ioDBHost << std::endl;
299 if (vm.count (
"port")) {
300 ioDBPort = vm[
"port"].as< std::string >();
301 std::cout <<
"SQL database port number is: " << ioDBPort << std::endl;
304 if (vm.count (
"dbname")) {
305 ioDBDBName = vm[
"dbname"].as< std::string >();
306 std::cout <<
"SQL database name is: " << ioDBDBName << std::endl;
313 int main (
int argc,
char* argv[]) {
320 stdair::Filename_T lScheduleInputFilename;
323 stdair::Filename_T lOnDInputFilename;
326 std::string lFRAT5InputFilename;
329 std::string lFFDisutilityInputFilename;
332 stdair::Filename_T lYieldInputFilename;
335 stdair::Filename_T lFareInputFilename;
338 stdair::Filename_T lLogFilename;
342 std::string lDBPasswd;
345 std::string lDBDBName;
351 const int lOptionParserStatus =
353 lScheduleInputFilename, lOnDInputFilename,
354 lFRAT5InputFilename, lFFDisutilityInputFilename,
355 lYieldInputFilename, lFareInputFilename, lLogFilename,
356 lDBUser, lDBPasswd, lDBHost, lDBPort, lDBDBName);
363 const stdair::BasDBParams lDBParams (lDBUser, lDBPasswd, lDBHost, lDBPort,
367 std::ofstream logOutputFile;
369 logOutputFile.open (lLogFilename.c_str());
370 logOutputFile.clear();
373 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
377 if (isBuiltin ==
true) {
384 stdair::ScheduleFilePath lScheduleFilePath (lScheduleInputFilename);
385 stdair::ODFilePath lODFilePath (lOnDInputFilename);
386 stdair::FRAT5FilePath lFRAT5FilePath (lFRAT5InputFilename);
387 stdair::FFDisutilityFilePath lFFDisutilityFilePath (lFFDisutilityInputFilename);
388 const SIMFQT::FareFilePath lFareFilePath (lFareInputFilename);
389 const AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
390 simcrsService.
parseAndLoad (lScheduleFilePath, lODFilePath,
391 lFRAT5FilePath, lFFDisutilityFilePath,
392 lYieldFilePath, lFareFilePath);
398 const bool isForCRS =
true;
399 const stdair::BookingRequestStruct& lBookingRequest =
403 stdair::TravelSolutionList_T lTravelSolutionList =
407 if (lTravelSolutionList.empty() ==
true) {
408 STDAIR_LOG_ERROR (
"No travel solution has been found for: "
409 << lBookingRequest.display());
414 simcrsService.
fareQuote (lBookingRequest, lTravelSolutionList);
417 stdair::TravelSolutionStruct& lChosenTravelSolution =
418 lTravelSolutionList.front();
421 const stdair::KeyList_T& lsegmentDateKeyList =
422 lChosenTravelSolution.getSegmentPath();
424 const stdair::FareOptionList_T& lFareOptionList =
425 lChosenTravelSolution.getFareOptionList();
428 if (lFareOptionList.empty() ==
true) {
429 STDAIR_LOG_ERROR (
"No fare option for the chosen travel solution: "
430 << lChosenTravelSolution.display());
435 const stdair::FareOptionStruct& lFareOption = lFareOptionList.front();
436 lChosenTravelSolution.setChosenFareOption (lFareOption);
439 const std::string& lSegmentDateKey = lsegmentDateKeyList.front();
440 STDAIR_LOG_DEBUG (
"The chosen travel solution is: " << lSegmentDateKey
441 <<
", the fare is: " << lFareOption.getFare() <<
" Euros.");
444 const stdair::PartySize_T lPartySize (3);
445 const bool isSellSuccessful =
446 simcrsService.
sell (lChosenTravelSolution, lPartySize);
449 STDAIR_LOG_DEBUG (
"Sale ('" << lBookingRequest <<
"'): "
450 <<
" successful? " << isSellSuccessful);
453 const std::string& lCSVDump = simcrsService.
csvDisplay();
454 STDAIR_LOG_DEBUG (lCSVDump);
457 logOutputFile.close();