8 #include <stdair/basic/BasConst_Inventory.hpp>
9 #include <stdair/bom/BomRetriever.hpp>
10 #include <stdair/bom/BomManager.hpp>
11 #include <stdair/bom/SegmentDate.hpp>
12 #include <stdair/bom/SegmentCabin.hpp>
13 #include <stdair/bom/FareFamily.hpp>
14 #include <stdair/bom/BookingClass.hpp>
15 #include <stdair/bom/GuillotineBlock.hpp>
16 #include <stdair/service/Logger.hpp>
28 const stdair::DateTime_T& iSnapshotTime) {
31 const stdair::SegmentCabinIndexMap_T& lSegmentCabinIndexMap =
32 ioGuillotineBlock.getSegmentCabinIndexMap();
33 for (stdair::SegmentCabinIndexMap_T::const_iterator itSCIdx =
34 lSegmentCabinIndexMap.begin();
35 itSCIdx != lSegmentCabinIndexMap.end(); ++itSCIdx) {
36 const stdair::SegmentCabin* lSC_ptr = itSCIdx->first;
37 assert (lSC_ptr != NULL);
38 const stdair::BlockNumber_T& lSCIdx = itSCIdx->second;
40 const stdair::Date_T& lSnapshotDate = iSnapshotTime.date();
44 const stdair::SegmentDate& lSegmentDate =
45 stdair::BomManager::getParent<stdair::SegmentDate> (*lSC_ptr);
46 const stdair::Date_T& lDepartureDate = lSegmentDate.getBoardingDate();
47 const stdair::DateOffset_T lDateOffset = lDepartureDate - lSnapshotDate;
48 const stdair::DTD_T lDTD = lDateOffset.days() + 1;
50 if (lDTD >= 0 && lDTD <= stdair::DEFAULT_MAX_DTD) {
53 registerProductAndPriceOrientedBookings (ioGuillotineBlock,
54 lDTD, *lSC_ptr, lSCIdx);
62 const stdair::DTD_T& iDTD,
63 const stdair::SegmentCabin& iSegmentCabin,
64 const stdair::BlockNumber_T iSegmentCabinIdx) {
67 stdair::SegmentCabinDTDSnapshotView_T lBookingView = ioGuillotineBlock.
68 getSegmentCabinDTDBookingSnapshotView (iSegmentCabinIdx,
69 iSegmentCabinIdx, iDTD);
70 stdair::SegmentCabinDTDSnapshotView_T lCancellationView = ioGuillotineBlock.
71 getSegmentCabinDTDCancellationSnapshotView (iSegmentCabinIdx,
72 iSegmentCabinIdx, iDTD);
73 stdair::SegmentCabinDTDSnapshotView_T lAvailabilityView = ioGuillotineBlock.
74 getSegmentCabinDTDAvailabilitySnapshotView (iSegmentCabinIdx,
75 iSegmentCabinIdx, iDTD);
78 std::ostringstream lSCMapKey;
79 lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE
80 << iSegmentCabin.describeKey();
81 const stdair::BlockIndex_T& lCabinIdx =
82 ioGuillotineBlock.getBlockIndex (lSCMapKey.str());
83 lAvailabilityView[lCabinIdx] = iSegmentCabin.getAvailabilityPool();
87 const stdair::BookingClassList_T& lBCList =
88 stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
89 for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
90 itBC != lBCList.end(); ++itBC) {
91 const stdair::BookingClass* lBookingClass_ptr = *itBC;
92 assert (lBookingClass_ptr != NULL);
95 const stdair::BlockIndex_T& lIdx =
96 ioGuillotineBlock.getBlockIndex (lBookingClass_ptr->describeKey());
106 lBookingView[lIdx]=lBookingClass_ptr->getNbOfBookings();
107 lCancellationView[lIdx] =
108 lBookingClass_ptr->getNbOfCancellations();
109 lAvailabilityView[lIdx] =
110 lBookingClass_ptr->getSegmentAvailability();
115 void GuillotineBlockHelper::registerProductAndPriceOrientedBookings
116 (stdair::GuillotineBlock& ioGuillotineBlock,
const stdair::DTD_T& iDTD,
117 const stdair::SegmentCabin& iSegmentCabin,
118 const stdair::BlockNumber_T iSegmentCabinIdx) {
121 stdair::SegmentCabinDTDRangeSnapshotView_T lRangeBookingView =
122 ioGuillotineBlock.getSegmentCabinDTDRangeBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD, iDTD + 1);
123 stdair::SegmentCabinDTDRangeSnapshotView_T lRangeCancellationView =
124 ioGuillotineBlock.getSegmentCabinDTDRangeCancellationSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD, iDTD + 1);
125 stdair::SegmentCabinDTDSnapshotView_T lProductAndPriceOrientedBookingView =
126 ioGuillotineBlock.getSegmentCabinDTDProductAndPriceOrientedBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD);
129 std::ostringstream lSCMapKey;
130 lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE
131 << iSegmentCabin.describeKey();
132 const stdair::BlockIndex_T& lCabinIdx =
133 ioGuillotineBlock.getBlockIndex (lSCMapKey.str());
137 const stdair::BookingClassList_T& lBCList =
138 stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
139 stdair::BookingClassList_T::const_reverse_iterator itBC = lBCList.rbegin();
140 assert (itBC != lBCList.rend());
141 stdair::BookingClass* lLowestClass_ptr = *itBC; ++itBC;
142 assert (lLowestClass_ptr != NULL);
145 const stdair::BlockIndex_T& lClassIdx =
146 ioGuillotineBlock.getBlockIndex (lLowestClass_ptr->describeKey());
149 const stdair::NbOfBookings_T lNbOfNetBkgs =
150 lRangeBookingView[lClassIdx][0] - lRangeBookingView[lClassIdx][1];
151 const stdair::NbOfCancellations_T lNbOfCx =
152 lRangeCancellationView[lClassIdx][0]-lRangeCancellationView[lClassIdx][1];
153 const stdair::NbOfBookings_T lNbOfGrossBkgs = lNbOfNetBkgs + lNbOfCx;
156 lProductAndPriceOrientedBookingView[lCabinIdx] = lNbOfGrossBkgs;
159 const stdair::Yield_T& lLowestYield = lLowestClass_ptr->getYield();
162 bool noLowerClassAvl =
true;
163 if (lLowestClass_ptr->getSegmentAvailability() >= 1.0) {
164 noLowerClassAvl =
false;
168 const double lFRAT5Coef = getFRAT5Coefficient (iDTD);
169 const double lSellUpCoef = -log(0.5) / (lFRAT5Coef - 1);
172 for (; itBC != lBCList.rend(); ++itBC) {
173 const stdair::BookingClass* lBookingClass_ptr = *itBC;
174 assert (lBookingClass_ptr != NULL);
177 const stdair::Yield_T& lYield = lBookingClass_ptr->getYield();
178 assert (lYield > lLowestYield);
181 const stdair::BlockIndex_T& lIdx =
182 ioGuillotineBlock.getBlockIndex (lBookingClass_ptr->describeKey());
185 const stdair::NbOfBookings_T lNetBkgs =
186 lRangeBookingView[lIdx][0] - lRangeBookingView[lIdx][1];
187 const stdair::NbOfCancellations_T lCx =
188 lRangeCancellationView[lIdx][0] - lRangeCancellationView[lIdx][1];
189 const stdair::NbOfBookings_T lGrossBkgs = lNetBkgs + lCx;
194 if (noLowerClassAvl ==
false) {
195 lProductAndPriceOrientedBookingView[lIdx] = lGrossBkgs;
198 const stdair::NbOfBookings_T lQEquiBkgs =
199 lGrossBkgs / exp ((1.0 - lYield/lLowestYield) * lSellUpCoef);
200 lProductAndPriceOrientedBookingView[lCabinIdx] += lQEquiBkgs;
202 if (lBookingClass_ptr->getSegmentAvailability() >= 1.0) {
203 noLowerClassAvl =
false;
210 double GuillotineBlockHelper::getFRAT5Coefficient (
const stdair::DTD_T& iDTD){
211 FRAT5Curve_T::const_iterator itFRAT5 =
216 return itFRAT5->second;
220 FRAT5Curve_T::const_iterator itNextFRAT5 = itFRAT5; --itNextFRAT5;
222 const stdair::DTD_T& lPrevDTD = itFRAT5->first;
223 const stdair::DTD_T& lNextDTD = itNextFRAT5->first;
224 const double& lPrevFRAT5 = itFRAT5->second;
225 const double& lNextFRAT5 = itNextFRAT5->second;
226 assert (lPrevDTD > lNextDTD);
228 double oFRAT5 = lPrevFRAT5
229 + (iDTD - lNextDTD) * (lNextFRAT5 - lPrevFRAT5) / (lPrevDTD - lNextDTD);