$treeview $search $mathjax
RMOL Logo  1.00.1
$projectbrief
$projectbrief
$searchbox

rmol/bom/EMDetruncator.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <iostream>
00006 #include <cmath>
00007 #include <vector>
00008 #include <cassert>
00009 // StdAir
00010 #include <stdair/stdair_basic_types.hpp>
00011 #include <stdair/service/Logger.hpp>
00012 // RMOL
00013 #include <rmol/bom/HistoricalBookingHolder.hpp>
00014 #include <rmol/bom/EMDetruncator.hpp>
00015 
00016 namespace RMOL {
00017     
00018   // ////////////////////////////////////////////////////////////////////
00019   void EMDetruncator::unconstrain
00020   (HistoricalBookingHolder& ioHistoricalBookingHolder) {
00021       
00022     // Number of flights.
00023     const short lNbOfFlights =
00024       ioHistoricalBookingHolder.getNbOfFlights();
00025 
00026     // Number of uncensored booking data.
00027     const short lNbOfUncensoredData =
00028       ioHistoricalBookingHolder.getNbOfUncensoredData();
00029 
00030     if (lNbOfUncensoredData > 1) {
00031       // Number of uncensored bookings.
00032       const stdair::NbOfBookings_T lNbOfUncensoredBookings =
00033         ioHistoricalBookingHolder.getNbOfUncensoredBookings();
00034         
00035       const double lMeanOfUncensoredBookings =
00036         static_cast<double>(lNbOfUncensoredBookings/lNbOfUncensoredData);
00037 
00038       const double lStdDevOfUncensoredBookings =
00039         ioHistoricalBookingHolder.getUncensoredStandardDeviation
00040         (lMeanOfUncensoredBookings, lNbOfUncensoredData);
00041 
00042       std::vector<bool> toBeUnconstrained =
00043         ioHistoricalBookingHolder.getListOfToBeUnconstrainedFlags();
00044 
00045       double lDemandMean = lMeanOfUncensoredBookings;
00046       double lStdDev = lStdDevOfUncensoredBookings;
00047 
00048       // DEBUG
00049       // STDAIR_LOG_DEBUG ("mean: " << lDemandMean << ", std: " << lStdDev);
00050         
00051       if (lStdDev != 0) {
00052         bool stopUnconstraining = false;
00053         while (stopUnconstraining == false) {
00054           stopUnconstraining = true;
00055             
00056           for (short i = 0; i < lNbOfFlights; ++i) {
00057             if (toBeUnconstrained.at(i) == true) {
00058               // Get the unconstrained demand of the (i+1)-th flight.
00059               const stdair::NbOfBookings_T demand =
00060                 ioHistoricalBookingHolder.getUnconstrainedDemand (i);
00061               //STDAIR_LOG_DEBUG ("demand: " << demand);
00062                 
00063               // Execute the Expectation step.
00064               const stdair::NbOfBookings_T expectedDemand =
00065                 ioHistoricalBookingHolder.
00066                 calculateExpectedDemand (lDemandMean, lStdDev, i, demand);
00067               //STDAIR_LOG_DEBUG ("expected: " << expectedDemand);
00068                
00069               double absDiff =
00070                 static_cast<double>(expectedDemand - demand);
00071                 
00072               if (absDiff < 0) {
00073                 absDiff = - absDiff;
00074               }
00075               if (absDiff < 0.001) {
00076                 toBeUnconstrained.at (i) = false;
00077               }
00078               else {
00079                 stopUnconstraining = false;
00080               }
00081                 
00082               ioHistoricalBookingHolder.setUnconstrainedDemand (expectedDemand,
00083                                                                 i);
00084             }
00085           }
00086             
00087           if (stopUnconstraining == false) {
00088             lDemandMean = ioHistoricalBookingHolder.getDemandMean();
00089             lStdDev =
00090               ioHistoricalBookingHolder.getStandardDeviation (lDemandMean);
00091           }
00092         }
00093       }
00094     }
00095       
00096   }
00097 }