7 #include <stdair/basic/RandomGeneration.hpp>
8 #include <stdair/basic/BasFileMgr.hpp>
9 #include <stdair/service/Logger.hpp>
16 namespace bsc = boost::spirit::classic;
20 namespace DemandParserHelper {
27 : _demand (ioDemand) {
57 const stdair::DateOffset_T oneDay (1);
76 stdair::DOW_String_T lDow (iStr, iStrEnd);
87 stdair::AirportCode_T lOrigin (iStr, iStrEnd);
99 stdair::AirportCode_T lDestination (iStr, iStrEnd);
111 stdair::CabinCode_T lPrefCabin (iStr, iStrEnd);
191 const stdair::AirportCode_T lPosCode (iStr, iStrEnd);
203 const bool hasInsertBeenSuccessfull =
207 if (hasInsertBeenSuccessfull ==
false) {
209 <<
"') has probably been given twice");
210 throw stdair::CodeDuplicationException (
"The same POS code ('"
212 +
"') has probably been given twice");
237 const bool hasInsertBeenSuccessfull =
241 if (hasInsertBeenSuccessfull ==
false) {
242 STDAIR_LOG_ERROR (
"The same channel type code ('"
244 <<
"') has probably been given twice");
245 throw stdair::CodeDuplicationException (
"The same channel type code ('"
247 +
"') has probably been given twice");
272 const bool hasInsertBeenSuccessfull =
276 if (hasInsertBeenSuccessfull ==
false) {
277 STDAIR_LOG_ERROR (
"The same trip type code ('"
279 <<
"') has probably been given twice");
280 throw stdair::CodeDuplicationException (
"The same trip type code ('"
282 +
"') has probably been given twice");
295 const stdair::DayDuration_T lStayDuration (iInteger);
307 const bool hasInsertBeenSuccessfull =
311 if (hasInsertBeenSuccessfull ==
false) {
312 std::ostringstream oStr;
314 <<
"') has probably been given twice";
315 STDAIR_LOG_ERROR (oStr.str());
316 throw stdair::CodeDuplicationException (oStr.str());
340 const bool hasInsertBeenSuccessfull =
344 if (hasInsertBeenSuccessfull ==
false) {
345 STDAIR_LOG_ERROR (
"The same Frequent Flyer code ('"
347 <<
"') has probably been given twice");
348 throw stdair::CodeDuplicationException(
"The same Frequent Flyer code ('"
350 +
"') has probably been given twice");
383 const stdair::IntDuration_T lIntDuration =
388 value_type (lIntDuration, iReal));
434 const stdair::DayDuration_T lDTD (iInteger);
446 const stdair::FloatDuration_T lZeroDTDFloat = 0.0;
447 stdair::FloatDuration_T lDTDFloat =
449 lDTDFloat = lZeroDTDFloat - lDTDFloat;
452 value_type (lDTDFloat, iReal));
458 stdair::RandomGeneration& ioSharedGenerator,
462 _sevmgrServicePtr (ioSEVMGR_ServicePtr),
463 _uniformGenerator (ioSharedGenerator),
464 _posProbabilityMass (iPOSProbMass) {
569 stdair::RandomGeneration& ioSharedGenerator,
572 : _sevmgrServicePtr (ioSEVMGR_ServicePtr),
573 _uniformGenerator (ioSharedGenerator),
574 _posProbabilityMass (iPOSProbMass), _demand (ioDemand) {
578 template<
typename ScannerT>
582 demand_list = *( not_to_be_parsed |
586 not_to_be_parsed = bsc::
587 lexeme_d[bsc::comment_p(
"//")
588 | bsc::comment_p(
"/*",
"*/")
594 >>
';' >> origin >>
';' >> destination
597 >>
';' >> channel_dist
601 >>
';' >> change_fees
602 >>
';' >> non_refundable
603 >>
';' >> pref_dep_time_dist
605 >>
';' >> time_value_dist
607 >>
';' >> demand_params
609 self._uniformGenerator,
610 self._posProbabilityMass,
self._demand)]
613 demand_end = bsc::ch_p(
';')
618 >>
';' >> dow[
storeDow(
self._demand)]
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)]
628 dow = bsc::lexeme_d[
dow_p ]
642 pos_pair >> *(
',' >> pos_pair )
652 | bsc::chseq_p(
"row")
660 channel_pair >> *(
',' >> channel_pair )
665 >>
':' >> channel_share
669 bsc::chseq_p(
"DF") | bsc::chseq_p(
"DN")
670 | bsc::chseq_p(
"IF") | bsc::chseq_p(
"IN")
678 trip_pair >> *(
',' >> trip_pair )
687 bsc::chseq_p(
"RO") | bsc::chseq_p(
"RI") | bsc::chseq_p(
"OW")
695 stay_pair >> *(
',' >> stay_pair )
708 ff_pair >> *(
',' >> ff_pair )
733 pref_dep_time_pair >> *(
',' >> pref_dep_time_pair )
738 >>
':' >> pref_dep_time_share
741 pref_dep_time_share =
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)])
754 (bsc::ureal_p)[
storeWTP(
self._demand)]
758 time_value_pair >> *(
',' >> time_value_pair )
763 >>
':' >> time_value_share
771 dtd_pair >> *(
',' >> dtd_pair )
775 (bsc::ureal_p)[
storeDTD(
self._demand)]
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);
837 template<
typename ScannerT>
838 bsc::rule<ScannerT>
const&
855 stdair::RandomGeneration& ioSharedGenerator,
857 const std::string& iFilename)
858 : _filename (iFilename),
859 _sevmgrServicePtr (ioSEVMGR_ServicePtr),
860 _uniformGenerator (ioSharedGenerator),
861 _posProbabilityMass (iPOSProbMass) {
866 void DemandFileParser::init() {
868 const bool doesExistAndIsReadable =
869 stdair::BasFileMgr::doesExistAndIsReadable (_filename);
871 if (doesExistAndIsReadable ==
false) {
872 STDAIR_LOG_ERROR (
"The demand file " << _filename
873 <<
" does not exist or can not be read.");
876 +
" does not exist or can not "
884 if (!_startIterator) {
885 STDAIR_LOG_ERROR (
"The demand file " << _filename <<
" can not be open.");
887 throw DemandInputFileNotFoundException (
"The demand file " + _filename
888 +
" does not exist or can not "
893 _endIterator = _startIterator.make_end();
898 bool oResult =
false;
900 STDAIR_LOG_DEBUG (
"Parsing demand input file: " << _filename);
911 bsc::parse_info<iterator_t> info =
912 bsc::parse (_startIterator, _endIterator, lDemandParser,
913 bsc::space_p - bsc::eol_p);
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);
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: "
932 STDAIR_LOG_ERROR (oStr.str());
933 throw stdair::ParserException (oStr.str());