StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LegCabin.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
12 #include <stdair/bom/LegDate.hpp>
13 #include <stdair/bom/LegCabin.hpp>
14 
15 
16 namespace stdair {
17 
18  // ////////////////////////////////////////////////////////////////////
19  LegCabin::LegCabin() : _key (DEFAULT_CABIN_CODE), _parent (NULL) {
20  assert (false);
21  }
22 
23  // ////////////////////////////////////////////////////////////////////
24  LegCabin::LegCabin (const LegCabin&)
25  : _key (DEFAULT_CABIN_CODE), _parent (NULL) {
26  assert (false);
27  }
28 
29  // ////////////////////////////////////////////////////////////////////
30  LegCabin::LegCabin (const Key_T& iKey)
31  : _key (iKey), _parent (NULL),
32  _offeredCapacity (DEFAULT_CABIN_CAPACITY),
33  _physicalCapacity (DEFAULT_CABIN_CAPACITY),
34  _soldSeat (DEFAULT_CLASS_NB_OF_BOOKINGS),
35  _committedSpace (DEFAULT_COMMITTED_SPACE),
36  _availabilityPool (DEFAULT_AVAILABILITY),
37  _availability (DEFAULT_AVAILABILITY),
38  _currentBidPrice (DEFAULT_BID_PRICE),
39  _bidPriceVector (DEFAULT_BID_PRICE_VECTOR) {
40  }
41 
42  // ////////////////////////////////////////////////////////////////////
44  }
45 
46  // ////////////////////////////////////////////////////////////////////
47  void LegCabin::setCapacities (const CabinCapacity_T& iCapacity) {
48  _offeredCapacity = iCapacity;
49  _physicalCapacity = iCapacity;
51  }
52 
53  // ////////////////////////////////////////////////////////////////////
55  const LegDate& lLegDate = BomManager::getParent<LegDate> (*this);
56 
57  const MapKey_T oFullKey =
59  return oFullKey;
60  }
61 
62  // ////////////////////////////////////////////////////////////////////
63  std::string LegCabin::toString() const {
64  std::ostringstream oStr;
65  oStr << describeKey();
66  return oStr.str();
67  }
68 
69  // ////////////////////////////////////////////////////////////////////
70  const std::string LegCabin::displayVirtualClassList () const {
71  std::ostringstream oStr;
72 
73  for (VirtualClassList_T::const_iterator itVC = _virtualClassList.begin();
74  itVC != _virtualClassList.end(); ++itVC) {
75  const VirtualClassStruct& lVC = *itVC;
76  oStr << std::endl << "Yield: " << std::fixed << std::setprecision (2)
77  << lVC.getYield()
78  << ", Protection: " << std::fixed << std::setprecision (2)
79  << lVC.getCumulatedProtection()
80  << ", Booking limit: " << std::fixed << std::setprecision (2)
81  << lVC.getCumulatedBookingLimit();
82  }
83 
84  return oStr.str();
85  }
86 
87  // ////////////////////////////////////////////////////////////////////
88  void LegCabin::updateFromReservation (const NbOfBookings_T& iNbOfBookings) {
89  _committedSpace += iNbOfBookings;
91  }
92 
93  // ////////////////////////////////////////////////////////////////////
95  const unsigned short lAvailabilityPool =
96  static_cast<unsigned short> (std::floor (_availabilityPool));
97 
98  if (lAvailabilityPool >= 1) {
99  const unsigned short lBidPriceVectorSize = _bidPriceVector.size();
100  if (lBidPriceVectorSize >= lAvailabilityPool) {
101  _currentBidPrice = _bidPriceVector.at (lAvailabilityPool - 1);
102  }
103  }
104  }
105 
106  // ////////////////////////////////////////////////////////////////////
108  const MeanValue_T& iMeanValue,
109  const StdDevValue_T& iStdDevValue) {
110  //
111  const int lYieldLevel =
112  static_cast<int> (std::floor (iYield + 0.5));
113 
114  //
115  YieldLevelDemandMap_T::iterator itDemand =
116  _yieldLevelDemandMap.find (lYieldLevel);
117 
118  if (itDemand == _yieldLevelDemandMap.end()) {
119  MeanStdDevPair_T lMeanStdDevPair (iMeanValue,iStdDevValue);
120  const bool hasInsertBeenSuccessful = _yieldLevelDemandMap.
121  insert (YieldLevelDemandMap_T::value_type (lYieldLevel,
122  lMeanStdDevPair)).second;
123  assert (hasInsertBeenSuccessful == true);
124 
125  } else {
126  //
127  MeanStdDevPair_T& lMeanStdDevPair = itDemand->second;
128  MeanValue_T lMeanValue = iMeanValue + lMeanStdDevPair.first;
129  StdDevValue_T lStdDevValue = iStdDevValue * iStdDevValue + lMeanStdDevPair.second * lMeanStdDevPair.second;
130  lStdDevValue = std::sqrt (lStdDevValue);
131 
132  //
133  lMeanStdDevPair = MeanStdDevPair_T (lMeanValue, lStdDevValue);
134  }
135  }
136 
137 }
138