$treeview $search $mathjax
TravelCCM Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

HybridModel.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/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/HybridModel.hpp>
00016 
00017 namespace TRAVELCCM { 
00018 
00019   // ////////////////////////////////////////////////////////////////////
00020   // Initialization of the static member
00021   const HybridModel HybridModel::_hybridModel; 
00022 
00023   // ////////////////////////////////////////////////////////////////////
00024   HybridModel::HybridModel () : 
00025     CustomerChoiceModel(stdair::PassengerChoiceModel::HYBRID) {
00026   } 
00027 
00028   // ////////////////////////////////////////////////////////////////////
00029   HybridModel::~HybridModel () {
00030   }
00031 
00032   // ////////////////////////////////////////////////////////////////////
00033   const stdair::TravelSolutionStruct* HybridModel::
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     // Retrieve the restrictions of the customer
00045     // Retrieve the Change Fees of the customer
00046     const stdair::ChangeFees_T& lCustomerChangeFees = 
00047       iBookingRequest.getChangeFees();
00048   
00049     //Retrieve the Non Refundable of the customer
00050     const stdair::NonRefundable_T& lCustomerNonRefundable = 
00051       iBookingRequest.getNonRefundable();
00052 
00053     // Retrieve the Disutility of the customer
00054     const stdair::Fare_T& lChangeFeesDisutility = 
00055       iBookingRequest.getChangeFeeDisutility();
00056     const stdair::Fare_T& lNonRefundableDisutility =
00057       iBookingRequest.getNonRefundableDisutility();
00058     
00059     // Browse the travel solution list and choose the cheapest one
00060     stdair::Fare_T lLowestFare = std::numeric_limits<stdair::Fare_T>::max();
00061     for (stdair::TravelSolutionList_T::iterator itTS = ioTSList.begin();
00062          itTS != ioTSList.end(); ++itTS) {
00063       stdair::TravelSolutionStruct& lTS = *itTS;
00064 
00065       // Browse the fare options
00066       const stdair::FareOptionList_T& lFOList = lTS.getFareOptionList();
00067       for (stdair::FareOptionList_T::const_iterator itFO = lFOList.begin();
00068            itFO != lFOList.end(); ++itFO) {
00069         const stdair::FareOptionStruct& lFO = *itFO;
00070         const stdair::Fare_T& lFOFare = lFO.getFare();
00071 
00072         // Check the value of the disutility of the fare option
00073         stdair::Fare_T lFODisutility = 0;
00074         
00075         // Check the change fees restriction
00076         if (lCustomerChangeFees == false) {
00077           const bool lFOChangeFees = lFO.getChangeFees();
00078           if (lFOChangeFees == true){
00079             lFODisutility += lChangeFeesDisutility;
00080           }
00081         }
00082 
00083         // Check the non refundable restriction
00084         if (lCustomerNonRefundable == false) {
00085           const bool lFONonRefundable = lFO.getNonRefundable();
00086           if (lFONonRefundable == true){
00087             lFODisutility += lNonRefundableDisutility;
00088           }
00089         }
00090         
00091            
00092         // Choose the current fare option and the current solution
00093         // if the current fare with penalities is lower than the current 
00094         // lowest fare.
00095         
00096         const stdair::Availability_T& lFOAvl = lFO.getAvailability();
00097         const stdair::Fare_T lFOFareWithinDisutility = lFOFare + lFODisutility;
00098 
00099         if (lFOFareWithinDisutility < lLowestFare 
00100             && lFOFare <= lWTP
00101             && lFOAvl >= lPartySize) {
00102 
00103           // DEBUG
00104           
00105           //  STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
00106           //  << "' is chosen because its fare with disutility (" 
00107           //  << lFOFare + lFODisutility
00108           //  << ") is lower than the lowest fare (" << lLowestFare
00109           //  << ") and because its fare ("<< lFOFare
00110           //  << ") is lower than the WTP (" << lWTP
00111           //  << "), and because the party size (" << lPartySize
00112           //  << ") is lower than the availability (" << lFOAvl
00113           //  << ")");
00114           
00115 
00116           lLowestFare = lFOFare + lFODisutility;
00117           oChosenTS_ptr = &lTS;
00118           oChosenTS_ptr->setChosenFareOption (lFO);
00119 
00120         } else {
00121           // DEBUG
00122           
00123           //  STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
00124           //  << "' is not chosen because either its fare with disutility ("
00125           //  << lFOFare + lFODisutility << ") is greater than the " 
00126           //  << "lowest fare (" << lLowestFare << "), or because its fare ("
00127           //  << lFOFare << ") " << "is greater than the WTP (" << lWTP
00128           //  << "), or because the party size (" << lPartySize
00129           //  << ") is greater than the availability (" << lFOAvl
00130           //  << ")");
00131           
00132         }
00133       }
00134     }
00135     
00136     return oChosenTS_ptr;
00137   }
00138 
00139 }