RMOL Logo Get Revenue Management Optimisation Library at SourceForge.net. Fast, secure and Free Open Source software downloads

Bucket.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // C
00005 #include <assert.h>
00006 // STL
00007 #include <iostream>
00008 #include <iomanip>
00009 // RMOL
00010 #include <rmol/bom/Demand.hpp>
00011 #include <rmol/bom/Bucket.hpp>
00012 
00013 namespace RMOL {
00014 
00015   // //////////////////////////////////////////////////////////////////////
00016   Bucket::Bucket ()
00017     : _demand (NULL),
00018       _yieldRange (), _protection (0.0), _cumulatedProtection (0.0),
00019       _bookingLimit (0.0), _cumulatedBookingLimit (0.0) {
00020   }
00021   
00022   // //////////////////////////////////////////////////////////////////////
00023   Bucket::Bucket (const Bucket& iBucket) :
00024     _demand (&iBucket.getDemand()), 
00025     _yieldRange (iBucket.getYieldRange()), 
00026     _protection (iBucket.getProtection()),
00027     _cumulatedProtection (iBucket.getCumulatedProtection()),
00028     _bookingLimit (iBucket.getBookingLimit()),
00029     _cumulatedBookingLimit (iBucket.getCumulatedBookingLimit()) {
00030   }
00031 
00032   // //////////////////////////////////////////////////////////////////////
00033   Bucket::Bucket (const FldYieldRange& iYieldRange) :
00034     _demand (NULL),
00035     _yieldRange (iYieldRange), _protection (0.0), _cumulatedProtection (0.0),
00036     _bookingLimit (0.0), _cumulatedBookingLimit (0.0) {
00037   }
00038   
00039   // //////////////////////////////////////////////////////////////////////
00040   Bucket::~Bucket() {
00041   }
00042 
00043   // //////////////////////////////////////////////////////////////////////
00044   const std::string Bucket::describeShortKey() const {
00045     std::ostringstream oStr;
00046     oStr << _yieldRange;
00047     return oStr.str();
00048   }
00049   
00050   // //////////////////////////////////////////////////////////////////////
00051   const std::string Bucket::describeKey() const {
00052     return describeShortKey();
00053   }
00054 
00055   // //////////////////////////////////////////////////////////////////////
00056   std::string Bucket::toString() const {
00057     std::ostringstream oStr;
00058     oStr << describeShortKey() << ", ";
00059     const double pj = getUpperYield();
00060     const double mj = getMean();
00061     const double sj = getStandardDeviation();
00062     const double proj = getProtection();
00063     const double yj = getCumulatedProtection();
00064     const double bj = getCumulatedBookingLimit();
00065     oStr << std::fixed << std::setprecision (2)
00066          << pj << "; " << mj << "; " << sj << "; " << proj << "; " << yj
00067          << "; " << bj << std::endl;
00068     
00069     return oStr.str();
00070   }   
00071 
00072   // //////////////////////////////////////////////////////////////////////
00073   void Bucket::toStream (std::ostream& ioOut) const {
00074     ioOut << toString();
00075   }
00076   
00077   // //////////////////////////////////////////////////////////////////////
00078   void Bucket::fromStream (std::istream& ioIn) {
00079   }
00080   
00081   // //////////////////////////////////////////////////////////////////////
00082   const std::string Bucket::shortDisplay() const {
00083     std::ostringstream oStr;
00084     oStr << describeKey();
00085     const double pj = getUpperYield();
00086     const double mj = getMean();
00087     const double sj = getStandardDeviation();
00088     const double proj = getProtection();
00089     const double yj = getCumulatedProtection();
00090     const double blj = getBookingLimit();
00091     const double bj = getCumulatedBookingLimit();
00092     oStr << std::fixed << std::setprecision (2)
00093          << ", upper yield = " << pj << "; "
00094          << ", mean = " << mj << "; " << ", std_dev = " << sj << "; "
00095          << ", protection = " << proj << "; "
00096          << ", cumulative protection = " << yj << "; "
00097          << ", booking limit = " << blj
00098          << ", cumulative booking limit = " << bj << std::endl;
00099 
00100     return oStr.str();
00101   }
00102   
00103   // //////////////////////////////////////////////////////////////////////
00104   const std::string Bucket::display() const {
00105     std::ostringstream oStr;
00106     oStr << shortDisplay();
00107     return oStr.str();
00108   }
00109 
00110   // //////////////////////////////////////////////////////////////////////
00111   const FldDistributionParameters& Bucket::getDistributionParameters() const {
00112     assert (_demand != NULL);
00113     return _demand->getDistributionParameters();
00114   }
00115 
00116   // //////////////////////////////////////////////////////////////////////
00117   Demand& Bucket::getDemand() const {
00118     assert (_demand != NULL);
00119     return *_demand;
00120   }
00121 
00122   // //////////////////////////////////////////////////////////////////////
00123   void Bucket::setDemand (Demand& iDemand) {
00124     _demand = &iDemand;
00125   }
00126 
00127   // //////////////////////////////////////////////////////////////////////
00128   void Bucket::setYieldRange (const double iYield) {
00129     _yieldRange.setUpperYield (iYield);
00130     _yieldRange.setAverageYield (iYield);
00131     _yieldRange.setLowerYield (iYield);
00132   }
00133 
00134   // //////////////////////////////////////////////////////////////////////
00135   void Bucket::setDemandParameters (const double iMean, const double iSD) {
00136     _demand->setMean (iMean);
00137     _demand->setSD (iSD);
00138   }
00139 
00140   // //////////////////////////////////////////////////////////////////////
00141   const double Bucket::getMean() const {
00142     assert (_demand != NULL);
00143     return _demand->getMean();
00144   }
00145 
00146   // //////////////////////////////////////////////////////////////////////
00147   const double Bucket::getStandardDeviation() const {
00148     assert (_demand != NULL);
00149     return _demand->getStandardDeviation();
00150   }
00151 
00152   // //////////////////////////////////////////////////////////////////////
00153   const double Bucket::getUpperYield() const {
00154     return _yieldRange.getUpperYield();
00155   }
00156 
00157   // //////////////////////////////////////////////////////////////////////
00158   const double Bucket::getAverageYield() const {
00159     return _yieldRange.getAverageYield();
00160   }
00161 
00162   // //////////////////////////////////////////////////////////////////////
00163   const double Bucket::getLowerYield() const {
00164     return _yieldRange.getLowerYield();
00165   }
00166 
00167 }
SourceForge Logo

Generated on Sun Jun 14 23:33:59 2009 for RMOL by Doxygen 1.5.8