StdAir Logo  0.43.0
C++ Standard Airline IT Library
LegCabin.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // StdAir
00008 #include <stdair/basic/BasConst_BookingClass.hpp>
00009 #include <stdair/basic/BasConst_Inventory.hpp>
00010 #include <stdair/basic/BasConst_BomDisplay.hpp>
00011 #include <stdair/bom/BomManager.hpp>
00012 #include <stdair/bom/LegDate.hpp>
00013 #include <stdair/bom/LegCabin.hpp>
00014 
00015 
00016 namespace stdair {
00017 
00018   // ////////////////////////////////////////////////////////////////////
00019   LegCabin::LegCabin() : _key (DEFAULT_CABIN_CODE), _parent (NULL) {
00020     assert (false);
00021   }
00022 
00023   // ////////////////////////////////////////////////////////////////////
00024   LegCabin::LegCabin (const LegCabin&)
00025     : _key (DEFAULT_CABIN_CODE), _parent (NULL) {
00026     assert (false);
00027   }
00028 
00029   // ////////////////////////////////////////////////////////////////////
00030   LegCabin::LegCabin (const Key_T& iKey)
00031     : _key (iKey), _parent (NULL),
00032       _offeredCapacity (DEFAULT_CABIN_CAPACITY),
00033       _physicalCapacity (DEFAULT_CABIN_CAPACITY),
00034       _soldSeat (DEFAULT_CLASS_NB_OF_BOOKINGS),
00035       _committedSpace (DEFAULT_COMMITTED_SPACE),
00036       _availabilityPool (DEFAULT_AVAILABILITY),
00037       _availability (DEFAULT_AVAILABILITY),
00038       _currentBidPrice (DEFAULT_BID_PRICE),
00039       _bidPriceVector (DEFAULT_BID_PRICE_VECTOR) {
00040   }
00041 
00042   // ////////////////////////////////////////////////////////////////////
00043   LegCabin::~LegCabin() {
00044   }
00045 
00046   // ////////////////////////////////////////////////////////////////////
00047   const MapKey_T LegCabin::getFullerKey() const {
00048     const LegDate& lLegDate = BomManager::getParent<LegDate> (*this);
00049 
00050     const MapKey_T oFullKey =
00051       lLegDate.describeKey() + DEFAULT_KEY_FLD_DELIMITER + getCabinCode();
00052     return oFullKey;
00053   }
00054 
00055   // ////////////////////////////////////////////////////////////////////
00056   std::string LegCabin::toString() const {
00057     std::ostringstream oStr;
00058     oStr << describeKey();
00059     return oStr.str();
00060   }
00061 
00062   // ////////////////////////////////////////////////////////////////////
00063   const std::string LegCabin::displayVirtualClassList () const {
00064     std::ostringstream oStr;
00065     
00066     for (VirtualClassList_T::const_iterator itVC = _virtualClassList.begin();
00067          itVC != _virtualClassList.end(); ++itVC) {
00068       const VirtualClassStruct& lVC = *itVC;
00069       oStr << std::endl << "Yield: " << std::fixed << std::setprecision (2)
00070            << lVC.getYield()
00071            << ", Protection: " << std::fixed << std::setprecision (2)
00072            << lVC.getCumulatedProtection()
00073            << ", Booking limit: " << std::fixed << std::setprecision (2)
00074            << lVC.getCumulatedBookingLimit();
00075     }
00076     
00077     return oStr.str();
00078   }
00079 
00080   // ////////////////////////////////////////////////////////////////////
00081   void LegCabin::updateFromReservation (const NbOfBookings_T& iNbOfBookings) {
00082     _committedSpace += iNbOfBookings;
00083     _availabilityPool = _offeredCapacity - _committedSpace;
00084   }
00085 
00086   // ////////////////////////////////////////////////////////////////////
00087   void LegCabin::addDemandInformation (const YieldValue_T& iYield,
00088                                        const MeanValue_T& iMeanValue,
00089                                        const StdDevValue_T& iStdDevValue) {
00090     //
00091     const int lYieldLevel = std::floor (iYield + 0.5);
00092 
00093     //
00094     YieldLevelDemandMap_T::iterator itDemand = _yieldLevelDemandMap.find (lYieldLevel);
00095     if (itDemand == _yieldLevelDemandMap.end()) {
00096       MeanStdDevPair_T lMeanStdDevPair (iMeanValue,iStdDevValue);
00097       const bool hasInsertBeenSuccessful =
00098         _yieldLevelDemandMap.insert(YieldLevelDemandMap_T::value_type (lYieldLevel,lMeanStdDevPair)).second;
00099       assert (hasInsertBeenSuccessful == true);
00100       
00101     } else {
00102       //
00103       MeanStdDevPair_T& lMeanStdDevPair = itDemand->second;
00104       MeanValue_T lMeanValue = iMeanValue + lMeanStdDevPair.first;
00105       StdDevValue_T lStdDevValue2 = iStdDevValue * iStdDevValue + lMeanStdDevPair.second * lMeanStdDevPair.second;
00106       StdDevValue_T lStdDevValue = std::sqrt (lStdDevValue2);
00107 
00108       //
00109       lMeanStdDevPair = MeanStdDevPair_T (lMeanValue, lStdDevValue);
00110     }
00111   }  
00112 
00113 }
00114