RMOL Logo  1.00.1
C++ library of Revenue Management and Optimisation classes and functions
bomsforforecaster.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <cassert>
10 #include <limits>
11 #include <sstream>
12 #include <fstream>
13 #include <string>
14 // Boost Unit Test Framework (UTF)
15 #define BOOST_TEST_DYN_LINK
16 #define BOOST_TEST_MAIN
17 #define BOOST_TEST_MODULE OptimiseTestSuite
18 #include <boost/test/unit_test.hpp>
19 #include <boost/version.hpp>
20 // StdAir
21 #include <stdair/basic/BasLogParams.hpp>
22 #include <stdair/basic/BasDBParams.hpp>
23 #include <stdair/service/Logger.hpp>
24 // 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 ("bomsforforecaster_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 namespace RMOL {
55 
57  struct BookingClassData {
58 
59  // Attributes
60  double _bookingCount;
61  double _fare;
62  double _sellupFactor;
63  bool _censorshipFlag;
64 
65  // Constructer
66  BookingClassData (const double iBookingCount, const double iFare,
67  const double iSellupFactor, const bool iCensorshipFlag)
68  : _bookingCount(iBookingCount), _fare(iFare),
69  _sellupFactor(iSellupFactor), _censorshipFlag(iCensorshipFlag) {
70  }
71 
72  // Getters
73  double getFare () const {
74  return _fare;
75  }
76 
77  bool getCensorshipFlag () const {
78  return _censorshipFlag;
79  }
80 
81  // Display
82  std::string toString() const {
83  std::ostringstream oStr;
84  oStr << std::endl
85  << "[Booking class data information]" << std::endl
86  << "Booking counter: " << _bookingCount << std::endl
87  << "Fare: " << _fare << std::endl
88  << "Sell-up Factor: " << _sellupFactor << std::endl
89  << "censorshipFlag: " << _censorshipFlag << std::endl;
90  return oStr.str();
91  }
92 
93  };
94 
96  struct BookingClassDataSet {
97 
98  typedef std::vector<BookingClassData*> BookingClassDataList_T;
99 
100  // Attributes
101  int _numberOfClass;
102  double _minimumFare;
103  bool _censorshipFlag; // true if any of the classes is censored
104  BookingClassDataList_T _bookingClassDataList;
105 
106  // Constructor
107  BookingClassDataSet ()
108  : _numberOfClass(0), _minimumFare(0),
109  _censorshipFlag(false) {
110  }
111 
112  // Add BookingClassData
113  void addBookingClassData (BookingClassData& ioBookingClassData) {
114  _bookingClassDataList.push_back (&ioBookingClassData);
115  }
116 
117  // Getters
118  stdair::NbOfClasses_T getNumberOfClass () const {
119  return _bookingClassDataList.size();
120  }
121 
122  double getMinimumFare () const {
123  return _minimumFare;
124  }
125 
126  bool getCensorshipFlag () const {
127  return _censorshipFlag;
128  }
129 
130  // Setters
131  void setMinimumFare (const double iMinFare) {
132  _minimumFare = iMinFare;
133  }
134 
135  void setCensorshipFlag (const bool iCensorshipFlag) {
136  _censorshipFlag = iCensorshipFlag;
137  }
138 
139  // compute minimum fare
140  void updateMinimumFare() {
141  double minFare = std::numeric_limits<double>::max();
142  BookingClassDataList_T::iterator itBookingClassDataList;
143  for (itBookingClassDataList = _bookingClassDataList.begin();
144  itBookingClassDataList != _bookingClassDataList.end();
145  ++itBookingClassDataList) {
146  BookingClassData* lBookingClassData = *itBookingClassDataList;
147  assert (lBookingClassData != NULL);
148 
149  const double lFare = lBookingClassData->getFare();
150  if (lFare < minFare) {
151  minFare = lFare;
152  }
153  }
154  //
155  setMinimumFare(minFare);
156  }
157 
158  // compute censorship flag for the data set
159  void updateCensorshipFlag () {
160  bool censorshipFlag = false;
161  BookingClassDataList_T::iterator itBookingClassDataList;
162  for (itBookingClassDataList = _bookingClassDataList.begin();
163  itBookingClassDataList != _bookingClassDataList.end();
164  ++itBookingClassDataList) {
165  BookingClassData* lBookingClassData = *itBookingClassDataList;
166  assert (lBookingClassData != NULL);
167 
168  const bool lCensorshipFlagOfAClass =
169  lBookingClassData->getCensorshipFlag();
170  if (lCensorshipFlagOfAClass) {
171  censorshipFlag = true;
172  break;
173  }
174  }
175  //
176  setCensorshipFlag(censorshipFlag);
177  }
178 
179  // Display
180  std::string toString() const {
181  std::ostringstream oStr;
182  oStr << std::endl
183  << "[Booking class data set information]" << std::endl
184  << "Number of classes: " << _numberOfClass << std::endl
185  << "Minimum fare: " << _minimumFare << std::endl
186  << "The data of the class set are sensored: " << _censorshipFlag
187  << std::endl;
188  return oStr.str();
189  }
190 
191  };
192 
193  // /**-------------- BOM : Q-Forecaster ----------------------- */
194  // struct QForecaster {
195 
196  // // Function focused BOM
197 
198  // // 1. calculate sell up probability for Q-eq
199 
200  // // 2. calculate Q-Equivalent Booking
201  // double calculateQEqBooking (BookingClassDataSet& iBookingClassDataSet) {
202  // double lQEqBooking = 0.0;
203  // double lMinFare = iBookingClassDataSet.getMinimumFare();
204 
205 
206  // return lQEqBooking;
207  // }
208 
209  // /* Calculate Q-equivalent demand
210  // [<- performed by unconstrainer if necessary (Using ExpMax BOM)]
211  // */
212 
213 
214  // // 3. Partition to each class
215 
216  // //
217 
218  // };
219 
220 }
221 
222 // /////////////// Main: Unit Test Suite //////////////
223 
224 // Set the UTF configuration (re-direct the output to a specific file)
225 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
226 
230 BOOST_AUTO_TEST_SUITE (master_test_suite)
231 
232 
235 BOOST_AUTO_TEST_CASE (rmol_forecaster) {
236 
237  // Output log File
238  std::string lLogFilename ("bomsforforecaster.log");
239  std::ofstream logOutputFile;
240 
241  // Open and clean the log outputfile
242  logOutputFile.open (lLogFilename.c_str());
243  logOutputFile.clear();
244 
245  // Initialise the RMOL service
246  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
247 
248  // Initialise the RMOL service
249  RMOL::RMOL_Service rmolService (lLogParams);
250 
251  // Build a sample BOM tree
252  rmolService.buildSampleBom();
253 
254  // Register BCDataSet
255  RMOL::BookingClassDataSet lBookingClassDataSet;
256 
257  // Register BookingClassData
258  RMOL::BookingClassData QClassData (10, 100, 1, false);
259  RMOL::BookingClassData MClassData (5, 150, 0.8, true);
260  RMOL::BookingClassData BClassData (0, 200, 0.6, false);
261  RMOL::BookingClassData YClassData (0, 300, 0.3, false);
262 
263  // Display
264  STDAIR_LOG_DEBUG (QClassData.toString());
265  STDAIR_LOG_DEBUG (MClassData.toString());
266  STDAIR_LOG_DEBUG (BClassData.toString());
267  STDAIR_LOG_DEBUG (YClassData.toString());
268 
269  // Add BookingClassData into the BCDataSet
270  lBookingClassDataSet.addBookingClassData (QClassData);
271  lBookingClassDataSet.addBookingClassData (MClassData);
272  lBookingClassDataSet.addBookingClassData (BClassData);
273  lBookingClassDataSet.addBookingClassData (YClassData);
274 
275  // DEBUG
276  STDAIR_LOG_DEBUG (lBookingClassDataSet.toString());
277 
278  // Number of classes
279  const stdair::NbOfClasses_T lNbOfClass = lBookingClassDataSet.getNumberOfClass();
280 
281  // DEBUG
282  STDAIR_LOG_DEBUG ("Number of Classes: " << lNbOfClass);
283 
284  // Minimum fare
285  BOOST_CHECK_NO_THROW (lBookingClassDataSet.updateMinimumFare());
286  const double lMinFare = lBookingClassDataSet.getMinimumFare();
287 
288  // DEBUG
289  STDAIR_LOG_DEBUG ("Minimum fare: " << lMinFare);
290 
291  // Censorship flag
292  BOOST_CHECK_NO_THROW (lBookingClassDataSet.updateCensorshipFlag());
293  const bool lCensorshipFlag = lBookingClassDataSet.getCensorshipFlag();
294 
295  // DEBUG
296  STDAIR_LOG_DEBUG ("Censorship Flag: " << lCensorshipFlag);
297 
298  // Close the log output file
299  logOutputFile.close();
300 }
301 
302 // End the test suite
303 BOOST_AUTO_TEST_SUITE_END()
304 
305 
Definition: BasConst.cpp:7
Interface for the RMOL Services.