AirRAC Logo  0.2.0
C++ Simulated Revenue Accounting (RAC) System Library
YieldManager.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // StdAir
00007 #include <stdair/basic/BasConst_Request.hpp>
00008 #include <stdair/bom/BomManager.hpp>
00009 #include <stdair/bom/BomRoot.hpp>
00010 #include <stdair/bom/Inventory.hpp>
00011 #include <stdair/bom/FlightDate.hpp>
00012 #include <stdair/bom/SegmentDate.hpp>
00013 #include <stdair/bom/SegmentCabin.hpp>
00014 #include <stdair/bom/FareFamily.hpp>
00015 #include <stdair/bom/BookingClass.hpp>
00016 #include <stdair/bom/TravelSolutionStruct.hpp>
00017 #include <stdair/bom/AirportPair.hpp>
00018 #include <stdair/bom/PosChannel.hpp>
00019 #include <stdair/bom/DatePeriod.hpp>
00020 #include <stdair/bom/TimePeriod.hpp>
00021 #include <stdair/bom/YieldFeatures.hpp>
00022 #include <stdair/bom/AirlineClassList.hpp>
00023 #include <stdair/factory/FacBomManager.hpp>
00024 #include <stdair/service/Logger.hpp>
00025 // Airrac
00026 #include <airrac/AIRRAC_Types.hpp>
00027 #include <airrac/command/YieldManager.hpp>
00028 
00029 namespace AIRRAC {
00030 
00031   // ////////////////////////////////////////////////////////////////////
00032   YieldManager::YieldManager() {
00033     assert (false);
00034   }
00035 
00036   // ////////////////////////////////////////////////////////////////////
00037   YieldManager::YieldManager (const YieldManager&) {
00038     assert (false);
00039   }
00040 
00041   // ////////////////////////////////////////////////////////////////////
00042   YieldManager::~YieldManager() {
00043   }
00044 
00045   // ////////////////////////////////////////////////////////////////////
00046   void YieldManager::
00047   calculateYield (stdair::TravelSolutionList_T& ioTravelSolutionList,
00048                   const stdair::BomRoot& iBomRoot) {
00049 
00050     // Browse the list of TravelSolution structures
00051     for (stdair::TravelSolutionList_T::iterator itTravelSolution =
00052            ioTravelSolutionList.begin();
00053          itTravelSolution != ioTravelSolutionList.end(); ++itTravelSolution) {
00054       stdair::TravelSolutionStruct& lTravelSolution = *itTravelSolution;
00055       
00056       //
00057       YieldManager::calculateYield (lTravelSolution, iBomRoot);
00058     }
00059   }
00060 
00061   // ////////////////////////////////////////////////////////////////////
00062   void YieldManager::
00063   calculateYield (stdair::TravelSolutionStruct& ioTravelSolution,
00064                   const stdair::BomRoot& iBomRoot) {
00065 
00066     // Calculate/retrieve the yield for the given travel solution
00067     //YieldStore::calculateYield (ioYield, ioTravelSolution);
00068 
00069     // TODO: update the statistical attributes of the yield.
00070   }
00071 
00072   // ////////////////////////////////////////////////////////////////////
00073   void YieldManager::updateYields (const stdair::BomRoot& iBomRoot) {
00074     // Browse the list of booking classes and update yield for each one.
00075     const stdair::InventoryList_T lInvList =
00076       stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
00077     for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
00078          itInv != lInvList.end(); ++itInv) {
00079       const stdair::Inventory* lInv_ptr = *itInv;
00080       assert (lInv_ptr != NULL);
00081 
00082       // Retrieve the airline code.
00083       const stdair::AirlineCode_T& lAirlineCode = lInv_ptr->getAirlineCode();
00084 
00085       //
00086       const stdair::FlightDateList_T& lFDList =
00087         stdair::BomManager::getList<stdair::FlightDate> (*lInv_ptr);
00088       for (stdair::FlightDateList_T::const_iterator itFD = lFDList.begin();
00089            itFD != lFDList.end(); ++itFD) {
00090         const stdair::FlightDate* lFD_ptr = *itFD;
00091         assert (lFD_ptr != NULL);
00092 
00093         //
00094         const stdair::SegmentDateList_T& lSDList =
00095           stdair::BomManager::getList<stdair::SegmentDate> (*lFD_ptr);
00096         for (stdair::SegmentDateList_T::const_iterator itSD = lSDList.begin();
00097              itSD != lSDList.end(); ++itSD) {
00098           const stdair::SegmentDate* lSD_ptr = *itSD;
00099           assert (lSD_ptr != NULL);
00100 
00101           // Retrieve the origin and the destination
00102           const stdair::AirportCode_T& lOrigin = lSD_ptr->getBoardingPoint();
00103           const stdair::AirportCode_T& lDestination = lSD_ptr->getOffPoint();
00104 
00105           // Retrieve the airport pair in the yield structure.
00106           const stdair::AirportPairKey lAirportPairKey (lOrigin, lDestination);
00107           stdair::AirportPair* lAirportPair_ptr = stdair::BomManager::
00108             getObjectPtr<stdair::AirportPair> (iBomRoot,
00109                                                lAirportPairKey.toString());
00110           if (lAirportPair_ptr == NULL) {
00111             STDAIR_LOG_ERROR ("Cannot find yield corresponding to the airport "
00112                               << "pair: " << lAirportPairKey.toString());
00113             assert (false);
00114           }
00115 
00116           // Retrieve the boarding date and time
00117           const stdair::Date_T& lDate = lSD_ptr->getBoardingDate();
00118           const stdair::Duration_T& lTime = lSD_ptr->getBoardingTime();
00119 
00120           // Retrieve the corresponding date period.
00121           const stdair::DatePeriodList_T& lDatePeriodList =
00122             stdair::BomManager::getList<stdair::DatePeriod> (*lAirportPair_ptr);
00123           for (stdair::DatePeriodList_T::const_iterator itDatePeriod =
00124                  lDatePeriodList.begin();
00125                itDatePeriod != lDatePeriodList.end(); ++itDatePeriod) {
00126             const stdair::DatePeriod* lDatePeriod_ptr = *itDatePeriod;
00127             assert (lDatePeriod_ptr != NULL);
00128 
00129             const bool isDepartureDateValid =
00130               lDatePeriod_ptr->isDepartureDateValid (lDate);
00131 
00132             if (isDepartureDateValid == true) {
00133 
00134               // Retrieve the PoS-Channel.
00135               const stdair::PosChannelKey lPosChannelKey (stdair::DEFAULT_POS,
00136                                                           stdair::DEFAULT_CHANNEL);
00137               stdair::PosChannel* lPosChannel_ptr = stdair::BomManager::
00138                 getObjectPtr<stdair::PosChannel> (*lDatePeriod_ptr,
00139                                                   lPosChannelKey.toString());
00140               if (lPosChannel_ptr == NULL) {
00141                 STDAIR_LOG_ERROR ("Cannot find yield corresponding to the PoS-"
00142                                   << "Channel: " << lPosChannelKey.toString());
00143                 assert (false);
00144               }
00145               
00146               // Retrieve the corresponding time period.
00147               const stdair::TimePeriodList_T& lTimePeriodList = stdair::
00148                 BomManager::getList<stdair::TimePeriod> (*lPosChannel_ptr);
00149               for (stdair::TimePeriodList_T::const_iterator itTimePeriod =
00150                      lTimePeriodList.begin();
00151                    itTimePeriod != lTimePeriodList.end(); ++itTimePeriod) {
00152                 const stdair::TimePeriod* lTimePeriod_ptr = *itTimePeriod;
00153                 assert (lTimePeriod_ptr != NULL);
00154 
00155                 const bool isDepartureTimeValid =
00156                   lTimePeriod_ptr->isDepartureTimeValid (lTime);
00157 
00158                 if (isDepartureTimeValid == true) {
00159                   updateYields (*lSD_ptr, *lTimePeriod_ptr, lAirlineCode);
00160                 }
00161               }
00162             }
00163           }
00164         }
00165       }
00166     }
00167   }
00168 
00169   // ////////////////////////////////////////////////////////////////////
00170   void YieldManager::updateYields (const stdair::SegmentDate& iSegmentDate,
00171                                    const stdair::TimePeriod& iTimePeriod,
00172                                    const stdair::AirlineCode_T& iAirlineCode) {
00173     // Browse the segment-cabin list and retrieve the corresponding
00174     // yield features.
00175     const stdair::SegmentCabinList_T& lSegmentCabinList =
00176       stdair::BomManager::getList<stdair::SegmentCabin> (iSegmentDate);
00177     for (stdair::SegmentCabinList_T::const_iterator itSC =
00178            lSegmentCabinList.begin(); itSC != lSegmentCabinList.end(); ++itSC) {
00179       const stdair::SegmentCabin* lSegmentCabin_ptr = *itSC;
00180       assert (lSegmentCabin_ptr != NULL);
00181 
00182       const stdair::CabinCode_T& lCabinCode = lSegmentCabin_ptr->getCabinCode();
00183       const stdair::TripType_T lTripType (stdair::TRIP_TYPE_ONE_WAY);
00184       const stdair::YieldFeaturesKey lYieldFeaturesKey (lTripType,
00185                                                         lCabinCode);
00186       const stdair::YieldFeatures* lYieldFeatures_ptr = stdair::BomManager::
00187         getObjectPtr<stdair::YieldFeatures> (iTimePeriod,
00188                                              lYieldFeaturesKey.toString());
00189       if (lYieldFeatures_ptr == NULL) {
00190         STDAIR_LOG_ERROR ("Cannot find the yield features corresponding to "
00191                           << iTimePeriod.describeKey() << ", "
00192                           << lCabinCode << " and " << lTripType);
00193         assert (false);
00194       }
00195 
00196       // Browse the list of booking class and update the yield for each one.
00197       const stdair::FareFamilyList_T& lFFlist = stdair::BomManager::
00198         getList<stdair::FareFamily> (*lSegmentCabin_ptr);
00199       for (stdair::FareFamilyList_T::const_iterator itFF = lFFlist.begin();
00200            itFF != lFFlist.end(); ++itFF) {
00201         const stdair::FareFamily* lFF_ptr = *itFF;
00202         assert (lFF_ptr != NULL);
00203 
00204         const stdair::BookingClassList_T& lBCList = stdair::BomManager::
00205           getList<stdair::BookingClass> (*lFF_ptr);
00206         for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
00207              itBC != lBCList.end(); ++itBC) {
00208           stdair::BookingClass* lBookingClass_ptr = *itBC;
00209           assert (lBookingClass_ptr != NULL);
00210 
00211           const stdair::ClassCode_T& lClassCode =
00212             lBookingClass_ptr->getClassCode();
00213           stdair::AirlineCodeList_T lAirlineCodeList;
00214           lAirlineCodeList.push_back (iAirlineCode);
00215           stdair::ClassList_StringList_T lClassList;
00216           lClassList.push_back (lClassCode);
00217           const stdair::AirlineClassListKey lACListKey (lAirlineCodeList,
00218                                                         lClassList);
00219 
00220           const stdair::AirlineClassList* lAirlineClassList_ptr = stdair::
00221             BomManager::getObjectPtr<stdair::AirlineClassList> (*lYieldFeatures_ptr, lACListKey.toString());
00222           if (lAirlineClassList_ptr != NULL) {
00223             const stdair::Yield_T& lYield = lAirlineClassList_ptr->getYield();
00224             lBookingClass_ptr->setYield (lYield);
00225 
00226             //DEBUG
00227             STDAIR_LOG_DEBUG ("Update yield of " << lYield << " for "
00228                               << iAirlineCode << ", "
00229                               << iSegmentDate.describeKey() << ", "
00230                               << lBookingClass_ptr->describeKey());
00231           }
00232         }
00233       }
00234     }
00235   }
00236 }