7 #include <stdair/basic/RandomGeneration.hpp>
8 #include <stdair/basic/BasFileMgr.hpp>
9 #include <stdair/bom/EventQueue.hpp>
10 #include <stdair/service/Logger.hpp>
17 namespace bsc = boost::spirit::classic;
21 namespace DemandParserHelper {
28 : _demand (ioDemand) {
58 const stdair::DateOffset_T oneDay (1);
77 stdair::DOW_String_T lDow (iStr, iStrEnd);
88 stdair::AirportCode_T lOrigin (iStr, iStrEnd);
100 stdair::AirportCode_T lDestination (iStr, iStrEnd);
112 stdair::CabinCode_T lPrefCabin (iStr, iStrEnd);
146 const stdair::AirportCode_T lPosCode (iStr, iStrEnd);
158 const bool hasInsertBeenSuccessfull =
162 if (hasInsertBeenSuccessfull ==
false) {
164 <<
"') has probably been given twice");
165 throw stdair::CodeDuplicationException (
"The same POS code ('"
167 +
"') has probably been given twice");
192 const bool hasInsertBeenSuccessfull =
196 if (hasInsertBeenSuccessfull ==
false) {
197 STDAIR_LOG_ERROR (
"The same channel type code ('"
199 <<
"') has probably been given twice");
200 throw stdair::CodeDuplicationException (
"The same channel type code ('"
202 +
"') has probably been given twice");
227 const bool hasInsertBeenSuccessfull =
231 if (hasInsertBeenSuccessfull ==
false) {
232 STDAIR_LOG_ERROR (
"The same trip type code ('"
234 <<
"') has probably been given twice");
235 throw stdair::CodeDuplicationException (
"The same trip type code ('"
237 +
"') has probably been given twice");
250 const stdair::DayDuration_T lStayDuration (iInteger);
262 const bool hasInsertBeenSuccessfull =
266 if (hasInsertBeenSuccessfull ==
false) {
267 std::ostringstream oStr;
269 <<
"') has probably been given twice";
270 STDAIR_LOG_ERROR (oStr.str());
271 throw stdair::CodeDuplicationException (oStr.str());
295 const bool hasInsertBeenSuccessfull =
299 if (hasInsertBeenSuccessfull ==
false) {
300 STDAIR_LOG_ERROR (
"The same Frequent Flyer code ('"
302 <<
"') has probably been given twice");
303 throw stdair::CodeDuplicationException(
"The same Frequent Flyer code ('"
305 +
"') has probably been given twice");
338 const stdair::IntDuration_T lIntDuration =
343 value_type (lIntDuration, iReal));
389 const stdair::DayDuration_T lDTD (iInteger);
401 const stdair::FloatDuration_T lZeroDTDFloat = 0.0;
402 stdair::FloatDuration_T lDTDFloat =
404 lDTDFloat = lZeroDTDFloat - lDTDFloat;
407 value_type (lDTDFloat, iReal));
413 stdair::RandomGeneration& ioSharedGenerator,
417 _uniformGenerator (ioSharedGenerator),
418 _posProbabilityMass (iPOSProbMass) {
522 stdair::RandomGeneration& ioSharedGenerator,
525 : _eventQueue (ioEventQueue), _uniformGenerator (ioSharedGenerator),
526 _posProbabilityMass (iPOSProbMass), _demand (ioDemand) {
530 template<
typename ScannerT>
534 demand_list = *( not_to_be_parsed |
538 not_to_be_parsed = bsc::
539 lexeme_d[bsc::comment_p(
"//")
540 | bsc::comment_p(
"/*",
"*/")
546 >>
';' >> origin >>
';' >> destination
549 >>
';' >> channel_dist
553 >>
';' >> pref_dep_time_dist
555 >>
';' >> time_value_dist
557 >>
';' >> demand_params
558 >> demand_end[
doEndDemand (
self._eventQueue,
self._uniformGenerator,
559 self._posProbabilityMass,
self._demand)]
562 demand_end = bsc::ch_p(
';')
567 >>
';' >> dow[
storeDow(
self._demand)]
571 bsc::lexeme_d[(
year_p)[bsc::assign_a(
self._demand._itYear)]
572 >>
'-' >> (
month_p)[bsc::assign_a(
self._demand._itMonth)]
573 >>
'-' >> (
day_p)[bsc::assign_a(
self._demand._itDay)]
577 dow = bsc::lexeme_d[
dow_p ]
591 pos_pair >> *(
',' >> pos_pair )
601 | bsc::chseq_p(
"row")
609 channel_pair >> *(
',' >> channel_pair )
614 >>
':' >> channel_share
618 bsc::chseq_p(
"DF") | bsc::chseq_p(
"DN")
619 | bsc::chseq_p(
"IF") | bsc::chseq_p(
"IN")
627 trip_pair >> *(
',' >> trip_pair )
636 bsc::chseq_p(
"RO") | bsc::chseq_p(
"RI") | bsc::chseq_p(
"OW")
644 stay_pair >> *(
',' >> stay_pair )
657 ff_pair >> *(
',' >> ff_pair )
672 pref_dep_time_pair >> *(
',' >> pref_dep_time_pair )
677 >>
':' >> pref_dep_time_share
680 pref_dep_time_share =
686 (
hours_p)[bsc::assign_a(
self._demand._itHours)]
687 >> !(
'.' >> (
minutes_p)[bsc::assign_a(
self._demand._itMinutes)])
688 >> !(
'.' >> (
seconds_p)[bsc::assign_a(
self._demand._itSeconds)])
693 (bsc::ureal_p)[
storeWTP(
self._demand)]
697 time_value_pair >> *(
',' >> time_value_pair )
702 >>
':' >> time_value_share
710 dtd_pair >> *(
',' >> dtd_pair )
714 (bsc::ureal_p)[
storeDTD(
self._demand)]
731 BOOST_SPIRIT_DEBUG_NODE (demand_list);
732 BOOST_SPIRIT_DEBUG_NODE (not_to_be_parsed);
733 BOOST_SPIRIT_DEBUG_NODE (demand);
734 BOOST_SPIRIT_DEBUG_NODE (demand_end);
735 BOOST_SPIRIT_DEBUG_NODE (pref_dep_date);
736 BOOST_SPIRIT_DEBUG_NODE (date);
737 BOOST_SPIRIT_DEBUG_NODE (origin);
738 BOOST_SPIRIT_DEBUG_NODE (destination);
739 BOOST_SPIRIT_DEBUG_NODE (pref_cabin);
740 BOOST_SPIRIT_DEBUG_NODE (pos_dist);
741 BOOST_SPIRIT_DEBUG_NODE (pos_pair);
742 BOOST_SPIRIT_DEBUG_NODE (pos_code);
743 BOOST_SPIRIT_DEBUG_NODE (pos_share);
744 BOOST_SPIRIT_DEBUG_NODE (channel_dist);
745 BOOST_SPIRIT_DEBUG_NODE (channel_pair);
746 BOOST_SPIRIT_DEBUG_NODE (channel_code);
747 BOOST_SPIRIT_DEBUG_NODE (channel_share);
748 BOOST_SPIRIT_DEBUG_NODE (trip_dist);
749 BOOST_SPIRIT_DEBUG_NODE (trip_pair);
750 BOOST_SPIRIT_DEBUG_NODE (trip_code);
751 BOOST_SPIRIT_DEBUG_NODE (trip_share);
752 BOOST_SPIRIT_DEBUG_NODE (stay_dist);
753 BOOST_SPIRIT_DEBUG_NODE (stay_pair);
754 BOOST_SPIRIT_DEBUG_NODE (stay_share);
755 BOOST_SPIRIT_DEBUG_NODE (ff_dist);
756 BOOST_SPIRIT_DEBUG_NODE (ff_pair);
757 BOOST_SPIRIT_DEBUG_NODE (ff_code);
758 BOOST_SPIRIT_DEBUG_NODE (ff_share);
759 BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_dist);
760 BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_pair);
761 BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_share);
762 BOOST_SPIRIT_DEBUG_NODE (time);
763 BOOST_SPIRIT_DEBUG_NODE (wtp);
764 BOOST_SPIRIT_DEBUG_NODE (time_value_dist);
765 BOOST_SPIRIT_DEBUG_NODE (time_value_pair);
766 BOOST_SPIRIT_DEBUG_NODE (time_value_share);
767 BOOST_SPIRIT_DEBUG_NODE (dtd_dist);
768 BOOST_SPIRIT_DEBUG_NODE (dtd_pair);
769 BOOST_SPIRIT_DEBUG_NODE (dtd_share);
770 BOOST_SPIRIT_DEBUG_NODE (demand_params);
774 template<
typename ScannerT>
775 bsc::rule<ScannerT>
const&
792 stdair::RandomGeneration& ioSharedGenerator,
794 const std::string& iFilename)
795 : _filename (iFilename), _eventQueue (ioEventQueue),
796 _uniformGenerator (ioSharedGenerator),
797 _posProbabilityMass (iPOSProbMass) {
802 void DemandFileParser::init() {
804 const bool doesExistAndIsReadable =
805 stdair::BasFileMgr::doesExistAndIsReadable (_filename);
807 if (doesExistAndIsReadable ==
false) {
808 STDAIR_LOG_ERROR (
"The demand file " << _filename
809 <<
" does not exist or can not be read.");
812 +
" does not exist or can not "
820 if (!_startIterator) {
821 STDAIR_LOG_ERROR (
"The demand file " << _filename <<
" can not be open.");
823 throw DemandInputFileNotFoundException (
"The demand file " + _filename
824 +
" does not exist or can not "
829 _endIterator = _startIterator.make_end();
834 bool oResult =
false;
836 STDAIR_LOG_DEBUG (
"Parsing demand input file: " << _filename);
847 bsc::parse_info<iterator_t> info =
848 bsc::parse (_startIterator, _endIterator, lDemandParser,
849 bsc::space_p - bsc::eol_p);
854 const std::string hasBeenFullyReadStr = (info.full ==
true)?
"":
"not ";
855 if (oResult ==
true) {
856 STDAIR_LOG_DEBUG (
"Parsing of demand input file: " << _filename
857 <<
" succeeded: read " << info.length
858 <<
" characters. The input file has "
859 << hasBeenFullyReadStr
860 <<
"been fully read. Stop point: " << info.stop);
863 std::ostringstream oStr;
864 oStr <<
"Parsing of demand input file: " << _filename <<
" failed: read "
865 << info.length <<
" characters. The input file has "
866 << hasBeenFullyReadStr <<
"been fully read. Stop point: "
868 STDAIR_LOG_ERROR (oStr.str());
869 throw stdair::ParserException (oStr.str());