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