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

Emsr.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // C
00005 #include <assert.h>
00006 // STL
00007 #include <iostream>
00008 #include <cmath>
00009 #include <list>
00010 // RMOL
00011 #include <rmol/bom/VariateList.hpp>
00012 #include <rmol/bom/Gaussian.hpp>
00013 #include <rmol/bom/Emsr.hpp>
00014 #include <rmol/bom/BucketHolder.hpp>
00015 #include <rmol/bom/EmsrUtils.hpp>
00016 #include <rmol/bom/Bucket.hpp>
00017 
00018 namespace RMOL {
00019 
00020   // //////////////////////////////////////////////////////////////////
00021   void Emsr::
00022   heuristicOptimisationByEmsr (const ResourceCapacity_T iCabinCapacity,
00023                                BucketHolder& ioBucketHolder,
00024                                BidPriceVector_T& ioBidPriceVector) {
00025     // Number of classes/buckets: n
00026     const short nbOfClasses = ioBucketHolder.getSize();
00027 
00028     // Cabin capacity in integer.
00029     const int lCabinCapacity = static_cast<const int>(iCabinCapacity);
00030 
00031     // List of all EMSR values.
00032     EmsrValueList_T lEmsrValueList;
00033 
00039     ioBucketHolder.begin();
00040     for (short j = 1; j <= nbOfClasses; j++, ioBucketHolder.iterate()) {
00041       Bucket& currentBucket = ioBucketHolder.getCurrentBucket();
00042       for (int k = 1; k <= lCabinCapacity; ++k) {
00043         const double emsrValue = EmsrUtils::computeEmsrValue (k, currentBucket);
00044         lEmsrValueList.push_back(emsrValue);
00045       }
00046     }
00047 
00048     // Sort the EMSR values from high to low.
00049     lEmsrValueList.sort();
00050     lEmsrValueList.reverse();
00051 
00052     // Sanity check
00053     const int lEmsrValueListSize = lEmsrValueList.size();
00054     assert (lEmsrValueListSize >= lCabinCapacity);
00055 
00056     // Copy the EMSR sorted values to the BPV.
00057     EmsrValueList_T::iterator currentValue = lEmsrValueList.begin();
00058     for (int j = 0; j < lCabinCapacity; ++j, ++currentValue) {
00059       const double bidPrice = *currentValue;
00060       ioBidPriceVector.push_back(bidPrice);
00061     }
00062     lEmsrValueList.clear();
00063     
00064     // Build the protection levels and booking limits.
00065     if (nbOfClasses > 1) {
00066       int capacityIndex = 0;
00067       ioBucketHolder.begin();
00068       for (short j = 1; j <= nbOfClasses - 1; j++, ioBucketHolder.iterate()) {
00069         Bucket& currentBucket = ioBucketHolder.getCurrentBucket();
00070         Bucket& nextBucket = ioBucketHolder.getNextBucket();
00071         const double lNextYield = nextBucket.getAverageYield();
00072         while ((capacityIndex < lCabinCapacity)
00073                && (ioBidPriceVector.at(capacityIndex) > lNextYield)) {
00074             ++capacityIndex;
00075         }
00076         currentBucket.setCumulatedProtection (capacityIndex);
00077         nextBucket.setCumulatedBookingLimit (iCabinCapacity - capacityIndex);
00078       }
00079     }
00080   }
00081 
00082   // //////////////////////////////////////////////////////////////////
00083   void Emsr::
00084   heuristicOptimisationByEmsrA (const ResourceCapacity_T iCabinCapacity,
00085                                 BucketHolder& ioBucketHolder) {
00086     // Number of classes/buckets: n
00087     const short nbOfClasses = ioBucketHolder.getSize();
00088 
00094     ioBucketHolder.begin();
00095     Bucket& firstBucket = ioBucketHolder.getCurrentBucket();
00096     firstBucket.setCumulatedBookingLimit (iCabinCapacity);
00097     for (short j = 1; j <= nbOfClasses - 1; j++, ioBucketHolder.iterate()) {
00098       Bucket& nextBucket = ioBucketHolder.getNextBucket();
00099 
00100       // Initialise the protection for class/bucket j.
00101       double lProtectionLevel = 0.0;
00102       
00103       ioBucketHolder.begin();
00104       for(short k = 1; k <= j; k++) {
00105         Bucket& currentBucket = ioBucketHolder.getCurrentBucket();
00106         const double lPartialProtectionLevel =
00107           EmsrUtils::computeProtectionLevel (currentBucket, nextBucket);
00108         lProtectionLevel += lPartialProtectionLevel;
00109         if (k < j) {
00110           ioBucketHolder.iterate();
00111         }
00112       }
00113       Bucket& currentBucket = ioBucketHolder.getCurrentBucket();
00114       currentBucket.setCumulatedProtection (lProtectionLevel);
00115 
00116       // Compute the booking limit for the class/bucket j+1 (can be negative).
00117       const double lBookingLimit = iCabinCapacity - lProtectionLevel;
00118       
00119       // Set the booking limit for class/bucket j+1.
00120       nextBucket.setCumulatedBookingLimit (lBookingLimit);   
00121     }
00122     
00123     /*
00124     // Number of classes/buckets: n
00125     const short nbOfClasses = ioBucketHolder.getSize();
00126     for (int s = 1; s <= iCabinCapacity; s++){
00127       double maxEmsrValue = 0.0;
00128       int highestBucket = 1;
00129       
00130       for(ioBucketHolder.begin();
00131           ioBucketHolder.hasNotReachedEnd();
00132           ioBucketHolder.iterate()){
00133         Bucket& currentBucket = ioBucketHolder.getCurrentBucket();
00134         
00135         // Compute EMSR value of the seat #s for class j
00136         double emsrForsj=0;
00137         // Evaluate if this class j has the highest EMSR value for
00138         // seat #s.  If so, maxEMSRValue is the EMSR value of j, and
00139         // j becomes temporarily the highest class.
00140         
00141         if(emsrForsj >= maxEmsrValue){
00142           maxEmsrValue = emsrForsj;
00143           ioBucketHolder.tag();
00144         }
00145       }
00146       
00147       Bucket& theHighestBucket = ioBucketHolder.getTaggedBucket();
00148       theHighestBucket._protection += 1.0;
00149     }
00150     */
00151   }
00152 
00153   // //////////////////////////////////////////////////////////////////
00154   void Emsr::
00155   heuristicOptimisationByEmsrB (const ResourceCapacity_T iCabinCapacity,
00156                                 BucketHolder& ioBucketHolder,
00157                                 Bucket& ioAggregatedBucket) {
00158     // Number of classes/buckets: n
00159     const short nbOfClasses = ioBucketHolder.getSize();
00160 
00166     ioBucketHolder.begin();
00167     Bucket& firstBucket = ioBucketHolder.getCurrentBucket();
00168     firstBucket.setCumulatedBookingLimit (iCabinCapacity);
00169     for (short j = 1; j <= nbOfClasses - 1; j++, ioBucketHolder.iterate()) {
00170       Bucket& currentBucket = ioBucketHolder.getCurrentBucket();
00171       Bucket& nextBucket = ioBucketHolder.getNextBucket();
00172 
00173       // Compute the aggregated class/bucket of classes/buckets 1,..,j.
00174       EmsrUtils::computeAggregatedBucket (ioAggregatedBucket,
00175                                           currentBucket);
00176 
00177       // Compute the protection level for the aggregated class/bucket
00178       // using the Little-Wood formular.
00179       const double lProtectionLevel =
00180         EmsrUtils::computeProtectionLevel (ioAggregatedBucket, nextBucket);
00181 
00182       // Set the protection level for class/bucket j.
00183       currentBucket.setCumulatedProtection (lProtectionLevel);
00184 
00185       // Compute the booking limit for class/bucket j+1 (can be negative).
00186       const double lBookingLimit = iCabinCapacity - lProtectionLevel;
00187       
00188       // Set the booking limit for class/bucket j+1.
00189       nextBucket.setCumulatedBookingLimit (lBookingLimit);
00190     }
00191   
00192   }
00193 }
SourceForge Logo

Generated on Sun Jun 14 23:33:59 2009 for RMOL by Doxygen 1.5.8