9 #include <stdair/basic/BasConst_General.hpp>
10 #include <stdair/basic/BasConst_Inventory.hpp>
11 #include <stdair/bom/BomManager.hpp>
12 #include <stdair/bom/SegmentCabin.hpp>
13 #include <stdair/bom/BookingClass.hpp>
14 #include <stdair/bom/SimpleNestingStructure.hpp>
15 #include <stdair/bom/NestingNode.hpp>
16 #include <stdair/bom/Policy.hpp>
17 #include <stdair/factory/FacBomManager.hpp>
18 #include <stdair/service/Logger.hpp>
32 buildNestedConvexHull (ioSegmentCabin);
33 bool isSucceeded = adjustYieldAndDemand (ioSegmentCabin);
39 void MarginalRevenueTransformation::
40 buildConvexHull (stdair::SegmentCabin& ioSegmentCabin) {
42 ioSegmentCabin.resetConvexHull();
46 const stdair::PolicyList_T& lPolicyList =
47 stdair::BomManager::getList<stdair::Policy> (ioSegmentCabin);
51 stdair::PolicyList_T::const_iterator itPolicy=lPolicyList.begin();
52 stdair::Policy* lEmptyPolicy_ptr = *itPolicy;
53 assert (lEmptyPolicy_ptr != NULL);
54 ioSegmentCabin.addPolicy (*lEmptyPolicy_ptr);
57 stdair::Policy* lCurrentPolicy_ptr = lEmptyPolicy_ptr;
58 bool lEndOfHull =
false;
62 while (lEndOfHull ==
false) {
64 const double& lCurrentDem = lCurrentPolicy_ptr->getDemand();
65 const double lCurrentTR = lCurrentPolicy_ptr->getTotalRevenue();
68 double lGradient = 0.0;
69 stdair::Policy* lNextPolicy_ptr = NULL;
70 for (stdair::PolicyList_T::const_iterator itPol = lPolicyList.begin();
71 itPol != lPolicyList.end(); ++itPol) {
72 stdair::Policy* lPolicy_ptr = *itPol;
73 assert (lPolicy_ptr != NULL);
75 const double& lDem = lPolicy_ptr->getDemand();
76 const double lTR = lPolicy_ptr->getTotalRevenue();
77 if (lDem > lCurrentDem && lTR > lCurrentTR) {
78 const double lNewGradient = (lTR-lCurrentTR)/(lDem-lCurrentDem);
79 if (lNewGradient > lGradient) {
80 lGradient = lNewGradient;
81 lNextPolicy_ptr = lPolicy_ptr;
87 if (lNextPolicy_ptr == NULL) {
90 ioSegmentCabin.addPolicy (*lNextPolicy_ptr);
91 lCurrentPolicy_ptr = lNextPolicy_ptr;
97 void MarginalRevenueTransformation::
98 buildNestedConvexHull (stdair::SegmentCabin& ioSegmentCabin) {
100 ioSegmentCabin.resetConvexHull();
104 const stdair::PolicyList_T& lPolicyList =
105 stdair::BomManager::getList<stdair::Policy> (ioSegmentCabin);
109 stdair::PolicyList_T::const_iterator itPolicy=lPolicyList.begin();
110 stdair::Policy* lEmptyPolicy_ptr = *itPolicy;
111 assert (lEmptyPolicy_ptr != NULL);
112 ioSegmentCabin.addPolicy (*lEmptyPolicy_ptr);
115 stdair::Policy* lCurrentPolicy_ptr = lEmptyPolicy_ptr;
116 bool lEndOfHull =
false;
120 while (lEndOfHull ==
false) {
122 const double& lCurrentDem = lCurrentPolicy_ptr->getDemand();
123 const double lCurrentTR = lCurrentPolicy_ptr->getTotalRevenue();
126 double lGradient = 0.0;
127 stdair::Policy* lNextPolicy_ptr = NULL;
128 for (stdair::PolicyList_T::const_iterator itPol = lPolicyList.begin();
129 itPol != lPolicyList.end(); ++itPol) {
130 stdair::Policy* lPolicy_ptr = *itPol;
131 assert (lPolicy_ptr != NULL);
133 const double& lDem = lPolicy_ptr->getDemand();
134 const double lTR = lPolicy_ptr->getTotalRevenue();
135 if (lDem > lCurrentDem && lTR > lCurrentTR
137 const double lNewGradient = (lTR-lCurrentTR)/(lDem-lCurrentDem);
138 if (lNewGradient > lGradient) {
139 lGradient = lNewGradient;
140 lNextPolicy_ptr = lPolicy_ptr;
146 if (lNextPolicy_ptr == NULL) {
149 ioSegmentCabin.addPolicy (*lNextPolicy_ptr);
150 lCurrentPolicy_ptr = lNextPolicy_ptr;
156 bool MarginalRevenueTransformation::
157 adjustYieldAndDemand (stdair::SegmentCabin& ioSegmentCabin) {
158 bool isSucceeded =
false;
159 stdair::NbOfClasses_T lBookingClassCounter = 0;
162 const stdair::PolicyList_T& lConvexHull = ioSegmentCabin.getConvexHull();
163 stdair::PolicyList_T::const_iterator itCurrentPolicy = lConvexHull.begin();
164 assert (itCurrentPolicy != lConvexHull.end());
165 stdair::PolicyList_T::const_iterator itNextPolicy = itCurrentPolicy;
169 if (itNextPolicy == lConvexHull.end()) {
174 stdair::FacBomManager::resetYieldBasedNestingStructure (ioSegmentCabin);
177 stdair::SimpleNestingStructure& lYieldBasedNS =
178 stdair::BomManager::getObject<stdair::SimpleNestingStructure> (ioSegmentCabin, stdair::YIELD_BASED_NESTING_STRUCTURE_CODE);
179 const stdair::NestingNodeList_T& lNodeList =
180 stdair::BomManager::getList<stdair::NestingNode> (lYieldBasedNS);
181 stdair::NestingNodeList_T::const_iterator itNode = lNodeList.begin();
183 for (; itNextPolicy != lConvexHull.end();
184 ++itCurrentPolicy, ++itNextPolicy, ++itNode){
185 const stdair::Policy* lCurrentPolicy_ptr = *itCurrentPolicy;
186 assert (lCurrentPolicy_ptr != NULL);
187 const stdair::Policy* lNextPolicy_ptr = *itNextPolicy;
188 assert (lNextPolicy_ptr != NULL);
191 stdair::NestingNode* lNode_ptr = NULL;
192 if (itNode == lNodeList.end()) {
194 stdair::NestingNodeCode_T lNodeCode (
"XXX");
195 stdair::NestingNodeKey lNodeKey (lNodeCode);
196 stdair::NestingNode& lNestingNode =
197 stdair::FacBom<stdair::NestingNode>::instance().create (lNodeKey);
198 stdair::FacBomManager::addToList (lYieldBasedNS, lNestingNode);
199 stdair::FacBomManager::linkWithParent (lYieldBasedNS, lNestingNode);
200 lNode_ptr = &lNestingNode;
204 assert (lNode_ptr != NULL);
206 *lCurrentPolicy_ptr);
213 const stdair::MeanValue_T lAdjustedDemMean =
214 lNextPolicy_ptr->getDemand()-lCurrentPolicy_ptr->getDemand();
215 assert (lAdjustedDemMean > 0.0);
216 const stdair::StdDevValue_T& lCurrentStdDev =
217 lCurrentPolicy_ptr->getStdDev();
218 const stdair::StdDevValue_T& lNextStdDev = lNextPolicy_ptr->getStdDev();
219 assert (lNextStdDev > lCurrentStdDev);
220 const stdair::StdDevValue_T lAdjustedDemStdDev =
221 std::sqrt (lNextStdDev*lNextStdDev - lCurrentStdDev*lCurrentStdDev);
222 const stdair::Yield_T lAdjustedYield =
223 (lNextPolicy_ptr->getTotalRevenue()-lCurrentPolicy_ptr->getTotalRevenue())/(lAdjustedDemMean);
224 assert (lAdjustedYield > 0.0);
225 lNode_ptr->setYield (lAdjustedYield);
230 const stdair::BookingClassList_T lBCList =
231 stdair::BomManager::getList<stdair::BookingClass> (*lNode_ptr);
232 stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
233 assert (itBC != lBCList.end());
234 stdair::BookingClass* lFirstClass = *itBC;
235 assert (lFirstClass != NULL);
236 lFirstClass->setMean (lAdjustedDemMean);
237 lFirstClass->setStdDev (lAdjustedDemStdDev);
238 for (; itBC != lBCList.end(); ++itBC) {
239 stdair::BookingClass* lClass = *itBC;
240 assert (lClass != NULL);
241 lClass->setAdjustedYield (lAdjustedYield);
242 ++lBookingClassCounter;
246 const stdair::BookingClassList_T& lSCBookingClassList =
247 stdair::BomManager::getList<stdair::BookingClass> (ioSegmentCabin);
248 const stdair::NbOfClasses_T lNbOfBookingClass = lSCBookingClassList.size();
249 assert (lNbOfBookingClass >= lBookingClassCounter);
250 if (lBookingClassCounter < lNbOfBookingClass) {
255 stdair::NestingNode* lLastNode_ptr = NULL;
256 if (itNode == lNodeList.end()) {
258 stdair::NestingNodeCode_T lNodeCode (
"XXX");
259 stdair::NestingNodeKey lNodeKey (lNodeCode);
260 stdair::NestingNode& lNestingNode =
261 stdair::FacBom<stdair::NestingNode>::instance().create (lNodeKey);
262 stdair::FacBomManager::addToList (lYieldBasedNS, lNestingNode);
263 stdair::FacBomManager::linkWithParent (lYieldBasedNS, lNestingNode);
265 stdair::BomManager::getObjectPtr<stdair::NestingNode>(lYieldBasedNS,
266 lNodeKey.toString());
268 lLastNode_ptr = *itNode;
270 assert (lLastNode_ptr != NULL);
271 const stdair::Policy* lLastPolicy_ptr = *itCurrentPolicy;
272 assert (lLastPolicy_ptr != NULL);