StdAir Logo  1.00.0
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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& iLegCabin)
25  : _key (iLegCabin._key), _parent (NULL),
26  _offeredCapacity (iLegCabin._offeredCapacity),
27  _physicalCapacity (iLegCabin._physicalCapacity),
28  _soldSeat (iLegCabin._soldSeat),
29  _committedSpace (iLegCabin._committedSpace),
30  _availabilityPool (iLegCabin._availabilityPool),
31  _availability (iLegCabin._availability),
32  _currentBidPrice (iLegCabin._currentBidPrice),
33  _dcsRegrade (iLegCabin._dcsRegrade),
34  _au (iLegCabin._au),
35  _upr (iLegCabin._upr),
36  _nav (iLegCabin._nav),
37  _gav (iLegCabin._gav),
38  _acp (iLegCabin._acp),
39  _etb (iLegCabin._etb),
40  _staffNbOfBookings (iLegCabin._staffNbOfBookings),
41  _wlNbOfBookings (iLegCabin._wlNbOfBookings),
42  _groupNbOfBookings (iLegCabin._groupNbOfBookings) {
43  }
44 
45  // ////////////////////////////////////////////////////////////////////
46  LegCabin::LegCabin (const Key_T& iKey)
47  : _key (iKey), _parent (NULL),
48  _offeredCapacity (DEFAULT_CABIN_CAPACITY),
49  _physicalCapacity (DEFAULT_CABIN_CAPACITY),
50  _soldSeat (DEFAULT_CLASS_NB_OF_BOOKINGS),
51  _committedSpace (DEFAULT_COMMITTED_SPACE),
52  _availabilityPool (DEFAULT_AVAILABILITY),
53  _availability (DEFAULT_AVAILABILITY),
54  _currentBidPrice (DEFAULT_BID_PRICE),
55  _bidPriceVector (DEFAULT_BID_PRICE_VECTOR),
58  _upr (DEFAULT_NULL_UPR),
59  _nav (DEFAULT_AVAILABILITY),
60  _gav (DEFAULT_AVAILABILITY),
63  _staffNbOfBookings (DEFAULT_NULL_BOOKING_NUMBER),
64  _wlNbOfBookings (DEFAULT_NULL_BOOKING_NUMBER),
65  _groupNbOfBookings (DEFAULT_NULL_BOOKING_NUMBER) {
66  }
67 
68  // ////////////////////////////////////////////////////////////////////
70  }
71 
72  // ////////////////////////////////////////////////////////////////////
73  void LegCabin::setCapacities (const CabinCapacity_T& iCapacity) {
74  _offeredCapacity = iCapacity;
75  _physicalCapacity = iCapacity;
77  }
78 
79  // ////////////////////////////////////////////////////////////////////
81  const LegDate& lLegDate = BomManager::getParent<LegDate> (*this);
82 
83  const MapKey_T oFullKey =
85  return oFullKey;
86  }
87 
88  // ////////////////////////////////////////////////////////////////////
89  std::string LegCabin::toString() const {
90  std::ostringstream oStr;
91  oStr << describeKey();
92  return oStr.str();
93  }
94 
95  // ////////////////////////////////////////////////////////////////////
96  const std::string LegCabin::displayVirtualClassList () const {
97  std::ostringstream oStr;
98 
99  for (VirtualClassList_T::const_iterator itVC = _virtualClassList.begin();
100  itVC != _virtualClassList.end(); ++itVC) {
101  const VirtualClassStruct& lVC = *itVC;
102  oStr << std::endl << "Yield: " << std::fixed << std::setprecision (2)
103  << lVC.getYield()
104  << ", Protection: " << std::fixed << std::setprecision (2)
105  << lVC.getCumulatedProtection()
106  << ", Booking limit: " << std::fixed << std::setprecision (2)
107  << lVC.getCumulatedBookingLimit();
108  }
109 
110  return oStr.str();
111  }
112 
113  // ////////////////////////////////////////////////////////////////////
114  void LegCabin::updateFromReservation (const NbOfBookings_T& iNbOfBookings) {
115  _committedSpace += iNbOfBookings;
117  }
118 
119  // ////////////////////////////////////////////////////////////////////
121  const unsigned short lAvailabilityPool =
122  static_cast<unsigned short> (std::floor (_availabilityPool));
123 
124  if (lAvailabilityPool >= 1) {
125  const unsigned short lBidPriceVectorSize = _bidPriceVector.size();
126  if (lBidPriceVectorSize >= lAvailabilityPool) {
127  _currentBidPrice = _bidPriceVector.at (lAvailabilityPool - 1);
128  }
129  }
130  }
131 
132  // ////////////////////////////////////////////////////////////////////
134  const MeanValue_T& iMeanValue,
135  const StdDevValue_T& iStdDevValue) {
136  //
137  const int lYieldLevel =
138  static_cast<int> (std::floor (iYield + 0.5));
139 
140  //
141  YieldLevelDemandMap_T::iterator itDemand =
142  _yieldLevelDemandMap.find (lYieldLevel);
143 
144  if (itDemand == _yieldLevelDemandMap.end()) {
145  MeanStdDevPair_T lMeanStdDevPair (iMeanValue,iStdDevValue);
146  const bool hasInsertBeenSuccessful = _yieldLevelDemandMap.
147  insert (YieldLevelDemandMap_T::value_type (lYieldLevel,
148  lMeanStdDevPair)).second;
149  assert (hasInsertBeenSuccessful == true);
150 
151  } else {
152  //
153  MeanStdDevPair_T& lMeanStdDevPair = itDemand->second;
154  MeanValue_T lMeanValue = iMeanValue + lMeanStdDevPair.first;
155  StdDevValue_T lStdDevValue = iStdDevValue * iStdDevValue + lMeanStdDevPair.second * lMeanStdDevPair.second;
156  lStdDevValue = std::sqrt (lStdDevValue);
157 
158  //
159  lMeanStdDevPair = MeanStdDevPair_T (lMeanValue, lStdDevValue);
160  }
161  }
162 
163 }
164