11 #include <stdair/stdair_basic_types.hpp>
12 #include <stdair/bom/BomManager.hpp>
13 #include <stdair/bom/LegCabin.hpp>
14 #include <stdair/bom/SegmentCabin.hpp>
15 #include <stdair/bom/BookingClass.hpp>
16 #include <stdair/bom/VirtualClassStruct.hpp>
17 #include <stdair/service/Logger.hpp>
18 #include <stdair/basic/RandomGeneration.hpp>
19 #include <stdair/basic/BasConst_General.hpp>
30 const stdair::SegmentCabinList_T lSegmentCabinList =
31 stdair::BomManager::getList<stdair::SegmentCabin> (ioLegCabin);
32 stdair::SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
33 assert (itSC != lSegmentCabinList.end());
34 const stdair::SegmentCabin* lSegmentCabin_ptr = *itSC;
35 assert (lSegmentCabin_ptr != NULL);
38 const stdair::BookingClassList_T lBookingClassList =
39 stdair::BomManager::getList<stdair::BookingClass> (*lSegmentCabin_ptr);
42 const stdair::Availability_T& lCap = ioLegCabin.getAvailabilityPool();
43 const int lCapacity =
static_cast<const int> (lCap);
44 const stdair::UnsignedIndex_T lCapacityIndex =
45 static_cast<const stdair::UnsignedIndex_T
> ((lCapacity+abs(lCapacity))/2);
48 stdair::VirtualClassList_T& lVCList = ioLegCabin.getVirtualClassList();
51 stdair::VirtualClassList_T::iterator itCurrentVC = lVCList.begin();
52 assert (itCurrentVC != lVCList.end());
53 stdair::VirtualClassList_T::iterator itNextVC = itCurrentVC; ++itNextVC;
57 stdair::VirtualClassStruct& lFirstVC = *itCurrentVC;
58 stdair::GeneratedDemandVector_T lPartialSumHolder =
59 lFirstVC.getGeneratedDemandVector();
63 lFirstVC.setCumulatedBookingLimit (lCap);
67 ioLegCabin.emptyBidPriceVector();
68 stdair::BidPriceVector_T& lBPV = ioLegCabin.getBidPriceVector();
71 stdair::UnsignedIndex_T idx = 1;
73 for (; itNextVC != lVCList.end(); ++itCurrentVC, ++itNextVC) {
75 stdair::VirtualClassStruct& lCurrentVC = *itCurrentVC;
76 stdair::VirtualClassStruct& lNextVC = *itNextVC;
77 const stdair::Yield_T& yj = lCurrentVC.getYield ();
78 const stdair::Yield_T& yj1 = lNextVC.getYield ();
85 std::sort (lPartialSumHolder.begin(), lPartialSumHolder.end());
86 const stdair::UnsignedIndex_T K = lPartialSumHolder.size ();
89 const double ljdouble = std::floor (K * (yj - yj1) / yj);
90 stdair::UnsignedIndex_T lj =
91 static_cast<stdair::UnsignedIndex_T
> (ljdouble);
94 assert (lj >= 1 && lj < K);
97 const double sjl = lPartialSumHolder.at (lj - 1);
98 const double sjlp1 = lPartialSumHolder.at (lj + 1 - 1);
99 const double pj = (sjl + sjlp1) / 2;
102 lCurrentVC.setCumulatedProtection (pj);
104 lNextVC.setCumulatedBookingLimit (lCap - pj);
110 const stdair::UnsignedIndex_T pjint =
static_cast<const int> (pj);
111 stdair::GeneratedDemandVector_T::iterator itLowerBound =
112 lPartialSumHolder.begin();
113 for (; idx <= pjint && idx <= lCapacityIndex; ++idx) {
115 std::lower_bound (itLowerBound, lPartialSumHolder.end(), idx);
116 const stdair::UnsignedIndex_T pos =
117 itLowerBound - lPartialSumHolder.begin();
119 const stdair::BidPrice_T lBP = yj * (K - pos) / K;
120 lBPV.push_back (lBP);
124 const stdair::GeneratedDemandVector_T& lNextPSH =
125 lNextVC.getGeneratedDemandVector();
126 assert (K <= lNextPSH.size());
127 for (stdair::UnsignedIndex_T i = 0; i < K - lj; ++i) {
128 lPartialSumHolder.at(i) = lPartialSumHolder.at(i + lj) + lNextPSH.at(i);
130 lPartialSumHolder.resize (K - lj);
137 stdair::VirtualClassStruct& lLastVC = *itCurrentVC;
138 const stdair::Yield_T& yn = lLastVC.getYield();
139 stdair::GeneratedDemandVector_T::iterator itLowerBound =
140 lPartialSumHolder.begin();
141 for (; idx <= lCapacityIndex; ++idx) {
143 std::lower_bound (itLowerBound, lPartialSumHolder.end(), idx);
144 const stdair::UnsignedIndex_T pos =
145 itLowerBound - lPartialSumHolder.begin();
146 const stdair::UnsignedIndex_T K = lPartialSumHolder.size();
147 const stdair::BidPrice_T lBP = yn * (K - pos) / K;
148 lBPV.push_back (lBP);
155 const stdair::StdDevValue_T& iStdDev,
156 const stdair::NbOfSamples_T& K) {
157 stdair::GeneratedDemandVector_T oDemandVector;
159 stdair::RandomGeneration lGenerator (stdair::DEFAULT_RANDOM_SEED);
160 for (
unsigned int i = 0; i < K; ++i) {
161 stdair::RealNumber_T lDemandSample =
162 lGenerator.generateNormal (iMean, iStdDev);
163 oDemandVector.push_back (lDemandSample);
166 for (
unsigned int i = 0; i < K; ++i) {
167 oDemandVector.push_back (iMean);
170 return oDemandVector;
179 const stdair::YieldLevelDemandMap_T& lYieldDemandMap =
180 ioLegCabin.getYieldLevelDemandMap();
181 assert (!lYieldDemandMap.empty());
183 std::ostringstream oStr;
184 oStr <<
"Yield list ";
185 for (stdair::YieldLevelDemandMap_T::const_iterator itYD =
186 lYieldDemandMap.begin();
187 itYD != lYieldDemandMap.end(); ++itYD) {
188 const stdair::Yield_T& y = itYD->first;
192 STDAIR_LOG_DEBUG (oStr.str());
193 ioLegCabin.emptyBidPriceVector();
194 stdair::BidPriceVector_T& lBidPriceVector =
195 ioLegCabin.getBidPriceVector();
196 const stdair::Availability_T& lAvailabilityPool =
197 ioLegCabin.getAvailabilityPool();
200 const stdair::BidPrice_T& lMinBP = 1.0;
202 stdair::YieldLevelDemandMap_T::const_reverse_iterator itCurrentYD =
203 lYieldDemandMap.rbegin();
204 stdair::YieldLevelDemandMap_T::const_reverse_iterator itNextYD = itCurrentYD;
208 stdair::MeanStdDevPair_T lMeanStdDevPair = itCurrentYD->second;
209 stdair::GeneratedDemandVector_T lPartialSumHolder =
212 stdair::UnsignedIndex_T idx = 1;
213 for (; itNextYD!=lYieldDemandMap.rend(); ++itCurrentYD, ++itNextYD) {
214 const stdair::Yield_T& yj = itCurrentYD->first;
215 const stdair::Yield_T& yj1 = itNextYD->first;
220 std::sort (lPartialSumHolder.begin(), lPartialSumHolder.end());
223 K = lPartialSumHolder.size ();
225 const double ljdouble = std::floor (K * (yj - yj1) / yj);
226 stdair::UnsignedIndex_T lj =
227 static_cast<stdair::UnsignedIndex_T
> (ljdouble);
229 assert (lj >= 1 && lj < K);
231 const double sjl = lPartialSumHolder.at (lj - 1);
232 const double sjlp1 = lPartialSumHolder.at (lj + 1 - 1);
233 const double pj = (sjl + sjlp1) / 2;
238 const stdair::UnsignedIndex_T pjint =
static_cast<const int> (pj);
239 stdair::GeneratedDemandVector_T::iterator itLowerBound =
240 lPartialSumHolder.begin();
241 for (; idx <= pjint && idx <= lAvailabilityPool; ++idx) {
243 std::lower_bound (itLowerBound, lPartialSumHolder.end(), idx);
244 const stdair::UnsignedIndex_T pos =
245 itLowerBound - lPartialSumHolder.begin();
247 const stdair::BidPrice_T lBP = yj * (K - pos) / K;
248 lBidPriceVector.push_back (lBP);
251 lMeanStdDevPair = itNextYD->second;
252 const stdair::GeneratedDemandVector_T& lNextDV =
254 lMeanStdDevPair.second, K - lj);
255 for (stdair::UnsignedIndex_T i = 0; i < K - lj; ++i) {
256 lPartialSumHolder.at(i) = lPartialSumHolder.at(i + lj) + lNextDV.at(i);
258 lPartialSumHolder.resize (K - lj);
271 std::sort (lPartialSumHolder.begin(), lPartialSumHolder.end());
272 const stdair::Yield_T& yn = itCurrentYD->first;
273 stdair::GeneratedDemandVector_T::iterator itLowerBound =
274 lPartialSumHolder.begin();
275 K = lPartialSumHolder.size();
277 bool lMinBPReached =
false;
278 for (; idx <= lAvailabilityPool; ++idx) {
280 std::lower_bound (itLowerBound, lPartialSumHolder.end(), idx);
282 if (!lMinBPReached) {
283 const stdair::UnsignedIndex_T pos =
284 itLowerBound - lPartialSumHolder.begin();
285 stdair::BidPrice_T lBP = yn * (K - pos) / K;
288 lBP = lMinBP; lMinBPReached =
true;
291 lBidPriceVector.push_back (lBP);
294 lBidPriceVector.push_back (lMinBP);
300 ioLegCabin.updatePreviousBidPrice();
301 ioLegCabin.setCurrentBidPrice (lBidPriceVector.back());
304 const stdair::BidPrice_T lPreviousBP = ioLegCabin.getPreviousBidPrice();
305 stdair::BidPrice_T lNewBP = ioLegCabin.getCurrentBidPrice();
307 assert (lPreviousBP != 0);
308 stdair::BidPrice_T lBidPriceDelta = lNewBP - lPreviousBP;
310 double lBidPriceVariation = 100*lBidPriceDelta/lPreviousBP;
312 STDAIR_LOG_DEBUG (
"Bid price: previous value " << lPreviousBP
313 <<
", new value " << lNewBP
314 <<
", variation " << lBidPriceVariation <<
" %"
315 <<
", BPV size " << lBidPriceVector.size());