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