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