RMOL Logo  1.00.0
C++ library of Revenue Management and Optimisation classes and functions
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
OptimiseTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <sstream>
10 #include <fstream>
11 #include <string>
12 // Boost Unit Test Framework (UTF)
13 #define BOOST_TEST_DYN_LINK
14 #define BOOST_TEST_MAIN
15 #define BOOST_TEST_MODULE OptimiseTestSuite
16 #include <boost/test/unit_test.hpp>
17 // StdAir
18 #include <stdair/basic/BasLogParams.hpp>
19 #include <stdair/basic/BasDBParams.hpp>
20 #include <stdair/basic/BasFileMgr.hpp>
21 #include <stdair/service/Logger.hpp>
22 // RMOL
24 #include <rmol/RMOL_Service.hpp>
25 #include <rmol/config/rmol-paths.hpp>
26 
27 namespace boost_utf = boost::unit_test;
28 
29 // (Boost) Unit Test XML Report
30 std::ofstream utfReportStream ("OptimiseTestSuite_utfresults.xml");
31 
35 struct UnitTestConfig {
37  UnitTestConfig() {
38  boost_utf::unit_test_log.set_stream (utfReportStream);
39  boost_utf::unit_test_log.set_format (boost_utf::XML);
40  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
41  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
42  }
43 
45  ~UnitTestConfig() {
46  }
47 };
48 
49 
50 // //////////////////////////////////////////////////////////////////////
51 int testOptimiseHelper (const unsigned short optimisationMethodFlag,
52  const bool isBuiltin) {
53 
54  // Return value
55  int oExpectedBookingLimit = 0;
56 
57  // Output log File
58  std::ostringstream oStr;
59  oStr << "OptimiseTestSuite_" << optimisationMethodFlag << "_" << isBuiltin << ".log";
60  const stdair::Filename_T lLogFilename (oStr.str());
61 
62  // Number of random draws to be generated (best if greater than 100)
64 
65  // Methods of optimisation (0 = Monte-Carlo, 1 = Dynamic Programming,
66  // 2 = EMSR, 3 = EMSR-a, 4 = EMSR-b, 5 = EMSR-a with sellup prob.)
67  const unsigned short METHOD_FLAG = optimisationMethodFlag;
68 
69  // Cabin Capacity (it must be greater then 100 here)
70  const double cabinCapacity = 100.0;
71 
72  // Set the log parameters
73  std::ofstream logOutputFile;
74  // Open and clean the log outputfile
75  logOutputFile.open (lLogFilename.c_str());
76  logOutputFile.clear();
77 
78  // Initialise the RMOL service
79  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
80  RMOL::RMOL_Service rmolService (lLogParams);
81 
82  // Check wether or not a (CSV) input file should be read
83  if (isBuiltin == true) {
84 
85  // Build the default sample BOM tree and build a dummy BOM tree.
86  rmolService.buildSampleBom();
87 
88  } else {
89 
90  // Parse the optimisation data and build a dummy BOM tree
91  const stdair::Filename_T lRMInputFileName (STDAIR_SAMPLE_DIR "/rm02.csv");
92  rmolService.parseAndLoad (cabinCapacity, lRMInputFileName);
93  }
94 
95  switch (METHOD_FLAG) {
96  case 0: {
97  // DEBUG
98  STDAIR_LOG_DEBUG ("Optimisation by Monte-Carlo (MC)");
99 
100  // Calculate the optimal protections by the Monte Carlo
101  // Integration approach
102  rmolService.optimalOptimisationByMCIntegration (K);
103  break;
104  }
105 
106  case 1: {
107  // DEBUG
108  STDAIR_LOG_DEBUG ("Optimisation by Dynamic Programming (DP)");
109 
110  // Calculate the optimal protections by DP.
111  rmolService.optimalOptimisationByDP ();
112  break;
113  }
114 
115  case 2: {
116  // DEBUG
117  STDAIR_LOG_DEBUG ("Calculate the Bid-Price Vectors (BPV) by EMSR");
118 
119  // Calculate the Bid-Price Vector by EMSR
120  rmolService.heuristicOptimisationByEmsr ();
121  break;
122  }
123 
124  case 3: {
125  // DEBUG
126  STDAIR_LOG_DEBUG ("Calculate the Authorisation Levels (AUs) by EMSRa");
127 
128  // Calculate the protections by EMSR-a
129  // Test the EMSR-a algorithm implementation
130  rmolService.heuristicOptimisationByEmsrA ();
131 
132  // Return a cumulated booking limit value to test
133  // oExpectedBookingLimit = static_cast<int> (lBookingLimitVector.at(2));
134  break;
135  }
136 
137  case 4: {
138  // DEBUG
139  STDAIR_LOG_DEBUG ("Calculate the Authorisation Levels (AUs) by EMSRb");
140 
141  // Calculate the protections by EMSR-b
142  rmolService.heuristicOptimisationByEmsrB ();
143  break;
144  }
145 
146  default: rmolService.optimalOptimisationByMCIntegration (K);
147  }
148 
149  // Close the log file
150  logOutputFile.close();
151 
152  return oExpectedBookingLimit;
153 }
154 
155 
156 // /////////////// Main: Unit Test Suite //////////////
157 
158 // Set the UTF configuration (re-direct the output to a specific file)
159 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
160 
161 // //////////////////////////////////////////////////////////////////////
162 // Tests are based on the following input values
163 // price; mean; standard deviation;
164 // 1050; 17.3; 5.8;
165 // 567; 45.1; 15.0;
166 // 534; 39.6; 13.2;
167 // 520; 34.0; 11.3;
168 // //////////////////////////////////////////////////////////////////////
169 
174 BOOST_AUTO_TEST_SUITE (master_test_suite)
175 
176 
179 BOOST_AUTO_TEST_CASE (rmol_optimisation_monte_carlo) {
180 
181  // State whether the BOM tree should be built-in or parsed from an input file
182  const bool isBuiltin = false;
183 
184  BOOST_CHECK_NO_THROW (testOptimiseHelper(0, isBuiltin););
185 }
186 
190 BOOST_AUTO_TEST_CASE (rmol_optimisation_dynamic_programming) {
191 
192  // State whether the BOM tree should be built-in or parsed from an input file
193  const bool isBuiltin = false;
194 
195  BOOST_CHECK_NO_THROW (testOptimiseHelper(1, isBuiltin););
196 }
197 
202 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_bpv) {
203 
204  // State whether the BOM tree should be built-in or parsed from an input file
205  const bool isBuiltin = false;
206 
207  BOOST_CHECK_NO_THROW (testOptimiseHelper(2, isBuiltin););
208 }
209 
214 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_a) {
215 
216  // State whether the BOM tree should be built-in or parsed from an input file
217  const bool isBuiltin = false;
218 
219  BOOST_CHECK_NO_THROW (testOptimiseHelper(3, isBuiltin););
220  // const int lBookingLimit = testOptimiseHelper(3);
221  // const int lExpectedBookingLimit = 61;
222  // BOOST_CHECK_EQUAL (lBookingLimit, lExpectedBookingLimit);
223  // BOOST_CHECK_MESSAGE (lBookingLimit == lExpectedBookingLimit,
224  // "The booking limit is " << lBookingLimit
225  // << ", but it is expected to be "
226  // << lExpectedBookingLimit);
227 }
228 
233 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_b) {
234 
235  // State whether the BOM tree should be built-in or parsed from an input file
236  const bool isBuiltin = false;
237 
238  BOOST_CHECK_NO_THROW (testOptimiseHelper(4, isBuiltin););
239 }
240 
244 BOOST_AUTO_TEST_CASE (rmol_optimisation_monte_carlo_built_in) {
245 
246  // State whether the BOM tree should be built-in or parsed from an input file
247  const bool isBuiltin = true;
248 
249  BOOST_CHECK_NO_THROW (testOptimiseHelper(0, isBuiltin););
250 }
251 
255 BOOST_AUTO_TEST_CASE (rmol_optimisation_dynamic_programming_built_in) {
256 
257  // State whether the BOM tree should be built-in or parsed from an input file
258  const bool isBuiltin = true;
259 
260  BOOST_CHECK_NO_THROW (testOptimiseHelper(1, isBuiltin););
261 }
262 
267 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_bpv_built_in) {
268 
269  // State whether the BOM tree should be built-in or parsed from an input file
270  const bool isBuiltin = true;
271 
272  BOOST_CHECK_NO_THROW (testOptimiseHelper(2, isBuiltin););
273 }
274 
279 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_a_built_in) {
280 
281  // State whether the BOM tree should be built-in or parsed from an input file
282  const bool isBuiltin = true;
283 
284  BOOST_CHECK_NO_THROW (testOptimiseHelper(3, isBuiltin););
285 }
286 
291 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_b_built_in) {
292 
293  // State whether the BOM tree should be built-in or parsed from an input file
294  const bool isBuiltin = true;
295 
296  BOOST_CHECK_NO_THROW (testOptimiseHelper(4, isBuiltin););
297 }
298 
299 // End the test suite
300 BOOST_AUTO_TEST_SUITE_END()
301 
302