Go to the documentation of this file.00001
00002
00003
00004
00005 #include <sstream>
00006 #include <iostream>
00007 #include <iomanip>
00008 #include <cmath>
00009 #include <cassert>
00010
00011 #include <stdair/service/Logger.hpp>
00012
00013 #include <rmol/bom/HistoricalBooking.hpp>
00014 #include <rmol/bom/HistoricalBookingHolder.hpp>
00015
00016 namespace RMOL {
00017
00018
00019 HistoricalBookingHolder::HistoricalBookingHolder () {
00020 }
00021
00022
00023 HistoricalBookingHolder::~HistoricalBookingHolder () {
00024 _historicalBookingVector.clear();
00025 }
00026
00027
00028 const short HistoricalBookingHolder::getNbOfFlights () const {
00029 return _historicalBookingVector.size();
00030 }
00031
00032
00033 const short HistoricalBookingHolder::getNbOfUncensoredData () const {
00034 short lResult = 0;
00035 const short lSize = _historicalBookingVector.size();
00036
00037 for (short ite = 0; ite < lSize; ++ite) {
00038 const stdair::Flag_T lFlag = _historicalBookingVector.at(ite).getFlag ();
00039 if (lFlag == false) {
00040 ++ lResult;
00041 }
00042 }
00043
00044 return lResult;
00045 }
00046
00047
00048 const stdair::NbOfBookings_T HistoricalBookingHolder::
00049 getNbOfUncensoredBookings () const {
00050 stdair::NbOfBookings_T lResult = 0;
00051 const short lSize = _historicalBookingVector.size();
00052
00053 for (short ite = 0; ite < lSize; ++ite) {
00054 const HistoricalBooking& lHistorialBooking =
00055 _historicalBookingVector.at (ite);
00056 const stdair::Flag_T lFlag = lHistorialBooking.getFlag ();
00057 if (lFlag == false) {
00058 const stdair::NbOfBookings_T& lBooking =
00059 lHistorialBooking.getNbOfBookings ();
00060 lResult += lBooking;
00061 }
00062 }
00063
00064 return lResult;
00065 }
00066
00067
00068 const double HistoricalBookingHolder::
00069 getUncensoredStandardDeviation (const double& iMeanOfUncensoredBookings,
00070 const short iNbOfUncensoredData) const {
00071
00072 double lResult = 0;
00073 const short lSize = _historicalBookingVector.size();
00074
00075 for (short ite = 0; ite < lSize; ++ite) {
00076 const stdair::Flag_T lFlag = _historicalBookingVector.at(ite).getFlag ();
00077 if (lFlag == false) {
00078 const HistoricalBooking& lHistorialBooking =
00079 _historicalBookingVector.at (ite);
00080
00081 const stdair::NbOfBookings_T& lBooking =
00082 lHistorialBooking.getNbOfBookings ();
00083
00084 lResult += (lBooking - iMeanOfUncensoredBookings)
00085 * (lBooking - iMeanOfUncensoredBookings);
00086 }
00087 }
00088 lResult /= (iNbOfUncensoredData - 1);
00089 lResult = sqrt (lResult);
00090
00091 return lResult;
00092 }
00093
00094
00095 const double HistoricalBookingHolder::getDemandMean () const {
00096 double lResult = 0;
00097 const short lSize = _historicalBookingVector.size();
00098
00099 for (short ite = 0; ite < lSize; ++ite) {
00100 const HistoricalBooking& lHistorialBooking =
00101 _historicalBookingVector.at(ite);
00102
00103 const stdair::NbOfBookings_T& lDemand =
00104 lHistorialBooking.getUnconstrainedDemand ();
00105
00106 lResult += static_cast<double>(lDemand);
00107 }
00108
00109 lResult /= lSize;
00110
00111 return lResult;
00112 }
00113
00114
00115 const double HistoricalBookingHolder::getStandardDeviation
00116 (const double iDemandMean) const {
00117 double lResult = 0;
00118 const short lSize = _historicalBookingVector.size();
00119
00120 for (short ite = 0; ite < lSize; ++ite) {
00121 const HistoricalBooking& lHistorialBooking =
00122 _historicalBookingVector.at(ite);
00123
00124 const stdair::NbOfBookings_T& lDemand =
00125 lHistorialBooking.getUnconstrainedDemand ();
00126
00127 const double lDoubleDemand = static_cast<double> (lDemand);
00128 lResult += (lDoubleDemand - iDemandMean) * (lDoubleDemand - iDemandMean);
00129 }
00130
00131 lResult /= (lSize - 1);
00132
00133 lResult = sqrt (lResult);
00134
00135 return lResult;
00136 }
00137
00138
00139 const std::vector<bool> HistoricalBookingHolder::
00140 getListOfToBeUnconstrainedFlags () const {
00141 std::vector<bool> lResult;
00142 const short lSize = _historicalBookingVector.size();
00143
00144 for (short ite = 0; ite < lSize; ++ite) {
00145 const HistoricalBooking& lHistorialBooking =
00146 _historicalBookingVector.at(ite);
00147 const stdair::Flag_T lFlag = lHistorialBooking.getFlag ();
00148 if (lFlag == true) {
00149 lResult.push_back(true);
00150 }
00151 else {
00152 lResult.push_back(false);
00153 }
00154 }
00155
00156 return lResult;
00157 }
00158
00159
00160 const stdair::NbOfBookings_T& HistoricalBookingHolder::
00161 getHistoricalBooking (const short i) const {
00162 const HistoricalBooking& lHistorialBooking =
00163 _historicalBookingVector.at(i);
00164 return lHistorialBooking.getNbOfBookings();
00165 }
00166
00167
00168 const stdair::NbOfBookings_T& HistoricalBookingHolder::
00169 getUnconstrainedDemand (const short i) const {
00170 const HistoricalBooking& lHistorialBooking =
00171 _historicalBookingVector.at(i);
00172 return lHistorialBooking.getUnconstrainedDemand();
00173 }
00174
00175
00176 const stdair::Flag_T& HistoricalBookingHolder::
00177 getCensorshipFlag (const short i) const {
00178 const HistoricalBooking& lHistorialBooking =
00179 _historicalBookingVector.at(i);
00180 return lHistorialBooking.getFlag();
00181 }
00182
00183
00184 void HistoricalBookingHolder::setUnconstrainedDemand
00185 (const stdair::NbOfBookings_T& iExpectedDemand, const short i) {
00186 _historicalBookingVector.at(i).setUnconstrainedDemand(iExpectedDemand);
00187 }
00188
00189
00190 const stdair::NbOfBookings_T HistoricalBookingHolder::calculateExpectedDemand
00191 (const double iMean, const double iSD,
00192 const short i, const stdair::NbOfBookings_T iDemand) const {
00193
00194 const HistoricalBooking lHistorialBooking =
00195 _historicalBookingVector.at(i);
00196 const double lBooking =
00197 static_cast <double> (lHistorialBooking.getNbOfBookings());
00198 double e, d1, d2;
00199
00200 e = - (lBooking - iMean) * (lBooking - iMean) * 0.625 / (iSD * iSD);
00201
00202 e = exp (e);
00203
00204
00205 double s = sqrt (1 - e);
00206
00207
00208 if (lBooking >= iMean) {
00209 if (e < 0.01) {
00210 return iDemand;
00211 }
00212 d1 = 0.5 * (1 - s);
00213 }
00214 else {
00215 d1 = 0.5 * (1 + s);
00216 }
00217
00218
00219 e = - (lBooking - iMean) * (lBooking - iMean) * 0.5 / (iSD * iSD);
00220 e = exp (e);
00221 d2 = e * iSD / sqrt(2 * 3.14159265);
00222
00223
00224 if (d1 == 0) {
00225 return iDemand;
00226 }
00227
00228 const stdair::NbOfBookings_T lDemand =
00229 static_cast<stdair::NbOfBookings_T> (iMean + d2/d1);
00230
00231 return lDemand;
00232 }
00233
00234
00235 void HistoricalBookingHolder::addHistoricalBooking
00236 (const HistoricalBooking& iHistoricalBooking) {
00237 _historicalBookingVector.push_back(iHistoricalBooking);
00238 }
00239
00240
00241 void HistoricalBookingHolder::toStream (std::ostream& ioOut) const {
00242 const short lSize = _historicalBookingVector.size();
00243
00244 ioOut << "Historical Booking; Unconstrained Demand; Flag" << std::endl;
00245
00246 for (short ite = 0; ite < lSize; ++ite) {
00247 const HistoricalBooking& lHistorialBooking =
00248 _historicalBookingVector.at(ite);
00249
00250 const stdair::NbOfBookings_T& lBooking =
00251 lHistorialBooking.getNbOfBookings();
00252
00253 const stdair::NbOfBookings_T& lDemand =
00254 lHistorialBooking.getUnconstrainedDemand();
00255
00256 const stdair::Flag_T lFlag = lHistorialBooking.getFlag();
00257
00258 ioOut << lBooking << " "
00259 << lDemand << " "
00260 << lFlag << std::endl;
00261 }
00262 }
00263
00264
00265 const std::string HistoricalBookingHolder::describe() const {
00266 std::ostringstream ostr;
00267 ostr << "Holder of HistoricalBooking structs.";
00268
00269 return ostr.str();
00270 }
00271
00272
00273 void HistoricalBookingHolder::display() const {
00274 toStream (std::cout);
00275 }
00276 }