AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
SegmentCabinHelper.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // StdAir
00008 #include <stdair/bom/BomManager.hpp>
00009 #include <stdair/bom/FlightDate.hpp>
00010 #include <stdair/bom/LegCabin.hpp>
00011 #include <stdair/bom/SegmentCabin.hpp>
00012 #include <stdair/bom/FareFamily.hpp>
00013 #include <stdair/bom/BookingClass.hpp>
00014 // AirInv
00015 #include <airinv/bom/SegmentCabinHelper.hpp>
00016 #include <airinv/bom/FlightDateHelper.hpp>
00017 
00018 namespace AIRINV {
00019 
00020   // ////////////////////////////////////////////////////////////////////
00021   void SegmentCabinHelper::initialiseAU (stdair::SegmentCabin& iSegmentCabin) {
00022 
00023     // Initialise the capacity and availability pool.
00024     const stdair::LegCabinList_T& lLCList =
00025       stdair::BomManager::getList<stdair::LegCabin> (iSegmentCabin);
00026 
00027     stdair::CabinCapacity_T lCapacity =
00028       std::numeric_limits<stdair::CabinCapacity_T>::max();
00029     for (stdair::LegCabinList_T::const_iterator itLC = lLCList.begin();
00030          itLC != lLCList.end(); ++itLC) {
00031 
00032       const stdair::LegCabin* lLC_ptr = *itLC;
00033       assert (lLC_ptr != NULL);
00034 
00035       const stdair::CabinCapacity_T& lCabinCap = lLC_ptr->getOfferedCapacity();
00036       if (lCapacity > lCabinCap) {
00037         lCapacity = lCabinCap;
00038       }
00039     }
00040     iSegmentCabin.setCapacity (lCapacity);
00041     iSegmentCabin.setAvailabilityPool (lCapacity);
00042     
00043     // Browse the list of booking classes and set the AU of each booking
00044     // class to the availability pool of the cabin.
00045     const stdair::BookingClassList_T& lBCList =
00046       stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
00047     for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
00048          itBC != lBCList.end(); ++itBC) {
00049       stdair::BookingClass* lBC_ptr = *itBC;
00050       assert (lBC_ptr != NULL);
00051       lBC_ptr->setAuthorizationLevel (lCapacity);
00052     }
00053   }
00054   
00055   // ////////////////////////////////////////////////////////////////////
00056   void SegmentCabinHelper::
00057   updateFromReservation (const stdair::FlightDate& iFlightDate,
00058                          stdair::SegmentCabin& ioSegmentCabin,
00059                          const stdair::PartySize_T& iNbOfBookings){
00060     // Update the commited space of the segment-cabin.
00061     ioSegmentCabin.updateFromReservation (iNbOfBookings);
00062 
00063     // Update the commited space of the member leg-cabins.
00064     const stdair::LegCabinList_T& lLegCabinList =
00065       stdair::BomManager::getList<stdair::LegCabin> (ioSegmentCabin);
00066     for (stdair::LegCabinList_T::const_iterator itLegCabin =
00067            lLegCabinList.begin();
00068          itLegCabin != lLegCabinList.end(); ++itLegCabin) {
00069       stdair::LegCabin* lLegCabin_ptr = *itLegCabin;
00070       assert (lLegCabin_ptr != NULL);
00071       lLegCabin_ptr->updateFromReservation (iNbOfBookings);
00072     }
00073 
00074     // Update the availability pool of all the segment-cabin which belong to the
00075     // same flight-date.
00076     const stdair::CabinCode_T& lCabinCode = ioSegmentCabin.getCabinCode();
00077     FlightDateHelper::updateAvailablityPool (iFlightDate, lCabinCode);
00078   }
00079 
00080   // ////////////////////////////////////////////////////////////////////
00081   void SegmentCabinHelper::
00082   buildPseudoBidPriceVector (stdair::SegmentCabin& ioSegmentCabin) {
00083     // Retrieve the segment-cabin capacity.
00084     const stdair::Availability_T& lAvlPool=ioSegmentCabin.getAvailabilityPool();
00085     const unsigned int lAvlPoolInt =
00086       static_cast<unsigned int> (lAvlPool);
00087     stdair::BidPriceVector_T lPseudoBidPriceVector (lAvlPoolInt, 0.0);
00088 
00089     // Browse the leg-cabin list.
00090     const stdair::LegCabinList_T& lLCList =
00091       stdair::BomManager::getList<stdair::LegCabin> (ioSegmentCabin);
00092     for (stdair::LegCabinList_T::const_iterator itLC = lLCList.begin();
00093          itLC != lLCList.end(); ++itLC) {
00094       const stdair::LegCabin* lLC_ptr = *itLC;
00095       assert (lLC_ptr != NULL);
00096 
00097       const stdair::BidPriceVector_T& lBPV = lLC_ptr->getBidPriceVector();
00098       stdair::BidPriceVector_T::const_reverse_iterator itBP = lBPV.rbegin();
00099       for (stdair::BidPriceVector_T::reverse_iterator itPBP =
00100              lPseudoBidPriceVector.rbegin();
00101            itPBP != lPseudoBidPriceVector.rend(); ++itPBP, ++itBP) {
00102         assert (itBP != lBPV.rend());
00103         stdair::BidPrice_T& lCurrentPBP = *itPBP;
00104         const stdair::BidPrice_T& lCurrentBP = *itBP;
00105         lCurrentPBP += lCurrentBP;
00106       }
00107     }
00108 
00109     ioSegmentCabin.setBidPriceVector (lPseudoBidPriceVector);
00110     
00111     // // DEBUG
00112     // std::ostringstream ostr;
00113     // ostr << "Pseudo BPV: ";
00114     // for (stdair::BidPriceVector_T::const_iterator itBP =
00115     //       lPseudoBidPriceVector.begin(); itBP != lPseudoBidPriceVector.end();
00116     //      ++itBP) {
00117     //   const stdair::BidPrice_T& lCurrentBP = *itBP;      
00118     //   ostr << lCurrentBP << " ";
00119     // }
00120     // //    STDAIR_LOG_DEBUG (ostr.str());
00121     // std::cout << ostr.str() << std::endl;
00122   }
00123 
00124   // ////////////////////////////////////////////////////////////////////
00125   void SegmentCabinHelper::
00126   updateBookingControlsUsingPseudoBidPriceVector (const stdair::SegmentCabin& iSegmentCabin) {
00127     // Retrieve the pseudo bid price vector.
00128     const stdair::BidPriceVector_T& lPseudoBPV =
00129       iSegmentCabin.getBidPriceVector();
00130     const stdair::Availability_T& lAvlPool=iSegmentCabin.getAvailabilityPool();
00131     
00132     // Update the cumulative booking limit for all booking classes.
00133     const stdair::BookingClassList_T& lBCList =
00134       stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
00135     for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
00136          itBC != lBCList.end(); ++itBC) {
00137       stdair::BookingClass* lBC_ptr = *itBC;
00138       assert (lBC_ptr != NULL);
00139 
00140       lBC_ptr->setCumulatedBookingLimit (lAvlPool);
00141       const stdair::Yield_T& lYield = lBC_ptr->getYield();
00142       for (stdair::BidPriceVector_T::const_reverse_iterator itBP =
00143              lPseudoBPV.rbegin(); itBP != lPseudoBPV.rend(); ++itBP) {
00144         const stdair::BidPrice_T& lBP = *itBP;
00145         if (lYield < lBP) {
00146           stdair::BookingLimit_T lCumuBL = itBP - lPseudoBPV.rbegin();
00147           lBC_ptr->setCumulatedBookingLimit (lCumuBL);
00148           break;
00149         }
00150       }
00151     }
00152 
00153     // Update the authorization levels from the booking limits
00154     updateAUs (iSegmentCabin);
00155   }
00156 
00157   // ////////////////////////////////////////////////////////////////////
00158   void SegmentCabinHelper::updateAUs(const stdair::SegmentCabin& iSegmentCabin){
00159     // Browse the booking class list and compute the AU from the
00160     // cumulative booking counter and the cumulative booking limit.
00161     stdair::NbOfBookings_T lCumulativeBookingCounter = 0.0;
00162     const stdair::BookingClassList_T& lBCList =
00163       stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
00164     for (stdair::BookingClassList_T::const_reverse_iterator itBC =
00165            lBCList.rbegin(); itBC != lBCList.rend(); ++itBC) {
00166       stdair::BookingClass* lBC_ptr = *itBC;
00167       assert (lBC_ptr != NULL);
00168 
00169       const stdair::NbOfBookings_T& lNbOfBookings = lBC_ptr->getNbOfBookings();
00170       lCumulativeBookingCounter += lNbOfBookings;
00171 
00172       const stdair::BookingLimit_T& lCumuBookingLimit =
00173         lBC_ptr->getCumulatedBookingLimit();
00174 
00175       stdair::AuthorizationLevel_T lAU =
00176         lCumulativeBookingCounter + lCumuBookingLimit;
00177       lBC_ptr->setAuthorizationLevel (lAU);
00178 
00179       // DEBUG
00180       // STDAIR_LOG_DEBUG ("Updating the AU for class: "
00181       //                   << lBC_ptr->describeKey()
00182       //                   << ", with BL: " << lCumuBookingLimit
00183       //                   << ", CumuBkg: " << lCumulativeBookingCounter
00184       //                   << ", AU: " << lAU);
00185     }
00186   }
00187 
00188   // ////////////////////////////////////////////////////////////////////
00189   void SegmentCabinHelper::
00190   updateAvailabilities (const stdair::SegmentCabin& iSegmentCabin) {
00191     // Browse the booking class list and compute the avl from the
00192     // cumulative booking counter and the AU.
00193     stdair::NbOfBookings_T lCumulativeBookingCounter = 0.0;
00194     const stdair::BookingClassList_T& lBCList =
00195       stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
00196     for (stdair::BookingClassList_T::const_reverse_iterator itBC =
00197            lBCList.rbegin(); itBC != lBCList.rend(); ++itBC) {
00198       stdair::BookingClass* lBC_ptr = *itBC;
00199       assert (lBC_ptr != NULL);
00200 
00201       const stdair::NbOfBookings_T& lNbOfBookings = lBC_ptr->getNbOfBookings();
00202       lCumulativeBookingCounter += lNbOfBookings;
00203 
00204       const stdair::AuthorizationLevel_T& lAU=lBC_ptr->getAuthorizationLevel();
00205 
00206       const stdair::Availability_T lAvl = lAU - lCumulativeBookingCounter;
00207       lBC_ptr->setSegmentAvailability (lAvl);
00208     }
00209   }
00210 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines