RMOL Logo  1.00.13
C++ library of Revenue Management and Optimisation classes and functions
Loading...
Searching...
No Matches
BasedForecasting.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6#include <sstream>
7#include <cmath>
8// StdAir
9#include <stdair/basic/BasConst_General.hpp>
10#include <stdair/basic/BasConst_Inventory.hpp>
11#include <stdair/basic/RandomGeneration.hpp>
12#include <stdair/bom/BomManager.hpp>
13#include <stdair/bom/LegDate.hpp>
14#include <stdair/bom/SegmentDate.hpp>
15#include <stdair/bom/LegCabin.hpp>
16#include <stdair/bom/SegmentCabin.hpp>
17#include <stdair/bom/SegmentSnapshotTable.hpp>
18#include <stdair/bom/BookingClass.hpp>
19#include <stdair/service/Logger.hpp>
20// RMOL
27
28namespace RMOL {
29 // ////////////////////////////////////////////////////////////////////
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) {
36
37 // Retrieve the snapshot table.
38 const stdair::SegmentSnapshotTable& lSegmentSnapshotTable =
39 ioSegmentCabin.getSegmentSnapshotTable();
40
41 // Retrieve the booking class list.
42 const stdair::BookingClassList_T& lBCList =
43 stdair::BomManager::getList<stdair::BookingClass>(ioSegmentCabin);
44
45 // Browse all remaining DCP's and do unconstraining and forecasting for
46 // all demand.
47 const stdair::DCPList_T lWholeDCPList = stdair::DEFAULT_DCP_LIST;
48 stdair::DCPList_T::const_iterator itDCP = lWholeDCPList.begin();
49 stdair::DCPList_T::const_iterator itNextDCP = itDCP; ++itNextDCP;
50 for (; itNextDCP != lWholeDCPList.end(); ++itDCP, ++itNextDCP) {
51 const stdair::DCP_T& lCurrentDCP = *itDCP;
52 const stdair::DCP_T& lNextDCP = *itNextDCP;
53
54 // The end of the interval is after the current DTD.
55 if (lNextDCP < iCurrentDTD) {
56 // Get the number of similar segments which has already passed the
57 // (lNextDCP+1)
58 const stdair::NbOfSegments_T& lNbOfUsableSegments =
60 getNbOfSegmentAlreadyPassedThisDTD (lSegmentSnapshotTable,
61 lNextDCP+1,
62 iCurrentDate);
63 stdair::NbOfSegments_T lSegmentBegin = 0;
64 const stdair::NbOfSegments_T lSegmentEnd = lNbOfUsableSegments-1;
65 if (iNbOfDepartedSegments > 52) {
66 lSegmentBegin = iNbOfDepartedSegments - 52;
67 }
68
69 // Browse the list of booking classes and forecast the product-oriented
70 // demand for each class.
71 for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
72 itBC != lBCList.end(); ++itBC) {
73 stdair::BookingClass* lBC_ptr = *itBC;
74 assert (lBC_ptr != NULL);
75
76 // Retrieve the historical product-oriented bookings for the
77 // given class.
79 prepareHistoricalBooking (ioSegmentCabin, *lBC_ptr,
80 lSegmentSnapshotTable,
81 lHBHolder,
82 lCurrentDCP, lNextDCP,
83 lSegmentBegin, lSegmentEnd);
84
85 // Unconstrain the historical bookings.
86 Detruncator::unconstrain (lHBHolder, iUnconstrainingMethod);
87
88 // Retrieve the historical unconstrained demand and perform the
89 // forecasting.
90 stdair::UncDemVector_T lUncDemVector;
91 const short lNbOfHistoricalFlights = lHBHolder.getNbOfFlights();
92 for (short i = 0; i < lNbOfHistoricalFlights; ++i) {
93 const stdair::NbOfBookings_T& lUncDemand =
94 lHBHolder.getUnconstrainedDemand (i);
95 lUncDemVector.push_back (lUncDemand);
96 }
97 stdair::MeanValue_T lMean = 0.0;
98 stdair::StdDevValue_T lStdDev = 0.0;
100 lMean, lStdDev);
101
102 // Add the demand forecast to the booking class.
103 const stdair::MeanValue_T& lCurrentMean = lBC_ptr->getProductDemMean();
104 const stdair::StdDevValue_T& lCurrentStdDev =
105 lBC_ptr->getProductDemStdDev();
106
107 const stdair::MeanValue_T lNewMean = lCurrentMean + lMean;
108 const stdair::StdDevValue_T lNewStdDev =
109 std::sqrt (lCurrentStdDev * lCurrentStdDev + lStdDev * lStdDev);
110
111 lBC_ptr->setProductDemMean (lNewMean);
112 lBC_ptr->setProductDemStdDev (lNewStdDev);
113 }
114 }
115 }
116 return true;
117 }
118
119 // ////////////////////////////////////////////////////////////////////
121 (const stdair::SegmentCabin& iSegmentCabin,
122 const stdair::BookingClass& iBookingClass,
123 const stdair::SegmentSnapshotTable& iSegmentSnapshotTable,
124 HistoricalBookingHolder& ioHBHolder,
125 const stdair::DCP_T& iDCPBegin, const stdair::DCP_T& iDCPEnd,
126 const stdair::NbOfSegments_T& iSegmentBegin,
127 const stdair::NbOfSegments_T& iSegmentEnd) {
128
129 // Retrieve the booking class index within the snapshot table
130 const stdair::ClassIndex_T& lClassIdx =
131 iSegmentSnapshotTable.getClassIndex (iBookingClass.describeKey());
132
133 // Retrieve the gross daily booking and availability snapshots.
134 const stdair::ConstSegmentCabinDTDRangeSnapshotView_T lPriceBookingView =
135 iSegmentSnapshotTable.getConstSegmentCabinDTDRangePriceOrientedGrossBookingSnapshotView (iSegmentBegin, iSegmentEnd, iDCPEnd, iDCPBegin);
136 const stdair::ConstSegmentCabinDTDRangeSnapshotView_T lProductBookingView =
137 iSegmentSnapshotTable.getConstSegmentCabinDTDRangeProductOrientedGrossBookingSnapshotView (iSegmentBegin, iSegmentEnd, iDCPEnd, iDCPBegin);
138 const stdair::ConstSegmentCabinDTDRangeSnapshotView_T lAvlView =
139 iSegmentSnapshotTable.getConstSegmentCabinDTDRangeAvailabilitySnapshotView (iSegmentBegin, iSegmentEnd, iDCPEnd, iDCPBegin);
140
141 // Browse the list of segments and build the historical booking holder.
142 const stdair::ClassIndexMap_T& lVTIdxMap =
143 iSegmentSnapshotTable.getClassIndexMap();
144 const stdair::NbOfClasses_T lNbOfClasses = lVTIdxMap.size();
145
146 for (short i = 0; i <= iSegmentEnd-iSegmentBegin; ++i) {
147 stdair::Flag_T lCensorshipFlag = false;
148 const short lNbOfDTDs = iDCPBegin - iDCPEnd + 1;
149 const stdair::UnsignedIndex_T lIdx = i*lNbOfClasses + lClassIdx;
150
151 // Parse the DTDs during the period and compute the censorship flag
152 for (short j = 0; j < lNbOfDTDs; ++j) {
153 // Check if the data has been censored during this day.
154 // STDAIR_LOG_DEBUG ("i: " << i << ", NbOfClasses: " << lNbOfClasses
155 // << ", ClassIdx: " << iClassIdx << ", j: " << j);
156 if (lAvlView[lIdx][j] < 1.0) {
157 lCensorshipFlag = true;
158 break;
159 }
160 }
161
162 // Retrieve the historical bookings
163 stdair::NbOfBookings_T lNbOfHistoricalBkgs = 0.0;
164 for (short j = 0; j < lNbOfDTDs; ++j) {
165 lNbOfHistoricalBkgs +=
166 lPriceBookingView[lIdx][j] + lProductBookingView[lIdx][j];
167 }
168 HistoricalBooking lHistoricalBkg (lNbOfHistoricalBkgs, lCensorshipFlag);
169 ioHBHolder.addHistoricalBooking (lHistoricalBkg);
170 }
171 }
172
173}
Structure keeping track, for a given class, of the number of historical bookings and of the censorshi...
void addHistoricalBooking(const HistoricalBooking &iHistoricalBooking)
const stdair::NbOfBookings_T & getUnconstrainedDemand(const short i) const
static stdair::NbOfSegments_T getNbOfSegmentAlreadyPassedThisDTD(const stdair::SegmentSnapshotTable &, const stdair::DTD_T &, const stdair::Date_T &)
static void computeDistributionParameters(const stdair::UncDemVector_T &, stdair::MeanValue_T &, stdair::StdDevValue_T &)
Definition Utilities.cpp:27
static void prepareHistoricalBooking(const stdair::SegmentCabin &, const stdair::BookingClass &, const stdair::SegmentSnapshotTable &, HistoricalBookingHolder &, const stdair::DCP_T &, const stdair::DCP_T &, const stdair::NbOfSegments_T &, const stdair::NbOfSegments_T &)
static bool forecast(stdair::SegmentCabin &, const stdair::Date_T &, const stdair::DTD_T &, const stdair::UnconstrainingMethod &, const stdair::NbOfSegments_T &)
static void unconstrain(HistoricalBookingHolder &, const stdair::UnconstrainingMethod &)