StdAir Logo  0.45.0
C++ Standard Airline IT Object 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   void LegCabin::setCapacities (const CabinCapacity_T& iCapacity) {
00048     _offeredCapacity = iCapacity;
00049     _physicalCapacity = iCapacity;
00050     setAvailabilityPool (iCapacity - _committedSpace);
00051   }
00052 
00053   // ////////////////////////////////////////////////////////////////////
00054   const MapKey_T LegCabin::getFullerKey() const {
00055     const LegDate& lLegDate = BomManager::getParent<LegDate> (*this);
00056 
00057     const MapKey_T oFullKey =
00058       lLegDate.describeKey() + DEFAULT_KEY_FLD_DELIMITER + getCabinCode();
00059     return oFullKey;
00060   }
00061 
00062   // ////////////////////////////////////////////////////////////////////
00063   std::string LegCabin::toString() const {
00064     std::ostringstream oStr;
00065     oStr << describeKey();
00066     return oStr.str();
00067   }
00068 
00069   // ////////////////////////////////////////////////////////////////////
00070   const std::string LegCabin::displayVirtualClassList () const {
00071     std::ostringstream oStr;
00072     
00073     for (VirtualClassList_T::const_iterator itVC = _virtualClassList.begin();
00074          itVC != _virtualClassList.end(); ++itVC) {
00075       const VirtualClassStruct& lVC = *itVC;
00076       oStr << std::endl << "Yield: " << std::fixed << std::setprecision (2)
00077            << lVC.getYield()
00078            << ", Protection: " << std::fixed << std::setprecision (2)
00079            << lVC.getCumulatedProtection()
00080            << ", Booking limit: " << std::fixed << std::setprecision (2)
00081            << lVC.getCumulatedBookingLimit();
00082     }
00083     
00084     return oStr.str();
00085   }
00086 
00087   // ////////////////////////////////////////////////////////////////////
00088   void LegCabin::updateFromReservation (const NbOfBookings_T& iNbOfBookings) {
00089     _committedSpace += iNbOfBookings;
00090     _availabilityPool = _offeredCapacity - _committedSpace;
00091   }
00092 
00093   // ////////////////////////////////////////////////////////////////////
00094   void LegCabin::updateCurrentBidPrice() {
00095     const unsigned short lAvailabilityPool =
00096       static_cast<unsigned short> (std::floor (_availabilityPool));
00097 
00098     if (lAvailabilityPool >= 1) {
00099       const unsigned short lBidPriceVectorSize = _bidPriceVector.size();
00100       if (lBidPriceVectorSize >= lAvailabilityPool) {
00101         _currentBidPrice = _bidPriceVector.at (lAvailabilityPool - 1);
00102       }
00103     }
00104   }
00105 
00106   // ////////////////////////////////////////////////////////////////////
00107   void LegCabin::addDemandInformation (const YieldValue_T& iYield,
00108                                        const MeanValue_T& iMeanValue,
00109                                        const StdDevValue_T& iStdDevValue) {
00110     //
00111     const int lYieldLevel =
00112       static_cast<int> (std::floor (iYield + 0.5));
00113 
00114     //
00115     YieldLevelDemandMap_T::iterator itDemand =
00116       _yieldLevelDemandMap.find (lYieldLevel);
00117 
00118     if (itDemand == _yieldLevelDemandMap.end()) {
00119       MeanStdDevPair_T lMeanStdDevPair (iMeanValue,iStdDevValue);
00120       const bool hasInsertBeenSuccessful = _yieldLevelDemandMap.
00121         insert (YieldLevelDemandMap_T::value_type (lYieldLevel,
00122                                                    lMeanStdDevPair)).second;
00123       assert (hasInsertBeenSuccessful == true);
00124       
00125     } else {
00126       //
00127       MeanStdDevPair_T& lMeanStdDevPair = itDemand->second;
00128       MeanValue_T lMeanValue = iMeanValue + lMeanStdDevPair.first;
00129       StdDevValue_T lStdDevValue = iStdDevValue * iStdDevValue + lMeanStdDevPair.second * lMeanStdDevPair.second;
00130       lStdDevValue = std::sqrt (lStdDevValue);
00131 
00132       //
00133       lMeanStdDevPair = MeanStdDevPair_T (lMeanValue, lStdDevValue);
00134     }
00135   }  
00136 
00137 }
00138