TravelCCM Logo  1.00.1
C++ Travel Customer Choice Model Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
HardRestrictionModel.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* HardRestrictionModel::
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  // Check if the hard restrictions (change fees, non refundable) are
44  // satisfied
45  bool lHardRestrictionsSatisfied = true;
46  if (lFO.getChangeFees() == true
47  && iBookingRequest.getChangeFees() == false) {
48  lHardRestrictionsSatisfied = false;
49  } else if (lFO.getNonRefundable() == true
50  && iBookingRequest.getNonRefundable() == false) {
51  lHardRestrictionsSatisfied = false;
52  }
53 
54  if (lHardRestrictionsSatisfied == true) {
55  // Choose the current fare option and the current solution
56  // if the current fare is lower than the current lowest fare.
57  const stdair::Fare_T& lFOFare = lFO.getFare();
58  const stdair::Availability_T& lFOAvl = lFO.getAvailability();
59 
60  if (lFOFare < lLowestFare && lFOFare <= lWTP
61  && lFOAvl >= lPartySize) {
62 
63  // DEBUG
64  /*
65  STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
66  << "' is chosen because its fare (" << lFOFare
67  << ") is lower than the lowest fare (" << lLowestFare
68  << ") and than the WTP (" << lWTP
69  << "), and because the party size (" << lPartySize
70  << ") is lower than the availability (" << lFOAvl
71  << ")");
72  */
73 
74  lLowestFare = lFOFare;
75  oChosenTS_ptr = &lTS;
76  oChosenTS_ptr->setChosenFareOption (lFO);
77 
78  } else {
79  // DEBUG
80  /*
81  STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
82  << "' is not chosen because either its fare ("
83  << lFOFare << ") is greater than the lowest fare ("
84  << lLowestFare << ") or than the WTP (" << lWTP
85  << "), or because the party size (" << lPartySize
86  << ") is greater than the availability (" << lFOAvl
87  << ")");
88  */
89  }
90  }
91  }
92  }
93 
94  return oChosenTS_ptr;
95  }
96 
97 }