9 #include <stdair/basic/BasConst_General.hpp>
10 #include <stdair/basic/BasConst_Inventory.hpp>
11 #include <stdair/bom/BomManager.hpp>
12 #include <stdair/bom/SegmentDate.hpp>
13 #include <stdair/bom/SegmentCabin.hpp>
14 #include <stdair/bom/SegmentSnapshotTable.hpp>
15 #include <stdair/bom/FareFamily.hpp>
16 #include <stdair/bom/BookingClass.hpp>
17 #include <stdair/bom/Policy.hpp>
18 #include <stdair/service/Logger.hpp>
31 forecast (stdair::SegmentCabin& ioSegmentCabin,
32 const stdair::Date_T& iCurrentDate,
33 const stdair::DTD_T& iCurrentDTD,
34 const stdair::UnconstrainingMethod& iUnconstrainingMethod,
35 const stdair::NbOfSegments_T& iNbOfDepartedSegments) {
37 const stdair::SegmentSnapshotTable& lSegmentSnapshotTable =
38 ioSegmentCabin.getSegmentSnapshotTable();
42 const stdair::FareFamilyList_T& lFFList =
43 stdair::BomManager::getList<stdair::FareFamily>(ioSegmentCabin);
44 for (stdair::FareFamilyList_T::const_iterator itFF = lFFList.begin();
45 itFF != lFFList.end(); ++itFF) {
46 stdair::FareFamily* lFF_ptr = *itFF;
47 assert (lFF_ptr != NULL);
52 iUnconstrainingMethod,
53 iNbOfDepartedSegments,
54 lSegmentSnapshotTable);
58 dispatchDemandForecastToPolicies (ioSegmentCabin);
65 forecast (stdair::FareFamily& ioFareFamily,
66 const stdair::Date_T& iCurrentDate,
67 const stdair::DTD_T& iCurrentDTD,
68 const stdair::UnconstrainingMethod& iUnconstrainingMethod,
69 const stdair::NbOfSegments_T& iNbOfDepartedSegments,
70 const stdair::SegmentSnapshotTable& iSegmentSnapshotTable) {
72 const stdair::FRAT5Curve_T& lFRAT5Curve = ioFareFamily.getFrat5Curve();
76 const stdair::BookingClassList_T& lBCList =
77 stdair::BomManager::getList<stdair::BookingClass>(ioFareFamily);
78 const stdair::BookingClassSellUpCurveMap_T lBCSellUpCurveMap =
80 const stdair::BookingClassDispatchingCurveMap_T lBCDispatchingCurveMap =
85 const stdair::DCPList_T lWholeDCPList = stdair::DEFAULT_DCP_LIST;
86 stdair::DCPList_T::const_iterator itDCP = lWholeDCPList.begin();
87 stdair::DCPList_T::const_iterator itNextDCP = itDCP; ++itNextDCP;
88 for (; itNextDCP != lWholeDCPList.end(); ++itDCP, ++itNextDCP) {
89 const stdair::DCP_T& lCurrentDCP = *itDCP;
90 const stdair::DCP_T& lNextDCP = *itNextDCP;
93 if (lNextDCP < iCurrentDTD) {
96 const stdair::NbOfSegments_T& lNbOfUsableSegments =
101 stdair::NbOfSegments_T lSegmentBegin = 0;
102 const stdair::NbOfSegments_T lSegmentEnd = lNbOfUsableSegments-1;
103 if (iNbOfDepartedSegments > 52) {
104 lSegmentBegin = iNbOfDepartedSegments - 52;
109 HistoricalBookingHolder lHBHolder;
110 preparePriceOrientedHistoricalBooking (ioFareFamily,
111 iSegmentSnapshotTable,
113 lCurrentDCP, lNextDCP,
114 lSegmentBegin, lSegmentEnd,
122 stdair::UncDemVector_T lUncDemVector;
125 const short lNbOfHistoricalFlights = lHBHolder.getNbOfFlights();
126 for (
short i = 0; i < lNbOfHistoricalFlights; ++i) {
127 const stdair::NbOfBookings_T& lUncDemand =
128 lHBHolder.getUnconstrainedDemand (i);
129 lUncDemVector.push_back (lUncDemand);
131 stdair::MeanValue_T lMean = 0.0;
132 stdair::StdDevValue_T lStdDev = 0.0;
138 lMean, lStdDev, lCurrentDCP);
143 lMean, lStdDev, lCurrentDCP);
146 const stdair::MeanValue_T& lCurrentMean = ioFareFamily.getMean();
147 const stdair::StdDevValue_T& lCurrentStdDev = ioFareFamily.getStdDev();
149 const stdair::MeanValue_T lNewMean = lCurrentMean + lMean;
150 const stdair::StdDevValue_T lNewStdDev =
151 std::sqrt (lCurrentStdDev * lCurrentStdDev + lStdDev * lStdDev);
153 ioFareFamily.setMean (lNewMean);
154 ioFareFamily.setStdDev (lNewStdDev);
161 void NewQFF::preparePriceOrientedHistoricalBooking
162 (
const stdair::FareFamily& iFareFamily,
163 const stdair::SegmentSnapshotTable& iSegmentSnapshotTable,
164 HistoricalBookingHolder& ioHBHolder,
165 const stdair::DCP_T& iDCPBegin,
const stdair::DCP_T& iDCPEnd,
166 const stdair::NbOfSegments_T& iSegmentBegin,
167 const stdair::NbOfSegments_T& iSegmentEnd,
168 const stdair::BookingClassSellUpCurveMap_T& iBCSellUpCurveMap) {
171 const stdair::ConstSegmentCabinDTDRangeSnapshotView_T lPriceBookingView =
172 iSegmentSnapshotTable.getConstSegmentCabinDTDRangePriceOrientedGrossBookingSnapshotView (iSegmentBegin, iSegmentEnd, iDCPEnd, iDCPBegin);
173 const stdair::ConstSegmentCabinDTDRangeSnapshotView_T lProductBookingView =
174 iSegmentSnapshotTable.getConstSegmentCabinDTDRangeProductOrientedGrossBookingSnapshotView (iSegmentBegin, iSegmentEnd, iDCPEnd, iDCPBegin);
175 const stdair::ConstSegmentCabinDTDRangeSnapshotView_T lAvlView =
176 iSegmentSnapshotTable.getConstSegmentCabinDTDRangeAvailabilitySnapshotView (iSegmentBegin, iSegmentEnd, iDCPEnd, iDCPBegin);
179 const stdair::ClassIndexMap_T& lVTIdxMap =
180 iSegmentSnapshotTable.getClassIndexMap();
181 const stdair::NbOfClasses_T lNbOfClasses = lVTIdxMap.size();
183 for (
short i = 0; i <= iSegmentEnd-iSegmentBegin; ++i) {
184 stdair::Flag_T lCensorshipFlag =
false;
185 const short lNbOfDTDs = iDCPBegin - iDCPEnd + 1;
188 for (
short j = 0; j < lNbOfDTDs; ++j) {
192 bool tempCensorship =
true;
193 for (stdair::BookingClassSellUpCurveMap_T::const_iterator itBCSUC =
194 iBCSellUpCurveMap.begin();
195 itBCSUC != iBCSellUpCurveMap.end(); ++itBCSUC) {
196 const stdair::BookingClass* lBookingClass_ptr = itBCSUC->first;
197 assert (lBookingClass_ptr != NULL);
198 const stdair::ClassIndex_T& lClassIdx =
199 iSegmentSnapshotTable.getClassIndex(lBookingClass_ptr->describeKey());
200 const stdair::UnsignedIndex_T lAvlIdx = i*lNbOfClasses + lClassIdx;
201 if (lAvlView[lAvlIdx][j] >= 1.0) {
202 tempCensorship =
false;
206 if (tempCensorship ==
true) {
207 lCensorshipFlag =
true;
213 stdair::NbOfBookings_T lNbOfHistoricalBkgs = 0.0;
214 for (stdair::BookingClassSellUpCurveMap_T::const_iterator itBCSUC =
215 iBCSellUpCurveMap.begin();
216 itBCSUC != iBCSellUpCurveMap.end(); ++itBCSUC) {
217 const stdair::BookingClass* lBookingClass_ptr = itBCSUC->first;
218 assert (lBookingClass_ptr != NULL);
219 const stdair::SellUpCurve_T& lSellUpCurve = itBCSUC->second;
220 stdair::SellUpCurve_T::const_iterator itSellUp =
221 lSellUpCurve.find (iDCPBegin);
222 assert (itSellUp != lSellUpCurve.end());
223 const stdair::SellupProbability_T& lSellUp = itSellUp->second;
224 assert (lSellUp != 0);
227 const stdair::ClassIndex_T& lClassIdx =
228 iSegmentSnapshotTable.getClassIndex(lBookingClass_ptr->describeKey());
229 const stdair::UnsignedIndex_T lIdx = i*lNbOfClasses + lClassIdx;
231 stdair::NbOfBookings_T lNbOfBookings = 0.0;
232 for (
short j = 0; j < lNbOfDTDs; ++j) {
234 lPriceBookingView[lIdx][j] + lProductBookingView[lIdx][j];
236 const stdair::NbOfBookings_T lNbOfQEquivalentBkgs=lNbOfBookings/lSellUp;
238 lNbOfHistoricalBkgs += lNbOfQEquivalentBkgs;
241 HistoricalBooking lHistoricalBkg (lNbOfHistoricalBkgs, lCensorshipFlag);
242 ioHBHolder.addHistoricalBooking (lHistoricalBkg);
248 dispatchDemandForecastToPolicies (
const stdair::SegmentCabin& iSegmentCabin){
250 const stdair::PolicyList_T& lPolicyList =
251 stdair::BomManager::getList<stdair::Policy> (iSegmentCabin);
253 for (stdair::PolicyList_T::const_iterator itPolicy = lPolicyList.begin();
254 itPolicy != lPolicyList.end(); ++itPolicy) {
255 stdair::Policy* lPolicy_ptr = *itPolicy;
256 assert (lPolicy_ptr != NULL);
257 dispatchDemandForecastToPolicy(*lPolicy_ptr);
263 dispatchDemandForecastToPolicy (stdair::Policy& ioPolicy){
265 ioPolicy.resetDemandForecast();
267 const stdair::MeanValue_T& lPolicyDemand = ioPolicy.getDemand();
268 const stdair::StdDevValue_T& lPolicyStdDev = ioPolicy.getStdDev();
269 stdair::MeanValue_T lNewPolicyDemand = lPolicyDemand;
270 stdair::MeanValue_T lNewPolicyStdDev = lPolicyStdDev;
274 const bool hasAListOfBC =
275 stdair::BomManager::hasList<stdair::BookingClass> (ioPolicy);
276 if (hasAListOfBC ==
true) {
277 const stdair::BookingClassList_T& lBCList =
278 stdair::BomManager::getList<stdair::BookingClass> (ioPolicy);
279 for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
280 itBC != lBCList.end(); ++itBC) {
281 const stdair::BookingClass* lBC_ptr = *itBC;
282 assert (lBC_ptr != NULL);
283 const stdair::Yield_T& lYield = lBC_ptr->getYield();
284 const stdair::MeanValue_T& lDemand = lBC_ptr->getCumuPriceDemMean();
285 const stdair::StdDevValue_T& lStdDev =
286 lBC_ptr->getCumuPriceDemStdDev();
288 ioPolicy.addYieldDemand (lYield, lDemand);
289 lNewPolicyDemand += lDemand;
290 const stdair::StdDevValue_T lSquareNewPolicyStdDev =
291 lNewPolicyStdDev*lNewPolicyStdDev + lStdDev*lStdDev;
293 std::sqrt (lSquareNewPolicyStdDev);
295 ioPolicy.setDemand(lNewPolicyDemand);
296 ioPolicy.setStdDev(lNewPolicyStdDev);