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