AirRAC Logo  1.00.0
C++ Simulated Revenue Accounting (RAC) System Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
YieldManager.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // StdAir
7 #include <stdair/basic/BasConst_Request.hpp>
8 #include <stdair/bom/BomManager.hpp>
9 #include <stdair/bom/BomRoot.hpp>
10 #include <stdair/bom/Inventory.hpp>
11 #include <stdair/bom/FlightDate.hpp>
12 #include <stdair/bom/SegmentDate.hpp>
13 #include <stdair/bom/SegmentCabin.hpp>
14 #include <stdair/bom/FareFamily.hpp>
15 #include <stdair/bom/BookingClass.hpp>
16 #include <stdair/bom/TravelSolutionStruct.hpp>
17 #include <stdair/bom/AirportPair.hpp>
18 #include <stdair/bom/PosChannel.hpp>
19 #include <stdair/bom/DatePeriod.hpp>
20 #include <stdair/bom/TimePeriod.hpp>
21 #include <stdair/bom/YieldFeatures.hpp>
22 #include <stdair/bom/AirlineClassList.hpp>
23 #include <stdair/factory/FacBomManager.hpp>
24 #include <stdair/service/Logger.hpp>
25 // Airrac
26 #include <airrac/AIRRAC_Types.hpp>
28 
29 namespace AIRRAC {
30 
31  // ////////////////////////////////////////////////////////////////////
32  YieldManager::YieldManager() {
33  assert (false);
34  }
35 
36  // ////////////////////////////////////////////////////////////////////
37  YieldManager::YieldManager (const YieldManager&) {
38  assert (false);
39  }
40 
41  // ////////////////////////////////////////////////////////////////////
42  YieldManager::~YieldManager() {
43  }
44 
45  // ////////////////////////////////////////////////////////////////////
46  void YieldManager::
47  calculateYield (stdair::TravelSolutionList_T& ioTravelSolutionList,
48  const stdair::BomRoot& iBomRoot) {
49 
50  // Browse the list of TravelSolution structures
51  for (stdair::TravelSolutionList_T::iterator itTravelSolution =
52  ioTravelSolutionList.begin();
53  itTravelSolution != ioTravelSolutionList.end(); ++itTravelSolution) {
54  stdair::TravelSolutionStruct& lTravelSolution = *itTravelSolution;
55 
56  //
57  YieldManager::calculateYield (lTravelSolution, iBomRoot);
58  }
59  }
60 
61  // ////////////////////////////////////////////////////////////////////
62  void YieldManager::
63  calculateYield (stdair::TravelSolutionStruct& ioTravelSolution,
64  const stdair::BomRoot& iBomRoot) {
65 
66  // Calculate/retrieve the yield for the given travel solution
67  //YieldStore::calculateYield (ioYield, ioTravelSolution);
68 
69  // TODO: update the statistical attributes of the yield.
70  }
71 
72  // ////////////////////////////////////////////////////////////////////
73  void YieldManager::updateYields (const stdair::BomRoot& iBomRoot) {
74  // Browse the list of booking classes and update yield for each one.
75  const stdair::InventoryList_T lInvList =
76  stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
77  for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
78  itInv != lInvList.end(); ++itInv) {
79  const stdair::Inventory* lInv_ptr = *itInv;
80  assert (lInv_ptr != NULL);
81 
82  // Retrieve the airline code.
83  const stdair::AirlineCode_T& lAirlineCode = lInv_ptr->getAirlineCode();
84 
85  //
86  const stdair::FlightDateList_T& lFDList =
87  stdair::BomManager::getList<stdair::FlightDate> (*lInv_ptr);
88  for (stdair::FlightDateList_T::const_iterator itFD = lFDList.begin();
89  itFD != lFDList.end(); ++itFD) {
90  const stdair::FlightDate* lFD_ptr = *itFD;
91  assert (lFD_ptr != NULL);
92 
93  //
94  const stdair::SegmentDateList_T& lSDList =
95  stdair::BomManager::getList<stdair::SegmentDate> (*lFD_ptr);
96  for (stdair::SegmentDateList_T::const_iterator itSD = lSDList.begin();
97  itSD != lSDList.end(); ++itSD) {
98  const stdair::SegmentDate* lSD_ptr = *itSD;
99  assert (lSD_ptr != NULL);
100 
101  // Retrieve the origin and the destination
102  const stdair::AirportCode_T& lOrigin = lSD_ptr->getBoardingPoint();
103  const stdair::AirportCode_T& lDestination = lSD_ptr->getOffPoint();
104 
105  // Retrieve the airport pair in the yield structure.
106  const stdair::AirportPairKey lAirportPairKey (lOrigin, lDestination);
107  stdair::AirportPair* lAirportPair_ptr = stdair::BomManager::
108  getObjectPtr<stdair::AirportPair> (iBomRoot,
109  lAirportPairKey.toString());
110  if (lAirportPair_ptr == NULL) {
111  STDAIR_LOG_ERROR ("Cannot find yield corresponding to the airport "
112  << "pair: " << lAirportPairKey.toString());
113  assert (false);
114  }
115 
116  // Retrieve the boarding date and time
117  const stdair::Date_T& lDate = lSD_ptr->getBoardingDate();
118  const stdair::Duration_T& lTime = lSD_ptr->getBoardingTime();
119 
120  // Retrieve the corresponding date period.
121  const stdair::DatePeriodList_T& lDatePeriodList =
122  stdair::BomManager::getList<stdair::DatePeriod> (*lAirportPair_ptr);
123  for (stdair::DatePeriodList_T::const_iterator itDatePeriod =
124  lDatePeriodList.begin();
125  itDatePeriod != lDatePeriodList.end(); ++itDatePeriod) {
126  const stdair::DatePeriod* lDatePeriod_ptr = *itDatePeriod;
127  assert (lDatePeriod_ptr != NULL);
128 
129  const bool isDepartureDateValid =
130  lDatePeriod_ptr->isDepartureDateValid (lDate);
131 
132  if (isDepartureDateValid == true) {
133 
134  // Retrieve the PoS-Channel.
135  const stdair::PosChannelKey lPosChannelKey (stdair::DEFAULT_POS,
136  stdair::DEFAULT_CHANNEL);
137  stdair::PosChannel* lPosChannel_ptr = stdair::BomManager::
138  getObjectPtr<stdair::PosChannel> (*lDatePeriod_ptr,
139  lPosChannelKey.toString());
140  if (lPosChannel_ptr == NULL) {
141  STDAIR_LOG_ERROR ("Cannot find yield corresponding to the PoS-"
142  << "Channel: " << lPosChannelKey.toString());
143  assert (false);
144  }
145 
146  // Retrieve the corresponding time period.
147  const stdair::TimePeriodList_T& lTimePeriodList = stdair::
148  BomManager::getList<stdair::TimePeriod> (*lPosChannel_ptr);
149  for (stdair::TimePeriodList_T::const_iterator itTimePeriod =
150  lTimePeriodList.begin();
151  itTimePeriod != lTimePeriodList.end(); ++itTimePeriod) {
152  const stdair::TimePeriod* lTimePeriod_ptr = *itTimePeriod;
153  assert (lTimePeriod_ptr != NULL);
154 
155  const bool isDepartureTimeValid =
156  lTimePeriod_ptr->isDepartureTimeValid (lTime);
157 
158  if (isDepartureTimeValid == true) {
159  updateYields (*lSD_ptr, *lTimePeriod_ptr, lAirlineCode);
160  }
161  }
162  }
163  }
164  }
165  }
166  }
167  }
168 
169  // ////////////////////////////////////////////////////////////////////
170  void YieldManager::updateYields (const stdair::SegmentDate& iSegmentDate,
171  const stdair::TimePeriod& iTimePeriod,
172  const stdair::AirlineCode_T& iAirlineCode) {
173  // Browse the segment-cabin list and retrieve the corresponding
174  // yield features.
175  const stdair::SegmentCabinList_T& lSegmentCabinList =
176  stdair::BomManager::getList<stdair::SegmentCabin> (iSegmentDate);
177  for (stdair::SegmentCabinList_T::const_iterator itSC =
178  lSegmentCabinList.begin(); itSC != lSegmentCabinList.end(); ++itSC) {
179  const stdair::SegmentCabin* lSegmentCabin_ptr = *itSC;
180  assert (lSegmentCabin_ptr != NULL);
181 
182  const stdair::CabinCode_T& lCabinCode = lSegmentCabin_ptr->getCabinCode();
183  const stdair::TripType_T lTripType (stdair::TRIP_TYPE_ONE_WAY);
184  const stdair::YieldFeaturesKey lYieldFeaturesKey (lTripType,
185  lCabinCode);
186  const stdair::YieldFeatures* lYieldFeatures_ptr = stdair::BomManager::
187  getObjectPtr<stdair::YieldFeatures> (iTimePeriod,
188  lYieldFeaturesKey.toString());
189  if (lYieldFeatures_ptr == NULL) {
190  STDAIR_LOG_ERROR ("Cannot find the yield features corresponding to "
191  << iTimePeriod.describeKey() << ", "
192  << lCabinCode << " and " << lTripType);
193  assert (false);
194  }
195 
196  // Browse the list of booking class and update the yield for each one.
197  const stdair::FareFamilyList_T& lFFlist = stdair::BomManager::
198  getList<stdair::FareFamily> (*lSegmentCabin_ptr);
199  for (stdair::FareFamilyList_T::const_iterator itFF = lFFlist.begin();
200  itFF != lFFlist.end(); ++itFF) {
201  const stdair::FareFamily* lFF_ptr = *itFF;
202  assert (lFF_ptr != NULL);
203 
204  const stdair::BookingClassList_T& lBCList = stdair::BomManager::
205  getList<stdair::BookingClass> (*lFF_ptr);
206  for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
207  itBC != lBCList.end(); ++itBC) {
208  stdair::BookingClass* lBookingClass_ptr = *itBC;
209  assert (lBookingClass_ptr != NULL);
210 
211  const stdair::ClassCode_T& lClassCode =
212  lBookingClass_ptr->getClassCode();
213  stdair::AirlineCodeList_T lAirlineCodeList;
214  lAirlineCodeList.push_back (iAirlineCode);
215  stdair::ClassList_StringList_T lClassList;
216  lClassList.push_back (lClassCode);
217  const stdair::AirlineClassListKey lACListKey (lAirlineCodeList,
218  lClassList);
219 
220  const stdair::AirlineClassList* lAirlineClassList_ptr = stdair::
221  BomManager::getObjectPtr<stdair::AirlineClassList> (*lYieldFeatures_ptr, lACListKey.toString());
222  if (lAirlineClassList_ptr != NULL) {
223  const stdair::Yield_T& lYield = lAirlineClassList_ptr->getYield();
224  lBookingClass_ptr->setYield (lYield);
225 
226  //DEBUG
227  STDAIR_LOG_DEBUG ("Update yield of " << lYield << " for "
228  << iAirlineCode << ", "
229  << iSegmentDate.describeKey() << ", "
230  << lBookingClass_ptr->describeKey());
231  }
232  }
233  }
234  }
235  }
236 }