$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 // Boost 00007 #include <boost/make_shared.hpp> 00008 // StdAir 00009 #include <stdair/stdair_json.hpp> 00010 #include <stdair/basic/BasChronometer.hpp> 00011 #include <stdair/basic/JSonCommand.hpp> 00012 #include <stdair/basic/PartnershipTechnique.hpp> 00013 #include <stdair/basic/UnconstrainingMethod.hpp> 00014 #include <stdair/basic/OptimisationMethod.hpp> 00015 #include <stdair/bom/BomKeyManager.hpp> 00016 #include <stdair/bom/BomManager.hpp> 00017 #include <stdair/bom/BomRoot.hpp> 00018 #include <stdair/bom/Inventory.hpp> 00019 #include <stdair/bom/FlightDate.hpp> 00020 #include <stdair/bom/SegmentCabin.hpp> 00021 #include <stdair/bom/AirlineFeature.hpp> 00022 #include <stdair/bom/RMEventStruct.hpp> 00023 #include <stdair/bom/BomJSONImport.hpp> 00024 #include <stdair/bom/BomJSONExport.hpp> 00025 #include <stdair/factory/FacBomManager.hpp> 00026 #include <stdair/service/Logger.hpp> 00027 #include <stdair/STDAIR_Service.hpp> 00028 // RMOL 00029 #include <rmol/RMOL_Service.hpp> 00030 // AirRAC 00031 #include <airrac/AIRRAC_Service.hpp> 00032 // SEvMgr 00033 #include <sevmgr/SEVMGR_Service.hpp> 00034 // AirInv 00035 #include <airinv/basic/BasConst_AIRINV_Service.hpp> 00036 #include <airinv/factory/FacAirinvServiceContext.hpp> 00037 #include <airinv/command/ScheduleParser.hpp> 00038 #include <airinv/command/FRAT5Parser.hpp> 00039 #include <airinv/command/FFDisutilityParser.hpp> 00040 #include <airinv/command/InventoryParser.hpp> 00041 #include <airinv/command/InventoryManager.hpp> 00042 #include <airinv/command/InventoryBuilder.hpp> 00043 #include <airinv/service/AIRINV_ServiceContext.hpp> 00044 #include <airinv/AIRINV_Service.hpp> 00045 00046 namespace AIRINV { 00047 00048 // //////////////////////////////////////////////////////////////////// 00049 AIRINV_Service::AIRINV_Service () : _airinvServiceContext (NULL) { 00050 assert (false); 00051 } 00052 00053 // //////////////////////////////////////////////////////////////////// 00054 AIRINV_Service::AIRINV_Service (const AIRINV_Service& iService) 00055 : _airinvServiceContext (NULL) { 00056 assert (false); 00057 } 00058 00059 // //////////////////////////////////////////////////////////////////// 00060 AIRINV_Service::AIRINV_Service (const stdair::BasLogParams& iLogParams) 00061 : _airinvServiceContext (NULL) { 00062 00063 // Initialise the STDAIR service handler 00064 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00065 initStdAirService (iLogParams); 00066 00067 // Initialise the service context 00068 initServiceContext(); 00069 00070 // Add the StdAir service context to the AIRINV service context 00071 // \note AIRINV owns the STDAIR service resources here. 00072 const bool ownStdairService = true; 00073 addStdAirService (lSTDAIR_Service_ptr, ownStdairService); 00074 00075 // Initalise the RMOL service. 00076 initRMOLService(); 00077 00078 // Initalise the AIRRAC service. 00079 initAIRRACService(); 00080 00081 // Initalise the SEvMgr service. 00082 initSEVMGRService(); 00083 00084 // Initialise the (remaining of the) context 00085 initAirinvService(); 00086 } 00087 00088 // //////////////////////////////////////////////////////////////////// 00089 AIRINV_Service::AIRINV_Service (const stdair::BasLogParams& iLogParams, 00090 const stdair::BasDBParams& iDBParams) 00091 : _airinvServiceContext (NULL) { 00092 00093 // Initialise the STDAIR service handler 00094 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00095 initStdAirService (iLogParams, iDBParams); 00096 00097 // Initialise the service context 00098 initServiceContext(); 00099 00100 // Add the StdAir service context to the AIRINV service context 00101 // \note AIRINV owns the STDAIR service resources here. 00102 const bool ownStdairService = true; 00103 addStdAirService (lSTDAIR_Service_ptr, ownStdairService); 00104 00105 // Initalise the RMOL service. 00106 initRMOLService(); 00107 00108 // Initalise the AIRRAC service. 00109 initAIRRACService(); 00110 00111 // Initalise the SEVMGR service. 00112 initSEVMGRService(); 00113 00114 // Initialise the (remaining of the) context 00115 initAirinvService(); 00116 } 00117 00118 // ////////////////////////////////////////////////////////////////////// 00119 AIRINV_Service:: 00120 AIRINV_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr) 00121 00122 : _airinvServiceContext (NULL) { 00123 00124 // Initialise the service context 00125 initServiceContext(); 00126 00127 // Store the STDAIR service object within the (AIRINV) service context 00128 // \note AirInv does not own the STDAIR service resources here. 00129 const bool doesNotOwnStdairService = false; 00130 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService); 00131 00132 // Initalise the RMOL service. 00133 initRMOLService(); 00134 00135 // Initalise the AIRRAC service. 00136 initAIRRACService(); 00137 00138 // Initalise the SEVMGR service. 00139 initSEVMGRService(); 00140 00141 // Initialise the (remaining of the) context 00142 initAirinvService(); 00143 00144 } 00145 00146 // ////////////////////////////////////////////////////////////////////// 00147 AIRINV_Service:: 00148 AIRINV_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr, 00149 SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr) 00150 00151 : _airinvServiceContext (NULL) { 00152 00153 // Initialise the service context 00154 initServiceContext(); 00155 00156 // Store the STDAIR service object within the (AIRINV) service context 00157 // \note AirInv does not own the STDAIR service resources here. 00158 const bool doesNotOwnStdairService = false; 00159 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService); 00160 00161 //Add the SEvMgr service to the TRADEMGEN service context. 00162 const bool doesNotOwnSEVMGRService = false; 00163 addSEVMGRService (ioSEVMGR_Service_ptr, doesNotOwnSEVMGRService); 00164 00165 // Initalise the RMOL service. 00166 initRMOLService(); 00167 00168 // Initalise the AIRRAC service. 00169 initAIRRACService(); 00170 00171 // Initialise the (remaining of the) context 00172 initAirinvService(); 00173 00174 } 00175 00176 // //////////////////////////////////////////////////////////////////// 00177 AIRINV_Service::~AIRINV_Service() { 00178 // Delete/Clean all the objects from memory 00179 finalise(); 00180 } 00181 00182 // //////////////////////////////////////////////////////////////////// 00183 void AIRINV_Service::finalise() { 00184 assert (_airinvServiceContext != NULL); 00185 // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object. 00186 _airinvServiceContext->reset(); 00187 } 00188 00189 // //////////////////////////////////////////////////////////////////// 00190 void AIRINV_Service::initServiceContext() { 00191 // Initialise the context 00192 AIRINV_ServiceContext& lAIRINV_ServiceContext = 00193 FacAirinvServiceContext::instance().create(); 00194 _airinvServiceContext = &lAIRINV_ServiceContext; 00195 } 00196 00197 // //////////////////////////////////////////////////////////////////// 00198 void AIRINV_Service:: 00199 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr, 00200 const bool iOwnStdairService) { 00201 00202 // Retrieve the Airinv service context 00203 assert (_airinvServiceContext != NULL); 00204 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00205 00206 // Store the STDAIR service object within the (AIRINV) service context 00207 lAIRINV_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr, 00208 iOwnStdairService); 00209 } 00210 00211 // //////////////////////////////////////////////////////////////////// 00212 void AIRINV_Service:: 00213 addSEVMGRService (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr, 00214 const bool iOwnSEVMGRService) { 00215 00216 // Retrieve the Airinv service context 00217 assert (_airinvServiceContext != NULL); 00218 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00219 00220 // Store the STDAIR service object within the (TRADEMGEN) service context 00221 lAIRINV_ServiceContext.setSEVMGR_Service (ioSEVMGR_Service_ptr, 00222 iOwnSEVMGRService); 00223 } 00224 00225 // //////////////////////////////////////////////////////////////////// 00226 stdair::STDAIR_ServicePtr_T AIRINV_Service:: 00227 initStdAirService (const stdair::BasLogParams& iLogParams, 00228 const stdair::BasDBParams& iDBParams) { 00229 00237 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00238 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams); 00239 00240 return lSTDAIR_Service_ptr; 00241 } 00242 00243 // //////////////////////////////////////////////////////////////////// 00244 stdair::STDAIR_ServicePtr_T AIRINV_Service:: 00245 initStdAirService (const stdair::BasLogParams& iLogParams) { 00246 00254 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00255 boost::make_shared<stdair::STDAIR_Service> (iLogParams); 00256 00257 return lSTDAIR_Service_ptr; 00258 } 00259 00260 // //////////////////////////////////////////////////////////////////// 00261 void AIRINV_Service::initRMOLService() { 00262 00263 // Retrieve the AirInv service context 00264 assert (_airinvServiceContext != NULL); 00265 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00266 00267 // Retrieve the StdAir service context 00268 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00269 lAIRINV_ServiceContext.getSTDAIR_ServicePtr(); 00270 00278 RMOL::RMOL_ServicePtr_T lRMOL_Service_ptr = 00279 boost::make_shared<RMOL::RMOL_Service> (lSTDAIR_Service_ptr); 00280 00281 // Store the RMOL service object within the (AIRINV) service context 00282 lAIRINV_ServiceContext.setRMOL_Service (lRMOL_Service_ptr); 00283 } 00284 00285 // //////////////////////////////////////////////////////////////////// 00286 void AIRINV_Service::initAIRRACService() { 00287 00288 // Retrieve the AirInv service context 00289 assert (_airinvServiceContext != NULL); 00290 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00291 00292 // Retrieve the StdAir service context 00293 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00294 lAIRINV_ServiceContext.getSTDAIR_ServicePtr(); 00295 00303 AIRRAC::AIRRAC_ServicePtr_T lAIRRAC_Service_ptr = 00304 boost::make_shared<AIRRAC::AIRRAC_Service> (lSTDAIR_Service_ptr); 00305 00306 // Store the AIRRAC service object within the (AIRINV) service context 00307 lAIRINV_ServiceContext.setAIRRAC_Service (lAIRRAC_Service_ptr); 00308 } 00309 00310 // //////////////////////////////////////////////////////////////////// 00311 void AIRINV_Service::initSEVMGRService() { 00312 00313 // Retrieve the AIRINV service context 00314 assert (_airinvServiceContext != NULL); 00315 AIRINV_ServiceContext& lAIRINV_ServiceContext = 00316 *_airinvServiceContext; 00317 00318 // Retrieve the StdAir service context 00319 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00320 lAIRINV_ServiceContext.getSTDAIR_ServicePtr(); 00321 00329 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr = 00330 boost::make_shared<SEVMGR::SEVMGR_Service> (lSTDAIR_Service_ptr); 00331 00332 // Store the SEvMgr service object within the (TraDemGen) service context 00333 const bool doesOwnSEVMGRService = true; 00334 lAIRINV_ServiceContext.setSEVMGR_Service (lSEVMGR_Service_ptr, 00335 doesOwnSEVMGRService); 00336 } 00337 00338 // //////////////////////////////////////////////////////////////////// 00339 void AIRINV_Service::initAirinvService() { 00340 // Do nothing at this stage. A sample BOM tree may be built by 00341 // calling the buildSampleBom() method 00342 } 00343 00344 // //////////////////////////////////////////////////////////////////// 00345 void AIRINV_Service:: 00346 parseAndLoad (const AIRINV::InventoryFilePath& iInventoryInputFilename) { 00347 00348 // Retrieve the AirInv service context 00349 if (_airinvServiceContext == NULL) { 00350 throw stdair::NonInitialisedServiceException("The AirInv service has not " 00351 "been initialised"); 00352 } 00353 assert (_airinvServiceContext != NULL); 00354 00355 // Retrieve the AirInv service context and whether it owns the Stdair 00356 // service 00357 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00358 const bool doesOwnStdairService = 00359 lAIRINV_ServiceContext.getOwnStdairServiceFlag(); 00360 00361 // Retrieve the StdAir service object from the (AirInv) service context 00362 stdair::STDAIR_Service& lSTDAIR_Service = 00363 lAIRINV_ServiceContext.getSTDAIR_Service(); 00364 00365 // Retrieve the persistent BOM root object. 00366 stdair::BomRoot& lPersistentBomRoot = 00367 lSTDAIR_Service.getPersistentBomRoot(); 00368 00372 InventoryParser::buildInventory (iInventoryInputFilename, 00373 lPersistentBomRoot); 00374 00378 InventoryBuilder::buildPartnerInventories (lPersistentBomRoot); 00379 00383 lSTDAIR_Service.updateAirlineFeatures(); 00384 00389 buildComplementaryLinks (lPersistentBomRoot); 00390 00395 if (doesOwnStdairService == true) { 00396 00397 // 00398 clonePersistentBom (); 00399 } 00400 } 00401 00402 // //////////////////////////////////////////////////////////////////// 00403 void AIRINV_Service:: 00404 parseAndLoad (const stdair::ScheduleFilePath& iScheduleInputFilename, 00405 const stdair::ODFilePath& iODInputFilename, 00406 const stdair::FRAT5FilePath& iFRAT5InputFilename, 00407 const stdair::FFDisutilityFilePath& iFFDisutilityInputFilename, 00408 const AIRRAC::YieldFilePath& iYieldFilename) { 00409 00410 // Retrieve the AirInv service context 00411 if (_airinvServiceContext == NULL) { 00412 throw stdair::NonInitialisedServiceException("The AirInv service has not " 00413 "been initialised"); 00414 } 00415 assert (_airinvServiceContext != NULL); 00416 00417 // Retrieve the AirInv service context and whether it owns the Stdair 00418 // service 00419 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00420 const bool doesOwnStdairService = 00421 lAIRINV_ServiceContext.getOwnStdairServiceFlag(); 00422 00423 // Retrieve the StdAir service object from the (AirInv) service context 00424 stdair::STDAIR_Service& lSTDAIR_Service = 00425 lAIRINV_ServiceContext.getSTDAIR_Service(); 00426 00427 // Retrieve the perssitent BOM root object. 00428 stdair::BomRoot& lPersistentBomRoot = 00429 lSTDAIR_Service.getPersistentBomRoot(); 00430 00434 FRAT5Parser::parse (iFRAT5InputFilename, lPersistentBomRoot); 00435 FFDisutilityParser::parse (iFFDisutilityInputFilename, lPersistentBomRoot); 00436 ScheduleParser::generateInventories (iScheduleInputFilename, 00437 lPersistentBomRoot); 00438 00442 InventoryBuilder::buildPartnerInventories (lPersistentBomRoot); 00443 00447 lSTDAIR_Service.updateAirlineFeatures(); 00448 00453 buildComplementaryLinks (lPersistentBomRoot); 00454 00463 AIRRAC::AIRRAC_Service& lAIRRAC_Service = 00464 lAIRINV_ServiceContext.getAIRRAC_Service(); 00465 lAIRRAC_Service.parseAndLoad (iYieldFilename); 00473 lAIRRAC_Service.updateYields(lPersistentBomRoot); 00474 00479 if (doesOwnStdairService == true) { 00480 00481 // 00482 clonePersistentBom (); 00483 } 00484 } 00485 00486 // //////////////////////////////////////////////////////////////////// 00487 void AIRINV_Service::buildSampleBom() { 00488 00489 // Retrieve the AirInv service context 00490 if (_airinvServiceContext == NULL) { 00491 throw stdair::NonInitialisedServiceException("The AirInv service has not " 00492 "been initialised"); 00493 } 00494 assert (_airinvServiceContext != NULL); 00495 00496 // Retrieve the AirInv service context and whether it owns the Stdair 00497 // service 00498 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00499 const bool doesOwnStdairService = 00500 lAIRINV_ServiceContext.getOwnStdairServiceFlag(); 00501 00502 // Retrieve the StdAir service object from the (AirInv) service context 00503 stdair::STDAIR_Service& lSTDAIR_Service = 00504 lAIRINV_ServiceContext.getSTDAIR_Service(); 00505 00506 // Retrieve the perssitent BOM root object. 00507 stdair::BomRoot& lPersistentBomRoot = 00508 lSTDAIR_Service.getPersistentBomRoot(); 00509 00514 if (doesOwnStdairService == true) { 00515 // 00516 lSTDAIR_Service.buildSampleBom(); 00517 } 00518 00529 AIRRAC::AIRRAC_Service& lAIRRAC_Service = 00530 lAIRINV_ServiceContext.getAIRRAC_Service(); 00531 lAIRRAC_Service.buildSampleBom(); 00532 00538 RMOL::RMOL_Service& lRMOL_Service = 00539 lAIRINV_ServiceContext.getRMOL_Service(); 00540 lRMOL_Service.buildSampleBom(); 00541 00545 InventoryBuilder::buildPartnerInventories (lPersistentBomRoot); 00546 00551 buildComplementaryLinks (lPersistentBomRoot); 00552 00556 lSTDAIR_Service.updateAirlineFeatures(); 00557 00562 if (doesOwnStdairService == true) { 00563 00564 // 00565 clonePersistentBom (); 00566 } 00567 } 00568 00569 // //////////////////////////////////////////////////////////////////// 00570 void AIRINV_Service::clonePersistentBom () { 00571 00572 // Retrieve the AirInv service context 00573 if (_airinvServiceContext == NULL) { 00574 throw stdair::NonInitialisedServiceException("The AirInv service has not " 00575 "been initialised"); 00576 } 00577 assert (_airinvServiceContext != NULL); 00578 00579 // Retrieve the AirInv service context and whether it owns the Stdair 00580 // service 00581 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00582 const bool doesOwnStdairService = 00583 lAIRINV_ServiceContext.getOwnStdairServiceFlag(); 00584 00585 // Retrieve the StdAir service object from the (AirInv) service context 00586 stdair::STDAIR_Service& lSTDAIR_Service = 00587 lAIRINV_ServiceContext.getSTDAIR_Service(); 00588 00593 if (doesOwnStdairService == true) { 00594 00595 // 00596 lSTDAIR_Service.clonePersistentBom (); 00597 } 00598 00602 stdair::BomRoot& lBomRoot = 00603 lSTDAIR_Service.getBomRoot(); 00604 buildComplementaryLinks (lBomRoot); 00605 } 00606 00607 // //////////////////////////////////////////////////////////////////// 00608 void AIRINV_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) { 00609 00620 InventoryManager::createDirectAccesses (ioBomRoot); 00621 00626 InventoryManager::buildSimilarSegmentCabinSets (ioBomRoot); 00627 00631 InventoryManager::setDefaultBidPriceVector (ioBomRoot); 00632 00636 InventoryManager::initialiseYieldBasedNestingStructures (ioBomRoot); 00637 00641 InventoryManager::initialiseListsOfUsablePolicies (ioBomRoot); 00642 } 00643 00644 // //////////////////////////////////////////////////////////////////// 00645 std::string AIRINV_Service:: 00646 jsonHandler (const stdair::JSONString& iJSONString) const { 00647 00648 // 00649 // Extract from the JSON-ified string the command 00650 // 00651 stdair::JSonCommand::EN_JSonCommand lEN_JSonCommand; 00652 const bool hasCommandBeenRetrieved = 00653 stdair::BomJSONImport::jsonImportCommand (iJSONString, 00654 lEN_JSonCommand); 00655 00656 if (hasCommandBeenRetrieved == false) { 00657 // Return an error JSON-ified string 00658 std::ostringstream oErrorStream; 00659 oErrorStream << "{\"error\": \"Wrong JSON-ified string: " 00660 << "the command is not understood.\"}"; 00661 return oErrorStream.str(); 00662 } 00663 assert (hasCommandBeenRetrieved == true); 00664 00665 // 00666 // Extract from the JSON-ified string an airline code 00667 // 00668 stdair::AirlineCode_T lAirlineCode; 00669 const bool hasKeyBeenRetrieved = 00670 stdair::BomJSONImport::jsonImportInventoryKey (iJSONString, 00671 lAirlineCode); 00672 00673 if (hasKeyBeenRetrieved == false) { 00674 // Return an error JSON-ified string 00675 std::ostringstream oErrorStream; 00676 oErrorStream << "{\"error\": \"Wrong JSON-ified string: " 00677 << "the inventory key is not understood.\"}"; 00678 return oErrorStream.str(); 00679 } 00680 assert (hasKeyBeenRetrieved == true); 00681 00682 // 00683 // Extract from the JSON-ified string a flight number 00684 // 00685 stdair::FlightNumber_T lFlightNumber; 00686 const bool hasFlightNumBeenRetrieved = 00687 stdair::BomJSONImport::jsonImportFlightNumber (iJSONString, 00688 lFlightNumber); 00689 00690 if (hasFlightNumBeenRetrieved == false) { 00691 // Return an error JSON-ified string 00692 std::ostringstream oErrorStream; 00693 oErrorStream << "{\"error\": \"Wrong JSON-ified string: " 00694 << "the flight number is not understood.\"}"; 00695 return oErrorStream.str(); 00696 } 00697 assert (hasFlightNumBeenRetrieved == true); 00698 00699 switch (lEN_JSonCommand) { 00700 case stdair::JSonCommand::FLIGHT_DATE:{ 00701 00702 // Extract from the JSON-ified string a flight date 00703 stdair::Date_T lDate; 00704 const bool hasDateBeenRetrieved = 00705 stdair::BomJSONImport::jsonImportFlightDate (iJSONString, 00706 lDate); 00707 00708 if (hasDateBeenRetrieved == false) { 00709 // Return an error JSON-ified string 00710 std::ostringstream oErrorStream; 00711 oErrorStream << "{\"error\": \"Wrong JSON-ified string: " 00712 << "the flight date is not understood.\"}"; 00713 return oErrorStream.str(); 00714 } 00715 00716 // DEBUG 00717 STDAIR_LOG_DEBUG ("=> airline code = '" << lAirlineCode 00718 << "', flight number = " << lFlightNumber 00719 << "', departure date = '" << lDate << "'"); 00720 00721 // DEBUG: Display the flight-date details dump 00722 const std::string& lFlightDateDetailsCSVDump = 00723 csvDisplay (lAirlineCode, lFlightNumber, lDate); 00724 STDAIR_LOG_DEBUG (std::endl << lFlightDateDetailsCSVDump); 00725 00726 // Dump the full details of the flight-date into the JSON-ified flight-date 00727 const std::string& lFlightDateDetailsJSONDump = 00728 jsonExportFlightDateObjects (lAirlineCode, 00729 lFlightNumber, 00730 lDate); 00731 00732 // DEBUG 00733 STDAIR_LOG_DEBUG ("Send: '" << lFlightDateDetailsJSONDump << "'"); 00734 00735 return lFlightDateDetailsJSONDump; 00736 break; 00737 } 00738 case stdair::JSonCommand::LIST:{ 00739 00740 // DEBUG 00741 STDAIR_LOG_DEBUG ("=> airline code = '" << lAirlineCode 00742 << "', flight number = " << lFlightNumber << "'"); 00743 00744 // DEBUG: Display the flight-date list dump 00745 const std::string& lFlightDateListCSVDump = 00746 list (lAirlineCode, lFlightNumber); 00747 STDAIR_LOG_DEBUG (std::endl << lFlightDateListCSVDump); 00748 00749 // Dump the full list of the flight-date into the JSON-ified flight-date 00750 const std::string& lFlightDateListJSONDump = 00751 jsonExportFlightDateList (lAirlineCode, lFlightNumber); 00752 00753 // DEBUG 00754 STDAIR_LOG_DEBUG ("Send: '" << lFlightDateListCSVDump << "'"); 00755 00756 return lFlightDateListJSONDump; 00757 break; 00758 } 00759 default: { 00760 // Return an Error string 00761 std::ostringstream lErrorCmdMessage; 00762 const std::string& lCommandStr = 00763 stdair::JSonCommand::getLabel(lEN_JSonCommand); 00764 lErrorCmdMessage << "{\"error\": \"The command '" << lCommandStr 00765 << "' is not handled by the AirInv service.\"}"; 00766 return lErrorCmdMessage.str(); 00767 break; 00768 } 00769 } 00770 // Return an error JSON-ified string 00771 assert (false); 00772 std::string lJSONDump ("{\"error\": \"Wrong JSON-ified string\"}"); 00773 return lJSONDump; 00774 } 00775 00776 // //////////////////////////////////////////////////////////////////// 00777 std::string AIRINV_Service:: 00778 jsonExportFlightDateList (const stdair::AirlineCode_T& iAirlineCode, 00779 const stdair::FlightNumber_T& iFlightNumber) const { 00780 00781 // Retrieve the AIRINV service context 00782 if (_airinvServiceContext == NULL) { 00783 throw stdair::NonInitialisedServiceException ("The AirInv service " 00784 "has not been initialised"); 00785 } 00786 assert (_airinvServiceContext != NULL); 00787 00788 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00789 00790 // Retrieve the STDAIR service object from the (AIRINV) service context 00791 stdair::STDAIR_Service& lSTDAIR_Service = 00792 lAIRINV_ServiceContext.getSTDAIR_Service(); 00793 00794 // Delegate the JSON export to the dedicated service 00795 return lSTDAIR_Service.jsonExportFlightDateList (iAirlineCode, 00796 iFlightNumber); 00797 } 00798 00799 // //////////////////////////////////////////////////////////////////// 00800 std::string AIRINV_Service:: 00801 jsonExportFlightDateObjects (const stdair::AirlineCode_T& iAirlineCode, 00802 const stdair::FlightNumber_T& iFlightNumber, 00803 const stdair::Date_T& iDepartureDate) const { 00804 00805 // Retrieve the AIRINV service context 00806 if (_airinvServiceContext == NULL) { 00807 throw stdair::NonInitialisedServiceException ("The AirInv service " 00808 "has not been initialised"); 00809 } 00810 assert (_airinvServiceContext != NULL); 00811 00812 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00813 00814 // Retrieve the STDAIR service object from the (AIRINV) service context 00815 stdair::STDAIR_Service& lSTDAIR_Service = 00816 lAIRINV_ServiceContext.getSTDAIR_Service(); 00817 00818 // Delegate the JSON export to the dedicated service 00819 return lSTDAIR_Service.jsonExportFlightDateObjects (iAirlineCode, 00820 iFlightNumber, 00821 iDepartureDate); 00822 } 00823 00824 // //////////////////////////////////////////////////////////////////// 00825 std::string AIRINV_Service:: 00826 list (const stdair::AirlineCode_T& iAirlineCode, 00827 const stdair::FlightNumber_T& iFlightNumber) const { 00828 std::ostringstream oFlightListStr; 00829 00830 if (_airinvServiceContext == NULL) { 00831 throw stdair::NonInitialisedServiceException ("The AirInv service " 00832 "has not been initialised"); 00833 } 00834 assert (_airinvServiceContext != NULL); 00835 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00836 00837 // \todo Check that the current AIRINV_Service is actually operating for 00838 // the given airline 00839 00840 // Retrieve the STDAIR service object from the (AirInv) service context 00841 stdair::STDAIR_Service& lSTDAIR_Service = 00842 lAIRINV_ServiceContext.getSTDAIR_Service(); 00843 00844 // Delegate the BOM display to the dedicated service 00845 return lSTDAIR_Service.list (iAirlineCode, iFlightNumber); 00846 } 00847 00848 // //////////////////////////////////////////////////////////////////// 00849 bool AIRINV_Service:: 00850 check (const stdair::AirlineCode_T& iAirlineCode, 00851 const stdair::FlightNumber_T& iFlightNumber, 00852 const stdair::Date_T& iDepartureDate) const { 00853 std::ostringstream oFlightListStr; 00854 00855 if (_airinvServiceContext == NULL) { 00856 throw stdair::NonInitialisedServiceException ("The AirInv service " 00857 "has not been initialised"); 00858 } 00859 assert (_airinvServiceContext != NULL); 00860 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00861 00862 // \todo Check that the current AIRINV_Service is actually operating for 00863 // the given airline 00864 00865 // Retrieve the STDAIR service object from the (AirInv) service context 00866 stdair::STDAIR_Service& lSTDAIR_Service = 00867 lAIRINV_ServiceContext.getSTDAIR_Service(); 00868 00869 // Delegate the BOM display to the dedicated service 00870 return lSTDAIR_Service.check (iAirlineCode, iFlightNumber, iDepartureDate); 00871 } 00872 00873 // //////////////////////////////////////////////////////////////////// 00874 std::string AIRINV_Service::csvDisplay() const { 00875 00876 // Retrieve the AIRINV service context 00877 if (_airinvServiceContext == NULL) { 00878 throw stdair::NonInitialisedServiceException ("The AirInv service " 00879 "has not been initialised"); 00880 } 00881 assert (_airinvServiceContext != NULL); 00882 00883 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00884 00885 // Retrieve the STDAIR service object from the (AirInv) service context 00886 stdair::STDAIR_Service& lSTDAIR_Service = 00887 lAIRINV_ServiceContext.getSTDAIR_Service(); 00888 const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 00889 00890 // Delegate the BOM display to the dedicated service 00891 return lSTDAIR_Service.csvDisplay(lBomRoot); 00892 } 00893 00894 // //////////////////////////////////////////////////////////////////// 00895 std::string AIRINV_Service:: 00896 csvDisplay (const stdair::AirlineCode_T& iAirlineCode, 00897 const stdair::FlightNumber_T& iFlightNumber, 00898 const stdair::Date_T& iDepartureDate) const { 00899 00900 // Retrieve the AIRINV service context 00901 if (_airinvServiceContext == NULL) { 00902 throw stdair::NonInitialisedServiceException ("The AirInv service " 00903 "has not been initialised"); 00904 } 00905 assert (_airinvServiceContext != NULL); 00906 00907 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00908 00909 // Retrieve the STDAIR service object from the (AirInv) service context 00910 stdair::STDAIR_Service& lSTDAIR_Service = 00911 lAIRINV_ServiceContext.getSTDAIR_Service(); 00912 00913 // Delegate the BOM display to the dedicated service 00914 return lSTDAIR_Service.csvDisplay (iAirlineCode, iFlightNumber, 00915 iDepartureDate); 00916 } 00917 00918 // //////////////////////////////////////////////////////////////////// 00919 stdair::RMEventList_T AIRINV_Service:: 00920 initRMEvents (const stdair::Date_T& iStartDate, 00921 const stdair::Date_T& iEndDate) { 00922 00923 if (_airinvServiceContext == NULL) { 00924 throw stdair::NonInitialisedServiceException ("The AirInv service " 00925 "has not been initialised"); 00926 } 00927 assert (_airinvServiceContext != NULL); 00928 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00929 00930 // \todo Retrieve the corresponding inventory 00931 stdair::STDAIR_Service& lSTDAIR_Service = 00932 lAIRINV_ServiceContext.getSTDAIR_Service(); 00933 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 00934 00935 stdair::RMEventList_T oRMEventList; 00936 const stdair::InventoryList_T& lInventoryList = 00937 stdair::BomManager::getList<stdair::Inventory> (lBomRoot); 00938 for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin(); 00939 itInv != lInventoryList.end(); ++itInv) { 00940 const stdair::Inventory* lInv_ptr = *itInv; 00941 assert (lInv_ptr != NULL); 00942 00943 InventoryManager::initRMEvents (*lInv_ptr, oRMEventList, 00944 iStartDate, iEndDate); 00945 } 00946 00947 return oRMEventList; 00948 } 00949 00950 // //////////////////////////////////////////////////////////////////// 00951 void AIRINV_Service:: 00952 calculateAvailability (stdair::TravelSolutionStruct& ioTravelSolution) { 00953 00954 if (_airinvServiceContext == NULL) { 00955 throw stdair::NonInitialisedServiceException ("The AirInv service " 00956 "has not been initialised"); 00957 } 00958 assert (_airinvServiceContext != NULL); 00959 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00960 00961 // Retrieve the corresponding inventory. 00962 stdair::STDAIR_Service& lSTDAIR_Service = 00963 lAIRINV_ServiceContext.getSTDAIR_Service(); 00964 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 00965 00966 // Delegate the booking to the dedicated command 00967 stdair::BasChronometer lAvlChronometer; 00968 lAvlChronometer.start(); 00969 InventoryManager::calculateAvailability (lBomRoot, ioTravelSolution); 00970 // const double lAvlMeasure = lAvlChronometer.elapsed(); 00971 00972 // DEBUG 00973 // STDAIR_LOG_DEBUG ("Availability retrieval: " << lAvlMeasure << " - " 00974 // << lAIRINV_ServiceContext.display()); 00975 } 00976 00977 // //////////////////////////////////////////////////////////////////// 00978 bool AIRINV_Service::sell (const std::string& iSegmentDateKey, 00979 const stdair::ClassCode_T& iClassCode, 00980 const stdair::PartySize_T& iPartySize) { 00981 bool isSellSuccessful = false; 00982 00983 if (_airinvServiceContext == NULL) { 00984 throw stdair::NonInitialisedServiceException ("The AirInv service " 00985 "has not been initialised"); 00986 } 00987 assert (_airinvServiceContext != NULL); 00988 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 00989 00990 // \todo Check that the current AIRINV_Service is actually operating for 00991 // the given airline (inventory key) 00992 // Retrieve the corresponding inventory key 00993 const stdair::InventoryKey& lInventoryKey = 00994 stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey); 00995 00996 // Retrieve the root of the BOM tree 00997 stdair::STDAIR_Service& lSTDAIR_Service = 00998 lAIRINV_ServiceContext.getSTDAIR_Service(); 00999 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 01000 01001 // Retrieve the corresponding inventory 01002 stdair::Inventory& lInventory = stdair::BomManager:: 01003 getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString()); 01004 01005 // Delegate the booking to the dedicated command 01006 stdair::BasChronometer lSellChronometer; lSellChronometer.start(); 01007 isSellSuccessful = InventoryManager::sell (lInventory, iSegmentDateKey, 01008 iClassCode, iPartySize); 01009 // const double lSellMeasure = lSellChronometer.elapsed(); 01010 01011 // DEBUG 01012 // STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - " 01013 // << lAIRINV_ServiceContext.display()); 01014 01015 return isSellSuccessful; 01016 } 01017 01018 // //////////////////////////////////////////////////////////////////// 01019 bool AIRINV_Service::sell (const stdair::BookingClassID_T& iClassID, 01020 const stdair::PartySize_T& iPartySize) { 01021 bool isSellSuccessful = false; 01022 01023 // Delegate the booking to the dedicated command 01024 stdair::BasChronometer lSellChronometer; lSellChronometer.start(); 01025 isSellSuccessful = InventoryManager::sell (iClassID, iPartySize); 01026 // const double lSellMeasure = lSellChronometer.elapsed(); 01027 01028 // DEBUG 01029 // STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - " 01030 // << lAIRINV_ServiceContext.display()); 01031 01032 return isSellSuccessful; 01033 } 01034 01035 // //////////////////////////////////////////////////////////////////// 01036 bool AIRINV_Service::cancel (const std::string& iSegmentDateKey, 01037 const stdair::ClassCode_T& iClassCode, 01038 const stdair::PartySize_T& iPartySize) { 01039 bool isCancellationSuccessful = false; 01040 01041 if (_airinvServiceContext == NULL) { 01042 throw stdair::NonInitialisedServiceException ("The AirInv service " 01043 "has not been initialised"); 01044 } 01045 assert (_airinvServiceContext != NULL); 01046 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 01047 01048 // \todo Check that the current AIRINV_Service is actually operating for 01049 // the given airline (inventory key) 01050 // Retrieve the corresponding inventory key 01051 const stdair::InventoryKey& lInventoryKey = 01052 stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey); 01053 01054 // Retrieve the root of the BOM tree 01055 stdair::STDAIR_Service& lSTDAIR_Service = 01056 lAIRINV_ServiceContext.getSTDAIR_Service(); 01057 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 01058 01059 // Retrieve the corresponding inventory 01060 stdair::Inventory& lInventory = stdair::BomManager:: 01061 getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString()); 01062 01063 // Delegate the booking to the dedicated command 01064 stdair::BasChronometer lCancellationChronometer; 01065 lCancellationChronometer.start(); 01066 isCancellationSuccessful = InventoryManager::cancel (lInventory, 01067 iSegmentDateKey, 01068 iClassCode,iPartySize); 01069 // const double lCancellationMeasure = lCancellationChronometer.elapsed(); 01070 01071 // DEBUG 01072 // STDAIR_LOG_DEBUG ("Booking cancellation: " 01073 // << lCancellationMeasure << " - " 01074 // << lAIRINV_ServiceContext.display()); 01075 01076 return isCancellationSuccessful; 01077 } 01078 01079 // //////////////////////////////////////////////////////////////////// 01080 bool AIRINV_Service::cancel (const stdair::BookingClassID_T& iClassID, 01081 const stdair::PartySize_T& iPartySize) { 01082 bool isCancelSuccessful = false; 01083 01084 // Delegate the booking to the dedicated command 01085 stdair::BasChronometer lCancelChronometer; lCancelChronometer.start(); 01086 isCancelSuccessful = InventoryManager::cancel (iClassID, iPartySize); 01087 // const double lCancelMeasure = lCancelChronometer.elapsed(); 01088 01089 // DEBUG 01090 // STDAIR_LOG_DEBUG ("Booking cancel: " << lCancelMeasure << " - " 01091 // << lAIRINV_ServiceContext.display()); 01092 01093 return isCancelSuccessful; 01094 } 01095 01096 // //////////////////////////////////////////////////////////////////// 01097 void AIRINV_Service::takeSnapshots (const stdair::AirlineCode_T& iAirlineCode, 01098 const stdair::DateTime_T& iSnapshotTime) { 01099 01100 if (_airinvServiceContext == NULL) { 01101 throw stdair::NonInitialisedServiceException ("The AirInv service " 01102 "has not been initialised"); 01103 } 01104 assert (_airinvServiceContext != NULL); 01105 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 01106 01107 // TODO: Retrieve the corresponding inventory. 01108 stdair::STDAIR_Service& lSTDAIR_Service = 01109 lAIRINV_ServiceContext.getSTDAIR_Service(); 01110 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 01111 01112 const stdair::InventoryList_T lInventoryList = 01113 stdair::BomManager::getList<stdair::Inventory> (lBomRoot); 01114 for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin(); 01115 itInv != lInventoryList.end(); ++itInv) { 01116 const stdair::Inventory* lInv_ptr = *itInv; 01117 assert (lInv_ptr != NULL); 01118 01119 InventoryManager::takeSnapshots (*lInv_ptr, iSnapshotTime); 01120 } 01121 } 01122 01123 // //////////////////////////////////////////////////////////////////// 01124 void AIRINV_Service::optimise (const stdair::AirlineCode_T& iAirlineCode, 01125 const stdair::KeyDescription_T& iFDDescription, 01126 const stdair::DateTime_T& iRMEventTime) { 01127 01128 if (_airinvServiceContext == NULL) { 01129 throw stdair::NonInitialisedServiceException ("The AirInv service " 01130 "has not been initialised"); 01131 } 01132 assert (_airinvServiceContext != NULL); 01133 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext; 01134 01135 // Retrieve the corresponding inventory & flight-date 01136 stdair::STDAIR_Service& lSTDAIR_Service = 01137 lAIRINV_ServiceContext.getSTDAIR_Service(); 01138 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 01139 stdair::Inventory* lInventory_ptr = 01140 stdair::BomManager::getObjectPtr<stdair::Inventory> (lBomRoot, iAirlineCode); 01141 if (lInventory_ptr == NULL) { 01142 std::ostringstream oErrorMessage; 01143 oErrorMessage << "The Inventory '" << iAirlineCode 01144 << "', can not be retrieved."; 01145 STDAIR_LOG_ERROR (oErrorMessage.str()); 01146 throw InventoryNotFoundException (oErrorMessage.str()); 01147 } 01148 assert (lInventory_ptr != NULL); 01149 stdair::FlightDate* lFlightDate_ptr = 01150 stdair::BomManager::getObjectPtr<stdair::FlightDate> (*lInventory_ptr, 01151 iFDDescription); 01152 if (lFlightDate_ptr == NULL) { 01153 std::ostringstream oErrorMessage; 01154 oErrorMessage << "The flight date '" << iFDDescription 01155 << "', can not be retrieved in the '" 01156 << iAirlineCode << "' inventory."; 01157 STDAIR_LOG_ERROR (oErrorMessage.str()); 01158 throw FlightDateNotFoundException (oErrorMessage.str()); 01159 } 01160 assert (lFlightDate_ptr != NULL); 01161 01162 const stdair::UnconstrainingMethod& lUnconstrainingMethod = 01163 lInventory_ptr->getUnconstrainingMethod(); 01164 const stdair::ForecastingMethod& lForecastingMethod = 01165 lInventory_ptr->getForecastingMethod(); 01166 const stdair::PreOptimisationMethod& lPreOptimisationMethod = 01167 lInventory_ptr->getPreOptimisationMethod(); 01168 const stdair::OptimisationMethod& lOptimisationMethod = 01169 lInventory_ptr->getOptimisationMethod(); 01170 const stdair::PartnershipTechnique& lPartnershipTechnique = 01171 lInventory_ptr->getPartnershipTechnique(); 01172 01173 // Retrieve the RMOL service. 01174 RMOL::RMOL_Service& lRMOL_Service = lAIRINV_ServiceContext.getRMOL_Service(); 01175 01176 // Optimise the flight-date. 01177 bool isOptimised = lRMOL_Service.optimise (*lFlightDate_ptr, iRMEventTime, 01178 lUnconstrainingMethod, 01179 lForecastingMethod, 01180 lPreOptimisationMethod, 01181 lOptimisationMethod, 01182 lPartnershipTechnique); 01183 01184 const stdair::OptimisationMethod::EN_OptimisationMethod& lENOptimisationMethod = lOptimisationMethod.getMethod(); 01185 const bool isEMSRb = 01186 (lENOptimisationMethod == stdair::OptimisationMethod::LEG_BASED_EMSR_B); 01187 // Update the inventory with the new controls. 01188 // updateBookingControls uses bid price vector to set 01189 // the authorization level. But EMSRb sets directly the 01190 // authorization level and does not compute the bid price vector. 01191 // So if EMSRb is used, do not call updateBookingControls. 01192 if (isOptimised == true && isEMSRb == false) { 01193 InventoryManager::updateBookingControls (*lFlightDate_ptr); 01194 InventoryManager::recalculateAvailability (*lFlightDate_ptr); 01195 } 01196 } 01197 }