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