00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // C 00005 #include <assert.h> 00006 // STL 00007 #include <iostream> 00008 #include <cmath> 00009 #include <list> 00010 #include <algorithm> 00011 // RMOL 00012 #include <rmol/bom/VariateList.hpp> 00013 #include <rmol/bom/Gaussian.hpp> 00014 #include <rmol/bom/Emsr.hpp> 00015 #include <rmol/bom/BucketHolder.hpp> 00016 #include <rmol/bom/EmsrUtils.hpp> 00017 #include <rmol/bom/Bucket.hpp> 00018 00019 namespace RMOL { 00020 00021 // ////////////////////////////////////////////////////////////////// 00022 void Emsr:: 00023 heuristicOptimisationByEmsr (const ResourceCapacity_T iCabinCapacity, 00024 BucketHolder& ioBucketHolder, 00025 BidPriceVector_T& ioBidPriceVector) { 00026 // Number of classes/buckets: n 00027 const short nbOfClasses = ioBucketHolder.getSize(); 00028 00029 // Cabin capacity in integer. 00030 const int lCabinCapacity = static_cast<const int>(iCabinCapacity); 00031 00032 // List of all EMSR values. 00033 EmsrValueList_T lEmsrValueList; 00034 00040 ioBucketHolder.begin(); 00041 for (short j = 1; j <= nbOfClasses; j++, ioBucketHolder.iterate()) { 00042 Bucket& currentBucket = ioBucketHolder.getCurrentBucket(); 00043 for (int k = 1; k <= lCabinCapacity; ++k) { 00044 const double emsrValue = EmsrUtils::computeEmsrValue (k, currentBucket); 00045 lEmsrValueList.push_back(emsrValue); 00046 } 00047 } 00048 00049 // Sort the EMSR values from high to low. 00050 std::sort(lEmsrValueList.rbegin(), lEmsrValueList.rend()); 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::const_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 // ////////////////////////////////////////////////////////////////// 00125 void Emsr::heuristicOptimisationByEmsrAwithSellup 00126 (const ResourceCapacity_T iCabinCapacity, 00127 BucketHolder& ioBucketHolder, 00128 SellupProbabilityVector_T& iSellupProbabilityVector){ 00129 00130 // Number of classes/Buckets: n 00131 const short nbOfBuckets = ioBucketHolder.getSize(); 00132 00133 // Set the booking limit of the highest class to the cabin capacity 00134 ioBucketHolder.begin(); 00135 Bucket& highestBucket = ioBucketHolder.getCurrentBucket(); 00136 highestBucket.setCumulatedBookingLimit (iCabinCapacity); 00137 00138 // Set the booking limit for the rest n-1 classes 00139 // by iterating on the classes/Buckets from 1 to n-1 00140 for (short j=1; j <= nbOfBuckets-1; j++, ioBucketHolder.iterate()) { 00141 // Get the next class/bucket (the next high fare class) 00142 Bucket& nextBucket = ioBucketHolder.getNextBucket(); 00143 00144 // Get the probability of sell-up from nextBucket to the next higher 00145 double sellupProbability = iSellupProbabilityVector[j-1]; 00146 00147 // Initialize protection level for the current class j 00148 double lProtectionLevel = 0.0; 00149 00150 // Sum the protection levels for each higher fare class 00151 ioBucketHolder.begin(); 00152 for (short k=1; k<=j; k++) { 00153 Bucket& higherBucket = ioBucketHolder.getCurrentBucket(); 00154 00155 double lPRotectionLevelAgainstAHigherBucket = 0.0; 00156 00157 if (k == j) { 00158 lPRotectionLevelAgainstAHigherBucket = 00159 EmsrUtils::computeProtectionLevelwithSellup 00160 (higherBucket, nextBucket, sellupProbability); 00161 } else { 00162 lPRotectionLevelAgainstAHigherBucket = 00163 EmsrUtils::computeProtectionLevelwithSellup 00164 (higherBucket, nextBucket, 0); 00165 ioBucketHolder.iterate(); 00166 } 00167 00168 lProtectionLevel += lPRotectionLevelAgainstAHigherBucket; 00169 } 00170 00171 // Set cumulated protection level for class j 00172 Bucket& currentBucket = ioBucketHolder.getCurrentBucket(); 00173 currentBucket.setCumulatedProtection (lProtectionLevel); 00174 00175 // Compute the booking limit for the class j+1 (can be negative) 00176 const double lBookingLimit = iCabinCapacity - lProtectionLevel; 00177 00178 // Set the booking limit for class j+1 00179 nextBucket.setCumulatedBookingLimit (lBookingLimit); 00180 } 00181 } 00182 00183 // ////////////////////////////////////////////////////////////////// 00184 void Emsr:: 00185 heuristicOptimisationByEmsrB (const ResourceCapacity_T iCabinCapacity, 00186 BucketHolder& ioBucketHolder, 00187 Bucket& ioAggregatedBucket) { 00188 // Number of classes/buckets: n 00189 const short nbOfClasses = ioBucketHolder.getSize(); 00190 00196 ioBucketHolder.begin(); 00197 Bucket& firstBucket = ioBucketHolder.getCurrentBucket(); 00198 firstBucket.setCumulatedBookingLimit (iCabinCapacity); 00199 for (short j = 1; j <= nbOfClasses - 1; j++, ioBucketHolder.iterate()) { 00200 Bucket& currentBucket = ioBucketHolder.getCurrentBucket(); 00201 Bucket& nextBucket = ioBucketHolder.getNextBucket(); 00202 00203 // Compute the aggregated class/bucket of classes/buckets 1,..,j. 00204 EmsrUtils::computeAggregatedBucket (ioAggregatedBucket, 00205 currentBucket); 00206 00207 // Compute the protection level for the aggregated class/bucket 00208 // using the Little-Wood formular. 00209 const double lProtectionLevel = 00210 EmsrUtils::computeProtectionLevel (ioAggregatedBucket, nextBucket); 00211 00212 // Set the protection level for class/bucket j. 00213 currentBucket.setCumulatedProtection (lProtectionLevel); 00214 00215 // Compute the booking limit for class/bucket j+1 (can be negative). 00216 const double lBookingLimit = iCabinCapacity - lProtectionLevel; 00217 00218 // Set the booking limit for class/bucket j+1. 00219 nextBucket.setCumulatedBookingLimit (lBookingLimit); 00220 } 00221 00222 } 00223 }
Generated on Sat Jun 6 13:48:51 2009 for RMOL by Doxygen 1.5.7.1