RMOL Logo  1.00.1
C++ library of Revenue Management and Optimisation classes and functions
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 #include <boost/version.hpp>
18 // StdAir
19 #include <stdair/basic/BasLogParams.hpp>
20 #include <stdair/basic/BasDBParams.hpp>
21 #include <stdair/basic/BasFileMgr.hpp>
22 #include <stdair/service/Logger.hpp>
23 // RMOL
25 #include <rmol/RMOL_Service.hpp>
27 
28 namespace boost_utf = boost::unit_test;
29 
30 // (Boost) Unit Test XML Report
31 std::ofstream utfReportStream ("OptimiseTestSuite_utfresults.xml");
32 
36 struct UnitTestConfig {
38  UnitTestConfig() {
39  boost_utf::unit_test_log.set_stream (utfReportStream);
40 #if BOOST_VERSION >= 105900
41  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
42 #else
43  boost_utf::unit_test_log.set_format (boost_utf::XML);
44 #endif
45  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
46  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
47  }
48 
50  ~UnitTestConfig() {
51  }
52 };
53 
54 
55 // //////////////////////////////////////////////////////////////////////
56 int testOptimiseHelper (const unsigned short optimisationMethodFlag,
57  const bool isBuiltin) {
58 
59  // Return value
60  int oExpectedBookingLimit = 0;
61 
62  // Output log File
63  std::ostringstream oStr;
64  oStr << "OptimiseTestSuite_" << optimisationMethodFlag << "_" << isBuiltin << ".log";
65  const stdair::Filename_T lLogFilename (oStr.str());
66 
67  // Number of random draws to be generated (best if greater than 100)
69 
70  // Methods of optimisation (0 = Monte-Carlo, 1 = Dynamic Programming,
71  // 2 = EMSR, 3 = EMSR-a, 4 = EMSR-b, 5 = EMSR-a with sellup prob.)
72  const unsigned short METHOD_FLAG = optimisationMethodFlag;
73 
74  // Cabin Capacity (it must be greater then 100 here)
75  const double cabinCapacity = 100.0;
76 
77  // Set the log parameters
78  std::ofstream logOutputFile;
79  // Open and clean the log outputfile
80  logOutputFile.open (lLogFilename.c_str());
81  logOutputFile.clear();
82 
83  // Initialise the RMOL service
84  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
85  RMOL::RMOL_Service rmolService (lLogParams);
86 
87  // Check wether or not a (CSV) input file should be read
88  if (isBuiltin == true) {
89 
90  // Build the default sample BOM tree and build a dummy BOM tree.
91  rmolService.buildSampleBom();
92 
93  } else {
94 
95  // Parse the optimisation data and build a dummy BOM tree
96  const stdair::Filename_T lRMInputFileName (STDAIR_SAMPLE_DIR "/rm02.csv");
97  rmolService.parseAndLoad (cabinCapacity, lRMInputFileName);
98  }
99 
100  switch (METHOD_FLAG) {
101  case 0: {
102  // DEBUG
103  STDAIR_LOG_DEBUG ("Optimisation by Monte-Carlo (MC)");
104 
105  // Calculate the optimal protections by the Monte Carlo
106  // Integration approach
107  rmolService.optimalOptimisationByMCIntegration (K);
108  break;
109  }
110 
111  case 1: {
112  // DEBUG
113  STDAIR_LOG_DEBUG ("Optimisation by Dynamic Programming (DP)");
114 
115  // Calculate the optimal protections by DP.
116  rmolService.optimalOptimisationByDP ();
117  break;
118  }
119 
120  case 2: {
121  // DEBUG
122  STDAIR_LOG_DEBUG ("Calculate the Bid-Price Vectors (BPV) by EMSR");
123 
124  // Calculate the Bid-Price Vector by EMSR
125  rmolService.heuristicOptimisationByEmsr ();
126  break;
127  }
128 
129  case 3: {
130  // DEBUG
131  STDAIR_LOG_DEBUG ("Calculate the Authorisation Levels (AUs) by EMSRa");
132 
133  // Calculate the protections by EMSR-a
134  // Test the EMSR-a algorithm implementation
135  rmolService.heuristicOptimisationByEmsrA ();
136 
137  // Return a cumulated booking limit value to test
138  // oExpectedBookingLimit = static_cast<int> (lBookingLimitVector.at(2));
139  break;
140  }
141 
142  case 4: {
143  // DEBUG
144  STDAIR_LOG_DEBUG ("Calculate the Authorisation Levels (AUs) by EMSRb");
145 
146  // Calculate the protections by EMSR-b
147  rmolService.heuristicOptimisationByEmsrB ();
148  break;
149  }
150 
151  default: rmolService.optimalOptimisationByMCIntegration (K);
152  }
153 
154  // Close the log file
155  logOutputFile.close();
156 
157  return oExpectedBookingLimit;
158 }
159 
160 
161 // /////////////// Main: Unit Test Suite //////////////
162 
163 // Set the UTF configuration (re-direct the output to a specific file)
164 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
165 
166 // //////////////////////////////////////////////////////////////////////
167 // Tests are based on the following input values
168 // price; mean; standard deviation;
169 // 1050; 17.3; 5.8;
170 // 567; 45.1; 15.0;
171 // 534; 39.6; 13.2;
172 // 520; 34.0; 11.3;
173 // //////////////////////////////////////////////////////////////////////
174 
179 BOOST_AUTO_TEST_SUITE (master_test_suite)
180 
181 
184 BOOST_AUTO_TEST_CASE (rmol_optimisation_monte_carlo) {
185 
186  // State whether the BOM tree should be built-in or parsed from an input file
187  const bool isBuiltin = false;
188 
189  BOOST_CHECK_NO_THROW (testOptimiseHelper(0, isBuiltin););
190 }
191 
195 BOOST_AUTO_TEST_CASE (rmol_optimisation_dynamic_programming) {
196 
197  // State whether the BOM tree should be built-in or parsed from an input file
198  const bool isBuiltin = false;
199 
200  BOOST_CHECK_NO_THROW (testOptimiseHelper(1, isBuiltin););
201 }
202 
207 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_bpv) {
208 
209  // State whether the BOM tree should be built-in or parsed from an input file
210  const bool isBuiltin = false;
211 
212  BOOST_CHECK_NO_THROW (testOptimiseHelper(2, isBuiltin););
213 }
214 
219 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_a) {
220 
221  // State whether the BOM tree should be built-in or parsed from an input file
222  const bool isBuiltin = false;
223 
224  BOOST_CHECK_NO_THROW (testOptimiseHelper(3, isBuiltin););
225  // const int lBookingLimit = testOptimiseHelper(3);
226  // const int lExpectedBookingLimit = 61;
227  // BOOST_CHECK_EQUAL (lBookingLimit, lExpectedBookingLimit);
228  // BOOST_CHECK_MESSAGE (lBookingLimit == lExpectedBookingLimit,
229  // "The booking limit is " << lBookingLimit
230  // << ", but it is expected to be "
231  // << lExpectedBookingLimit);
232 }
233 
238 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_b) {
239 
240  // State whether the BOM tree should be built-in or parsed from an input file
241  const bool isBuiltin = false;
242 
243  BOOST_CHECK_NO_THROW (testOptimiseHelper(4, isBuiltin););
244 }
245 
249 BOOST_AUTO_TEST_CASE (rmol_optimisation_monte_carlo_built_in) {
250 
251  // State whether the BOM tree should be built-in or parsed from an input file
252  const bool isBuiltin = true;
253 
254  BOOST_CHECK_NO_THROW (testOptimiseHelper(0, isBuiltin););
255 }
256 
260 BOOST_AUTO_TEST_CASE (rmol_optimisation_dynamic_programming_built_in) {
261 
262  // State whether the BOM tree should be built-in or parsed from an input file
263  const bool isBuiltin = true;
264 
265  BOOST_CHECK_NO_THROW (testOptimiseHelper(1, isBuiltin););
266 }
267 
272 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_bpv_built_in) {
273 
274  // State whether the BOM tree should be built-in or parsed from an input file
275  const bool isBuiltin = true;
276 
277  BOOST_CHECK_NO_THROW (testOptimiseHelper(2, isBuiltin););
278 }
279 
284 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_a_built_in) {
285 
286  // State whether the BOM tree should be built-in or parsed from an input file
287  const bool isBuiltin = true;
288 
289  BOOST_CHECK_NO_THROW (testOptimiseHelper(3, isBuiltin););
290 }
291 
296 BOOST_AUTO_TEST_CASE (rmol_optimisation_emsr_b_built_in) {
297 
298  // State whether the BOM tree should be built-in or parsed from an input file
299  const bool isBuiltin = true;
300 
301  BOOST_CHECK_NO_THROW (testOptimiseHelper(4, isBuiltin););
302 }
303 
304 // End the test suite
305 BOOST_AUTO_TEST_SUITE_END()
306 
307 
#define STDAIR_SAMPLE_DIR
Definition: rmol-paths.hpp:22
const int DEFAULT_NUMBER_OF_DRAWS_FOR_MC_SIMULATION
Definition: BasConst.cpp:17
Interface for the RMOL Services.