AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
AIRINV_Service.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // Boost
00007 #include <boost/make_shared.hpp>
00008 // StdAir
00009 #include <stdair/basic/BasChronometer.hpp>
00010 #include <stdair/bom/BomKeyManager.hpp> 
00011 #include <stdair/bom/BomManager.hpp> 
00012 #include <stdair/bom/BomKeyManager.hpp> 
00013 #include <stdair/bom/BomRoot.hpp>
00014 #include <stdair/bom/Inventory.hpp>
00015 #include <stdair/bom/FlightDate.hpp>
00016 #include <stdair/bom/AirlineFeature.hpp>
00017 #include <stdair/bom/RMEventStruct.hpp>
00018 #include <stdair/factory/FacBomManager.hpp>
00019 #include <stdair/service/Logger.hpp>
00020 #include <stdair/STDAIR_Service.hpp>
00021 // RMOL
00022 #include <rmol/RMOL_Service.hpp>
00023 // AirRAC
00024 #include <airrac/AIRRAC_Service.hpp>
00025 // AirInv
00026 #include <airinv/basic/BasConst_AIRINV_Service.hpp>
00027 #include <airinv/factory/FacAirinvServiceContext.hpp>
00028 #include <airinv/command/ScheduleParser.hpp>
00029 #include <airinv/command/InventoryParser.hpp>
00030 #include <airinv/command/InventoryManager.hpp>
00031 #include <airinv/service/AIRINV_ServiceContext.hpp>
00032 #include <airinv/AIRINV_Service.hpp>
00033 
00034 namespace AIRINV {
00035 
00036   // ////////////////////////////////////////////////////////////////////
00037   AIRINV_Service::AIRINV_Service () : _airinvServiceContext (NULL) {
00038     assert (false);
00039   }
00040 
00041   // ////////////////////////////////////////////////////////////////////
00042   AIRINV_Service::AIRINV_Service (const AIRINV_Service& iService)
00043   : _airinvServiceContext (NULL) {
00044     assert (false);
00045   }
00046 
00047   // ////////////////////////////////////////////////////////////////////
00048   AIRINV_Service::AIRINV_Service (const stdair::BasLogParams& iLogParams)
00049     : _airinvServiceContext (NULL) {
00050     
00051     // Initialise the STDAIR service handler
00052     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00053       initStdAirService (iLogParams);
00054     
00055     // Initialise the service context
00056     initServiceContext();
00057 
00058     // Add the StdAir service context to the AIRINV service context
00059     // \note AIRINV owns the STDAIR service resources here.
00060     const bool ownStdairService = true;
00061     addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00062 
00063     // Initalise the RMOL service.
00064     initRMOLService();
00065 
00066     // Initalise the AIRRAC service.
00067     initAIRRACService();
00068     
00069     // Initialise the (remaining of the) context
00070     initAirinvService();
00071   }
00072 
00073   // ////////////////////////////////////////////////////////////////////
00074   AIRINV_Service::AIRINV_Service (const stdair::BasLogParams& iLogParams,
00075                                   const stdair::BasDBParams& iDBParams)
00076     : _airinvServiceContext (NULL) {
00077     
00078     // Initialise the STDAIR service handler
00079     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00080       initStdAirService (iLogParams, iDBParams);
00081     
00082     // Initialise the service context
00083     initServiceContext();
00084 
00085     // Add the StdAir service context to the AIRINV service context
00086     // \note AIRINV owns the STDAIR service resources here.
00087     const bool ownStdairService = true;
00088     addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00089 
00090     // Initalise the RMOL service.
00091     initRMOLService();
00092 
00093     // Initalise the AIRRAC service.
00094     initAIRRACService();
00095     
00096     // Initialise the (remaining of the) context
00097     initAirinvService();
00098   }
00099   // //////////////////////////////////////////////////////////////////////
00100   AIRINV_Service::
00101   AIRINV_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
00102     : _airinvServiceContext (NULL) {
00103 
00104     // Initialise the service context
00105     initServiceContext();
00106     
00107     // Store the STDAIR service object within the (AIRINV) service context
00108     // \note AirInv does not own the STDAIR service resources here.
00109     const bool doesNotOwnStdairService = false;
00110     addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
00111     
00112     // Initalise the RMOL service.
00113     initRMOLService();
00114     
00115     // Initalise the AIRRAC service.
00116     initAIRRACService();
00117     
00118     // Initialise the (remaining of the) context
00119     initAirinvService();
00120     
00121   }
00122   
00123   // ////////////////////////////////////////////////////////////////////
00124   AIRINV_Service::~AIRINV_Service() {
00125     // Delete/Clean all the objects from memory
00126     finalise();
00127   }
00128 
00129   // ////////////////////////////////////////////////////////////////////
00130   void AIRINV_Service::finalise() {
00131     assert (_airinvServiceContext != NULL);
00132     // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
00133     _airinvServiceContext->reset();
00134   }
00135 
00136   // ////////////////////////////////////////////////////////////////////
00137   void AIRINV_Service::initServiceContext() {
00138     // Initialise the context
00139     AIRINV_ServiceContext& lAIRINV_ServiceContext = 
00140       FacAirinvServiceContext::instance().create();
00141     _airinvServiceContext = &lAIRINV_ServiceContext;
00142   }
00143 
00144   // ////////////////////////////////////////////////////////////////////
00145   void AIRINV_Service::
00146   addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
00147                     const bool iOwnStdairService) {
00148 
00149     // Retrieve the Airinv service context
00150     assert (_airinvServiceContext != NULL);
00151     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00152 
00153     // Store the STDAIR service object within the (AIRINV) service context
00154     lAIRINV_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
00155                                               iOwnStdairService);
00156   }
00157   
00158   // ////////////////////////////////////////////////////////////////////
00159   stdair::STDAIR_ServicePtr_T AIRINV_Service::
00160   initStdAirService (const stdair::BasLogParams& iLogParams,
00161                      const stdair::BasDBParams& iDBParams) {
00162 
00170     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 
00171       boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
00172     
00173     return lSTDAIR_Service_ptr;
00174   }
00175   
00176   // ////////////////////////////////////////////////////////////////////
00177   stdair::STDAIR_ServicePtr_T AIRINV_Service::
00178   initStdAirService (const stdair::BasLogParams& iLogParams) {
00179 
00187     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 
00188       boost::make_shared<stdair::STDAIR_Service> (iLogParams);
00189 
00190     return lSTDAIR_Service_ptr;
00191   }
00192   
00193   // ////////////////////////////////////////////////////////////////////
00194   void AIRINV_Service::initRMOLService() {
00195 
00196     // Retrieve the AirInv service context
00197     assert (_airinvServiceContext != NULL);
00198     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00199 
00200     // Retrieve the StdAir service context
00201     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00202       lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
00203 
00211     RMOL::RMOL_ServicePtr_T lRMOL_Service_ptr = 
00212       boost::make_shared<RMOL::RMOL_Service> (lSTDAIR_Service_ptr);
00213     
00214     // Store the RMOL service object within the (AIRINV) service context
00215     lAIRINV_ServiceContext.setRMOL_Service (lRMOL_Service_ptr);
00216   }
00217   
00218   // ////////////////////////////////////////////////////////////////////
00219   void AIRINV_Service::initAIRRACService() {
00220 
00221     // Retrieve the AirInv service context
00222     assert (_airinvServiceContext != NULL);
00223     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00224 
00225     // Retrieve the StdAir service context
00226     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00227       lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
00228 
00236     AIRRAC::AIRRAC_ServicePtr_T lAIRRAC_Service_ptr = 
00237       boost::make_shared<AIRRAC::AIRRAC_Service> (lSTDAIR_Service_ptr);
00238     
00239     // Store the AIRRAC service object within the (AIRINV) service context
00240     lAIRINV_ServiceContext.setAIRRAC_Service (lAIRRAC_Service_ptr);
00241   }
00242   
00243   // ////////////////////////////////////////////////////////////////////
00244   void AIRINV_Service::initAirinvService() {
00245     // Do nothing at this stage. A sample BOM tree may be built by
00246     // calling the buildSampleBom() method
00247   }
00248   
00249   // ////////////////////////////////////////////////////////////////////
00250   void AIRINV_Service::
00251   parseAndLoad (const stdair::Filename_T& iInventoryInputFilename) {
00252 
00253     // Retrieve the BOM root object.
00254     assert (_airinvServiceContext != NULL);
00255     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00256     stdair::STDAIR_Service& lSTDAIR_Service =
00257       lAIRINV_ServiceContext.getSTDAIR_Service();
00258     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00259     
00260     // Initialise the airline inventories
00261     InventoryParser::buildInventory (iInventoryInputFilename, lBomRoot);
00262   }
00263   
00264   // ////////////////////////////////////////////////////////////////////
00265   void AIRINV_Service::
00266   parseAndLoad (const stdair::Filename_T& iScheduleInputFilename,
00267                 const stdair::Filename_T& iODInputFilename,
00268                 const AIRRAC::YieldFilePath& iYieldFilename) {
00269 
00270     // Retrieve the BOM root object.
00271     assert (_airinvServiceContext != NULL);
00272     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00273     stdair::STDAIR_Service& lSTDAIR_Service =
00274       lAIRINV_ServiceContext.getSTDAIR_Service();
00275     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00276     
00277     // Initialise the airline inventories
00278     ScheduleParser::generateInventories (iScheduleInputFilename, lBomRoot);
00279 
00280     // Parse the yield structures.
00281     AIRRAC::AIRRAC_Service& lAIRRAC_Service =
00282       lAIRINV_ServiceContext.getAIRRAC_Service();
00283     lAIRRAC_Service.parseAndLoad (iYieldFilename);
00284 
00285     // Update yield values for booking classes and O&D.
00286     lAIRRAC_Service.updateYields();
00287   }
00288   
00289   // ////////////////////////////////////////////////////////////////////
00290   void AIRINV_Service::buildSampleBom() {
00291 
00292     // Retrieve the AirInv service context
00293     if (_airinvServiceContext == NULL) {
00294       throw stdair::NonInitialisedServiceException("The AirInv service has not "
00295                                                    "been initialised");
00296     }
00297     assert (_airinvServiceContext != NULL);
00298 
00299     // Retrieve the AirInv service context and whether it owns the Stdair
00300     // service
00301     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00302     const bool doesOwnStdairService =
00303       lAIRINV_ServiceContext.getOwnStdairServiceFlag();
00304 
00305     // Retrieve the StdAir service object from the (AirInv) service context
00306     stdair::STDAIR_Service& lSTDAIR_Service =
00307       lAIRINV_ServiceContext.getSTDAIR_Service();
00308 
00313     if (doesOwnStdairService == true) {
00314       //
00315       lSTDAIR_Service.buildSampleBom();
00316     }
00317 
00328     AIRRAC::AIRRAC_Service& lAIRRAC_Service =
00329       lAIRINV_ServiceContext.getAIRRAC_Service();
00330     lAIRRAC_Service.buildSampleBom();
00331 
00337     RMOL::RMOL_Service& lRMOL_Service= lAIRINV_ServiceContext.getRMOL_Service();
00338     lRMOL_Service.buildSampleBom();
00339     
00365     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00366     InventoryManager::buildSimilarSegmentCabinSets (lBomRoot);
00367 
00371     //    InventoryManager::setDefaultBidPriceVector (lBomRoot);
00372   }
00373 
00374   // ////////////////////////////////////////////////////////////////////
00375   std::string AIRINV_Service::
00376   jsonExport (const stdair::AirlineCode_T& iAirlineCode,
00377               const stdair::FlightNumber_T& iFlightNumber,
00378               const stdair::Date_T& iDepartureDate) const {
00379 
00380     // Retrieve the AIRINV service context
00381     if (_airinvServiceContext == NULL) {
00382       throw stdair::NonInitialisedServiceException ("The AirInv service "
00383                                                     "has not been initialised");
00384     }
00385     assert (_airinvServiceContext != NULL);
00386 
00387     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00388   
00389     // Retrieve the STDAIR service object from the (AIRINV) service context
00390     stdair::STDAIR_Service& lSTDAIR_Service =
00391       lAIRINV_ServiceContext.getSTDAIR_Service();
00392 
00393     // Delegate the JSON export to the dedicated service
00394     return lSTDAIR_Service.jsonExport (iAirlineCode, iFlightNumber,
00395                                        iDepartureDate);
00396   }
00397   
00398   // ////////////////////////////////////////////////////////////////////
00399   std::string AIRINV_Service::
00400   list (const stdair::AirlineCode_T& iAirlineCode,
00401         const stdair::FlightNumber_T& iFlightNumber) const {
00402     std::ostringstream oFlightListStr;
00403 
00404     if (_airinvServiceContext == NULL) {
00405       throw stdair::NonInitialisedServiceException ("The AirInv service "
00406                                                     "has not been initialised");
00407     }
00408     assert (_airinvServiceContext != NULL);
00409     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00410 
00411     // \todo Check that the current AIRINV_Service is actually operating for
00412     //       the given airline
00413 
00414     // Retrieve the STDAIR service object from the (AirInv) service context
00415     stdair::STDAIR_Service& lSTDAIR_Service =
00416       lAIRINV_ServiceContext.getSTDAIR_Service();
00417 
00418     // Delegate the BOM display to the dedicated service
00419     return lSTDAIR_Service.list (iAirlineCode, iFlightNumber);
00420   }
00421   
00422   // ////////////////////////////////////////////////////////////////////
00423   bool AIRINV_Service::
00424   check (const stdair::AirlineCode_T& iAirlineCode,
00425          const stdair::FlightNumber_T& iFlightNumber,
00426          const stdair::Date_T& iDepartureDate) const {
00427     std::ostringstream oFlightListStr;
00428 
00429     if (_airinvServiceContext == NULL) {
00430       throw stdair::NonInitialisedServiceException ("The AirInv service "
00431                                                     "has not been initialised");
00432     }
00433     assert (_airinvServiceContext != NULL);
00434     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00435 
00436     // \todo Check that the current AIRINV_Service is actually operating for
00437     //       the given airline
00438 
00439     // Retrieve the STDAIR service object from the (AirInv) service context
00440     stdair::STDAIR_Service& lSTDAIR_Service =
00441       lAIRINV_ServiceContext.getSTDAIR_Service();
00442 
00443     // Delegate the BOM display to the dedicated service
00444     return lSTDAIR_Service.check (iAirlineCode, iFlightNumber, iDepartureDate);
00445   }
00446   
00447   // ////////////////////////////////////////////////////////////////////
00448   std::string AIRINV_Service::csvDisplay() const {
00449 
00450     // Retrieve the AIRINV service context
00451     if (_airinvServiceContext == NULL) {
00452       throw stdair::NonInitialisedServiceException ("The AirInv service "
00453                                                     "has not been initialised");
00454     }
00455     assert (_airinvServiceContext != NULL);
00456 
00457     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00458   
00459     // Retrieve the STDAIR service object from the (AirInv) service context
00460     stdair::STDAIR_Service& lSTDAIR_Service =
00461       lAIRINV_ServiceContext.getSTDAIR_Service();
00462 
00463     // Delegate the BOM display to the dedicated service
00464     return lSTDAIR_Service.csvDisplay();
00465   }
00466   
00467   // ////////////////////////////////////////////////////////////////////
00468   std::string AIRINV_Service::
00469   csvDisplay (const stdair::AirlineCode_T& iAirlineCode,
00470               const stdair::FlightNumber_T& iFlightNumber,
00471               const stdair::Date_T& iDepartureDate) const {
00472 
00473     // Retrieve the AIRINV service context
00474     if (_airinvServiceContext == NULL) {
00475       throw stdair::NonInitialisedServiceException ("The AirInv service "
00476                                                     "has not been initialised");
00477     }
00478     assert (_airinvServiceContext != NULL);
00479 
00480     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00481   
00482     // Retrieve the STDAIR service object from the (AirInv) service context
00483     stdair::STDAIR_Service& lSTDAIR_Service =
00484       lAIRINV_ServiceContext.getSTDAIR_Service();
00485 
00486     // Delegate the BOM display to the dedicated service
00487     return lSTDAIR_Service.csvDisplay (iAirlineCode, iFlightNumber,
00488                                        iDepartureDate);
00489   }
00490   
00491   // ////////////////////////////////////////////////////////////////////
00492   stdair::RMEventList_T AIRINV_Service::
00493   initRMEvents (const stdair::Date_T& iStartDate,
00494                 const stdair::Date_T& iEndDate) {
00495 
00496     if (_airinvServiceContext == NULL) {
00497       throw stdair::NonInitialisedServiceException ("The AirInv service "
00498                                                     "has not been initialised");
00499     }
00500     assert (_airinvServiceContext != NULL);
00501     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00502 
00503     // \todo Retrieve the corresponding inventory
00504     stdair::STDAIR_Service& lSTDAIR_Service =
00505       lAIRINV_ServiceContext.getSTDAIR_Service();
00506     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00507 
00508     stdair::RMEventList_T oRMEventList;
00509     const stdair::InventoryList_T& lInventoryList =
00510       stdair::BomManager::getList<stdair::Inventory> (lBomRoot);
00511     for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
00512          itInv != lInventoryList.end(); ++itInv) {
00513       const stdair::Inventory* lInv_ptr = *itInv;
00514       assert (lInv_ptr != NULL);
00515       
00516       InventoryManager::initRMEvents (*lInv_ptr, oRMEventList,
00517                                       iStartDate, iEndDate); 
00518     }
00519 
00520     return oRMEventList;
00521   }
00522   
00523   // ////////////////////////////////////////////////////////////////////
00524   void AIRINV_Service::
00525   calculateAvailability (stdair::TravelSolutionStruct& ioTravelSolution,
00526                          const stdair::PartnershipTechnique& iPartnershipTechnique) {
00527     
00528     if (_airinvServiceContext == NULL) {
00529       throw stdair::NonInitialisedServiceException ("The AirInv service "
00530                                                     "has not been initialised");
00531     }
00532     assert (_airinvServiceContext != NULL);
00533     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00534 
00535     // Retrieve the corresponding inventory.
00536     stdair::STDAIR_Service& lSTDAIR_Service =
00537       lAIRINV_ServiceContext.getSTDAIR_Service();
00538     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00539 
00540     // Delegate the booking to the dedicated command
00541     stdair::BasChronometer lAvlChronometer;
00542     lAvlChronometer.start();
00543     InventoryManager::calculateAvailability (lBomRoot, ioTravelSolution, iPartnershipTechnique);
00544     // const double lAvlMeasure = lAvlChronometer.elapsed();
00545 
00546     // DEBUG
00547     // STDAIR_LOG_DEBUG ("Availability retrieval: " << lAvlMeasure << " - "
00548     //                   << lAIRINV_ServiceContext.display());
00549   }
00550   
00551   // ////////////////////////////////////////////////////////////////////
00552   bool AIRINV_Service::sell (const std::string& iSegmentDateKey,
00553                              const stdair::ClassCode_T& iClassCode,
00554                              const stdair::PartySize_T& iPartySize) {
00555     bool isSellSuccessful = false;
00556 
00557     if (_airinvServiceContext == NULL) {
00558       throw stdair::NonInitialisedServiceException ("The AirInv service "
00559                                                     "has not been initialised");
00560     }
00561     assert (_airinvServiceContext != NULL);
00562     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00563 
00564     // \todo Check that the current AIRINV_Service is actually operating for
00565     //       the given airline (inventory key)
00566     // Retrieve the corresponding inventory key
00567     const stdair::InventoryKey& lInventoryKey =
00568       stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
00569 
00570     // Retrieve the root of the BOM tree
00571     stdair::STDAIR_Service& lSTDAIR_Service =
00572       lAIRINV_ServiceContext.getSTDAIR_Service();
00573     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00574 
00575     // Retrieve the corresponding inventory
00576     stdair::Inventory& lInventory = stdair::BomManager::
00577       getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString());
00578 
00579     // Delegate the booking to the dedicated command
00580     stdair::BasChronometer lSellChronometer; lSellChronometer.start();
00581     isSellSuccessful = InventoryManager::sell (lInventory, iSegmentDateKey,
00582                                                iClassCode, iPartySize);
00583     // const double lSellMeasure = lSellChronometer.elapsed();
00584 
00585     // DEBUG
00586     // STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - "
00587     //                  << lAIRINV_ServiceContext.display());
00588 
00589     return isSellSuccessful;
00590   }
00591   
00592   // ////////////////////////////////////////////////////////////////////
00593   bool AIRINV_Service::cancel (const std::string& iSegmentDateKey,
00594                              const stdair::ClassCode_T& iClassCode,
00595                              const stdair::PartySize_T& iPartySize) {
00596     bool isCancellationSuccessful = false;
00597 
00598     if (_airinvServiceContext == NULL) {
00599       throw stdair::NonInitialisedServiceException ("The AirInv service "
00600                                                     "has not been initialised");
00601     }
00602     assert (_airinvServiceContext != NULL);
00603     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00604 
00605     // \todo Check that the current AIRINV_Service is actually operating for
00606     //       the given airline (inventory key)
00607     // Retrieve the corresponding inventory key
00608     const stdair::InventoryKey& lInventoryKey =
00609       stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
00610 
00611     // Retrieve the root of the BOM tree
00612     stdair::STDAIR_Service& lSTDAIR_Service =
00613       lAIRINV_ServiceContext.getSTDAIR_Service();
00614     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00615 
00616     // Retrieve the corresponding inventory
00617     stdair::Inventory& lInventory = stdair::BomManager::
00618       getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString());
00619 
00620     // Delegate the booking to the dedicated command
00621     stdair::BasChronometer lCancellationChronometer;
00622     lCancellationChronometer.start();
00623     isCancellationSuccessful = InventoryManager::cancel (lInventory,
00624                                                          iSegmentDateKey,
00625                                                          iClassCode,iPartySize);
00626     // const double lCancellationMeasure = lCancellationChronometer.elapsed();
00627 
00628     // DEBUG
00629     // STDAIR_LOG_DEBUG ("Booking cancellation: "
00630     //                  << lCancellationMeasure << " - "
00631     //                  << lAIRINV_ServiceContext.display());
00632 
00633     return isCancellationSuccessful;
00634   }
00635   
00636   // ////////////////////////////////////////////////////////////////////
00637   void AIRINV_Service::takeSnapshots (const stdair::AirlineCode_T& iAirlineCode,
00638                                       const stdair::DateTime_T& iSnapshotTime) {
00639 
00640     if (_airinvServiceContext == NULL) {
00641       throw stdair::NonInitialisedServiceException ("The AirInv service "
00642                                                     "has not been initialised");
00643     }
00644     assert (_airinvServiceContext != NULL);
00645     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00646 
00647     // TODO: Retrieve the corresponding inventory.
00648     stdair::STDAIR_Service& lSTDAIR_Service =
00649       lAIRINV_ServiceContext.getSTDAIR_Service();
00650     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00651 
00652     const stdair::InventoryList_T lInventoryList =
00653       stdair::BomManager::getList<stdair::Inventory> (lBomRoot);
00654     for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
00655          itInv != lInventoryList.end(); ++itInv) {
00656       const stdair::Inventory* lInv_ptr = *itInv;
00657       assert (lInv_ptr != NULL);
00658       
00659       InventoryManager::takeSnapshots (*lInv_ptr, iSnapshotTime); 
00660     }
00661   }
00662 
00663   // ////////////////////////////////////////////////////////////////////
00664   void AIRINV_Service::optimise (const stdair::AirlineCode_T& iAirlineCode,
00665                                  const stdair::KeyDescription_T& iFDDescription,
00666                                  const stdair::DateTime_T& iRMEventTime,
00667                                  const stdair::ForecastingMethod& iForecastingMethod,
00668                                  const stdair::PartnershipTechnique& iPartnershipTechnique) {
00669     if (_airinvServiceContext == NULL) {
00670       throw stdair::NonInitialisedServiceException ("The AirInv service "
00671                                                     "has not been initialised");
00672     }
00673     assert (_airinvServiceContext != NULL);
00674     AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
00675 
00676     // Retrieve the corresponding inventory & flight-date
00677     stdair::STDAIR_Service& lSTDAIR_Service =
00678       lAIRINV_ServiceContext.getSTDAIR_Service();
00679     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00680     stdair::Inventory& lInventory =
00681       stdair::BomManager::getObject<stdair::Inventory> (lBomRoot, iAirlineCode);
00682     stdair::FlightDate& lFlightDate =
00683       stdair::BomManager::getObject<stdair::FlightDate> (lInventory,
00684                                                          iFDDescription);
00685 
00686     // Retrieve the RMOL service.
00687     RMOL::RMOL_Service& lRMOL_Service =lAIRINV_ServiceContext.getRMOL_Service();
00688 
00689     // Optimise the flight-date.
00690     bool isOptimised = lRMOL_Service.optimise (lFlightDate, iRMEventTime,
00691                                                iForecastingMethod, iPartnershipTechnique);
00692 
00693     // Update the inventory with the new controls.
00694     if (isOptimised == true) {
00695       InventoryManager::updateBookingControls (lFlightDate);
00696     }
00697   }
00698 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines