8 #include <stdair/basic/BasConst_General.hpp>
9 #include <stdair/basic/RandomGeneration.hpp>
10 #include <stdair/bom/BomManager.hpp>
11 #include <stdair/bom/FlightDate.hpp>
12 #include <stdair/bom/LegDate.hpp>
13 #include <stdair/bom/SegmentDate.hpp>
14 #include <stdair/bom/LegCabin.hpp>
15 #include <stdair/bom/SegmentCabin.hpp>
16 #include <stdair/bom/FareFamily.hpp>
17 #include <stdair/bom/BookingClass.hpp>
18 #include <stdair/service/Logger.hpp>
31 stdair::LegCabin& ioLegCabin) {
33 const stdair::SegmentCabinList_T lSegmentCabinList =
34 stdair::BomManager::getList<stdair::SegmentCabin> (ioLegCabin);
35 stdair::SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
36 assert (itSC != lSegmentCabinList.end());
37 const stdair::SegmentCabin* lSegmentCabin_ptr = *itSC;
38 assert (lSegmentCabin_ptr != NULL);
41 const stdair::BookingClassList_T lBookingClassList =
42 stdair::BomManager::getList<stdair::BookingClass> (*lSegmentCabin_ptr);
43 stdair::RandomGeneration lSeedGenerator (stdair::DEFAULT_RANDOM_SEED);
46 for (stdair::BookingClassList_T::const_iterator itBC =
47 lBookingClassList.begin(); itBC != lBookingClassList.end(); ++itBC) {
48 stdair::RandomSeed_T lRandomSeed =
49 lSeedGenerator.generateUniform01 () * 1e9;
50 stdair::BookingClass* lBookingClass_ptr = *itBC;
51 assert (lBookingClass_ptr != NULL);
52 lBookingClass_ptr->generateDemandSamples (K, lRandomSeed);
85 const stdair::OptimisationMethod& iOptimisationMethod) {
86 bool optimiseSucceeded =
false;
89 const stdair::LegDateList_T& lLDList =
90 stdair::BomManager::getList<stdair::LegDate> (ioFlightDate);
91 for (stdair::LegDateList_T::const_iterator itLD = lLDList.begin();
92 itLD != lLDList.end(); ++itLD) {
93 stdair::LegDate* lLD_ptr = *itLD;
94 assert (lLD_ptr != NULL);
95 const bool isSucceeded =
optimise(*lLD_ptr, iOptimisationMethod);
97 if (isSucceeded ==
true) {
98 optimiseSucceeded =
true;
102 return optimiseSucceeded;
107 optimise (stdair::LegDate& ioLegDate,
108 const stdair::OptimisationMethod& iOptimisationMethod) {
109 bool optimiseSucceeded =
false;
111 const stdair::LegCabinList_T& lLCList =
112 stdair::BomManager::getList<stdair::LegCabin> (ioLegDate);
113 for (stdair::LegCabinList_T::const_iterator itLC = lLCList.begin();
114 itLC != lLCList.end(); ++itLC) {
115 stdair::LegCabin* lLC_ptr = *itLC;
116 assert (lLC_ptr != NULL);
117 const bool isSucceeded =
optimise(*lLC_ptr, iOptimisationMethod);
119 if (isSucceeded ==
true) {
120 optimiseSucceeded =
true;
124 return optimiseSucceeded;
129 optimise (stdair::LegCabin& ioLegCabin,
130 const stdair::OptimisationMethod& iOptimisationMethod) {
131 bool optimiseSucceeded =
false;
134 bool hasVirtualClass =
136 if (hasVirtualClass ==
true) {
137 switch (iOptimisationMethod.getMethod()) {
138 case stdair::OptimisationMethod::LEG_BASED_MC: {
141 const stdair::NbOfSamples_T lNbOfSamples =
144 optimiseSucceeded =
true;
147 case stdair::OptimisationMethod::LEG_BASED_EMSR_B: {
149 optimiseSucceeded =
true;
159 return optimiseSucceeded;
166 stdair::VirtualClassMap_T lVirtualClassMap;
167 bool isNotEmpty =
false;
170 const stdair::SegmentCabinList_T& lSegmentCabinList =
171 stdair::BomManager::getList<stdair::SegmentCabin> (ioLegCabin);
172 stdair::SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
173 assert (itSC != lSegmentCabinList.end());
174 const stdair::SegmentCabin* lSegmentCabin_ptr = *itSC;
175 assert (lSegmentCabin_ptr != NULL);
178 const stdair::BookingClassList_T lBookingClassList =
179 stdair::BomManager::getList<stdair::BookingClass> (*lSegmentCabin_ptr);
182 for (stdair::BookingClassList_T::const_iterator itBC =
183 lBookingClassList.begin(); itBC != lBookingClassList.end(); ++itBC) {
184 stdair::BookingClass* lBookingClass_ptr = *itBC;
185 assert (lBookingClass_ptr != NULL);
190 const stdair::NbOfRequests_T& lMean = lBookingClass_ptr->getMean();
191 const stdair::StdDevValue_T& lStdDev = lBookingClass_ptr->getStdDev();
193 const stdair::Yield_T& lYield = lBookingClass_ptr->getAdjustedYield();
195 assert (lYield >= 0.0);
196 const stdair::Yield_T lRoundedYieldDouble = std::floor(lYield +0.5);
197 const stdair::YieldLevel_T lRoundedYieldLevel =
198 static_cast<stdair::YieldLevel_T
>(lRoundedYieldDouble);
199 if (lRoundedYieldLevel > 0) {
203 stdair::VirtualClassMap_T::iterator itVCMap =
204 lVirtualClassMap.find(lRoundedYieldLevel);
205 if (itVCMap == lVirtualClassMap.end()) {
206 stdair::BookingClassList_T lBookingClassList;
207 lBookingClassList.push_back(lBookingClass_ptr);
208 stdair::VirtualClassStruct lVirtualClass (lBookingClassList);
209 lVirtualClass.setYield (lRoundedYieldLevel);
210 lVirtualClass.setMean (lMean);
211 lVirtualClass.setStdDev (lStdDev);
213 lVirtualClassMap.insert (stdair::VirtualClassMap_T::
214 value_type (lRoundedYieldLevel, lVirtualClass));
216 stdair::VirtualClassStruct& lVirtualClass = itVCMap->second;
217 const stdair::MeanValue_T& lVCMean = lVirtualClass.getMean();
218 const stdair::StdDevValue_T& lVCStdDev = lVirtualClass.getStdDev();
219 const stdair::MeanValue_T lNewMean = lVCMean + lMean;
220 const stdair::StdDevValue_T lNewStdDev =
221 std::sqrt(lVCStdDev * lVCStdDev + lStdDev * lStdDev);
222 lVirtualClass.setMean (lNewMean);
223 lVirtualClass.setStdDev (lNewStdDev);
225 lVirtualClass.addBookingClass(*lBookingClass_ptr);
232 ioLegCabin.emptyVirtualClassList();
233 for (stdair::VirtualClassMap_T::reverse_iterator itVC =
234 lVirtualClassMap.rbegin(); itVC != lVirtualClassMap.rend(); ++itVC) {
235 stdair::VirtualClassStruct& lVC = itVC->second;
237 ioLegCabin.addVirtualClass (lVC);
238 if (isNotEmpty ==
false) {
248 const bool& iReduceFluctuations) {
249 double lMaxBPVariation = 0.0;
252 const bool hasLegDateList =
253 stdair::BomManager::hasList<stdair::LegDate> (ioFlightDate);
254 if (hasLegDateList ==
true) {
255 STDAIR_LOG_DEBUG (
"Optimisation for the flight date: "
256 << ioFlightDate.toString());
257 const stdair::LegDateList_T& lLDList =
258 stdair::BomManager::getList<stdair::LegDate> (ioFlightDate);
259 for (stdair::LegDateList_T::const_iterator itLD = lLDList.begin();
260 itLD != lLDList.end(); ++itLD) {
261 stdair::LegDate* lLD_ptr = *itLD;
262 assert (lLD_ptr != NULL);
265 const stdair::LegCabinList_T& lLCList =
266 stdair::BomManager::getList<stdair::LegCabin> (*lLD_ptr);
267 for (stdair::LegCabinList_T::const_iterator itLC = lLCList.begin();
268 itLC != lLCList.end(); ++itLC) {
269 stdair::LegCabin* lLC_ptr = *itLC;
270 assert (lLC_ptr != NULL);
272 const stdair::BidPrice_T& lCurrentBidPrice =
273 lLC_ptr->getCurrentBidPrice();
274 const stdair::BidPrice_T& lPreviousBidPrice =
275 lLC_ptr->getPreviousBidPrice();
276 assert (lPreviousBidPrice != 0);
277 const double lBPVariation =
278 std::abs((lCurrentBidPrice - lPreviousBidPrice)/lPreviousBidPrice);
279 lMaxBPVariation = std::max(lMaxBPVariation, lBPVariation);
283 return lMaxBPVariation;