$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <sstream> 00006 #include <cassert> 00007 #include <iomanip> 00008 #include <iostream> 00009 //STDAIR 00010 #include <stdair/basic/BasConst_Inventory.hpp> 00011 #include <stdair/bom/BomManager.hpp> 00012 #include <stdair/bom/BookingClass.hpp> 00013 #include <stdair/bom/BookingClassTypes.hpp> 00014 #include <stdair/bom/Policy.hpp> 00015 00016 namespace stdair { 00017 00018 // //////////////////////////////////////////////////////////////////// 00019 Policy::Policy () : 00020 _key (DEFAULT_POLICY_CODE), _parent (NULL) { 00021 assert (false); 00022 } 00023 00024 // //////////////////////////////////////////////////////////////////// 00025 Policy::Policy (const Policy& iPolicy) 00026 : _key (DEFAULT_POLICY_CODE), _parent (NULL) { 00027 assert (false); 00028 } 00029 00030 // //////////////////////////////////////////////////////////////////// 00031 Policy::Policy (const Key_T& iKey) : _key (iKey), _parent (NULL) { 00032 } 00033 00034 // //////////////////////////////////////////////////////////////////// 00035 Policy::~Policy() { 00036 } 00037 00038 // //////////////////////////////////////////////////////////////////// 00039 std::string Policy::toString () const { 00040 std::ostringstream oStr; 00041 oStr << describeKey(); 00042 00043 oStr << std::fixed << std::setprecision (2) 00044 << "; " << _demand 00045 << "; " << _stdDev 00046 << "; " << _yield << std::endl; 00047 00048 return oStr.str(); 00049 } 00050 00051 // //////////////////////////////////////////////////////////////////// 00052 const BookingClassList_T& Policy::getBookingClassList() const { 00053 return BomManager::getList<BookingClass> (*this); 00054 } 00055 00056 // //////////////////////////////////////////////////////////////////// 00057 const Revenue_T Policy::getTotalRevenue () const { 00058 Revenue_T oTotalRevenue = 0.0; 00059 for (YieldDemandMap_T::const_iterator itYD = _yieldDemandMap.begin(); 00060 itYD != _yieldDemandMap.end(); ++itYD) { 00061 const Yield_T& lYield = itYD->first; 00062 const double& lDemand = itYD->second; 00063 oTotalRevenue += lYield*lDemand; 00064 } 00065 00066 return oTotalRevenue; 00067 } 00068 00069 // //////////////////////////////////////////////////////////////////// 00070 void Policy::addYieldDemand (const Yield_T& iYield, 00071 const NbOfBookings_T& iDemand) { 00072 YieldDemandMap_T::iterator itYD = _yieldDemandMap.find (iYield); 00073 if (itYD == _yieldDemandMap.end()) { 00074 bool insert = _yieldDemandMap.insert (YieldDemandMap_T::value_type 00075 (iYield, iDemand)).second; 00076 assert (insert == true); 00077 } else { 00078 NbOfBookings_T& lDemand = itYD->second; 00079 lDemand += iDemand; 00080 } 00081 } 00082 00083 }