RMOL Logo  0.25.3
C++ library of Revenue Management and Optimisation classes and functions
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines
OptimiseTestSuite.cpp
Go to the documentation of this file.
00001 
00005 // //////////////////////////////////////////////////////////////////////
00006 // Import section
00007 // //////////////////////////////////////////////////////////////////////
00008 // STL
00009 #include <sstream>
00010 #include <fstream>
00011 #include <string>
00012 // Boost Unit Test Framework (UTF)
00013 #define BOOST_TEST_DYN_LINK
00014 #define BOOST_TEST_MAIN
00015 #define BOOST_TEST_MODULE OptimiseTestSuite
00016 #include <boost/test/unit_test.hpp>
00017 // StdAir
00018 #include <stdair/basic/BasLogParams.hpp>
00019 #include <stdair/basic/BasDBParams.hpp>
00020 #include <stdair/basic/BasFileMgr.hpp>
00021 #include <stdair/service/Logger.hpp>
00022 // RMOL
00023 #include <rmol/RMOL_Service.hpp>
00024 #include <rmol/config/rmol-paths.hpp>
00025 
00026 namespace boost_utf = boost::unit_test;
00027 
00028 // (Boost) Unit Test XML Report
00029 std::ofstream utfReportStream ("OptimiseTestSuite_utfresults.xml");
00030 
00034 struct UnitTestConfig {
00036   UnitTestConfig() {
00037     boost_utf::unit_test_log.set_stream (utfReportStream);
00038     boost_utf::unit_test_log.set_format (boost_utf::XML);
00039     boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00040     //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
00041   }
00042 
00044   ~UnitTestConfig() {
00045   }
00046 };
00047 
00048 
00049 // //////////////////////////////////////////////////////////////////////
00050 int testOptimiseHelper (const unsigned short optimisationMethodFlag,
00051                         const bool isBuiltin) {
00052 
00053   // Return value
00054   int oExpectedBookingLimit = 0;
00055 
00056   // Output log File
00057   std::ostringstream oStr;
00058   oStr << "OptimiseTestSuite_" << optimisationMethodFlag << ".log";
00059   const stdair::Filename_T lLogFilename (oStr.str());
00060     
00061   // Number of random draws to be generated (best if greater than 100)
00062   const int K = 100000;
00063     
00064   // Methods of optimisation (0 = Monte-Carlo, 1 = Dynamic Programming, 
00065   // 2 = EMSR, 3 = EMSR-a, 4 = EMSR-b, 5 = EMSR-a with sellup prob.)
00066   const unsigned short METHOD_FLAG = optimisationMethodFlag;
00067     
00068   // Cabin Capacity (it must be greater then 100 here)
00069   const double cabinCapacity = 100.0;
00070     
00071   // Set the log parameters
00072   std::ofstream logOutputFile;
00073   // Open and clean the log outputfile
00074   logOutputFile.open (lLogFilename.c_str());
00075   logOutputFile.clear();
00076     
00077   // Initialise the RMOL service
00078   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00079   RMOL::RMOL_Service rmolService (lLogParams);
00080 
00081   // Check wether or not a (CSV) input file should be read
00082   if (isBuiltin == true) {
00083 
00084     // Build the default sample BOM tree and build a dummy BOM tree.
00085     rmolService.buildSampleBom();
00086 
00087   } else {
00088 
00089     // Parse the optimisation data and build a dummy BOM tree 
00090     const stdair::Filename_T lRMInputFileName (STDAIR_SAMPLE_DIR "/rm02.csv");
00091     rmolService.parseAndLoad (cabinCapacity, lRMInputFileName);
00092   }
00093 
00094   switch (METHOD_FLAG) {
00095   case 0: {
00096     // DEBUG
00097     STDAIR_LOG_DEBUG ("Optimisation by Monte-Carlo (MC)");
00098     
00099     // Calculate the optimal protections by the Monte Carlo
00100     // Integration approach        
00101     rmolService.optimalOptimisationByMCIntegration (K);
00102     break;
00103   }
00104       
00105   case 1: {
00106     // DEBUG
00107     STDAIR_LOG_DEBUG ("Optimisation by Dynamic Programming (DP)");
00108     
00109     // Calculate the optimal protections by DP.
00110     rmolService.optimalOptimisationByDP ();
00111     break;
00112   }
00113       
00114   case 2: {
00115     // DEBUG
00116     STDAIR_LOG_DEBUG ("Calculate the Bid-Price Vectors (BPV) by EMSR");
00117     
00118     // Calculate the Bid-Price Vector by EMSR
00119     rmolService.heuristicOptimisationByEmsr ();
00120     break;
00121   }
00122       
00123   case 3: {
00124     // DEBUG
00125     STDAIR_LOG_DEBUG ("Calculate the Authorisation Levels (AUs) by EMSRa");
00126     
00127     // Calculate the protections by EMSR-a
00128     // Test the EMSR-a algorithm implementation
00129     rmolService.heuristicOptimisationByEmsrA ();
00130 
00131     // Return a cumulated booking limit value to test
00132     // oExpectedBookingLimit = static_cast<int> (lBookingLimitVector.at(2));
00133     break;
00134   }
00135       
00136   case 4: {
00137     // DEBUG
00138     STDAIR_LOG_DEBUG ("Calculate the Authorisation Levels (AUs) by EMSRb");
00139     
00140     // Calculate the protections by EMSR-b
00141     rmolService.heuristicOptimisationByEmsrB ();
00142     break;
00143   }
00144 
00145   default: rmolService.optimalOptimisationByMCIntegration (K);
00146   }
00147         
00148   // Close the log file
00149   logOutputFile.close();
00150   
00151   return oExpectedBookingLimit;
00152 }
00153 
00154 
00155 // /////////////// Main: Unit Test Suite //////////////
00156 
00157 // Set the UTF configuration (re-direct the output to a specific file)
00158 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00159 
00160 // //////////////////////////////////////////////////////////////////////
00161 // Tests are based on the following input values
00162 // price; mean; standard deviation;
00163 // 1050; 17.3; 5.8;
00164 // 567; 45.1; 15.0;
00165 // 534; 39.6; 13.2;
00166 // 520; 34.0; 11.3;
00167 // //////////////////////////////////////////////////////////////////////
00168 
00173 BOOST_AUTO_TEST_SUITE (master_test_suite)
00174 
00175 
00178 BOOST_AUTO_TEST_CASE (rmol_optimisation_monte_carlo) {
00179   
00180   // State whether the BOM tree should be built-in or parsed from an input file
00181   const bool isBuiltin = false;
00182   
00183   BOOST_CHECK_NO_THROW (testOptimiseHelper(0, isBuiltin););
00184 }
00185 
00189 BOOST_AUTO_TEST_CASE (rmol_optimisation_dynamic_programming) {
00190   
00191   // State whether the BOM tree should be built-in or parsed from an input file
00192   const bool isBuiltin = false;
00193   
00194   BOOST_CHECK_NO_THROW (testOptimiseHelper(1, isBuiltin););
00195 }
00196 
00201 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_bpv) {
00202   
00203   // State whether the BOM tree should be built-in or parsed from an input file
00204   const bool isBuiltin = false;
00205   
00206   BOOST_CHECK_NO_THROW (testOptimiseHelper(2, isBuiltin););
00207 }
00208 
00213 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_a) {
00214 
00215   // State whether the BOM tree should be built-in or parsed from an input file
00216   const bool isBuiltin = false;
00217   
00218   BOOST_CHECK_NO_THROW (testOptimiseHelper(3, isBuiltin););
00219   // const int lBookingLimit = testOptimiseHelper(3);
00220   // const int lExpectedBookingLimit = 61;
00221   // BOOST_CHECK_EQUAL (lBookingLimit, lExpectedBookingLimit);
00222   // BOOST_CHECK_MESSAGE (lBookingLimit == lExpectedBookingLimit,
00223   //                      "The booking limit is " << lBookingLimit
00224   //                      << ", but it is expected to be "
00225   //                      << lExpectedBookingLimit);
00226 }
00227 
00232 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_b) {
00233 
00234   // State whether the BOM tree should be built-in or parsed from an input file
00235   const bool isBuiltin = false;
00236   
00237   BOOST_CHECK_NO_THROW (testOptimiseHelper(4, isBuiltin););
00238 }
00239 
00243 BOOST_AUTO_TEST_CASE (rmol_optimisation_monte_carlo_built_in) {
00244   
00245   // State whether the BOM tree should be built-in or parsed from an input file
00246   const bool isBuiltin = true;
00247   
00248   BOOST_CHECK_NO_THROW (testOptimiseHelper(5, isBuiltin););
00249 }
00250 
00254 BOOST_AUTO_TEST_CASE (rmol_optimisation_dynamic_programming_built_in) {
00255   
00256   // State whether the BOM tree should be built-in or parsed from an input file
00257   const bool isBuiltin = true;
00258   
00259   BOOST_CHECK_NO_THROW (testOptimiseHelper(6, isBuiltin););
00260 }
00261 
00266 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_bpv_built_in) {
00267   
00268   // State whether the BOM tree should be built-in or parsed from an input file
00269   const bool isBuiltin = true;
00270   
00271   BOOST_CHECK_NO_THROW (testOptimiseHelper(7, isBuiltin););
00272 }
00273 
00278 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_a_built_in) {
00279 
00280   // State whether the BOM tree should be built-in or parsed from an input file
00281   const bool isBuiltin = true;
00282   
00283   BOOST_CHECK_NO_THROW (testOptimiseHelper(8, isBuiltin););
00284 }
00285 
00290 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_b_built_in) {
00291 
00292   // State whether the BOM tree should be built-in or parsed from an input file
00293   const bool isBuiltin = true;
00294   
00295   BOOST_CHECK_NO_THROW (testOptimiseHelper(9, isBuiltin););
00296 }
00297 
00298 // End the test suite
00299 BOOST_AUTO_TEST_SUITE_END()
00300 
00301