[go: up one dir, main page]

Menu

[a7b38a]: / rmol / bom / Emsr.cpp  Maximize  Restore  History

Download this file

174 lines (148 with data), 6.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// //////////////////////////////////////////////////////////////////////
// Import section
// //////////////////////////////////////////////////////////////////////
// C
#include <assert.h>
// STL
#include <iostream>
#include <cmath>
#include <list>
#include <algorithm>
// StdAir
#include <stdair/stdair_rm_types.hpp>
#include <stdair/bom/LegCabin.hpp>
#include <stdair/bom/VirtualClassStruct.hpp>
// RMOL
#include <rmol/bom/Emsr.hpp>
#include <rmol/bom/EmsrUtils.hpp>
namespace RMOL {
// //////////////////////////////////////////////////////////////////
void Emsr::heuristicOptimisationByEmsrA (stdair::LegCabin& ioLegCabin) {
stdair::VirtualClassList_T& lVirtualClassList =
ioLegCabin.getVirtualClassList ();
const stdair::CabinCapacity_T& lCabinCapacity =
ioLegCabin.getOfferedCapacity();
/**
Iterate on the classes/buckets, from 1 to n-1.
Note that n-1 corresponds to the size of the parameter list,
i.e., n corresponds to the number of classes/buckets.
*/
stdair::VirtualClassList_T::iterator itVC =lVirtualClassList.begin();
assert (itVC != lVirtualClassList.end());
stdair::VirtualClassStruct& lFirstVC = *itVC;
lFirstVC.setCumulatedBookingLimit (lCabinCapacity);
++itVC;
for (; itVC != lVirtualClassList.end(); ++itVC) {
stdair::VirtualClassStruct& lNextVC = *itVC;
// Initialise the protection for class/bucket j.
stdair::ProtectionLevel_T lProtectionLevel = 0.0;
for(stdair::VirtualClassList_T::iterator itHigherVC =
lVirtualClassList.begin(); itHigherVC != itVC; ++itHigherVC) {
stdair::VirtualClassStruct& lHigherVC = *itHigherVC;
const double lPartialProtectionLevel =
EmsrUtils::computeProtectionLevel (lHigherVC, lNextVC);
lProtectionLevel += lPartialProtectionLevel;
}
stdair::VirtualClassList_T::iterator itCurrentVC = itVC; --itCurrentVC;
stdair::VirtualClassStruct& lCurrentVC = *itCurrentVC;
lCurrentVC.setCumulatedProtection (lProtectionLevel);
// Compute the booking limit for the class/bucket j+1 (can be negative).
const double lBookingLimit = lCabinCapacity - lProtectionLevel;
// Set the booking limit for class/bucket j+1.
lNextVC.setCumulatedBookingLimit (lBookingLimit);
}
}
// //////////////////////////////////////////////////////////////////
void Emsr::heuristicOptimisationByEmsrB (stdair::LegCabin& ioLegCabin) {
stdair::VirtualClassList_T& lVirtualClassList =
ioLegCabin.getVirtualClassList ();
const stdair::CabinCapacity_T& lCabinCapacity =
ioLegCabin.getOfferedCapacity();
/**
Iterate on the classes/buckets, from 1 to n-1.
Note that n-1 corresponds to the size of the parameter list,
i.e., n corresponds to the number of classes/buckets.
*/
stdair::VirtualClassList_T::iterator itVC =lVirtualClassList.begin();
assert (itVC != lVirtualClassList.end());
stdair::VirtualClassStruct& lFirstVC = *itVC;
lFirstVC.setCumulatedBookingLimit (lCabinCapacity);
++itVC;
stdair::VirtualClassStruct lAggregatedVC = lFirstVC;
for (; itVC != lVirtualClassList.end(); ++itVC) {
stdair::VirtualClassStruct& lNextVC = *itVC;
// Compute the protection level for the aggregated class/bucket
// using the Little-Wood formular.
const stdair::ProtectionLevel_T lProtectionLevel =
EmsrUtils::computeProtectionLevel (lAggregatedVC, lNextVC);
// Set the protection level for class/bucket j.
stdair::VirtualClassList_T::iterator itCurrentVC = itVC; --itCurrentVC;
stdair::VirtualClassStruct& lCurrentVC = *itCurrentVC;
lCurrentVC.setCumulatedProtection (lProtectionLevel);
// Compute the booking limit for class/bucket j+1 (can be negative).
const double lBookingLimit = lCabinCapacity - lProtectionLevel;
// Set the booking limit for class/bucket j+1.
lNextVC.setCumulatedBookingLimit (lBookingLimit);
// Compute the aggregated class/bucket of classes/buckets 1,..,j.
EmsrUtils::computeAggregatedVirtualClass (lAggregatedVC, lNextVC);
}
}
// //////////////////////////////////////////////////////////////////
void Emsr::heuristicOptimisationByEmsr (stdair::LegCabin& ioLegCabin) {
stdair::VirtualClassList_T& lVirtualClassList =
ioLegCabin.getVirtualClassList ();
const stdair::CabinCapacity_T& lCapacity = ioLegCabin.getOfferedCapacity();
ioLegCabin.emptyBidPriceVector();
stdair::BidPriceVector_T& lBidPriceVector =
ioLegCabin.getBidPriceVector();
// Cabin capacity in integer.
const int lCabinCapacity = static_cast<const int> (lCapacity);
// List of all EMSR values.
stdair::EmsrValueList_T lEmsrValueList;
/**
Iterate on the classes/buckets, from 1 to n.
Note that n-1 corresponds to the size of the parameter list,
i.e., n corresponds to the number of classes/buckets.
*/
for (stdair::VirtualClassList_T::iterator itVC = lVirtualClassList.begin();
itVC != lVirtualClassList.end(); ++itVC) {
stdair::VirtualClassStruct& lCurrentVC = *itVC;
for (int k = 1; k <= lCabinCapacity; ++k) {
const double emsrValue = EmsrUtils::computeEmsrValue (k, lCurrentVC);
lEmsrValueList.push_back(emsrValue);
}
}
// Sort the EMSR values from high to low.
std::sort(lEmsrValueList.rbegin(), lEmsrValueList.rend());
// Sanity check
const int lEmsrValueListSize = lEmsrValueList.size();
assert (lEmsrValueListSize >= lCabinCapacity);
// Copy the EMSR sorted values to the BPV.
stdair::EmsrValueList_T::const_iterator itCurrentValue =
lEmsrValueList.begin();
for (int j = 0; j < lCabinCapacity; ++j, ++itCurrentValue) {
const double lBidPrice = *itCurrentValue;
lBidPriceVector.push_back (lBidPrice);
}
lEmsrValueList.clear();
// Build the protection levels and booking limits.
if (lVirtualClassList.size() > 1) {
int lCapacityIndex = 0;
for (stdair::VirtualClassList_T::iterator itVC =lVirtualClassList.begin();
itVC != lVirtualClassList.end();) {
stdair::VirtualClassStruct& lCurrentVC = *itVC;
if (itVC != lVirtualClassList.end()) {
++itVC;
}
stdair::VirtualClassStruct& lNextVC = *itVC;
const stdair::Yield_T lNextYield = lNextVC.getYield();
while ((lCapacityIndex < lCabinCapacity)
&& (lBidPriceVector.at(lCapacityIndex) > lNextYield)) {
++lCapacityIndex;
}
lCurrentVC.setCumulatedProtection (lCapacityIndex);
lNextVC.setCumulatedBookingLimit (lCapacity - lCapacityIndex);
}
}
}
}