RMOL Logo  1.00.0
C++ library of Revenue Management and Optimisation classes and functions
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
EMDetruncator.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <iostream>
6 #include <cmath>
7 #include <vector>
8 #include <cassert>
9 // StdAir
10 #include <stdair/stdair_basic_types.hpp>
11 #include <stdair/service/Logger.hpp>
12 // RMOL
15 
16 namespace RMOL {
17 
18  // ////////////////////////////////////////////////////////////////////
20  (HistoricalBookingHolder& ioHistoricalBookingHolder) {
21 
22  // Number of flights.
23  const short lNbOfFlights =
24  ioHistoricalBookingHolder.getNbOfFlights();
25 
26  // Number of uncensored booking data.
27  const short lNbOfUncensoredData =
28  ioHistoricalBookingHolder.getNbOfUncensoredData();
29 
30  if (lNbOfUncensoredData > 1) {
31  // Number of uncensored bookings.
32  const stdair::NbOfBookings_T lNbOfUncensoredBookings =
33  ioHistoricalBookingHolder.getNbOfUncensoredBookings();
34 
35  const double lMeanOfUncensoredBookings =
36  static_cast<double>(lNbOfUncensoredBookings/lNbOfUncensoredData);
37 
38  const double lStdDevOfUncensoredBookings =
39  ioHistoricalBookingHolder.getUncensoredStandardDeviation
40  (lMeanOfUncensoredBookings, lNbOfUncensoredData);
41 
42  std::vector<bool> toBeUnconstrained =
43  ioHistoricalBookingHolder.getListOfToBeUnconstrainedFlags();
44 
45  double lDemandMean = lMeanOfUncensoredBookings;
46  double lStdDev = lStdDevOfUncensoredBookings;
47 
48  // DEBUG
49  // STDAIR_LOG_DEBUG ("mean: " << lDemandMean << ", std: " << lStdDev);
50 
51  if (lStdDev != 0) {
52  bool stopUnconstraining = false;
53  while (stopUnconstraining == false) {
54  stopUnconstraining = true;
55 
56  for (short i = 0; i < lNbOfFlights; ++i) {
57  if (toBeUnconstrained.at(i) == true) {
58  // Get the unconstrained demand of the (i+1)-th flight.
59  const stdair::NbOfBookings_T demand =
60  ioHistoricalBookingHolder.getUnconstrainedDemand (i);
61  //STDAIR_LOG_DEBUG ("demand: " << demand);
62 
63  // Execute the Expectation step.
64  const stdair::NbOfBookings_T expectedDemand =
65  ioHistoricalBookingHolder.
66  calculateExpectedDemand (lDemandMean, lStdDev, i, demand);
67  //STDAIR_LOG_DEBUG ("expected: " << expectedDemand);
68  assert (expectedDemand >= 0 || expectedDemand < 0);
69 
70  double absDiff =
71  static_cast<double>(expectedDemand - demand);
72 
73  if (absDiff < 0) {
74  absDiff = - absDiff;
75  }
76  if (absDiff < 0.001) {
77  toBeUnconstrained.at (i) = false;
78  }
79  else {
80  stopUnconstraining = false;
81  }
82 
83  ioHistoricalBookingHolder.setUnconstrainedDemand (expectedDemand,
84  i);
85  }
86  }
87 
88  if (stopUnconstraining == false) {
89  lDemandMean = ioHistoricalBookingHolder.getDemandMean();
90  lStdDev =
91  ioHistoricalBookingHolder.getStandardDeviation (lDemandMean);
92  }
93  }
94  }
95  }
96 
97  }
98 }