$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 #include <cmath> 00007 // StdAir 00008 #include <stdair/basic/BasConst_Inventory.hpp> 00009 #include <stdair/bom/BomRetriever.hpp> 00010 #include <stdair/bom/BomManager.hpp> 00011 #include <stdair/bom/SegmentDate.hpp> 00012 #include <stdair/bom/SegmentCabin.hpp> 00013 #include <stdair/bom/FareFamily.hpp> 00014 #include <stdair/bom/BookingClass.hpp> 00015 #include <stdair/bom/SegmentSnapshotTable.hpp> 00016 #include <stdair/service/Logger.hpp> 00017 // AirInv 00018 #include <airinv/basic/BasConst_Curves.hpp> 00019 #include <airinv/bom/SegmentSnapshotTableHelper.hpp> 00020 #include <airinv/bom/FlightDateHelper.hpp> 00021 #include <airinv/bom/SegmentCabinHelper.hpp> 00022 00023 namespace AIRINV { 00024 00025 // //////////////////////////////////////////////////////////////////// 00026 void SegmentSnapshotTableHelper:: 00027 takeSnapshots (stdair::SegmentSnapshotTable& ioSegmentSnapshotTable, 00028 const stdair::DateTime_T& iSnapshotTime) { 00029 // Retrieve the segment-cabin index and take the snapshots for 00030 // each segment-cabin. 00031 const stdair::SegmentCabinIndexMap_T& lSegmentCabinIndexMap = 00032 ioSegmentSnapshotTable.getSegmentCabinIndexMap(); 00033 for (stdair::SegmentCabinIndexMap_T::const_iterator itSCIdx = 00034 lSegmentCabinIndexMap.begin(); 00035 itSCIdx != lSegmentCabinIndexMap.end(); ++itSCIdx) { 00036 const stdair::SegmentCabin* lSC_ptr = itSCIdx->first; 00037 assert (lSC_ptr != NULL); 00038 const stdair::SegmentDataID_T& lSCIdx = itSCIdx->second; 00039 00040 const stdair::Date_T& lSnapshotDate = iSnapshotTime.date(); 00041 00042 // Compare the date of the snapshot time and the departure date of 00043 // the segment-cabin in order to verify the necescity of taking snapshots. 00044 const stdair::SegmentDate& lSegmentDate = 00045 stdair::BomManager::getParent<stdair::SegmentDate> (*lSC_ptr); 00046 const stdair::Date_T& lDepartureDate = lSegmentDate.getBoardingDate(); 00047 const stdair::DateOffset_T lDateOffset = lDepartureDate - lSnapshotDate; 00048 const stdair::DTD_T lDTD = lDateOffset.days() + 1; 00049 00050 if (lDTD >= 0 && lDTD <= stdair::DEFAULT_MAX_DTD) { 00051 SegmentCabinHelper::updateAvailabilities (*lSC_ptr); 00052 takeSnapshots (ioSegmentSnapshotTable, lDTD, *lSC_ptr, lSCIdx); 00053 registerProductAndPriceOrientedBookings (ioSegmentSnapshotTable, 00054 lDTD, *lSC_ptr, lSCIdx); 00055 } 00056 } 00057 } 00058 00059 // //////////////////////////////////////////////////////////////////// 00060 void SegmentSnapshotTableHelper:: 00061 takeSnapshots (stdair::SegmentSnapshotTable& ioSegmentSnapshotTable, 00062 const stdair::DTD_T& iDTD, 00063 const stdair::SegmentCabin& iSegmentCabin, 00064 const stdair::SegmentDataID_T iSegmentCabinIdx) { 00065 00066 // Extract the views for the corresponding DTD and segment-cabin. 00067 stdair::SegmentCabinDTDSnapshotView_T lBookingView = ioSegmentSnapshotTable. 00068 getSegmentCabinDTDBookingSnapshotView (iSegmentCabinIdx, 00069 iSegmentCabinIdx, iDTD); 00070 stdair::SegmentCabinDTDSnapshotView_T lCancellationView = ioSegmentSnapshotTable. 00071 getSegmentCabinDTDCancellationSnapshotView (iSegmentCabinIdx, 00072 iSegmentCabinIdx, iDTD); 00073 stdair::SegmentCabinDTDSnapshotView_T lAvailabilityView = ioSegmentSnapshotTable. 00074 getSegmentCabinDTDAvailabilitySnapshotView (iSegmentCabinIdx, 00075 iSegmentCabinIdx, iDTD); 00076 00077 // Retrieve the block index of the segment-cabin. 00078 std::ostringstream lSCMapKey; 00079 lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE 00080 << iSegmentCabin.describeKey(); 00081 const stdair::ClassIndex_T& lCabinIdx = 00082 ioSegmentSnapshotTable.getClassIndex (lSCMapKey.str()); 00083 lAvailabilityView[lCabinIdx] = iSegmentCabin.getAvailabilityPool(); 00084 lBookingView[lCabinIdx] = iSegmentCabin.getCommittedSpace(); 00085 00086 00087 // Browse the booking class list 00088 const stdair::BookingClassList_T& lBCList = 00089 stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin); 00090 for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin(); 00091 itBC != lBCList.end(); ++itBC) { 00092 const stdair::BookingClass* lBookingClass_ptr = *itBC; 00093 assert (lBookingClass_ptr != NULL); 00094 00095 // Retrieve the block index of the booking class. 00096 const stdair::ClassIndex_T& lIdx = 00097 ioSegmentSnapshotTable.getClassIndex (lBookingClass_ptr->describeKey()); 00098 00099 // DEBUG 00100 // STDAIR_LOG_DEBUG ("Taking snapshot for " 00101 // << iSegmentCabin.describeKey() << ", " 00102 // << lBookingClass_ptr->describeKey() 00103 // << ", DTD: " << iDTD << ", nb of bookings: " 00104 // << lBookingClass_ptr->getNbOfBookings()); 00105 00106 // Write the snapshot. 00107 lBookingView[lIdx]=lBookingClass_ptr->getNbOfBookings(); 00108 lCancellationView[lIdx] = 00109 lBookingClass_ptr->getNbOfCancellations(); 00110 lAvailabilityView[lIdx] = 00111 lBookingClass_ptr->getSegmentAvailability(); 00112 } 00113 } 00114 00115 // //////////////////////////////////////////////////////////////////// 00116 void SegmentSnapshotTableHelper::registerProductAndPriceOrientedBookings 00117 (stdair::SegmentSnapshotTable& ioSegmentSnapshotTable, const stdair::DTD_T& iDTD, 00118 const stdair::SegmentCabin& iSegmentCabin, 00119 const stdair::SegmentDataID_T iSegmentCabinIdx) { 00120 00121 // Extract the views for the corresponding DTD and segment-cabin. 00122 stdair::SegmentCabinDTDRangeSnapshotView_T lRangeBookingView = 00123 ioSegmentSnapshotTable.getSegmentCabinDTDRangeBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD, iDTD + 1); 00124 stdair::SegmentCabinDTDRangeSnapshotView_T lRangeCancellationView = 00125 ioSegmentSnapshotTable.getSegmentCabinDTDRangeCancellationSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD, iDTD + 1); 00126 stdair::SegmentCabinDTDSnapshotView_T lProductOrientedGrossBookingView = 00127 ioSegmentSnapshotTable.getSegmentCabinDTDProductOrientedGrossBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD); 00128 stdair::SegmentCabinDTDSnapshotView_T lPriceOrientedGrossBookingView = 00129 ioSegmentSnapshotTable.getSegmentCabinDTDPriceOrientedGrossBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD); 00130 stdair::SegmentCabinDTDSnapshotView_T lProductOrientedNetBookingView = 00131 ioSegmentSnapshotTable.getSegmentCabinDTDProductOrientedNetBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD); 00132 stdair::SegmentCabinDTDSnapshotView_T lPriceOrientedNetBookingView = 00133 ioSegmentSnapshotTable.getSegmentCabinDTDPriceOrientedNetBookingSnapshotView (iSegmentCabinIdx, iSegmentCabinIdx, iDTD); 00134 00135 // Retrieve the lowest yield and the lowest class and treat the number of gross 00136 // bookings of this class the price oriented bookings. 00137 const stdair::BookingClassList_T& lBCList = 00138 stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin); 00139 stdair::BookingClassList_T::const_iterator iterBC = lBCList.begin(); 00140 assert (iterBC != lBCList.end()); 00141 stdair::BookingClass* lLowestClass_ptr = *iterBC; 00142 assert (lLowestClass_ptr != NULL); 00143 stdair::Yield_T lLowestYield = lLowestClass_ptr->getYield(); 00144 for (; iterBC != lBCList.end(); iterBC++) { 00145 const stdair::BookingClass* lBookingClass_ptr = *iterBC; 00146 assert (lBookingClass_ptr != NULL); 00147 const stdair::Yield_T& lYield = lBookingClass_ptr->getYield(); 00148 if (lYield < lLowestYield) { 00149 lLowestYield = lYield; 00150 lLowestClass_ptr = *iterBC; 00151 } 00152 } 00153 assert (lLowestClass_ptr != NULL); 00154 00155 // Retrieve the block index of the booking class. 00156 const stdair::ClassIndex_T& lClassIdx = 00157 ioSegmentSnapshotTable.getClassIndex (lLowestClass_ptr->describeKey()); 00158 00159 // Compute the number of gross bookings for this class. 00160 const stdair::NbOfBookings_T lNbOfNetBkgs = 00161 lRangeBookingView[lClassIdx][0] - lRangeBookingView[lClassIdx][1]; 00162 const stdair::NbOfCancellations_T lNbOfCx = 00163 lRangeCancellationView[lClassIdx][0]-lRangeCancellationView[lClassIdx][1]; 00164 const stdair::NbOfBookings_T lNbOfGrossBkgs = lNbOfNetBkgs + lNbOfCx; 00165 00166 // Write these numbern of bookings to the price-oriented value. 00167 lPriceOrientedGrossBookingView[lClassIdx] = lNbOfGrossBkgs; 00168 lPriceOrientedNetBookingView[lClassIdx] = lNbOfNetBkgs; 00169 00170 // Boolean for "no lower class available" verification. 00171 bool noLowerClassAvl = true; 00172 if (lLowestClass_ptr->getSegmentAvailability() >= 1.0) { 00173 noLowerClassAvl = false; 00174 } 00175 00176 // Browse the booking class list 00177 stdair::BookingClassList_T::const_reverse_iterator itBC = lBCList.rbegin(); 00178 for (; itBC != lBCList.rend(); itBC++) { 00179 const stdair::BookingClass* lBookingClass_ptr = *itBC; 00180 assert (lBookingClass_ptr != NULL); 00181 00182 // Retrieve the yield of the this class. 00183 const stdair::Yield_T& lYield = lBookingClass_ptr->getYield(); 00184 assert (lYield >= lLowestYield); 00185 if (lYield > lLowestYield) { 00186 00187 // Retrieve the block index of the booking class. 00188 const stdair::ClassIndex_T& lIdx = 00189 ioSegmentSnapshotTable.getClassIndex (lBookingClass_ptr->describeKey()); 00190 00191 // Compute the number of gross bookings for this class. 00192 const stdair::NbOfBookings_T lNetBkgs = 00193 lRangeBookingView[lIdx][0] - lRangeBookingView[lIdx][1]; 00194 const stdair::NbOfCancellations_T lCx = 00195 lRangeCancellationView[lIdx][0] - lRangeCancellationView[lIdx][1]; 00196 const stdair::NbOfBookings_T lGrossBkgs = lNetBkgs + lCx; 00197 00198 // If there is a lower class available, these gross bookings 00199 // will be considered product-oriented. Otherwise, they will be 00200 // considered price-oriented 00201 if (noLowerClassAvl == false) { 00202 lProductOrientedGrossBookingView[lIdx] = lGrossBkgs; 00203 lProductOrientedNetBookingView[lIdx] = lNetBkgs; 00204 } else { 00205 lPriceOrientedGrossBookingView[lIdx] = lGrossBkgs; 00206 lPriceOrientedNetBookingView[lIdx] = lNetBkgs; 00207 00208 if (lBookingClass_ptr->getSegmentAvailability() >= 1.0) { 00209 noLowerClassAvl = false; 00210 } 00211 } 00212 } 00213 } 00214 } 00215 00216 }