AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/basic/BasChronometer.hpp>
10 #include <stdair/bom/BomKeyManager.hpp>
11 #include <stdair/bom/BomManager.hpp>
12 #include <stdair/bom/BomKeyManager.hpp>
13 #include <stdair/bom/BomRoot.hpp>
14 #include <stdair/bom/Inventory.hpp>
15 #include <stdair/bom/FlightDate.hpp>
16 #include <stdair/bom/AirlineFeature.hpp>
17 #include <stdair/bom/RMEventStruct.hpp>
18 #include <stdair/factory/FacBomManager.hpp>
19 #include <stdair/service/Logger.hpp>
20 #include <stdair/STDAIR_Service.hpp>
21 // RMOL
22 #include <rmol/RMOL_Service.hpp>
23 // AirRAC
24 #include <airrac/AIRRAC_Service.hpp>
25 // AirInv
33 
34 namespace AIRINV {
35 
36  // ////////////////////////////////////////////////////////////////////
37  AIRINV_Service::AIRINV_Service () : _airinvServiceContext (NULL) {
38  assert (false);
39  }
40 
41  // ////////////////////////////////////////////////////////////////////
42  AIRINV_Service::AIRINV_Service (const AIRINV_Service& iService)
43  : _airinvServiceContext (NULL) {
44  assert (false);
45  }
46 
47  // ////////////////////////////////////////////////////////////////////
48  AIRINV_Service::AIRINV_Service (const stdair::BasLogParams& iLogParams)
49  : _airinvServiceContext (NULL) {
50 
51  // Initialise the STDAIR service handler
52  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
53  initStdAirService (iLogParams);
54 
55  // Initialise the service context
56  initServiceContext();
57 
58  // Add the StdAir service context to the AIRINV service context
59  // \note AIRINV owns the STDAIR service resources here.
60  const bool ownStdairService = true;
61  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
62 
63  // Initalise the RMOL service.
64  initRMOLService();
65 
66  // Initalise the AIRRAC service.
67  initAIRRACService();
68 
69  // Initialise the (remaining of the) context
70  initAirinvService();
71  }
72 
73  // ////////////////////////////////////////////////////////////////////
74  AIRINV_Service::AIRINV_Service (const stdair::BasLogParams& iLogParams,
75  const stdair::BasDBParams& iDBParams)
76  : _airinvServiceContext (NULL) {
77 
78  // Initialise the STDAIR service handler
79  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
80  initStdAirService (iLogParams, iDBParams);
81 
82  // Initialise the service context
83  initServiceContext();
84 
85  // Add the StdAir service context to the AIRINV service context
86  // \note AIRINV owns the STDAIR service resources here.
87  const bool ownStdairService = true;
88  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
89 
90  // Initalise the RMOL service.
91  initRMOLService();
92 
93  // Initalise the AIRRAC service.
94  initAIRRACService();
95 
96  // Initialise the (remaining of the) context
97  initAirinvService();
98  }
99  // //////////////////////////////////////////////////////////////////////
100  AIRINV_Service::
101  AIRINV_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
102  : _airinvServiceContext (NULL) {
103 
104  // Initialise the service context
105  initServiceContext();
106 
107  // Store the STDAIR service object within the (AIRINV) service context
108  // \note AirInv does not own the STDAIR service resources here.
109  const bool doesNotOwnStdairService = false;
110  addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
111 
112  // Initalise the RMOL service.
113  initRMOLService();
114 
115  // Initalise the AIRRAC service.
116  initAIRRACService();
117 
118  // Initialise the (remaining of the) context
119  initAirinvService();
120 
121  }
122 
123  // ////////////////////////////////////////////////////////////////////
125  // Delete/Clean all the objects from memory
126  finalise();
127  }
128 
129  // ////////////////////////////////////////////////////////////////////
130  void AIRINV_Service::finalise() {
131  assert (_airinvServiceContext != NULL);
132  // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
133  _airinvServiceContext->reset();
134  }
135 
136  // ////////////////////////////////////////////////////////////////////
137  void AIRINV_Service::initServiceContext() {
138  // Initialise the context
139  AIRINV_ServiceContext& lAIRINV_ServiceContext =
141  _airinvServiceContext = &lAIRINV_ServiceContext;
142  }
143 
144  // ////////////////////////////////////////////////////////////////////
145  void AIRINV_Service::
146  addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
147  const bool iOwnStdairService) {
148 
149  // Retrieve the Airinv service context
150  assert (_airinvServiceContext != NULL);
151  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
152 
153  // Store the STDAIR service object within the (AIRINV) service context
154  lAIRINV_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
155  iOwnStdairService);
156  }
157 
158  // ////////////////////////////////////////////////////////////////////
159  stdair::STDAIR_ServicePtr_T AIRINV_Service::
160  initStdAirService (const stdair::BasLogParams& iLogParams,
161  const stdair::BasDBParams& iDBParams) {
162 
170  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
171  boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
172 
173  return lSTDAIR_Service_ptr;
174  }
175 
176  // ////////////////////////////////////////////////////////////////////
177  stdair::STDAIR_ServicePtr_T AIRINV_Service::
178  initStdAirService (const stdair::BasLogParams& iLogParams) {
179 
187  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
188  boost::make_shared<stdair::STDAIR_Service> (iLogParams);
189 
190  return lSTDAIR_Service_ptr;
191  }
192 
193  // ////////////////////////////////////////////////////////////////////
194  void AIRINV_Service::initRMOLService() {
195 
196  // Retrieve the AirInv service context
197  assert (_airinvServiceContext != NULL);
198  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
199 
200  // Retrieve the StdAir service context
201  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
202  lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
203 
211  RMOL::RMOL_ServicePtr_T lRMOL_Service_ptr =
212  boost::make_shared<RMOL::RMOL_Service> (lSTDAIR_Service_ptr);
213 
214  // Store the RMOL service object within the (AIRINV) service context
215  lAIRINV_ServiceContext.setRMOL_Service (lRMOL_Service_ptr);
216  }
217 
218  // ////////////////////////////////////////////////////////////////////
219  void AIRINV_Service::initAIRRACService() {
220 
221  // Retrieve the AirInv service context
222  assert (_airinvServiceContext != NULL);
223  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
224 
225  // Retrieve the StdAir service context
226  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
227  lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
228 
236  AIRRAC::AIRRAC_ServicePtr_T lAIRRAC_Service_ptr =
237  boost::make_shared<AIRRAC::AIRRAC_Service> (lSTDAIR_Service_ptr);
238 
239  // Store the AIRRAC service object within the (AIRINV) service context
240  lAIRINV_ServiceContext.setAIRRAC_Service (lAIRRAC_Service_ptr);
241  }
242 
243  // ////////////////////////////////////////////////////////////////////
244  void AIRINV_Service::initAirinvService() {
245  // Do nothing at this stage. A sample BOM tree may be built by
246  // calling the buildSampleBom() method
247  }
248 
249  // ////////////////////////////////////////////////////////////////////
250  void AIRINV_Service::
251  parseAndLoad (const stdair::Filename_T& iInventoryInputFilename) {
252 
253  // Retrieve the BOM root object.
254  assert (_airinvServiceContext != NULL);
255  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
256  stdair::STDAIR_Service& lSTDAIR_Service =
257  lAIRINV_ServiceContext.getSTDAIR_Service();
258  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
259 
260  // Initialise the airline inventories
261  InventoryParser::buildInventory (iInventoryInputFilename, lBomRoot);
262  }
263 
264  // ////////////////////////////////////////////////////////////////////
265  void AIRINV_Service::
266  parseAndLoad (const stdair::Filename_T& iScheduleInputFilename,
267  const stdair::Filename_T& iODInputFilename,
268  const AIRRAC::YieldFilePath& iYieldFilename) {
269 
270  // Retrieve the BOM root object.
271  assert (_airinvServiceContext != NULL);
272  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
273  stdair::STDAIR_Service& lSTDAIR_Service =
274  lAIRINV_ServiceContext.getSTDAIR_Service();
275  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
276 
277  // Initialise the airline inventories
278  ScheduleParser::generateInventories (iScheduleInputFilename, lBomRoot);
279 
280  // Parse the yield structures.
281  AIRRAC::AIRRAC_Service& lAIRRAC_Service =
282  lAIRINV_ServiceContext.getAIRRAC_Service();
283  lAIRRAC_Service.parseAndLoad (iYieldFilename);
284 
285  // Update yield values for booking classes and O&D.
286  lAIRRAC_Service.updateYields();
287  }
288 
289  // ////////////////////////////////////////////////////////////////////
291 
292  // Retrieve the AirInv service context
293  if (_airinvServiceContext == NULL) {
294  throw stdair::NonInitialisedServiceException("The AirInv service has not "
295  "been initialised");
296  }
297  assert (_airinvServiceContext != NULL);
298 
299  // Retrieve the AirInv service context and whether it owns the Stdair
300  // service
301  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
302  const bool doesOwnStdairService =
303  lAIRINV_ServiceContext.getOwnStdairServiceFlag();
304 
305  // Retrieve the StdAir service object from the (AirInv) service context
306  stdair::STDAIR_Service& lSTDAIR_Service =
307  lAIRINV_ServiceContext.getSTDAIR_Service();
308 
313  if (doesOwnStdairService == true) {
314  //
315  lSTDAIR_Service.buildSampleBom();
316  }
317 
328  AIRRAC::AIRRAC_Service& lAIRRAC_Service =
329  lAIRINV_ServiceContext.getAIRRAC_Service();
330  lAIRRAC_Service.buildSampleBom();
331 
337  RMOL::RMOL_Service& lRMOL_Service= lAIRINV_ServiceContext.getRMOL_Service();
338  lRMOL_Service.buildSampleBom();
339 
365  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
367 
371  // InventoryManager::setDefaultBidPriceVector (lBomRoot);
372  }
373 
374  // ////////////////////////////////////////////////////////////////////
375  std::string AIRINV_Service::
376  jsonExport (const stdair::AirlineCode_T& iAirlineCode,
377  const stdair::FlightNumber_T& iFlightNumber,
378  const stdair::Date_T& iDepartureDate) const {
379 
380  // Retrieve the AIRINV service context
381  if (_airinvServiceContext == NULL) {
382  throw stdair::NonInitialisedServiceException ("The AirInv service "
383  "has not been initialised");
384  }
385  assert (_airinvServiceContext != NULL);
386 
387  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
388 
389  // Retrieve the STDAIR service object from the (AIRINV) service context
390  stdair::STDAIR_Service& lSTDAIR_Service =
391  lAIRINV_ServiceContext.getSTDAIR_Service();
392 
393  // Delegate the JSON export to the dedicated service
394  return lSTDAIR_Service.jsonExport (iAirlineCode, iFlightNumber,
395  iDepartureDate);
396  }
397 
398  // ////////////////////////////////////////////////////////////////////
399  std::string AIRINV_Service::
400  list (const stdair::AirlineCode_T& iAirlineCode,
401  const stdair::FlightNumber_T& iFlightNumber) const {
402  std::ostringstream oFlightListStr;
403 
404  if (_airinvServiceContext == NULL) {
405  throw stdair::NonInitialisedServiceException ("The AirInv service "
406  "has not been initialised");
407  }
408  assert (_airinvServiceContext != NULL);
409  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
410 
411  // \todo Check that the current AIRINV_Service is actually operating for
412  // the given airline
413 
414  // Retrieve the STDAIR service object from the (AirInv) service context
415  stdair::STDAIR_Service& lSTDAIR_Service =
416  lAIRINV_ServiceContext.getSTDAIR_Service();
417 
418  // Delegate the BOM display to the dedicated service
419  return lSTDAIR_Service.list (iAirlineCode, iFlightNumber);
420  }
421 
422  // ////////////////////////////////////////////////////////////////////
423  bool AIRINV_Service::
424  check (const stdair::AirlineCode_T& iAirlineCode,
425  const stdair::FlightNumber_T& iFlightNumber,
426  const stdair::Date_T& iDepartureDate) const {
427  std::ostringstream oFlightListStr;
428 
429  if (_airinvServiceContext == NULL) {
430  throw stdair::NonInitialisedServiceException ("The AirInv service "
431  "has not been initialised");
432  }
433  assert (_airinvServiceContext != NULL);
434  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
435 
436  // \todo Check that the current AIRINV_Service is actually operating for
437  // the given airline
438 
439  // Retrieve the STDAIR service object from the (AirInv) service context
440  stdair::STDAIR_Service& lSTDAIR_Service =
441  lAIRINV_ServiceContext.getSTDAIR_Service();
442 
443  // Delegate the BOM display to the dedicated service
444  return lSTDAIR_Service.check (iAirlineCode, iFlightNumber, iDepartureDate);
445  }
446 
447  // ////////////////////////////////////////////////////////////////////
448  std::string AIRINV_Service::csvDisplay() const {
449 
450  // Retrieve the AIRINV service context
451  if (_airinvServiceContext == NULL) {
452  throw stdair::NonInitialisedServiceException ("The AirInv service "
453  "has not been initialised");
454  }
455  assert (_airinvServiceContext != NULL);
456 
457  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
458 
459  // Retrieve the STDAIR service object from the (AirInv) service context
460  stdair::STDAIR_Service& lSTDAIR_Service =
461  lAIRINV_ServiceContext.getSTDAIR_Service();
462 
463  // Delegate the BOM display to the dedicated service
464  return lSTDAIR_Service.csvDisplay();
465  }
466 
467  // ////////////////////////////////////////////////////////////////////
468  std::string AIRINV_Service::
469  csvDisplay (const stdair::AirlineCode_T& iAirlineCode,
470  const stdair::FlightNumber_T& iFlightNumber,
471  const stdair::Date_T& iDepartureDate) const {
472 
473  // Retrieve the AIRINV service context
474  if (_airinvServiceContext == NULL) {
475  throw stdair::NonInitialisedServiceException ("The AirInv service "
476  "has not been initialised");
477  }
478  assert (_airinvServiceContext != NULL);
479 
480  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
481 
482  // Retrieve the STDAIR service object from the (AirInv) service context
483  stdair::STDAIR_Service& lSTDAIR_Service =
484  lAIRINV_ServiceContext.getSTDAIR_Service();
485 
486  // Delegate the BOM display to the dedicated service
487  return lSTDAIR_Service.csvDisplay (iAirlineCode, iFlightNumber,
488  iDepartureDate);
489  }
490 
491  // ////////////////////////////////////////////////////////////////////
492  stdair::RMEventList_T AIRINV_Service::
493  initRMEvents (const stdair::Date_T& iStartDate,
494  const stdair::Date_T& iEndDate) {
495 
496  if (_airinvServiceContext == NULL) {
497  throw stdair::NonInitialisedServiceException ("The AirInv service "
498  "has not been initialised");
499  }
500  assert (_airinvServiceContext != NULL);
501  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
502 
503  // \todo Retrieve the corresponding inventory
504  stdair::STDAIR_Service& lSTDAIR_Service =
505  lAIRINV_ServiceContext.getSTDAIR_Service();
506  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
507 
508  stdair::RMEventList_T oRMEventList;
509  const stdair::InventoryList_T& lInventoryList =
510  stdair::BomManager::getList<stdair::Inventory> (lBomRoot);
511  for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
512  itInv != lInventoryList.end(); ++itInv) {
513  const stdair::Inventory* lInv_ptr = *itInv;
514  assert (lInv_ptr != NULL);
515 
516  InventoryManager::initRMEvents (*lInv_ptr, oRMEventList,
517  iStartDate, iEndDate);
518  }
519 
520  return oRMEventList;
521  }
522 
523  // ////////////////////////////////////////////////////////////////////
524  void AIRINV_Service::
525  calculateAvailability (stdair::TravelSolutionStruct& ioTravelSolution,
526  const stdair::PartnershipTechnique& iPartnershipTechnique) {
527 
528  if (_airinvServiceContext == NULL) {
529  throw stdair::NonInitialisedServiceException ("The AirInv service "
530  "has not been initialised");
531  }
532  assert (_airinvServiceContext != NULL);
533  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
534 
535  // Retrieve the corresponding inventory.
536  stdair::STDAIR_Service& lSTDAIR_Service =
537  lAIRINV_ServiceContext.getSTDAIR_Service();
538  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
539 
540  // Delegate the booking to the dedicated command
541  stdair::BasChronometer lAvlChronometer;
542  lAvlChronometer.start();
543  InventoryManager::calculateAvailability (lBomRoot, ioTravelSolution, iPartnershipTechnique);
544  // const double lAvlMeasure = lAvlChronometer.elapsed();
545 
546  // DEBUG
547  // STDAIR_LOG_DEBUG ("Availability retrieval: " << lAvlMeasure << " - "
548  // << lAIRINV_ServiceContext.display());
549  }
550 
551  // ////////////////////////////////////////////////////////////////////
552  bool AIRINV_Service::sell (const std::string& iSegmentDateKey,
553  const stdair::ClassCode_T& iClassCode,
554  const stdair::PartySize_T& iPartySize) {
555  bool isSellSuccessful = false;
556 
557  if (_airinvServiceContext == NULL) {
558  throw stdair::NonInitialisedServiceException ("The AirInv service "
559  "has not been initialised");
560  }
561  assert (_airinvServiceContext != NULL);
562  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
563 
564  // \todo Check that the current AIRINV_Service is actually operating for
565  // the given airline (inventory key)
566  // Retrieve the corresponding inventory key
567  const stdair::InventoryKey& lInventoryKey =
568  stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
569 
570  // Retrieve the root of the BOM tree
571  stdair::STDAIR_Service& lSTDAIR_Service =
572  lAIRINV_ServiceContext.getSTDAIR_Service();
573  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
574 
575  // Retrieve the corresponding inventory
576  stdair::Inventory& lInventory = stdair::BomManager::
577  getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString());
578 
579  // Delegate the booking to the dedicated command
580  stdair::BasChronometer lSellChronometer; lSellChronometer.start();
581  isSellSuccessful = InventoryManager::sell (lInventory, iSegmentDateKey,
582  iClassCode, iPartySize);
583  // const double lSellMeasure = lSellChronometer.elapsed();
584 
585  // DEBUG
586  // STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - "
587  // << lAIRINV_ServiceContext.display());
588 
589  return isSellSuccessful;
590  }
591 
592  // ////////////////////////////////////////////////////////////////////
593  bool AIRINV_Service::cancel (const std::string& iSegmentDateKey,
594  const stdair::ClassCode_T& iClassCode,
595  const stdair::PartySize_T& iPartySize) {
596  bool isCancellationSuccessful = false;
597 
598  if (_airinvServiceContext == NULL) {
599  throw stdair::NonInitialisedServiceException ("The AirInv service "
600  "has not been initialised");
601  }
602  assert (_airinvServiceContext != NULL);
603  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
604 
605  // \todo Check that the current AIRINV_Service is actually operating for
606  // the given airline (inventory key)
607  // Retrieve the corresponding inventory key
608  const stdair::InventoryKey& lInventoryKey =
609  stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
610 
611  // Retrieve the root of the BOM tree
612  stdair::STDAIR_Service& lSTDAIR_Service =
613  lAIRINV_ServiceContext.getSTDAIR_Service();
614  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
615 
616  // Retrieve the corresponding inventory
617  stdair::Inventory& lInventory = stdair::BomManager::
618  getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString());
619 
620  // Delegate the booking to the dedicated command
621  stdair::BasChronometer lCancellationChronometer;
622  lCancellationChronometer.start();
623  isCancellationSuccessful = InventoryManager::cancel (lInventory,
624  iSegmentDateKey,
625  iClassCode,iPartySize);
626  // const double lCancellationMeasure = lCancellationChronometer.elapsed();
627 
628  // DEBUG
629  // STDAIR_LOG_DEBUG ("Booking cancellation: "
630  // << lCancellationMeasure << " - "
631  // << lAIRINV_ServiceContext.display());
632 
633  return isCancellationSuccessful;
634  }
635 
636  // ////////////////////////////////////////////////////////////////////
637  void AIRINV_Service::takeSnapshots (const stdair::AirlineCode_T& iAirlineCode,
638  const stdair::DateTime_T& iSnapshotTime) {
639 
640  if (_airinvServiceContext == NULL) {
641  throw stdair::NonInitialisedServiceException ("The AirInv service "
642  "has not been initialised");
643  }
644  assert (_airinvServiceContext != NULL);
645  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
646 
647  // TODO: Retrieve the corresponding inventory.
648  stdair::STDAIR_Service& lSTDAIR_Service =
649  lAIRINV_ServiceContext.getSTDAIR_Service();
650  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
651 
652  const stdair::InventoryList_T lInventoryList =
653  stdair::BomManager::getList<stdair::Inventory> (lBomRoot);
654  for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
655  itInv != lInventoryList.end(); ++itInv) {
656  const stdair::Inventory* lInv_ptr = *itInv;
657  assert (lInv_ptr != NULL);
658 
659  InventoryManager::takeSnapshots (*lInv_ptr, iSnapshotTime);
660  }
661  }
662 
663  // ////////////////////////////////////////////////////////////////////
664  void AIRINV_Service::optimise (const stdair::AirlineCode_T& iAirlineCode,
665  const stdair::KeyDescription_T& iFDDescription,
666  const stdair::DateTime_T& iRMEventTime,
667  const stdair::ForecastingMethod& iForecastingMethod,
668  const stdair::PartnershipTechnique& iPartnershipTechnique) {
669  if (_airinvServiceContext == NULL) {
670  throw stdair::NonInitialisedServiceException ("The AirInv service "
671  "has not been initialised");
672  }
673  assert (_airinvServiceContext != NULL);
674  AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
675 
676  // Retrieve the corresponding inventory & flight-date
677  stdair::STDAIR_Service& lSTDAIR_Service =
678  lAIRINV_ServiceContext.getSTDAIR_Service();
679  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
680  stdair::Inventory& lInventory =
681  stdair::BomManager::getObject<stdair::Inventory> (lBomRoot, iAirlineCode);
682  stdair::FlightDate& lFlightDate =
683  stdair::BomManager::getObject<stdair::FlightDate> (lInventory,
684  iFDDescription);
685 
686  // Retrieve the RMOL service.
687  RMOL::RMOL_Service& lRMOL_Service =lAIRINV_ServiceContext.getRMOL_Service();
688 
689  // Optimise the flight-date.
690  bool isOptimised = lRMOL_Service.optimise (lFlightDate, iRMEventTime,
691  iForecastingMethod, iPartnershipTechnique);
692 
693  // Update the inventory with the new controls.
694  if (isOptimised == true) {
695  InventoryManager::updateBookingControls (lFlightDate);
696  }
697  }
698 }