RMOL Logo  0.25.3
C++ library of Revenue Management and Optimisation classes and functions
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines
bomsforforecaster.cpp
Go to the documentation of this file.
00001 
00005 // //////////////////////////////////////////////////////////////////////
00006 // Import section
00007 // //////////////////////////////////////////////////////////////////////
00008 // STL
00009 #include <cassert>
00010 #include <limits>
00011 #include <sstream>
00012 #include <fstream>
00013 #include <string>
00014 // Boost Unit Test Framework (UTF)
00015 #define BOOST_TEST_DYN_LINK
00016 #define BOOST_TEST_MAIN
00017 #define BOOST_TEST_MODULE OptimiseTestSuite
00018 #include <boost/test/unit_test.hpp>
00019 // StdAir
00020 #include <stdair/basic/BasLogParams.hpp>
00021 #include <stdair/basic/BasDBParams.hpp>
00022 #include <stdair/service/Logger.hpp>
00023 // RMOL
00024 #include <rmol/RMOL_Service.hpp>
00025 #include <rmol/config/rmol-paths.hpp>
00026 
00027 namespace boost_utf = boost::unit_test;
00028 
00029 // (Boost) Unit Test XML Report
00030 std::ofstream utfReportStream ("bomsforforecaster_utfresults.xml");
00031 
00035 struct UnitTestConfig {
00037   UnitTestConfig() {
00038     boost_utf::unit_test_log.set_stream (utfReportStream);
00039     boost_utf::unit_test_log.set_format (boost_utf::XML);
00040     boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00041     //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
00042   }
00043 
00045   ~UnitTestConfig() {
00046   }
00047 };
00048 
00049 namespace RMOL {
00050 
00052   struct BookingClassData {
00053 
00054     // Attributes
00055     double _bookingCount;
00056     double _fare;
00057     double _sellupFactor;
00058     bool _censorshipFlag;
00059       
00060     // Constructer
00061     BookingClassData (const double iBookingCount, const double iFare, 
00062                       const double iSellupFactor, const bool iCensorshipFlag)
00063       : _bookingCount(iBookingCount), _fare(iFare), 
00064         _sellupFactor(iSellupFactor), _censorshipFlag(iCensorshipFlag) {
00065     }
00066       
00067     // Getters
00068     double getFare () const {
00069       return _fare;
00070     }
00071       
00072     bool getCensorshipFlag () const {
00073       return _censorshipFlag;
00074     }
00075 
00076     // Display
00077     std::string toString() const {
00078       std::ostringstream oStr;
00079       oStr <<  std::endl 
00080            << "[Booking class data information]" << std::endl
00081            << "Booking counter: " << _bookingCount << std::endl
00082            << "Fare: " << _fare << std::endl
00083            << "Sell-up Factor: " << _sellupFactor << std::endl
00084            << "censorshipFlag: " << _censorshipFlag << std::endl;
00085       return oStr.str();
00086     }
00087 
00088   };
00089  
00091   struct BookingClassDataSet {
00092 
00093     typedef std::vector<BookingClassData*> BookingClassDataList_T;
00094 
00095     // Attributes 
00096     int _numberOfClass;
00097     double _minimumFare;
00098     bool _censorshipFlag; // true if any of the classes is censored
00099     BookingClassDataList_T _bookingClassDataList;
00100 
00101     // Constructor
00102     BookingClassDataSet ()
00103       : _numberOfClass(0), _minimumFare(0),
00104         _censorshipFlag(false) {
00105     }
00106 
00107     // Add BookingClassData
00108     void addBookingClassData (BookingClassData& ioBookingClassData) {
00109       _bookingClassDataList.push_back (&ioBookingClassData);
00110     }
00111 
00112     // Getters
00113     unsigned int getNumberOfClass () const {
00114       return _bookingClassDataList.size();
00115     }
00116 
00117     double getMinimumFare () const {
00118       return _minimumFare;
00119     }
00120 
00121     bool getCensorshipFlag () const {
00122       return _censorshipFlag;
00123     }
00124 
00125     // Setters
00126     void setMinimumFare (const double iMinFare) {
00127       _minimumFare = iMinFare;
00128     }
00129 
00130     void setCensorshipFlag (const bool iCensorshipFlag) {
00131       _censorshipFlag = iCensorshipFlag;
00132     }
00133 
00134     // compute minimum fare 
00135     void updateMinimumFare() {
00136       double minFare = std::numeric_limits<double>::max();
00137       BookingClassDataList_T::iterator itBookingClassDataList;
00138       for (itBookingClassDataList = _bookingClassDataList.begin();
00139            itBookingClassDataList != _bookingClassDataList.end();
00140            ++itBookingClassDataList) {
00141         BookingClassData* lBookingClassData = *itBookingClassDataList;
00142         assert (lBookingClassData != NULL);
00143         
00144         const double lFare = lBookingClassData->getFare();
00145         if (lFare < minFare) { 
00146           minFare = lFare; 
00147         }
00148       }
00149       //
00150       setMinimumFare(minFare);
00151     }
00152 
00153     // compute censorship flag for the data set
00154     void updateCensorshipFlag () {
00155       bool censorshipFlag = false;
00156       BookingClassDataList_T::iterator itBookingClassDataList;
00157       for (itBookingClassDataList = _bookingClassDataList.begin();
00158            itBookingClassDataList != _bookingClassDataList.end();
00159            ++itBookingClassDataList) {
00160         BookingClassData* lBookingClassData = *itBookingClassDataList;
00161         assert (lBookingClassData != NULL);
00162         
00163         const bool lCensorshipFlagOfAClass =
00164           lBookingClassData->getCensorshipFlag();
00165         if (lCensorshipFlagOfAClass) {
00166           censorshipFlag = true;
00167           break;
00168         }
00169       }
00170       //
00171       setCensorshipFlag(censorshipFlag);
00172     }
00173     
00174     // Display
00175     std::string toString() const {
00176       std::ostringstream oStr;
00177       oStr << std::endl
00178            << "[Booking class data set information]" << std::endl
00179            << "Number of classes: " << _numberOfClass << std::endl
00180            << "Minimum fare: " << _minimumFare << std::endl
00181            << "The data of the class set are sensored: " << _censorshipFlag
00182            << std::endl;
00183       return oStr.str();
00184     }
00185 
00186   };
00187 
00188   // /**-------------- BOM : Q-Forecaster ----------------------- */ 
00189   // struct QForecaster {
00190 
00191   //   // Function focused BOM
00192 
00193   //   // 1. calculate sell up probability for Q-eq
00194 
00195   //   // 2. calculate Q-Equivalent Booking
00196   //   double calculateQEqBooking (BookingClassDataSet& iBookingClassDataSet) {
00197   //     double lQEqBooking = 0.0;
00198   //     double lMinFare = iBookingClassDataSet.getMinimumFare();
00199 
00200 
00201   //     return lQEqBooking;
00202   //   }
00203     
00204   //   /* Calculate Q-equivalent demand 
00205   //      [<- performed by unconstrainer if necessary (Using ExpMax BOM)] 
00206   //   */
00207 
00208    
00209   //   // 3. Partition to each class
00210 
00211   //   // 
00212     
00213   // };
00214 
00215 }
00216 
00217 // /////////////// Main: Unit Test Suite //////////////
00218 
00219 // Set the UTF configuration (re-direct the output to a specific file)
00220 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00221 
00225 BOOST_AUTO_TEST_SUITE (master_test_suite)
00226 
00227 
00230 BOOST_AUTO_TEST_CASE (rmol_forecaster) {
00231 
00232   // Output log File
00233   std::string lLogFilename ("bomsforforecaster.log");
00234   std::ofstream logOutputFile;
00235 
00236   // Open and clean the log outputfile
00237   logOutputFile.open (lLogFilename.c_str());
00238   logOutputFile.clear();
00239 
00240   // Initialise the RMOL service
00241   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00242 
00243   // Initialise the RMOL service
00244   RMOL::RMOL_Service rmolService (lLogParams);
00245 
00246   // Build a sample BOM tree
00247   rmolService.buildSampleBom();
00248 
00249   // Register BCDataSet
00250   RMOL::BookingClassDataSet lBookingClassDataSet;
00251 
00252   // Register BookingClassData
00253   RMOL::BookingClassData QClassData (10, 100, 1, false);
00254   RMOL::BookingClassData MClassData (5, 150, 0.8, true);
00255   RMOL::BookingClassData BClassData (0, 200, 0.6, false);
00256   RMOL::BookingClassData YClassData (0, 300, 0.3, false);
00257 
00258   // Display
00259   STDAIR_LOG_DEBUG (QClassData.toString());
00260   STDAIR_LOG_DEBUG (MClassData.toString());
00261   STDAIR_LOG_DEBUG (BClassData.toString());
00262   STDAIR_LOG_DEBUG (YClassData.toString());
00263 
00264   // Add BookingClassData into the BCDataSet
00265   lBookingClassDataSet.addBookingClassData (QClassData);
00266   lBookingClassDataSet.addBookingClassData (MClassData);
00267   lBookingClassDataSet.addBookingClassData (BClassData);
00268   lBookingClassDataSet.addBookingClassData (YClassData);
00269 
00270   // DEBUG
00271   STDAIR_LOG_DEBUG (lBookingClassDataSet.toString());
00272 
00273   // Number of classes
00274   const unsigned int lNoOfClass = lBookingClassDataSet.getNumberOfClass();
00275 
00276   // DEBUG
00277   STDAIR_LOG_DEBUG ("Number of Classes: " << lNoOfClass);
00278 
00279   // Minimum fare
00280   BOOST_CHECK_NO_THROW (lBookingClassDataSet.updateMinimumFare());
00281   const double lMinFare = lBookingClassDataSet.getMinimumFare();
00282 
00283   // DEBUG
00284   STDAIR_LOG_DEBUG ("Minimum fare: " << lMinFare);
00285 
00286   // Censorship flag
00287   BOOST_CHECK_NO_THROW (lBookingClassDataSet.updateCensorshipFlag());
00288   const bool lCensorshipFlag = lBookingClassDataSet.getCensorshipFlag();
00289 
00290   // DEBUG
00291   STDAIR_LOG_DEBUG ("Censorship Flag: " << lCensorshipFlag);
00292 
00293   // Close the log output file
00294   logOutputFile.close();
00295 }
00296 
00297 // End the test suite
00298 BOOST_AUTO_TEST_SUITE_END()
00299 
00300