RMOL Logo  1.00.9
C++ library of Revenue Management and Optimisation classes and functions
Loading...
Searching...
No Matches
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
16namespace 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
69 double absDiff =
70 static_cast<double>(expectedDemand - demand);
71
72 if (absDiff < 0) {
73 absDiff = - absDiff;
74 }
75 if (absDiff < 0.001) {
76 toBeUnconstrained.at (i) = false;
77 }
78 else {
79 stopUnconstraining = false;
80 }
81
82 ioHistoricalBookingHolder.setUnconstrainedDemand (expectedDemand,
83 i);
84 }
85 }
86
87 if (stopUnconstraining == false) {
88 lDemandMean = ioHistoricalBookingHolder.getDemandMean();
89 lStdDev =
90 ioHistoricalBookingHolder.getStandardDeviation (lDemandMean);
91 }
92 }
93 }
94 }
95
96 }
97}
static void unconstrain(HistoricalBookingHolder &)
const stdair::NbOfBookings_T getNbOfUncensoredBookings() const
const double getUncensoredStandardDeviation(const double &iMeanOfUncensoredBookings, const short iNbOfUncensoredData) const
void setUnconstrainedDemand(const stdair::NbOfBookings_T &iExpectedDemand, const short i)
const std::vector< bool > getListOfToBeUnconstrainedFlags() const
const stdair::NbOfBookings_T & getUnconstrainedDemand(const short i) const
const double getStandardDeviation(const double) const