TravelCCM Logo  1.00.1
C++ Travel Customer Choice Model Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
PriceOrientedModel.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
8 #include <stdair/bom/BomKeyManager.hpp>
9 #include <stdair/bom/BookingClassKey.hpp>
10 #include <stdair/bom/BookingRequestStruct.hpp>
11 #include <stdair/bom/TravelSolutionStruct.hpp>
12 #include <stdair/bom/FareOptionStruct.hpp>
13 #include <stdair/service/Logger.hpp>
14 // TravelCCM
16 
17 namespace TRAVELCCM {
18 
19  // ////////////////////////////////////////////////////////////////////
20  const stdair::TravelSolutionStruct* PriceOrientedModel::
21  chooseTravelSolution (stdair::TravelSolutionList_T& ioTSList,
22  const stdair::BookingRequestStruct& iBookingRequest) {
23  stdair::TravelSolutionStruct* oChosenTS_ptr = NULL;
24 
25  // Retrieve the number of passengers
26  const stdair::NbOfSeats_T& lPartySize = iBookingRequest.getPartySize();
27 
28  // Retrieve the Willingness-to-Pay (WTP) of the customer
29  const stdair::WTP_T& lWTP = iBookingRequest.getWTP();
30 
31  // Browse the travel solution list and choose the cheapest one
32  stdair::Fare_T lLowestFare = std::numeric_limits<stdair::Fare_T>::max();
33  for (stdair::TravelSolutionList_T::iterator itTS = ioTSList.begin();
34  itTS != ioTSList.end(); ++itTS) {
35  stdair::TravelSolutionStruct& lTS = *itTS;
36 
37  // Browse the fare options
38  const stdair::FareOptionList_T& lFOList = lTS.getFareOptionList();
39  for (stdair::FareOptionList_T::const_iterator itFO = lFOList.begin();
40  itFO != lFOList.end(); ++itFO) {
41  const stdair::FareOptionStruct& lFO = *itFO;
42 
43  // Choose the current fare option and the current solution
44  // if the current fare is lower than the current lowest fare.
45  const stdair::Fare_T& lFOFare = lFO.getFare();
46  const stdair::Availability_T& lFOAvl = lFO.getAvailability();
47 
48  if (lFOFare < lLowestFare && lFOFare <= lWTP && lFOAvl >= lPartySize) {
49 
50  // DEBUG
51  /*
52  STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
53  << "' is chosen because its fare (" << lFOFare
54  << ") is lower than the lowest fare (" << lLowestFare
55  << ") and than the WTP (" << lWTP
56  << "), and because the party size (" << lPartySize
57  << ") is lower than the availability (" << lFOAvl
58  << ")");
59  */
60 
61  lLowestFare = lFOFare;
62  oChosenTS_ptr = &lTS;
63  oChosenTS_ptr->setChosenFareOption (lFO);
64 
65  } else {
66  // DEBUG
67  /*
68  STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
69  << "' is not chosen because either its fare ("
70  << lFOFare << ") is greater than the lowest fare ("
71  << lLowestFare << ") or than the WTP (" << lWTP
72  << "), or because the party size (" << lPartySize
73  << ") is greater than the availability (" << lFOAvl
74  << ")");
75  */
76  }
77  }
78  }
79 
80  return oChosenTS_ptr;
81  }
82 
83 }