TravelCCM Logo  1.00.1
C++ Travel Customer Choice Model Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
HybridModel.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* HybridModel::
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  // Retrieve the restrictions of the customer
32  // Retrieve the Change Fees of the customer
33  const stdair::ChangeFees_T& lCustomerChangeFees =
34  iBookingRequest.getChangeFees();
35 
36  //Retrieve the Non Refundable of the customer
37  const stdair::NonRefundable_T& lCustomerNonRefundable =
38  iBookingRequest.getNonRefundable();
39 
40  // Retrieve the Disutility of the customer
41  const stdair::Fare_T& lChangeFeesDisutility =
42  iBookingRequest.getChangeFeeDisutility();
43  const stdair::Fare_T& lNonRefundableDisutility =
44  iBookingRequest.getNonRefundableDisutility();
45 
46  // Browse the travel solution list and choose the cheapest one
47  stdair::Fare_T lLowestFare = std::numeric_limits<stdair::Fare_T>::max();
48  for (stdair::TravelSolutionList_T::iterator itTS = ioTSList.begin();
49  itTS != ioTSList.end(); ++itTS) {
50  stdair::TravelSolutionStruct& lTS = *itTS;
51 
52  // Browse the fare options
53  const stdair::FareOptionList_T& lFOList = lTS.getFareOptionList();
54  for (stdair::FareOptionList_T::const_iterator itFO = lFOList.begin();
55  itFO != lFOList.end(); ++itFO) {
56  const stdair::FareOptionStruct& lFO = *itFO;
57  const stdair::Fare_T& lFOFare = lFO.getFare();
58 
59  // Check the value of the disutility of the fare option
60  stdair::Fare_T lFODisutility = 0;
61 
62  // Check the change fees restriction
63  if (lCustomerChangeFees == false) {
64  const bool lFOChangeFees = lFO.getChangeFees();
65  if (lFOChangeFees == true){
66  lFODisutility += lChangeFeesDisutility;
67  }
68  }
69 
70  // Check the non refundable restriction
71  if (lCustomerNonRefundable == false) {
72  const bool lFONonRefundable = lFO.getNonRefundable();
73  if (lFONonRefundable == true){
74  lFODisutility += lNonRefundableDisutility;
75  }
76  }
77 
78 
79  // Choose the current fare option and the current solution
80  // if the current fare with penalities is lower than the current
81  // lowest fare.
82 
83  const stdair::Availability_T& lFOAvl = lFO.getAvailability();
84  const stdair::Fare_T lFOFareWithinDisutility = lFOFare + lFODisutility;
85 
86  if (lFOFareWithinDisutility < lLowestFare
87  && lFOFare <= lWTP
88  && lFOAvl >= lPartySize) {
89 
90  // DEBUG
91 
92  // STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
93  // << "' is chosen because its fare with disutility ("
94  // << lFOFare + lFODisutility
95  // << ") is lower than the lowest fare (" << lLowestFare
96  // << ") and because its fare ("<< lFOFare
97  // << ") is lower than the WTP (" << lWTP
98  // << "), and because the party size (" << lPartySize
99  // << ") is lower than the availability (" << lFOAvl
100  // << ")");
101 
102 
103  lLowestFare = lFOFare + lFODisutility;
104  oChosenTS_ptr = &lTS;
105  oChosenTS_ptr->setChosenFareOption (lFO);
106 
107  } else {
108  // DEBUG
109 
110  // STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
111  // << "' is not chosen because either its fare with disutility ("
112  // << lFOFare + lFODisutility << ") is greater than the "
113  // << "lowest fare (" << lLowestFare << "), or because its fare ("
114  // << lFOFare << ") " << "is greater than the WTP (" << lWTP
115  // << "), or because the party size (" << lPartySize
116  // << ") is greater than the availability (" << lFOAvl
117  // << ")");
118 
119  }
120  }
121  }
122 
123  return oChosenTS_ptr;
124  }
125 
126 }