$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 #include <cmath> 00007 // Boost Math 00008 #include <boost/math/distributions/normal.hpp> 00009 // StdAir 00010 #include <stdair/stdair_maths_types.hpp> 00011 #include <stdair/bom/VirtualClassStruct.hpp> 00012 // RMOL 00013 #include <rmol/bom/EmsrUtils.hpp> 00014 #include <rmol/basic/BasConst_General.hpp> 00015 00016 namespace RMOL { 00017 // //////////////////////////////////////////////////////////////////// 00018 void EmsrUtils::computeAggregatedVirtualClass 00019 (stdair::VirtualClassStruct& ioAggregatedVirtualClass, 00020 stdair::VirtualClassStruct& ioCurrentVirtualClass) { 00021 // Retrieve the demand mean, demand standard deviation and average 00022 // yield of the classes/buckets. 00023 const stdair::MeanValue_T lAggregatedMean = 00024 ioAggregatedVirtualClass.getMean(); 00025 const stdair::MeanValue_T lCurrentMean = ioCurrentVirtualClass.getMean(); 00026 const stdair::StdDevValue_T lAggregatedSD = 00027 ioAggregatedVirtualClass.getStdDev(); 00028 const stdair::StdDevValue_T lCurrentSD = ioCurrentVirtualClass.getStdDev(); 00029 const stdair::Yield_T lAggregatedYield = 00030 ioAggregatedVirtualClass.getYield(); 00031 const stdair::Yield_T lCurrentYield = ioCurrentVirtualClass.getYield(); 00032 00033 // Compute the new demand mean, new demand standard deviation and 00034 // new average yield for the new aggregated class/bucket. 00035 const stdair::MeanValue_T lNewMean = lAggregatedMean + lCurrentMean; 00036 const stdair::StdDevValue_T lNewSD = 00037 std::sqrt (lAggregatedSD*lAggregatedSD + lCurrentSD*lCurrentSD); 00038 stdair::Yield_T lNewYield = lCurrentYield; 00039 if (lNewMean > 0) { 00040 lNewYield = (lAggregatedYield*lAggregatedMean + 00041 lCurrentYield*lCurrentMean) / lNewMean; 00042 } 00043 // Set the new yield range for the new aggregated class/bucket. 00044 ioAggregatedVirtualClass.setYield(lNewYield); 00045 00046 // Set the new demand for the new aggregated class/bucket. 00047 ioAggregatedVirtualClass.setMean (lNewMean); 00048 ioAggregatedVirtualClass.setStdDev (lNewSD); 00049 } 00050 00051 // //////////////////////////////////////////////////////////////////// 00052 const stdair::ProtectionLevel_T EmsrUtils:: 00053 computeProtectionLevel (stdair::VirtualClassStruct& ioAggregatedVirtualClass, 00054 stdair::VirtualClassStruct& ioNextVirtualClass) { 00055 // Retrive the mean & standard deviation of the aggregated 00056 // class/bucket and the average yield of all the two 00057 // classes/buckets. 00058 const stdair::MeanValue_T lMean = ioAggregatedVirtualClass.getMean(); 00059 const stdair::StdDevValue_T lSD = ioAggregatedVirtualClass.getStdDev(); 00060 const stdair::Yield_T lAggreatedYield = ioAggregatedVirtualClass.getYield(); 00061 const stdair::Yield_T lNextYield = ioNextVirtualClass.getYield(); 00062 assert (lAggreatedYield != 0); 00063 00064 // Compute the yield ratio between the higher bucket and the current one 00065 const double lYieldRatio = lNextYield / lAggreatedYield; 00066 00070 boost::math::normal lNormalDistribution (lMean, lSD); 00071 const stdair::ProtectionLevel_T lProtection = 00072 boost::math::quantile (boost::math::complement (lNormalDistribution, 00073 lYieldRatio)); 00074 00075 return lProtection; 00076 } 00077 00078 // //////////////////////////////////////////////////////////////////// 00079 const double EmsrUtils:: 00080 computeEmsrValue (double iCapacity, 00081 stdair::VirtualClassStruct& ioVirtualClass){ 00082 // Retrieve the average yield, mean and standard deviation of the 00083 // demand of the class/bucket. 00084 const stdair::MeanValue_T lMean = ioVirtualClass.getMean(); 00085 const stdair::StdDevValue_T lSD = ioVirtualClass.getStdDev(); 00086 const stdair::Yield_T lYield = ioVirtualClass.getYield(); 00087 00088 // Compute the EMSR value = lYield * Pr (demand >= iCapacity). 00089 boost::math::normal lNormalDistribution (lMean, lSD); 00090 const double emsrValue = 00091 lYield * boost::math::cdf (boost::math::complement (lNormalDistribution, 00092 iCapacity)); 00093 00094 return emsrValue; 00095 } 00096 }