RMOL Logo Get Revenue Management Optimisation Library at SourceForge.net. Fast, secure and Free Open Source software downloads

EmsrUtils.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // GSL Random Number Generation (GSL Reference Manual, version 1.7, Chapter 19)
00005 #include <gsl/gsl_cdf.h>
00006 // C
00007 #include <math.h>
00008 #include <assert.h>
00009 // RMOL
00010 #include <rmol/bom/EmsrUtils.hpp>
00011 #include <rmol/bom/Bucket.hpp>
00012 #include <rmol/basic/BasConst_General.hpp>
00013 
00014 namespace RMOL {
00015   // ////////////////////////////////////////////////////////////////////
00016   void EmsrUtils::computeAggregatedBucket (Bucket& ioAggregatedBucket,
00017                                               Bucket& ioCurrentBucket) {
00018     // Retrieve the demand mean, demand standard deviation and average
00019     // yield of the classes/buckets.
00020     const double lAggregatedMean = ioAggregatedBucket.getMean();
00021     const double lCurrentMean = ioCurrentBucket.getMean();
00022     const double lAggregatedSD = ioAggregatedBucket.getStandardDeviation();
00023     const double lCurrentSD = ioCurrentBucket.getStandardDeviation();
00024     const double lAggregatedAverageYield = ioAggregatedBucket.getAverageYield();
00025     const double lCurrentAverageYield = ioCurrentBucket.getAverageYield();
00026 
00027     // Compute the new demand mean, new demand standard deviation and
00028     // new average yield for the new aggregated class/bucket.
00029     const double lNewMean = lAggregatedMean + lCurrentMean;
00030     const double lNewSD =
00031       sqrt(lAggregatedSD*lAggregatedSD + lCurrentSD*lCurrentSD);
00032     double lNewAverageYield = lCurrentAverageYield;
00033     if (lNewMean > 0) {
00034       lNewAverageYield = (lAggregatedAverageYield*lAggregatedMean +
00035                           lCurrentAverageYield*lCurrentMean)/lNewMean;
00036     } 
00037     // Set the new yield range for the new aggregated class/bucket.
00038     ioAggregatedBucket.setYieldRange(lNewAverageYield);
00039 
00040     // Set the new demand for the new aggregated class/bucket.
00041     ioAggregatedBucket.setDemandParameters (lNewMean, lNewSD);
00042   }
00043 
00044   // ////////////////////////////////////////////////////////////////////
00045   const double EmsrUtils::computeProtectionLevel (Bucket& ioAggregatedBucket,
00046                                                   Bucket& ioNextBucket) {
00047     // Retrive the mean & standard deviation of the aggregated
00048     // class/bucket and the average yield of all the two
00049     // classes/buckets.
00050     const double lMean = ioAggregatedBucket.getMean();
00051     const double lSD = ioAggregatedBucket.getStandardDeviation();
00052     const double lAggreatedYield = ioAggregatedBucket.getAverageYield();
00053     const double lNextYield = ioNextBucket.getAverageYield();
00054     assert (lAggreatedYield != 0);
00055     
00056     // Compute the protection for the aggregated class/bucket
00057     const double lProtection = 
00058       lMean + gsl_cdf_gaussian_Qinv (lNextYield/lAggreatedYield, lSD);
00059     
00060     return lProtection;
00061   }
00062 
00063   // ////////////////////////////////////////////////////////////////////
00064   const double EmsrUtils::computeProtectionLevelwithSellup (Bucket& iHigherBucket,
00065                                                             Bucket& iBucket,
00066                                                             double iSellupFactor){
00067     // Retrieve the mean and the standard deviation of the higher 
00068     // class(es)/bucket(s) depending EMSR-a or EMSR-b
00069     // and the average yield of each input classes/buckets
00070     const double lMean = iHigherBucket.getMean();
00071     const double lSD = iHigherBucket.getStandardDeviation();
00072     const double lHigherBucketYield = iHigherBucket.getAverageYield();
00073     const double lBucketYield = iBucket.getAverageYield();
00074     assert (lHigherBucketYield > DEFAULT_EPSILON);
00075     assert (1-iSellupFactor > DEFAULT_EPSILON);
00076 
00077     // compute the protection level for the higher class/bucket
00078     const double lProtectionLevel = 
00079       lMean + 
00080       gsl_cdf_gaussian_Pinv((lHigherBucketYield-lBucketYield)/
00081                             (lHigherBucketYield*(1-iSellupFactor)),lSD);
00082     
00083     return lProtectionLevel;
00084   }
00085 
00086   // ////////////////////////////////////////////////////////////////////
00087   const double EmsrUtils::computeEmsrValue (double iCapacity, Bucket& ioBucket) {
00088     // Retrive the average yield, mean and standard deviation of the
00089     // demand of the class/bucket.
00090     const double lMean = ioBucket.getMean();
00091     const double lSD = ioBucket.getStandardDeviation();
00092     const double lYield = ioBucket.getAverageYield();
00093 
00094     // Compute the EMSR value = lYield * Pr (demand >= iCapacity).
00095     const double emsrValue = lYield * gsl_cdf_gaussian_Q(iCapacity-lMean, lSD);
00096 
00097     return emsrValue;
00098   }
00099 }
SourceForge Logo

Generated on Fri Jul 30 21:42:59 2010 for RMOL by Doxygen 1.6.2-20100208