[go: up one dir, main page]

Menu

[a7b38a]: / rmol / bom / Utilities.cpp  Maximize  Restore  History

Download this file

318 lines (281 with data), 13.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// //////////////////////////////////////////////////////////////////////
// Import section
// //////////////////////////////////////////////////////////////////////
// STL
#include <cassert>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
// StdAir
#include <stdair/basic/BasConst_Inventory.hpp>
#include <stdair/bom/BomManager.hpp>
#include <stdair/bom/SegmentCabin.hpp>
#include <stdair/bom/FareFamily.hpp>
#include <stdair/bom/BookingClass.hpp>
#include <stdair/bom/BookingClassTypes.hpp>
#include <stdair/service/Logger.hpp>
// RMOL
#include <rmol/basic/BasConst_General.hpp>
#include <rmol/bom/Utilities.hpp>
#include <rmol/bom/SegmentSnapshotTableHelper.hpp>
namespace RMOL {
// ////////////////////////////////////////////////////////////////////
void Utilities::
computeDistributionParameters (const stdair::UncDemVector_T& iVector,
stdair::MeanValue_T& ioMean,
stdair::StdDevValue_T& ioStdDev) {
ioMean = 0.0; ioStdDev = 0.0;
const stdair::NbOfSamples_T lNbOfSamples = iVector.size();
assert (lNbOfSamples > 1);
// Compute the mean
for (stdair::UncDemVector_T::const_iterator itSample = iVector.begin();
itSample != iVector.end(); ++itSample) {
//STDAIR_LOG_NOTIFICATION (*itSample);
ioMean += *itSample;
}
ioMean /= lNbOfSamples;
// Compute the standard deviation
for (stdair::UncDemVector_T::const_iterator itSample = iVector.begin();
itSample != iVector.end(); ++itSample) {
const stdair::MeanValue_T& lSample = *itSample;
ioStdDev += ((lSample - ioMean) * (lSample - ioMean));
}
ioStdDev /= (lNbOfSamples - 1);
ioStdDev = std::sqrt (ioStdDev);
// Sanity check
if (ioStdDev == 0) {
ioStdDev = 0.1;
}
}
// ////////////////////////////////////////////////////////////////////
stdair::DCPList_T Utilities::
buildRemainingDCPList (const stdair::DTD_T& iDTD) {
stdair::DCPList_T oDCPList;
const stdair::DCPList_T lWholeDCPList = stdair::DEFAULT_DCP_LIST;
stdair::DCPList_T::const_iterator itDCP = lWholeDCPList.begin();
while (itDCP != lWholeDCPList.end()) {
const stdair::DCP_T& lDCP = *itDCP;
if (iDTD >= lDCP) {
break;
}
++itDCP;
}
assert (itDCP != lWholeDCPList.end());
oDCPList.push_back (iDTD);
++itDCP;
for (; itDCP != lWholeDCPList.end(); ++itDCP) {
oDCPList.push_back (*itDCP);
}
return oDCPList;
}
// ////////////////////////////////////////////////////////////////////
stdair::DCPList_T Utilities::
buildPastDCPList (const stdair::DTD_T& iDTD) {
stdair::DCPList_T oDCPList;
const stdair::DCPList_T lWholeDCPList = stdair::DEFAULT_DCP_LIST;
stdair::DCPList_T::const_iterator itDCP = lWholeDCPList.begin();
while (itDCP != lWholeDCPList.end()) {
const stdair::DCP_T& lDCP = *itDCP;
if (iDTD <= lDCP) {
oDCPList.push_back (lDCP);
++itDCP;
} else {
break;
}
}
return oDCPList;
}
// ////////////////////////////////////////////////////////////////////
stdair::NbOfSegments_T Utilities::
getNbOfDepartedSimilarSegments (const stdair::SegmentCabin& iSegmentCabin,
const stdair::Date_T& iEventDate) {
stdair::DTD_T lDTD = 0;
// Retrieve the guillotine block.
const stdair::SegmentSnapshotTable& lSegmentSnapshotTable =
iSegmentCabin.getSegmentSnapshotTable();
return SegmentSnapshotTableHelper::
getNbOfSegmentAlreadyPassedThisDTD (lSegmentSnapshotTable, lDTD, iEventDate);
}
// ////////////////////////////////////////////////////////////////////
stdair::BookingClassSellUpCurveMap_T Utilities::
computeSellUpFactorCurves (const stdair::FRAT5Curve_T& iFRAT5Curve,
const stdair::BookingClassList_T& iBCList) {
stdair::BookingClassSellUpCurveMap_T oBCSellUpFactorMap;
// Initialise a sell-up factor curve of 1.0 values
stdair::SellUpCurve_T lBasedSellUpCurve;
for (stdair::FRAT5Curve_T::const_iterator itFRAT5 = iFRAT5Curve.begin();
itFRAT5 != iFRAT5Curve.end(); ++itFRAT5) {
const stdair::DTD_T& lDTD = itFRAT5->first;
lBasedSellUpCurve.insert(stdair::SellUpCurve_T::value_type(lDTD, 1.0));
}
// Retrieve the classes from low to high and compute the distributions of
// product-oriented and price-oriented demand.
// Retrieve the lowest class.
stdair::BookingClassList_T::const_reverse_iterator itCurrentClass =
iBCList.rbegin();
assert (itCurrentClass != iBCList.rend());
// If there is only one class in the cabin, all the sell-up factors
// will be 1.
stdair::BookingClass* lLowestBC_ptr = *itCurrentClass;
assert (lLowestBC_ptr != NULL);
const stdair::Yield_T& lLowestYield = lLowestBC_ptr->getYield();
bool insert = oBCSellUpFactorMap.
insert (stdair::BookingClassSellUpCurveMap_T::
value_type(lLowestBC_ptr, lBasedSellUpCurve)).second;
assert (insert == true);
++itCurrentClass;
// Compute the demand for higher class using the formula
// Pro_sell_up_from_Q_to_F = e ^ ((y_F/y_Q - 1) * ln (0.5) / (FRAT5 - 1))
for (; itCurrentClass != iBCList.rend(); ++itCurrentClass) {
stdair::BookingClass* lCurrentBC_ptr = *itCurrentClass;
assert (lCurrentBC_ptr != NULL);
const stdair::Yield_T& lCurrentYield = lCurrentBC_ptr->getYield();
// Compute the sell-up factor curve for the current class.
stdair::SellUpCurve_T lCurrentSellUpCurve;
for (stdair::FRAT5Curve_T::const_iterator itFRAT5 = iFRAT5Curve.begin();
itFRAT5 != iFRAT5Curve.end(); ++itFRAT5) {
const stdair::DTD_T& lDTD = itFRAT5->first;
const stdair::FRAT5_T& lFRAT5 = itFRAT5->second;
const double lSellUpCoef = log(0.5)/(lFRAT5-1);
const stdair::SellupProbability_T lSellUpFactor =
exp ((lCurrentYield/lLowestYield - 1.0) * lSellUpCoef);
const bool isInsertionSuccessful =
lCurrentSellUpCurve.insert (stdair::SellUpCurve_T::value_type(lDTD, lSellUpFactor)).second;
assert (isInsertionSuccessful == true);
}
const bool isInsertionSuccessful = oBCSellUpFactorMap.
insert (stdair::BookingClassSellUpCurveMap_T::
value_type(lCurrentBC_ptr, lCurrentSellUpCurve)).second;
assert (isInsertionSuccessful == true);
}
return oBCSellUpFactorMap;
}
// ////////////////////////////////////////////////////////////////////
stdair::BookingClassDispatchingCurveMap_T Utilities::
computeDispatchingFactorCurves (const stdair::FRAT5Curve_T& iFRAT5Curve,
const stdair::BookingClassList_T& iBCList) {
stdair::BookingClassDispatchingCurveMap_T oBCDispatchingFactorMap;
// Initialise a sell-up factor curve of 1.0 values
stdair::DispatchingCurve_T lBasedDispatchingCurve;
for (stdair::FRAT5Curve_T::const_iterator itFRAT5 = iFRAT5Curve.begin();
itFRAT5 != iFRAT5Curve.end(); ++itFRAT5) {
const stdair::DTD_T& lDTD = itFRAT5->first;
lBasedDispatchingCurve.insert(stdair::DispatchingCurve_T::value_type(lDTD, 1.0));
}
// Retrieve the classes from low to high and compute the distributions of
// product-oriented and price-oriented demand.
// Retrieve the lowest class.
stdair::BookingClassList_T::const_reverse_iterator itCurrentClass =
iBCList.rbegin();
assert (itCurrentClass != iBCList.rend());
stdair::BookingClassList_T::const_reverse_iterator itNextClass =
itCurrentClass; ++itNextClass;
// If there is only one class in the cabin, all the sell-up factors
// will be 1.
stdair::BookingClass* lLowestBC_ptr = *itCurrentClass;
assert (lLowestBC_ptr != NULL);
const stdair::Yield_T& lLowestYield = lLowestBC_ptr->getYield();
if (itNextClass == iBCList.rend()) {
bool insert = oBCDispatchingFactorMap.
insert (stdair::BookingClassDispatchingCurveMap_T::
value_type(lLowestBC_ptr, lBasedDispatchingCurve)).second;
assert (insert == true);
} else {
// Compute the demand for higher class using the formula
// Pro_sell_up_from_Q_to_F = e ^ ((y_F/y_Q - 1) * ln (0.5) / (FRAT5 - 1))
for (; itNextClass != iBCList.rend(); ++itCurrentClass, ++itNextClass) {
stdair::BookingClass* lCurrentBC_ptr = *itCurrentClass;
stdair::BookingClass* lNextBC_ptr = *itNextClass;
assert (lNextBC_ptr != NULL);
const stdair::Yield_T& lNextYield = lNextBC_ptr->getYield();
// Compute the sell-up factor curve for the current class.
stdair::DispatchingCurve_T lCurrentDispatchingCurve;
for (stdair::FRAT5Curve_T::const_iterator itFRAT5 = iFRAT5Curve.begin();
itFRAT5 != iFRAT5Curve.end(); ++itFRAT5) {
const stdair::DTD_T& lDTD = itFRAT5->first;
const stdair::FRAT5_T& lFRAT5 = itFRAT5->second;
const double lDispatchingCoef = log(0.5)/(lFRAT5-1);
double lDispatchingFactor =
exp ((lNextYield/lLowestYield - 1.0) * lDispatchingCoef);
stdair::DispatchingCurve_T::iterator itBasedDispatching =
lBasedDispatchingCurve.find (lDTD);
assert (itBasedDispatching != lBasedDispatchingCurve.end());
double& lBasedFactor = itBasedDispatching->second;
bool insert = lCurrentDispatchingCurve.insert (stdair::DispatchingCurve_T::value_type(lDTD, lBasedFactor - lDispatchingFactor)).second;
assert (insert == true);
lBasedFactor = lDispatchingFactor;
}
bool insert = oBCDispatchingFactorMap.
insert (stdair::BookingClassDispatchingCurveMap_T::
value_type(lCurrentBC_ptr, lCurrentDispatchingCurve)).second;
assert (insert == true);
}
// Compute the sell-up factor curve for the highest class (which is the
// "current class")
stdair::BookingClass* lCurrentBC_ptr = *itCurrentClass;
bool insert = oBCDispatchingFactorMap.
insert (stdair::BookingClassDispatchingCurveMap_T::
value_type(lCurrentBC_ptr, lBasedDispatchingCurve)).second;
assert (insert == true);
}
return oBCDispatchingFactorMap;
}
// ////////////////////////////////////////////////////////////////////
void Utilities::dispatchDemandForecast
(const stdair::BookingClassDispatchingCurveMap_T& iBCDispatchingCurveMap,
const stdair::MeanValue_T& iMean,
const stdair::StdDevValue_T& iStdDev,
const stdair::DTD_T& iCurrentDCP) {
for (stdair::BookingClassDispatchingCurveMap_T::const_iterator itBCDC =
iBCDispatchingCurveMap.begin();
itBCDC != iBCDispatchingCurveMap.end(); ++itBCDC) {
stdair::BookingClass* lBC_ptr = itBCDC->first;
assert (lBC_ptr != NULL);
const stdair::DispatchingCurve_T& lDispatchingCurve = itBCDC->second;
stdair::DispatchingCurve_T::const_iterator itDispatchingFactor =
lDispatchingCurve.find (iCurrentDCP);
assert (itDispatchingFactor != lDispatchingCurve.end());
const double& lDF = itDispatchingFactor->second;
const stdair::MeanValue_T& lCurrentMean = lBC_ptr->getPriceDemMean();
const stdair::StdDevValue_T& lCurrentStdDev = lBC_ptr->getPriceDemStdDev();
const stdair::MeanValue_T lAdditionalMean = iMean * lDF;
const stdair::StdDevValue_T lAdditionalStdDev = iStdDev * std::sqrt (lDF);
const stdair::MeanValue_T lNewMean = lCurrentMean + lAdditionalMean;
const stdair::StdDevValue_T lNewStdDev =
std::sqrt (lCurrentStdDev * lCurrentStdDev
+ lAdditionalStdDev * lAdditionalStdDev);
lBC_ptr->setPriceDemMean (lNewMean);
lBC_ptr->setPriceDemStdDev (lNewStdDev);
}
}
// ////////////////////////////////////////////////////////////////////
void Utilities::dispatchDemandForecastForFA
(const stdair::BookingClassSellUpCurveMap_T& iBCSellUpCurveMap,
const stdair::MeanValue_T& iMean,
const stdair::StdDevValue_T& iStdDev,
const stdair::DTD_T& iCurrentDCP) {
for (stdair::BookingClassSellUpCurveMap_T::const_iterator itBCSU =
iBCSellUpCurveMap.begin();
itBCSU != iBCSellUpCurveMap.end(); ++itBCSU) {
stdair::BookingClass* lBC_ptr = itBCSU->first;
assert (lBC_ptr != NULL);
const stdair::SellUpCurve_T& lSellUpCurve = itBCSU->second;
stdair::SellUpCurve_T::const_iterator itSellUpFactor =
lSellUpCurve.find (iCurrentDCP);
assert (itSellUpFactor != lSellUpCurve.end());
const stdair::SellupProbability_T& lSU = itSellUpFactor->second;
const stdair::MeanValue_T& lCurrentMean = lBC_ptr->getCumuPriceDemMean();
const stdair::StdDevValue_T& lCurrentStdDev =
lBC_ptr->getCumuPriceDemStdDev();
const stdair::MeanValue_T lAdditionalMean = iMean * lSU;
const stdair::StdDevValue_T lAdditionalStdDev = iStdDev * std::sqrt (lSU);
const stdair::MeanValue_T lNewMean = lCurrentMean + lAdditionalMean;
const stdair::StdDevValue_T lNewStdDev =
std::sqrt (lCurrentStdDev * lCurrentStdDev
+ lAdditionalStdDev * lAdditionalStdDev);
lBC_ptr->setCumuPriceDemMean (lNewMean);
lBC_ptr->setCumuPriceDemStdDev (lNewStdDev);
}
}
}