TravelCCM Logo  1.00.2
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  // Initialization of the static member
21  const HybridModel HybridModel::_hybridModel;
22 
23  // ////////////////////////////////////////////////////////////////////
25  CustomerChoiceModel(stdair::PassengerChoiceModel::HYBRID) {
26  }
27 
28  // ////////////////////////////////////////////////////////////////////
30  }
31 
32  // ////////////////////////////////////////////////////////////////////
33  const stdair::TravelSolutionStruct* HybridModel::
34  chooseTravelSolution (stdair::TravelSolutionList_T& ioTSList,
35  const stdair::BookingRequestStruct& iBookingRequest) const {
36  stdair::TravelSolutionStruct* oChosenTS_ptr = NULL;
37 
38  // Retrieve the number of passengers
39  const stdair::NbOfSeats_T& lPartySize = iBookingRequest.getPartySize();
40 
41  // Retrieve the Willingness-to-Pay (WTP) of the customer
42  const stdair::WTP_T& lWTP = iBookingRequest.getWTP();
43 
44  // Retrieve the restrictions of the customer
45  // Retrieve the Change Fees of the customer
46  const stdair::ChangeFees_T& lCustomerChangeFees =
47  iBookingRequest.getChangeFees();
48 
49  //Retrieve the Non Refundable of the customer
50  const stdair::NonRefundable_T& lCustomerNonRefundable =
51  iBookingRequest.getNonRefundable();
52 
53  // Retrieve the Disutility of the customer
54  const stdair::Fare_T& lChangeFeesDisutility =
55  iBookingRequest.getChangeFeeDisutility();
56  const stdair::Fare_T& lNonRefundableDisutility =
57  iBookingRequest.getNonRefundableDisutility();
58 
59  // Browse the travel solution list and choose the cheapest one
60  stdair::Fare_T lLowestFare = std::numeric_limits<stdair::Fare_T>::max();
61  for (stdair::TravelSolutionList_T::iterator itTS = ioTSList.begin();
62  itTS != ioTSList.end(); ++itTS) {
63  stdair::TravelSolutionStruct& lTS = *itTS;
64 
65  // Browse the fare options
66  const stdair::FareOptionList_T& lFOList = lTS.getFareOptionList();
67  for (stdair::FareOptionList_T::const_iterator itFO = lFOList.begin();
68  itFO != lFOList.end(); ++itFO) {
69  const stdair::FareOptionStruct& lFO = *itFO;
70  const stdair::Fare_T& lFOFare = lFO.getFare();
71 
72  // Check the value of the disutility of the fare option
73  stdair::Fare_T lFODisutility = 0;
74 
75  // Check the change fees restriction
76  if (lCustomerChangeFees == false) {
77  const bool lFOChangeFees = lFO.getChangeFees();
78  if (lFOChangeFees == true){
79  lFODisutility += lChangeFeesDisutility;
80  }
81  }
82 
83  // Check the non refundable restriction
84  if (lCustomerNonRefundable == false) {
85  const bool lFONonRefundable = lFO.getNonRefundable();
86  if (lFONonRefundable == true){
87  lFODisutility += lNonRefundableDisutility;
88  }
89  }
90 
91 
92  // Choose the current fare option and the current solution
93  // if the current fare with penalities is lower than the current
94  // lowest fare.
95 
96  const stdair::Availability_T& lFOAvl = lFO.getAvailability();
97  const stdair::Fare_T lFOFareWithinDisutility = lFOFare + lFODisutility;
98 
99  if (lFOFareWithinDisutility < lLowestFare
100  && lFOFare <= lWTP
101  && lFOAvl >= lPartySize) {
102 
103  // DEBUG
104 
105  // STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
106  // << "' is chosen because its fare with disutility ("
107  // << lFOFare + lFODisutility
108  // << ") is lower than the lowest fare (" << lLowestFare
109  // << ") and because its fare ("<< lFOFare
110  // << ") is lower than the WTP (" << lWTP
111  // << "), and because the party size (" << lPartySize
112  // << ") is lower than the availability (" << lFOAvl
113  // << ")");
114 
115 
116  lLowestFare = lFOFare + lFODisutility;
117  oChosenTS_ptr = &lTS;
118  oChosenTS_ptr->setChosenFareOption (lFO);
119 
120  } else {
121  // DEBUG
122 
123  // STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
124  // << "' is not chosen because either its fare with disutility ("
125  // << lFOFare + lFODisutility << ") is greater than the "
126  // << "lowest fare (" << lLowestFare << "), or because its fare ("
127  // << lFOFare << ") " << "is greater than the WTP (" << lWTP
128  // << "), or because the party size (" << lPartySize
129  // << ") is greater than the availability (" << lFOAvl
130  // << ")");
131 
132  }
133  }
134  }
135 
136  return oChosenTS_ptr;
137  }
138 
139 }
const stdair::TravelSolutionStruct * chooseTravelSolution(stdair::TravelSolutionList_T &, const stdair::BookingRequestStruct &) const
Definition: HybridModel.cpp:34