AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SegmentCabinHelper.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/BomManager.hpp>
9 #include <stdair/bom/FlightDate.hpp>
10 #include <stdair/bom/LegCabin.hpp>
11 #include <stdair/bom/SegmentCabin.hpp>
12 #include <stdair/bom/FareFamily.hpp>
13 #include <stdair/bom/BookingClass.hpp>
14 // AirInv
17 
18 namespace AIRINV {
19 
20  // ////////////////////////////////////////////////////////////////////
21  void SegmentCabinHelper::initialiseAU (stdair::SegmentCabin& iSegmentCabin) {
22 
23  // Initialise the capacity and availability pool.
24  const stdair::LegCabinList_T& lLCList =
25  stdair::BomManager::getList<stdair::LegCabin> (iSegmentCabin);
26 
27  stdair::CabinCapacity_T lCapacity =
28  std::numeric_limits<stdair::CabinCapacity_T>::max();
29  for (stdair::LegCabinList_T::const_iterator itLC = lLCList.begin();
30  itLC != lLCList.end(); ++itLC) {
31 
32  const stdair::LegCabin* lLC_ptr = *itLC;
33  assert (lLC_ptr != NULL);
34 
35  const stdair::CabinCapacity_T& lCabinCap = lLC_ptr->getOfferedCapacity();
36  if (lCapacity > lCabinCap) {
37  lCapacity = lCabinCap;
38  }
39  }
40  iSegmentCabin.setCapacity (lCapacity);
41  iSegmentCabin.setAvailabilityPool (lCapacity);
42 
43  // Browse the list of booking classes and set the AU of each booking
44  // class to the availability pool of the cabin.
45  const stdair::BookingClassList_T& lBCList =
46  stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
47  for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
48  itBC != lBCList.end(); ++itBC) {
49  stdair::BookingClass* lBC_ptr = *itBC;
50  assert (lBC_ptr != NULL);
51  lBC_ptr->setAuthorizationLevel (lCapacity);
52  }
53  }
54 
55  // ////////////////////////////////////////////////////////////////////
57  updateFromReservation (const stdair::FlightDate& iFlightDate,
58  stdair::SegmentCabin& ioSegmentCabin,
59  const stdair::PartySize_T& iNbOfBookings){
60  // Update the commited space of the segment-cabin.
61  ioSegmentCabin.updateFromReservation (iNbOfBookings);
62 
63  // Update the commited space of the member leg-cabins.
64  const stdair::LegCabinList_T& lLegCabinList =
65  stdair::BomManager::getList<stdair::LegCabin> (ioSegmentCabin);
66  for (stdair::LegCabinList_T::const_iterator itLegCabin =
67  lLegCabinList.begin();
68  itLegCabin != lLegCabinList.end(); ++itLegCabin) {
69  stdair::LegCabin* lLegCabin_ptr = *itLegCabin;
70  assert (lLegCabin_ptr != NULL);
71  lLegCabin_ptr->updateFromReservation (iNbOfBookings);
72  }
73 
74  // Update the availability pool of all the segment-cabin which belong to the
75  // same flight-date.
76  const stdair::CabinCode_T& lCabinCode = ioSegmentCabin.getCabinCode();
77  FlightDateHelper::updateAvailablityPool (iFlightDate, lCabinCode);
78  }
79 
80  // ////////////////////////////////////////////////////////////////////
82  buildPseudoBidPriceVector (stdair::SegmentCabin& ioSegmentCabin) {
83  // Retrieve the segment-cabin capacity.
84  const stdair::Availability_T& lAvlPool=ioSegmentCabin.getAvailabilityPool();
85  const unsigned int lAvlPoolInt =
86  static_cast<unsigned int> (lAvlPool);
87  stdair::BidPriceVector_T lPseudoBidPriceVector (lAvlPoolInt, 0.0);
88 
89  // Browse the leg-cabin list.
90  const stdair::LegCabinList_T& lLCList =
91  stdair::BomManager::getList<stdair::LegCabin> (ioSegmentCabin);
92  for (stdair::LegCabinList_T::const_iterator itLC = lLCList.begin();
93  itLC != lLCList.end(); ++itLC) {
94  const stdair::LegCabin* lLC_ptr = *itLC;
95  assert (lLC_ptr != NULL);
96 
97  const stdair::BidPriceVector_T& lBPV = lLC_ptr->getBidPriceVector();
98  stdair::BidPriceVector_T::const_reverse_iterator itBP = lBPV.rbegin();
99  for (stdair::BidPriceVector_T::reverse_iterator itPBP =
100  lPseudoBidPriceVector.rbegin();
101  itPBP != lPseudoBidPriceVector.rend(); ++itPBP, ++itBP) {
102  assert (itBP != lBPV.rend());
103  stdair::BidPrice_T& lCurrentPBP = *itPBP;
104  const stdair::BidPrice_T& lCurrentBP = *itBP;
105  lCurrentPBP += lCurrentBP;
106  }
107  }
108 
109  ioSegmentCabin.setBidPriceVector (lPseudoBidPriceVector);
110 
111  // // DEBUG
112  // std::ostringstream ostr;
113  // ostr << "Pseudo BPV: ";
114  // for (stdair::BidPriceVector_T::const_iterator itBP =
115  // lPseudoBidPriceVector.begin(); itBP != lPseudoBidPriceVector.end();
116  // ++itBP) {
117  // const stdair::BidPrice_T& lCurrentBP = *itBP;
118  // ostr << lCurrentBP << " ";
119  // }
120  // // STDAIR_LOG_DEBUG (ostr.str());
121  // std::cout << ostr.str() << std::endl;
122  }
123 
124  // ////////////////////////////////////////////////////////////////////
126  updateBookingControlsUsingPseudoBidPriceVector (const stdair::SegmentCabin& iSegmentCabin) {
127  // Retrieve the pseudo bid price vector.
128  const stdair::BidPriceVector_T& lPseudoBPV =
129  iSegmentCabin.getBidPriceVector();
130  const stdair::Availability_T& lAvlPool=iSegmentCabin.getAvailabilityPool();
131 
132  // Update the cumulative booking limit for all booking classes.
133  const stdair::BookingClassList_T& lBCList =
134  stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
135  for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
136  itBC != lBCList.end(); ++itBC) {
137  stdair::BookingClass* lBC_ptr = *itBC;
138  assert (lBC_ptr != NULL);
139 
140  lBC_ptr->setCumulatedBookingLimit (lAvlPool);
141  const stdair::Yield_T& lYield = lBC_ptr->getYield();
142  for (stdair::BidPriceVector_T::const_reverse_iterator itBP =
143  lPseudoBPV.rbegin(); itBP != lPseudoBPV.rend(); ++itBP) {
144  const stdair::BidPrice_T& lBP = *itBP;
145  if (lYield < lBP) {
146  stdair::BookingLimit_T lCumuBL = itBP - lPseudoBPV.rbegin();
147  lBC_ptr->setCumulatedBookingLimit (lCumuBL);
148  break;
149  }
150  }
151  }
152 
153  // Update the authorization levels from the booking limits
154  updateAUs (iSegmentCabin);
155  }
156 
157  // ////////////////////////////////////////////////////////////////////
158  void SegmentCabinHelper::updateAUs(const stdair::SegmentCabin& iSegmentCabin){
159  // Browse the booking class list and compute the AU from the
160  // cumulative booking counter and the cumulative booking limit.
161  stdair::NbOfBookings_T lCumulativeBookingCounter = 0.0;
162  const stdair::BookingClassList_T& lBCList =
163  stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
164  for (stdair::BookingClassList_T::const_reverse_iterator itBC =
165  lBCList.rbegin(); itBC != lBCList.rend(); ++itBC) {
166  stdair::BookingClass* lBC_ptr = *itBC;
167  assert (lBC_ptr != NULL);
168 
169  const stdair::NbOfBookings_T& lNbOfBookings = lBC_ptr->getNbOfBookings();
170  lCumulativeBookingCounter += lNbOfBookings;
171 
172  const stdair::BookingLimit_T& lCumuBookingLimit =
173  lBC_ptr->getCumulatedBookingLimit();
174 
175  stdair::AuthorizationLevel_T lAU =
176  lCumulativeBookingCounter + lCumuBookingLimit;
177  lBC_ptr->setAuthorizationLevel (lAU);
178 
179  // DEBUG
180  // STDAIR_LOG_DEBUG ("Updating the AU for class: "
181  // << lBC_ptr->describeKey()
182  // << ", with BL: " << lCumuBookingLimit
183  // << ", CumuBkg: " << lCumulativeBookingCounter
184  // << ", AU: " << lAU);
185  }
186  }
187 
188  // ////////////////////////////////////////////////////////////////////
190  updateAvailabilities (const stdair::SegmentCabin& iSegmentCabin) {
191  // Browse the booking class list and compute the avl from the
192  // cumulative booking counter and the AU.
193  stdair::NbOfBookings_T lCumulativeBookingCounter = 0.0;
194  const stdair::BookingClassList_T& lBCList =
195  stdair::BomManager::getList<stdair::BookingClass> (iSegmentCabin);
196  for (stdair::BookingClassList_T::const_reverse_iterator itBC =
197  lBCList.rbegin(); itBC != lBCList.rend(); ++itBC) {
198  stdair::BookingClass* lBC_ptr = *itBC;
199  assert (lBC_ptr != NULL);
200 
201  const stdair::NbOfBookings_T& lNbOfBookings = lBC_ptr->getNbOfBookings();
202  lCumulativeBookingCounter += lNbOfBookings;
203 
204  const stdair::AuthorizationLevel_T& lAU=lBC_ptr->getAuthorizationLevel();
205 
206  const stdair::Availability_T lAvl = lAU - lCumulativeBookingCounter;
207  lBC_ptr->setSegmentAvailability (lAvl);
208  }
209  }
210 }