AirInv Logo  1.00.0
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InventoryManager.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <exception>
6 #include <algorithm> // To use min
7 // Boost
8 #include <boost/make_shared.hpp>
9 // StdAir
10 #include <stdair/basic/BasConst_Inventory.hpp>
11 #include <stdair/basic/BasConst_BomDisplay.hpp>
12 #include <stdair/bom/BomManager.hpp>
13 #include <stdair/bom/BomKeyManager.hpp>
14 #include <stdair/bom/BomRoot.hpp>
15 #include <stdair/bom/Inventory.hpp>
16 #include <stdair/bom/FlightDate.hpp>
17 #include <stdair/bom/SegmentDate.hpp>
18 #include <stdair/bom/SegmentCabin.hpp>
19 #include <stdair/bom/LegDate.hpp>
20 #include <stdair/bom/LegCabin.hpp>
21 #include <stdair/bom/FareFamily.hpp>
22 #include <stdair/bom/BookingClass.hpp>
23 #include <stdair/bom/SegmentSnapshotTable.hpp>
24 #include <stdair/bom/TravelSolutionStruct.hpp>
25 #include <stdair/bom/FareOptionStruct.hpp>
26 #include <stdair/bom/EventStruct.hpp>
27 #include <stdair/bom/SnapshotStruct.hpp>
28 #include <stdair/bom/RMEventStruct.hpp>
29 #include <stdair/bom/FareFamily.hpp> // Contains the definition of FareFamilyList_T
30 #include <stdair/bom/BookingClass.hpp> //
31 #include <stdair/bom/BomRetriever.hpp>
32 #include <stdair/factory/FacBomManager.hpp>
33 #include <stdair/factory/FacBom.hpp>
34 #include <stdair/service/Logger.hpp>// SEvMgr
35 #include <sevmgr/SEVMGR_Service.hpp>
36 // AirInv
37 #include <airinv/AIRINV_Types.hpp>
43 
44 namespace AIRINV {
45 
46  // ////////////////////////////////////////////////////////////////////
47  void InventoryManager::
48  calculateAvailability (const stdair::BomRoot& iBomRoot,
49  stdair::TravelSolutionStruct& ioTravelSolution) {
50 
51  stdair::PartnershipTechnique::EN_PartnershipTechnique lENPartnershipTechnique =
52  stdair::PartnershipTechnique::NONE;
53 
54  // Browse the list of segments and get the availability for the
55  // children classes.
56  const stdair::SegmentPath_T& lSegmentPath =
57  ioTravelSolution.getSegmentPath();
58  for (stdair::SegmentPath_T::const_iterator itSK = lSegmentPath.begin();
59  itSK != lSegmentPath.end(); ++itSK) {
60  const std::string& lSegmentKey = *itSK;
61  const stdair::InventoryKey lInvKey =
62  stdair::BomKeyManager::extractInventoryKey (lSegmentKey);
63  stdair::Inventory& lInventory =
64  stdair::BomManager::getObject<stdair::Inventory>(iBomRoot,
65  lInvKey.toString());
66 
67  lENPartnershipTechnique = lInventory.getPartnershipTechnique();
68 
69  switch (lENPartnershipTechnique) {
70 
71  case stdair::PartnershipTechnique::NONE:{
72  InventoryHelper::calculateAvailability (lInventory, lSegmentKey,
73  ioTravelSolution);
74  break;
75  }
76  default:{
77  InventoryHelper::getYieldAndBidPrice (lInventory, lSegmentKey,
78  ioTravelSolution);
79  break;
80  }
81  }
82 
83  }
84 
85  switch (lENPartnershipTechnique) {
86  case stdair::PartnershipTechnique::NONE:{
87  // Compute the availabitliy for each fare option using the AU's.
88  calculateAvailabilityByAU (ioTravelSolution);
89  break;
90  }
91  case stdair::PartnershipTechnique::RAE_DA:
92  case stdair::PartnershipTechnique::RAE_YP:{
93  // 1. Compute the availability for each fare option using RAE
94  calculateAvailabilityByRAE (ioTravelSolution);
95  break;
96  }
97  case stdair::PartnershipTechnique::IBP_DA:
98  case stdair::PartnershipTechnique::IBP_YP:{
99  // 2. Compute the availability for each fare option using protective IBP
100  calculateAvailabilityByProtectiveIBP (ioTravelSolution);
101  break;
102  }
103  case stdair::PartnershipTechnique::IBP_YP_U:
104  case stdair::PartnershipTechnique::RMC:
105  case stdair::PartnershipTechnique::A_RMC:{
106  // 3. Compute the availability for each fare option using IBP
107  calculateAvailabilityByIBP (ioTravelSolution);
108  break;
109  }
110  default: {
111  assert (false);
112  break;
113  }
114  }
115 
116  }
117 
118  // ////////////////////////////////////////////////////////////////////
119  void InventoryManager::
120  calculateAvailabilityByAU (stdair::TravelSolutionStruct& ioTravelSolution) {
121 
122  // MODIF: segment path string for availability display
123  std::ostringstream oStr;
124  const stdair::SegmentPath_T& lSP = ioTravelSolution.getSegmentPath();
125  for (stdair::SegmentPath_T::const_iterator itSP = lSP.begin();
126  itSP != lSP.end(); itSP++) {
127  oStr << *itSP << ";";
128  }
129 
130  // Browse the fare options
131  stdair::FareOptionList_T& lFOList = ioTravelSolution.getFareOptionListRef();
132  for (stdair::FareOptionList_T::iterator itFO = lFOList.begin();
133  itFO != lFOList.end(); ++itFO) {
134 
135  stdair::FareOptionStruct& lFO = *itFO;
136 
137  // Check the availability
138  const stdair::ClassList_StringList_T& lClassPath = lFO.getClassPath();
139 
140  const stdair::ClassAvailabilityMapHolder_T& lClassAvailabilityMapHolder =
141  ioTravelSolution.getClassAvailabilityMapHolder();
142 
143  // Initialise the flag stating whether the availability is enough
144  stdair::Availability_T lAvl =
145  std::numeric_limits<stdair::Availability_T>::max();
146 
147  // Sanity check: the travel solution must contain two lists,
148  // one for the booking class availabilities, the other for the
149  // fare options.
150  assert (lClassAvailabilityMapHolder.empty() == false
151  && lClassPath.empty() == false);
152 
153  // List of booking class availability maps (one map per segment)
154  stdair::ClassAvailabilityMapHolder_T::const_iterator itCAMH =
155  lClassAvailabilityMapHolder.begin();
156 
157  // List of fare options
158  stdair::ClassList_StringList_T::const_iterator itClassList =
159  lClassPath.begin();
160 
161  // Browse both lists at the same time, i.e., one element per segment
162  for (; itCAMH != lClassAvailabilityMapHolder.end()
163  && itClassList != lClassPath.end(); ++itCAMH, ++itClassList) {
164 
165  // Retrieve the booking class list for the current segment
166  const stdair::ClassList_String_T& lCurrentClassList = *itClassList;
167  assert (lCurrentClassList.size() > 0);
168 
169  // TODO: instead of just extracting the first booking class,
170  // perform a choice on the full list of classes.
171  // Extract one booking class key (class code)
172  stdair::ClassCode_T lFirstClass;
173  lFirstClass.append (lCurrentClassList, 0, 1);
174 
175  // Retrieve the booking class map for the current segment
176  const stdair::ClassAvailabilityMap_T& lClassAvlMap = *itCAMH;
177 
178  // Retrieve the availability of the chosen booking class
179  const stdair::ClassAvailabilityMap_T::const_iterator itClassAvl =
180  lClassAvlMap.find (lFirstClass);
181 
182  if (itClassAvl == lClassAvlMap.end()) {
183  // DEBUG
184  STDAIR_LOG_DEBUG ("No availability has been set up for the class '"
185  << lFirstClass << "'. Travel solution: "
186  << ioTravelSolution.display());
187  }
188  assert (itClassAvl != lClassAvlMap.end());
189 
190  const stdair::Availability_T& lCurrentAvl = itClassAvl->second;
191  if (lAvl > lCurrentAvl) {
192  lAvl = lCurrentAvl;
193  }
194  }
195 
196  lFO.setAvailability (lAvl);
197 
198  //MODIF: availability display
199  STDAIR_LOG_DEBUG ("Fare option " << lFO.describe() << ", "
200  << "Availability " << lFO.getAvailability() << ", "
201  << "Segment Path " << oStr.str());
202  }
203  }
204 
205  // \todo: the following code must be either re-written or removed.
206  // There is indeed a lot of code duplication.
207  // ////////////////////////////////////////////////////////////////////
208  void InventoryManager::
209  calculateAvailabilityByRAE (stdair::TravelSolutionStruct& ioTravelSolution) {
210 
211  std::ostringstream oStr;
212  const stdair::SegmentPath_T& lSP = ioTravelSolution.getSegmentPath();
213  for (stdair::SegmentPath_T::const_iterator itSP = lSP.begin();
214  itSP != lSP.end(); itSP++) {
215  oStr << *itSP << ";";
216  }
217 
218  //Retrieve bid price vector and yield maps
219  const stdair::ClassYieldMapHolder_T& lClassYieldMapHolder =
220  ioTravelSolution.getClassYieldMapHolder();
221  const stdair::ClassBpvMapHolder_T& lClassBpvMapHolder =
222  ioTravelSolution.getClassBpvMapHolder();
223 
224  //Retrieve the list of fare options and browse it
225  stdair::FareOptionList_T& lFOList = ioTravelSolution.getFareOptionListRef();
226  for (stdair::FareOptionList_T::iterator itFO = lFOList.begin();
227  itFO != lFOList.end(); ++itFO) {
228 
229  stdair::FareOptionStruct& lFO = *itFO;
230 
231  stdair::ClassYieldMapHolder_T::const_iterator itCYM =
232  lClassYieldMapHolder.begin();
233  stdair::ClassBpvMapHolder_T::const_iterator itCBPM =
234  lClassBpvMapHolder.begin();
235 
236  const stdair::ClassList_StringList_T& lClassPath = lFO.getClassPath();
237 
238 
239  // Sanity checks
240  assert (lClassPath.size() == lClassYieldMapHolder.size());
241  assert (lClassPath.size() == lClassBpvMapHolder.size());
242 
243  // Browse class path, class-yield maps, class-(bid price vector) maps.
244  // Each iteration corresponds to one segment.
245 
246  std::ostringstream oCPStr;
247  for (stdair::ClassList_StringList_T::const_iterator itCL =
248  lClassPath.begin();
249  itCL != lClassPath.end(); ++itCL, ++itCYM, ++itCBPM) {
250 
251  // Class path determination
252  if (itCL == lClassPath.begin()) {
253  oCPStr << *itCL;
254 
255  } else {
256  oCPStr << "-" << *itCL;
257  }
258 
259  const stdair::ClassList_String_T& lCL = *itCL;
260  stdair::ClassCode_T lCC;
261  lCC.append (lCL, 0, 1);
262 
263  const stdair::ClassYieldMap_T& lCYM = *itCYM;
264  stdair::ClassYieldMap_T::const_iterator itCCCYM = lCYM.find (lCC);
265  assert (itCCCYM != lCYM.end());
266 
267  const stdair::ClassBpvMap_T& lCBPM = *itCBPM;
268  stdair::ClassBpvMap_T::const_iterator itCCCBPM = lCBPM.find (lCC);
269  assert (itCCCBPM != lCBPM.end());
270 
271  const stdair::BidPriceVector_T* lBidPriceVector_ptr = itCCCBPM->second;
272  assert (lBidPriceVector_ptr != NULL);
273 
274  // Initialization of fare option availability
275  if (itCL == lClassPath.begin()) {
276  lFO.setAvailability (lBidPriceVector_ptr->size());
277  }
278 
279  // Availability update
280  if (lFO.getAvailability() > 0) {
281 
282  //Segment availability calculation
283  stdair::BidPriceVector_T lReverseBPV (lBidPriceVector_ptr->size());
284  std::reverse_copy (lBidPriceVector_ptr->begin(),
285  lBidPriceVector_ptr->end(),
286  lReverseBPV.begin());
287 
288  const stdair::YieldValue_T& lYield = itCCCYM->second;
289  stdair::BidPriceVector_T::const_iterator lBidPrice =
290  std::upper_bound (lReverseBPV.begin(), lReverseBPV.end(), lYield);
291 
292  const stdair::Availability_T lAvl = lBidPrice - lReverseBPV.begin();
293 
294  // Availability update
295  lFO.setAvailability (std::min (lFO.getAvailability(), lAvl));
296  }
297  }
298 
299  // DEBUG
300  STDAIR_LOG_DEBUG ("Fare option: " << lFO.describe() << ", "
301  << "Availability: " << lFO.getAvailability() << ", "
302  << "Segment Path: " << oStr.str() << ", ");
303  }
304  }
305 
306  // \todo: the following code must be either re-written or removed.
307  // There is indeed a lot of code duplication.
308  // ////////////////////////////////////////////////////////////////////
309  void InventoryManager::
310  calculateAvailabilityByIBP (stdair::TravelSolutionStruct& ioTravelSolution) {
311  std::ostringstream oStr;
312 
313  // Yield valuation coefficient for multi-segment travel solutions
314  double alpha = 1.0;
315 
316  const stdair::SegmentPath_T& lSP = ioTravelSolution.getSegmentPath();
317  for (stdair::SegmentPath_T::const_iterator itSP = lSP.begin();
318  itSP != lSP.end(); itSP++) {
319  oStr << *itSP << ";";
320  }
321 
322  //Retrieve bid price vector and yield maps
323  const stdair::ClassYieldMapHolder_T& lClassYieldMapHolder =
324  ioTravelSolution.getClassYieldMapHolder();
325  const stdair::ClassBpvMapHolder_T& lClassBpvMapHolder =
326  ioTravelSolution.getClassBpvMapHolder();
327 
328  // Retrieve the list of fare options and browse it
329  stdair::FareOptionList_T& lFOList = ioTravelSolution.getFareOptionListRef();
330  for (stdair::FareOptionList_T::iterator itFO = lFOList.begin();
331  itFO != lFOList.end(); ++itFO) {
332 
333  stdair::FareOptionStruct& lFO = *itFO;
334 
335  stdair::ClassYieldMapHolder_T::const_iterator itCYM =
336  lClassYieldMapHolder.begin();
337  stdair::ClassBpvMapHolder_T::const_iterator itCBPM =
338  lClassBpvMapHolder.begin();
339 
340  const stdair::ClassList_StringList_T& lClassPath = lFO.getClassPath();
341 
342  // Sanity checks
343  assert (lClassPath.size() == lClassYieldMapHolder.size());
344  assert (lClassPath.size() == lClassBpvMapHolder.size());
345 
346  // Yield is taken to be equal to fare (connecting flights)
347 
348  // \todo: take yield instead
349  stdair::YieldValue_T lTotalYield = lFO.getFare();
350  // Bid price initialisation
351  stdair::BidPrice_T lTotalBidPrice = 0;
352 
353  // Browse class path, class-yield maps, class-(bid price vector) maps.
354  // Each iteration corresponds to one segment.
355 
356  std::ostringstream oCPStr;
357  for (stdair::ClassList_StringList_T::const_iterator itCL =
358  lClassPath.begin();
359  itCL != lClassPath.end(); ++itCL, ++itCYM, ++itCBPM) {
360 
361  // Class path determination
362  if (itCL == lClassPath.begin()) {
363  oCPStr << *itCL;
364 
365  } else {
366  oCPStr << "-" << *itCL;
367  }
368 
369  const stdair::ClassList_String_T& lCL = *itCL;
370  stdair::ClassCode_T lCC;
371  lCC.append (lCL, 0, 1);
372 
373  const stdair::ClassYieldMap_T& lCYM = *itCYM;
374  stdair::ClassYieldMap_T::const_iterator itCCCYM = lCYM.find (lCC);
375  assert (itCCCYM != lCYM.end());
376 
377  const stdair::ClassBpvMap_T& lCBPM = *itCBPM;
378  stdair::ClassBpvMap_T::const_iterator itCCCBPM = lCBPM.find (lCC);
379  assert (itCCCBPM != lCBPM.end());
380 
381  const stdair::BidPriceVector_T* lBidPriceVector_ptr = itCCCBPM->second;
382  assert (lBidPriceVector_ptr != NULL);
383 
384  //Initialization of fare option availability
385  if (itCL == lClassPath.begin()) {
386  lFO.setAvailability (lBidPriceVector_ptr->size());
387  }
388 
389  // Availability update
390  if (lFO.getAvailability() > 0) {
391  //Segment availability calculation
392  stdair::BidPriceVector_T lReverseBPV (lBidPriceVector_ptr->size());
393  std::reverse_copy (lBidPriceVector_ptr->begin(),
394  lBidPriceVector_ptr->end(), lReverseBPV.begin());
395 
396  const stdair::YieldValue_T& lYield = itCCCYM->second;
397  stdair::BidPriceVector_T::const_iterator lBidPrice =
398  std::upper_bound (lReverseBPV.begin(), lReverseBPV.end(), lYield);
399 
400  const stdair::Availability_T lAvl = lBidPrice - lReverseBPV.begin();
401 
402  // Availability update
403  lFO.setAvailability (std::min(lFO.getAvailability(), lAvl));
404  }
405 
406  // Total bid price calculation
407  if (lBidPriceVector_ptr->size() > 0) {
408  lTotalBidPrice += lBidPriceVector_ptr->back();
409 
410  } else {
411  lTotalBidPrice = std::numeric_limits<stdair::BidPrice_T>::max();
412  }
413 
414  // Total yield calculation (has been replaced by total fare).
415  //lTotalYield += lYield;
416  }
417  // Multi-segment bid price control
418 
419  if (lClassPath.size() > 1) {
420  if (lFO.getAvailability() > 0) {
421  const stdair::Availability_T lAvl =
422  alpha * lTotalYield >= lTotalBidPrice;
423  lFO.setAvailability (lAvl * lFO.getAvailability());
424 
425  } else {
426  const stdair::Availability_T lAvl =
427  alpha * lTotalYield >= lTotalBidPrice;
428  lFO.setAvailability (lAvl);
429  }
430 
431  // DEBUG
432  STDAIR_LOG_DEBUG ("Class: " << oCPStr.str()
433  << ", " << "Yield: " << alpha*lTotalYield << ", "
434  << "Bid price: " << lTotalBidPrice << ", "
435  << "Remaining capacity: " << "Undefined" << " "
436  << "Segment date: " << oStr.str());
437  }
438 
439  // DEBUG
440  STDAIR_LOG_DEBUG ("Fare option " << lFO.describe() << ", "
441  << "Availability " << lFO.getAvailability() << ", "
442  << "Segment Path " << oStr.str() << ", ");
443  }
444  }
445 
446  // \todo: the following code must be either re-written or removed.
447  // There is indeed a lot of code duplication.
448  // ////////////////////////////////////////////////////////////////////
449  void InventoryManager::
450  calculateAvailabilityByProtectiveIBP (stdair::TravelSolutionStruct& ioTravelSolution) {
451  std::ostringstream oStr;
452 
453  // Yield valuation coefficient for multi-segment travel solutions
454  double alpha = 1.0;
455 
456  const stdair::SegmentPath_T& lSP = ioTravelSolution.getSegmentPath();
457  for (stdair::SegmentPath_T::const_iterator itSP = lSP.begin();
458  itSP != lSP.end(); itSP++) {
459  oStr << *itSP << ";";
460  }
461 
462  //Retrieve bid price vector and yield maps
463  const stdair::ClassYieldMapHolder_T& lClassYieldMapHolder =
464  ioTravelSolution.getClassYieldMapHolder();
465  const stdair::ClassBpvMapHolder_T& lClassBpvMapHolder =
466  ioTravelSolution.getClassBpvMapHolder();
467 
468  //Retrieve the list of fare options and browse it
469  stdair::FareOptionList_T& lFOList = ioTravelSolution.getFareOptionListRef();
470  for (stdair::FareOptionList_T::iterator itFO = lFOList.begin();
471  itFO != lFOList.end(); ++itFO) {
472 
473  stdair::FareOptionStruct& lFO = *itFO;
474 
475  stdair::ClassYieldMapHolder_T::const_iterator itCYM =
476  lClassYieldMapHolder.begin();
477  stdair::ClassBpvMapHolder_T::const_iterator itCBPM =
478  lClassBpvMapHolder.begin();
479 
480  const stdair::ClassList_StringList_T& lClassPath = lFO.getClassPath();
481 
482  // Sanity checks
483  assert (lClassPath.size() == lClassYieldMapHolder.size());
484  assert (lClassPath.size() == lClassBpvMapHolder.size());
485 
486  // Yield is taken to be equal to fare (connecting flights)
487  // TODO : take yield instead
488  stdair::YieldValue_T lTotalYield = lFO.getFare();
489  // Bid price initialisation
490  stdair::BidPrice_T lTotalBidPrice = 0;
491  // Maximal bid price initialisation
492  stdair::BidPrice_T lMaxBidPrice = 0;
493 
494  //Browse class path, class-yield maps, class-(bid price vector) maps.
495  //Each iteration corresponds to one segment.
496 
497  std::ostringstream oCPStr;
498  for (stdair::ClassList_StringList_T::const_iterator itCL =
499  lClassPath.begin();
500  itCL != lClassPath.end(); ++itCL, ++itCYM, ++itCBPM) {
501 
502  // Class path determination
503  if (itCL == lClassPath.begin()) {
504  oCPStr << *itCL;
505 
506  } else {
507  oCPStr << "-" << *itCL;
508  }
509 
510  const stdair::ClassList_String_T& lCL = *itCL;
511  stdair::ClassCode_T lCC;
512  lCC.append (lCL, 0, 1);
513 
514  const stdair::ClassYieldMap_T& lCYM = *itCYM;
515  stdair::ClassYieldMap_T::const_iterator itCCCYM = lCYM.find (lCC);
516  assert (itCCCYM != lCYM.end());
517 
518  const stdair::YieldValue_T& lYield = itCCCYM->second;
519  const stdair::ClassBpvMap_T& lCBPM = *itCBPM;
520  stdair::ClassBpvMap_T::const_iterator itCCCBPM = lCBPM.find (lCC);
521  assert (itCCCBPM != lCBPM.end());
522 
523  const stdair::BidPriceVector_T* lBidPriceVector_ptr = itCCCBPM->second;
524  assert (lBidPriceVector_ptr != NULL);
525 
526  // Initialization of fare option availability
527  if (itCL == lClassPath.begin()) {
528  lFO.setAvailability (lBidPriceVector_ptr->size());
529  }
530 
531  // Availability update
532  if (lFO.getAvailability() > 0) {
533 
534  //Segment availability calculation
535  stdair::BidPriceVector_T lReverseBPV (lBidPriceVector_ptr->size());
536  std::reverse_copy (lBidPriceVector_ptr->begin(),
537  lBidPriceVector_ptr->end(), lReverseBPV.begin());
538 
539  stdair::BidPriceVector_T::const_iterator lBidPrice =
540  std::upper_bound (lReverseBPV.begin(), lReverseBPV.end(), lYield);
541 
542  const stdair::Availability_T lAvl = lBidPrice - lReverseBPV.begin();
543 
544  // Availability update
545  lFO.setAvailability (std::min(lFO.getAvailability(), lAvl));
546 
547  }
548 
549  // Total bid price calculation
550  if (lBidPriceVector_ptr->size() > 0) {
551  lTotalBidPrice += lBidPriceVector_ptr->back();
552 
553  if (lMaxBidPrice < lBidPriceVector_ptr->back()) {
554  lMaxBidPrice = lBidPriceVector_ptr->back();
555  }
556 
557  } else {
558  lTotalBidPrice = std::numeric_limits<stdair::BidPrice_T>::max();
559  }
560 
561  // Total yield calculation (has been replaced by total fare).
562  //lTotalYield += lYield;
563  }
564  // Multi-segment bid price control
565 
566  // Protective IBP (maximin): guarantees the minimal yield for each airline
567  // Proration factors are all equal to 1/{number of partners}.
568 
569  lTotalBidPrice = std::max (lMaxBidPrice * lClassPath.size(),
570  lTotalBidPrice);
571 
572  if (lClassPath.size() > 1) {
573  if (lFO.getAvailability() > 0) {
574  const stdair::Availability_T lAvl =
575  alpha * lTotalYield >= lTotalBidPrice;
576  lFO.setAvailability (lAvl * lFO.getAvailability());
577 
578  } else {
579  const stdair::Availability_T lAvl =
580  alpha * lTotalYield >= lTotalBidPrice;
581  lFO.setAvailability (lAvl);
582  }
583 
584  // DEBUG
585  STDAIR_LOG_DEBUG ("Class: " << oCPStr.str()
586  << ", " << "Yield: " << alpha*lTotalYield << ", "
587  << "Bid price: " << lTotalBidPrice << ", "
588  << "Remaining capacity: " << "Undefined" << " "
589  << "Segment date: " << oStr.str());
590  }
591 
592  // DEBUG
593  STDAIR_LOG_DEBUG ("Fare option " << lFO.describe() << ", "
594  << "Availability " << lFO.getAvailability() << ", "
595  << "Segment Path " << oStr.str() << ", ");
596  }
597  }
598 
599  //MODIF
600  // ////////////////////////////////////////////////////////////////////
601  void InventoryManager::setDefaultBidPriceVector (stdair::BomRoot& ioBomRoot) {
602 
603  const stdair::InventoryList_T& lInvList =
604  stdair::BomManager::getList<stdair::Inventory> (ioBomRoot);
605  for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
606  itInv != lInvList.end(); ++itInv) {
607  stdair::Inventory* lCurrentInv_ptr = *itInv;
608  assert (lCurrentInv_ptr != NULL);
609 
610  // Set the default bid price for own cabins.
611  setDefaultBidPriceVector (*lCurrentInv_ptr);
612 
613  // Check if the inventory contains images of partner inventories.
614  // If so, set the default bid price for their cabins.
615  if (stdair::BomManager::hasList<stdair::Inventory> (*lCurrentInv_ptr)) {
616  const stdair::InventoryList_T& lPartnerInvList =
617  stdair::BomManager::getList<stdair::Inventory> (*lCurrentInv_ptr);
618 
619  for (stdair::InventoryList_T::const_iterator itPartnerInv =
620  lPartnerInvList.begin();
621  itPartnerInv != lPartnerInvList.end(); ++itPartnerInv) {
622  stdair::Inventory* lCurrentPartnerInv_ptr = *itPartnerInv;
623  assert (lCurrentPartnerInv_ptr != NULL);
624 
625  setDefaultBidPriceVector (*lCurrentPartnerInv_ptr);
626  }
627  }
628  }
629  }
630 
631  // ////////////////////////////////////////////////////////////////////
632  void InventoryManager::
633  setDefaultBidPriceVector (stdair::Inventory& ioInventory) {
634 
635  const stdair::FlightDateList_T& lFlightDateList =
636  stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
637  for (stdair::FlightDateList_T::const_iterator itFlightDate =
638  lFlightDateList.begin();
639  itFlightDate != lFlightDateList.end(); ++itFlightDate) {
640  stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate;
641  assert (lCurrentFlightDate_ptr != NULL);
642 
643  // Check if the flight date holds a list of leg dates.
644  // If so retrieve it and initialise the bid price vectors of their cabins.
645  if (stdair::BomManager::hasList<stdair::LegDate> (*lCurrentFlightDate_ptr)) {
646  const stdair::LegDateList_T& lLegDateList =
647  stdair::BomManager::getList<stdair::LegDate> (*lCurrentFlightDate_ptr);
648  for (stdair::LegDateList_T::const_iterator itLegDate =
649  lLegDateList.begin();
650  itLegDate != lLegDateList.end(); ++itLegDate) {
651  stdair::LegDate* lCurrentLegDate_ptr = *itLegDate;
652  assert (lCurrentLegDate_ptr != NULL);
653 
654  const stdair::LegCabinList_T& lLegCabinList =
655  stdair::BomManager::getList<stdair::LegCabin> (*lCurrentLegDate_ptr);
656  for (stdair::LegCabinList_T::const_iterator itLegCabin =
657  lLegCabinList.begin();
658  itLegCabin != lLegCabinList.end(); ++itLegCabin) {
659  stdair::LegCabin* lCurrentLegCabin_ptr = *itLegCabin;
660  assert (lCurrentLegCabin_ptr != NULL);
661 
662  const stdair::CabinCapacity_T& lCabinCapacity =
663  lCurrentLegCabin_ptr->getPhysicalCapacity();
664  lCurrentLegCabin_ptr->emptyBidPriceVector();
665 
666  stdair::BidPriceVector_T& lBPV =
667  lCurrentLegCabin_ptr->getBidPriceVector();
668 
669  //for (stdair::CabinCapacity_T k = 0;k!=lCabinCapacity;k++) {lBPV.push_back(400 + 300/sqrt(k+1));}
670  for (stdair::CabinCapacity_T k = 0; k != lCabinCapacity; k++) {
671  lBPV.push_back (400);
672  }
673 
674  lCurrentLegCabin_ptr->setPreviousBidPrice (lBPV.back());
675  lCurrentLegCabin_ptr->setCurrentBidPrice (lBPV.back());
676  }
677  }
678  }
679  }
680  }
681 
682  // ////////////////////////////////////////////////////////////////////
683  bool InventoryManager::sell (stdair::Inventory& ioInventory,
684  const std::string& iSegmentDateKey,
685  const stdair::ClassCode_T& iClassCode,
686  const stdair::PartySize_T& iPartySize) {
687 
688  // Make the sale within the inventory.
689  return InventoryHelper::sell (ioInventory, iSegmentDateKey,
690  iClassCode, iPartySize);
691  }
692 
693  // ////////////////////////////////////////////////////////////////////
694  bool InventoryManager::sell (const stdair::BookingClassID_T& iClassID,
695  const stdair::PartySize_T& iPartySize) {
696 
697  // Make the sale within the inventory.
698  return InventoryHelper::sell (iClassID, iPartySize);
699  }
700 
701  // ////////////////////////////////////////////////////////////////////
702  bool InventoryManager::cancel (stdair::Inventory& ioInventory,
703  const std::string& iSegmentDateKey,
704  const stdair::ClassCode_T& iClassCode,
705  const stdair::PartySize_T& iPartySize) {
706 
707  // Make the cancellation within the inventory.
708  return InventoryHelper::cancel (ioInventory, iSegmentDateKey,
709  iClassCode, iPartySize);
710  }
711 
712  // ////////////////////////////////////////////////////////////////////
713  bool InventoryManager::cancel (const stdair::BookingClassID_T& iClassID,
714  const stdair::PartySize_T& iPartySize) {
715 
716  // Make the cancellation within the inventory.
717  return InventoryHelper::cancel (iClassID, iPartySize);
718  }
719 
720  // ////////////////////////////////////////////////////////////////////
721  void InventoryManager::
722  updateBookingControls (stdair::FlightDate& ioFlightDate) {
723 
724  // Forward the call to FlightDateHelper.
726  }
727 
728  // ////////////////////////////////////////////////////////////////////
729  void InventoryManager::
730  recalculateAvailability (stdair::FlightDate& ioFlightDate) {
731 
732  // Forward the call to FlightDateHelper.
734  }
735 
736  // ////////////////////////////////////////////////////////////////////
737  void InventoryManager::takeSnapshots(const stdair::Inventory& iInventory,
738  const stdair::DateTime_T& iSnapshotTime){
739 
740  // Make the snapshots within the inventory
741  InventoryHelper::takeSnapshots (iInventory, iSnapshotTime);
742  }
743 
744  // ////////////////////////////////////////////////////////////////////
745  void InventoryManager::
746  createDirectAccesses (const stdair::BomRoot& iBomRoot) {
747 
748  // Browse the list of inventories and create direct accesses
749  // within each inventory.
750  const stdair::InventoryList_T& lInvList =
751  stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
752  for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
753  itInv != lInvList.end(); ++itInv) {
754  stdair::Inventory* lCurrentInv_ptr = *itInv;
755  assert (lCurrentInv_ptr != NULL);
756 
757  createDirectAccesses (iBomRoot, *lCurrentInv_ptr);
758  }
759 
760  // Browse the list of inventories and create partner accesses
761  // within each inventory.
762  for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
763  itInv != lInvList.end(); ++itInv) {
764  stdair::Inventory* lCurrentInv_ptr = *itInv;
765  assert (lCurrentInv_ptr != NULL);
766 
767  createPartnerAccesses (iBomRoot, *lCurrentInv_ptr);
768  }
769 
770  // Fill some attributes of segment-date with the routing legs.
771  BomRootHelper::fillFromRouting (iBomRoot);
772  }
773 
774  // ////////////////////////////////////////////////////////////////////
775  void InventoryManager::
776  createDirectAccesses (const stdair::BomRoot& iBomRoot,
777  stdair::Inventory& ioInventory) {
778 
779  // Browse the list of flight-dates and create direct accesses
780  // within each flight-date.
781  const stdair::FlightDateList_T& lFlightDateList =
782  stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
783  for (stdair::FlightDateList_T::const_iterator itFlightDate =
784  lFlightDateList.begin();
785  itFlightDate != lFlightDateList.end(); ++itFlightDate) {
786  stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate;
787  assert (lCurrentFlightDate_ptr != NULL);
788 
789  createDirectAccesses (iBomRoot, ioInventory, *lCurrentFlightDate_ptr);
790  }
791 
792  // Browse the list of inventories and create direct accesses
793  // within each inventory.
794  const bool hasInventoryList =
795  stdair::BomManager::hasList<stdair::Inventory> (ioInventory);
796  if (hasInventoryList == true) {
797  const stdair::InventoryList_T& lInvList =
798  stdair::BomManager::getList<stdair::Inventory> (ioInventory);
799  for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
800  itInv != lInvList.end(); ++itInv) {
801  stdair::Inventory* lCurrentInv_ptr = *itInv;
802  assert (lCurrentInv_ptr != NULL);
803 
804  createDirectAccesses (iBomRoot, *lCurrentInv_ptr);
805  }
806  }
807  }
808 
809  // ////////////////////////////////////////////////////////////////////
810  void InventoryManager::
811  createDirectAccesses (const stdair::BomRoot& ioBomRoot,
812  stdair::Inventory& ioInventory,
813  stdair::FlightDate& ioFlightDate) {
814 
815  bool areSegmentAndRoutingLegLinked = false;
816 
817  // Browse the list of segment-dates and create direct accesses
818  // within each segment-date.
819  const stdair::SegmentDateList_T& lSegmentDateList =
820  stdair::BomManager::getList<stdair::SegmentDate> (ioFlightDate);
821  for (stdair::SegmentDateList_T::const_iterator itSegmentDate =
822  lSegmentDateList.begin();
823  itSegmentDate != lSegmentDateList.end(); ++itSegmentDate) {
824 
825  stdair::SegmentDate* lCurrentSegmentDate_ptr = *itSegmentDate;
826  assert (lCurrentSegmentDate_ptr != NULL);
827 
828  // Get the routing leg keys list
829  const stdair::RoutingLegKeyList_T& lRoutingLegKeyList =
830  lCurrentSegmentDate_ptr->getLegKeyList ();
831 
832  // Browse the list of routing leg keys and try to create direct accesses
833  // with each corresponding leg date.
834  for (stdair::RoutingLegKeyList_T::const_iterator itRoutingLegKey =
835  lRoutingLegKeyList.begin();
836  itRoutingLegKey != lRoutingLegKeyList.end(); ++itRoutingLegKey) {
837 
838  // Try to retrieve the routing LegDate within the flight date
839  stdair::LegDate* lLegDate_ptr = stdair::BomRetriever::
840  retrieveOperatingLegDateFromLongKey (ioFlightDate, *itRoutingLegKey);
841 
842  if (lLegDate_ptr != NULL) {
843 
844  // Link the SegmentDate and LegDate together
845  stdair::FacBomManager::addToListAndMap (*lCurrentSegmentDate_ptr,
846  *lLegDate_ptr);
847  stdair::FacBomManager::addToListAndMap (*lLegDate_ptr,
848  *lCurrentSegmentDate_ptr);
849  areSegmentAndRoutingLegLinked = true;
850  }
851  }
852  if (areSegmentAndRoutingLegLinked == true) {
853  createDirectAccesses (*lCurrentSegmentDate_ptr);
854  }
855  }
856  }
857 
858  // ////////////////////////////////////////////////////////////////////
859  void InventoryManager::
860  createDirectAccesses (stdair::SegmentDate& ioSegmentDate) {
861 
862  // Browse the list of segment-cabins and create direct accesses
863  // within each segment-cabin.
864  const stdair::SegmentCabinList_T& lSegmentCabinList =
865  stdair::BomManager::getList<stdair::SegmentCabin> (ioSegmentDate);
866  for (stdair::SegmentCabinList_T::const_iterator itSegmentCabin =
867  lSegmentCabinList.begin();
868  itSegmentCabin != lSegmentCabinList.end(); ++itSegmentCabin) {
869 
870  //
871  stdair::SegmentCabin* lCurrentSegmentCabin_ptr = *itSegmentCabin;
872  assert (lCurrentSegmentCabin_ptr != NULL);
873 
874  //
875  const stdair::CabinCode_T& lCabinCode =
876  lCurrentSegmentCabin_ptr->getCabinCode();
877 
878  // Iterate on the routing legs
879  const stdair::LegDateList_T& lLegDateList =
880  stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
881  for (stdair::LegDateList_T::const_iterator itLegDate =
882  lLegDateList.begin();
883  itLegDate != lLegDateList.end(); ++itLegDate) {
884 
885  const stdair::LegDate* lCurrentLegDate_ptr = *itLegDate;
886  assert (lCurrentLegDate_ptr != NULL);
887 
888  // Retrieve the LegCabin getting the same class of service
889  // (cabin code) as the SegmentCabin.
890  stdair::LegCabin& lLegCabin = stdair::BomManager::
891  getObject<stdair::LegCabin> (*lCurrentLegDate_ptr, lCabinCode);
892 
903  stdair::FacBomManager::addToListAndMap (*lCurrentSegmentCabin_ptr,
904  lLegCabin,
905  lLegCabin.getFullerKey());
906 
917  stdair::FacBomManager::
918  addToListAndMap (lLegCabin, *lCurrentSegmentCabin_ptr,
919  lCurrentSegmentCabin_ptr->getFullerKey());
920  }
921  }
922  }
923 
924  // ////////////////////////////////////////////////////////////////////
925  void InventoryManager::
926  createPartnerAccesses (const stdair::BomRoot& iBomRoot,
927  stdair::Inventory& ioInventory) {
928 
929  // Browse the list of flight-dates and create partner accesses
930  // within each flight-date.
931  const stdair::FlightDateList_T& lFlightDateList =
932  stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
933  for (stdair::FlightDateList_T::const_iterator itFlightDate =
934  lFlightDateList.begin();
935  itFlightDate != lFlightDateList.end(); ++itFlightDate) {
936  stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate;
937  assert (lCurrentFlightDate_ptr != NULL);
938 
939  createPartnerAccesses (iBomRoot, ioInventory, *lCurrentFlightDate_ptr);
940  }
941  }
942 
943  // ////////////////////////////////////////////////////////////////////
944  void InventoryManager::
945  createPartnerAccesses (const stdair::BomRoot& ioBomRoot,
946  stdair::Inventory& ioInventory,
947  stdair::FlightDate& ioFlightDate) {
948 
949  // Browse the list of segment-dates and create partner accesses
950  // within each segment-date.
951  const stdair::SegmentDateList_T& lSegmentDateList =
952  stdair::BomManager::getList<stdair::SegmentDate> (ioFlightDate);
953  for (stdair::SegmentDateList_T::const_iterator itSegmentDate =
954  lSegmentDateList.begin();
955  itSegmentDate != lSegmentDateList.end(); ++itSegmentDate) {
956 
957  stdair::SegmentDate* lCurrentSegmentDate_ptr = *itSegmentDate;
958  assert (lCurrentSegmentDate_ptr != NULL);
959 
960  // Get the routing leg keys list
961  const stdair::RoutingLegKeyList_T& lRoutingLegKeyList =
962  lCurrentSegmentDate_ptr->getLegKeyList ();
963 
964  // Browse the list of routing leg keys and try to create partner accesses
965  // with each corresponding leg date.
966  for (stdair::RoutingLegKeyList_T::const_iterator itRoutingLegKey =
967  lRoutingLegKeyList.begin();
968  itRoutingLegKey != lRoutingLegKeyList.end(); ++itRoutingLegKey) {
969 
970  // Try to retrieve the LegDate getting that Boarding Point within the
971  // flight date
972  stdair::LegDate* lLegDate_ptr = stdair::BomRetriever::
973  retrieveOperatingLegDateFromLongKey (ioFlightDate, *itRoutingLegKey);
974 
975  // If there is no LegDate getting that Boarding Point within the flight
976  // date, the segment is operating by a partner
977  if (lLegDate_ptr == NULL) {
978 
979  // Retrieve the (unique) operating LegDate getting that Boarding Point
980  // within the partner inventory
981  std::ostringstream lRoutingSegmentKey;
982  lRoutingSegmentKey << *itRoutingLegKey << ";"
983  << lCurrentSegmentDate_ptr->getOffPoint();
984 
985  stdair::SegmentDate* lPartnerOperatingSegmentDate_ptr =
986  stdair::BomRetriever::
987  retrievePartnerSegmentDateFromLongKey (ioInventory,
988  lRoutingSegmentKey.str());
989  assert (lPartnerOperatingSegmentDate_ptr != NULL);
990 
991  // Link the current segment date with its operating one
992  stdair::FacBomManager::linkWithOperating (*lCurrentSegmentDate_ptr,
993  *lPartnerOperatingSegmentDate_ptr);
994 
995  stdair::SegmentDate* lOperatingSegmentDate_ptr =
996  stdair::BomRetriever::
997  retrieveSegmentDateFromLongKey (ioBomRoot,
998  lRoutingSegmentKey.str());
999  assert(lOperatingSegmentDate_ptr != NULL);
1000 
1001  stdair::Inventory* lInventory_ptr =
1002  stdair::BomRetriever::
1003  retrieveInventoryFromLongKey (ioBomRoot, *itRoutingLegKey);
1004  assert (lInventory_ptr != NULL);
1005 
1006  std::ostringstream lRoutingSegment;
1007  lRoutingSegment << ioFlightDate.getAirlineCode() << ";"
1008  << ioFlightDate.describeKey() << ";"
1009  << lCurrentSegmentDate_ptr->getBoardingPoint() << ";"
1010  << lCurrentSegmentDate_ptr->getOffPoint();
1011 
1012  stdair::SegmentDate* lPartnerMarketingSegmentDate_ptr =
1013  stdair::BomRetriever::
1014  retrievePartnerSegmentDateFromLongKey (*lInventory_ptr, lRoutingSegment.str());
1015  assert(lPartnerMarketingSegmentDate_ptr != NULL);
1016 
1017  stdair::FacBomManager::addToList (*lOperatingSegmentDate_ptr, *lPartnerMarketingSegmentDate_ptr);
1018 
1019  }
1020  }
1021  }
1022  }
1023 
1024 
1025  // ////////////////////////////////////////////////////////////////////
1026  void InventoryManager::
1027  buildSimilarSegmentCabinSets (const stdair::BomRoot& iBomRoot) {
1028  // Browse the list of inventories and create direct accesses
1029  // within each inventory.
1030  const stdair::InventoryList_T& lInvList =
1031  stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
1032  for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
1033  itInv != lInvList.end(); ++itInv) {
1034  stdair::Inventory* lCurrentInv_ptr = *itInv;
1035  assert (lCurrentInv_ptr != NULL);
1036 
1037  buildSimilarSegmentCabinSets (*lCurrentInv_ptr);
1038  }
1039  }
1040 
1041  // ////////////////////////////////////////////////////////////////////
1042  void InventoryManager::
1043  buildSimilarSegmentCabinSets (stdair::Inventory& ioInventory) {
1044  // For instance, we consider two flight-dates are
1045  // similar if they have the same flight number and the same
1046  // day-of-the-week departure.
1047 
1048  // Browse the segment-cabin list and build the sets of segment-cabin
1049  // which have the same flight number and origin-destination
1051 
1052  // Browsing the flight-date list
1053  const stdair::FlightDateList_T& lFlightDateList =
1054  stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
1055  for (stdair::FlightDateList_T::const_iterator itFD= lFlightDateList.begin();
1056  itFD != lFlightDateList.end(); ++itFD) {
1057  const stdair::FlightDate* lFD_ptr = *itFD;
1058  assert (lFD_ptr != NULL);
1059  const stdair::FlightNumber_T& lFlightNumber = lFD_ptr->getFlightNumber();
1060 
1061  // Browsing the segment-date list and retrieve the departure
1062  // date, the origine and the destination of the segment
1063  const stdair::SegmentDateList_T& lSegmentDateList =
1064  stdair::BomManager::getList<stdair::SegmentDate> (*lFD_ptr);
1065  for (stdair::SegmentDateList_T::const_iterator itSD =
1066  lSegmentDateList.begin(); itSD != lSegmentDateList.end(); ++itSD) {
1067  const stdair::SegmentDate* lSD_ptr = *itSD;
1068  assert (lSD_ptr != NULL);
1069 
1070  const stdair::Date_T& lDepartureDate = lSD_ptr->getBoardingDate();
1071  const stdair::AirportCode_T& lOrigin = lSD_ptr->getBoardingPoint();
1072  const stdair::AirportCode_T& lDestination = lSD_ptr->getOffPoint();
1073 
1074  // Browsing the segment-cabin list and retrieve the cabin code and
1075  // build the corresponding key map.
1076  const stdair::SegmentCabinList_T& lSegmentCabinList =
1077  stdair::BomManager::getList<stdair::SegmentCabin> (*lSD_ptr);
1078  for (stdair::SegmentCabinList_T::const_iterator itSC =
1079  lSegmentCabinList.begin();
1080  itSC != lSegmentCabinList.end(); ++itSC) {
1081  stdair::SegmentCabin* lSC_ptr = *itSC;
1082  assert (lSC_ptr != NULL);
1083 
1084  std::ostringstream oStr;
1085  oStr << lFlightNumber << lDepartureDate.day_of_week()
1086  << lOrigin << lDestination << lSC_ptr->getCabinCode();
1087  const std::string lMapKey = oStr.str();
1088 
1089  // Add the segment cabin to the similar segment cabin set map.
1090  SimilarSegmentCabinSetMap_T::iterator itSSCS = lSSCSM.find (lMapKey);
1091  if (itSSCS == lSSCSM.end()) {
1093  lDDSCMap.insert (DepartureDateSegmentCabinMap_T::
1094  value_type (lDepartureDate, lSC_ptr));
1095  lSSCSM.insert (SimilarSegmentCabinSetMap_T::
1096  value_type (lMapKey, lDDSCMap));
1097  } else {
1098  DepartureDateSegmentCabinMap_T& lDDSCMap = itSSCS->second;
1099  lDDSCMap.insert (DepartureDateSegmentCabinMap_T::
1100  value_type (lDepartureDate, lSC_ptr));
1101  }
1102  }
1103  }
1104  }
1105 
1106  // Initialise the segment data table.
1107  stdair::TableID_T lTableID = 1;
1108  for (SimilarSegmentCabinSetMap_T::const_iterator itSSCS = lSSCSM.begin();
1109  itSSCS != lSSCSM.end(); ++itSSCS, ++lTableID) {
1110  const DepartureDateSegmentCabinMap_T& lDDSCMap = itSSCS->second;
1111 
1112  buildSegmentSnapshotTable (ioInventory, lTableID, lDDSCMap);
1113  }
1114  }
1115 
1116  // ////////////////////////////////////////////////////////////////////
1117  void InventoryManager::
1118  buildSegmentSnapshotTable (stdair::Inventory& ioInventory,
1119  const stdair::TableID_T& iTableID,
1120  const DepartureDateSegmentCabinMap_T& iDDSCMap) {
1121  // Build an empty segment data table.
1122  const stdair::SegmentSnapshotTableKey lKey (iTableID);
1123  stdair::SegmentSnapshotTable& lSegmentSnapshotTable =
1124  stdair::FacBom<stdair::SegmentSnapshotTable>::instance().create (lKey);
1125  stdair::FacBomManager::addToListAndMap (ioInventory, lSegmentSnapshotTable);
1126 
1127  // Build the value type index map.
1128  DepartureDateSegmentCabinMap_T::const_iterator itDDSC = iDDSCMap.begin();
1129  assert (itDDSC != iDDSCMap.end());
1130  const stdair::SegmentCabin* lSegmentCabin_ptr = itDDSC->second;
1131 
1132  // Browse the booking class list and build the value type for the classes
1133  // as well as for the cabin (Q-equivalent).
1134  stdair::ClassIndexMap_T lClassIndexMap;
1135  stdair::ClassIndex_T lClassIndex = 0;
1136  std::ostringstream lSCMapKey;
1137  lSCMapKey << stdair::DEFAULT_SEGMENT_CABIN_VALUE_TYPE
1138  << lSegmentCabin_ptr->describeKey();
1139  lClassIndexMap.insert (stdair::ClassIndexMap_T::
1140  value_type (lSCMapKey.str(), lClassIndex));
1141  ++lClassIndex;
1142 
1143  // Browse the booking class list
1144  const stdair::BookingClassList_T& lBCList =
1145  stdair::BomManager::getList<stdair::BookingClass>(*lSegmentCabin_ptr);
1146  for (stdair::BookingClassList_T::const_iterator itBC= lBCList.begin();
1147  itBC != lBCList.end(); ++itBC) {
1148  const stdair::BookingClass* lBookingClass_ptr = *itBC;
1149  assert (lBookingClass_ptr != NULL);
1150  lClassIndexMap.
1151  insert (stdair::ClassIndexMap_T::
1152  value_type(lBookingClass_ptr->describeKey(),lClassIndex));
1153  ++lClassIndex;
1154  }
1155 
1156  // Build the segment-cabin index map
1157  stdair::SegmentCabinIndexMap_T lSegmentCabinIndexMap;
1158  stdair::SegmentDataID_T lSegmentDataID = 0;
1159  for (; itDDSC != iDDSCMap.end(); ++itDDSC, ++lSegmentDataID) {
1160  stdair::SegmentCabin* lCurrentSC_ptr = itDDSC->second;
1161  assert (lCurrentSC_ptr != NULL);
1162  lSegmentCabinIndexMap.
1163  insert (stdair::SegmentCabinIndexMap_T::value_type (lCurrentSC_ptr,
1164  lSegmentDataID));
1165 
1166  // Added the data table to the segment-cabin.
1167  lCurrentSC_ptr->setSegmentSnapshotTable (lSegmentSnapshotTable);
1168  }
1169 
1170  // Initialise the segment data table.
1171  lSegmentSnapshotTable.initSnapshotBlocks(lSegmentCabinIndexMap,
1172  lClassIndexMap);
1173  }
1174 
1175  // ////////////////////////////////////////////////////////////////////
1176  void InventoryManager::initSnapshotEvents (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
1177  const stdair::Date_T& iStartDate,
1178  const stdair::Date_T& iEndDate) {
1179  const stdair::Duration_T lTimeZero (0, 0, 0);
1180  const stdair::Duration_T lOneDayDuration (24, 0, 0);
1181  const stdair::DateTime_T lBeginSnapshotTime (iStartDate, lTimeZero);
1182  const stdair::DateTime_T lEndSnapshotTime (iEndDate, lTimeZero);
1183 
1184  // TODO: remove the defaut airline code.
1185  stdair::NbOfEvents_T lNbOfSnapshots = 0.0;
1186  for (stdair::DateTime_T lSnapshotTime = lBeginSnapshotTime;
1187  lSnapshotTime < lEndSnapshotTime; lSnapshotTime += lOneDayDuration) {
1188  // Create the snapshot event structure
1189  stdair::SnapshotPtr_T lSnapshotStruct =
1190  boost::make_shared<stdair::SnapshotStruct>(stdair::DEFAULT_AIRLINE_CODE,
1191  lSnapshotTime);
1192  // Create the event structure
1193  stdair::EventStruct lEventStruct (stdair::EventType::SNAPSHOT,
1194  lSnapshotStruct);
1195 
1203  ioSEVMGR_ServicePtr->addEvent (lEventStruct);
1204  ++lNbOfSnapshots;
1205  }
1206 
1207  // Update the status of snap shots within the event queue.
1208  ioSEVMGR_ServicePtr->addStatus (stdair::EventType::SNAPSHOT, lNbOfSnapshots);
1209  }
1210 
1211  // ////////////////////////////////////////////////////////////////////
1212  void InventoryManager::
1213  initRMEvents (const stdair::Inventory& iInventory,
1214  stdair::RMEventList_T& ioRMEventList,
1215  const stdair::Date_T& iStartDate,
1216  const stdair::Date_T& iEndDate) {
1217  const stdair::Duration_T lTimeZero (0, 0, 0);
1218  const stdair::Duration_T lTime (0, 0, 10);
1219  const stdair::Duration_T lOneDayDuration (24, 0, 0);
1220  const stdair::DateTime_T lEarliestEventTime (iStartDate, lTimeZero);
1221  const stdair::DateTime_T lLatestEventTime (iEndDate, lTimeZero);
1222 
1223  const stdair::AirlineCode_T& lAirlineCode = iInventory.getAirlineCode();
1224 
1225  // Browse the list of flight-dates and initialise the RM events for
1226  // each flight-date.
1227  const stdair::FlightDateList_T& lFDList =
1228  stdair::BomManager::getList<stdair::FlightDate> (iInventory);
1229  for (stdair::FlightDateList_T::const_iterator itFD = lFDList.begin();
1230  itFD != lFDList.end(); ++itFD) {
1231  const stdair::FlightDate* lFD_ptr = *itFD;
1232  assert (lFD_ptr != NULL);
1233 
1234  // Retrive the departure date and initialise the RM events with
1235  // the data collection points of the inventory.
1236  const stdair::Date_T& lDepartureDate = lFD_ptr->getDepartureDate();
1237  const stdair::DateTime_T lDepatureDateTime (lDepartureDate, lTime);
1238  for (stdair::DCPList_T::const_iterator itDCP =
1239  stdair::DEFAULT_DCP_LIST.begin();
1240  itDCP != stdair::DEFAULT_DCP_LIST.end(); ++itDCP) {
1241  const stdair::DCP_T& lDCP = *itDCP;
1242 
1243  // Create the event time and check if it is in the validate interval
1244  const stdair::DateTime_T lEventTime =
1245  lDepatureDateTime - lOneDayDuration * lDCP;
1246  if (lEventTime >= lEarliestEventTime && lEventTime <= lLatestEventTime){
1247  const stdair::KeyDescription_T lKeyDes = lFD_ptr->describeKey();
1248  stdair::RMEventStruct lRMEvent (lAirlineCode, lKeyDes, lEventTime);
1249  ioRMEventList.push_back (lRMEvent);
1250  }
1251  }
1252  }
1253  }
1254 
1255  // ////////////////////////////////////////////////////////////////////
1256  void InventoryManager::
1257  addRMEventsToEventQueue (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_ServicePtr,
1258  stdair::RMEventList_T& ioRMEventList) {
1259  // Browse the RM event list and add them to the queue.
1260  for (stdair::RMEventList_T::iterator itRMEvent = ioRMEventList.begin();
1261  itRMEvent != ioRMEventList.end(); ++itRMEvent) {
1262  stdair::RMEventStruct& lRMEvent = *itRMEvent;
1263  stdair::RMEventPtr_T lRMEventPtr =
1264  boost::make_shared<stdair::RMEventStruct> (lRMEvent);
1265  stdair::EventStruct lEventStruct (stdair::EventType::RM, lRMEventPtr);
1266  ioSEVMGR_ServicePtr->addEvent (lEventStruct);
1267  }
1268 
1269  // Update the status of RM events within the event queue.
1270  const stdair::Count_T lRMEventListSize = ioRMEventList.size();
1271  ioSEVMGR_ServicePtr->addStatus (stdair::EventType::RM, lRMEventListSize);
1272 
1273  }
1274 
1275  // ////////////////////////////////////////////////////////////////////
1276  void InventoryManager::
1277  initialiseYieldBasedNestingStructures (const stdair::BomRoot& iBomRoot) {
1278  // DEBUG
1279  STDAIR_LOG_DEBUG ("Initialise the yield-based nesting structure for "
1280  << "all segment-cabins");
1281 
1282  // Browse the list of inventories
1283  const stdair::InventoryList_T& lInvList =
1284  stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
1285 
1286  // Browse the inventories
1287  for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
1288  itInv != lInvList.end(); ++itInv) {
1289  stdair::Inventory* lCurrentInv_ptr = *itInv;
1290  assert (lCurrentInv_ptr != NULL);
1291  const stdair::FlightDateList_T& lFlightDateList =
1292  stdair::BomManager::getList<stdair::FlightDate> (*lCurrentInv_ptr);
1293 
1294  // Browse the flight dates
1295  for (stdair::FlightDateList_T::const_iterator itFD =
1296  lFlightDateList.begin(); itFD != lFlightDateList.end(); ++itFD) {
1297  const stdair::FlightDate* lFD_ptr = *itFD;
1298  assert (lFD_ptr != NULL);
1299  const stdair::SegmentDateList_T& lSegmentDateList =
1300  stdair::BomManager::getList<stdair::SegmentDate> (*lFD_ptr);
1301 
1302  // Browse the segment dates
1303  for (stdair::SegmentDateList_T::const_iterator itSD =
1304  lSegmentDateList.begin(); itSD != lSegmentDateList.end(); ++itSD) {
1305  const stdair::SegmentDate* lSD_ptr = *itSD;
1306  assert (lSD_ptr != NULL);
1307  const stdair::SegmentCabinList_T& lSegmentCabinList =
1308  stdair::BomManager::getList<stdair::SegmentCabin> (*lSD_ptr);
1309 
1310  // Browse the segment cabins
1311  for (stdair::SegmentCabinList_T::const_iterator itSC =
1312  lSegmentCabinList.begin(); itSC != lSegmentCabinList.end();
1313  ++itSC) {
1314  stdair::SegmentCabin* lSC_ptr = *itSC;
1315  assert (lSC_ptr != NULL);
1316 
1317  // Initialise the nesting structure of the segment cabin
1319  }
1320  }
1321  }
1322  }
1323  }
1324 
1325  // ////////////////////////////////////////////////////////////////////
1326  void InventoryManager::
1327  initialiseListsOfUsablePolicies (const stdair::BomRoot& iBomRoot) {
1328  // Browse the list of inventories
1329  const stdair::InventoryList_T& lInvList =
1330  stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
1331 
1332  // Browse the inventories
1333  for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
1334  itInv != lInvList.end(); ++itInv) {
1335  stdair::Inventory* lCurrentInv_ptr = *itInv;
1336  assert (lCurrentInv_ptr != NULL);
1337 
1338  // Create the policies if the optimisation method uses Marginal
1339  // Revenue Transformation
1340  stdair::PreOptimisationMethod::EN_PreOptimisationMethod lPreOptMethod =
1341  lCurrentInv_ptr->getPreOptimisationMethod();
1342 
1343  if (lPreOptMethod == stdair::PreOptimisationMethod::MRT) {
1344  const stdair::FlightDateList_T& lFlightDateList =
1345  stdair::BomManager::getList<stdair::FlightDate> (*lCurrentInv_ptr);
1346 
1347  // Browse the flight dates
1348  for (stdair::FlightDateList_T::const_iterator itFD =
1349  lFlightDateList.begin(); itFD != lFlightDateList.end(); ++itFD) {
1350  const stdair::FlightDate* lFD_ptr = *itFD;
1351  assert (lFD_ptr != NULL);
1352  const stdair::SegmentDateList_T& lSegmentDateList =
1353  stdair::BomManager::getList<stdair::SegmentDate> (*lFD_ptr);
1354 
1355  // Browse the segment dates
1356  for (stdair::SegmentDateList_T::const_iterator itSD =
1357  lSegmentDateList.begin();
1358  itSD != lSegmentDateList.end(); ++itSD) {
1359  const stdair::SegmentDate* lSD_ptr = *itSD;
1360  assert (lSD_ptr != NULL);
1361  const stdair::SegmentCabinList_T& lSegmentCabinList =
1362  stdair::BomManager::getList<stdair::SegmentCabin> (*lSD_ptr);
1363 
1364  // Browse the segment cabins
1365  for (stdair::SegmentCabinList_T::const_iterator itSC =
1366  lSegmentCabinList.begin(); itSC != lSegmentCabinList.end();
1367  ++itSC) {
1368  stdair::SegmentCabin* lSC_ptr = *itSC;
1369  assert (lSC_ptr != NULL);
1370 
1371  if (lSC_ptr->getFareFamilyStatus() == true) {
1372  // Initialise the nesting structure of the segment cabin
1374  }
1375  }
1376  }
1377  }
1378  }
1379  }
1380  }
1381 
1382 }