$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 #include <sstream> 00007 // StdAir 00008 #include <stdair/bom/BomKeyManager.hpp> 00009 #include <stdair/bom/BookingClassKey.hpp> 00010 #include <stdair/bom/BookingRequestStruct.hpp> 00011 #include <stdair/bom/TravelSolutionStruct.hpp> 00012 #include <stdair/bom/FareOptionStruct.hpp> 00013 #include <stdair/service/Logger.hpp> 00014 // TravelCCM 00015 #include <travelccm/bom/HardRestrictionModel.hpp> 00016 00017 namespace TRAVELCCM { 00018 00019 // //////////////////////////////////////////////////////////////////// 00020 // Initialization of the static member 00021 const HardRestrictionModel HardRestrictionModel::_hardRestrictionModel; 00022 00023 // //////////////////////////////////////////////////////////////////// 00024 HardRestrictionModel::HardRestrictionModel () : 00025 CustomerChoiceModel(stdair::PassengerChoiceModel::HARD_RESTRICTION) { 00026 } 00027 00028 // //////////////////////////////////////////////////////////////////// 00029 HardRestrictionModel::~HardRestrictionModel () { 00030 } 00031 00032 // //////////////////////////////////////////////////////////////////// 00033 const stdair::TravelSolutionStruct* HardRestrictionModel:: 00034 chooseTravelSolution (stdair::TravelSolutionList_T& ioTSList, 00035 const stdair::BookingRequestStruct& iBookingRequest) const { 00036 stdair::TravelSolutionStruct* oChosenTS_ptr = NULL; 00037 00038 // Retrieve the number of passengers 00039 const stdair::NbOfSeats_T& lPartySize = iBookingRequest.getPartySize(); 00040 00041 // Retrieve the Willingness-to-Pay (WTP) of the customer 00042 const stdair::WTP_T& lWTP = iBookingRequest.getWTP(); 00043 00044 // Browse the travel solution list and choose the cheapest one 00045 stdair::Fare_T lLowestFare = std::numeric_limits<stdair::Fare_T>::max(); 00046 for (stdair::TravelSolutionList_T::iterator itTS = ioTSList.begin(); 00047 itTS != ioTSList.end(); ++itTS) { 00048 stdair::TravelSolutionStruct& lTS = *itTS; 00049 00050 // Browse the fare options 00051 const stdair::FareOptionList_T& lFOList = lTS.getFareOptionList(); 00052 for (stdair::FareOptionList_T::const_iterator itFO = lFOList.begin(); 00053 itFO != lFOList.end(); ++itFO) { 00054 const stdair::FareOptionStruct& lFO = *itFO; 00055 00056 // Check if the hard restrictions (change fees, non refundable) are 00057 // satisfied 00058 bool lHardRestrictionsSatisfied = true; 00059 if (lFO.getChangeFees() == true 00060 && iBookingRequest.getChangeFees() == false) { 00061 lHardRestrictionsSatisfied = false; 00062 } else if (lFO.getNonRefundable() == true 00063 && iBookingRequest.getNonRefundable() == false) { 00064 lHardRestrictionsSatisfied = false; 00065 } 00066 00067 if (lHardRestrictionsSatisfied == true) { 00068 // Choose the current fare option and the current solution 00069 // if the current fare is lower than the current lowest fare. 00070 const stdair::Fare_T& lFOFare = lFO.getFare(); 00071 const stdair::Availability_T& lFOAvl = lFO.getAvailability(); 00072 00073 if (lFOFare < lLowestFare && lFOFare <= lWTP 00074 && lFOAvl >= lPartySize) { 00075 00076 // DEBUG 00077 /* 00078 STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS 00079 << "' is chosen because its fare (" << lFOFare 00080 << ") is lower than the lowest fare (" << lLowestFare 00081 << ") and than the WTP (" << lWTP 00082 << "), and because the party size (" << lPartySize 00083 << ") is lower than the availability (" << lFOAvl 00084 << ")"); 00085 */ 00086 00087 lLowestFare = lFOFare; 00088 oChosenTS_ptr = &lTS; 00089 oChosenTS_ptr->setChosenFareOption (lFO); 00090 00091 } else { 00092 // DEBUG 00093 /* 00094 STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS 00095 << "' is not chosen because either its fare (" 00096 << lFOFare << ") is greater than the lowest fare (" 00097 << lLowestFare << ") or than the WTP (" << lWTP 00098 << "), or because the party size (" << lPartySize 00099 << ") is greater than the availability (" << lFOAvl 00100 << ")"); 00101 */ 00102 } 00103 } 00104 } 00105 } 00106 00107 return oChosenTS_ptr; 00108 } 00109 00110 }