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,
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
613 demand_end = bsc::ch_p(
';')
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 =
758 time_value_pair >> *(
',' >> time_value_pair )
763 >>
':' >> time_value_share
771 dtd_pair >> *(
',' >> dtd_pair )
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),
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.");
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());
stdair::DatePeriod_T _dateRange
stdair::Date_T _prefDepDateEnd
stdair::MeanValue_T _demandMean
storeChannelCode(DemandStruct &)
boost::spirit::classic::uint_parser< unsigned int, 10, 1, 4 > uint1_4_p_t
storeOrigin(DemandStruct &)
void operator()(double iReal) const
storePrefDepDateRangeStart(DemandStruct &)
boost::spirit::classic::bounded< uint1_4_p_t, unsigned int > bounded1_4_p_t
repeat_p_t class_code_list_p(chset_t("A-Z").derived(), 1, 26)
storeDemandChangeFeeProb(DemandStruct &)
storePosCode(DemandStruct &)
bounded2_p_t day_p(uint2_p.derived(), 1u, 31u)
DemandParser(SEVMGR::SEVMGR_ServicePtr_T, stdair::RandomGeneration &, const POSProbabilityMass_T &, DemandStruct &)
void operator()(iterator_t iStr, iterator_t iStrEnd) const
chset_t passenger_type_p("A-Z")
void operator()(iterator_t iStr, iterator_t iStrEnd) const
bounded1_2_p_t hours_p(uint1_2_p.derived(), 0u, 23u)
PreferredDepartureTimeContinuousDistribution_T _prefDepTimeProbDist
stdair::AirportCode_T _origin
void operator()(double iReal) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
boost::spirit::classic::uint_parser< unsigned int, 10, 4, 4 > uint4_p_t
ValueOfTimeContinuousDistribution_T _timeValueProbDist
repeat_p_t airline_code_p(chset_t("0-9A-Z").derived(), 2, 3)
void operator()(unsigned int iInteger) const
stdair::RandomGeneration & _uniformGenerator
storeDemandStdDev(DemandStruct &)
boost::spirit::classic::uint_parser< unsigned int, 10, 1, 3 > uint1_3_p_t
boost::spirit::classic::bounded< uint4_p_t, unsigned int > bounded4_p_t
boost::spirit::classic::bounded< uint1_3_p_t, unsigned int > bounded1_3_p_t
void operator()(double iReal) const
void operator()(double iReal) const
ValueOfTimeCumulativeDistribution_T::ContinuousDistribution_T ValueOfTimeContinuousDistribution_T
void operator()(double iReal) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
StayDurationProbabilityMassFunction_T _stayProbDist
void operator()(double iReal) const
void operator()(double iReal) const
FrequentFlyerProbabilityMass_T::ProbabilityMassFunction_T FrequentFlyerProbabilityMassFunction_T
stdair::Disutility_T _changeFeeDisutility
storeTimeValueProbMass(DemandStruct &)
boost::spirit::classic::file_iterator< char_t > iterator_t
storeTimeValue(DemandStruct &)
stdair::RandomGeneration & _uniformGenerator
storePrefDepTime(DemandStruct &)
void operator()(iterator_t iStr, iterator_t iStrEnd) const
bounded1_4_p_t flight_number_p(uint1_4_p.derived(), 0u, 9999u)
storeDemandMean(DemandStruct &)
SEVMGR::SEVMGR_ServicePtr_T _sevmgrServicePtr
void operator()(double iReal) const
storeStayCode(DemandStruct &)
doEndDemand(SEVMGR::SEVMGR_ServicePtr_T, stdair::RandomGeneration &, const POSProbabilityMass_T &, DemandStruct &)
stdair::Duration_T _itPrefDepTime
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
stdair::AirportCode_T _itPosCode
stdair::DayDuration_T _itStayDuration
stdair::NonRefundableRatio_T _nonRefundableProb
repeat_p_t dow_p(chset_t("0-1").derived().derived(), 7, 7)
const POSProbabilityMass_T & _posProbabilityMass
storePrefCabin(DemandStruct &)
stdair::TripType_T _itTripCode
DemandFileParser(SEVMGR::SEVMGR_ServicePtr_T, stdair::RandomGeneration &, const POSProbabilityMass_T &, const stdair::Filename_T &iDemandInputFilename)
boost::spirit::classic::int_parser< unsigned int, 10, 1, 1 > int1_p_t
void operator()(double iReal) const
stdair::FrequentFlyer_T _itFFCode
stdair::AirportCode_T _destination
storePrefDepDateRangeEnd(DemandStruct &)
storeDTDProbMass(DemandStruct &)
void operator()(iterator_t iStr, iterator_t iStrEnd) const
ArrivalPatternCumulativeDistribution_T _dtdProbDist
stdair::Duration_T getTime() const
const POSProbabilityMass_T & _posProbabilityMass
POSProbabilityMass_T::ProbabilityMassFunction_T POSProbabilityMassFunction_T
bounded2_p_t month_p(uint2_p.derived(), 1u, 12u)
definition(DemandParser const &self)
ChannelProbabilityMass_T::ProbabilityMassFunction_T ChannelProbabilityMassFunction_T
void operator()(iterator_t iStr, iterator_t iStrEnd) const
bounded2_p_t minutes_p(uint2_p.derived(), 0u, 59u)
repeat_p_t airport_p(chset_t("0-9A-Z").derived(), 3, 3)
storeFFProbMass(DemandStruct &)
SEVMGR::SEVMGR_ServicePtr_T _sevmgrServicePtr
void operator()(unsigned int iInteger) const
stdair::ChannelLabel_T _itChannelCode
bounded1_3_p_t stay_duration_p(uint1_3_p.derived(), 0u, 999u)
chset_t cabin_code_p("A-Z")
boost::spirit::classic::rule< ScannerT > const & start() const
stdair::DayDuration_T _itDTD
storeDemandNonRefundableProb(DemandStruct &)
stdair::Date_T _prefDepDateStart
void operator()(double iReal) const
stdair::StdDevValue_T _demandStdDev
void operator()(double iReal) const
storeDemandNonRefundableDisutility(DemandStruct &)
boost::spirit::classic::uint_parser< unsigned int, 10, 2, 2 > uint2_p_t
storeTripCode(DemandStruct &)
void operator()(double iReal) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
stdair::ChangeFeesRatio_T _changeFeeProb
storePrefDepTimeProbMass(DemandStruct &)
void operator()(double iReal) const
storePosProbMass(DemandStruct &)
boost::spirit::classic::impl::loop_traits< chset_t, unsigned int, unsigned int >::type repeat_p_t
ChannelProbabilityMassFunction_T _channelProbDist
storeTripProbMass(DemandStruct &)
bounded4_p_t year_p(uint4_p.derived(), 2000u, 2099u)
void operator()(double iReal) const
PreferredDepartureTimeCumulativeDistribution_T::ContinuousDistribution_T PreferredDepartureTimeContinuousDistribution_T
stdair::PriceValue_T _itTimeValue
TripTypeProbabilityMass_T::ProbabilityMassFunction_T TripTypeProbabilityMassFunction_T
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
StayDurationProbabilityMass_T::ProbabilityMassFunction_T StayDurationProbabilityMassFunction_T
bounded2_p_t seconds_p(uint2_p.derived(), 0u, 59u)
storeDestination(DemandStruct &)
TripTypeProbabilityMassFunction_T _tripProbDist
ParserSemanticAction(DemandStruct &)
storeChannelProbMass(DemandStruct &)
storeDemandChangeFeeDisutility(DemandStruct &)
POSProbabilityMassFunction_T _posProbDist
stdair::Date_T getDate() const
void operator()(double iReal) const
boost::spirit::classic::uint_parser< unsigned int, 10, 1, 2 > uint1_2_p_t
FrequentFlyerProbabilityMassFunction_T _ffProbDist
boost::spirit::classic::chset< char_t > chset_t
void operator()(double iReal) const
stdair::Disutility_T _nonRefundableDisutility
boost::spirit::classic::bounded< uint2_p_t, unsigned int > bounded2_p_t
boost::spirit::classic::bounded< uint1_2_p_t, unsigned int > bounded1_2_p_t
ContinuousFloatDuration_T::ContinuousDistribution_T ArrivalPatternCumulativeDistribution_T
storeStayProbMass(DemandStruct &)
storeFFCode(DemandStruct &)
stdair::CabinCode_T _prefCabin