TraDemGen Logo  1.00.12
C++ Simulated Travel Demand Generation Library
Loading...
Searching...
No Matches
DemandParserHelper.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6// StdAir
7#include <stdair/basic/RandomGeneration.hpp>
8#include <stdair/basic/BasFileMgr.hpp>
9#include <stdair/service/Logger.hpp>
10// TraDemGen
12//#define BOOST_SPIRIT_DEBUG
15
16namespace bsc = boost::spirit::classic;
17
18namespace TRADEMGEN {
19
20 namespace DemandParserHelper {
21
22 // //////////////////////////////////////////////////////////////////
23 // Semantic actions
24 // //////////////////////////////////////////////////////////////////
25
29
30 // //////////////////////////////////////////////////////////////////
35
36 // //////////////////////////////////////////////////////////////////
38 iterator_t iStrEnd) const {
39 _demand._prefDepDateStart = _demand.getDate();
40
41 // Reset the number of seconds
42 _demand._itSeconds = 0;
43 }
44
45 // //////////////////////////////////////////////////////////////////
50
51 // //////////////////////////////////////////////////////////////////
53 iterator_t iStrEnd) const {
54 // As a Boost date period (DatePeriod_T) defines the last day of
55 // the period to be end-date - one day, we have to add one day to that
56 // end date before.
57 const stdair::DateOffset_T oneDay (1);
58 _demand._prefDepDateEnd = _demand.getDate() + oneDay;
59
60 // Transform the date pair (i.e., the date range) into a date period
61 _demand._dateRange =
62 stdair::DatePeriod_T (_demand._prefDepDateStart,
63 _demand._prefDepDateEnd);
64
65 // Reset the number of seconds
66 _demand._itSeconds = 0;
67 }
68
69 // //////////////////////////////////////////////////////////////////
71 : ParserSemanticAction (ioDemand) {
72 }
73
74 // //////////////////////////////////////////////////////////////////
75 void storeDow::operator() (iterator_t iStr, iterator_t iStrEnd) const {
76 stdair::DOW_String_T lDow (iStr, iStrEnd);
77 _demand._dow = lDow;
78 }
79
80 // //////////////////////////////////////////////////////////////////
84
85 // //////////////////////////////////////////////////////////////////
87 stdair::AirportCode_T lOrigin (iStr, iStrEnd);
88 _demand._origin = lOrigin;
89 }
90
91 // //////////////////////////////////////////////////////////////////
95
96 // //////////////////////////////////////////////////////////////////
98 iterator_t iStrEnd) const {
99 stdair::AirportCode_T lDestination (iStr, iStrEnd);
100 _demand._destination = lDestination;
101 }
102
103 // //////////////////////////////////////////////////////////////////
107
108 // //////////////////////////////////////////////////////////////////
110 iterator_t iStrEnd) const {
111 stdair::CabinCode_T lPrefCabin (iStr, iStrEnd);
112 _demand._prefCabin = lPrefCabin;
113 //STDAIR_LOG_DEBUG ("Preferred cabin: " << lPrefCabin);
114 }
115
116 // //////////////////////////////////////////////////////////////////
120
121 // //////////////////////////////////////////////////////////////////
122 void storeDemandMean::operator() (double iReal) const {
123 _demand._demandMean = iReal;
124 //STDAIR_LOG_DEBUG ("Demand mean: " << iReal);
125 }
126
127 // //////////////////////////////////////////////////////////////////
131
132 // //////////////////////////////////////////////////////////////////
133 void storeDemandStdDev::operator() (double iReal) const {
134 _demand._demandStdDev = iReal;
135 //STDAIR_LOG_DEBUG ("Demand stddev: " << iReal);
136 }
137
138 // //////////////////////////////////////////////////////////////////
142
143 // //////////////////////////////////////////////////////////////////
144 void storeDemandChangeFeeProb::operator() (double iReal) const {
145 _demand._changeFeeProb = iReal;
146 //STDAIR_LOG_DEBUG ("Demand change fee prob: " << iReal);
147 }
148
149 // //////////////////////////////////////////////////////////////////
153
154 // //////////////////////////////////////////////////////////////////
156 _demand._changeFeeDisutility = iReal;
157 //STDAIR_LOG_DEBUG ("Demand change fee disutility: " << iReal);
158 }
159
160 // //////////////////////////////////////////////////////////////////
165
166 // //////////////////////////////////////////////////////////////////
168 _demand._nonRefundableProb = iReal;
169 //STDAIR_LOG_DEBUG ("Demand non refundable prob: " << iReal);
170 }
171
172 // //////////////////////////////////////////////////////////////////
177
178 // //////////////////////////////////////////////////////////////////
180 _demand._nonRefundableDisutility = iReal;
181 //STDAIR_LOG_DEBUG ("Demand non refundable disutility: " << iReal);
182 }
183
184 // //////////////////////////////////////////////////////////////////
188
189 // //////////////////////////////////////////////////////////////////
191 const stdair::AirportCode_T lPosCode (iStr, iStrEnd);
192 _demand._itPosCode = lPosCode;
193 //STDAIR_LOG_DEBUG ("Pos code: " << lPosCode);
194 }
195
196 // //////////////////////////////////////////////////////////////////
200
201 // //////////////////////////////////////////////////////////////////
202 void storePosProbMass::operator() (double iReal) const {
203 const bool hasInsertBeenSuccessfull =
204 _demand._posProbDist.
206 value_type (_demand._itPosCode, iReal)).second;
207 if (hasInsertBeenSuccessfull == false) {
208 STDAIR_LOG_ERROR ("The same POS code ('" << _demand._itPosCode
209 << "') has probably been given twice");
210 throw stdair::CodeDuplicationException ("The same POS code ('"
211 + _demand._itPosCode
212 + "') has probably been given twice");
213 }
214
215 //STDAIR_LOG_DEBUG ("PosProbMass: " << iReal);
216 }
217
218 // //////////////////////////////////////////////////////////////////
222
223 // //////////////////////////////////////////////////////////////////
225 iterator_t iStrEnd) const {
226 _demand._itChannelCode = std::string (iStr, iStrEnd);
227 //STDAIR_LOG_DEBUG ("Channel code: " << _demand._itChannelCode);
228 }
229
230 // //////////////////////////////////////////////////////////////////
234
235 // //////////////////////////////////////////////////////////////////
236 void storeChannelProbMass::operator() (double iReal) const {
237 const bool hasInsertBeenSuccessfull =
238 _demand._channelProbDist.
240 value_type (_demand._itChannelCode, iReal)).second;
241 if (hasInsertBeenSuccessfull == false) {
242 STDAIR_LOG_ERROR ("The same channel type code ('"
243 << _demand._itChannelCode
244 << "') has probably been given twice");
245 throw stdair::CodeDuplicationException ("The same channel type code ('"
246 + _demand._itChannelCode
247 + "') has probably been given twice");
248 }
249
250 //STDAIR_LOG_DEBUG ("ChannelProbMass: " << iReal);
251 }
252
253 // //////////////////////////////////////////////////////////////////
257
258 // //////////////////////////////////////////////////////////////////
260 iterator_t iStrEnd) const {
261 _demand._itTripCode = std::string (iStr, iStrEnd);
262 //STDAIR_LOG_DEBUG ("Trip code: " << _demand._itTripCode);
263 }
264
265 // //////////////////////////////////////////////////////////////////
269
270 // //////////////////////////////////////////////////////////////////
271 void storeTripProbMass::operator() (double iReal) const {
272 const bool hasInsertBeenSuccessfull =
273 _demand._tripProbDist.
275 value_type (_demand._itTripCode, iReal)).second;
276 if (hasInsertBeenSuccessfull == false) {
277 STDAIR_LOG_ERROR ("The same trip type code ('"
278 << _demand._itTripCode
279 << "') has probably been given twice");
280 throw stdair::CodeDuplicationException ("The same trip type code ('"
281 + _demand._itTripCode
282 + "') has probably been given twice");
283 }
284
285 //STDAIR_LOG_DEBUG ("TripProbMass: " << iReal);
286 }
287
288 // //////////////////////////////////////////////////////////////////
292
293 // //////////////////////////////////////////////////////////////////
294 void storeStayCode::operator() (unsigned int iInteger) const {
295 const stdair::DayDuration_T lStayDuration (iInteger);
296 _demand._itStayDuration = lStayDuration;
297 // STDAIR_LOG_DEBUG ("Stay duration: " << lStayDuration);
298 }
299
300 // //////////////////////////////////////////////////////////////////
304
305 // //////////////////////////////////////////////////////////////////
306 void storeStayProbMass::operator() (double iReal) const {
307 const bool hasInsertBeenSuccessfull =
308 _demand._stayProbDist.
310 value_type (_demand._itStayDuration, iReal)).second;
311 if (hasInsertBeenSuccessfull == false) {
312 std::ostringstream oStr;
313 oStr << "The same stay duration ('" << _demand._itStayDuration
314 << "') has probably been given twice";
315 STDAIR_LOG_ERROR (oStr.str());
316 throw stdair::CodeDuplicationException (oStr.str());
317 }
318
319 // STDAIR_LOG_DEBUG ("StayProbMass: " << iReal);
320 }
321
322 // //////////////////////////////////////////////////////////////////
324 : ParserSemanticAction (ioDemand) {
325 }
326
327 // //////////////////////////////////////////////////////////////////
329 _demand._itFFCode = std::string (iStr, iStrEnd);
330 //STDAIR_LOG_DEBUG ("FF code: " << _demand._itFFCode);
331 }
332
333 // //////////////////////////////////////////////////////////////////
337
338 // //////////////////////////////////////////////////////////////////
339 void storeFFProbMass::operator() (double iReal) const {
340 const bool hasInsertBeenSuccessfull =
341 _demand._ffProbDist.
343 value_type (_demand._itFFCode, iReal)).second;
344 if (hasInsertBeenSuccessfull == false) {
345 STDAIR_LOG_ERROR ("The same Frequent Flyer code ('"
346 << _demand._itFFCode
347 << "') has probably been given twice");
348 throw stdair::CodeDuplicationException("The same Frequent Flyer code ('"
349 + _demand._itFFCode
350 + "') has probably been given twice");
351 }
352
353 //STDAIR_LOG_DEBUG ("FfProbMass: " << iReal);
354 }
355
356 // //////////////////////////////////////////////////////////////////
360
361 // //////////////////////////////////////////////////////////////////
363 iterator_t iStrEnd) const {
364 _demand._itPrefDepTime = _demand.getTime();
365
366 // DEBUG
367 // STDAIR_LOG_DEBUG ("Pref dep time: " << _demand._itHours << ":"
368 // << _demand._itMinutes << ":" << _demand._itSeconds
369 // << " ==> " << _demand._itPrefDepTime);
370
371 // Reset the number of minutes and seconds
372 _demand._itMinutes = 0;
373 _demand._itSeconds = 0;
374 }
375
376 // //////////////////////////////////////////////////////////////////
380
381 // //////////////////////////////////////////////////////////////////
382 void storePrefDepTimeProbMass::operator() (double iReal) const {
383 const stdair::IntDuration_T lIntDuration =
384 _demand._itPrefDepTime.total_seconds();
385
386 _demand._prefDepTimeProbDist.
388 value_type (lIntDuration, iReal));
389 //STDAIR_LOG_DEBUG ("PrefDepTimeProbMass: " << iReal);
390 }
391
392 // //////////////////////////////////////////////////////////////////
394 : ParserSemanticAction (ioDemand) {
395 }
396
397 // //////////////////////////////////////////////////////////////////
398 void storeWTP::operator() (double iReal) const {
399 _demand._minWTP = iReal;
400 //STDAIR_LOG_DEBUG ("WTP: " << iReal);
401 }
402
403 // //////////////////////////////////////////////////////////////////
407
408 // //////////////////////////////////////////////////////////////////
409 void storeTimeValue::operator() (double iReal) const {
410 _demand._itTimeValue = iReal;
411 //STDAIR_LOG_DEBUG ("Time value: " << iReal);
412 }
413
414 // //////////////////////////////////////////////////////////////////
418
419 // //////////////////////////////////////////////////////////////////
420 void storeTimeValueProbMass::operator() (double iReal) const {
421 _demand._timeValueProbDist.
423 value_type (_demand._itTimeValue, iReal));
424 //STDAIR_LOG_DEBUG ("TimeValueProbMass: " << iReal);
425 }
426
427 // //////////////////////////////////////////////////////////////////
429 : ParserSemanticAction (ioDemand) {
430 }
431
432 // //////////////////////////////////////////////////////////////////
433 void storeDTD::operator() (unsigned int iInteger) const {
434 const stdair::DayDuration_T lDTD (iInteger);
435 _demand._itDTD = lDTD;
436 //STDAIR_LOG_DEBUG ("DTD: " << lDTD);
437 }
438
439 // //////////////////////////////////////////////////////////////////
443
444 // //////////////////////////////////////////////////////////////////
445 void storeDTDProbMass::operator() (double iReal) const {
446 const stdair::FloatDuration_T lZeroDTDFloat = 0.0;
447 stdair::FloatDuration_T lDTDFloat =
448 static_cast<stdair::FloatDuration_T> (_demand._itDTD);
449 lDTDFloat = lZeroDTDFloat - lDTDFloat;
450
452 value_type (lDTDFloat, iReal));
453 //STDAIR_LOG_DEBUG ("DTDProbMass: " << iReal);
454 }
455
456 // //////////////////////////////////////////////////////////////////
457 doEndDemand::doEndDemand (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
458 stdair::RandomGeneration& ioSharedGenerator,
459 const POSProbabilityMass_T& iPOSProbMass,
460 DemandStruct& ioDemand)
461 : ParserSemanticAction (ioDemand),
462 _sevmgrServicePtr (ioSEVMGR_ServicePtr),
463 _uniformGenerator (ioSharedGenerator),
464 _posProbabilityMass (iPOSProbMass) {
465 }
466
467 // //////////////////////////////////////////////////////////////////
468 // void doEndDemand::operator() (char iChar) const {
470
471 // DEBUG: Display the result
472 // STDAIR_LOG_DEBUG ("Demand: " << _demand.describe());
473
474 // Create the Demand BOM objects
475 DemandManager::createDemandCharacteristics (_sevmgrServicePtr,
478
479 // Clean the lists
480 _demand._posProbDist.clear();
481 _demand._channelProbDist.clear();
482 _demand._tripProbDist.clear();
483 _demand._stayProbDist.clear();
484 _demand._ffProbDist.clear();
485 _demand._prefDepTimeProbDist.clear();
486 _demand._timeValueProbDist.clear();
487 _demand._dtdProbDist.clear();
488 }
489
490
491 // ///////////////////////////////////////////////////////////////////
492 //
493 // Utility Parsers
494 //
495 // ///////////////////////////////////////////////////////////////////
498
501
504
507
510
513
515 repeat_p_t airline_code_p (chset_t("0-9A-Z").derived(), 2, 3);
516
519
521 bounded4_p_t year_p (uint4_p.derived(), 2000u, 2099u);
522
524 bounded2_p_t month_p (uint2_p.derived(), 1u, 12u);
525
527 bounded2_p_t day_p (uint2_p.derived(), 1u, 31u);
528
530 repeat_p_t dow_p (chset_t("0-1").derived().derived(), 7, 7);
531
533 repeat_p_t airport_p (chset_t("0-9A-Z").derived(), 3, 3);
534
536 bounded1_2_p_t hours_p (uint1_2_p.derived(), 0u, 23u);
537
539 bounded2_p_t minutes_p (uint2_p.derived(), 0u, 59u);
540
542 bounded2_p_t seconds_p (uint2_p.derived(), 0u, 59u);
543
546
549
552
555
557 repeat_p_t class_code_list_p (chset_t("A-Z").derived(), 1, 26);
558
561
562
563 // //////////////////////////////////////////////////////////////////
564 // (Boost Spirit) Grammar Definition
565 // //////////////////////////////////////////////////////////////////
566
567 // //////////////////////////////////////////////////////////////////
568 DemandParser::DemandParser (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
569 stdair::RandomGeneration& ioSharedGenerator,
570 const POSProbabilityMass_T& iPOSProbMass,
571 DemandStruct& ioDemand)
572 : _sevmgrServicePtr (ioSEVMGR_ServicePtr),
573 _uniformGenerator (ioSharedGenerator),
574 _posProbabilityMass (iPOSProbMass), _demand (ioDemand) {
575 }
576
577 // //////////////////////////////////////////////////////////////////
578 template<typename ScannerT>
580 definition (DemandParser const& self) {
581
583 demand)
584 ;
585
586 not_to_be_parsed = bsc::
587 lexeme_d[bsc::comment_p("//")
588 | bsc::comment_p("/*", "*/")
589 | bsc::eol_p]
590 ;
591
592 demand =
594 >> ';' >> origin >> ';' >> destination
595 >> ';' >> pref_cabin[storePrefCabin(self._demand)]
596 >> ';' >> pos_dist
597 >> ';' >> channel_dist
598 >> ';' >> trip_dist
599 >> ';' >> stay_dist
600 >> ';' >> ff_dist
601 >> ';' >> change_fees
602 >> ';' >> non_refundable
603 >> ';' >> pref_dep_time_dist
604 >> ';' >> wtp
605 >> ';' >> time_value_dist
606 >> ';' >> dtd_dist
607 >> ';' >> demand_params
610 self._posProbabilityMass, self._demand)]
611 ;
612
613 demand_end = bsc::ch_p(';')
614 ;
615
617 >> ';' >> date[storePrefDepDateRangeEnd(self._demand)]
618 >> ';' >> dow[storeDow(self._demand)]
619 ;
620
621 date =
622 bsc::lexeme_d[(year_p)[bsc::assign_a(self._demand._itYear)]
623 >> '-' >> (month_p)[bsc::assign_a(self._demand._itMonth)]
624 >> '-' >> (day_p)[bsc::assign_a(self._demand._itDay)]
625 ]
626 ;
627
628 dow = bsc::lexeme_d[ dow_p ]
629 ;
630
631 origin =
633 ;
634
637 ;
638
640
641 pos_dist =
642 pos_pair >> *( ',' >> pos_pair )
643 ;
644
645 pos_pair =
647 >> ':' >> pos_share
648 ;
649
650 pos_code =
652 | bsc::chseq_p("row")
653 ;
654
655 pos_share =
656 (bsc::ureal_p)[storePosProbMass(self._demand)]
657 ;
658
660 channel_pair >> *( ',' >> channel_pair )
661 ;
662
665 >> ':' >> channel_share
666 ;
667
669 bsc::chseq_p("DF") | bsc::chseq_p("DN")
670 | bsc::chseq_p("IF") | bsc::chseq_p("IN")
671 ;
672
674 (bsc::ureal_p)[storeChannelProbMass(self._demand)]
675 ;
676
677 trip_dist =
678 trip_pair >> *( ',' >> trip_pair )
679 ;
680
681 trip_pair =
683 >> ':' >> trip_share
684 ;
685
686 trip_code =
687 bsc::chseq_p("RO") | bsc::chseq_p("RI") | bsc::chseq_p("OW")
688 ;
689
690 trip_share =
691 (bsc::ureal_p)[storeTripProbMass(self._demand)]
692 ;
693
694 stay_dist =
695 stay_pair >> *( ',' >> stay_pair )
696 ;
697
698 stay_pair =
700 >> ':' >> stay_share
701 ;
702
703 stay_share =
704 (bsc::ureal_p)[storeStayProbMass(self._demand)]
705 ;
706
707 ff_dist =
708 ff_pair >> *( ',' >> ff_pair )
709 ;
710
711 ff_pair =
713 >> ':' >> ff_share
714 ;
715
717
718 ff_share =
719 (bsc::ureal_p)[storeFFProbMass(self._demand)]
720 ;
721
723 (bsc::ureal_p)[storeDemandChangeFeeProb(self._demand)]
724 >> ';' >> (bsc::ureal_p)[storeDemandChangeFeeDisutility(self._demand)]
725 ;
726
728 (bsc::ureal_p)[storeDemandNonRefundableProb(self._demand)]
729 >> ';' >> (bsc::ureal_p)[storeDemandNonRefundableDisutility(self._demand)]
730 ;
731
734 ;
735
738 >> ':' >> pref_dep_time_share
739 ;
740
742 (bsc::ureal_p)[storePrefDepTimeProbMass(self._demand)]
743 ;
744
745 time =
746 bsc::lexeme_d[
747 (hours_p)[bsc::assign_a(self._demand._itHours)]
748 >> !('.' >> (minutes_p)[bsc::assign_a(self._demand._itMinutes)])
749 >> !('.' >> (seconds_p)[bsc::assign_a(self._demand._itSeconds)])
750 ]
751 ;
752
753 wtp =
754 (bsc::ureal_p)[storeWTP(self._demand)]
755 ;
756
758 time_value_pair >> *( ',' >> time_value_pair )
759 ;
760
762 (bsc::ureal_p)[storeTimeValue(self._demand)]
763 >> ':' >> time_value_share
764 ;
765
767 (bsc::ureal_p)[storeTimeValueProbMass(self._demand)]
768 ;
769
770 dtd_dist =
771 dtd_pair >> *( ',' >> dtd_pair )
772 ;
773
774 dtd_pair =
775 (bsc::ureal_p)[storeDTD(self._demand)]
776 >> ':' >> dtd_share
777 ;
778
779 dtd_share =
780 (bsc::ureal_p)[storeDTDProbMass(self._demand)]
781 ;
782
784 bsc::ch_p('N')
785 >> ','
786 >> (bsc::ureal_p)[storeDemandMean(self._demand)]
787 >> ','
788 >> (bsc::ureal_p)[storeDemandStdDev(self._demand)]
789 ;
790
791 // BOOST_SPIRIT_DEBUG_NODE (DemandParser);
792 BOOST_SPIRIT_DEBUG_NODE (demand_list);
793 BOOST_SPIRIT_DEBUG_NODE (not_to_be_parsed);
794 BOOST_SPIRIT_DEBUG_NODE (demand);
795 BOOST_SPIRIT_DEBUG_NODE (demand_end);
796 BOOST_SPIRIT_DEBUG_NODE (pref_dep_date);
797 BOOST_SPIRIT_DEBUG_NODE (date);
798 BOOST_SPIRIT_DEBUG_NODE (origin);
799 BOOST_SPIRIT_DEBUG_NODE (destination);
800 BOOST_SPIRIT_DEBUG_NODE (pref_cabin);
801 BOOST_SPIRIT_DEBUG_NODE (pos_dist);
802 BOOST_SPIRIT_DEBUG_NODE (pos_pair);
803 BOOST_SPIRIT_DEBUG_NODE (pos_code);
804 BOOST_SPIRIT_DEBUG_NODE (pos_share);
805 BOOST_SPIRIT_DEBUG_NODE (channel_dist);
806 BOOST_SPIRIT_DEBUG_NODE (channel_pair);
807 BOOST_SPIRIT_DEBUG_NODE (channel_code);
808 BOOST_SPIRIT_DEBUG_NODE (channel_share);
809 BOOST_SPIRIT_DEBUG_NODE (trip_dist);
810 BOOST_SPIRIT_DEBUG_NODE (trip_pair);
811 BOOST_SPIRIT_DEBUG_NODE (trip_code);
812 BOOST_SPIRIT_DEBUG_NODE (trip_share);
813 BOOST_SPIRIT_DEBUG_NODE (stay_dist);
814 BOOST_SPIRIT_DEBUG_NODE (stay_pair);
815 BOOST_SPIRIT_DEBUG_NODE (stay_share);
816 BOOST_SPIRIT_DEBUG_NODE (ff_dist);
817 BOOST_SPIRIT_DEBUG_NODE (ff_pair);
818 BOOST_SPIRIT_DEBUG_NODE (ff_code);
819 BOOST_SPIRIT_DEBUG_NODE (ff_share);
820 BOOST_SPIRIT_DEBUG_NODE (change_fees);
821 BOOST_SPIRIT_DEBUG_NODE (non_refundable);
822 BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_dist);
823 BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_pair);
824 BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_share);
825 BOOST_SPIRIT_DEBUG_NODE (time);
826 BOOST_SPIRIT_DEBUG_NODE (wtp);
827 BOOST_SPIRIT_DEBUG_NODE (time_value_dist);
828 BOOST_SPIRIT_DEBUG_NODE (time_value_pair);
829 BOOST_SPIRIT_DEBUG_NODE (time_value_share);
830 BOOST_SPIRIT_DEBUG_NODE (dtd_dist);
831 BOOST_SPIRIT_DEBUG_NODE (dtd_pair);
832 BOOST_SPIRIT_DEBUG_NODE (dtd_share);
833 BOOST_SPIRIT_DEBUG_NODE (demand_params);
834 }
835
836 // //////////////////////////////////////////////////////////////////
837 template<typename ScannerT>
838 bsc::rule<ScannerT> const&
842
843 }
844
845
847 //
848 // Entry class for the file parser
849 //
851
852 // //////////////////////////////////////////////////////////////////////
854 DemandFileParser (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
855 stdair::RandomGeneration& ioSharedGenerator,
856 const POSProbabilityMass_T& iPOSProbMass,
857 const std::string& iFilename)
858 : _filename (iFilename),
859 _sevmgrServicePtr (ioSEVMGR_ServicePtr),
860 _uniformGenerator (ioSharedGenerator),
861 _posProbabilityMass (iPOSProbMass) {
862 init();
863 }
864
865 // //////////////////////////////////////////////////////////////////////
866 void DemandFileParser::init() {
867 // Check that the file exists and is readable
868 const bool doesExistAndIsReadable =
869 stdair::BasFileMgr::doesExistAndIsReadable (_filename);
870
871 if (doesExistAndIsReadable == false) {
872 STDAIR_LOG_ERROR ("The demand file " << _filename
873 << " does not exist or can not be read.");
874
875 throw DemandInputFileNotFoundException ("The demand file " + _filename
876 + " does not exist or can not "
877 + "be read");
878 }
879
880 // Open the file
881 _startIterator = iterator_t (_filename);
882
883 // Check the filename exists and can be open
884 if (!_startIterator) {
885 STDAIR_LOG_ERROR ("The demand file " << _filename << " can not be open.");
886
887 throw DemandInputFileNotFoundException ("The demand file " + _filename
888 + " does not exist or can not "
889 + "be read");
890 }
891
892 // Create an EOF iterator
893 _endIterator = _startIterator.make_end();
894 }
895
896 // //////////////////////////////////////////////////////////////////////
898 bool oResult = false;
899
900 STDAIR_LOG_DEBUG ("Parsing demand input file: " << _filename);
901
902 // Initialise the parser (grammar) with the helper/staging structure.
903 DemandParserHelper::DemandParser lDemandParser (_sevmgrServicePtr,
904 _uniformGenerator,
905 _posProbabilityMass,
906 _demand);
907
908 // Launch the parsing of the file and, thanks to the doEndDemand
909 // call-back structure, the building of the whole EventQueue BOM
910 // (i.e., including Inventory, FlightDate, LegDate, SegmentDate, etc.)
911 bsc::parse_info<iterator_t> info =
912 bsc::parse (_startIterator, _endIterator, lDemandParser,
913 bsc::space_p - bsc::eol_p);
914
915 // Retrieves whether or not the parsing was successful
916 oResult = info.hit;
917
918 const std::string hasBeenFullyReadStr = (info.full == true)?"":"not ";
919 if (oResult == true) {
920 STDAIR_LOG_DEBUG ("Parsing of demand input file: " << _filename
921 << " succeeded: read " << info.length
922 << " characters. The input file has "
923 << hasBeenFullyReadStr
924 << "been fully read. Stop point: " << info.stop);
925
926 } else {
927 std::ostringstream oStr;
928 oStr << "Parsing of demand input file: " << _filename << " failed: read "
929 << info.length << " characters. The input file has "
930 << hasBeenFullyReadStr << "been fully read. Stop point: "
931 << info.stop;
932 STDAIR_LOG_ERROR (oStr.str());
933 throw stdair::ParserException (oStr.str());
934 }
935
936 return oResult;
937 }
938
939}
boost::spirit::classic::file_iterator< char_t > iterator_t
FrequentFlyerProbabilityMass_T::ProbabilityMassFunction_T FrequentFlyerProbabilityMassFunction_T
StayDurationProbabilityMass_T::ProbabilityMassFunction_T StayDurationProbabilityMassFunction_T
ValueOfTimeCumulativeDistribution_T::ContinuousDistribution_T ValueOfTimeContinuousDistribution_T
boost::spirit::classic::uint_parser< unsigned int, 10, 1, 3 > uint1_3_p_t
boost::spirit::classic::uint_parser< unsigned int, 10, 2, 2 > uint2_p_t
boost::spirit::classic::impl::loop_traits< chset_t, unsignedint, unsignedint >::type repeat_p_t
boost::spirit::classic::bounded< uint1_4_p_t, unsigned int > bounded1_4_p_t
boost::spirit::classic::uint_parser< unsigned int, 10, 4, 4 > uint4_p_t
boost::spirit::classic::bounded< uint4_p_t, unsigned int > bounded4_p_t
TripTypeProbabilityMass_T::ProbabilityMassFunction_T TripTypeProbabilityMassFunction_T
boost::spirit::classic::bounded< uint1_2_p_t, unsigned int > bounded1_2_p_t
boost::spirit::classic::bounded< uint1_3_p_t, unsigned int > bounded1_3_p_t
CategoricalAttributeLite< stdair::AirportCode_T > POSProbabilityMass_T
boost::spirit::classic::bounded< uint2_p_t, unsigned int > bounded2_p_t
boost::spirit::classic::uint_parser< unsigned int, 10, 1, 2 > uint1_2_p_t
boost::spirit::classic::chset< char_t > chset_t
ContinuousFloatDuration_T::ContinuousDistribution_T ArrivalPatternCumulativeDistribution_T
PreferredDepartureTimeCumulativeDistribution_T::ContinuousDistribution_T PreferredDepartureTimeContinuousDistribution_T
boost::spirit::classic::uint_parser< unsigned int, 10, 1, 4 > uint1_4_p_t
ChannelProbabilityMass_T::ProbabilityMassFunction_T ChannelProbabilityMassFunction_T
POSProbabilityMass_T::ProbabilityMassFunction_T POSProbabilityMassFunction_T
boost::spirit::classic::int_parser< unsigned int, 10, 1, 1 > int1_p_t
bounded4_p_t year_p(uint4_p.derived(), 2000u, 2099u)
bounded2_p_t seconds_p(uint2_p.derived(), 0u, 59u)
repeat_p_t airline_code_p(chset_t("0-9A-Z").derived(), 2, 3)
repeat_p_t class_code_list_p(chset_t("A-Z").derived(), 1, 26)
bounded2_p_t month_p(uint2_p.derived(), 1u, 12u)
bounded2_p_t minutes_p(uint2_p.derived(), 0u, 59u)
bounded1_4_p_t flight_number_p(uint1_4_p.derived(), 0u, 9999u)
bounded2_p_t day_p(uint2_p.derived(), 1u, 31u)
repeat_p_t dow_p(chset_t("0-1").derived().derived(), 7, 7)
bounded1_2_p_t hours_p(uint1_2_p.derived(), 0u, 23u)
repeat_p_t airport_p(chset_t("0-9A-Z").derived(), 3, 3)
bounded1_3_p_t stay_duration_p(uint1_3_p.derived(), 0u, 999u)
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(unsigned int iInteger) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(unsigned int iInteger) const
doEndDemand(SEVMGR::SEVMGR_ServicePtr_T, stdair::RandomGeneration &, const POSProbabilityMass_T &, DemandStruct &)
void operator()(iterator_t iStr, iterator_t iStrEnd) const
DemandParser(SEVMGR::SEVMGR_ServicePtr_T, stdair::RandomGeneration &, const POSProbabilityMass_T &, DemandStruct &)
boost::spirit::classic::rule< ScannerT > trip_share
boost::spirit::classic::rule< ScannerT > demand_list
boost::spirit::classic::rule< ScannerT > non_refundable
boost::spirit::classic::rule< ScannerT > demand_end
boost::spirit::classic::rule< ScannerT > channel_code
boost::spirit::classic::rule< ScannerT > pref_dep_time_dist
boost::spirit::classic::rule< ScannerT > pref_dep_time_share
boost::spirit::classic::rule< ScannerT > pref_cabin
boost::spirit::classic::rule< ScannerT > channel_share
boost::spirit::classic::rule< ScannerT > channel_pair
boost::spirit::classic::rule< ScannerT > stay_share
boost::spirit::classic::rule< ScannerT > time_value_pair
boost::spirit::classic::rule< ScannerT > destination
boost::spirit::classic::rule< ScannerT > demand_params
boost::spirit::classic::rule< ScannerT > pref_dep_time_pair
boost::spirit::classic::rule< ScannerT > time_value_dist
boost::spirit::classic::rule< ScannerT > change_fees
boost::spirit::classic::rule< ScannerT > const & start() const
boost::spirit::classic::rule< ScannerT > pref_dep_date_range
boost::spirit::classic::rule< ScannerT > channel_dist
boost::spirit::classic::rule< ScannerT > time_value_share
boost::spirit::classic::rule< ScannerT > not_to_be_parsed
DemandFileParser(SEVMGR::SEVMGR_ServicePtr_T, stdair::RandomGeneration &, const POSProbabilityMass_T &, const stdair::Filename_T &iDemandInputFilename)