RMOL Logo  1.00.0
C++ library of Revenue Management and Optimisation classes and functions
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
EmsrUtils.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <cmath>
7 // Boost Math
8 #include <boost/math/distributions/normal.hpp>
9 // StdAir
10 #include <stdair/stdair_maths_types.hpp>
11 #include <stdair/bom/VirtualClassStruct.hpp>
12 // RMOL
13 #include <rmol/bom/EmsrUtils.hpp>
15 
16 namespace RMOL {
17  // ////////////////////////////////////////////////////////////////////
19  (stdair::VirtualClassStruct& ioAggregatedVirtualClass,
20  stdair::VirtualClassStruct& ioCurrentVirtualClass) {
21  // Retrieve the demand mean, demand standard deviation and average
22  // yield of the classes/buckets.
23  const stdair::MeanValue_T lAggregatedMean =
24  ioAggregatedVirtualClass.getMean();
25  const stdair::MeanValue_T lCurrentMean = ioCurrentVirtualClass.getMean();
26  const stdair::StdDevValue_T lAggregatedSD =
27  ioAggregatedVirtualClass.getStdDev();
28  const stdair::StdDevValue_T lCurrentSD = ioCurrentVirtualClass.getStdDev();
29  const stdair::Yield_T lAggregatedYield =
30  ioAggregatedVirtualClass.getYield();
31  const stdair::Yield_T lCurrentYield = ioCurrentVirtualClass.getYield();
32 
33  // Compute the new demand mean, new demand standard deviation and
34  // new average yield for the new aggregated class/bucket.
35  const stdair::MeanValue_T lNewMean = lAggregatedMean + lCurrentMean;
36  const stdair::StdDevValue_T lNewSD =
37  std::sqrt (lAggregatedSD*lAggregatedSD + lCurrentSD*lCurrentSD);
38  stdair::Yield_T lNewYield = lCurrentYield;
39  if (lNewMean > 0) {
40  lNewYield = (lAggregatedYield*lAggregatedMean +
41  lCurrentYield*lCurrentMean) / lNewMean;
42  }
43  // Set the new yield range for the new aggregated class/bucket.
44  ioAggregatedVirtualClass.setYield(lNewYield);
45 
46  // Set the new demand for the new aggregated class/bucket.
47  ioAggregatedVirtualClass.setMean (lNewMean);
48  ioAggregatedVirtualClass.setStdDev (lNewSD);
49  }
50 
51  // ////////////////////////////////////////////////////////////////////
52  const stdair::ProtectionLevel_T EmsrUtils::
53  computeProtectionLevel (stdair::VirtualClassStruct& ioAggregatedVirtualClass,
54  stdair::VirtualClassStruct& ioNextVirtualClass) {
55  // Retrive the mean & standard deviation of the aggregated
56  // class/bucket and the average yield of all the two
57  // classes/buckets.
58  const stdair::MeanValue_T lMean = ioAggregatedVirtualClass.getMean();
59  const stdair::StdDevValue_T lSD = ioAggregatedVirtualClass.getStdDev();
60  const stdair::Yield_T lAggreatedYield = ioAggregatedVirtualClass.getYield();
61  const stdair::Yield_T lNextYield = ioNextVirtualClass.getYield();
62  assert (lAggreatedYield != 0);
63 
64  // Compute the yield ratio between the higher bucket and the current one
65  const double lYieldRatio = lNextYield / lAggreatedYield;
66 
70  boost::math::normal lNormalDistribution (lMean, lSD);
71  const stdair::ProtectionLevel_T lProtection =
72  boost::math::quantile (boost::math::complement (lNormalDistribution,
73  lYieldRatio));
74 
75  return lProtection;
76  }
77 
78  // ////////////////////////////////////////////////////////////////////
79  const double EmsrUtils::
80  computeEmsrValue (double iCapacity,
81  stdair::VirtualClassStruct& ioVirtualClass){
82  // Retrieve the average yield, mean and standard deviation of the
83  // demand of the class/bucket.
84  const stdair::MeanValue_T lMean = ioVirtualClass.getMean();
85  const stdair::StdDevValue_T lSD = ioVirtualClass.getStdDev();
86  const stdair::Yield_T lYield = ioVirtualClass.getYield();
87 
88  // Compute the EMSR value = lYield * Pr (demand >= iCapacity).
89  boost::math::normal lNormalDistribution (lMean, lSD);
90  const double emsrValue =
91  lYield * boost::math::cdf (boost::math::complement (lNormalDistribution,
92  iCapacity));
93 
94  return emsrValue;
95  }
96 }