$treeview $search $mathjax
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/basic/BasConst_General.hpp> 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 ("OptimiseTestSuite_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 00050 // ////////////////////////////////////////////////////////////////////// 00051 int testOptimiseHelper (const unsigned short optimisationMethodFlag, 00052 const bool isBuiltin) { 00053 00054 // Return value 00055 int oExpectedBookingLimit = 0; 00056 00057 // Output log File 00058 std::ostringstream oStr; 00059 oStr << "OptimiseTestSuite_" << optimisationMethodFlag << "_" << isBuiltin << ".log"; 00060 const stdair::Filename_T lLogFilename (oStr.str()); 00061 00062 // Number of random draws to be generated (best if greater than 100) 00063 const int K = RMOL::DEFAULT_NUMBER_OF_DRAWS_FOR_MC_SIMULATION; 00064 00065 // Methods of optimisation (0 = Monte-Carlo, 1 = Dynamic Programming, 00066 // 2 = EMSR, 3 = EMSR-a, 4 = EMSR-b, 5 = EMSR-a with sellup prob.) 00067 const unsigned short METHOD_FLAG = optimisationMethodFlag; 00068 00069 // Cabin Capacity (it must be greater then 100 here) 00070 const double cabinCapacity = 100.0; 00071 00072 // Set the log parameters 00073 std::ofstream logOutputFile; 00074 // Open and clean the log outputfile 00075 logOutputFile.open (lLogFilename.c_str()); 00076 logOutputFile.clear(); 00077 00078 // Initialise the RMOL service 00079 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); 00080 RMOL::RMOL_Service rmolService (lLogParams); 00081 00082 // Check wether or not a (CSV) input file should be read 00083 if (isBuiltin == true) { 00084 00085 // Build the default sample BOM tree and build a dummy BOM tree. 00086 rmolService.buildSampleBom(); 00087 00088 } else { 00089 00090 // Parse the optimisation data and build a dummy BOM tree 00091 const stdair::Filename_T lRMInputFileName (STDAIR_SAMPLE_DIR "/rm02.csv"); 00092 rmolService.parseAndLoad (cabinCapacity, lRMInputFileName); 00093 } 00094 00095 switch (METHOD_FLAG) { 00096 case 0: { 00097 // DEBUG 00098 STDAIR_LOG_DEBUG ("Optimisation by Monte-Carlo (MC)"); 00099 00100 // Calculate the optimal protections by the Monte Carlo 00101 // Integration approach 00102 rmolService.optimalOptimisationByMCIntegration (K); 00103 break; 00104 } 00105 00106 case 1: { 00107 // DEBUG 00108 STDAIR_LOG_DEBUG ("Optimisation by Dynamic Programming (DP)"); 00109 00110 // Calculate the optimal protections by DP. 00111 rmolService.optimalOptimisationByDP (); 00112 break; 00113 } 00114 00115 case 2: { 00116 // DEBUG 00117 STDAIR_LOG_DEBUG ("Calculate the Bid-Price Vectors (BPV) by EMSR"); 00118 00119 // Calculate the Bid-Price Vector by EMSR 00120 rmolService.heuristicOptimisationByEmsr (); 00121 break; 00122 } 00123 00124 case 3: { 00125 // DEBUG 00126 STDAIR_LOG_DEBUG ("Calculate the Authorisation Levels (AUs) by EMSRa"); 00127 00128 // Calculate the protections by EMSR-a 00129 // Test the EMSR-a algorithm implementation 00130 rmolService.heuristicOptimisationByEmsrA (); 00131 00132 // Return a cumulated booking limit value to test 00133 // oExpectedBookingLimit = static_cast<int> (lBookingLimitVector.at(2)); 00134 break; 00135 } 00136 00137 case 4: { 00138 // DEBUG 00139 STDAIR_LOG_DEBUG ("Calculate the Authorisation Levels (AUs) by EMSRb"); 00140 00141 // Calculate the protections by EMSR-b 00142 rmolService.heuristicOptimisationByEmsrB (); 00143 break; 00144 } 00145 00146 default: rmolService.optimalOptimisationByMCIntegration (K); 00147 } 00148 00149 // Close the log file 00150 logOutputFile.close(); 00151 00152 return oExpectedBookingLimit; 00153 } 00154 00155 00156 // /////////////// Main: Unit Test Suite ////////////// 00157 00158 // Set the UTF configuration (re-direct the output to a specific file) 00159 BOOST_GLOBAL_FIXTURE (UnitTestConfig); 00160 00161 // ////////////////////////////////////////////////////////////////////// 00162 // Tests are based on the following input values 00163 // price; mean; standard deviation; 00164 // 1050; 17.3; 5.8; 00165 // 567; 45.1; 15.0; 00166 // 534; 39.6; 13.2; 00167 // 520; 34.0; 11.3; 00168 // ////////////////////////////////////////////////////////////////////// 00169 00174 BOOST_AUTO_TEST_SUITE (master_test_suite) 00175 00176 00179 BOOST_AUTO_TEST_CASE (rmol_optimisation_monte_carlo) { 00180 00181 // State whether the BOM tree should be built-in or parsed from an input file 00182 const bool isBuiltin = false; 00183 00184 BOOST_CHECK_NO_THROW (testOptimiseHelper(0, isBuiltin);); 00185 } 00186 00190 BOOST_AUTO_TEST_CASE (rmol_optimisation_dynamic_programming) { 00191 00192 // State whether the BOM tree should be built-in or parsed from an input file 00193 const bool isBuiltin = false; 00194 00195 BOOST_CHECK_NO_THROW (testOptimiseHelper(1, isBuiltin);); 00196 } 00197 00202 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_bpv) { 00203 00204 // State whether the BOM tree should be built-in or parsed from an input file 00205 const bool isBuiltin = false; 00206 00207 BOOST_CHECK_NO_THROW (testOptimiseHelper(2, isBuiltin);); 00208 } 00209 00214 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_a) { 00215 00216 // State whether the BOM tree should be built-in or parsed from an input file 00217 const bool isBuiltin = false; 00218 00219 BOOST_CHECK_NO_THROW (testOptimiseHelper(3, isBuiltin);); 00220 // const int lBookingLimit = testOptimiseHelper(3); 00221 // const int lExpectedBookingLimit = 61; 00222 // BOOST_CHECK_EQUAL (lBookingLimit, lExpectedBookingLimit); 00223 // BOOST_CHECK_MESSAGE (lBookingLimit == lExpectedBookingLimit, 00224 // "The booking limit is " << lBookingLimit 00225 // << ", but it is expected to be " 00226 // << lExpectedBookingLimit); 00227 } 00228 00233 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_b) { 00234 00235 // State whether the BOM tree should be built-in or parsed from an input file 00236 const bool isBuiltin = false; 00237 00238 BOOST_CHECK_NO_THROW (testOptimiseHelper(4, isBuiltin);); 00239 } 00240 00244 BOOST_AUTO_TEST_CASE (rmol_optimisation_monte_carlo_built_in) { 00245 00246 // State whether the BOM tree should be built-in or parsed from an input file 00247 const bool isBuiltin = true; 00248 00249 BOOST_CHECK_NO_THROW (testOptimiseHelper(0, isBuiltin);); 00250 } 00251 00255 BOOST_AUTO_TEST_CASE (rmol_optimisation_dynamic_programming_built_in) { 00256 00257 // State whether the BOM tree should be built-in or parsed from an input file 00258 const bool isBuiltin = true; 00259 00260 BOOST_CHECK_NO_THROW (testOptimiseHelper(1, isBuiltin);); 00261 } 00262 00267 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_bpv_built_in) { 00268 00269 // State whether the BOM tree should be built-in or parsed from an input file 00270 const bool isBuiltin = true; 00271 00272 BOOST_CHECK_NO_THROW (testOptimiseHelper(2, isBuiltin);); 00273 } 00274 00279 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_a_built_in) { 00280 00281 // State whether the BOM tree should be built-in or parsed from an input file 00282 const bool isBuiltin = true; 00283 00284 BOOST_CHECK_NO_THROW (testOptimiseHelper(3, isBuiltin);); 00285 } 00286 00291 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_b_built_in) { 00292 00293 // State whether the BOM tree should be built-in or parsed from an input file 00294 const bool isBuiltin = true; 00295 00296 BOOST_CHECK_NO_THROW (testOptimiseHelper(4, isBuiltin);); 00297 } 00298 00299 // End the test suite 00300 BOOST_AUTO_TEST_SUITE_END() 00301 00302