AirInv Logo  1.00.10
C++ Simulated Airline Inventory Management System Library
Loading...
Searching...
No Matches
AIRINV_Service.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6// Boost
7#include <boost/make_shared.hpp>
8// StdAir
9#include <stdair/stdair_json.hpp>
10#include <stdair/basic/BasChronometer.hpp>
11#include <stdair/basic/JSonCommand.hpp>
12#include <stdair/basic/PartnershipTechnique.hpp>
13#include <stdair/basic/UnconstrainingMethod.hpp>
14#include <stdair/basic/OptimisationMethod.hpp>
15#include <stdair/bom/BomKeyManager.hpp>
16#include <stdair/bom/BomManager.hpp>
17#include <stdair/bom/BomRoot.hpp>
18#include <stdair/bom/Inventory.hpp>
19#include <stdair/bom/FlightDate.hpp>
20#include <stdair/bom/SegmentCabin.hpp>
21#include <stdair/bom/AirlineFeature.hpp>
22#include <stdair/bom/RMEventStruct.hpp>
23#include <stdair/bom/BomJSONImport.hpp>
24#include <stdair/bom/BomJSONExport.hpp>
25#include <stdair/factory/FacBomManager.hpp>
26#include <stdair/service/Logger.hpp>
27#include <stdair/STDAIR_Service.hpp>
28// RMOL
29#include <rmol/RMOL_Service.hpp>
30// AirRAC
31#include <airrac/AIRRAC_Service.hpp>
32// SEvMgr
33#include <sevmgr/SEVMGR_Service.hpp>
34// AirInv
45
46namespace AIRINV {
47
48 // ////////////////////////////////////////////////////////////////////
49 AIRINV_Service::AIRINV_Service () : _airinvServiceContext (NULL) {
50 assert (false);
51 }
52
53 // ////////////////////////////////////////////////////////////////////
54 AIRINV_Service::AIRINV_Service (const AIRINV_Service& iService)
55 : _airinvServiceContext (NULL) {
56 assert (false);
57 }
58
59 // ////////////////////////////////////////////////////////////////////
60 AIRINV_Service::AIRINV_Service (const stdair::BasLogParams& iLogParams)
61 : _airinvServiceContext (NULL) {
62
63 // Initialise the STDAIR service handler
64 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
65 initStdAirService (iLogParams);
66
67 // Initialise the service context
68 initServiceContext();
69
70 // Add the StdAir service context to the AIRINV service context
71 // \note AIRINV owns the STDAIR service resources here.
72 const bool ownStdairService = true;
73 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
74
75 // Initalise the RMOL service.
76 initRMOLService();
77
78 // Initalise the AIRRAC service.
79 initAIRRACService();
80
81 // Initalise the SEvMgr service.
82 initSEVMGRService();
83
84 // Initialise the (remaining of the) context
85 initAirinvService();
86 }
87
88 // ////////////////////////////////////////////////////////////////////
89 AIRINV_Service::AIRINV_Service (const stdair::BasLogParams& iLogParams,
90 const stdair::BasDBParams& iDBParams)
91 : _airinvServiceContext (NULL) {
92
93 // Initialise the STDAIR service handler
94 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
95 initStdAirService (iLogParams, iDBParams);
96
97 // Initialise the service context
98 initServiceContext();
99
100 // Add the StdAir service context to the AIRINV service context
101 // \note AIRINV owns the STDAIR service resources here.
102 const bool ownStdairService = true;
103 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
104
105 // Initalise the RMOL service.
106 initRMOLService();
107
108 // Initalise the AIRRAC service.
109 initAIRRACService();
110
111 // Initalise the SEVMGR service.
112 initSEVMGRService();
113
114 // Initialise the (remaining of the) context
115 initAirinvService();
116 }
117
118 // //////////////////////////////////////////////////////////////////////
119 AIRINV_Service::
120 AIRINV_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
121
122 : _airinvServiceContext (NULL) {
123
124 // Initialise the service context
125 initServiceContext();
126
127 // Store the STDAIR service object within the (AIRINV) service context
128 // \note AirInv does not own the STDAIR service resources here.
129 const bool doesNotOwnStdairService = false;
130 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
131
132 // Initalise the RMOL service.
133 initRMOLService();
134
135 // Initalise the AIRRAC service.
136 initAIRRACService();
137
138 // Initalise the SEVMGR service.
139 initSEVMGRService();
140
141 // Initialise the (remaining of the) context
142 initAirinvService();
143
144 }
145
146 // //////////////////////////////////////////////////////////////////////
147 AIRINV_Service::
148 AIRINV_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
149 SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr)
150
151 : _airinvServiceContext (NULL) {
152
153 // Initialise the service context
154 initServiceContext();
155
156 // Store the STDAIR service object within the (AIRINV) service context
157 // \note AirInv does not own the STDAIR service resources here.
158 const bool doesNotOwnStdairService = false;
159 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
160
161 //Add the SEvMgr service to the TRADEMGEN service context.
162 const bool doesNotOwnSEVMGRService = false;
163 addSEVMGRService (ioSEVMGR_Service_ptr, doesNotOwnSEVMGRService);
164
165 // Initalise the RMOL service.
166 initRMOLService();
167
168 // Initalise the AIRRAC service.
169 initAIRRACService();
170
171 // Initialise the (remaining of the) context
172 initAirinvService();
173
174 }
175
176 // ////////////////////////////////////////////////////////////////////
178 // Delete/Clean all the objects from memory
179 finalise();
180 }
181
182 // ////////////////////////////////////////////////////////////////////
183 void AIRINV_Service::finalise() {
184 assert (_airinvServiceContext != NULL);
185 // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
186 _airinvServiceContext->reset();
187 }
188
189 // ////////////////////////////////////////////////////////////////////
190 void AIRINV_Service::initServiceContext() {
191 // Initialise the context
192 AIRINV_ServiceContext& lAIRINV_ServiceContext =
194 _airinvServiceContext = &lAIRINV_ServiceContext;
195 }
196
197 // ////////////////////////////////////////////////////////////////////
198 void AIRINV_Service::
199 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
200 const bool iOwnStdairService) {
201
202 // Retrieve the Airinv service context
203 assert (_airinvServiceContext != NULL);
204 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
205
206 // Store the STDAIR service object within the (AIRINV) service context
207 lAIRINV_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
208 iOwnStdairService);
209 }
210
211 // ////////////////////////////////////////////////////////////////////
212 void AIRINV_Service::
213 addSEVMGRService (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr,
214 const bool iOwnSEVMGRService) {
215
216 // Retrieve the Airinv service context
217 assert (_airinvServiceContext != NULL);
218 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
219
220 // Store the STDAIR service object within the (TRADEMGEN) service context
221 lAIRINV_ServiceContext.setSEVMGR_Service (ioSEVMGR_Service_ptr,
222 iOwnSEVMGRService);
223 }
224
225 // ////////////////////////////////////////////////////////////////////
226 stdair::STDAIR_ServicePtr_T AIRINV_Service::
227 initStdAirService (const stdair::BasLogParams& iLogParams,
228 const stdair::BasDBParams& iDBParams) {
229
237 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
238 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
239
240 return lSTDAIR_Service_ptr;
241 }
242
243 // ////////////////////////////////////////////////////////////////////
244 stdair::STDAIR_ServicePtr_T AIRINV_Service::
245 initStdAirService (const stdair::BasLogParams& iLogParams) {
246
254 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
255 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
256
257 return lSTDAIR_Service_ptr;
258 }
259
260 // ////////////////////////////////////////////////////////////////////
261 void AIRINV_Service::initRMOLService() {
262
263 // Retrieve the AirInv service context
264 assert (_airinvServiceContext != NULL);
265 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
266
267 // Retrieve the StdAir service context
268 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
269 lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
270
278 RMOL::RMOL_ServicePtr_T lRMOL_Service_ptr =
279 boost::make_shared<RMOL::RMOL_Service> (lSTDAIR_Service_ptr);
280
281 // Store the RMOL service object within the (AIRINV) service context
282 lAIRINV_ServiceContext.setRMOL_Service (lRMOL_Service_ptr);
283 }
284
285 // ////////////////////////////////////////////////////////////////////
286 void AIRINV_Service::initAIRRACService() {
287
288 // Retrieve the AirInv service context
289 assert (_airinvServiceContext != NULL);
290 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
291
292 // Retrieve the StdAir service context
293 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
294 lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
295
303 AIRRAC::AIRRAC_ServicePtr_T lAIRRAC_Service_ptr =
304 boost::make_shared<AIRRAC::AIRRAC_Service> (lSTDAIR_Service_ptr);
305
306 // Store the AIRRAC service object within the (AIRINV) service context
307 lAIRINV_ServiceContext.setAIRRAC_Service (lAIRRAC_Service_ptr);
308 }
309
310 // ////////////////////////////////////////////////////////////////////
311 void AIRINV_Service::initSEVMGRService() {
312
313 // Retrieve the AIRINV service context
314 assert (_airinvServiceContext != NULL);
315 AIRINV_ServiceContext& lAIRINV_ServiceContext =
316 *_airinvServiceContext;
317
318 // Retrieve the StdAir service context
319 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
320 lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
321
329 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
330 boost::make_shared<SEVMGR::SEVMGR_Service> (lSTDAIR_Service_ptr);
331
332 // Store the SEvMgr service object within the (TraDemGen) service context
333 const bool doesOwnSEVMGRService = true;
334 lAIRINV_ServiceContext.setSEVMGR_Service (lSEVMGR_Service_ptr,
335 doesOwnSEVMGRService);
336 }
337
338 // ////////////////////////////////////////////////////////////////////
339 void AIRINV_Service::initAirinvService() {
340 // Do nothing at this stage. A sample BOM tree may be built by
341 // calling the buildSampleBom() method
342 }
343
344 // ////////////////////////////////////////////////////////////////////
346 parseAndLoad (const AIRINV::InventoryFilePath& iInventoryInputFilename) {
347
348 // Retrieve the AirInv service context
349 if (_airinvServiceContext == NULL) {
350 throw stdair::NonInitialisedServiceException("The AirInv service has not "
351 "been initialised");
352 }
353 assert (_airinvServiceContext != NULL);
354
355 // Retrieve the AirInv service context and whether it owns the Stdair
356 // service
357 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
358 const bool doesOwnStdairService =
359 lAIRINV_ServiceContext.getOwnStdairServiceFlag();
360
361 // Retrieve the StdAir service object from the (AirInv) service context
362 stdair::STDAIR_Service& lSTDAIR_Service =
363 lAIRINV_ServiceContext.getSTDAIR_Service();
364
365 // Retrieve the persistent BOM root object.
366 stdair::BomRoot& lPersistentBomRoot =
367 lSTDAIR_Service.getPersistentBomRoot();
368
372 InventoryParser::buildInventory (iInventoryInputFilename,
373 lPersistentBomRoot);
374
378 InventoryBuilder::buildPartnerInventories (lPersistentBomRoot);
379
383 lSTDAIR_Service.updateAirlineFeatures();
384
389 buildComplementaryLinks (lPersistentBomRoot);
390
395 if (doesOwnStdairService == true) {
396
397 //
399 }
400 }
401
402 // ////////////////////////////////////////////////////////////////////
404 parseAndLoad (const stdair::ScheduleFilePath& iScheduleInputFilename,
405 const stdair::ODFilePath& iODInputFilename,
406 const stdair::FRAT5FilePath& iFRAT5InputFilename,
407 const stdair::FFDisutilityFilePath& iFFDisutilityInputFilename,
408 const AIRRAC::YieldFilePath& iYieldFilename) {
409
410 // Retrieve the AirInv service context
411 if (_airinvServiceContext == NULL) {
412 throw stdair::NonInitialisedServiceException("The AirInv service has not "
413 "been initialised");
414 }
415 assert (_airinvServiceContext != NULL);
416
417 // Retrieve the AirInv service context and whether it owns the Stdair
418 // service
419 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
420 const bool doesOwnStdairService =
421 lAIRINV_ServiceContext.getOwnStdairServiceFlag();
422
423 // Retrieve the StdAir service object from the (AirInv) service context
424 stdair::STDAIR_Service& lSTDAIR_Service =
425 lAIRINV_ServiceContext.getSTDAIR_Service();
426
427 // Retrieve the perssitent BOM root object.
428 stdair::BomRoot& lPersistentBomRoot =
429 lSTDAIR_Service.getPersistentBomRoot();
430
434 FRAT5Parser::parse (iFRAT5InputFilename, lPersistentBomRoot);
435 FFDisutilityParser::parse (iFFDisutilityInputFilename, lPersistentBomRoot);
436 ScheduleParser::generateInventories (iScheduleInputFilename,
437 lPersistentBomRoot);
438
442 InventoryBuilder::buildPartnerInventories (lPersistentBomRoot);
443
447 lSTDAIR_Service.updateAirlineFeatures();
448
453 buildComplementaryLinks (lPersistentBomRoot);
454
463 AIRRAC::AIRRAC_Service& lAIRRAC_Service =
464 lAIRINV_ServiceContext.getAIRRAC_Service();
465 lAIRRAC_Service.parseAndLoad (iYieldFilename);
473 lAIRRAC_Service.updateYields(lPersistentBomRoot);
474
479 if (doesOwnStdairService == true) {
480
481 //
483 }
484 }
485
486 // ////////////////////////////////////////////////////////////////////
488
489 // Retrieve the AirInv service context
490 if (_airinvServiceContext == NULL) {
491 throw stdair::NonInitialisedServiceException("The AirInv service has not "
492 "been initialised");
493 }
494 assert (_airinvServiceContext != NULL);
495
496 // Retrieve the AirInv service context and whether it owns the Stdair
497 // service
498 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
499 const bool doesOwnStdairService =
500 lAIRINV_ServiceContext.getOwnStdairServiceFlag();
501
502 // Retrieve the StdAir service object from the (AirInv) service context
503 stdair::STDAIR_Service& lSTDAIR_Service =
504 lAIRINV_ServiceContext.getSTDAIR_Service();
505
506 // Retrieve the perssitent BOM root object.
507 stdair::BomRoot& lPersistentBomRoot =
508 lSTDAIR_Service.getPersistentBomRoot();
509
514 if (doesOwnStdairService == true) {
515 //
516 lSTDAIR_Service.buildSampleBom();
517 }
518
529 AIRRAC::AIRRAC_Service& lAIRRAC_Service =
530 lAIRINV_ServiceContext.getAIRRAC_Service();
531 lAIRRAC_Service.buildSampleBom();
532
538 RMOL::RMOL_Service& lRMOL_Service =
539 lAIRINV_ServiceContext.getRMOL_Service();
540 lRMOL_Service.buildSampleBom();
541
545 InventoryBuilder::buildPartnerInventories (lPersistentBomRoot);
546
551 buildComplementaryLinks (lPersistentBomRoot);
552
556 lSTDAIR_Service.updateAirlineFeatures();
557
562 if (doesOwnStdairService == true) {
563
564 //
566 }
567 }
568
569 // ////////////////////////////////////////////////////////////////////
571
572 // Retrieve the AirInv service context
573 if (_airinvServiceContext == NULL) {
574 throw stdair::NonInitialisedServiceException("The AirInv service has not "
575 "been initialised");
576 }
577 assert (_airinvServiceContext != NULL);
578
579 // Retrieve the AirInv service context and whether it owns the Stdair
580 // service
581 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
582 const bool doesOwnStdairService =
583 lAIRINV_ServiceContext.getOwnStdairServiceFlag();
584
585 // Retrieve the StdAir service object from the (AirInv) service context
586 stdair::STDAIR_Service& lSTDAIR_Service =
587 lAIRINV_ServiceContext.getSTDAIR_Service();
588
593 if (doesOwnStdairService == true) {
594
595 //
596 lSTDAIR_Service.clonePersistentBom ();
597 }
598
602 stdair::BomRoot& lBomRoot =
603 lSTDAIR_Service.getBomRoot();
604 buildComplementaryLinks (lBomRoot);
605 }
606
607 // ////////////////////////////////////////////////////////////////////
643
644 // ////////////////////////////////////////////////////////////////////
646 jsonHandler (const stdair::JSONString& iJSONString) const {
647
648 //
649 // Extract from the JSON-ified string the command
650 //
651 stdair::JSonCommand::EN_JSonCommand lEN_JSonCommand;
652 const bool hasCommandBeenRetrieved =
653 stdair::BomJSONImport::jsonImportCommand (iJSONString,
654 lEN_JSonCommand);
655
656 if (hasCommandBeenRetrieved == false) {
657 // Return an error JSON-ified string
658 std::ostringstream oErrorStream;
659 oErrorStream << "{\"error\": \"Wrong JSON-ified string: "
660 << "the command is not understood.\"}";
661 return oErrorStream.str();
662 }
663 assert (hasCommandBeenRetrieved == true);
664
665 //
666 // Extract from the JSON-ified string an airline code
667 //
668 stdair::AirlineCode_T lAirlineCode;
669 const bool hasKeyBeenRetrieved =
670 stdair::BomJSONImport::jsonImportInventoryKey (iJSONString,
671 lAirlineCode);
672
673 if (hasKeyBeenRetrieved == false) {
674 // Return an error JSON-ified string
675 std::ostringstream oErrorStream;
676 oErrorStream << "{\"error\": \"Wrong JSON-ified string: "
677 << "the inventory key is not understood.\"}";
678 return oErrorStream.str();
679 }
680 assert (hasKeyBeenRetrieved == true);
681
682 //
683 // Extract from the JSON-ified string a flight number
684 //
685 stdair::FlightNumber_T lFlightNumber;
686 const bool hasFlightNumBeenRetrieved =
687 stdair::BomJSONImport::jsonImportFlightNumber (iJSONString,
688 lFlightNumber);
689
690 if (hasFlightNumBeenRetrieved == false) {
691 // Return an error JSON-ified string
692 std::ostringstream oErrorStream;
693 oErrorStream << "{\"error\": \"Wrong JSON-ified string: "
694 << "the flight number is not understood.\"}";
695 return oErrorStream.str();
696 }
697 assert (hasFlightNumBeenRetrieved == true);
698
699 switch (lEN_JSonCommand) {
700 case stdair::JSonCommand::FLIGHT_DATE:{
701
702 // Extract from the JSON-ified string a flight date
703 stdair::Date_T lDate;
704 const bool hasDateBeenRetrieved =
705 stdair::BomJSONImport::jsonImportFlightDate (iJSONString,
706 lDate);
707
708 if (hasDateBeenRetrieved == false) {
709 // Return an error JSON-ified string
710 std::ostringstream oErrorStream;
711 oErrorStream << "{\"error\": \"Wrong JSON-ified string: "
712 << "the flight date is not understood.\"}";
713 return oErrorStream.str();
714 }
715
716 // DEBUG
717 STDAIR_LOG_DEBUG ("=> airline code = '" << lAirlineCode
718 << "', flight number = " << lFlightNumber
719 << "', departure date = '" << lDate << "'");
720
721 // DEBUG: Display the flight-date details dump
722 const std::string& lFlightDateDetailsCSVDump =
723 csvDisplay (lAirlineCode, lFlightNumber, lDate);
724 STDAIR_LOG_DEBUG (std::endl << lFlightDateDetailsCSVDump);
725
726 // Dump the full details of the flight-date into the JSON-ified flight-date
727 const std::string& lFlightDateDetailsJSONDump =
728 jsonExportFlightDateObjects (lAirlineCode,
729 lFlightNumber,
730 lDate);
731
732 // DEBUG
733 STDAIR_LOG_DEBUG ("Send: '" << lFlightDateDetailsJSONDump << "'");
734
735 return lFlightDateDetailsJSONDump;
736 break;
737 }
738 case stdair::JSonCommand::LIST:{
739
740 // DEBUG
741 STDAIR_LOG_DEBUG ("=> airline code = '" << lAirlineCode
742 << "', flight number = " << lFlightNumber << "'");
743
744 // DEBUG: Display the flight-date list dump
745 const std::string& lFlightDateListCSVDump =
746 list (lAirlineCode, lFlightNumber);
747 STDAIR_LOG_DEBUG (std::endl << lFlightDateListCSVDump);
748
749 // Dump the full list of the flight-date into the JSON-ified flight-date
750 const std::string& lFlightDateListJSONDump =
751 jsonExportFlightDateList (lAirlineCode, lFlightNumber);
752
753 // DEBUG
754 STDAIR_LOG_DEBUG ("Send: '" << lFlightDateListCSVDump << "'");
755
756 return lFlightDateListJSONDump;
757 break;
758 }
759 default: {
760 // Return an Error string
761 std::ostringstream lErrorCmdMessage;
762 const std::string& lCommandStr =
763 stdair::JSonCommand::getLabel(lEN_JSonCommand);
764 lErrorCmdMessage << "{\"error\": \"The command '" << lCommandStr
765 << "' is not handled by the AirInv service.\"}";
766 return lErrorCmdMessage.str();
767 break;
768 }
769 }
770 // Return an error JSON-ified string
771 assert (false);
772 std::string lJSONDump ("{\"error\": \"Wrong JSON-ified string\"}");
773 return lJSONDump;
774 }
775
776 // ////////////////////////////////////////////////////////////////////
778 jsonExportFlightDateList (const stdair::AirlineCode_T& iAirlineCode,
779 const stdair::FlightNumber_T& iFlightNumber) const {
780
781 // Retrieve the AIRINV service context
782 if (_airinvServiceContext == NULL) {
783 throw stdair::NonInitialisedServiceException ("The AirInv service "
784 "has not been initialised");
785 }
786 assert (_airinvServiceContext != NULL);
787
788 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
789
790 // Retrieve the STDAIR service object from the (AIRINV) service context
791 stdair::STDAIR_Service& lSTDAIR_Service =
792 lAIRINV_ServiceContext.getSTDAIR_Service();
793
794 // Delegate the JSON export to the dedicated service
795 return lSTDAIR_Service.jsonExportFlightDateList (iAirlineCode,
796 iFlightNumber);
797 }
798
799 // ////////////////////////////////////////////////////////////////////
801 jsonExportFlightDateObjects (const stdair::AirlineCode_T& iAirlineCode,
802 const stdair::FlightNumber_T& iFlightNumber,
803 const stdair::Date_T& iDepartureDate) const {
804
805 // Retrieve the AIRINV service context
806 if (_airinvServiceContext == NULL) {
807 throw stdair::NonInitialisedServiceException ("The AirInv service "
808 "has not been initialised");
809 }
810 assert (_airinvServiceContext != NULL);
811
812 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
813
814 // Retrieve the STDAIR service object from the (AIRINV) service context
815 stdair::STDAIR_Service& lSTDAIR_Service =
816 lAIRINV_ServiceContext.getSTDAIR_Service();
817
818 // Delegate the JSON export to the dedicated service
819 return lSTDAIR_Service.jsonExportFlightDateObjects (iAirlineCode,
820 iFlightNumber,
821 iDepartureDate);
822 }
823
824 // ////////////////////////////////////////////////////////////////////
826 list (const stdair::AirlineCode_T& iAirlineCode,
827 const stdair::FlightNumber_T& iFlightNumber) const {
828 std::ostringstream oFlightListStr;
829
830 if (_airinvServiceContext == NULL) {
831 throw stdair::NonInitialisedServiceException ("The AirInv service "
832 "has not been initialised");
833 }
834 assert (_airinvServiceContext != NULL);
835 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
836
837 // \todo Check that the current AIRINV_Service is actually operating for
838 // the given airline
839
840 // Retrieve the STDAIR service object from the (AirInv) service context
841 stdair::STDAIR_Service& lSTDAIR_Service =
842 lAIRINV_ServiceContext.getSTDAIR_Service();
843
844 // Delegate the BOM display to the dedicated service
845 return lSTDAIR_Service.list (iAirlineCode, iFlightNumber);
846 }
847
848 // ////////////////////////////////////////////////////////////////////
850 check (const stdair::AirlineCode_T& iAirlineCode,
851 const stdair::FlightNumber_T& iFlightNumber,
852 const stdair::Date_T& iDepartureDate) const {
853 std::ostringstream oFlightListStr;
854
855 if (_airinvServiceContext == NULL) {
856 throw stdair::NonInitialisedServiceException ("The AirInv service "
857 "has not been initialised");
858 }
859 assert (_airinvServiceContext != NULL);
860 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
861
862 // \todo Check that the current AIRINV_Service is actually operating for
863 // the given airline
864
865 // Retrieve the STDAIR service object from the (AirInv) service context
866 stdair::STDAIR_Service& lSTDAIR_Service =
867 lAIRINV_ServiceContext.getSTDAIR_Service();
868
869 // Delegate the BOM display to the dedicated service
870 return lSTDAIR_Service.check (iAirlineCode, iFlightNumber, iDepartureDate);
871 }
872
873 // ////////////////////////////////////////////////////////////////////
874 std::string AIRINV_Service::csvDisplay() const {
875
876 // Retrieve the AIRINV service context
877 if (_airinvServiceContext == NULL) {
878 throw stdair::NonInitialisedServiceException ("The AirInv service "
879 "has not been initialised");
880 }
881 assert (_airinvServiceContext != NULL);
882
883 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
884
885 // Retrieve the STDAIR service object from the (AirInv) service context
886 stdair::STDAIR_Service& lSTDAIR_Service =
887 lAIRINV_ServiceContext.getSTDAIR_Service();
888 const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
889
890 // Delegate the BOM display to the dedicated service
891 return lSTDAIR_Service.csvDisplay(lBomRoot);
892 }
893
894 // ////////////////////////////////////////////////////////////////////
896 csvDisplay (const stdair::AirlineCode_T& iAirlineCode,
897 const stdair::FlightNumber_T& iFlightNumber,
898 const stdair::Date_T& iDepartureDate) const {
899
900 // Retrieve the AIRINV service context
901 if (_airinvServiceContext == NULL) {
902 throw stdair::NonInitialisedServiceException ("The AirInv service "
903 "has not been initialised");
904 }
905 assert (_airinvServiceContext != NULL);
906
907 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
908
909 // Retrieve the STDAIR service object from the (AirInv) service context
910 stdair::STDAIR_Service& lSTDAIR_Service =
911 lAIRINV_ServiceContext.getSTDAIR_Service();
912
913 // Delegate the BOM display to the dedicated service
914 return lSTDAIR_Service.csvDisplay (iAirlineCode, iFlightNumber,
915 iDepartureDate);
916 }
917
918 // ////////////////////////////////////////////////////////////////////
919 stdair::RMEventList_T AIRINV_Service::
920 initRMEvents (const stdair::Date_T& iStartDate,
921 const stdair::Date_T& iEndDate) {
922
923 if (_airinvServiceContext == NULL) {
924 throw stdair::NonInitialisedServiceException ("The AirInv service "
925 "has not been initialised");
926 }
927 assert (_airinvServiceContext != NULL);
928 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
929
930 // \todo Retrieve the corresponding inventory
931 stdair::STDAIR_Service& lSTDAIR_Service =
932 lAIRINV_ServiceContext.getSTDAIR_Service();
933 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
934
935 stdair::RMEventList_T oRMEventList;
936 const stdair::InventoryList_T& lInventoryList =
937 stdair::BomManager::getList<stdair::Inventory> (lBomRoot);
938 for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
939 itInv != lInventoryList.end(); ++itInv) {
940 const stdair::Inventory* lInv_ptr = *itInv;
941 assert (lInv_ptr != NULL);
942
943 InventoryManager::initRMEvents (*lInv_ptr, oRMEventList,
944 iStartDate, iEndDate);
945 }
946
947 return oRMEventList;
948 }
949
950 // ////////////////////////////////////////////////////////////////////
952 calculateAvailability (stdair::TravelSolutionStruct& ioTravelSolution) {
953
954 if (_airinvServiceContext == NULL) {
955 throw stdair::NonInitialisedServiceException ("The AirInv service "
956 "has not been initialised");
957 }
958 assert (_airinvServiceContext != NULL);
959 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
960
961 // Retrieve the corresponding inventory.
962 stdair::STDAIR_Service& lSTDAIR_Service =
963 lAIRINV_ServiceContext.getSTDAIR_Service();
964 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
965
966 // Delegate the booking to the dedicated command
967 stdair::BasChronometer lAvlChronometer;
968 lAvlChronometer.start();
969 InventoryManager::calculateAvailability (lBomRoot, ioTravelSolution);
970 // const double lAvlMeasure = lAvlChronometer.elapsed();
971
972 // DEBUG
973 // STDAIR_LOG_DEBUG ("Availability retrieval: " << lAvlMeasure << " - "
974 // << lAIRINV_ServiceContext.display());
975 }
976
977 // ////////////////////////////////////////////////////////////////////
978 bool AIRINV_Service::sell (const std::string& iSegmentDateKey,
979 const stdair::ClassCode_T& iClassCode,
980 const stdair::PartySize_T& iPartySize) {
981 bool isSellSuccessful = false;
982
983 if (_airinvServiceContext == NULL) {
984 throw stdair::NonInitialisedServiceException ("The AirInv service "
985 "has not been initialised");
986 }
987 assert (_airinvServiceContext != NULL);
988 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
989
990 // \todo Check that the current AIRINV_Service is actually operating for
991 // the given airline (inventory key)
992 // Retrieve the corresponding inventory key
993 const stdair::InventoryKey& lInventoryKey =
994 stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
995
996 // Retrieve the root of the BOM tree
997 stdair::STDAIR_Service& lSTDAIR_Service =
998 lAIRINV_ServiceContext.getSTDAIR_Service();
999 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
1000
1001 // Retrieve the corresponding inventory
1002 stdair::Inventory& lInventory = stdair::BomManager::
1003 getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString());
1004
1005 // Delegate the booking to the dedicated command
1006 stdair::BasChronometer lSellChronometer; lSellChronometer.start();
1007 isSellSuccessful = InventoryManager::sell (lInventory, iSegmentDateKey,
1008 iClassCode, iPartySize);
1009 // const double lSellMeasure = lSellChronometer.elapsed();
1010
1011 // DEBUG
1012 // STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - "
1013 // << lAIRINV_ServiceContext.display());
1014
1015 return isSellSuccessful;
1016 }
1017
1018 // ////////////////////////////////////////////////////////////////////
1019 bool AIRINV_Service::sell (const stdair::BookingClassID_T& iClassID,
1020 const stdair::PartySize_T& iPartySize) {
1021 bool isSellSuccessful = false;
1022
1023 // Delegate the booking to the dedicated command
1024 stdair::BasChronometer lSellChronometer; lSellChronometer.start();
1025 isSellSuccessful = InventoryManager::sell (iClassID, iPartySize);
1026 // const double lSellMeasure = lSellChronometer.elapsed();
1027
1028 // DEBUG
1029 // STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - "
1030 // << lAIRINV_ServiceContext.display());
1031
1032 return isSellSuccessful;
1033 }
1034
1035 // ////////////////////////////////////////////////////////////////////
1036 bool AIRINV_Service::cancel (const std::string& iSegmentDateKey,
1037 const stdair::ClassCode_T& iClassCode,
1038 const stdair::PartySize_T& iPartySize) {
1039 bool isCancellationSuccessful = false;
1040
1041 if (_airinvServiceContext == NULL) {
1042 throw stdair::NonInitialisedServiceException ("The AirInv service "
1043 "has not been initialised");
1044 }
1045 assert (_airinvServiceContext != NULL);
1046 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
1047
1048 // \todo Check that the current AIRINV_Service is actually operating for
1049 // the given airline (inventory key)
1050 // Retrieve the corresponding inventory key
1051 const stdair::InventoryKey& lInventoryKey =
1052 stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
1053
1054 // Retrieve the root of the BOM tree
1055 stdair::STDAIR_Service& lSTDAIR_Service =
1056 lAIRINV_ServiceContext.getSTDAIR_Service();
1057 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
1058
1059 // Retrieve the corresponding inventory
1060 stdair::Inventory& lInventory = stdair::BomManager::
1061 getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString());
1062
1063 // Delegate the booking to the dedicated command
1064 stdair::BasChronometer lCancellationChronometer;
1065 lCancellationChronometer.start();
1066 isCancellationSuccessful = InventoryManager::cancel (lInventory,
1067 iSegmentDateKey,
1068 iClassCode,iPartySize);
1069 // const double lCancellationMeasure = lCancellationChronometer.elapsed();
1070
1071 // DEBUG
1072 // STDAIR_LOG_DEBUG ("Booking cancellation: "
1073 // << lCancellationMeasure << " - "
1074 // << lAIRINV_ServiceContext.display());
1075
1076 return isCancellationSuccessful;
1077 }
1078
1079 // ////////////////////////////////////////////////////////////////////
1080 bool AIRINV_Service::cancel (const stdair::BookingClassID_T& iClassID,
1081 const stdair::PartySize_T& iPartySize) {
1082 bool isCancelSuccessful = false;
1083
1084 // Delegate the booking to the dedicated command
1085 stdair::BasChronometer lCancelChronometer; lCancelChronometer.start();
1086 isCancelSuccessful = InventoryManager::cancel (iClassID, iPartySize);
1087 // const double lCancelMeasure = lCancelChronometer.elapsed();
1088
1089 // DEBUG
1090 // STDAIR_LOG_DEBUG ("Booking cancel: " << lCancelMeasure << " - "
1091 // << lAIRINV_ServiceContext.display());
1092
1093 return isCancelSuccessful;
1094 }
1095
1096 // ////////////////////////////////////////////////////////////////////
1097 void AIRINV_Service::takeSnapshots (const stdair::AirlineCode_T& iAirlineCode,
1098 const stdair::DateTime_T& iSnapshotTime) {
1099
1100 if (_airinvServiceContext == NULL) {
1101 throw stdair::NonInitialisedServiceException ("The AirInv service "
1102 "has not been initialised");
1103 }
1104 assert (_airinvServiceContext != NULL);
1105 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
1106
1107 // TODO: Retrieve the corresponding inventory.
1108 stdair::STDAIR_Service& lSTDAIR_Service =
1109 lAIRINV_ServiceContext.getSTDAIR_Service();
1110 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
1111
1112 const stdair::InventoryList_T lInventoryList =
1113 stdair::BomManager::getList<stdair::Inventory> (lBomRoot);
1114 for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
1115 itInv != lInventoryList.end(); ++itInv) {
1116 const stdair::Inventory* lInv_ptr = *itInv;
1117 assert (lInv_ptr != NULL);
1118
1119 InventoryManager::takeSnapshots (*lInv_ptr, iSnapshotTime);
1120 }
1121 }
1122
1123 // ////////////////////////////////////////////////////////////////////
1124 void AIRINV_Service::optimise (const stdair::AirlineCode_T& iAirlineCode,
1125 const stdair::KeyDescription_T& iFDDescription,
1126 const stdair::DateTime_T& iRMEventTime) {
1127
1128 if (_airinvServiceContext == NULL) {
1129 throw stdair::NonInitialisedServiceException ("The AirInv service "
1130 "has not been initialised");
1131 }
1132 assert (_airinvServiceContext != NULL);
1133 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
1134
1135 // Retrieve the corresponding inventory & flight-date
1136 stdair::STDAIR_Service& lSTDAIR_Service =
1137 lAIRINV_ServiceContext.getSTDAIR_Service();
1138 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
1139 stdair::Inventory* lInventory_ptr =
1140 stdair::BomManager::getObjectPtr<stdair::Inventory> (lBomRoot, iAirlineCode);
1141 if (lInventory_ptr == NULL) {
1142 std::ostringstream oErrorMessage;
1143 oErrorMessage << "The Inventory '" << iAirlineCode
1144 << "', can not be retrieved.";
1145 STDAIR_LOG_ERROR (oErrorMessage.str());
1146 throw InventoryNotFoundException (oErrorMessage.str());
1147 }
1148 assert (lInventory_ptr != NULL);
1149 stdair::FlightDate* lFlightDate_ptr =
1150 stdair::BomManager::getObjectPtr<stdair::FlightDate> (*lInventory_ptr,
1151 iFDDescription);
1152 if (lFlightDate_ptr == NULL) {
1153 std::ostringstream oErrorMessage;
1154 oErrorMessage << "The flight date '" << iFDDescription
1155 << "', can not be retrieved in the '"
1156 << iAirlineCode << "' inventory.";
1157 STDAIR_LOG_ERROR (oErrorMessage.str());
1158 throw FlightDateNotFoundException (oErrorMessage.str());
1159 }
1160 assert (lFlightDate_ptr != NULL);
1161
1162 const stdair::UnconstrainingMethod& lUnconstrainingMethod =
1163 lInventory_ptr->getUnconstrainingMethod();
1164 const stdair::ForecastingMethod& lForecastingMethod =
1165 lInventory_ptr->getForecastingMethod();
1166 const stdair::PreOptimisationMethod& lPreOptimisationMethod =
1167 lInventory_ptr->getPreOptimisationMethod();
1168 const stdair::OptimisationMethod& lOptimisationMethod =
1169 lInventory_ptr->getOptimisationMethod();
1170 const stdair::PartnershipTechnique& lPartnershipTechnique =
1171 lInventory_ptr->getPartnershipTechnique();
1172
1173 // Retrieve the RMOL service.
1174 RMOL::RMOL_Service& lRMOL_Service = lAIRINV_ServiceContext.getRMOL_Service();
1175
1176 // Optimise the flight-date.
1177 bool isOptimised = lRMOL_Service.optimise (*lFlightDate_ptr, iRMEventTime,
1178 lUnconstrainingMethod,
1179 lForecastingMethod,
1180 lPreOptimisationMethod,
1181 lOptimisationMethod,
1182 lPartnershipTechnique);
1183
1184 const stdair::OptimisationMethod::EN_OptimisationMethod& lENOptimisationMethod = lOptimisationMethod.getMethod();
1185 const bool isEMSRb =
1186 (lENOptimisationMethod == stdair::OptimisationMethod::LEG_BASED_EMSR_B);
1187 // Update the inventory with the new controls.
1188 // updateBookingControls uses bid price vector to set
1189 // the authorization level. But EMSRb sets directly the
1190 // authorization level and does not compute the bid price vector.
1191 // So if EMSRb is used, do not call updateBookingControls.
1192 if (isOptimised == true && isEMSRb == false) {
1193 InventoryManager::updateBookingControls (*lFlightDate_ptr);
1194 InventoryManager::recalculateAvailability (*lFlightDate_ptr);
1195 }
1196 }
1197}
Class holding the context of the AirInv services.
AIRINV_Service(const stdair::BasLogParams &, const stdair::BasDBParams &)
void buildComplementaryLinks(stdair::BomRoot &)
bool sell(const std::string &iSegmentDateKey, const stdair::ClassCode_T &, const stdair::PartySize_T &)
void parseAndLoad(const AIRINV::InventoryFilePath &)
std::string jsonExportFlightDateObjects(const stdair::AirlineCode_T &, const stdair::FlightNumber_T &, const stdair::Date_T &iDepartureDate) const
std::string jsonExportFlightDateList(const stdair::AirlineCode_T &iAirlineCode="all", const stdair::FlightNumber_T &iFlightNumber=0) const
std::string csvDisplay() const
std::string list(const stdair::AirlineCode_T &iAirlineCode="all", const stdair::FlightNumber_T &iFlightNumber=0) const
void optimise(const stdair::AirlineCode_T &, const stdair::KeyDescription_T &, const stdair::DateTime_T &)
void takeSnapshots(const stdair::AirlineCode_T &, const stdair::DateTime_T &)
bool cancel(const std::string &iSegmentDateKey, const stdair::ClassCode_T &, const stdair::PartySize_T &)
stdair::RMEventList_T initRMEvents(const stdair::Date_T &iStartDate, const stdair::Date_T &iEndDate)
std::string jsonHandler(const stdair::JSONString &) const
void calculateAvailability(stdair::TravelSolutionStruct &)
bool check(const stdair::AirlineCode_T &, const stdair::FlightNumber_T &, const stdair::Date_T &iDepartureDate) const
static void parse(const stdair::FFDisutilityFilePath &iFFDisutilityInputFilename, stdair::BomRoot &)
static void parse(const stdair::FRAT5FilePath &iFRAT5InputFilename, stdair::BomRoot &)
static FacAirinvServiceContext & instance()
static void createDirectAccesses(const stdair::BomRoot &)
static void setDefaultBidPriceVector(stdair::BomRoot &)
static void buildSimilarSegmentCabinSets(const stdair::BomRoot &)
static void initialiseYieldBasedNestingStructures(const stdair::BomRoot &)
static void initialiseListsOfUsablePolicies(const stdair::BomRoot &)
static void buildInventory(const InventoryFilePath &, stdair::BomRoot &)
static void generateInventories(const stdair::ScheduleFilePath &iScheduleFilename, stdair::BomRoot &)