8 #include <boost/make_shared.hpp>
10 #include <stdair/basic/BasConst_Inventory.hpp>
11 #include <stdair/basic/BasConst_BomDisplay.hpp>
12 #include <stdair/bom/BomManager.hpp>
13 #include <stdair/bom/BomKeyManager.hpp>
14 #include <stdair/bom/BomRoot.hpp>
15 #include <stdair/bom/Inventory.hpp>
16 #include <stdair/bom/FlightDate.hpp>
17 #include <stdair/bom/SegmentDate.hpp>
18 #include <stdair/bom/SegmentCabin.hpp>
19 #include <stdair/bom/LegDate.hpp>
20 #include <stdair/bom/LegCabin.hpp>
21 #include <stdair/bom/FareFamily.hpp>
22 #include <stdair/bom/BookingClass.hpp>
23 #include <stdair/bom/SegmentSnapshotTable.hpp>
24 #include <stdair/bom/TravelSolutionStruct.hpp>
25 #include <stdair/bom/FareOptionStruct.hpp>
26 #include <stdair/bom/EventStruct.hpp>
27 #include <stdair/bom/SnapshotStruct.hpp>
28 #include <stdair/bom/RMEventStruct.hpp>
29 #include <stdair/bom/FareFamily.hpp>
30 #include <stdair/bom/BookingClass.hpp>
31 #include <stdair/bom/BomRetriever.hpp>
32 #include <stdair/factory/FacBomManager.hpp>
33 #include <stdair/factory/FacBom.hpp>
34 #include <stdair/service/Logger.hpp>
35 #include <sevmgr/SEVMGR_Service.hpp>
47 void InventoryManager::
48 calculateAvailability (
const stdair::BomRoot& iBomRoot,
49 stdair::TravelSolutionStruct& ioTravelSolution) {
51 stdair::PartnershipTechnique::EN_PartnershipTechnique lENPartnershipTechnique =
52 stdair::PartnershipTechnique::NONE;
56 const stdair::SegmentPath_T& lSegmentPath =
57 ioTravelSolution.getSegmentPath();
58 for (stdair::SegmentPath_T::const_iterator itSK = lSegmentPath.begin();
59 itSK != lSegmentPath.end(); ++itSK) {
60 const std::string& lSegmentKey = *itSK;
61 const stdair::InventoryKey lInvKey =
62 stdair::BomKeyManager::extractInventoryKey (lSegmentKey);
63 stdair::Inventory& lInventory =
64 stdair::BomManager::getObject<stdair::Inventory>(iBomRoot,
67 lENPartnershipTechnique = lInventory.getPartnershipTechnique();
69 switch (lENPartnershipTechnique) {
71 case stdair::PartnershipTechnique::NONE:{
85 switch (lENPartnershipTechnique) {
86 case stdair::PartnershipTechnique::NONE:{
88 calculateAvailabilityByAU (ioTravelSolution);
91 case stdair::PartnershipTechnique::RAE_DA:
92 case stdair::PartnershipTechnique::RAE_YP:{
94 calculateAvailabilityByRAE (ioTravelSolution);
97 case stdair::PartnershipTechnique::IBP_DA:
98 case stdair::PartnershipTechnique::IBP_YP:{
100 calculateAvailabilityByProtectiveIBP (ioTravelSolution);
103 case stdair::PartnershipTechnique::IBP_YP_U:
104 case stdair::PartnershipTechnique::RMC:
105 case stdair::PartnershipTechnique::A_RMC:{
107 calculateAvailabilityByIBP (ioTravelSolution);
119 void InventoryManager::
120 calculateAvailabilityByAU (stdair::TravelSolutionStruct& ioTravelSolution) {
123 std::ostringstream oStr;
124 const stdair::SegmentPath_T& lSP = ioTravelSolution.getSegmentPath();
125 for (stdair::SegmentPath_T::const_iterator itSP = lSP.begin();
126 itSP != lSP.end(); itSP++) {
127 oStr << *itSP <<
";";
131 stdair::FareOptionList_T& lFOList = ioTravelSolution.getFareOptionListRef();
132 for (stdair::FareOptionList_T::iterator itFO = lFOList.begin();
133 itFO != lFOList.end(); ++itFO) {
135 stdair::FareOptionStruct& lFO = *itFO;
138 const stdair::ClassList_StringList_T& lClassPath = lFO.getClassPath();
140 const stdair::ClassAvailabilityMapHolder_T& lClassAvailabilityMapHolder =
141 ioTravelSolution.getClassAvailabilityMapHolder();
144 stdair::Availability_T lAvl =
145 std::numeric_limits<stdair::Availability_T>::max();
150 assert (lClassAvailabilityMapHolder.empty() ==
false
151 && lClassPath.empty() ==
false);
154 stdair::ClassAvailabilityMapHolder_T::const_iterator itCAMH =
155 lClassAvailabilityMapHolder.begin();
158 stdair::ClassList_StringList_T::const_iterator itClassList =
162 for (; itCAMH != lClassAvailabilityMapHolder.end()
163 && itClassList != lClassPath.end(); ++itCAMH, ++itClassList) {
166 const stdair::ClassList_String_T& lCurrentClassList = *itClassList;
167 assert (lCurrentClassList.size() > 0);
172 stdair::ClassCode_T lFirstClass;
173 lFirstClass.append (lCurrentClassList, 0, 1);
176 const stdair::ClassAvailabilityMap_T& lClassAvlMap = *itCAMH;
179 const stdair::ClassAvailabilityMap_T::const_iterator itClassAvl =
180 lClassAvlMap.find (lFirstClass);
182 if (itClassAvl == lClassAvlMap.end()) {
184 STDAIR_LOG_DEBUG (
"No availability has been set up for the class '"
185 << lFirstClass <<
"'. Travel solution: "
186 << ioTravelSolution.display());
188 assert (itClassAvl != lClassAvlMap.end());
190 const stdair::Availability_T& lCurrentAvl = itClassAvl->second;
191 if (lAvl > lCurrentAvl) {
196 lFO.setAvailability (lAvl);
199 STDAIR_LOG_DEBUG (
"Fare option " << lFO.describe() <<
", "
200 <<
"Availability " << lFO.getAvailability() <<
", "
201 <<
"Segment Path " << oStr.str());
208 void InventoryManager::
209 calculateAvailabilityByRAE (stdair::TravelSolutionStruct& ioTravelSolution) {
211 std::ostringstream oStr;
212 const stdair::SegmentPath_T& lSP = ioTravelSolution.getSegmentPath();
213 for (stdair::SegmentPath_T::const_iterator itSP = lSP.begin();
214 itSP != lSP.end(); itSP++) {
215 oStr << *itSP <<
";";
219 const stdair::ClassYieldMapHolder_T& lClassYieldMapHolder =
220 ioTravelSolution.getClassYieldMapHolder();
221 const stdair::ClassBpvMapHolder_T& lClassBpvMapHolder =
222 ioTravelSolution.getClassBpvMapHolder();
225 stdair::FareOptionList_T& lFOList = ioTravelSolution.getFareOptionListRef();
226 for (stdair::FareOptionList_T::iterator itFO = lFOList.begin();
227 itFO != lFOList.end(); ++itFO) {
229 stdair::FareOptionStruct& lFO = *itFO;
231 stdair::ClassYieldMapHolder_T::const_iterator itCYM =
232 lClassYieldMapHolder.begin();
233 stdair::ClassBpvMapHolder_T::const_iterator itCBPM =
234 lClassBpvMapHolder.begin();
236 const stdair::ClassList_StringList_T& lClassPath = lFO.getClassPath();
240 assert (lClassPath.size() == lClassYieldMapHolder.size());
241 assert (lClassPath.size() == lClassBpvMapHolder.size());
246 std::ostringstream oCPStr;
247 for (stdair::ClassList_StringList_T::const_iterator itCL =
249 itCL != lClassPath.end(); ++itCL, ++itCYM, ++itCBPM) {
252 if (itCL == lClassPath.begin()) {
256 oCPStr <<
"-" << *itCL;
259 const stdair::ClassList_String_T& lCL = *itCL;
260 stdair::ClassCode_T lCC;
261 lCC.append (lCL, 0, 1);
263 const stdair::ClassYieldMap_T& lCYM = *itCYM;
264 stdair::ClassYieldMap_T::const_iterator itCCCYM = lCYM.find (lCC);
265 assert (itCCCYM != lCYM.end());
267 const stdair::ClassBpvMap_T& lCBPM = *itCBPM;
268 stdair::ClassBpvMap_T::const_iterator itCCCBPM = lCBPM.find (lCC);
269 assert (itCCCBPM != lCBPM.end());
271 const stdair::BidPriceVector_T* lBidPriceVector_ptr = itCCCBPM->second;
272 assert (lBidPriceVector_ptr != NULL);
275 if (itCL == lClassPath.begin()) {
276 lFO.setAvailability (lBidPriceVector_ptr->size());
280 if (lFO.getAvailability() > 0) {
283 stdair::BidPriceVector_T lReverseBPV (lBidPriceVector_ptr->size());
284 std::reverse_copy (lBidPriceVector_ptr->begin(),
285 lBidPriceVector_ptr->end(),
286 lReverseBPV.begin());
288 const stdair::YieldValue_T& lYield = itCCCYM->second;
289 stdair::BidPriceVector_T::const_iterator lBidPrice =
290 std::upper_bound (lReverseBPV.begin(), lReverseBPV.end(), lYield);
292 const stdair::Availability_T lAvl = lBidPrice - lReverseBPV.begin();
295 lFO.setAvailability (std::min (lFO.getAvailability(), lAvl));
300 STDAIR_LOG_DEBUG (
"Fare option: " << lFO.describe() <<
", "
301 <<
"Availability: " << lFO.getAvailability() <<
", "
302 <<
"Segment Path: " << oStr.str() <<
", ");
309 void InventoryManager::
310 calculateAvailabilityByIBP (stdair::TravelSolutionStruct& ioTravelSolution) {
311 std::ostringstream oStr;
316 const stdair::SegmentPath_T& lSP = ioTravelSolution.getSegmentPath();
317 for (stdair::SegmentPath_T::const_iterator itSP = lSP.begin();
318 itSP != lSP.end(); itSP++) {
319 oStr << *itSP <<
";";
323 const stdair::ClassYieldMapHolder_T& lClassYieldMapHolder =
324 ioTravelSolution.getClassYieldMapHolder();
325 const stdair::ClassBpvMapHolder_T& lClassBpvMapHolder =
326 ioTravelSolution.getClassBpvMapHolder();
329 stdair::FareOptionList_T& lFOList = ioTravelSolution.getFareOptionListRef();
330 for (stdair::FareOptionList_T::iterator itFO = lFOList.begin();
331 itFO != lFOList.end(); ++itFO) {
333 stdair::FareOptionStruct& lFO = *itFO;
335 stdair::ClassYieldMapHolder_T::const_iterator itCYM =
336 lClassYieldMapHolder.begin();
337 stdair::ClassBpvMapHolder_T::const_iterator itCBPM =
338 lClassBpvMapHolder.begin();
340 const stdair::ClassList_StringList_T& lClassPath = lFO.getClassPath();
343 assert (lClassPath.size() == lClassYieldMapHolder.size());
344 assert (lClassPath.size() == lClassBpvMapHolder.size());
349 stdair::YieldValue_T lTotalYield = lFO.getFare();
351 stdair::BidPrice_T lTotalBidPrice = 0;
356 std::ostringstream oCPStr;
357 for (stdair::ClassList_StringList_T::const_iterator itCL =
359 itCL != lClassPath.end(); ++itCL, ++itCYM, ++itCBPM) {
362 if (itCL == lClassPath.begin()) {
366 oCPStr <<
"-" << *itCL;
369 const stdair::ClassList_String_T& lCL = *itCL;
370 stdair::ClassCode_T lCC;
371 lCC.append (lCL, 0, 1);
373 const stdair::ClassYieldMap_T& lCYM = *itCYM;
374 stdair::ClassYieldMap_T::const_iterator itCCCYM = lCYM.find (lCC);
375 assert (itCCCYM != lCYM.end());
377 const stdair::ClassBpvMap_T& lCBPM = *itCBPM;
378 stdair::ClassBpvMap_T::const_iterator itCCCBPM = lCBPM.find (lCC);
379 assert (itCCCBPM != lCBPM.end());
381 const stdair::BidPriceVector_T* lBidPriceVector_ptr = itCCCBPM->second;
382 assert (lBidPriceVector_ptr != NULL);
385 if (itCL == lClassPath.begin()) {
386 lFO.setAvailability (lBidPriceVector_ptr->size());
390 if (lFO.getAvailability() > 0) {
392 stdair::BidPriceVector_T lReverseBPV (lBidPriceVector_ptr->size());
393 std::reverse_copy (lBidPriceVector_ptr->begin(),
394 lBidPriceVector_ptr->end(), lReverseBPV.begin());
396 const stdair::YieldValue_T& lYield = itCCCYM->second;
397 stdair::BidPriceVector_T::const_iterator lBidPrice =
398 std::upper_bound (lReverseBPV.begin(), lReverseBPV.end(), lYield);
400 const stdair::Availability_T lAvl = lBidPrice - lReverseBPV.begin();
403 lFO.setAvailability (std::min(lFO.getAvailability(), lAvl));
407 if (lBidPriceVector_ptr->size() > 0) {
408 lTotalBidPrice += lBidPriceVector_ptr->back();
411 lTotalBidPrice = std::numeric_limits<stdair::BidPrice_T>::max();
419 if (lClassPath.size() > 1) {
420 if (lFO.getAvailability() > 0) {
421 const stdair::Availability_T lAvl =
422 alpha * lTotalYield >= lTotalBidPrice;
423 lFO.setAvailability (lAvl * lFO.getAvailability());
426 const stdair::Availability_T lAvl =
427 alpha * lTotalYield >= lTotalBidPrice;
428 lFO.setAvailability (lAvl);
432 STDAIR_LOG_DEBUG (
"Class: " << oCPStr.str()
433 <<
", " <<
"Yield: " << alpha*lTotalYield <<
", "
434 <<
"Bid price: " << lTotalBidPrice <<
", "
435 <<
"Remaining capacity: " <<
"Undefined" <<
" "
436 <<
"Segment date: " << oStr.str());
440 STDAIR_LOG_DEBUG (
"Fare option " << lFO.describe() <<
", "
441 <<
"Availability " << lFO.getAvailability() <<
", "
442 <<
"Segment Path " << oStr.str() <<
", ");
449 void InventoryManager::
450 calculateAvailabilityByProtectiveIBP (stdair::TravelSolutionStruct& ioTravelSolution) {
451 std::ostringstream oStr;
456 const stdair::SegmentPath_T& lSP = ioTravelSolution.getSegmentPath();
457 for (stdair::SegmentPath_T::const_iterator itSP = lSP.begin();
458 itSP != lSP.end(); itSP++) {
459 oStr << *itSP <<
";";
463 const stdair::ClassYieldMapHolder_T& lClassYieldMapHolder =
464 ioTravelSolution.getClassYieldMapHolder();
465 const stdair::ClassBpvMapHolder_T& lClassBpvMapHolder =
466 ioTravelSolution.getClassBpvMapHolder();
469 stdair::FareOptionList_T& lFOList = ioTravelSolution.getFareOptionListRef();
470 for (stdair::FareOptionList_T::iterator itFO = lFOList.begin();
471 itFO != lFOList.end(); ++itFO) {
473 stdair::FareOptionStruct& lFO = *itFO;
475 stdair::ClassYieldMapHolder_T::const_iterator itCYM =
476 lClassYieldMapHolder.begin();
477 stdair::ClassBpvMapHolder_T::const_iterator itCBPM =
478 lClassBpvMapHolder.begin();
480 const stdair::ClassList_StringList_T& lClassPath = lFO.getClassPath();
483 assert (lClassPath.size() == lClassYieldMapHolder.size());
484 assert (lClassPath.size() == lClassBpvMapHolder.size());
488 stdair::YieldValue_T lTotalYield = lFO.getFare();
490 stdair::BidPrice_T lTotalBidPrice = 0;
492 stdair::BidPrice_T lMaxBidPrice = 0;
497 std::ostringstream oCPStr;
498 for (stdair::ClassList_StringList_T::const_iterator itCL =
500 itCL != lClassPath.end(); ++itCL, ++itCYM, ++itCBPM) {
503 if (itCL == lClassPath.begin()) {
507 oCPStr <<
"-" << *itCL;
510 const stdair::ClassList_String_T& lCL = *itCL;
511 stdair::ClassCode_T lCC;
512 lCC.append (lCL, 0, 1);
514 const stdair::ClassYieldMap_T& lCYM = *itCYM;
515 stdair::ClassYieldMap_T::const_iterator itCCCYM = lCYM.find (lCC);
516 assert (itCCCYM != lCYM.end());
518 const stdair::YieldValue_T& lYield = itCCCYM->second;
519 const stdair::ClassBpvMap_T& lCBPM = *itCBPM;
520 stdair::ClassBpvMap_T::const_iterator itCCCBPM = lCBPM.find (lCC);
521 assert (itCCCBPM != lCBPM.end());
523 const stdair::BidPriceVector_T* lBidPriceVector_ptr = itCCCBPM->second;
524 assert (lBidPriceVector_ptr != NULL);
527 if (itCL == lClassPath.begin()) {
528 lFO.setAvailability (lBidPriceVector_ptr->size());
532 if (lFO.getAvailability() > 0) {
535 stdair::BidPriceVector_T lReverseBPV (lBidPriceVector_ptr->size());
536 std::reverse_copy (lBidPriceVector_ptr->begin(),
537 lBidPriceVector_ptr->end(), lReverseBPV.begin());
539 stdair::BidPriceVector_T::const_iterator lBidPrice =
540 std::upper_bound (lReverseBPV.begin(), lReverseBPV.end(), lYield);
542 const stdair::Availability_T lAvl = lBidPrice - lReverseBPV.begin();
545 lFO.setAvailability (std::min(lFO.getAvailability(), lAvl));
550 if (lBidPriceVector_ptr->size() > 0) {
551 lTotalBidPrice += lBidPriceVector_ptr->back();
553 if (lMaxBidPrice < lBidPriceVector_ptr->back()) {
554 lMaxBidPrice = lBidPriceVector_ptr->back();
558 lTotalBidPrice = std::numeric_limits<stdair::BidPrice_T>::max();
569 lTotalBidPrice = std::max (lMaxBidPrice * lClassPath.size(),
572 if (lClassPath.size() > 1) {
573 if (lFO.getAvailability() > 0) {
574 const stdair::Availability_T lAvl =
575 alpha * lTotalYield >= lTotalBidPrice;
576 lFO.setAvailability (lAvl * lFO.getAvailability());
579 const stdair::Availability_T lAvl =
580 alpha * lTotalYield >= lTotalBidPrice;
581 lFO.setAvailability (lAvl);
585 STDAIR_LOG_DEBUG (
"Class: " << oCPStr.str()
586 <<
", " <<
"Yield: " << alpha*lTotalYield <<
", "
587 <<
"Bid price: " << lTotalBidPrice <<
", "
588 <<
"Remaining capacity: " <<
"Undefined" <<
" "
589 <<
"Segment date: " << oStr.str());
593 STDAIR_LOG_DEBUG (
"Fare option " << lFO.describe() <<
", "
594 <<
"Availability " << lFO.getAvailability() <<
", "
595 <<
"Segment Path " << oStr.str() <<
", ");
603 const stdair::InventoryList_T& lInvList =
604 stdair::BomManager::getList<stdair::Inventory> (ioBomRoot);
605 for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
606 itInv != lInvList.end(); ++itInv) {
607 stdair::Inventory* lCurrentInv_ptr = *itInv;
608 assert (lCurrentInv_ptr != NULL);
615 if (stdair::BomManager::hasList<stdair::Inventory> (*lCurrentInv_ptr)) {
616 const stdair::InventoryList_T& lPartnerInvList =
617 stdair::BomManager::getList<stdair::Inventory> (*lCurrentInv_ptr);
619 for (stdair::InventoryList_T::const_iterator itPartnerInv =
620 lPartnerInvList.begin();
621 itPartnerInv != lPartnerInvList.end(); ++itPartnerInv) {
622 stdair::Inventory* lCurrentPartnerInv_ptr = *itPartnerInv;
623 assert (lCurrentPartnerInv_ptr != NULL);
635 const stdair::FlightDateList_T& lFlightDateList =
636 stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
637 for (stdair::FlightDateList_T::const_iterator itFlightDate =
638 lFlightDateList.begin();
639 itFlightDate != lFlightDateList.end(); ++itFlightDate) {
640 stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate;
641 assert (lCurrentFlightDate_ptr != NULL);
645 if (stdair::BomManager::hasList<stdair::LegDate> (*lCurrentFlightDate_ptr)) {
646 const stdair::LegDateList_T& lLegDateList =
647 stdair::BomManager::getList<stdair::LegDate> (*lCurrentFlightDate_ptr);
648 for (stdair::LegDateList_T::const_iterator itLegDate =
649 lLegDateList.begin();
650 itLegDate != lLegDateList.end(); ++itLegDate) {
651 stdair::LegDate* lCurrentLegDate_ptr = *itLegDate;
652 assert (lCurrentLegDate_ptr != NULL);
654 const stdair::LegCabinList_T& lLegCabinList =
655 stdair::BomManager::getList<stdair::LegCabin> (*lCurrentLegDate_ptr);
656 for (stdair::LegCabinList_T::const_iterator itLegCabin =
657 lLegCabinList.begin();
658 itLegCabin != lLegCabinList.end(); ++itLegCabin) {
659 stdair::LegCabin* lCurrentLegCabin_ptr = *itLegCabin;
660 assert (lCurrentLegCabin_ptr != NULL);
662 const stdair::CabinCapacity_T& lCabinCapacity =
663 lCurrentLegCabin_ptr->getPhysicalCapacity();
664 lCurrentLegCabin_ptr->emptyBidPriceVector();
666 stdair::BidPriceVector_T& lBPV =
667 lCurrentLegCabin_ptr->getBidPriceVector();
670 for (stdair::CabinCapacity_T k = 0; k != lCabinCapacity; k++) {
671 lBPV.push_back (400);
674 lCurrentLegCabin_ptr->setPreviousBidPrice (lBPV.back());
675 lCurrentLegCabin_ptr->setCurrentBidPrice (lBPV.back());
683 bool InventoryManager::sell (stdair::Inventory& ioInventory,
684 const std::string& iSegmentDateKey,
685 const stdair::ClassCode_T& iClassCode,
686 const stdair::PartySize_T& iPartySize) {
690 iClassCode, iPartySize);
694 bool InventoryManager::sell (
const stdair::BookingClassID_T& iClassID,
695 const stdair::PartySize_T& iPartySize) {
702 bool InventoryManager::cancel (stdair::Inventory& ioInventory,
703 const std::string& iSegmentDateKey,
704 const stdair::ClassCode_T& iClassCode,
705 const stdair::PartySize_T& iPartySize) {
709 iClassCode, iPartySize);
713 bool InventoryManager::cancel (
const stdair::BookingClassID_T& iClassID,
714 const stdair::PartySize_T& iPartySize) {
721 void InventoryManager::
722 updateBookingControls (stdair::FlightDate& ioFlightDate) {
729 void InventoryManager::
730 recalculateAvailability (stdair::FlightDate& ioFlightDate) {
737 void InventoryManager::takeSnapshots(
const stdair::Inventory& iInventory,
738 const stdair::DateTime_T& iSnapshotTime){
750 const stdair::InventoryList_T& lInvList =
751 stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
752 for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
753 itInv != lInvList.end(); ++itInv) {
754 stdair::Inventory* lCurrentInv_ptr = *itInv;
755 assert (lCurrentInv_ptr != NULL);
762 for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
763 itInv != lInvList.end(); ++itInv) {
764 stdair::Inventory* lCurrentInv_ptr = *itInv;
765 assert (lCurrentInv_ptr != NULL);
777 stdair::Inventory& ioInventory) {
781 const stdair::FlightDateList_T& lFlightDateList =
782 stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
783 for (stdair::FlightDateList_T::const_iterator itFlightDate =
784 lFlightDateList.begin();
785 itFlightDate != lFlightDateList.end(); ++itFlightDate) {
786 stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate;
787 assert (lCurrentFlightDate_ptr != NULL);
794 const bool hasInventoryList =
795 stdair::BomManager::hasList<stdair::Inventory> (ioInventory);
796 if (hasInventoryList ==
true) {
797 const stdair::InventoryList_T& lInvList =
798 stdair::BomManager::getList<stdair::Inventory> (ioInventory);
799 for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
800 itInv != lInvList.end(); ++itInv) {
801 stdair::Inventory* lCurrentInv_ptr = *itInv;
802 assert (lCurrentInv_ptr != NULL);
812 stdair::Inventory& ioInventory,
813 stdair::FlightDate& ioFlightDate) {
815 bool areSegmentAndRoutingLegLinked =
false;
819 const stdair::SegmentDateList_T& lSegmentDateList =
820 stdair::BomManager::getList<stdair::SegmentDate> (ioFlightDate);
821 for (stdair::SegmentDateList_T::const_iterator itSegmentDate =
822 lSegmentDateList.begin();
823 itSegmentDate != lSegmentDateList.end(); ++itSegmentDate) {
825 stdair::SegmentDate* lCurrentSegmentDate_ptr = *itSegmentDate;
826 assert (lCurrentSegmentDate_ptr != NULL);
829 const stdair::RoutingLegKeyList_T& lRoutingLegKeyList =
830 lCurrentSegmentDate_ptr->getLegKeyList ();
834 for (stdair::RoutingLegKeyList_T::const_iterator itRoutingLegKey =
835 lRoutingLegKeyList.begin();
836 itRoutingLegKey != lRoutingLegKeyList.end(); ++itRoutingLegKey) {
839 stdair::LegDate* lLegDate_ptr = stdair::BomRetriever::
840 retrieveOperatingLegDateFromLongKey (ioFlightDate, *itRoutingLegKey);
842 if (lLegDate_ptr != NULL) {
845 stdair::FacBomManager::addToListAndMap (*lCurrentSegmentDate_ptr,
847 stdair::FacBomManager::addToListAndMap (*lLegDate_ptr,
848 *lCurrentSegmentDate_ptr);
849 areSegmentAndRoutingLegLinked =
true;
852 if (areSegmentAndRoutingLegLinked ==
true) {
864 const stdair::SegmentCabinList_T& lSegmentCabinList =
865 stdair::BomManager::getList<stdair::SegmentCabin> (ioSegmentDate);
866 for (stdair::SegmentCabinList_T::const_iterator itSegmentCabin =
867 lSegmentCabinList.begin();
868 itSegmentCabin != lSegmentCabinList.end(); ++itSegmentCabin) {
871 stdair::SegmentCabin* lCurrentSegmentCabin_ptr = *itSegmentCabin;
872 assert (lCurrentSegmentCabin_ptr != NULL);
875 const stdair::CabinCode_T& lCabinCode =
876 lCurrentSegmentCabin_ptr->getCabinCode();
879 const stdair::LegDateList_T& lLegDateList =
880 stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
881 for (stdair::LegDateList_T::const_iterator itLegDate =
882 lLegDateList.begin();
883 itLegDate != lLegDateList.end(); ++itLegDate) {
885 const stdair::LegDate* lCurrentLegDate_ptr = *itLegDate;
886 assert (lCurrentLegDate_ptr != NULL);
890 stdair::LegCabin& lLegCabin = stdair::BomManager::
891 getObject<stdair::LegCabin> (*lCurrentLegDate_ptr, lCabinCode);
903 stdair::FacBomManager::addToListAndMap (*lCurrentSegmentCabin_ptr,
905 lLegCabin.getFullerKey());
917 stdair::FacBomManager::
918 addToListAndMap (lLegCabin, *lCurrentSegmentCabin_ptr,
919 lCurrentSegmentCabin_ptr->getFullerKey());
927 stdair::Inventory& ioInventory) {
931 const stdair::FlightDateList_T& lFlightDateList =
932 stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
933 for (stdair::FlightDateList_T::const_iterator itFlightDate =
934 lFlightDateList.begin();
935 itFlightDate != lFlightDateList.end(); ++itFlightDate) {
936 stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate;
937 assert (lCurrentFlightDate_ptr != NULL);
946 stdair::Inventory& ioInventory,
947 stdair::FlightDate& ioFlightDate) {
951 const stdair::SegmentDateList_T& lSegmentDateList =
952 stdair::BomManager::getList<stdair::SegmentDate> (ioFlightDate);
953 for (stdair::SegmentDateList_T::const_iterator itSegmentDate =
954 lSegmentDateList.begin();
955 itSegmentDate != lSegmentDateList.end(); ++itSegmentDate) {
957 stdair::SegmentDate* lCurrentSegmentDate_ptr = *itSegmentDate;
958 assert (lCurrentSegmentDate_ptr != NULL);
961 const stdair::RoutingLegKeyList_T& lRoutingLegKeyList =
962 lCurrentSegmentDate_ptr->getLegKeyList ();
966 for (stdair::RoutingLegKeyList_T::const_iterator itRoutingLegKey =
967 lRoutingLegKeyList.begin();
968 itRoutingLegKey != lRoutingLegKeyList.end(); ++itRoutingLegKey) {
972 stdair::LegDate* lLegDate_ptr = stdair::BomRetriever::
973 retrieveOperatingLegDateFromLongKey (ioFlightDate, *itRoutingLegKey);
977 if (lLegDate_ptr == NULL) {
981 std::ostringstream lRoutingSegmentKey;
982 lRoutingSegmentKey << *itRoutingLegKey <<
";"
983 << lCurrentSegmentDate_ptr->getOffPoint();
985 stdair::SegmentDate* lPartnerOperatingSegmentDate_ptr =
986 stdair::BomRetriever::
987 retrievePartnerSegmentDateFromLongKey (ioInventory,
988 lRoutingSegmentKey.str());
989 assert (lPartnerOperatingSegmentDate_ptr != NULL);
992 stdair::FacBomManager::linkWithOperating (*lCurrentSegmentDate_ptr,
993 *lPartnerOperatingSegmentDate_ptr);
995 stdair::SegmentDate* lOperatingSegmentDate_ptr =
996 stdair::BomRetriever::
997 retrieveSegmentDateFromLongKey (ioBomRoot,
998 lRoutingSegmentKey.str());
999 assert(lOperatingSegmentDate_ptr != NULL);
1001 stdair::Inventory* lInventory_ptr =
1002 stdair::BomRetriever::
1003 retrieveInventoryFromLongKey (ioBomRoot, *itRoutingLegKey);
1004 assert (lInventory_ptr != NULL);
1006 std::ostringstream lRoutingSegment;
1007 lRoutingSegment << ioFlightDate.getAirlineCode() <<
";"
1008 << ioFlightDate.describeKey() <<
";"
1009 << lCurrentSegmentDate_ptr->getBoardingPoint() <<
";"
1010 << lCurrentSegmentDate_ptr->getOffPoint();
1012 stdair::SegmentDate* lPartnerMarketingSegmentDate_ptr =
1013 stdair::BomRetriever::
1014 retrievePartnerSegmentDateFromLongKey (*lInventory_ptr, lRoutingSegment.str());
1015 assert(lPartnerMarketingSegmentDate_ptr != NULL);
1017 stdair::FacBomManager::addToList (*lOperatingSegmentDate_ptr, *lPartnerMarketingSegmentDate_ptr);
1030 const stdair::InventoryList_T& lInvList =
1031 stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
1032 for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
1033 itInv != lInvList.end(); ++itInv) {
1034 stdair::Inventory* lCurrentInv_ptr = *itInv;
1035 assert (lCurrentInv_ptr != NULL);
1053 const stdair::FlightDateList_T& lFlightDateList =
1054 stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
1055 for (stdair::FlightDateList_T::const_iterator itFD= lFlightDateList.begin();
1056 itFD != lFlightDateList.end(); ++itFD) {
1057 const stdair::FlightDate* lFD_ptr = *itFD;
1058 assert (lFD_ptr != NULL);
1059 const stdair::FlightNumber_T& lFlightNumber = lFD_ptr->getFlightNumber();
1063 const stdair::SegmentDateList_T& lSegmentDateList =
1064 stdair::BomManager::getList<stdair::SegmentDate> (*lFD_ptr);
1065 for (stdair::SegmentDateList_T::const_iterator itSD =
1066 lSegmentDateList.begin(); itSD != lSegmentDateList.end(); ++itSD) {
1067 const stdair::SegmentDate* lSD_ptr = *itSD;
1068 assert (lSD_ptr != NULL);
1070 const stdair::Date_T& lDepartureDate = lSD_ptr->getBoardingDate();
1071 const stdair::AirportCode_T& lOrigin = lSD_ptr->getBoardingPoint();
1072 const stdair::AirportCode_T& lDestination = lSD_ptr->getOffPoint();
1076 const stdair::SegmentCabinList_T& lSegmentCabinList =
1077 stdair::BomManager::getList<stdair::SegmentCabin> (*lSD_ptr);
1078 for (stdair::SegmentCabinList_T::const_iterator itSC =
1079 lSegmentCabinList.begin();
1080 itSC != lSegmentCabinList.end(); ++itSC) {
1081 stdair::SegmentCabin* lSC_ptr = *itSC;
1082 assert (lSC_ptr != NULL);
1084 std::ostringstream oStr;
1085 oStr << lFlightNumber << lDepartureDate.day_of_week()
1086 << lOrigin << lDestination << lSC_ptr->getCabinCode();
1087 const std::string lMapKey = oStr.str();
1090 SimilarSegmentCabinSetMap_T::iterator itSSCS = lSSCSM.find (lMapKey);
1091 if (itSSCS == lSSCSM.end()) {
1094 value_type (lDepartureDate, lSC_ptr));
1096 value_type (lMapKey, lDDSCMap));
1100 value_type (lDepartureDate, lSC_ptr));
1107 stdair::TableID_T lTableID = 1;
1108 for (SimilarSegmentCabinSetMap_T::const_iterator itSSCS = lSSCSM.begin();
1109 itSSCS != lSSCSM.end(); ++itSSCS, ++lTableID) {
1119 const stdair::TableID_T& iTableID,
1122 const stdair::SegmentSnapshotTableKey lKey (iTableID);
1123 stdair::SegmentSnapshotTable& lSegmentSnapshotTable =
1124 stdair::FacBom<stdair::SegmentSnapshotTable>::instance().create (lKey);
1125 stdair::FacBomManager::addToListAndMap (ioInventory, lSegmentSnapshotTable);
1128 DepartureDateSegmentCabinMap_T::const_iterator itDDSC = iDDSCMap.begin();
1129 assert (itDDSC != iDDSCMap.end());
1130 const stdair::SegmentCabin* lSegmentCabin_ptr = itDDSC->second;
1134 stdair::ClassIndexMap_T lClassIndexMap;
1135 stdair::ClassIndex_T lClassIndex = 0;
1136 std::ostringstream lSCMapKey;
1137 lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE
1138 << lSegmentCabin_ptr->describeKey();
1139 lClassIndexMap.insert (stdair::ClassIndexMap_T::
1140 value_type (lSCMapKey.str(), lClassIndex));
1144 const stdair::BookingClassList_T& lBCList =
1145 stdair::BomManager::getList<stdair::BookingClass>(*lSegmentCabin_ptr);
1146 for (stdair::BookingClassList_T::const_iterator itBC= lBCList.begin();
1147 itBC != lBCList.end(); ++itBC) {
1148 const stdair::BookingClass* lBookingClass_ptr = *itBC;
1149 assert (lBookingClass_ptr != NULL);
1151 insert (stdair::ClassIndexMap_T::
1152 value_type(lBookingClass_ptr->describeKey(),lClassIndex));
1157 stdair::SegmentCabinIndexMap_T lSegmentCabinIndexMap;
1158 stdair::SegmentDataID_T lSegmentDataID = 0;
1159 for (; itDDSC != iDDSCMap.end(); ++itDDSC, ++lSegmentDataID) {
1160 stdair::SegmentCabin* lCurrentSC_ptr = itDDSC->second;
1161 assert (lCurrentSC_ptr != NULL);
1162 lSegmentCabinIndexMap.
1163 insert (stdair::SegmentCabinIndexMap_T::value_type (lCurrentSC_ptr,
1167 lCurrentSC_ptr->setSegmentSnapshotTable (lSegmentSnapshotTable);
1171 lSegmentSnapshotTable.initSnapshotBlocks(lSegmentCabinIndexMap,
1176 void InventoryManager::initSnapshotEvents (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
1177 const stdair::Date_T& iStartDate,
1178 const stdair::Date_T& iEndDate) {
1179 const stdair::Duration_T lTimeZero (0, 0, 0);
1180 const stdair::Duration_T lOneDayDuration (24, 0, 0);
1181 const stdair::DateTime_T lBeginSnapshotTime (iStartDate, lTimeZero);
1182 const stdair::DateTime_T lEndSnapshotTime (iEndDate, lTimeZero);
1185 stdair::NbOfEvents_T lNbOfSnapshots = 0.0;
1186 for (stdair::DateTime_T lSnapshotTime = lBeginSnapshotTime;
1187 lSnapshotTime < lEndSnapshotTime; lSnapshotTime += lOneDayDuration) {
1189 stdair::SnapshotPtr_T lSnapshotStruct =
1193 stdair::EventStruct lEventStruct (stdair::EventType::SNAPSHOT,
1203 ioSEVMGR_ServicePtr->addEvent (lEventStruct);
1208 ioSEVMGR_ServicePtr->addStatus (stdair::EventType::SNAPSHOT, lNbOfSnapshots);
1212 void InventoryManager::
1213 initRMEvents (
const stdair::Inventory& iInventory,
1214 stdair::RMEventList_T& ioRMEventList,
1215 const stdair::Date_T& iStartDate,
1216 const stdair::Date_T& iEndDate) {
1217 const stdair::Duration_T lTimeZero (0, 0, 0);
1218 const stdair::Duration_T lTime (0, 0, 10);
1219 const stdair::Duration_T lOneDayDuration (24, 0, 0);
1220 const stdair::DateTime_T lEarliestEventTime (iStartDate, lTimeZero);
1221 const stdair::DateTime_T lLatestEventTime (iEndDate, lTimeZero);
1223 const stdair::AirlineCode_T& lAirlineCode = iInventory.getAirlineCode();
1227 const stdair::FlightDateList_T& lFDList =
1228 stdair::BomManager::getList<stdair::FlightDate> (iInventory);
1229 for (stdair::FlightDateList_T::const_iterator itFD = lFDList.begin();
1230 itFD != lFDList.end(); ++itFD) {
1231 const stdair::FlightDate* lFD_ptr = *itFD;
1232 assert (lFD_ptr != NULL);
1236 const stdair::Date_T& lDepartureDate = lFD_ptr->getDepartureDate();
1237 const stdair::DateTime_T lDepatureDateTime (lDepartureDate, lTime);
1238 for (stdair::DCPList_T::const_iterator itDCP =
1239 stdair::DEFAULT_DCP_LIST.begin();
1240 itDCP != stdair::DEFAULT_DCP_LIST.end(); ++itDCP) {
1241 const stdair::DCP_T& lDCP = *itDCP;
1244 const stdair::DateTime_T lEventTime =
1245 lDepatureDateTime - lOneDayDuration * lDCP;
1246 if (lEventTime >= lEarliestEventTime && lEventTime <= lLatestEventTime){
1247 const stdair::KeyDescription_T lKeyDes = lFD_ptr->describeKey();
1248 stdair::RMEventStruct lRMEvent (lAirlineCode, lKeyDes, lEventTime);
1249 ioRMEventList.push_back (lRMEvent);
1256 void InventoryManager::
1257 addRMEventsToEventQueue (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
1258 stdair::RMEventList_T& ioRMEventList) {
1260 for (stdair::RMEventList_T::iterator itRMEvent = ioRMEventList.begin();
1261 itRMEvent != ioRMEventList.end(); ++itRMEvent) {
1262 stdair::RMEventStruct& lRMEvent = *itRMEvent;
1263 stdair::RMEventPtr_T lRMEventPtr =
1264 boost::make_shared<stdair::RMEventStruct> (lRMEvent);
1265 stdair::EventStruct lEventStruct (stdair::EventType::RM, lRMEventPtr);
1266 ioSEVMGR_ServicePtr->addEvent (lEventStruct);
1270 const stdair::Count_T lRMEventListSize = ioRMEventList.size();
1271 ioSEVMGR_ServicePtr->addStatus (stdair::EventType::RM, lRMEventListSize);
1279 STDAIR_LOG_DEBUG (
"Initialise the yield-based nesting structure for "
1280 <<
"all segment-cabins");
1283 const stdair::InventoryList_T& lInvList =
1284 stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
1287 for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
1288 itInv != lInvList.end(); ++itInv) {
1289 stdair::Inventory* lCurrentInv_ptr = *itInv;
1290 assert (lCurrentInv_ptr != NULL);
1291 const stdair::FlightDateList_T& lFlightDateList =
1292 stdair::BomManager::getList<stdair::FlightDate> (*lCurrentInv_ptr);
1295 for (stdair::FlightDateList_T::const_iterator itFD =
1296 lFlightDateList.begin(); itFD != lFlightDateList.end(); ++itFD) {
1297 const stdair::FlightDate* lFD_ptr = *itFD;
1298 assert (lFD_ptr != NULL);
1299 const stdair::SegmentDateList_T& lSegmentDateList =
1300 stdair::BomManager::getList<stdair::SegmentDate> (*lFD_ptr);
1303 for (stdair::SegmentDateList_T::const_iterator itSD =
1304 lSegmentDateList.begin(); itSD != lSegmentDateList.end(); ++itSD) {
1305 const stdair::SegmentDate* lSD_ptr = *itSD;
1306 assert (lSD_ptr != NULL);
1307 const stdair::SegmentCabinList_T& lSegmentCabinList =
1308 stdair::BomManager::getList<stdair::SegmentCabin> (*lSD_ptr);
1311 for (stdair::SegmentCabinList_T::const_iterator itSC =
1312 lSegmentCabinList.begin(); itSC != lSegmentCabinList.end();
1314 stdair::SegmentCabin* lSC_ptr = *itSC;
1315 assert (lSC_ptr != NULL);
1329 const stdair::InventoryList_T& lInvList =
1330 stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
1333 for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
1334 itInv != lInvList.end(); ++itInv) {
1335 stdair::Inventory* lCurrentInv_ptr = *itInv;
1336 assert (lCurrentInv_ptr != NULL);
1340 stdair::PreOptimisationMethod::EN_PreOptimisationMethod lPreOptMethod =
1341 lCurrentInv_ptr->getPreOptimisationMethod();
1343 if (lPreOptMethod == stdair::PreOptimisationMethod::MRT) {
1344 const stdair::FlightDateList_T& lFlightDateList =
1345 stdair::BomManager::getList<stdair::FlightDate> (*lCurrentInv_ptr);
1348 for (stdair::FlightDateList_T::const_iterator itFD =
1349 lFlightDateList.begin(); itFD != lFlightDateList.end(); ++itFD) {
1350 const stdair::FlightDate* lFD_ptr = *itFD;
1351 assert (lFD_ptr != NULL);
1352 const stdair::SegmentDateList_T& lSegmentDateList =
1353 stdair::BomManager::getList<stdair::SegmentDate> (*lFD_ptr);
1356 for (stdair::SegmentDateList_T::const_iterator itSD =
1357 lSegmentDateList.begin();
1358 itSD != lSegmentDateList.end(); ++itSD) {
1359 const stdair::SegmentDate* lSD_ptr = *itSD;
1360 assert (lSD_ptr != NULL);
1361 const stdair::SegmentCabinList_T& lSegmentCabinList =
1362 stdair::BomManager::getList<stdair::SegmentCabin> (*lSD_ptr);
1365 for (stdair::SegmentCabinList_T::const_iterator itSC =
1366 lSegmentCabinList.begin(); itSC != lSegmentCabinList.end();
1368 stdair::SegmentCabin* lSC_ptr = *itSC;
1369 assert (lSC_ptr != NULL);
1371 if (lSC_ptr->getFareFamilyStatus() ==
true) {