$treeview $search $mathjax
TraDemGen Logo  1.00.0
$projectbrief
$projectbrief
$searchbox

DemandParserHelper.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // StdAir
00007 #include <stdair/basic/RandomGeneration.hpp>
00008 #include <stdair/basic/BasFileMgr.hpp>
00009 #include <stdair/service/Logger.hpp>
00010 // TraDemGen
00011 #include <trademgen/basic/DemandCharacteristicsTypes.hpp>
00012 //#define BOOST_SPIRIT_DEBUG
00013 #include <trademgen/command/DemandParserHelper.hpp>
00014 #include <trademgen/command/DemandManager.hpp>
00015 
00016 namespace bsc = boost::spirit::classic;
00017 
00018 namespace TRADEMGEN {
00019 
00020   namespace DemandParserHelper {
00021       
00022     // //////////////////////////////////////////////////////////////////
00023     //  Semantic actions
00024     // //////////////////////////////////////////////////////////////////
00025 
00026     ParserSemanticAction::ParserSemanticAction (DemandStruct& ioDemand)
00027       : _demand (ioDemand) {
00028     } 
00029 
00030     // //////////////////////////////////////////////////////////////////
00031     storePrefDepDateRangeStart::
00032     storePrefDepDateRangeStart (DemandStruct& ioDemand)
00033       : ParserSemanticAction (ioDemand) {
00034     }
00035     
00036     // //////////////////////////////////////////////////////////////////
00037     void storePrefDepDateRangeStart::operator() (iterator_t iStr,
00038                                           iterator_t iStrEnd) const {
00039       _demand._prefDepDateStart = _demand.getDate();
00040         
00041       // Reset the number of seconds
00042       _demand._itSeconds = 0;
00043     }
00044       
00045     // //////////////////////////////////////////////////////////////////
00046     storePrefDepDateRangeEnd::
00047     storePrefDepDateRangeEnd (DemandStruct& ioDemand)
00048       : ParserSemanticAction (ioDemand) {
00049     }
00050     
00051     // //////////////////////////////////////////////////////////////////
00052     void storePrefDepDateRangeEnd::operator() (iterator_t iStr,
00053                                         iterator_t iStrEnd) const {
00054       // As a Boost date period (DatePeriod_T) defines the last day of
00055       // the period to be end-date - one day, we have to add one day to that
00056       // end date before.
00057       const stdair::DateOffset_T oneDay (1);
00058       _demand._prefDepDateEnd = _demand.getDate() + oneDay;
00059 
00060       // Transform the date pair (i.e., the date range) into a date period
00061       _demand._dateRange =
00062         stdair::DatePeriod_T (_demand._prefDepDateStart,
00063                               _demand._prefDepDateEnd);
00064         
00065       // Reset the number of seconds
00066       _demand._itSeconds = 0;
00067     }
00068 
00069     // //////////////////////////////////////////////////////////////////
00070     storeDow::storeDow (DemandStruct& ioDemand)
00071       : ParserSemanticAction (ioDemand) {
00072     }
00073 
00074     // //////////////////////////////////////////////////////////////////
00075     void storeDow::operator() (iterator_t iStr, iterator_t iStrEnd) const {
00076       stdair::DOW_String_T lDow (iStr, iStrEnd);
00077       _demand._dow = lDow;
00078     }     
00079       
00080     // //////////////////////////////////////////////////////////////////
00081     storeOrigin::storeOrigin (DemandStruct& ioDemand)
00082       : ParserSemanticAction (ioDemand) {
00083     }
00084 
00085     // //////////////////////////////////////////////////////////////////
00086     void storeOrigin::operator() (iterator_t iStr, iterator_t iStrEnd) const {
00087       stdair::AirportCode_T lOrigin (iStr, iStrEnd);
00088       _demand._origin = lOrigin;
00089     }
00090 
00091     // //////////////////////////////////////////////////////////////////
00092     storeDestination::storeDestination (DemandStruct& ioDemand)
00093       : ParserSemanticAction (ioDemand) {
00094     }
00095 
00096     // //////////////////////////////////////////////////////////////////
00097     void storeDestination::operator() (iterator_t iStr,
00098                                        iterator_t iStrEnd) const {
00099       stdair::AirportCode_T lDestination (iStr, iStrEnd);
00100       _demand._destination = lDestination;
00101     }
00102 
00103     // //////////////////////////////////////////////////////////////////
00104     storePrefCabin::storePrefCabin (DemandStruct& ioDemand)
00105       : ParserSemanticAction (ioDemand) {
00106     }
00107     
00108     // //////////////////////////////////////////////////////////////////
00109     void storePrefCabin::operator() (iterator_t iStr,
00110                                      iterator_t iStrEnd) const {
00111       stdair::CabinCode_T lPrefCabin  (iStr, iStrEnd);
00112       _demand._prefCabin = lPrefCabin; 
00113       //STDAIR_LOG_DEBUG ("Preferred cabin: " << lPrefCabin);
00114     }
00115     
00116     // //////////////////////////////////////////////////////////////////
00117     storeDemandMean::storeDemandMean (DemandStruct& ioDemand)
00118       : ParserSemanticAction (ioDemand) {
00119     }
00120     
00121     // //////////////////////////////////////////////////////////////////
00122     void storeDemandMean::operator() (double iReal) const { 
00123       _demand._demandMean = iReal; 
00124       //STDAIR_LOG_DEBUG ("Demand mean: " << iReal);
00125     }
00126 
00127     // //////////////////////////////////////////////////////////////////
00128     storeDemandStdDev::storeDemandStdDev (DemandStruct& ioDemand)
00129       : ParserSemanticAction (ioDemand) {
00130     }
00131     
00132     // //////////////////////////////////////////////////////////////////
00133     void storeDemandStdDev::operator() (double iReal) const { 
00134       _demand._demandStdDev = iReal; 
00135       //STDAIR_LOG_DEBUG ("Demand stddev: " << iReal);
00136     }
00137 
00138     // //////////////////////////////////////////////////////////////////
00139     storeDemandChangeFeeProb::storeDemandChangeFeeProb (DemandStruct& ioDemand)
00140       : ParserSemanticAction (ioDemand) {
00141     }
00142     
00143     // //////////////////////////////////////////////////////////////////
00144     void storeDemandChangeFeeProb::operator() (double iReal) const { 
00145       _demand._changeFeeProb = iReal; 
00146       //STDAIR_LOG_DEBUG ("Demand change fee prob: " << iReal);
00147     }
00148 
00149     // //////////////////////////////////////////////////////////////////
00150     storeDemandChangeFeeDisutility::storeDemandChangeFeeDisutility (DemandStruct& ioDemand)
00151       : ParserSemanticAction (ioDemand) {
00152     }
00153     
00154     // //////////////////////////////////////////////////////////////////
00155     void storeDemandChangeFeeDisutility::operator() (double iReal) const { 
00156       _demand._changeFeeDisutility = iReal; 
00157       //STDAIR_LOG_DEBUG ("Demand change fee disutility: " << iReal);
00158     }
00159 
00160     // //////////////////////////////////////////////////////////////////
00161     storeDemandNonRefundableProb::
00162     storeDemandNonRefundableProb (DemandStruct& ioDemand)
00163       : ParserSemanticAction (ioDemand) {
00164     }
00165     
00166     // //////////////////////////////////////////////////////////////////
00167     void storeDemandNonRefundableProb::operator() (double iReal) const { 
00168       _demand._nonRefundableProb = iReal; 
00169       //STDAIR_LOG_DEBUG ("Demand non refundable prob: " << iReal);
00170     }
00171 
00172     // //////////////////////////////////////////////////////////////////
00173     storeDemandNonRefundableDisutility::
00174     storeDemandNonRefundableDisutility (DemandStruct& ioDemand)
00175       : ParserSemanticAction (ioDemand) {
00176     }
00177     
00178     // //////////////////////////////////////////////////////////////////
00179     void storeDemandNonRefundableDisutility::operator() (double iReal) const { 
00180       _demand._nonRefundableDisutility = iReal; 
00181       //STDAIR_LOG_DEBUG ("Demand non refundable disutility: " << iReal);
00182     }
00183 
00184     // //////////////////////////////////////////////////////////////////
00185     storePosCode::storePosCode (DemandStruct& ioDemand)
00186       : ParserSemanticAction (ioDemand) {
00187     }
00188     
00189     // //////////////////////////////////////////////////////////////////
00190     void storePosCode::operator() (iterator_t iStr, iterator_t iStrEnd) const {
00191       const stdair::AirportCode_T lPosCode (iStr, iStrEnd);
00192       _demand._itPosCode = lPosCode;
00193       //STDAIR_LOG_DEBUG ("Pos code: " << lPosCode);
00194     }
00195 
00196     // //////////////////////////////////////////////////////////////////
00197     storePosProbMass::storePosProbMass (DemandStruct& ioDemand)
00198       : ParserSemanticAction (ioDemand) {
00199     }
00200     
00201     // //////////////////////////////////////////////////////////////////
00202     void storePosProbMass::operator() (double iReal) const {
00203       const bool hasInsertBeenSuccessfull = 
00204         _demand._posProbDist.
00205         insert (POSProbabilityMassFunction_T::
00206                 value_type (_demand._itPosCode, iReal)).second;
00207       if (hasInsertBeenSuccessfull == false) {
00208         STDAIR_LOG_ERROR ("The same POS code ('" << _demand._itPosCode
00209                           << "') has probably been given twice");
00210         throw stdair::CodeDuplicationException ("The same POS code ('"
00211                                                 + _demand._itPosCode
00212                                                 + "') has probably been given twice");
00213       }
00214       
00215       //STDAIR_LOG_DEBUG ("PosProbMass: " << iReal);
00216     }
00217 
00218     // //////////////////////////////////////////////////////////////////
00219     storeChannelCode::storeChannelCode (DemandStruct& ioDemand)
00220       : ParserSemanticAction (ioDemand) {
00221     }
00222     
00223     // //////////////////////////////////////////////////////////////////
00224     void storeChannelCode::operator() (iterator_t iStr,
00225                                        iterator_t iStrEnd) const {
00226       _demand._itChannelCode = std::string (iStr, iStrEnd);
00227       //STDAIR_LOG_DEBUG ("Channel code: " << _demand._itChannelCode);
00228     }
00229 
00230     // //////////////////////////////////////////////////////////////////
00231     storeChannelProbMass::storeChannelProbMass (DemandStruct& ioDemand)
00232       : ParserSemanticAction (ioDemand) {
00233     }
00234     
00235     // //////////////////////////////////////////////////////////////////
00236     void storeChannelProbMass::operator() (double iReal) const {
00237       const bool hasInsertBeenSuccessfull = 
00238         _demand._channelProbDist.
00239         insert (ChannelProbabilityMassFunction_T::
00240                 value_type (_demand._itChannelCode, iReal)).second;
00241       if (hasInsertBeenSuccessfull == false) {
00242         STDAIR_LOG_ERROR ("The same channel type code ('"
00243                           << _demand._itChannelCode
00244                           << "') has probably been given twice");
00245         throw stdair::CodeDuplicationException ("The same channel type code ('"
00246                                                 + _demand._itChannelCode
00247                                                 + "') has probably been given twice");
00248       }
00249       
00250       //STDAIR_LOG_DEBUG ("ChannelProbMass: " << iReal);
00251     }
00252 
00253     // //////////////////////////////////////////////////////////////////
00254     storeTripCode::storeTripCode (DemandStruct& ioDemand)
00255       : ParserSemanticAction (ioDemand) {
00256     }
00257     
00258     // //////////////////////////////////////////////////////////////////
00259     void storeTripCode::operator() (iterator_t iStr,
00260                                        iterator_t iStrEnd) const {
00261       _demand._itTripCode = std::string (iStr, iStrEnd);
00262       //STDAIR_LOG_DEBUG ("Trip code: " << _demand._itTripCode);
00263     }
00264 
00265     // //////////////////////////////////////////////////////////////////
00266     storeTripProbMass::storeTripProbMass (DemandStruct& ioDemand)
00267       : ParserSemanticAction (ioDemand) {
00268     }
00269     
00270     // //////////////////////////////////////////////////////////////////
00271     void storeTripProbMass::operator() (double iReal) const {
00272       const bool hasInsertBeenSuccessfull = 
00273         _demand._tripProbDist.
00274         insert (TripTypeProbabilityMassFunction_T::
00275                 value_type (_demand._itTripCode, iReal)).second;
00276       if (hasInsertBeenSuccessfull == false) {
00277         STDAIR_LOG_ERROR ("The same trip type code ('"
00278                           << _demand._itTripCode
00279                           << "') has probably been given twice");
00280         throw stdair::CodeDuplicationException ("The same trip type code ('"
00281                                                 + _demand._itTripCode
00282                                                 + "') has probably been given twice");
00283       }
00284       
00285       //STDAIR_LOG_DEBUG ("TripProbMass: " << iReal);
00286     }
00287 
00288     // //////////////////////////////////////////////////////////////////
00289     storeStayCode::storeStayCode (DemandStruct& ioDemand)
00290       : ParserSemanticAction (ioDemand) {
00291     }
00292     
00293     // //////////////////////////////////////////////////////////////////
00294     void storeStayCode::operator() (unsigned int iInteger) const {
00295       const stdair::DayDuration_T lStayDuration (iInteger);
00296       _demand._itStayDuration = lStayDuration;
00297       // STDAIR_LOG_DEBUG ("Stay duration: " << lStayDuration);
00298     }
00299 
00300     // //////////////////////////////////////////////////////////////////
00301     storeStayProbMass::storeStayProbMass (DemandStruct& ioDemand)
00302       : ParserSemanticAction (ioDemand) {
00303     }
00304     
00305     // //////////////////////////////////////////////////////////////////
00306     void storeStayProbMass::operator() (double iReal) const {
00307       const bool hasInsertBeenSuccessfull = 
00308         _demand._stayProbDist.
00309         insert (StayDurationProbabilityMassFunction_T::
00310                 value_type (_demand._itStayDuration, iReal)).second;
00311       if (hasInsertBeenSuccessfull == false) {
00312         std::ostringstream oStr;
00313         oStr << "The same stay duration ('" << _demand._itStayDuration
00314              << "') has probably been given twice";
00315         STDAIR_LOG_ERROR (oStr.str());
00316         throw stdair::CodeDuplicationException (oStr.str());
00317       }
00318       
00319       // STDAIR_LOG_DEBUG ("StayProbMass: " << iReal);
00320     }
00321 
00322     // //////////////////////////////////////////////////////////////////
00323     storeFFCode::storeFFCode (DemandStruct& ioDemand)
00324       : ParserSemanticAction (ioDemand) {
00325     }
00326     
00327     // //////////////////////////////////////////////////////////////////
00328     void storeFFCode::operator() (iterator_t iStr, iterator_t iStrEnd) const {
00329       _demand._itFFCode = std::string (iStr, iStrEnd);
00330       //STDAIR_LOG_DEBUG ("FF code: " << _demand._itFFCode);
00331     }
00332 
00333     // //////////////////////////////////////////////////////////////////
00334     storeFFProbMass::storeFFProbMass (DemandStruct& ioDemand)
00335       : ParserSemanticAction (ioDemand) {
00336     }
00337     
00338     // //////////////////////////////////////////////////////////////////
00339     void storeFFProbMass::operator() (double iReal) const {
00340       const bool hasInsertBeenSuccessfull = 
00341         _demand._ffProbDist.
00342         insert (FrequentFlyerProbabilityMassFunction_T::
00343                 value_type (_demand._itFFCode, iReal)).second;
00344       if (hasInsertBeenSuccessfull == false) {
00345         STDAIR_LOG_ERROR ("The same Frequent Flyer code ('"
00346                           << _demand._itFFCode
00347                           << "') has probably been given twice");
00348         throw stdair::CodeDuplicationException("The same Frequent Flyer code ('"
00349                                                + _demand._itFFCode
00350                                                + "') has probably been given twice");
00351       }
00352       
00353       //STDAIR_LOG_DEBUG ("FfProbMass: " << iReal);
00354     }
00355 
00356     // //////////////////////////////////////////////////////////////////
00357     storePrefDepTime::storePrefDepTime (DemandStruct& ioDemand)
00358       : ParserSemanticAction (ioDemand) {
00359     }
00360     
00361     // //////////////////////////////////////////////////////////////////
00362     void storePrefDepTime::operator() (iterator_t iStr,
00363                                        iterator_t iStrEnd) const {
00364       _demand._itPrefDepTime = _demand.getTime();
00365         
00366       // DEBUG
00367       // STDAIR_LOG_DEBUG ("Pref dep time: " << _demand._itHours << ":"
00368       //                   << _demand._itMinutes << ":" << _demand._itSeconds
00369       //                   << " ==> " << _demand._itPrefDepTime);
00370       
00371       // Reset the number of minutes and seconds
00372       _demand._itMinutes = 0;
00373       _demand._itSeconds = 0;
00374     }
00375 
00376     // //////////////////////////////////////////////////////////////////
00377     storePrefDepTimeProbMass::storePrefDepTimeProbMass (DemandStruct& ioDemand)
00378       : ParserSemanticAction (ioDemand) {
00379     }
00380     
00381     // //////////////////////////////////////////////////////////////////
00382     void storePrefDepTimeProbMass::operator() (double iReal) const {
00383       const stdair::IntDuration_T lIntDuration =
00384         _demand._itPrefDepTime.total_seconds();
00385       
00386       _demand._prefDepTimeProbDist.
00387         insert (PreferredDepartureTimeContinuousDistribution_T::
00388                 value_type (lIntDuration, iReal));
00389       //STDAIR_LOG_DEBUG ("PrefDepTimeProbMass: " << iReal);
00390     }
00391 
00392     // //////////////////////////////////////////////////////////////////
00393     storeWTP::storeWTP (DemandStruct& ioDemand)
00394       : ParserSemanticAction (ioDemand) {
00395     }
00396     
00397     // //////////////////////////////////////////////////////////////////
00398     void storeWTP::operator() (double iReal) const {
00399       _demand._minWTP = iReal;
00400       //STDAIR_LOG_DEBUG ("WTP: " << iReal);
00401     }
00402 
00403     // //////////////////////////////////////////////////////////////////
00404     storeTimeValue::storeTimeValue (DemandStruct& ioDemand)
00405       : ParserSemanticAction (ioDemand) {
00406     }
00407     
00408     // //////////////////////////////////////////////////////////////////
00409     void storeTimeValue::operator() (double iReal) const {
00410       _demand._itTimeValue = iReal;
00411       //STDAIR_LOG_DEBUG ("Time value: " << iReal);
00412     }
00413 
00414     // //////////////////////////////////////////////////////////////////
00415     storeTimeValueProbMass::storeTimeValueProbMass (DemandStruct& ioDemand)
00416       : ParserSemanticAction (ioDemand) {
00417     }
00418     
00419     // //////////////////////////////////////////////////////////////////
00420     void storeTimeValueProbMass::operator() (double iReal) const {
00421       _demand._timeValueProbDist.
00422         insert (ValueOfTimeContinuousDistribution_T::
00423                 value_type (_demand._itTimeValue, iReal));
00424       //STDAIR_LOG_DEBUG ("TimeValueProbMass: " << iReal);
00425     }
00426 
00427     // //////////////////////////////////////////////////////////////////
00428     storeDTD::storeDTD (DemandStruct& ioDemand)
00429       : ParserSemanticAction (ioDemand) {
00430     }
00431     
00432     // //////////////////////////////////////////////////////////////////
00433     void storeDTD::operator() (unsigned int iInteger) const {
00434       const stdair::DayDuration_T lDTD (iInteger);
00435       _demand._itDTD = lDTD;
00436       //STDAIR_LOG_DEBUG ("DTD: " << lDTD);
00437     }
00438 
00439     // //////////////////////////////////////////////////////////////////
00440     storeDTDProbMass::storeDTDProbMass (DemandStruct& ioDemand)
00441       : ParserSemanticAction (ioDemand) {
00442     }
00443     
00444     // //////////////////////////////////////////////////////////////////
00445     void storeDTDProbMass::operator() (double iReal) const {
00446       const stdair::FloatDuration_T lZeroDTDFloat = 0.0;
00447       stdair::FloatDuration_T lDTDFloat =
00448         static_cast<stdair::FloatDuration_T> (_demand._itDTD);
00449       lDTDFloat = lZeroDTDFloat - lDTDFloat;
00450 
00451       _demand._dtdProbDist.insert (ArrivalPatternCumulativeDistribution_T::
00452                                    value_type (lDTDFloat, iReal));
00453       //STDAIR_LOG_DEBUG ("DTDProbMass: " << iReal);
00454     }
00455 
00456     // //////////////////////////////////////////////////////////////////
00457     doEndDemand::doEndDemand (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
00458                               stdair::RandomGeneration& ioSharedGenerator,
00459                               const POSProbabilityMass_T& iPOSProbMass,
00460                               DemandStruct& ioDemand)
00461       : ParserSemanticAction (ioDemand),
00462         _sevmgrServicePtr (ioSEVMGR_ServicePtr),
00463         _uniformGenerator (ioSharedGenerator),
00464         _posProbabilityMass (iPOSProbMass) {
00465     }
00466     
00467     // //////////////////////////////////////////////////////////////////
00468     // void doEndDemand::operator() (char iChar) const {
00469     void doEndDemand::operator() (iterator_t iStr, iterator_t iStrEnd) const {
00470         
00471       // DEBUG: Display the result
00472       // STDAIR_LOG_DEBUG ("Demand: " << _demand.describe());
00473 
00474       // Create the Demand BOM objects
00475       DemandManager::createDemandCharacteristics (_sevmgrServicePtr,
00476                                                   _uniformGenerator,
00477                                                   _posProbabilityMass, _demand);
00478                                  
00479       // Clean the lists
00480       _demand._posProbDist.clear();
00481       _demand._channelProbDist.clear();
00482       _demand._tripProbDist.clear();
00483       _demand._stayProbDist.clear();
00484       _demand._ffProbDist.clear();
00485       _demand._prefDepTimeProbDist.clear(); 
00486       _demand._timeValueProbDist.clear();
00487       _demand._dtdProbDist.clear();
00488     }
00489 
00490       
00491     // ///////////////////////////////////////////////////////////////////
00492     //
00493     //  Utility Parsers
00494     //
00495     // ///////////////////////////////////////////////////////////////////
00497     int1_p_t int1_p;
00498     
00500     uint2_p_t uint2_p;
00501     
00503     uint1_2_p_t uint1_2_p;
00504 
00506     uint1_3_p_t uint1_3_p;
00507 
00509     uint4_p_t uint4_p;
00510     
00512     uint1_4_p_t uint1_4_p;
00513 
00515     repeat_p_t airline_code_p (chset_t("0-9A-Z").derived(), 2, 3);
00516       
00518     bounded1_4_p_t flight_number_p (uint1_4_p.derived(), 0u, 9999u);
00519 
00521     bounded4_p_t year_p (uint4_p.derived(), 2000u, 2099u);
00522       
00524     bounded2_p_t month_p (uint2_p.derived(), 1u, 12u);
00525 
00527     bounded2_p_t day_p (uint2_p.derived(), 1u, 31u);
00528      
00530     repeat_p_t dow_p (chset_t("0-1").derived().derived(), 7, 7);
00531 
00533     repeat_p_t airport_p (chset_t("0-9A-Z").derived(), 3, 3);
00534       
00536     bounded1_2_p_t hours_p (uint1_2_p.derived(), 0u, 23u);
00537 
00539     bounded2_p_t minutes_p (uint2_p.derived(), 0u, 59u);
00540 
00542     bounded2_p_t seconds_p (uint2_p.derived(), 0u, 59u);
00543 
00545     chset_t cabin_code_p ("A-Z");
00546 
00548     chset_t passenger_type_p ("A-Z");
00549 
00551     chset_t ff_type_p ("A-Z");
00552 
00554     int1_p_t family_code_p;
00555       
00557     repeat_p_t class_code_list_p (chset_t("A-Z").derived(), 1, 26);
00558 
00560     bounded1_3_p_t stay_duration_p (uint1_3_p.derived(), 0u, 999u);
00561 
00562 
00563     // //////////////////////////////////////////////////////////////////
00564     //  (Boost Spirit) Grammar Definition
00565     // //////////////////////////////////////////////////////////////////
00566 
00567     // //////////////////////////////////////////////////////////////////
00568     DemandParser::DemandParser (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
00569                                 stdair::RandomGeneration& ioSharedGenerator,
00570                                 const POSProbabilityMass_T& iPOSProbMass,
00571                                 DemandStruct& ioDemand) 
00572       : _sevmgrServicePtr (ioSEVMGR_ServicePtr),
00573         _uniformGenerator (ioSharedGenerator),
00574         _posProbabilityMass (iPOSProbMass), _demand (ioDemand) {
00575     }
00576 
00577     // //////////////////////////////////////////////////////////////////
00578     template<typename ScannerT>
00579     DemandParser::definition<ScannerT>::
00580     definition (DemandParser const& self) {
00581 
00582       demand_list = *( not_to_be_parsed |
00583                        demand)
00584         ;
00585 
00586      not_to_be_parsed = bsc::
00587        lexeme_d[bsc::comment_p("//")
00588                 | bsc::comment_p("/*", "*/")
00589                 | bsc::eol_p]
00590         ;
00591 
00592       demand =
00593         pref_dep_date_range
00594         >> ';' >> origin >> ';' >> destination
00595         >> ';' >> pref_cabin[storePrefCabin(self._demand)]
00596         >> ';' >> pos_dist
00597         >> ';' >> channel_dist
00598         >> ';' >> trip_dist
00599         >> ';' >> stay_dist
00600         >> ';' >> ff_dist
00601         >> ';' >> change_fees
00602         >> ';' >> non_refundable
00603         >> ';' >> pref_dep_time_dist
00604         >> ';' >> wtp
00605         >> ';' >> time_value_dist
00606         >> ';' >> dtd_dist
00607         >> ';' >> demand_params
00608         >> demand_end[doEndDemand (self._sevmgrServicePtr,
00609                                    self._uniformGenerator,
00610                                    self._posProbabilityMass, self._demand)]
00611         ;
00612 
00613       demand_end = bsc::ch_p(';')
00614         ;
00615       
00616       pref_dep_date_range = date[storePrefDepDateRangeStart(self._demand)]
00617         >> ';' >> date[storePrefDepDateRangeEnd(self._demand)]
00618         >> ';' >> dow[storeDow(self._demand)]
00619         ;
00620 
00621       date =
00622         bsc::lexeme_d[(year_p)[bsc::assign_a(self._demand._itYear)]
00623          >> '-' >> (month_p)[bsc::assign_a(self._demand._itMonth)]
00624          >> '-' >> (day_p)[bsc::assign_a(self._demand._itDay)]
00625          ]
00626         ;
00627 
00628       dow = bsc::lexeme_d[ dow_p ]
00629         ;
00630 
00631       origin =
00632         (airport_p)[storeOrigin(self._demand)]
00633         ;
00634 
00635       destination =
00636         (airport_p)[storeDestination(self._demand)]
00637         ;
00638 
00639       pref_cabin = cabin_code_p;
00640 
00641       pos_dist =
00642         pos_pair >> *( ',' >> pos_pair )
00643         ;
00644 
00645       pos_pair =
00646         pos_code[storePosCode(self._demand)]
00647         >> ':' >> pos_share
00648         ;
00649 
00650       pos_code =
00651         airport_p
00652         | bsc::chseq_p("row")
00653         ;
00654 
00655       pos_share =
00656         (bsc::ureal_p)[storePosProbMass(self._demand)]
00657         ;
00658 
00659       channel_dist =
00660         channel_pair >> *( ',' >> channel_pair )
00661         ;
00662 
00663       channel_pair =
00664         channel_code[storeChannelCode(self._demand)]
00665         >> ':' >> channel_share
00666         ;
00667 
00668       channel_code =
00669         bsc::chseq_p("DF") | bsc::chseq_p("DN")
00670         | bsc::chseq_p("IF") | bsc::chseq_p("IN")
00671         ;
00672 
00673       channel_share =
00674         (bsc::ureal_p)[storeChannelProbMass(self._demand)]
00675         ;
00676       
00677       trip_dist =
00678         trip_pair >> *( ',' >> trip_pair )
00679         ;
00680 
00681       trip_pair =
00682         trip_code[storeTripCode(self._demand)]
00683         >> ':' >> trip_share
00684         ;
00685 
00686       trip_code =
00687         bsc::chseq_p("RO") | bsc::chseq_p("RI") | bsc::chseq_p("OW")
00688         ;
00689 
00690       trip_share =
00691         (bsc::ureal_p)[storeTripProbMass(self._demand)]
00692         ;
00693       
00694       stay_dist =
00695         stay_pair >> *( ',' >> stay_pair )
00696         ;
00697 
00698       stay_pair =
00699         (stay_duration_p)[storeStayCode(self._demand)]
00700         >> ':' >> stay_share
00701         ;
00702 
00703       stay_share =
00704         (bsc::ureal_p)[storeStayProbMass(self._demand)]
00705         ;
00706 
00707       ff_dist =
00708         ff_pair >> *( ',' >> ff_pair )
00709         ;
00710 
00711       ff_pair =
00712         ff_code[storeFFCode(self._demand)]
00713         >> ':' >> ff_share
00714         ;
00715 
00716       ff_code = ff_type_p;
00717 
00718       ff_share =
00719         (bsc::ureal_p)[storeFFProbMass(self._demand)]
00720         ;
00721 
00722       change_fees =
00723         (bsc::ureal_p)[storeDemandChangeFeeProb(self._demand)]
00724         >> ';' >> (bsc::ureal_p)[storeDemandChangeFeeDisutility(self._demand)]
00725         ;
00726 
00727       non_refundable =
00728         (bsc::ureal_p)[storeDemandNonRefundableProb(self._demand)]
00729         >> ';' >> (bsc::ureal_p)[storeDemandNonRefundableDisutility(self._demand)]
00730         ;
00731       
00732       pref_dep_time_dist =
00733         pref_dep_time_pair >> *( ',' >> pref_dep_time_pair )
00734         ;
00735 
00736       pref_dep_time_pair =
00737         (time)[storePrefDepTime(self._demand)]
00738         >> ':' >> pref_dep_time_share
00739         ;
00740 
00741       pref_dep_time_share =
00742         (bsc::ureal_p)[storePrefDepTimeProbMass(self._demand)]
00743         ;
00744 
00745       time =
00746         bsc::lexeme_d[
00747        (hours_p)[bsc::assign_a(self._demand._itHours)]
00748        >> !('.' >> (minutes_p)[bsc::assign_a(self._demand._itMinutes)])
00749        >> !('.' >> (seconds_p)[bsc::assign_a(self._demand._itSeconds)])
00750        ]
00751         ;
00752 
00753       wtp =
00754         (bsc::ureal_p)[storeWTP(self._demand)]
00755         ;
00756 
00757       time_value_dist =
00758         time_value_pair >> *( ',' >> time_value_pair )
00759         ;
00760 
00761       time_value_pair =
00762         (bsc::ureal_p)[storeTimeValue(self._demand)]
00763         >> ':' >> time_value_share
00764         ;
00765 
00766       time_value_share =
00767         (bsc::ureal_p)[storeTimeValueProbMass(self._demand)]
00768         ;
00769 
00770       dtd_dist =
00771         dtd_pair >> *( ',' >> dtd_pair )
00772         ;
00773 
00774       dtd_pair =
00775         (bsc::ureal_p)[storeDTD(self._demand)]
00776         >> ':' >> dtd_share
00777         ;
00778 
00779       dtd_share =
00780         (bsc::ureal_p)[storeDTDProbMass(self._demand)]
00781         ;
00782 
00783       demand_params =
00784         bsc::ch_p('N')
00785         >> ','
00786         >> (bsc::ureal_p)[storeDemandMean(self._demand)]
00787         >> ','
00788         >> (bsc::ureal_p)[storeDemandStdDev(self._demand)]
00789         ;
00790       
00791       // BOOST_SPIRIT_DEBUG_NODE (DemandParser);
00792       BOOST_SPIRIT_DEBUG_NODE (demand_list);
00793       BOOST_SPIRIT_DEBUG_NODE (not_to_be_parsed);
00794       BOOST_SPIRIT_DEBUG_NODE (demand);
00795       BOOST_SPIRIT_DEBUG_NODE (demand_end);
00796       BOOST_SPIRIT_DEBUG_NODE (pref_dep_date);
00797       BOOST_SPIRIT_DEBUG_NODE (date);
00798       BOOST_SPIRIT_DEBUG_NODE (origin);
00799       BOOST_SPIRIT_DEBUG_NODE (destination);
00800       BOOST_SPIRIT_DEBUG_NODE (pref_cabin);
00801       BOOST_SPIRIT_DEBUG_NODE (pos_dist);
00802       BOOST_SPIRIT_DEBUG_NODE (pos_pair);
00803       BOOST_SPIRIT_DEBUG_NODE (pos_code);
00804       BOOST_SPIRIT_DEBUG_NODE (pos_share);
00805       BOOST_SPIRIT_DEBUG_NODE (channel_dist);
00806       BOOST_SPIRIT_DEBUG_NODE (channel_pair);
00807       BOOST_SPIRIT_DEBUG_NODE (channel_code);
00808       BOOST_SPIRIT_DEBUG_NODE (channel_share);
00809       BOOST_SPIRIT_DEBUG_NODE (trip_dist);
00810       BOOST_SPIRIT_DEBUG_NODE (trip_pair);
00811       BOOST_SPIRIT_DEBUG_NODE (trip_code);
00812       BOOST_SPIRIT_DEBUG_NODE (trip_share);
00813       BOOST_SPIRIT_DEBUG_NODE (stay_dist);
00814       BOOST_SPIRIT_DEBUG_NODE (stay_pair);
00815       BOOST_SPIRIT_DEBUG_NODE (stay_share);
00816       BOOST_SPIRIT_DEBUG_NODE (ff_dist);
00817       BOOST_SPIRIT_DEBUG_NODE (ff_pair);
00818       BOOST_SPIRIT_DEBUG_NODE (ff_code);
00819       BOOST_SPIRIT_DEBUG_NODE (ff_share);
00820       BOOST_SPIRIT_DEBUG_NODE (change_fees);
00821       BOOST_SPIRIT_DEBUG_NODE (non_refundable);
00822       BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_dist);
00823       BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_pair);
00824       BOOST_SPIRIT_DEBUG_NODE (pref_dep_time_share);
00825       BOOST_SPIRIT_DEBUG_NODE (time);
00826       BOOST_SPIRIT_DEBUG_NODE (wtp);
00827       BOOST_SPIRIT_DEBUG_NODE (time_value_dist);
00828       BOOST_SPIRIT_DEBUG_NODE (time_value_pair);
00829       BOOST_SPIRIT_DEBUG_NODE (time_value_share);
00830       BOOST_SPIRIT_DEBUG_NODE (dtd_dist);
00831       BOOST_SPIRIT_DEBUG_NODE (dtd_pair);
00832       BOOST_SPIRIT_DEBUG_NODE (dtd_share);
00833       BOOST_SPIRIT_DEBUG_NODE (demand_params);
00834     }
00835 
00836     // //////////////////////////////////////////////////////////////////
00837     template<typename ScannerT>
00838     bsc::rule<ScannerT> const&
00839     DemandParser::definition<ScannerT>::start() const {
00840       return demand_list;
00841     }
00842     
00843   }
00844 
00845 
00847   //
00848   //  Entry class for the file parser
00849   //
00851 
00852   // //////////////////////////////////////////////////////////////////////
00853   DemandFileParser::
00854   DemandFileParser (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
00855                     stdair::RandomGeneration& ioSharedGenerator,
00856                     const POSProbabilityMass_T& iPOSProbMass,
00857                     const std::string& iFilename)
00858     : _filename (iFilename),
00859       _sevmgrServicePtr (ioSEVMGR_ServicePtr),
00860       _uniformGenerator (ioSharedGenerator),
00861       _posProbabilityMass (iPOSProbMass) {
00862     init();
00863   }
00864 
00865   // //////////////////////////////////////////////////////////////////////
00866   void DemandFileParser::init() {
00867     // Check that the file exists and is readable
00868     const bool doesExistAndIsReadable =
00869       stdair::BasFileMgr::doesExistAndIsReadable (_filename);
00870 
00871     if (doesExistAndIsReadable == false) {
00872       STDAIR_LOG_ERROR ("The demand file " << _filename
00873                         << " does not exist or can not be read.");
00874 
00875       throw DemandInputFileNotFoundException ("The demand file " + _filename
00876                                               + " does not exist or can not "
00877                                               + "be read");
00878     }
00879     
00880     // Open the file
00881     _startIterator = iterator_t (_filename);
00882 
00883     // Check the filename exists and can be open
00884     if (!_startIterator) {
00885       STDAIR_LOG_ERROR ("The demand file " << _filename << " can not be open.");
00886 
00887       throw DemandInputFileNotFoundException ("The demand file " + _filename
00888                                               + " does not exist or can not "
00889                                               + "be read");
00890     }
00891 
00892     // Create an EOF iterator
00893     _endIterator = _startIterator.make_end();
00894   }
00895     
00896   // //////////////////////////////////////////////////////////////////////
00897   bool DemandFileParser::generateDemand () {
00898     bool oResult = false;
00899       
00900     STDAIR_LOG_DEBUG ("Parsing demand input file: " << _filename);
00901 
00902     // Initialise the parser (grammar) with the helper/staging structure.
00903     DemandParserHelper::DemandParser lDemandParser (_sevmgrServicePtr,
00904                                                     _uniformGenerator,
00905                                                     _posProbabilityMass,
00906                                                     _demand);
00907       
00908     // Launch the parsing of the file and, thanks to the doEndDemand
00909     // call-back structure, the building of the whole EventQueue BOM
00910     // (i.e., including Inventory, FlightDate, LegDate, SegmentDate, etc.)
00911     bsc::parse_info<iterator_t> info =
00912       bsc::parse (_startIterator, _endIterator, lDemandParser,
00913                   bsc::space_p - bsc::eol_p);
00914 
00915     // Retrieves whether or not the parsing was successful
00916     oResult = info.hit;
00917       
00918     const std::string hasBeenFullyReadStr = (info.full == true)?"":"not ";
00919     if (oResult == true) {
00920       STDAIR_LOG_DEBUG ("Parsing of demand input file: " << _filename
00921                        << " succeeded: read " << info.length
00922                        << " characters. The input file has "
00923                        << hasBeenFullyReadStr
00924                        << "been fully read. Stop point: " << info.stop);
00925         
00926     } else {
00927       std::ostringstream oStr;
00928       oStr << "Parsing of demand input file: " << _filename << " failed: read "
00929            << info.length << " characters. The input file has "
00930            << hasBeenFullyReadStr << "been fully read. Stop point: "
00931            << info.stop;
00932       STDAIR_LOG_ERROR (oStr.str());
00933       throw stdair::ParserException (oStr.str());
00934     }
00935 
00936     return oResult;
00937   }
00938     
00939 }