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

PriceOrientedModel.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/PriceOrientedModel.hpp>
00016 
00017 namespace TRAVELCCM {  
00018 
00019   // ////////////////////////////////////////////////////////////////////
00020   // Initialization of the static member
00021   const PriceOrientedModel PriceOrientedModel::_priceOrientedModel;  
00022 
00023   // ////////////////////////////////////////////////////////////////////
00024   PriceOrientedModel::PriceOrientedModel () : 
00025     CustomerChoiceModel(stdair::PassengerChoiceModel::PRICE_ORIENTED) {
00026   } 
00027 
00028   // ////////////////////////////////////////////////////////////////////
00029   PriceOrientedModel::~PriceOrientedModel () {
00030   }
00031 
00032   // ////////////////////////////////////////////////////////////////////
00033   const stdair::TravelSolutionStruct* PriceOrientedModel::
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         // Choose the current fare option and the current solution
00057         // if the current fare is lower than the current lowest fare.
00058         const stdair::Fare_T& lFOFare = lFO.getFare();
00059         const stdair::Availability_T& lFOAvl = lFO.getAvailability();
00060 
00061         if (lFOFare < lLowestFare && lFOFare <= lWTP && lFOAvl >= lPartySize) {
00062 
00063           // DEBUG
00064           /*
00065           STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
00066                             << "' is chosen because its fare (" << lFOFare
00067                             << ") is lower than the lowest fare (" << lLowestFare
00068                             << ") and than the WTP (" << lWTP
00069                             << "), and because the party size (" << lPartySize
00070                             << ") is lower than the availability (" << lFOAvl
00071                             << ")");
00072           */
00073 
00074           lLowestFare = lFOFare;
00075           oChosenTS_ptr = &lTS;
00076           oChosenTS_ptr->setChosenFareOption (lFO);
00077 
00078         } else {
00079           // DEBUG
00080           /*
00081           STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
00082                             << "' is not chosen because either its fare ("
00083                             << lFOFare << ") is greater than the lowest fare ("
00084                             << lLowestFare << ") or than the WTP (" << lWTP
00085                             << "), or because the party size (" << lPartySize
00086                             << ") is greater than the availability (" << lFOAvl
00087                             << ")");
00088           */
00089         }
00090       }
00091     }
00092     
00093     return oChosenTS_ptr;
00094   }
00095 
00096 }