7 #include <stdair/basic/BasConst_Inventory.hpp>
8 #include <stdair/bom/GuillotineBlock.hpp>
9 #include <stdair/bom/BomManager.hpp>
10 #include <stdair/bom/FlightDate.hpp>
11 #include <stdair/bom/SegmentDate.hpp>
12 #include <stdair/bom/SegmentCabin.hpp>
13 #include <stdair/bom/BookingClass.hpp>
14 #include <stdair/service/Logger.hpp>
28 const stdair::DCP_T& iDCPBegin,
const stdair::DCP_T& iDCPEnd,
29 const stdair::Date_T& iCurrentDate) {
32 const stdair::GuillotineBlock& lGuillotineBlock =
33 iSegmentCabin.getGuillotineBlock();
42 for (BookingClassUnconstrainedDemandVectorMap_T::iterator itBCUDV =
43 ioBkgClassUncDemMap.begin(); itBCUDV != ioBkgClassUncDemMap.end();
45 stdair::BookingClass* lBC_ptr = itBCUDV->first;
46 assert (lBC_ptr != NULL);
47 const stdair::MapKey_T& lBCKey = lBC_ptr->describeKey();
48 const stdair::BlockIndex_T& lBlockIdx =
49 lGuillotineBlock.getBlockIndex (lBCKey);
52 STDAIR_LOG_DEBUG (
"Unconstrain product-oriented bookings for " << lBCKey);
57 lNbOfUsableSegments, lBlockIdx);
62 std::ostringstream lSCMapKey;
63 lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE
64 << iSegmentCabin.describeKey();
65 const stdair::BlockIndex_T& lCabinIdx =
66 lGuillotineBlock.getBlockIndex (lSCMapKey.str());
68 STDAIR_LOG_DEBUG (
"Unconstrain price-oriented bookings");
71 iDCPBegin, iDCPEnd, lNbOfUsableSegments,
72 lCabinIdx, iSegmentCabin, iCurrentDate);
77 (
const stdair::GuillotineBlock& iGuillotineBlock,
79 const stdair::DCP_T& iDCPBegin,
const stdair::DCP_T& iDCPEnd,
80 const stdair::NbOfSegments_T& iNbOfUsableSegments,
81 const stdair::BlockIndex_T& iBlockIdx) {
83 stdair::NbOfSegments_T lSegBegin = 0;
84 if (iNbOfUsableSegments > 52) lSegBegin = iNbOfUsableSegments - 52;
86 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lBookingView =
87 iGuillotineBlock.getConstSegmentCabinDTDRangeProductAndPriceOrientedBookingSnapshotView (lSegBegin, iNbOfUsableSegments -1, iDCPEnd, iDCPBegin);
88 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lAvlView =
89 iGuillotineBlock.getConstSegmentCabinDTDRangeAvailabilitySnapshotView (lSegBegin, iNbOfUsableSegments -1, iDCPEnd, iDCPBegin);
92 const stdair::ValueTypeIndexMap_T& lVTIdxMap =
93 iGuillotineBlock.getValueTypeIndexMap();
94 const unsigned int lNbOfValueTypes = lVTIdxMap.size();
96 for (
short i = 0; i < iNbOfUsableSegments-lSegBegin; ++i) {
97 stdair::Flag_T lCensorshipFlag =
false;
98 stdair::NbOfBookings_T lNbOfHistoricalBkgs = 0.0;
99 const short lNbOfDTDs = iDCPBegin - iDCPEnd + 1;
102 for (
short j = 0; j < lNbOfDTDs; ++j) {
106 if (lCensorshipFlag ==
false) {
107 if (lAvlView[i*lNbOfValueTypes + iBlockIdx][j] < 1.0) {
108 lCensorshipFlag =
true;
114 lNbOfHistoricalBkgs += lBookingView[i*lNbOfValueTypes + iBlockIdx][j];
117 HistoricalBooking lHistoricalBkg (lNbOfHistoricalBkgs, lCensorshipFlag);
121 STDAIR_LOG_DEBUG (
"Historical bkgs: " << lNbOfHistoricalBkgs
122 <<
", censored: " << lCensorshipFlag);
128 STDAIR_LOG_DEBUG (
"Unconstrain by EM");
136 for (UnconstrainedDemandVector_T::iterator itUD = ioUncDemVector.begin();
137 itUD != ioUncDemVector.end(); ++itUD, ++idx) {
145 (
const stdair::GuillotineBlock& iGuillotineBlock,
147 const stdair::DCP_T& iDCPBegin,
const stdair::DCP_T& iDCPEnd,
148 const stdair::NbOfSegments_T& iNbOfUsableSegments,
149 const stdair::BlockIndex_T& iBlockIdx,
150 const stdair::SegmentCabin& iSegmentCabin,
151 const stdair::Date_T& iCurrentDate) {
153 stdair::NbOfSegments_T lSegBegin = 0;
154 if (iNbOfUsableSegments > 52) lSegBegin = iNbOfUsableSegments - 52;
156 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lBookingView =
157 iGuillotineBlock.getConstSegmentCabinDTDRangeProductAndPriceOrientedBookingSnapshotView (lSegBegin, iNbOfUsableSegments -1, iDCPEnd, iDCPBegin);
158 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lAvlView =
159 iGuillotineBlock.getConstSegmentCabinDTDRangeAvailabilitySnapshotView (lSegBegin, iNbOfUsableSegments -1, iDCPEnd, iDCPBegin);
162 const stdair::ValueTypeIndexMap_T& lVTIdxMap =
163 iGuillotineBlock.getValueTypeIndexMap();
164 const unsigned int lNbOfValueTypes = lVTIdxMap.size();
165 HistoricalBookingHolder lHBHolder;
166 for (
short i = 0; i < iNbOfUsableSegments-lSegBegin; ++i) {
167 stdair::Flag_T lCensorshipFlag =
false;
168 stdair::NbOfBookings_T lNbOfHistoricalBkgs = 0.0;
169 const short lNbOfDTDs = iDCPBegin - iDCPEnd + 1;
172 for (
short j = 0; j < lNbOfDTDs; ++j) {
176 if (lCensorshipFlag ==
false) {
177 if (lAvlView[i*lNbOfValueTypes + iBlockIdx][j] < 1.0) {
178 lCensorshipFlag =
true;
184 lNbOfHistoricalBkgs += lBookingView[i*lNbOfValueTypes + iBlockIdx][j];
187 HistoricalBooking lHistoricalBkg (lNbOfHistoricalBkgs, lCensorshipFlag);
188 lHBHolder.addHistoricalBooking (lHistoricalBkg);
191 STDAIR_LOG_DEBUG (
"Historical bkgs: " << lNbOfHistoricalBkgs
192 <<
", censored: " << lCensorshipFlag);
198 STDAIR_LOG_DEBUG (
"Unconstrain by EM");
206 const stdair::SegmentDate& lSegmentDate = stdair::BomManager::
207 getParent<stdair::SegmentDate, stdair::SegmentCabin> (iSegmentCabin);
208 const stdair::FlightDate& lFlightDate = stdair::BomManager::
209 getParent<stdair::FlightDate, stdair::SegmentDate> (lSegmentDate);
210 const stdair::Date_T& lDepDate = lFlightDate.getDepartureDate();
211 const boost::gregorian::date_duration lDD = lDepDate - iCurrentDate;
212 const long lDTD = lDD.days();
213 stdair::Date_T lRefDate (2012, boost::gregorian::Jan, 01);
216 for (UnconstrainedDemandVector_T::iterator itUD = ioUncDemVector.begin();
217 itUD != ioUncDemVector.end(); ++itUD, ++idx) {
218 *itUD += lHBHolder.getUnconstrainedDemand (idx);
219 if (lDepDate > lRefDate) {
220 const stdair::DateOffset_T lDateOffset (7 *(52 - idx) + 420);
221 const stdair::Date_T lHDate = lDepDate - lDateOffset;
222 STDAIR_LOG_NOTIFICATION (boost::gregorian::to_iso_string(lDepDate)
223 <<
";" << lDTD <<
";" << iDCPBegin <<
";"
225 << boost::gregorian::to_iso_string (lHDate)
226 <<
";"<<lHBHolder.getUnconstrainedDemand (idx));
228 STDAIR_LOG_NOTIFICATION (boost::gregorian::to_iso_string(lDepDate)
229 <<
";" << lDTD <<
";" << iDCPBegin <<
";"
231 << boost::gregorian::to_iso_string (lHDate)
232 <<
";"<<lHBHolder.getHistoricalBooking (idx));
239 (
const stdair::SegmentCabin& iSegmentCabin,
242 const stdair::DCP_T& iFirstDCP,
const stdair::NbOfSegments_T& iNbOfSegments,
243 const stdair::NbOfSegments_T& iNbOfUsedSegments){
246 const stdair::GuillotineBlock& lGuillotineBlock =
247 iSegmentCabin.getGuillotineBlock();
250 for (BookingClassUnconstrainedDemandVectorMap_T::iterator itBCUDV =
251 ioBkgClassUncDemVectorMap.begin();
252 itBCUDV != ioBkgClassUncDemVectorMap.end(); ++itBCUDV) {
253 stdair::BookingClass* lBC_ptr = itBCUDV->first;
254 assert (lBC_ptr != NULL);
255 const stdair::MapKey_T& lBCKey = lBC_ptr->describeKey();
256 const stdair::BlockIndex_T& lBlockIdx =
257 lGuillotineBlock.getBlockIndex (lBCKey);
260 STDAIR_LOG_DEBUG(
"Retrieve the unconstrained product-oriented demand for "
262 retrieveUnconstrainedDemandForFirstDCP (lGuillotineBlock, lUncDemVector,
263 iFirstDCP, lBlockIdx,
264 iNbOfSegments, iNbOfUsedSegments);
269 std::ostringstream lSCMapKey;
270 lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE
271 << iSegmentCabin.describeKey();
272 const stdair::BlockIndex_T& lCabinValueIdx =
273 lGuillotineBlock.getBlockIndex (lSCMapKey.str());
275 STDAIR_LOG_DEBUG (
"Retrieve the unconstrained price-oriented demand");
276 retrieveUnconstrainedDemandForFirstDCP (lGuillotineBlock,
277 ioQEquivalentDemandVector,iFirstDCP,
278 lCabinValueIdx, iNbOfSegments,
284 (
const stdair::GuillotineBlock& iGuillotineBlock,
286 const stdair::DCP_T& iFirstDCP,
const stdair::BlockIndex_T& iValueIdx,
287 const stdair::NbOfSegments_T& iNbOfSegments,
288 const stdair::NbOfSegments_T& iNbOfUsedSegments) {
291 stdair::NbOfSegments_T lSegBegin = iNbOfSegments - iNbOfUsedSegments;
295 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lRangeBookingView =
296 iGuillotineBlock.getConstSegmentCabinDTDRangeProductAndPriceOrientedBookingSnapshotView (lSegBegin, iNbOfSegments -1, iFirstDCP, stdair::DEFAULT_MAX_DTD);
300 const stdair::ValueTypeIndexMap_T& lVTIdxMap =
301 iGuillotineBlock.getValueTypeIndexMap();
302 const unsigned int lNbOfValueTypes = lVTIdxMap.size();
303 for (
int itSegment = 0; itSegment < iNbOfSegments-lSegBegin; ++itSegment) {
304 for (
int i = iFirstDCP; i <= stdair::DEFAULT_MAX_DTD; ++i) {
305 stdair::NbOfRequests_T& lUncDemand =
306 ioUnconstrainedDemandVector.at(itSegment);
308 lRangeBookingView[iValueIdx + itSegment*lNbOfValueTypes][i-iFirstDCP];
317 (
const stdair::SegmentCabin& iSegmentCabin,
320 const stdair::DCP_T& iDCPBegin,
const stdair::DCP_T& iDCPEnd,
321 const stdair::Date_T& iCurrentDate,
322 const stdair::NbOfSegments_T& iNbOfDepartedSegments) {
325 const stdair::GuillotineBlock& lGuillotineBlock =
326 iSegmentCabin.getGuillotineBlock();
335 for (BookingClassUnconstrainedDemandVectorMap_T::iterator itBCUDV =
336 ioBkgClassUncDemMap.begin(); itBCUDV != ioBkgClassUncDemMap.end();
338 stdair::BookingClass* lBC_ptr = itBCUDV->first;
339 assert (lBC_ptr != NULL);
340 const stdair::MapKey_T& lBCKey = lBC_ptr->describeKey();
341 const stdair::BlockIndex_T& lBlockIdx =
342 lGuillotineBlock.getBlockIndex (lBCKey);
345 STDAIR_LOG_DEBUG (
"Unconstrain product-oriented bookings for " << lBCKey);
346 unconstrainUsingMultiplicativePickUp (lGuillotineBlock, lUncDemVector,
348 lNbOfUsableSegments, lBlockIdx,
349 iNbOfDepartedSegments);
354 std::ostringstream lSCMapKey;
355 lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE
356 << iSegmentCabin.describeKey();
357 const stdair::BlockIndex_T& lCabinIdx =
358 lGuillotineBlock.getBlockIndex (lSCMapKey.str());
360 STDAIR_LOG_DEBUG (
"Unconstrain price-oriented bookings");
361 unconstrainUsingMultiplicativePickUp (lGuillotineBlock,
362 ioQEquivalentDemandVector,
364 lNbOfUsableSegments, lCabinIdx,
365 iNbOfDepartedSegments,
366 iSegmentCabin, iCurrentDate);
371 (
const stdair::GuillotineBlock& iGuillotineBlock,
373 const stdair::DCP_T& iDCPBegin,
const stdair::DCP_T& iDCPEnd,
374 const stdair::NbOfSegments_T& iNbOfUsableSegments,
375 const stdair::BlockIndex_T& iBlockIdx,
376 const stdair::NbOfSegments_T& iNbOfDepartedSegments) {
378 stdair::NbOfSegments_T lSegBegin = 0;
379 if (iNbOfDepartedSegments > 52) {
380 lSegBegin = iNbOfDepartedSegments - 52;
384 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lBookingView =
385 iGuillotineBlock.getConstSegmentCabinDTDRangeProductAndPriceOrientedBookingSnapshotView (lSegBegin, iNbOfUsableSegments -1, iDCPEnd, iDCPBegin);
386 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lAvlView =
387 iGuillotineBlock.getConstSegmentCabinDTDRangeAvailabilitySnapshotView (lSegBegin, iNbOfUsableSegments -1, iDCPEnd, iDCPBegin);
390 const stdair::ValueTypeIndexMap_T& lVTIdxMap =
391 iGuillotineBlock.getValueTypeIndexMap();
392 const unsigned int lNbOfValueTypes = lVTIdxMap.size();
393 HistoricalBookingHolder lHBHolder;
394 std::vector<short> lDataIndexList;
395 for (
short i = 0; i < iNbOfUsableSegments-lSegBegin; ++i) {
396 stdair::Flag_T lCensorshipFlag =
false;
397 stdair::NbOfBookings_T lNbOfHistoricalBkgs = 0.0;
398 const short lNbOfDTDs = iDCPBegin - iDCPEnd + 1;
401 for (
short j = 0; j < lNbOfDTDs; ++j) {
405 if (lCensorshipFlag ==
false) {
406 if (lAvlView[i*lNbOfValueTypes + iBlockIdx][j] < 1.0) {
407 lCensorshipFlag =
true;
413 lNbOfHistoricalBkgs += lBookingView[i*lNbOfValueTypes + iBlockIdx][j];
418 stdair::NbOfRequests_T& lUncDemand = ioUncDemVector.at (i);
419 if (lUncDemand < 1.0) {
420 lUncDemand += lNbOfHistoricalBkgs;
422 double lBkgDemandFactor = lNbOfHistoricalBkgs / lUncDemand;
423 HistoricalBooking lHistoricalBkg (lBkgDemandFactor, lCensorshipFlag);
424 lHBHolder.addHistoricalBooking (lHistoricalBkg);
425 lDataIndexList.push_back (i);
429 STDAIR_LOG_DEBUG (
"Historical bkgs: " << lNbOfHistoricalBkgs
430 <<
", censored: " << lCensorshipFlag);
434 STDAIR_LOG_DEBUG (
"Unconstrain by multiplicative pick-up using EM");
441 for (std::vector<short>::iterator itIdx = lDataIndexList.begin();
442 itIdx != lDataIndexList.end(); ++itIdx, ++i) {
444 stdair::NbOfRequests_T& lPastDemand = ioUncDemVector.at (lIdx);
445 const stdair::NbOfRequests_T& lUncDemandFactorOfThisPeriod =
446 lHBHolder.getUnconstrainedDemand (i);
447 lPastDemand *= (1+lUncDemandFactorOfThisPeriod);
453 (
const stdair::GuillotineBlock& iGuillotineBlock,
455 const stdair::DCP_T& iDCPBegin,
const stdair::DCP_T& iDCPEnd,
456 const stdair::NbOfSegments_T& iNbOfUsableSegments,
457 const stdair::BlockIndex_T& iBlockIdx,
458 const stdair::NbOfSegments_T& iNbOfDepartedSegments,
459 const stdair::SegmentCabin& iSegmentCabin,
460 const stdair::Date_T& iCurrentDate) {
462 stdair::NbOfSegments_T lSegBegin = 0;
463 if (iNbOfDepartedSegments > 52) {
464 lSegBegin = iNbOfDepartedSegments - 52;
468 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lBookingView =
469 iGuillotineBlock.getConstSegmentCabinDTDRangeProductAndPriceOrientedBookingSnapshotView (lSegBegin, iNbOfUsableSegments -1, iDCPEnd, iDCPBegin);
470 stdair::ConstSegmentCabinDTDRangeSnapshotView_T lAvlView =
471 iGuillotineBlock.getConstSegmentCabinDTDRangeAvailabilitySnapshotView (lSegBegin, iNbOfUsableSegments -1, iDCPEnd, iDCPBegin);
474 const stdair::ValueTypeIndexMap_T& lVTIdxMap =
475 iGuillotineBlock.getValueTypeIndexMap();
476 const unsigned int lNbOfValueTypes = lVTIdxMap.size();
477 HistoricalBookingHolder lHBHolder;
478 std::vector<short> lDataIndexList;
479 for (
short i = 0; i < iNbOfUsableSegments-lSegBegin; ++i) {
480 stdair::Flag_T lCensorshipFlag =
false;
481 stdair::NbOfBookings_T lNbOfHistoricalBkgs = 0.0;
482 const short lNbOfDTDs = iDCPBegin - iDCPEnd + 1;
485 for (
short j = 0; j < lNbOfDTDs; ++j) {
489 if (lCensorshipFlag ==
false) {
490 if (lAvlView[i*lNbOfValueTypes + iBlockIdx][j] < 1.0) {
491 lCensorshipFlag =
true;
497 lNbOfHistoricalBkgs += lBookingView[i*lNbOfValueTypes + iBlockIdx][j];
502 stdair::NbOfRequests_T& lUncDemand = ioUncDemVector.at (i);
503 if (lUncDemand < 1.0) {
504 lUncDemand += lNbOfHistoricalBkgs;
506 double lBkgDemandFactor = lNbOfHistoricalBkgs / lUncDemand;
507 HistoricalBooking lHistoricalBkg (lBkgDemandFactor, lCensorshipFlag);
508 lHBHolder.addHistoricalBooking (lHistoricalBkg);
509 lDataIndexList.push_back (i);
513 STDAIR_LOG_DEBUG (
"Historical bkgs: " << lNbOfHistoricalBkgs
514 <<
", censored: " << lCensorshipFlag);
518 STDAIR_LOG_DEBUG (
"Unconstrain by multiplicative pick-up");
525 const stdair::SegmentDate& lSegmentDate = stdair::BomManager::
526 getParent<stdair::SegmentDate, stdair::SegmentCabin> (iSegmentCabin);
527 const stdair::FlightDate& lFlightDate = stdair::BomManager::
528 getParent<stdair::FlightDate, stdair::SegmentDate> (lSegmentDate);
529 const stdair::Date_T& lDepDate = lFlightDate.getDepartureDate();
530 const boost::gregorian::date_duration lDD = lDepDate - iCurrentDate;
531 const long lDTD = lDD.days();
532 stdair::Date_T lRefDate (2012, boost::gregorian::Jan, 01);
535 for (std::vector<short>::iterator itIdx = lDataIndexList.begin();
536 itIdx != lDataIndexList.end(); ++itIdx, ++i) {
538 stdair::NbOfRequests_T& lPastDemand = ioUncDemVector.at (lIdx);
539 const stdair::NbOfRequests_T& lUncDemandFactorOfThisPeriod =
540 lHBHolder.getUnconstrainedDemand (i);
541 const double lUncDemThisPeriod =
542 lPastDemand * lUncDemandFactorOfThisPeriod;
543 lPastDemand *= (1+lUncDemandFactorOfThisPeriod);
544 if (lDepDate > lRefDate) {
545 const stdair::DateOffset_T lDateOffset (7 *(53 - lIdx) + 420);
546 const stdair::Date_T lHDate = lDepDate - lDateOffset;
547 STDAIR_LOG_NOTIFICATION (boost::gregorian::to_iso_string(lDepDate)
548 <<
";" << lDTD <<
";" << iDCPBegin <<
";"
550 << boost::gregorian::to_iso_string (lHDate)
551 <<
";" << lUncDemThisPeriod);
564 if (lNbOfUsedData > 0) {
565 double lSumOfValues = 0.0;
569 for (
short i = 0; i < lNbOfData; ++i) {
574 double lFirstAverage = lSumOfValues / lNbOfUsedData;
577 for (
short i = 0; i < lNbOfData; ++i) {
579 const stdair::NbOfBookings_T& lBkgs =
581 if (lBkgs >= lFirstAverage) {
582 lSumOfValues += lBkgs;
587 double lSecondAverage = lSumOfValues / lNbOfUsedData;
590 for (
short i = 0; i < lNbOfData; ++i) {
592 const stdair::NbOfBookings_T& lBkgs =
594 if (lBkgs < lSecondAverage) {