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