TravelCCM Logo  1.00.4
C++ Travel Customer Choice Model Library
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  // Initialization of the static member
21  const HardRestrictionModel HardRestrictionModel::_hardRestrictionModel;
22 
23  // ////////////////////////////////////////////////////////////////////
25  CustomerChoiceModel(stdair::PassengerChoiceModel::HARD_RESTRICTION) {
26  }
27 
28  // ////////////////////////////////////////////////////////////////////
30  }
31 
32  // ////////////////////////////////////////////////////////////////////
33  const stdair::TravelSolutionStruct* HardRestrictionModel::
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  // Browse the travel solution list and choose the cheapest one
45  stdair::Fare_T lLowestFare = std::numeric_limits<stdair::Fare_T>::max();
46  for (stdair::TravelSolutionList_T::iterator itTS = ioTSList.begin();
47  itTS != ioTSList.end(); ++itTS) {
48  stdair::TravelSolutionStruct& lTS = *itTS;
49 
50  // Browse the fare options
51  const stdair::FareOptionList_T& lFOList = lTS.getFareOptionList();
52  for (stdair::FareOptionList_T::const_iterator itFO = lFOList.begin();
53  itFO != lFOList.end(); ++itFO) {
54  const stdair::FareOptionStruct& lFO = *itFO;
55 
56  // Check if the hard restrictions (change fees, non refundable) are
57  // satisfied
58  bool lHardRestrictionsSatisfied = true;
59  if (lFO.getChangeFees() == true
60  && iBookingRequest.getChangeFees() == false) {
61  lHardRestrictionsSatisfied = false;
62  } else if (lFO.getNonRefundable() == true
63  && iBookingRequest.getNonRefundable() == false) {
64  lHardRestrictionsSatisfied = false;
65  }
66 
67  if (lHardRestrictionsSatisfied == true) {
68  // Choose the current fare option and the current solution
69  // if the current fare is lower than the current lowest fare.
70  const stdair::Fare_T& lFOFare = lFO.getFare();
71  const stdair::Availability_T& lFOAvl = lFO.getAvailability();
72 
73  if (lFOFare < lLowestFare && lFOFare <= lWTP
74  && lFOAvl >= lPartySize) {
75 
76  // DEBUG
77  /*
78  STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
79  << "' is chosen because its fare (" << lFOFare
80  << ") is lower than the lowest fare (" << lLowestFare
81  << ") and than the WTP (" << lWTP
82  << "), and because the party size (" << lPartySize
83  << ") is lower than the availability (" << lFOAvl
84  << ")");
85  */
86 
87  lLowestFare = lFOFare;
88  oChosenTS_ptr = &lTS;
89  oChosenTS_ptr->setChosenFareOption (lFO);
90 
91  } else {
92  // DEBUG
93  /*
94  STDAIR_LOG_DEBUG ("The travel solution (TS) '" << lTS
95  << "' is not chosen because either its fare ("
96  << lFOFare << ") is greater than the lowest fare ("
97  << lLowestFare << ") or than the WTP (" << lWTP
98  << "), or because the party size (" << lPartySize
99  << ") is greater than the availability (" << lFOAvl
100  << ")");
101  */
102  }
103  }
104  }
105  }
106 
107  return oChosenTS_ptr;
108  }
109 
110 }
stdair
Forward declarations.
Definition: CustomerChoiceModel.hpp:13
TRAVELCCM
Definition: BasConst.cpp:6
HardRestrictionModel.hpp
TRAVELCCM::HardRestrictionModel::~HardRestrictionModel
~HardRestrictionModel()
Definition: HardRestrictionModel.cpp:29
TRAVELCCM::HardRestrictionModel::HardRestrictionModel
HardRestrictionModel()
Definition: HardRestrictionModel.cpp:24
TRAVELCCM::HardRestrictionModel::chooseTravelSolution
const stdair::TravelSolutionStruct * chooseTravelSolution(stdair::TravelSolutionList_T &, const stdair::BookingRequestStruct &) const
Definition: HardRestrictionModel.cpp:34
TRAVELCCM::CustomerChoiceModel
Definition: CustomerChoiceModel.hpp:22