TraDemGen Logo  1.00.10
C++ Simulated Travel Demand Generation Library
Loading...
Searching...
No Matches
trademgen.cpp
Go to the documentation of this file.
1
5// STL
6#include <cassert>
7#include <iostream>
8#include <sstream>
9#include <fstream>
10#include <string>
11// Boost (Extended STL)
12#include <boost/program_options.hpp>
13#include <boost/tokenizer.hpp>
14#include <boost/regex.hpp>
15#include <boost/swap.hpp>
16#include <boost/algorithm/string/case_conv.hpp>
17// GNU Readline Wrapper
18#include <stdair/ui/cmdline/SReadline.hpp>
19// StdAir
20#include <stdair/stdair_basic_types.hpp>
21#include <stdair/stdair_json.hpp>
22#include <stdair/basic/BasConst_General.hpp>
23#include <stdair/basic/ProgressStatusSet.hpp>
24#include <stdair/basic/DemandGenerationMethod.hpp>
25#include <stdair/bom/EventStruct.hpp>
26#include <stdair/bom/BookingRequestStruct.hpp>
27#include <stdair/bom/BomDisplay.hpp>
28#include <stdair/service/Logger.hpp>
29// TraDemGen
31#include <trademgen/config/trademgen-paths.hpp>
32
33
34// //////// Type definitions ///////
38typedef std::vector<std::string> WordList_T;
39
40// //////// Specific type definitions ///////
41typedef unsigned int NbOfRuns_T;
42
43// //////// Constants //////
47const stdair::Filename_T K_TRADEMGEN_DEFAULT_LOG_FILENAME ("trademgen.log");
48
52const stdair::Filename_T K_TRADEMGEN_DEFAULT_INPUT_FILENAME (STDAIR_SAMPLE_DIR
53 "/rds01/demand05.csv");
54
58const stdair::DemandGenerationMethod
60 stdair::DemandGenerationMethod::POI_PRO;
61
67
71const stdair::RandomSeed_T K_TRADEMGEN_DEFAULT_RANDOM_SEED =
72 stdair::DEFAULT_RANDOM_SEED;
73
78const bool K_TRADEMGEN_DEFAULT_BUILT_IN_INPUT = false;
79
84
85// //////////////////////////////////////////////////////////////////////
90typedef std::vector<std::string> TokenList_T;
91
95struct Command_T {
96 typedef enum {
97 NOP = 0,
98 QUIT,
99 HELP,
100 LIST_EVENT,
101 LIST_DEMAND_STREAM,
102 RESET,
103 NEXT,
104 GENERATE_NEXT_BR,
105 GENERATE_FIRST_BR,
106 GENERATE_ALL_BR,
107 JSON_LIST,
108 LAST_VALUE
109 } Type_T;
110};
111
112// //////////////////////////////////////////////////////////////////////
113void tokeniseStringIntoWordList (const std::string& iPhrase,
114 WordList_T& ioWordList) {
115 // Empty the word list
116 ioWordList.clear();
117
118 // Boost Tokeniser
119 typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T;
120
121 // Define the separators
122 const boost::char_separator<char> lSepatorList(" .,;:|+-*/_=!@#$%`~^&(){}[]?'<>\"");
123
124 // Initialise the phrase to be tokenised
125 Tokeniser_T lTokens (iPhrase, lSepatorList);
126 for (Tokeniser_T::const_iterator tok_iter = lTokens.begin();
127 tok_iter != lTokens.end(); ++tok_iter) {
128 const std::string& lTerm = *tok_iter;
129 ioWordList.push_back (lTerm);
130 }
131
132}// //////////////////////////////////////////////////////////////////////
133std::string createStringFromWordList (const WordList_T& iWordList) {
134 std::ostringstream oStr;
135
136 unsigned short idx = iWordList.size();
137 for (WordList_T::const_iterator itWord = iWordList.begin();
138 itWord != iWordList.end(); ++itWord, --idx) {
139 const std::string& lWord = *itWord;
140 oStr << lWord;
141 if (idx > 1) {
142 oStr << " ";
143 }
144 }
145
146 return oStr.str();
147}
148
149
150// ///////// Parsing of Options & Configuration /////////
151// A helper function to simplify the main part.
152template<class T> std::ostream& operator<< (std::ostream& os,
153 const std::vector<T>& v) {
154 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, " "));
155 return os;
156}
160int readConfiguration (int argc, char* argv[], bool& ioIsBuiltin,
161 stdair::RandomSeed_T& ioRandomSeed,
162 stdair::Filename_T& ioInputFilename,
163 stdair::Filename_T& ioOutputFilename,
164 stdair::Filename_T& ioLogFilename,
165 stdair::DemandGenerationMethod& ioDemandGenerationMethod) {
166
167 // Demand generation method as a single char (e.g., 'P' or 'S').
168 char lDemandGenerationMethodChar;
169
170 // Default for the built-in input
172
173 // Declare a group of options that will be allowed only on command line
174 boost::program_options::options_description generic ("Generic options");
175 generic.add_options()
176 ("prefix", "print installation prefix")
177 ("version,v", "print version string")
178 ("help,h", "produce help message");
179
180 // Declare a group of options that will be allowed both on command
181 // line and in config file
182 boost::program_options::options_description config ("Configuration");
183 config.add_options()
184 ("builtin,b",
185 "The sample BOM tree can be either built-in or parsed from an input file. That latter must then be given with the -i/--input option")
186 ("seed,s",
187 boost::program_options::value<stdair::RandomSeed_T>(&ioRandomSeed)->default_value(K_TRADEMGEN_DEFAULT_RANDOM_SEED),
188 "Seed for the random generation")
189 ("demandgeneration,G",
190 boost::program_options::value< char >(&lDemandGenerationMethodChar)->default_value(K_TRADEMGEN_DEFAULT_DEMAND_GENERATION_METHOD_CHAR),
191 "Method used to generate the demand (i.e., the booking requests): Poisson Process (P) or Order Statistics (S)")
192 ("input,i",
193 boost::program_options::value< std::string >(&ioInputFilename)->default_value(K_TRADEMGEN_DEFAULT_INPUT_FILENAME),
194 "(CSV) input file for the demand distributions")
195 ("log,l",
196 boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_TRADEMGEN_DEFAULT_LOG_FILENAME),
197 "Filepath for the logs")
198 ;
199
200 // Hidden options, will be allowed both on command line and
201 // in config file, but will not be shown to the user.
202 boost::program_options::options_description hidden ("Hidden options");
203 hidden.add_options()
204 ("copyright",
205 boost::program_options::value< std::vector<std::string> >(),
206 "Show the copyright (license)");
207
208 boost::program_options::options_description cmdline_options;
209 cmdline_options.add(generic).add(config).add(hidden);
210
211 boost::program_options::options_description config_file_options;
212 config_file_options.add(config).add(hidden);
213
214 boost::program_options::options_description visible ("Allowed options");
215 visible.add(generic).add(config);
216
217 boost::program_options::positional_options_description p;
218 p.add ("copyright", -1);
219
220 boost::program_options::variables_map vm;
221 boost::program_options::
222 store (boost::program_options::command_line_parser (argc, argv).
223 options (cmdline_options).positional(p).run(), vm);
224
225 std::ifstream ifs ("trademgen.cfg");
226 boost::program_options::store (parse_config_file (ifs, config_file_options),
227 vm);
228 boost::program_options::notify (vm);
229
230 if (vm.count ("help")) {
231 std::cout << visible << std::endl;
233 }
234
235 if (vm.count ("version")) {
236 std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl;
238 }
239
240 if (vm.count ("prefix")) {
241 std::cout << "Installation prefix: " << PREFIXDIR << std::endl;
243 }
244
245 if (vm.count ("builtin")) {
246 ioIsBuiltin = true;
247 }
248 const std::string isBuiltinStr = (ioIsBuiltin == true)?"yes":"no";
249 std::cout << "The BOM should be built-in? " << isBuiltinStr << std::endl;
250
251 if (ioIsBuiltin == false) {
252
253 // The BOM tree should be built from parsing a demand input file
254 if (vm.count ("input")) {
255 ioInputFilename = vm["input"].as< std::string >();
256 std::cout << "Input filename is: " << ioInputFilename << std::endl;
257
258 } else {
259 // The built-in option is not selected. However, no demand input file
260 // is specified
261 std::cerr << "Either one among the -b/--builtin and -i/--input "
262 << "options must be specified" << std::endl;
263 }
264 }
265
266 if (vm.count ("output")) {
267 ioOutputFilename = vm["output"].as< std::string >();
268 std::cout << "Output filename is: " << ioOutputFilename << std::endl;
269 }
270
271 if (vm.count ("log")) {
272 ioLogFilename = vm["log"].as< std::string >();
273 std::cout << "Log filename is: " << ioLogFilename << std::endl;
274 }
275
276 if (vm.count ("demandgeneration")) {
277 ioDemandGenerationMethod =
278 stdair::DemandGenerationMethod (lDemandGenerationMethodChar);
279 std::cout << "Date-time request generation method is: "
280 << ioDemandGenerationMethod.describe() << std::endl;
281 }
282
283 //
284 std::cout << "The random generation seed is: " << ioRandomSeed << std::endl;
285
286 return 0;
287}
288
289// //////////////////////////////////////////////////////////////////
290void initReadline (swift::SReadline& ioInputReader) {
291
292 // Prepare the list of my own completers
293 std::vector<std::string> Completers;
294
295 // The following is supported:
296 // - "identifiers"
297 // - special identifier %file - means to perform a file name completion
298 Completers.push_back ("help");
299 Completers.push_back ("list_event");
300 Completers.push_back ("list_demand_stream");
301 Completers.push_back ("reset");
302 Completers.push_back ("generate_next_br");
303 Completers.push_back ("generate_first_br");
304 Completers.push_back ("generate_all_br");
305 Completers.push_back ("next");
306 Completers.push_back ("json_list");
307 Completers.push_back ("quit");
308
309 // Now register the completers.
310 // Actually it is possible to re-register another set at any time
311 ioInputReader.RegisterCompletions (Completers);
312}
313
314// //////////////////////////////////////////////////////////////////
315Command_T::Type_T extractCommand (TokenList_T& ioTokenList) {
316 Command_T::Type_T oCommandType = Command_T::LAST_VALUE;
317
318 // Interpret the user input
319 if (ioTokenList.empty() == false) {
320 TokenList_T::iterator itTok = ioTokenList.begin();
321 std::string lCommand (*itTok);
322 boost::algorithm::to_lower (lCommand);
323
324 if (lCommand == "help") {
325 oCommandType = Command_T::HELP;
326
327 } else if (lCommand == "list_event") {
328 oCommandType = Command_T::LIST_EVENT;
329
330 } else if (lCommand == "list_demand_stream") {
331 oCommandType = Command_T::LIST_DEMAND_STREAM;
332
333 } else if (lCommand == "reset") {
334 oCommandType = Command_T::RESET;
335
336 } else if (lCommand == "delete_first") {
337 oCommandType = Command_T::NEXT;
338
339 } else if (lCommand == "generate_first_br") {
340 oCommandType = Command_T::GENERATE_FIRST_BR;
341
342 } else if (lCommand == "generate_next_br") {
343 oCommandType = Command_T::GENERATE_NEXT_BR;
344
345 } else if (lCommand == "generate_all_br") {
346 oCommandType = Command_T::GENERATE_ALL_BR;
347
348 } else if (lCommand == "json_list") {
349 oCommandType = Command_T::JSON_LIST;
350
351 } else if (lCommand == "quit") {
352 oCommandType = Command_T::QUIT;
353 }
354
355 // Remove the first token (the command), as the corresponding information
356 // has been extracted in the form of the returned command type enumeration
357 ioTokenList.erase (itTok);
358
359 } else {
360 oCommandType = Command_T::NOP;
361 }
362
363 return oCommandType;
364}
365
366// /////////////////////////////////////////////////////////
367std::string toString (const TokenList_T& iTokenList) {
368 std::ostringstream oStr;
369
370 // Re-create the string with all the tokens, trimmed by read-line
371 unsigned short idx = 0;
372 for (TokenList_T::const_iterator itTok = iTokenList.begin();
373 itTok != iTokenList.end(); ++itTok, ++idx) {
374 if (idx != 0) {
375 oStr << " ";
376 }
377 oStr << *itTok;
378 }
379
380 return oStr.str();
381}
382
383// ///////// M A I N ////////////
384int main (int argc, char* argv[]) {
385
386 // Readline history
387 const unsigned int lHistorySize (100);
388 const std::string lHistoryFilename ("trademgen.hist");
389 const std::string lHistoryBackupFilename ("trademgen.hist.bak");
390
391 // Default parameters for the interactive session
392 stdair::EventStruct lCurrentInteractiveEventStruct;
393 //stdair::DateTime_T lCurrentInteractiveDateTime;
394 std::string lDefaultDemandStreamKey;
395
396 // State whether the BOM tree should be built-in or parsed from an input file
397 bool isBuiltin;
398
399 // Random generation seed
400 stdair::RandomSeed_T lRandomSeed;
401
402 // Input file name
403 stdair::Filename_T lInputFilename;
404
405 // Output file name
406 stdair::Filename_T lOutputFilename;
407
408 // Output log File
409 stdair::Filename_T lLogFilename;
410
411 // Demand generation method.
412 stdair::DemandGenerationMethod
413 lDemandGenerationMethod (K_TRADEMGEN_DEFAULT_DEMAND_GENERATION_METHOD);
414
415 // Call the command-line option parser
416 const int lOptionParserStatus =
417 readConfiguration (argc, argv, isBuiltin, lRandomSeed,
418 lInputFilename, lOutputFilename, lLogFilename,
419 lDemandGenerationMethod);
420
421 if (lOptionParserStatus == K_TRADEMGEN_EARLY_RETURN_STATUS) {
422 return 0;
423 }
424
425 // Set the log parameters
426 std::ofstream logOutputFile;
427 // Open and clean the log outputfile
428 logOutputFile.open (lLogFilename.c_str());
429 logOutputFile.clear();
430
431 // Set up the log parameters
432 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
433
434 // Initialise the TraDemGen service object
435 TRADEMGEN::TRADEMGEN_Service trademgenService (lLogParams, lRandomSeed);
436
437 // Check wether or not a (CSV) input file should be read
438 if (isBuiltin == true) {
439 // Create a sample DemandStream object, and insert it within the BOM tree
440 trademgenService.buildSampleBom();
441 lDefaultDemandStreamKey = "SIN-BKK 2010-Feb-08 Y";
442
443 } else {
444 // Create the DemandStream objects, and insert them within the BOM tree
445 const TRADEMGEN::DemandFilePath lDemandFilePath (lInputFilename);
446 trademgenService.parseAndLoad (lDemandFilePath);
447 lDefaultDemandStreamKey = "SIN-BKK 2009-Feb-09 Y";
448 }
449
450 // DEBUG
451 STDAIR_LOG_DEBUG ("====================================================");
452 STDAIR_LOG_DEBUG ("= Beginning of the interactive session =");
453 STDAIR_LOG_DEBUG ("====================================================");
454
455 // Initialise the GNU readline wrapper
456 swift::SReadline lReader (lHistoryFilename, lHistorySize);
457 initReadline (lReader);
458
459 // Now we can ask user for a line
460 std::string lUserInput;
461 bool EndOfInput (false);
462 Command_T::Type_T lCommandType (Command_T::NOP);
463
464 while (lCommandType != Command_T::QUIT && EndOfInput == false) {
465
466 // Update the interactive parameters which have not been updated yet
467 //lCurrentInteractiveDateTime = lCurrentInteractiveEventStruct.getEventTime ();
468 //lCurrentInteractiveEventType = lCurrentInteractiveEventStruct.getEventType ();
469
470 // Prompt
471 std::ostringstream oPromptStr;
472 oPromptStr << "trademgen " << "> " ;
473 // << stdair::EventType::getTypeLabelAsString(lCurrentInteractiveEventType)
474 // << " / " << lCurrentInteractiveDateTime << "> " ;
475 // Call read-line, which will fill the list of tokens
476 TokenList_T lTokenListByReadline;
477 lUserInput = lReader.GetLine (oPromptStr.str(), lTokenListByReadline,
478 EndOfInput);
479
480 // The history can be saved to an arbitrary file at any time
481 lReader.SaveHistory (lHistoryBackupFilename);
482
483 // The end-of-input typically corresponds to a CTRL-D typed by the user
484 if (EndOfInput) {
485 std::cout << std::endl;
486 break;
487 }
488
489 // Interpret the user input
490 lCommandType = extractCommand (lTokenListByReadline);
491
492 switch (lCommandType) {
493
494 // ////////////////////////////// Help ////////////////////////
495 case Command_T::HELP: {
496 std::cout << std::endl;
497 std::cout << "Commands: " << std::endl;
498 std::cout << " help" << "\t\t\t" << "Display this help" << std::endl;
499 std::cout << " quit" << "\t\t\t" << "Quit the application" << std::endl;
500 std::cout << " list_event" << "\t\t"
501 << "List all the events in the queue" << std::endl;
502 std::cout << " list_demand_stream" << "\t"
503 << "List the streams used to generate demand" << std::endl;
504 std::cout << " reset" << "\t\t\t" << "Reset the service (including the "
505 << "event queue)" << std::endl;
506 std::cout << " generate_first_br" << "\t" << "Generate the first booking "
507 << "request for each demand stream and add it to the event queue"
508 << std::endl;
509 std::cout << " generate_next_br" << "\t" << "Generate the next event for "
510 << "the specified demand stream and add it to the event queue"
511 << "\n\t\t\tFor instance:"
512 << "\n\t\t\t 'generate_next_br " << lDefaultDemandStreamKey
513 << "'" << std::endl;
514 std::cout << " generate_all_br" << "\t" << "Generate all the events for "
515 << "the specified demand stream and add it to the event queue"
516 << "\n\t\t\tFor instance:"
517 << "\n\t\t\t 'generate_all_br " << lDefaultDemandStreamKey
518 << "'" << std::endl;
519 std::cout << " delete_first" << "\t\t"
520 << "Pop the next event from the queue"
521 << std::endl;
522 std::cout << " \nDebug Commands" << std::endl;
523 std::cout << " json_list" << "\t\t"
524 << "List events in the queue in a JSON format"
525 << std::endl;
526 std::cout << std::endl;
527 break;
528 }
529
530 // ////////////////////////////// Quit ////////////////////////
531 case Command_T::QUIT: {
532 break;
533 }
534
535 // ////////////////////////////// List /////////////////////////
536 case Command_T::LIST_EVENT: {
537 //
538 std::cout << "List of events" << std::endl;
539
540 std::ostringstream oEventListStr;
541 oEventListStr << trademgenService.list ();
542 std::cout << oEventListStr.str() << std::endl;
543 STDAIR_LOG_DEBUG (oEventListStr.str());
544
545 //
546 break;
547 }
548
549 // ////////////////////////////// List /////////////////////////
550 case Command_T::LIST_DEMAND_STREAM: {
551 //
552 std::cout << "List of demand streams" << std::endl;
553
554 std::ostringstream oEventListStr;
555 oEventListStr << trademgenService.displayDemandStream ();
556 std::cout << oEventListStr.str() << std::endl;
557 STDAIR_LOG_DEBUG (oEventListStr.str());
558
559 //
560 break;
561 }
562
563 // ////////////////////////////// Reset /////////////////////////
564 case Command_T::RESET: {
565
566 std::cout << "Reset" << std::endl;
567
568 // Reset the service (including the event queue) for the next run
569 trademgenService.reset();
570
571 break;
572 }
573
574 // ////////////////////////////// Generate next request ////////////////////////
575 case Command_T::GENERATE_NEXT_BR: {
576
577 // Retrieve the corresponding demand stream key
578 const stdair::DemandGeneratorKey_T lDemandStreamKey =
579 toString(lTokenListByReadline);
580
581 // Check that such demand stream exists
582 const bool hasDemandStream =
583 trademgenService.hasDemandStream(lDemandStreamKey);
584
585 if (hasDemandStream == false) {
586 // DEBUG
587 std::ostringstream oNoDemandStreamStr;
588 oNoDemandStreamStr << "Wrong demand stream key: '"
589 << lDemandStreamKey << "'."
590 << "\nExisting demand streams are:\n"
591 << trademgenService.displayDemandStream();
592 std::cout << oNoDemandStreamStr.str() << std::endl;
593 STDAIR_LOG_DEBUG (oNoDemandStreamStr.str());
594 break;
595 }
596 assert (hasDemandStream == true);
597
598 stdair::ProgressStatusSet lProgressStatusSet (stdair::EventType::BKG_REQ);
599 const bool stillHavingRequestsToBeGenerated =
600 trademgenService.stillHavingRequestsToBeGenerated (lDemandStreamKey,
601 lProgressStatusSet,
602 lDemandGenerationMethod);
603 if (stillHavingRequestsToBeGenerated == false) {
604 // DEBUG
605 std::ostringstream oNoMoreEventToGenerateStr;
606 oNoMoreEventToGenerateStr << "No more events to generate for the demand "
607 << "stream: '" << lDemandStreamKey << "'.";
608 std::cout << oNoMoreEventToGenerateStr.str() << std::endl;
609 STDAIR_LOG_DEBUG (oNoMoreEventToGenerateStr.str());
610 break;
611 }
612 assert (stillHavingRequestsToBeGenerated == true);
613
614 trademgenService.generateNextRequest (lDemandStreamKey, lDemandGenerationMethod);
615
616 // DEBUG
617 std::ostringstream oOneMoreEventGeneratedStr;
618 oOneMoreEventGeneratedStr << "One more event have been generated for the demand "
619 << "stream: '" << lDemandStreamKey << "'.";
620 std::cout << oOneMoreEventGeneratedStr.str() << std::endl;
621 STDAIR_LOG_DEBUG (oOneMoreEventGeneratedStr.str());
622
623 break;
624 }
625
626 // ////////////////////////////// Generate first requests ////////////////////////
627 case Command_T::GENERATE_FIRST_BR: {
628
629 std::cout << "Generate first requests" << std::endl;
630
631 // Generate the first event for each demand stream.
632 trademgenService.generateFirstRequests (lDemandGenerationMethod);
633
634 break;
635 }
636
637 // ////////////////////////////// Generate all requests ////////////////////////
638 case Command_T::GENERATE_ALL_BR: {
639
640 // Retrieve the corresponding demand stream key
641 const stdair::DemandGeneratorKey_T lDemandStreamKey =
642 toString(lTokenListByReadline);
643
644 // Check that such demand stream exists
645 const bool hasDemandStream =
646 trademgenService.hasDemandStream(lDemandStreamKey);
647
648 if (hasDemandStream == false) {
649 // DEBUG
650 std::ostringstream oNoDemandStreamStr;
651 oNoDemandStreamStr << "Wrong demand stream key: '"
652 << lDemandStreamKey << "'."
653 << "\nExisting demand streams are:\n"
654 << trademgenService.displayDemandStream();
655 std::cout << oNoDemandStreamStr.str() << std::endl;
656 STDAIR_LOG_DEBUG (oNoDemandStreamStr.str());
657 break;
658 }
659 assert (hasDemandStream == true);
660
661 stdair::ProgressStatusSet lProgressStatusSet (stdair::EventType::BKG_REQ);
662 bool stillHavingRequestsToBeGenerated =
663 trademgenService.stillHavingRequestsToBeGenerated (lDemandStreamKey,
664 lProgressStatusSet,
665 lDemandGenerationMethod);
666
667
668 if (stillHavingRequestsToBeGenerated == false) {
669 // DEBUG
670 std::ostringstream oNoMoreEventToGenerateStr;
671 oNoMoreEventToGenerateStr << "No more events to generate for the demand "
672 << "stream: '" << lDemandStreamKey << "'.";
673 std::cout << oNoMoreEventToGenerateStr.str() << std::endl;
674 STDAIR_LOG_DEBUG (oNoMoreEventToGenerateStr.str());
675 break;
676 }
677 assert (stillHavingRequestsToBeGenerated == true);
678
679 stdair::Count_T lNumberOfRequests = 0;
680 while (stillHavingRequestsToBeGenerated == true) {
681 lNumberOfRequests++;
682 trademgenService.generateNextRequest (lDemandStreamKey, lDemandGenerationMethod);
683 stillHavingRequestsToBeGenerated =
684 trademgenService.stillHavingRequestsToBeGenerated (lDemandStreamKey,
685 lProgressStatusSet,
686 lDemandGenerationMethod);
687
688
689 }
690 // DEBUG
691 std::ostringstream oOneMoreEventGeneratedStr;
692 oOneMoreEventGeneratedStr << lNumberOfRequests
693 << " more event(s) have been generated for the demand "
694 << "stream: '" << lDemandStreamKey << "'.";
695 std::cout << oOneMoreEventGeneratedStr.str() << std::endl;
696 STDAIR_LOG_DEBUG (oOneMoreEventGeneratedStr.str());
697
698 break;
699 }
700
701 // ////////////////////////////// Next ////////////////////////
702 case Command_T::NEXT: {
703 //
704 std::cout << "Next" << std::endl;
705
706 if (trademgenService.isQueueDone() == true) {
707
708 // DEBUG
709 std::ostringstream oEmptyQueueStr;
710 oEmptyQueueStr << "The event queue is empty: no event can be popped out.";
711 std::cout << oEmptyQueueStr.str() << std::endl;
712 STDAIR_LOG_DEBUG (oEmptyQueueStr.str());
713
714 //
715 break;
716
717 }
718
719 // Get the next event from the event queue
720 trademgenService.popEvent (lCurrentInteractiveEventStruct);
721
722 // DEBUG
723 std::ostringstream oEventStr;
724 oEventStr << "Poped event: '"
725 << lCurrentInteractiveEventStruct.describe() << "'.";
726 std::cout << oEventStr.str() << std::endl;
727 STDAIR_LOG_DEBUG (oEventStr.str());
728
729 //
730 break;
731 }
732 // ////////////////////////////// JSon Event List ////////////////////////
733
734 case Command_T::JSON_LIST: {
735 //
736 std::cout << "JSON Event List" << std::endl;
737
738 std::ostringstream lMyCommandJSONstream;
739 lMyCommandJSONstream << "{\"event_list\":"
740 << "{ \"event_type\":\"" << "all"
741 << "\"}}";
742
743 // Delegate the call to the dedicated service
744 const stdair::JSONString lJSONCommandString (lMyCommandJSONstream.str());
745 const std::string& lCSVEventListDump =
746 trademgenService.jsonHandler (lJSONCommandString);
747
748 // DEBUG: Display the events queue JSON string
749 std::cout << lCSVEventListDump << std::endl;
750 STDAIR_LOG_DEBUG (lCSVEventListDump);
751
752 break;
753 }
754
755 // /////////////////////////// Default / No value ///////////////////////
756 case Command_T::NOP: {
757 break;
758 }
759
760 case Command_T::LAST_VALUE:
761 default: {
762 // DEBUG
763 std::ostringstream oStr;
764 oStr << "That command is not yet understood: '" << lUserInput
765 << "' => " << lTokenListByReadline;
766 STDAIR_LOG_DEBUG (oStr.str());
767 std::cout << oStr.str() << std::endl;
768 }
769 }
770 }
771
772 // DEBUG
773 STDAIR_LOG_DEBUG ("End of the session. Exiting.");
774 std::cout << "End of the session. Exiting." << std::endl;
775
776 // Close the Log outputFile
777 logOutputFile.close();
778
779 /*
780 Note: as that program is not intended to be run on a server in
781 production, it is better not to catch the exceptions. When it
782 happens (that an exception is throwned), that way we get the
783 call stack.
784 */
785
786 return 0;
787}
int main(int argc, char *argv[])
unsigned int NbOfRuns_T
const stdair::Filename_T K_TRADEMGEN_DEFAULT_INPUT_FILENAME(STDAIR_SAMPLE_DIR "/demand01.csv")
const stdair::RandomSeed_T K_TRADEMGEN_DEFAULT_RANDOM_SEED
int readConfiguration(int argc, char *argv[], bool &ioIsBuiltin, stdair::RandomSeed_T &ioRandomSeed, NbOfRuns_T &ioRandomRuns, stdair::Filename_T &ioInputFilename, stdair::Filename_T &ioOutputFilename, stdair::Filename_T &ioLogFilename, stdair::DemandGenerationMethod &ioDemandGenerationMethod)
std::ostream & operator<<(std::ostream &os, const std::vector< T > &v)
const stdair::DemandGenerationMethod K_TRADEMGEN_DEFAULT_DEMAND_GENERATION_METHOD
const char K_TRADEMGEN_DEFAULT_DEMAND_GENERATION_METHOD_CHAR
const int K_TRADEMGEN_EARLY_RETURN_STATUS
const stdair::Filename_T K_TRADEMGEN_DEFAULT_LOG_FILENAME("trademgen_generateDemand.log")
const bool K_TRADEMGEN_DEFAULT_BUILT_IN_INPUT
std::string createStringFromWordList(const WordList_T &iWordList)
void tokeniseStringIntoWordList(const std::string &iPhrase, WordList_T &ioWordList)
std::vector< std::string > WordList_T
class holding the services related to Travel Demand Generation.