$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 // StdAir 00007 #include <stdair/bom/BomRetriever.hpp> 00008 #include <stdair/bom/BomManager.hpp> 00009 #include <stdair/bom/Inventory.hpp> 00010 #include <stdair/bom/FlightDate.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/bom/TravelSolutionStruct.hpp> 00017 #include <stdair/service/Logger.hpp> 00018 #include <stdair/bom/LegCabin.hpp> 00019 // AirInv 00020 #include <airinv/bom/InventoryHelper.hpp> 00021 #include <airinv/bom/FlightDateHelper.hpp> 00022 #include <airinv/bom/SegmentSnapshotTableHelper.hpp> 00023 #include <airinv/bom/SegmentCabinHelper.hpp> 00024 00025 namespace AIRINV { 00026 00027 // //////////////////////////////////////////////////////////////////// 00028 void InventoryHelper::fillFromRouting (const stdair::Inventory& iInventory) { 00029 const stdair::FlightDateList_T& lFlightDateList = 00030 stdair::BomManager::getList<stdair::FlightDate> (iInventory); 00031 00032 // Browse the list of flight-dates and update each flight-date. 00033 for (stdair::FlightDateList_T::const_iterator itFlightDate = 00034 lFlightDateList.begin(); 00035 itFlightDate != lFlightDateList.end(); ++itFlightDate) { 00036 const stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate; 00037 assert (lCurrentFlightDate_ptr != NULL); 00038 FlightDateHelper::fillFromRouting (*lCurrentFlightDate_ptr); 00039 } 00040 } 00041 00042 // //////////////////////////////////////////////////////////////////// 00043 void InventoryHelper:: 00044 calculateAvailability (const stdair::Inventory& iInventory, 00045 const std::string& iFullSegmentDateKey, 00046 stdair::TravelSolutionStruct& ioTravelSolution) { 00047 00048 // Create the map of class/availability for the given segment date. 00049 stdair::ClassAvailabilityMap_T lClassAvailabilityMap; 00050 00051 // Create the map of class/object ID for the given segment date. 00052 stdair::ClassObjectIDMap_T lClassObjectIDMap; 00053 00054 // DEBUG 00055 STDAIR_LOG_DEBUG (iFullSegmentDateKey); 00056 // 00057 stdair::SegmentDate* lSegmentDate_ptr = 00058 stdair::BomRetriever::retrieveSegmentDateFromLongKey(iInventory, 00059 iFullSegmentDateKey); 00060 assert (lSegmentDate_ptr != NULL); 00061 00062 // Browse the segment-cabins and fill the map with the availability of 00063 // each booking class. 00064 const stdair::SegmentCabinList_T& lSegmentCabinList = 00065 stdair::BomManager::getList<stdair::SegmentCabin> (*lSegmentDate_ptr); 00066 for (stdair::SegmentCabinList_T::const_iterator itCabin = 00067 lSegmentCabinList.begin(); 00068 itCabin != lSegmentCabinList.end(); ++itCabin) { 00069 stdair::SegmentCabin* lSegmentCabin_ptr = *itCabin; 00070 assert (lSegmentCabin_ptr != NULL); 00071 00072 00073 // Compute the availability using the AU and the cumulative 00074 // booking counter. 00075 // SegmentCabinHelper::updateAvailabilities (*lSegmentCabin_ptr); 00076 const stdair::BookingClassList_T& lBCList = 00077 stdair::BomManager::getList<stdair::BookingClass> (*lSegmentCabin_ptr); 00078 for (stdair::BookingClassList_T::const_reverse_iterator itBC = 00079 lBCList.rbegin(); itBC != lBCList.rend(); ++itBC) { 00080 stdair::BookingClass* lBC_ptr = *itBC; 00081 assert (lBC_ptr != NULL); 00082 00083 const stdair::Availability_T lAvl = lBC_ptr->getSegmentAvailability(); 00084 00085 const stdair::ClassCode_T& lClassCode = lBC_ptr->getClassCode(); 00086 bool insertSuccessful = lClassAvailabilityMap. 00087 insert (stdair::ClassAvailabilityMap_T::value_type (lClassCode, 00088 lAvl)).second; 00089 assert (insertSuccessful == true); 00090 00091 stdair::BookingClassID_T lBCID (*lBC_ptr); 00092 insertSuccessful = lClassObjectIDMap. 00093 insert (stdair::ClassObjectIDMap_T::value_type (lClassCode, 00094 lBCID)).second; 00095 assert (insertSuccessful == true); 00096 } 00097 } 00098 00099 // 00100 ioTravelSolution.addClassAvailabilityMap (lClassAvailabilityMap); 00101 ioTravelSolution.addClassObjectIDMap (lClassObjectIDMap); 00102 } 00103 00104 00105 // //////////////////////////////////////////////////////////////////// 00106 void InventoryHelper:: 00107 getYieldAndBidPrice (const stdair::Inventory& iInventory, 00108 const std::string& iFullSegmentDateKey, 00109 stdair::TravelSolutionStruct& ioTravelSolution) { 00110 00111 // Create the map of class/availability for the given segment date. 00112 // stdair::ClassAvailabilityMap_T lClassAvailabilityMap; 00113 00114 stdair::ClassYieldMap_T lClassYieldMap; 00115 00116 stdair::ClassBpvMap_T lClassBpvMap; 00117 00118 // DEBUG 00119 STDAIR_LOG_DEBUG (iFullSegmentDateKey); 00120 // 00121 stdair::SegmentDate* lSegmentDate_ptr = 00122 stdair::BomRetriever::retrieveSegmentDateFromLongKey (iInventory, 00123 iFullSegmentDateKey); 00124 assert (lSegmentDate_ptr != NULL); 00125 00126 // Browse the segment-cabins and fill the maps with the bid price vector reference 00127 // and yield of each booking class. 00128 const stdair::SegmentCabinList_T& lSegmentCabinList = 00129 stdair::BomManager::getList<stdair::SegmentCabin> (*lSegmentDate_ptr); 00130 for (stdair::SegmentCabinList_T::const_iterator itCabin = 00131 lSegmentCabinList.begin(); 00132 itCabin != lSegmentCabinList.end(); ++itCabin) { 00133 stdair::SegmentCabin* lSegmentCabin_ptr = *itCabin; 00134 assert (lSegmentCabin_ptr != NULL); 00135 00136 stdair::BidPriceVector_T lBPV; 00137 00138 00139 //stdair::BidPriceVector_T lBPV; 00140 stdair::LegCabinList_T lLegCabinList = 00141 stdair::BomManager::getList<stdair::LegCabin> (*lSegmentCabin_ptr); 00142 assert (!lLegCabinList.empty()); 00143 if (lLegCabinList.size() > 1) { 00144 // Compute the sum of bid prices and return a vector containing that value. 00145 stdair::BidPrice_T lBidPriceValue = 0; 00146 for (stdair::LegCabinList_T::const_iterator itLC = lLegCabinList.begin(); 00147 itLC != lLegCabinList.end(); ++itLC) { 00148 const stdair::LegCabin* lLegCabin_ptr = *itLC; 00149 const stdair::BidPriceVector_T& lLegCabinBPV = lLegCabin_ptr->getBidPriceVector(); 00150 if (!lLegCabinBPV.empty()) { 00151 lBidPriceValue += lLegCabinBPV.back(); 00152 } else { 00153 // If the remaining capacity is zero (empty bid price vector) on one of the legs, 00154 // then the remaining capacity of the segment is also zero (return an empty bid price). 00155 lBidPriceValue = std::numeric_limits<stdair::BidPrice_T>::max(); 00156 break; 00157 } 00158 } 00159 if (lBidPriceValue < std::numeric_limits<stdair::BidPrice_T>::max()) { 00160 lBPV.push_back(lBidPriceValue); 00161 } 00162 00163 } else { 00164 const stdair::LegCabin* lLegCabin_ptr = lLegCabinList.front(); 00165 lBPV = lLegCabin_ptr->getBidPriceVector(); 00166 } 00167 00168 00169 // const stdair::CabinCapacity_T& lCabinCapacity = lSegmentCabin_ptr->getCapacity(); 00170 // const stdair::CommittedSpace_T& lCommittedSpace = lSegmentCabin_ptr->getCommittedSpace(); 00171 // assert (lCabinCapacity - lCommittedSpace > 0); 00172 // lBPV.resize(lCabinCapacity - lCommittedSpace); 00173 00174 const stdair::Availability_T& lAvailabilityPool = 00175 lSegmentCabin_ptr->getAvailabilityPool(); 00176 //assert (lAvailabilityPool > 0); 00177 00178 if (lAvailabilityPool < lBPV.size()) { 00179 lBPV.resize(lAvailabilityPool); 00180 } 00181 00182 00183 // 00184 ioTravelSolution.addBidPriceVector (lBPV); 00185 00186 const stdair::BidPriceVectorHolder_T& lBidPriceVectorHolder = 00187 ioTravelSolution.getBidPriceVectorHolder(); 00188 const stdair::BidPriceVectorHolder_T::const_reverse_iterator itBPV = 00189 lBidPriceVectorHolder.rbegin(); 00190 const stdair::BidPriceVector_T& lBpvRef = *itBPV; 00191 00192 const stdair::FareFamilyList_T& lFFList = 00193 stdair::BomManager::getList<stdair::FareFamily> (*lSegmentCabin_ptr); 00194 for (stdair::FareFamilyList_T::const_iterator itFF = lFFList.begin(); 00195 itFF != lFFList.end(); ++itFF) { 00196 const stdair::FareFamily* lFareFamily_ptr = *itFF; 00197 assert (lFareFamily_ptr != NULL); 00198 00199 const stdair::BookingClassList_T& lBCList = 00200 stdair::BomManager::getList<stdair::BookingClass> (*lFareFamily_ptr); 00201 for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin(); 00202 itBC != lBCList.end(); ++itBC) { 00203 const stdair::BookingClass* lBC_ptr = *itBC; 00204 assert (lBC_ptr != NULL); 00205 00206 const stdair::ClassCode_T& lClassCode = lBC_ptr->getClassCode(); 00207 00208 const stdair::YieldValue_T lYld = lBC_ptr->getYield() ; 00209 const bool insertYieldMapSuccessful = lClassYieldMap. 00210 insert (stdair::ClassYieldMap_T::value_type (lClassCode, 00211 lYld)).second; 00212 assert (insertYieldMapSuccessful == true); 00213 00214 const bool insertBpvMapSuccessful = lClassBpvMap. 00215 insert (stdair::ClassBpvMap_T::value_type (lClassCode, 00216 &lBpvRef)).second; 00217 assert (insertBpvMapSuccessful == true); 00218 00219 // DEBUG 00220 // STDAIR_LOG_DEBUG ("Class: " << lClassCode 00221 // << ", " << "Yield: " << lYld << ", " 00222 // << "Bid price: " << lBpvRef.back() << ", " 00223 // << "Remaining capacity: " 00224 // << lCabinCapacity - lCommittedSpace); 00225 00226 // 00227 stdair::BidPrice_T lBpvVal = std::numeric_limits<double>::max(); 00228 if (lBpvRef.empty() == false) { 00229 lBpvVal = lBpvRef.back(); 00230 } 00231 00232 //lBpvVal = boost::lexical_cast<std::string> (lBpvRef.back()); 00233 STDAIR_LOG_DEBUG ("Class: " << lClassCode 00234 << ", " << "Yield: " << lYld << ", " 00235 << "Bid price: " << lBpvVal << ", " 00236 << "Remaining capacity: " << lAvailabilityPool 00237 << " Segment date: " << iFullSegmentDateKey); 00238 } 00239 } 00240 } 00241 00242 // 00243 ioTravelSolution.addClassYieldMap (lClassYieldMap); 00244 ioTravelSolution.addClassBpvMap (lClassBpvMap); 00245 } 00246 00247 // //////////////////////////////////////////////////////////////////// 00248 bool InventoryHelper::sell (stdair::Inventory& ioInventory, 00249 const std::string& iFullSegmentDateKey, 00250 const stdair::ClassCode_T& iClassCode, 00251 const stdair::PartySize_T& iPartySize) { 00252 bool hasSaleBeenSuccessful = false; 00253 00254 // DEBUG 00255 STDAIR_LOG_DEBUG ("Full key: '" << iFullSegmentDateKey 00256 << "', " << iClassCode); 00257 00258 // 00259 stdair::BookingClass* lBookingClass_ptr = 00260 stdair::BomRetriever::retrieveBookingClassFromLongKey(ioInventory, 00261 iFullSegmentDateKey, 00262 iClassCode); 00263 00264 // DEBUG 00265 const std::string hasFoundBookingClassStr = 00266 (lBookingClass_ptr != NULL)?"Yes":"No"; 00267 STDAIR_LOG_DEBUG ("Found booking class? " << hasFoundBookingClassStr); 00268 00269 if (lBookingClass_ptr != NULL) { 00270 00271 // Register the sale in the class. 00272 hasSaleBeenSuccessful = 00273 InventoryHelper::sell (*lBookingClass_ptr, iPartySize); 00274 00275 return hasSaleBeenSuccessful; 00276 } 00277 00278 return hasSaleBeenSuccessful; 00279 } 00280 00281 // //////////////////////////////////////////////////////////////////// 00282 bool InventoryHelper::sell (const stdair::BookingClassID_T& iClassID, 00283 const stdair::PartySize_T& iPartySize) { 00284 00285 // 00286 stdair::BookingClass& lBookingClass = iClassID.getObject(); 00287 00288 // Register the sale in the class. 00289 const bool hasSaleBeenSuccessful = 00290 InventoryHelper::sell (lBookingClass, iPartySize); 00291 00292 return hasSaleBeenSuccessful; 00293 } 00294 00295 // //////////////////////////////////////////////////////////////////// 00296 bool InventoryHelper::sell (stdair::BookingClass& iBookingClass, 00297 const stdair::PartySize_T& iPartySize) { 00298 00299 // Register the sale in the class. 00300 iBookingClass.sell (iPartySize); 00301 00302 // 00303 stdair::FareFamily& lFareFamily = 00304 stdair::BomManager::getParent<stdair::FareFamily> (iBookingClass); 00305 00306 // 00307 stdair::SegmentCabin& lSegmentCabin = 00308 stdair::BomManager::getParent<stdair::SegmentCabin> (lFareFamily); 00309 00310 // 00311 stdair::SegmentDate& lSegmentDate = 00312 stdair::BomManager::getParent<stdair::SegmentDate, 00313 stdair::SegmentCabin> (lSegmentCabin); 00314 00315 // 00316 stdair::FlightDate& lFlightDate = 00317 stdair::BomManager::getParent<stdair::FlightDate, 00318 stdair::SegmentDate> (lSegmentDate); 00319 00320 // Update the commited space of the segment-cabins and the leg-cabins. 00321 SegmentCabinHelper::updateFromReservation (lFlightDate, lSegmentCabin, 00322 iPartySize); 00323 00324 return true; 00325 } 00326 00327 // //////////////////////////////////////////////////////////////////// 00328 bool InventoryHelper::cancel (stdair::Inventory& ioInventory, 00329 const std::string& iFullSegmentDateKey, 00330 const stdair::ClassCode_T& iClassCode, 00331 const stdair::PartySize_T& iPartySize) { 00332 bool hasCancellationBeenSuccessful = false; 00333 00334 // DEBUG 00335 STDAIR_LOG_DEBUG ("Full key: '" << iFullSegmentDateKey 00336 << "', " << iClassCode); 00337 00338 // 00339 stdair::BookingClass* lBookingClass_ptr = 00340 stdair::BomRetriever::retrieveBookingClassFromLongKey(ioInventory, 00341 iFullSegmentDateKey, 00342 iClassCode); 00343 00344 // DEBUG 00345 const std::string hasFoundBookingClassStr = 00346 (lBookingClass_ptr != NULL)?"Yes":"No"; 00347 STDAIR_LOG_DEBUG ("Found booking class? " << hasFoundBookingClassStr); 00348 00349 if (lBookingClass_ptr != NULL) { 00350 00351 // Register the cancellation in the class. 00352 hasCancellationBeenSuccessful = 00353 cancel (*lBookingClass_ptr, iPartySize); 00354 00355 return hasCancellationBeenSuccessful; 00356 } 00357 00358 return hasCancellationBeenSuccessful; 00359 } 00360 00361 // //////////////////////////////////////////////////////////////////// 00362 bool InventoryHelper::cancel (const stdair::BookingClassID_T& iClassID, 00363 const stdair::PartySize_T& iPartySize) { 00364 00365 stdair::BookingClass& lBookingClass = iClassID.getObject(); 00366 00367 // Register the cancellation in the class. 00368 const bool hasCancellationBeenSuccessful = 00369 cancel (lBookingClass, iPartySize); 00370 00371 return hasCancellationBeenSuccessful; 00372 } 00373 00374 // //////////////////////////////////////////////////////////////////// 00375 bool InventoryHelper::cancel (stdair::BookingClass& iBookingClass, 00376 const stdair::PartySize_T& iPartySize) { 00377 00378 // Register the cancellation in the class. 00379 iBookingClass.cancel (iPartySize); 00380 00381 // 00382 stdair::FareFamily& lFareFamily = 00383 stdair::BomManager::getParent<stdair::FareFamily> (iBookingClass); 00384 00385 // 00386 stdair::SegmentCabin& lSegmentCabin = 00387 stdair::BomManager::getParent<stdair::SegmentCabin> (lFareFamily); 00388 00389 // 00390 stdair::SegmentDate& lSegmentDate = 00391 stdair::BomManager::getParent<stdair::SegmentDate, 00392 stdair::SegmentCabin> (lSegmentCabin); 00393 00394 // 00395 stdair::FlightDate& lFlightDate = 00396 stdair::BomManager::getParent<stdair::FlightDate, 00397 stdair::SegmentDate> (lSegmentDate); 00398 00399 // Update the commited space of the segment-cabins and the leg-cabins. 00400 SegmentCabinHelper::updateFromReservation (lFlightDate, lSegmentCabin, 00401 -iPartySize); 00402 00403 return true; 00404 } 00405 00406 // //////////////////////////////////////////////////////////////////// 00407 void InventoryHelper::takeSnapshots(const stdair::Inventory& iInventory, 00408 const stdair::DateTime_T& iSnapshotTime) { 00409 // Browse the guillotine block list and take the snapshots for 00410 // each guillotine. 00411 const stdair::SegmentSnapshotTableList_T& lSegmentSnapshotTableList = 00412 stdair::BomManager::getList<stdair::SegmentSnapshotTable> (iInventory); 00413 for (stdair::SegmentSnapshotTableList_T::const_iterator itGB = 00414 lSegmentSnapshotTableList.begin(); 00415 itGB != lSegmentSnapshotTableList.end(); ++itGB) { 00416 stdair::SegmentSnapshotTable* lSegmentSnapshotTable_ptr = *itGB; 00417 00418 SegmentSnapshotTableHelper::takeSnapshots(*lSegmentSnapshotTable_ptr, 00419 iSnapshotTime); 00420 } 00421 } 00422 }