TravelCCM Logo  0.5.0
C++ Travel Customer Choice Model Library
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   const stdair::TravelSolutionStruct* PriceOrientedModel::
00021   chooseTravelSolution (stdair::TravelSolutionList_T& ioTSList,
00022                         const stdair::BookingRequestStruct& iBookingRequest) {
00023     stdair::TravelSolutionStruct* oChosenTS_ptr = NULL;
00024 
00025     // Retrieve the number of passengers
00026     const stdair::NbOfSeats_T& lPartySize = iBookingRequest.getPartySize();
00027 
00028     // Retrieve the Willingness-to-Pay (WTP) of the customer
00029     const stdair::WTP_T& lWTP = iBookingRequest.getWTP();
00030 
00031     // Browse the travel solution list and choose the cheapest one
00032     stdair::Fare_T lLowestFare = std::numeric_limits<stdair::Fare_T>::max();
00033     for (stdair::TravelSolutionList_T::iterator itTS = ioTSList.begin();
00034          itTS != ioTSList.end(); ++itTS) {
00035       stdair::TravelSolutionStruct& lTS = *itTS;
00036 
00037       // Browse the fare options
00038       const stdair::FareOptionList_T& lFOList = lTS.getFareOptionList();
00039       for (stdair::FareOptionList_T::const_iterator itFO = lFOList.begin();
00040            itFO != lFOList.end(); ++itFO) {
00041         const stdair::FareOptionStruct& lFO = *itFO;
00042 
00043         // Choose the current fare option and the current solution
00044         // if the current fare is lower than the current lowest fare.
00045         const stdair::Fare_T& lFOFare = lFO.getFare();
00046         const stdair::Availability_T& lFOAvl = lFO.getAvailability();
00047 
00048         if (lFOFare < lLowestFare && lFOFare <= lWTP && lFOAvl >= lPartySize) {
00049 
00050           // DEBUG
00051           /*
00052           STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
00053                             << "' is chosen because its fare (" << lFOFare
00054                             << ") is lower than the lowest fare (" << lLowestFare
00055                             << ") and than the WTP (" << lWTP
00056                             << "), and because the party size (" << lPartySize
00057                             << ") is lower than the availability (" << lFOAvl
00058                             << ")");
00059           */
00060 
00061           lLowestFare = lFOFare;
00062           oChosenTS_ptr = &lTS;
00063           oChosenTS_ptr->setChosenFareOption (lFO);
00064 
00065         } else {
00066           // DEBUG
00067           /*
00068           STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
00069                             << "' is not chosen because either its fare ("
00070                             << lFOFare << ") is greater than the lowest fare ("
00071                             << lLowestFare << ") or than the WTP (" << lWTP
00072                             << "), or because the party size (" << lPartySize
00073                             << ") is greater than the availability (" << lFOAvl
00074                             << ")");
00075           */
00076         }
00077       }
00078     }
00079     
00080     return oChosenTS_ptr;
00081   }
00082 
00083 }