From: <ben...@us...> - 2008-08-27 08:51:06
|
Revision: 158 http://rmol.svn.sourceforge.net/rmol/?rev=158&view=rev Author: benlardeux Date: 2008-08-27 08:40:35 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Add services that trigger optimization algorithms. Modified Paths: -------------- trunk/rmol/rmol/RMOL.cpp trunk/rmol/rmol/RMOL.hpp Modified: trunk/rmol/rmol/RMOL.cpp =================================================================== --- trunk/rmol/rmol/RMOL.cpp 2008-08-25 12:08:51 UTC (rev 157) +++ trunk/rmol/rmol/RMOL.cpp 2008-08-27 08:40:35 UTC (rev 158) @@ -74,6 +74,23 @@ // ////////////////////////////////////////////////////////////////////// void RMOL:: + optimalOptimisationByMCIntegration (const int K, + BookingLimitVector_T& ioBookingLimitVector) { + + assert (_context != NULL); + const double iCapacity = _context->getCapacity(); + BucketHolder* ioBucketHolder_ptr = _context->getBucketHolder(); + assert (ioBucketHolder_ptr != NULL); + + Optimiser::optimalOptimisationByMCIntegration (K, iCapacity, + *ioBucketHolder_ptr); + + // Fill up booking vector + ioBucketHolder_ptr->fillup(ioBookingLimitVector); + } + + // ////////////////////////////////////////////////////////////////////// + void RMOL:: optimalOptimisationByDP () { assert (_context != NULL); @@ -86,6 +103,21 @@ // Display ioBucketHolder_ptr->display(); } + + // ////////////////////////////////////////////////////////////////////// + void RMOL:: + optimalOptimisationByDP (BookingLimitVector_T& ioBookingLimitVector) { + + assert (_context != NULL); + const double iCapacity = _context->getCapacity(); + BucketHolder* ioBucketHolder_ptr = _context->getBucketHolder(); + assert (ioBucketHolder_ptr != NULL); + + Optimiser::optimalOptimisationByDP (iCapacity, *ioBucketHolder_ptr); + + // Fill up booking vector + ioBucketHolder_ptr->fillup(ioBookingLimitVector); + } // ////////////////////////////////////////////////////////////////////// void RMOL::heuristicOptimisationByEmsr () { @@ -101,6 +133,19 @@ } // ////////////////////////////////////////////////////////////////////// + void RMOL::heuristicOptimisationByEmsr (BookingLimitVector_T& ioBookingLimitVector) { + assert (_context != NULL); + const double iCapacity = _context->getCapacity(); + BucketHolder* ioBucketHolder_ptr = _context->getBucketHolder(); + assert (ioBucketHolder_ptr != NULL); + + Optimiser::heuristicOptimisationByEmsr (iCapacity, *ioBucketHolder_ptr); + + // Fill up booking vector + ioBucketHolder_ptr->fillup(ioBookingLimitVector); + } + + // ////////////////////////////////////////////////////////////////////// void RMOL::heuristicOptimisationByEmsrA () { assert (_context != NULL); const double iCapacity = _context->getCapacity(); @@ -112,6 +157,19 @@ // Display ioBucketHolder_ptr->display(); } + + // ////////////////////////////////////////////////////////////////////// + void RMOL::heuristicOptimisationByEmsrA (BookingLimitVector_T& ioBookingLimitVector) { + assert (_context != NULL); + const double iCapacity = _context->getCapacity(); + BucketHolder* ioBucketHolder_ptr = _context->getBucketHolder(); + assert (ioBucketHolder_ptr != NULL); + + Optimiser::heuristicOptimisationByEmsrA (iCapacity, *ioBucketHolder_ptr); + + // Fill up booking vector + ioBucketHolder_ptr->fillup(ioBookingLimitVector); + } // ////////////////////////////////////////////////////////////////////// void RMOL::heuristicOptimisationByEmsrB () { Modified: trunk/rmol/rmol/RMOL.hpp =================================================================== --- trunk/rmol/rmol/RMOL.hpp 2008-08-25 12:08:51 UTC (rev 157) +++ trunk/rmol/rmol/RMOL.hpp 2008-08-27 08:40:35 UTC (rev 158) @@ -29,22 +29,40 @@ /** Read the input data from a file. */ void readFromInputFile (const std::string& iInputFileName); - /** */ + /** Single resource optimization using the Monte Carlo algorithm. */ void optimalOptimisationByMCIntegration (const int K); - /** */ + /** Single resource optimization that uses Monte-Carlo algorithm and + returns a vector of cumulated booking limits. */ + void optimalOptimisationByMCIntegration (const int K, + BookingLimitVector_T&); + + /** Single resource optimization using dynamic programming. */ void optimalOptimisationByDP (); - /** */ + /** Single resource optimization that uses dynamic programming and + returns a vector of cumulated booking limits. */ + void optimalOptimisationByDP (BookingLimitVector_T&); + + /** Single resource optimization using EMSR heuristic. */ void heuristicOptimisationByEmsr (); + + /** Single resource optimization that uses EMSR heuristic and + returns a vector of cumulated booking limits. */ + void heuristicOptimisationByEmsr (BookingLimitVector_T&); - /** */ + /** Single resource optimization using EMSR-a heuristic. */ void heuristicOptimisationByEmsrA (); + + /** Single resource optimization that uses EMSR-a heuristic and + returns a vector of cumulated booking limits. */ + void heuristicOptimisationByEmsrA (BookingLimitVector_T&); - /** */ + /** Single resource optimization using EMSR-b heuristic. */ void heuristicOptimisationByEmsrB (); - /** */ + /** Single resource optimization that uses EMSR-b heuristic and + returns a vector of cumulated booking limits. */ void heuristicOptimisationByEmsrB (BookingLimitVector_T&); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <qua...@us...> - 2009-02-10 14:46:13
|
Revision: 164 http://rmol.svn.sourceforge.net/rmol/?rev=164&view=rev Author: quannaus Date: 2009-02-10 14:46:08 +0000 (Tue, 10 Feb 2009) Log Message: ----------- Small change in the call for EMSR method. Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.cpp trunk/rmol/rmol/command/Optimiser.cpp trunk/rmol/rmol/command/Optimiser.hpp Modified: trunk/rmol/rmol/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.cpp 2009-01-13 16:48:12 UTC (rev 163) +++ trunk/rmol/rmol/RMOL_Service.cpp 2009-02-10 14:46:08 UTC (rev 164) @@ -3,6 +3,8 @@ // ////////////////////////////////////////////////////////////////////// // C #include <assert.h> +// STL +#include <iomanip> // RMOL #include <rmol/basic/BasConst_RMOL_Service.hpp> #include <rmol/field/FldYieldRange.hpp> @@ -125,25 +127,35 @@ const double iCapacity = _context->getCapacity(); BucketHolder* ioBucketHolder_ptr = _context->getBucketHolder(); assert (ioBucketHolder_ptr != NULL); + BidPriceVector_T lBidPriceVector; - Optimiser::heuristicOptimisationByEmsr (iCapacity, *ioBucketHolder_ptr); + Optimiser::heuristicOptimisationByEmsr (iCapacity, *ioBucketHolder_ptr, + lBidPriceVector); // Display ioBucketHolder_ptr->display(); + + std::cout << "BVP: "; + unsigned int size = lBidPriceVector.size(); + + for (unsigned int i = 0; i < size; ++i) { + const double bidPrice = lBidPriceVector.at(i); + std::cout << std::fixed << std::setprecision (2) << bidPrice << " "; + } + std::cout << std::endl; + } // ////////////////////////////////////////////////////////////////////// void RMOL_Service:: - heuristicOptimisationByEmsr (BookingLimitVector_T& ioBookingLimitVector) { + heuristicOptimisationByEmsr (BidPriceVector_T& ioBidPriceVector) { assert (_context != NULL); const double iCapacity = _context->getCapacity(); BucketHolder* ioBucketHolder_ptr = _context->getBucketHolder(); assert (ioBucketHolder_ptr != NULL); - Optimiser::heuristicOptimisationByEmsr (iCapacity, *ioBucketHolder_ptr); - - // Fill up booking vector - ioBucketHolder_ptr->fillup(ioBookingLimitVector); + Optimiser::heuristicOptimisationByEmsr (iCapacity, *ioBucketHolder_ptr, + ioBidPriceVector); } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/command/Optimiser.cpp =================================================================== --- trunk/rmol/rmol/command/Optimiser.cpp 2009-01-13 16:48:12 UTC (rev 163) +++ trunk/rmol/rmol/command/Optimiser.cpp 2009-02-10 14:46:08 UTC (rev 164) @@ -79,19 +79,11 @@ // ////////////////////////////////////////////////////////////////////// void Optimiser:: heuristicOptimisationByEmsr (const ResourceCapacity_T iCabinCapacity, - BucketHolder& ioBucketHolder) { - BidPriceVector_T lBidPriceVector; + BucketHolder& ioBucketHolder, + BidPriceVector_T& ioBidPriceVector) { Emsr::heuristicOptimisationByEmsr (iCabinCapacity, ioBucketHolder, - lBidPriceVector); - std::cout << "BVP: "; - unsigned int size = lBidPriceVector.size(); - - for (unsigned int i = 0; i < size; ++i) { - const double bidPrice = lBidPriceVector.at(i); - std::cout << std::fixed << std::setprecision (2) << bidPrice << " "; - } - std::cout << std::endl; + ioBidPriceVector); } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/command/Optimiser.hpp =================================================================== --- trunk/rmol/rmol/command/Optimiser.hpp 2009-01-13 16:48:12 UTC (rev 163) +++ trunk/rmol/rmol/command/Optimiser.hpp 2009-02-10 14:46:08 UTC (rev 164) @@ -47,7 +47,8 @@ overbooking. */ static void heuristicOptimisationByEmsr (const ResourceCapacity_T, - BucketHolder&); + BucketHolder&, + BidPriceVector_T&); /** EMRS-a algorithm. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2009-03-22 16:47:24
|
Revision: 180 http://rmol.svn.sourceforge.net/rmol/?rev=180&view=rev Author: denis_arnaud Date: 2009-03-22 16:47:07 +0000 (Sun, 22 Mar 2009) Log Message: ----------- [Dev] Converted DOS-formatted files to Unix-formatted ones. Modified Paths: -------------- trunk/rmol/rmol/basic/BasConst_Overbooking.hpp trunk/rmol/rmol/bom/Overbooking.cpp trunk/rmol/rmol/bom/Overbooking.hpp trunk/rmol/rmol/field/FldOverbookingPolicy.cpp trunk/rmol/rmol/field/FldOverbookingPolicy.hpp Modified: trunk/rmol/rmol/basic/BasConst_Overbooking.hpp =================================================================== --- trunk/rmol/rmol/basic/BasConst_Overbooking.hpp 2009-03-20 17:03:01 UTC (rev 179) +++ trunk/rmol/rmol/basic/BasConst_Overbooking.hpp 2009-03-22 16:47:07 UTC (rev 180) @@ -1,30 +1,30 @@ -#ifndef __RMOL_BAS_BASCONST_OVERBOOKING_HPP -#define __RMOL_BAS_BASCONST_OVERBOOKING_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// - -namespace RMOL { - - /** Default value for the load factor used for overbooking calculation. */ - extern const double DEFAULT_OVERBOOKING_LOAD_FACTOR; - - /** Default value for the capacity used for overbooking calculation. */ - extern const unsigned int DEFAULT_OVERBOOKING_CAPACITY; - - /** Default value for the net bookings used for overbooking calculation. */ - extern const unsigned int DEFAULT_OVERBOOKING_NET_BOOKINGS; - - /** Default value for the overbooking used for overbooking calculation. */ - extern const double DEFAULT_OVERBOOKING_OVERBOOKING_PERCENTAGE; - - /** Default value for the mean used for overbooking calculation. */ - extern const double DEFAULT_OVERBOOKING_MEAN; - - /** Default value for the standard deviation used for overbooking - calculation. */ - extern const double DEFAULT_OVERBOOKING_STANDARD_DEVIATION; - -} -#endif // __RMOL_BAS_BASCONST_OVERBOOKING_HPP +#ifndef __RMOL_BAS_BASCONST_OVERBOOKING_HPP +#define __RMOL_BAS_BASCONST_OVERBOOKING_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// + +namespace RMOL { + + /** Default value for the load factor used for overbooking calculation. */ + extern const double DEFAULT_OVERBOOKING_LOAD_FACTOR; + + /** Default value for the capacity used for overbooking calculation. */ + extern const unsigned int DEFAULT_OVERBOOKING_CAPACITY; + + /** Default value for the net bookings used for overbooking calculation. */ + extern const unsigned int DEFAULT_OVERBOOKING_NET_BOOKINGS; + + /** Default value for the overbooking used for overbooking calculation. */ + extern const double DEFAULT_OVERBOOKING_OVERBOOKING_PERCENTAGE; + + /** Default value for the mean used for overbooking calculation. */ + extern const double DEFAULT_OVERBOOKING_MEAN; + + /** Default value for the standard deviation used for overbooking + calculation. */ + extern const double DEFAULT_OVERBOOKING_STANDARD_DEVIATION; + +} +#endif // __RMOL_BAS_BASCONST_OVERBOOKING_HPP Modified: trunk/rmol/rmol/bom/Overbooking.cpp =================================================================== --- trunk/rmol/rmol/bom/Overbooking.cpp 2009-03-20 17:03:01 UTC (rev 179) +++ trunk/rmol/rmol/bom/Overbooking.cpp 2009-03-22 16:47:07 UTC (rev 180) @@ -1,464 +1,464 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> -// STL -#include <iostream> -// GSL -#include <gsl/gsl_sys.h> -#include <gsl/gsl_math.h> -#include <gsl/gsl_sf.h> -#include <gsl/gsl_randist.h> -#include <gsl/gsl_cdf.h> -// RMOL -#include <rmol/basic/BasConst_Overbooking.hpp> -#include <rmol/bom/Overbooking.hpp> - -namespace RMOL { - - // ////////////////////////////////////////////////////////////////////// - Overbooking::Overbooking () : - _overbookingPercentage (DEFAULT_OVERBOOKING_OVERBOOKING_PERCENTAGE), - _capacity (DEFAULT_OVERBOOKING_CAPACITY), - _netBookings (DEFAULT_OVERBOOKING_NET_BOOKINGS), - _loadFactor (DEFAULT_OVERBOOKING_LOAD_FACTOR), - _noShowDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _cancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _remainingCancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _demandDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)) { - } - - // ////////////////////////////////////////////////////////////////////// - Overbooking::Overbooking (const Overbooking& iOverbooking) : - _overbookingPercentage (DEFAULT_OVERBOOKING_OVERBOOKING_PERCENTAGE), - _capacity (DEFAULT_OVERBOOKING_CAPACITY), - _netBookings (DEFAULT_OVERBOOKING_NET_BOOKINGS), - _loadFactor (DEFAULT_OVERBOOKING_LOAD_FACTOR), - _noShowDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _cancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _remainingCancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _demandDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)) { - } - - // ////////////////////////////////////////////////////////////////////// - Overbooking::Overbooking (const FldOverbookingPolicy& iPolicy) : - _policy (iPolicy), - _overbookingPercentage (DEFAULT_OVERBOOKING_OVERBOOKING_PERCENTAGE), - _capacity (DEFAULT_OVERBOOKING_CAPACITY), - _netBookings (DEFAULT_OVERBOOKING_NET_BOOKINGS), - _loadFactor (DEFAULT_OVERBOOKING_LOAD_FACTOR), - _noShowDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _cancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _remainingCancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), - _demandDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, - DEFAULT_OVERBOOKING_STANDARD_DEVIATION)) { - } - - // ////////////////////////////////////////////////////////////////////// - Overbooking::~Overbooking() { - } - - // ////////////////////////////////////////////////////////////////////// - const std::string Overbooking::describeShortKey() const { - std::ostringstream oStr; - oStr << _policy; - return oStr.str(); - } - - // ////////////////////////////////////////////////////////////////////// - const std::string Overbooking::describeKey() const { - return describeShortKey(); - } - - // ////////////////////////////////////////////////////////////////////// - std::string Overbooking::toString() const { - std::ostringstream oStr; - oStr << describeShortKey() - << ", " << _policy << ", " << _overbookingPercentage - << ", " << _capacity << ", " << _netBookings - << ", " << _loadFactor - << ", " << _noShowDistributionParameters - << ", " << _cancellationDistributionParameters - << ", " << _remainingCancellationDistributionParameters - << ", " << _demandDistributionParameters - << std::endl; - - return oStr.str(); - } - - // ////////////////////////////////////////////////////////////////////// - void Overbooking::toStream (std::ostream& ioOut) const { - ioOut << toString(); - } - - // ////////////////////////////////////////////////////////////////////// - void Overbooking::fromStream (std::istream& ioIn) { - } - - // ////////////////////////////////////////////////////////////////////// - const std::string Overbooking::shortDisplay() const { - std::ostringstream oStr; - oStr << describeKey(); - return oStr.str(); - } - - // ////////////////////////////////////////////////////////////////////// - const std::string Overbooking::display() const { - std::ostringstream oStr; - oStr << shortDisplay(); - oStr << "Policy = " << _policy - << "; OB% = " << _overbookingPercentage - << "; Capacity = " << _capacity - << "; Net Bookings = " << _netBookings - << "; Load Factor (LF) = " << _loadFactor - << "; No-Show Distrib. Params = " << _noShowDistributionParameters - << "; Cx Distrib. Params = " << _cancellationDistributionParameters - << "; Rem. Cx Distrib. Params = " << _remainingCancellationDistributionParameters - << "; Demand Distrib. Params = " << _demandDistributionParameters - << std::endl; - return oStr.str(); - } - - - // ////////////// TODO: REMOVE THOSE CONSTANTS ////////// - //Parameters given by RMS User , for the prototype we set at - //predefined values - - // = 0.5; to check the influence of this parameter , actually has 1 problem - const double PRICE_OVER_DENIED_COST = 0.5; - - // = 150; - // const unsigned int CAPACITY = 150; - - // = CAPACITY*1.2; - const double MAX_BOOKING_LIMIT = 180; - - // 0.8; // il faut calculer ro dans la requete - // const double SHOW_RATE = 0.9 ; - - // 120; - // const unsigned int NET_BOOKINGS = 120; - // const int OVERBOOKING_METHOD_TYPE = 0; - - - // service level parameters - //pSHOW_RATEbability that we have to deny one or more passengers = 1/10.000 - const double SERVICE_LEVEL1 = 0.0001; - - //the fraction of passengers who will be denied to board = 1 over 10.000 - const double SERVICE_LEVEL2 = 0.0001; - const int SERVICE_LEVEL_TYPE = 2; - - //parameters fSHOW_RATEm Forecaster - //demand average and deviation for a flight date - // const double DEMAND_AVERAGE = 135; - - //100,10 - // const double DEMAND_DEVIATION = 10; - // const double NS_PERCENTAGE = 0.1; - //10,2 - // const double NS_DEVIATION = 0.02; - // const double REMAINING_CANCELLATIONS_PERCENTAGE = 0.2; - //20,5 - const double CANCELLATIONS_DEVIATION = 0.05; - // ////////////// END OF TODO: REMOVE THOSE CONSTANTS ////////// - - // ////////////////////////////////////////////////////////////////////// - FldDistributionParameters Overbooking::getOverbookingCalculation () const { - FldDistributionParameters resultOBPercentage; - - const FldOverbookingPolicy::EN_Policy lPolicy = _policy.getPolicy(); - - switch (lPolicy) { - case FldOverbookingPolicy::HEUR: - resultOBPercentage = calculateHeuristic(); - break; - case FldOverbookingPolicy::RISK: - resultOBPercentage = calculateRiskBased(); - break; - case FldOverbookingPolicy::SL1: - resultOBPercentage = calculateServiceLevel(); - break; - case FldOverbookingPolicy::HYBRID: - resultOBPercentage = calculateHybridPolicy(); - break; - default: - resultOBPercentage = calculateHeuristic(); - break; - } - return resultOBPercentage; - } - - // 0 : Method Heuristic take No show and cancellations infor - //to calculate the Overbooking percentage and deviation - // ////////////////////////////////////////////////////////////////////// - FldDistributionParameters Overbooking::calculateHeuristic() const { - FldDistributionParameters resultOBPercentage; - - const double lCancellationsPercentage = - _remainingCancellationDistributionParameters.getMean() - * _netBookings / _capacity; - - // Overbooking average percentage - const double lNoShow = _noShowDistributionParameters.getMean(); - const double lOBMean = (lNoShow + lCancellationsPercentage) - / (1 - (lNoShow + lCancellationsPercentage)); - resultOBPercentage.setMean (lOBMean); - - // Overbooking deviation (heuristic) - const double lNSStdDev = - _noShowDistributionParameters.getStandardDeviation(); - const double lNSVariance = lNSStdDev * lNSStdDev; - - const double lCxStdDev = - _cancellationDistributionParameters.getStandardDeviation(); - const double lCxVariance = lCxStdDev * lCxStdDev; - - const double lOBStdDev = sqrt (lNSVariance + lCxVariance); - resultOBPercentage.setStandardDeviation (lOBStdDev); - - return resultOBPercentage ; - } - - // 1 : Method Risk based take No show and cancellations infor - //to calculate the Overbooking percentage and deviation - // ////////////////////////////////////////////////////////////////////// - FldDistributionParameters Overbooking::calculateRiskBased() const { - FldDistributionParameters resultOBPercentage; - - // take the Overbooking average and deviation by Heuristic method - // in order to calculate some parameters ? show rate par exemple - resultOBPercentage = calculateHeuristic(); - - //Calculation SHOW_RATE : Shows rate = shows/net booking; - //Calculation booking limit - const double lBookingLimit = calculateBookingLimit (); - - const double lOBMean = lBookingLimit / _capacity - 1.0; - resultOBPercentage.setMean (lOBMean); - - return resultOBPercentage; - } - - // 2 : Service level policy - // ////////////////////////////////////////////////////////////////////// - FldDistributionParameters Overbooking::calculateServiceLevel() const { - FldDistributionParameters resultOBPercentage; - - // No-Show Rate - const double lNoShowMean = _noShowDistributionParameters.getMean(); - - // service level 1 - unsigned int b = _capacity; - switch (SERVICE_LEVEL_TYPE){ - case 1: default: { - double test = serviceLevel1 (lNoShowMean, b, _capacity); - while (test < SERVICE_LEVEL1) { - b++; - test = serviceLevel1 (lNoShowMean, b, _capacity); - } - break; - } - case 2: { - // service level 2 - double test = fractionServiceLevel2 (lNoShowMean, b, _capacity); - while (test < SERVICE_LEVEL2){ - b++; - test = fractionServiceLevel2 (lNoShowMean, b, _capacity); - } - break; - } - } - resultOBPercentage.setMean (static_cast<double>(b) / _capacity - 1.0); - // TODO: To be altered - resultOBPercentage.setStandardDeviation (0); - - return resultOBPercentage; - } - - // 3 : Hybrid policy - // ////////////////////////////////////////////////////////////////////// - FldDistributionParameters Overbooking::calculateHybridPolicy() const { - FldDistributionParameters resultOBPercentage; - - FldDistributionParameters resultOBPercentage_1 = calculateRiskBased(); - FldDistributionParameters resultOBPercentage_2 = calculateServiceLevel(); - - //intermediate step to calculate the OB% - const double lMean1 = resultOBPercentage_1.getMean(); - const double lMean2 = resultOBPercentage_2.getMean(); - const double lSDeviation1 = resultOBPercentage_1.getStandardDeviation(); - const double lSDeviation2 = resultOBPercentage_2.getStandardDeviation(); - - //The hybrid method gets the minimum value - if (lMean1 > lMean2) { - resultOBPercentage.setMean (lMean2); - resultOBPercentage.setStandardDeviation (lSDeviation2); - return resultOBPercentage; - } - assert (lMean1 <= lMean2); - - resultOBPercentage.setMean (lMean1); - resultOBPercentage.setStandardDeviation (lSDeviation1); - - return resultOBPercentage; - } - - //Distribution - //binomial distribution, normal distribution - - // Service level - // in the Service Level policy method we can switch between service - // level 1 and 2 in the Hybrid policy, because they are constraints - // so we can choose one or the other or the two - - - // useful functions - // ////////////////////////////////////////////////////////////////////// - double Overbooking::calculateBookingLimit () const { - double resultBookingLimit = _capacity; - - // Demand Distribution Parameters - const double lDemandMean = _demandDistributionParameters.getMean(); - const double lDemandStdDev = - _demandDistributionParameters.getStandardDeviation(); - - // Algorithm - double pNormal = - gsl_cdf_gaussian_Q (_capacity - lDemandMean, lDemandStdDev); - - // double pNormal = probabilityNormal (CAPACITY, DEMAND_AVERAGE, - // DEMAND_DEVIATION); - - if (PRICE_OVER_DENIED_COST >= 1 - pNormal) { - resultBookingLimit = MAX_BOOKING_LIMIT; - return resultBookingLimit; - } - assert (PRICE_OVER_DENIED_COST < 1 - pNormal); - - pNormal = gsl_cdf_gaussian_Q (_capacity - 1 - lDemandMean, - lDemandStdDev); - - // pNormal = probabilityNormal (CAPACITY-1, DEMAND_AVERAGE, - // DEMAND_DEVIATION); - - const double lNoShowMean = _noShowDistributionParameters.getMean(); - - double lProbability = (1 - pNormal) - * gsl_sf_pow_int (lNoShowMean, _capacity); - - int counter = 1; - while ((lProbability < PRICE_OVER_DENIED_COST) && (counter < 100)) { - counter++; - if (resultBookingLimit >= MAX_BOOKING_LIMIT) { - return resultBookingLimit; - - } else { - resultBookingLimit += 1.0; - } - - const unsigned int b = static_cast<unsigned int> (resultBookingLimit); - - pNormal = gsl_cdf_gaussian_Q (b + 1 - lDemandMean, lDemandStdDev); - - // pNormal = probabilityNormal (b+1, DEMAND_AVERAGE, DEMAND_DEVIATION); - - assert (_capacity > 1); - assert (b - _capacity + 1 > 0); - // assert (b >= 0); (derived from the other two) - - - // The cumulated probability that the number of shows exceeds - // the leg/cabin physical capacity - lProbability += (1+pNormal) - * lNoShowMean * gsl_ran_binomial_pdf (_capacity-1, lNoShowMean, b); - - } - return resultBookingLimit; - } - - - // Private useful functions, some of them are to be replaced by gsl - // library's functions - - // ////////////////////////////////////////////////////////////////////// - //to be deleted, already available in gsl lib - //cumulated binomial probability - double Overbooking::probabilityNormal (const int b, const double average, - const double sdeviation) const { - double resultCdf = 0.0; - - for (int i=0; i < b+1 ; i++) { - resultCdf += 1 /( sqrt(2 * M_PI) ) - * gsl_sf_exp (-1* (gsl_sf_pow_int(i-average, 2)) / (2*sdeviation)); - } - return resultCdf; - } - - // ////////////////////////////////////////////////////////////////////// - - // to be deleted, already available in gsl lib, gsl_ran_binomial_pdf(unsigned int k, double SHOW_RATE, unsigned int b) - double Overbooking::binomialProbability_F_b_s (const double iShowRate, - const int b, - const int k) const { - double Factorials = gsl_sf_fact(b)/gsl_sf_fact(k)/gsl_sf_fact(b-k); - double f = Factorials* - gsl_sf_pow_int(iShowRate, k)*gsl_sf_pow_int(1-iShowRate, b-k) ; - - return f; - } - - // pSHOW_RATEbability to deny one or more services - // ////////////////////////////////////////////////////////////////////// - - - - ////////////// Private functions for Servive level policies///////////// - - // service level 1 : cumulated probability of having no-shows - //the constant SHOW_RATE can be changed in local variable in this function - - // ////////////////////////////////////////////////////////////////////// - double Overbooking::serviceLevel1 (const double iShowRate, - const int b, const int C) const { - double resultProbability = 1.0; - for (int i = 1; i<=C; i++) { - resultProbability -= gsl_ran_binomial_pdf (i, iShowRate, b);} - return resultProbability; - } - - //////////////fraction of customers who will be denied service/////////////// - double Overbooking::fractionServiceLevel2 (const double iShowRate, - const int b, const int C) const { - double resultFraction = serviceLevel1 (iShowRate, b-1, _capacity-1) - - C / b / iShowRate * serviceLevel1 (iShowRate, b, _capacity); - - return resultFraction; - } -} - - - /* where can I move this main function ?*/ - // int main(){ - //tester = a supprimer - // double []test; - // overBookingCalculation tester = new overBookingCalculation("AY", "831"); - // test = tester.getOverbookingCalculation(2); - - // System.out.println("OB % = " + test[0]); - // System.out.println("OB deviation = " + test[1]); - - - +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// C +#include <assert.h> +// STL +#include <iostream> +// GSL +#include <gsl/gsl_sys.h> +#include <gsl/gsl_math.h> +#include <gsl/gsl_sf.h> +#include <gsl/gsl_randist.h> +#include <gsl/gsl_cdf.h> +// RMOL +#include <rmol/basic/BasConst_Overbooking.hpp> +#include <rmol/bom/Overbooking.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + Overbooking::Overbooking () : + _overbookingPercentage (DEFAULT_OVERBOOKING_OVERBOOKING_PERCENTAGE), + _capacity (DEFAULT_OVERBOOKING_CAPACITY), + _netBookings (DEFAULT_OVERBOOKING_NET_BOOKINGS), + _loadFactor (DEFAULT_OVERBOOKING_LOAD_FACTOR), + _noShowDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _cancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _remainingCancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _demandDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)) { + } + + // ////////////////////////////////////////////////////////////////////// + Overbooking::Overbooking (const Overbooking& iOverbooking) : + _overbookingPercentage (DEFAULT_OVERBOOKING_OVERBOOKING_PERCENTAGE), + _capacity (DEFAULT_OVERBOOKING_CAPACITY), + _netBookings (DEFAULT_OVERBOOKING_NET_BOOKINGS), + _loadFactor (DEFAULT_OVERBOOKING_LOAD_FACTOR), + _noShowDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _cancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _remainingCancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _demandDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)) { + } + + // ////////////////////////////////////////////////////////////////////// + Overbooking::Overbooking (const FldOverbookingPolicy& iPolicy) : + _policy (iPolicy), + _overbookingPercentage (DEFAULT_OVERBOOKING_OVERBOOKING_PERCENTAGE), + _capacity (DEFAULT_OVERBOOKING_CAPACITY), + _netBookings (DEFAULT_OVERBOOKING_NET_BOOKINGS), + _loadFactor (DEFAULT_OVERBOOKING_LOAD_FACTOR), + _noShowDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _cancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _remainingCancellationDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)), + _demandDistributionParameters (FldDistributionParameters (DEFAULT_OVERBOOKING_MEAN, + DEFAULT_OVERBOOKING_STANDARD_DEVIATION)) { + } + + // ////////////////////////////////////////////////////////////////////// + Overbooking::~Overbooking() { + } + + // ////////////////////////////////////////////////////////////////////// + const std::string Overbooking::describeShortKey() const { + std::ostringstream oStr; + oStr << _policy; + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + const std::string Overbooking::describeKey() const { + return describeShortKey(); + } + + // ////////////////////////////////////////////////////////////////////// + std::string Overbooking::toString() const { + std::ostringstream oStr; + oStr << describeShortKey() + << ", " << _policy << ", " << _overbookingPercentage + << ", " << _capacity << ", " << _netBookings + << ", " << _loadFactor + << ", " << _noShowDistributionParameters + << ", " << _cancellationDistributionParameters + << ", " << _remainingCancellationDistributionParameters + << ", " << _demandDistributionParameters + << std::endl; + + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + void Overbooking::toStream (std::ostream& ioOut) const { + ioOut << toString(); + } + + // ////////////////////////////////////////////////////////////////////// + void Overbooking::fromStream (std::istream& ioIn) { + } + + // ////////////////////////////////////////////////////////////////////// + const std::string Overbooking::shortDisplay() const { + std::ostringstream oStr; + oStr << describeKey(); + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + const std::string Overbooking::display() const { + std::ostringstream oStr; + oStr << shortDisplay(); + oStr << "Policy = " << _policy + << "; OB% = " << _overbookingPercentage + << "; Capacity = " << _capacity + << "; Net Bookings = " << _netBookings + << "; Load Factor (LF) = " << _loadFactor + << "; No-Show Distrib. Params = " << _noShowDistributionParameters + << "; Cx Distrib. Params = " << _cancellationDistributionParameters + << "; Rem. Cx Distrib. Params = " << _remainingCancellationDistributionParameters + << "; Demand Distrib. Params = " << _demandDistributionParameters + << std::endl; + return oStr.str(); + } + + + // ////////////// TODO: REMOVE THOSE CONSTANTS ////////// + //Parameters given by RMS User , for the prototype we set at + //predefined values + + // = 0.5; to check the influence of this parameter , actually has 1 problem + const double PRICE_OVER_DENIED_COST = 0.5; + + // = 150; + // const unsigned int CAPACITY = 150; + + // = CAPACITY*1.2; + const double MAX_BOOKING_LIMIT = 180; + + // 0.8; // il faut calculer ro dans la requete + // const double SHOW_RATE = 0.9 ; + + // 120; + // const unsigned int NET_BOOKINGS = 120; + // const int OVERBOOKING_METHOD_TYPE = 0; + + + // service level parameters + //pSHOW_RATEbability that we have to deny one or more passengers = 1/10.000 + const double SERVICE_LEVEL1 = 0.0001; + + //the fraction of passengers who will be denied to board = 1 over 10.000 + const double SERVICE_LEVEL2 = 0.0001; + const int SERVICE_LEVEL_TYPE = 2; + + //parameters fSHOW_RATEm Forecaster + //demand average and deviation for a flight date + // const double DEMAND_AVERAGE = 135; + + //100,10 + // const double DEMAND_DEVIATION = 10; + // const double NS_PERCENTAGE = 0.1; + //10,2 + // const double NS_DEVIATION = 0.02; + // const double REMAINING_CANCELLATIONS_PERCENTAGE = 0.2; + //20,5 + const double CANCELLATIONS_DEVIATION = 0.05; + // ////////////// END OF TODO: REMOVE THOSE CONSTANTS ////////// + + // ////////////////////////////////////////////////////////////////////// + FldDistributionParameters Overbooking::getOverbookingCalculation () const { + FldDistributionParameters resultOBPercentage; + + const FldOverbookingPolicy::EN_Policy lPolicy = _policy.getPolicy(); + + switch (lPolicy) { + case FldOverbookingPolicy::HEUR: + resultOBPercentage = calculateHeuristic(); + break; + case FldOverbookingPolicy::RISK: + resultOBPercentage = calculateRiskBased(); + break; + case FldOverbookingPolicy::SL1: + resultOBPercentage = calculateServiceLevel(); + break; + case FldOverbookingPolicy::HYBRID: + resultOBPercentage = calculateHybridPolicy(); + break; + default: + resultOBPercentage = calculateHeuristic(); + break; + } + return resultOBPercentage; + } + + // 0 : Method Heuristic take No show and cancellations infor + //to calculate the Overbooking percentage and deviation + // ////////////////////////////////////////////////////////////////////// + FldDistributionParameters Overbooking::calculateHeuristic() const { + FldDistributionParameters resultOBPercentage; + + const double lCancellationsPercentage = + _remainingCancellationDistributionParameters.getMean() + * _netBookings / _capacity; + + // Overbooking average percentage + const double lNoShow = _noShowDistributionParameters.getMean(); + const double lOBMean = (lNoShow + lCancellationsPercentage) + / (1 - (lNoShow + lCancellationsPercentage)); + resultOBPercentage.setMean (lOBMean); + + // Overbooking deviation (heuristic) + const double lNSStdDev = + _noShowDistributionParameters.getStandardDeviation(); + const double lNSVariance = lNSStdDev * lNSStdDev; + + const double lCxStdDev = + _cancellationDistributionParameters.getStandardDeviation(); + const double lCxVariance = lCxStdDev * lCxStdDev; + + const double lOBStdDev = sqrt (lNSVariance + lCxVariance); + resultOBPercentage.setStandardDeviation (lOBStdDev); + + return resultOBPercentage ; + } + + // 1 : Method Risk based take No show and cancellations infor + //to calculate the Overbooking percentage and deviation + // ////////////////////////////////////////////////////////////////////// + FldDistributionParameters Overbooking::calculateRiskBased() const { + FldDistributionParameters resultOBPercentage; + + // take the Overbooking average and deviation by Heuristic method + // in order to calculate some parameters ? show rate par exemple + resultOBPercentage = calculateHeuristic(); + + //Calculation SHOW_RATE : Shows rate = shows/net booking; + //Calculation booking limit + const double lBookingLimit = calculateBookingLimit (); + + const double lOBMean = lBookingLimit / _capacity - 1.0; + resultOBPercentage.setMean (lOBMean); + + return resultOBPercentage; + } + + // 2 : Service level policy + // ////////////////////////////////////////////////////////////////////// + FldDistributionParameters Overbooking::calculateServiceLevel() const { + FldDistributionParameters resultOBPercentage; + + // No-Show Rate + const double lNoShowMean = _noShowDistributionParameters.getMean(); + + // service level 1 + unsigned int b = _capacity; + switch (SERVICE_LEVEL_TYPE){ + case 1: default: { + double test = serviceLevel1 (lNoShowMean, b, _capacity); + while (test < SERVICE_LEVEL1) { + b++; + test = serviceLevel1 (lNoShowMean, b, _capacity); + } + break; + } + case 2: { + // service level 2 + double test = fractionServiceLevel2 (lNoShowMean, b, _capacity); + while (test < SERVICE_LEVEL2){ + b++; + test = fractionServiceLevel2 (lNoShowMean, b, _capacity); + } + break; + } + } + resultOBPercentage.setMean (static_cast<double>(b) / _capacity - 1.0); + // TODO: To be altered + resultOBPercentage.setStandardDeviation (0); + + return resultOBPercentage; + } + + // 3 : Hybrid policy + // ////////////////////////////////////////////////////////////////////// + FldDistributionParameters Overbooking::calculateHybridPolicy() const { + FldDistributionParameters resultOBPercentage; + + FldDistributionParameters resultOBPercentage_1 = calculateRiskBased(); + FldDistributionParameters resultOBPercentage_2 = calculateServiceLevel(); + + //intermediate step to calculate the OB% + const double lMean1 = resultOBPercentage_1.getMean(); + const double lMean2 = resultOBPercentage_2.getMean(); + const double lSDeviation1 = resultOBPercentage_1.getStandardDeviation(); + const double lSDeviation2 = resultOBPercentage_2.getStandardDeviation(); + + //The hybrid method gets the minimum value + if (lMean1 > lMean2) { + resultOBPercentage.setMean (lMean2); + resultOBPercentage.setStandardDeviation (lSDeviation2); + return resultOBPercentage; + } + assert (lMean1 <= lMean2); + + resultOBPercentage.setMean (lMean1); + resultOBPercentage.setStandardDeviation (lSDeviation1); + + return resultOBPercentage; + } + + //Distribution + //binomial distribution, normal distribution + + // Service level + // in the Service Level policy method we can switch between service + // level 1 and 2 in the Hybrid policy, because they are constraints + // so we can choose one or the other or the two + + + // useful functions + // ////////////////////////////////////////////////////////////////////// + double Overbooking::calculateBookingLimit () const { + double resultBookingLimit = _capacity; + + // Demand Distribution Parameters + const double lDemandMean = _demandDistributionParameters.getMean(); + const double lDemandStdDev = + _demandDistributionParameters.getStandardDeviation(); + + // Algorithm + double pNormal = + gsl_cdf_gaussian_Q (_capacity - lDemandMean, lDemandStdDev); + + // double pNormal = probabilityNormal (CAPACITY, DEMAND_AVERAGE, + // DEMAND_DEVIATION); + + if (PRICE_OVER_DENIED_COST >= 1 - pNormal) { + resultBookingLimit = MAX_BOOKING_LIMIT; + return resultBookingLimit; + } + assert (PRICE_OVER_DENIED_COST < 1 - pNormal); + + pNormal = gsl_cdf_gaussian_Q (_capacity - 1 - lDemandMean, + lDemandStdDev); + + // pNormal = probabilityNormal (CAPACITY-1, DEMAND_AVERAGE, + // DEMAND_DEVIATION); + + const double lNoShowMean = _noShowDistributionParameters.getMean(); + + double lProbability = (1 - pNormal) + * gsl_sf_pow_int (lNoShowMean, _capacity); + + int counter = 1; + while ((lProbability < PRICE_OVER_DENIED_COST) && (counter < 100)) { + counter++; + if (resultBookingLimit >= MAX_BOOKING_LIMIT) { + return resultBookingLimit; + + } else { + resultBookingLimit += 1.0; + } + + const unsigned int b = static_cast<unsigned int> (resultBookingLimit); + + pNormal = gsl_cdf_gaussian_Q (b + 1 - lDemandMean, lDemandStdDev); + + // pNormal = probabilityNormal (b+1, DEMAND_AVERAGE, DEMAND_DEVIATION); + + assert (_capacity > 1); + assert (b - _capacity + 1 > 0); + // assert (b >= 0); (derived from the other two) + + + // The cumulated probability that the number of shows exceeds + // the leg/cabin physical capacity + lProbability += (1+pNormal) + * lNoShowMean * gsl_ran_binomial_pdf (_capacity-1, lNoShowMean, b); + + } + return resultBookingLimit; + } + + + // Private useful functions, some of them are to be replaced by gsl + // library's functions + + // ////////////////////////////////////////////////////////////////////// + //to be deleted, already available in gsl lib + //cumulated binomial probability + double Overbooking::probabilityNormal (const int b, const double average, + const double sdeviation) const { + double resultCdf = 0.0; + + for (int i=0; i < b+1 ; i++) { + resultCdf += 1 /( sqrt(2 * M_PI) ) + * gsl_sf_exp (-1* (gsl_sf_pow_int(i-average, 2)) / (2*sdeviation)); + } + return resultCdf; + } + + // ////////////////////////////////////////////////////////////////////// + + // to be deleted, already available in gsl lib, gsl_ran_binomial_pdf(unsigned int k, double SHOW_RATE, unsigned int b) + double Overbooking::binomialProbability_F_b_s (const double iShowRate, + const int b, + const int k) const { + double Factorials = gsl_sf_fact(b)/gsl_sf_fact(k)/gsl_sf_fact(b-k); + double f = Factorials* + gsl_sf_pow_int(iShowRate, k)*gsl_sf_pow_int(1-iShowRate, b-k) ; + + return f; + } + + // pSHOW_RATEbability to deny one or more services + // ////////////////////////////////////////////////////////////////////// + + + + ////////////// Private functions for Servive level policies///////////// + + // service level 1 : cumulated probability of having no-shows + //the constant SHOW_RATE can be changed in local variable in this function + + // ////////////////////////////////////////////////////////////////////// + double Overbooking::serviceLevel1 (const double iShowRate, + const int b, const int C) const { + double resultProbability = 1.0; + for (int i = 1; i<=C; i++) { + resultProbability -= gsl_ran_binomial_pdf (i, iShowRate, b);} + return resultProbability; + } + + //////////////fraction of customers who will be denied service/////////////// + double Overbooking::fractionServiceLevel2 (const double iShowRate, + const int b, const int C) const { + double resultFraction = serviceLevel1 (iShowRate, b-1, _capacity-1) + - C / b / iShowRate * serviceLevel1 (iShowRate, b, _capacity); + + return resultFraction; + } +} + + + /* where can I move this main function ?*/ + // int main(){ + //tester = a supprimer + // double []test; + // overBookingCalculation tester = new overBookingCalculation("AY", "831"); + // test = tester.getOverbookingCalculation(2); + + // System.out.println("OB % = " + test[0]); + // System.out.println("OB deviation = " + test[1]); + + + Modified: trunk/rmol/rmol/bom/Overbooking.hpp =================================================================== --- trunk/rmol/rmol/bom/Overbooking.hpp 2009-03-20 17:03:01 UTC (rev 179) +++ trunk/rmol/rmol/bom/Overbooking.hpp 2009-03-22 16:47:07 UTC (rev 180) @@ -1,227 +1,227 @@ -#ifndef __RMOL_OVERBOOKING_HPP -#define __RMOL_OVERBOOKING_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <iostream> -#include <vector> -// RMOL -#include <rmol/field/FldDistributionParameters.hpp> -#include <rmol/field/FldOverbookingPolicy.hpp> -#include <rmol/bom/DistributionParameterList.hpp> -#include <rmol/bom/BomAbstract.hpp> - -namespace RMOL { - - /** Class holding the algorithms for the optimisation of the - overbooking controls. */ - class Overbooking : public BomAbstract { - /** Friend Classes - <br>Those classes need to access the internal attributes of this object - in order to construct and initialise it.*/ - friend class FacOverbooking; - - public: - // ///////// Getters ///////// - /** Get the overbooking calculation policy. */ - const FldOverbookingPolicy& getPolicy () const { - return _policy; - } - - /** Get the overbooking percentage. */ - double getOverbookingPercentage () const { - return _overbookingPercentage; - } - - /** Get the load factor. */ - double getLoadFactor () const { - return _loadFactor; - } - - /** Get the capacity. */ - unsigned int getCapacity () const { - return _capacity; - } - - /** Get the net bookings. */ - unsigned int getNetBookings () const { - return _netBookings; - } - - - /** Get the No-Show Distribution Parameters. */ - FldDistributionParameters getNoShowDistributionParameters () const { - return _noShowDistributionParameters; - } - - /** Get the Cancellation Distribution Parameters. */ - FldDistributionParameters getCancellationDistributionParameters () const { - return _cancellationDistributionParameters; - } - - /** Get the Remaining Cancellation Distribution Parameters. */ - FldDistributionParameters getRemainingCancellationDistributionParameters () const { - return _remainingCancellationDistributionParameters; - } - - /** Get the Demand Distribution Parameters. */ - FldDistributionParameters getDemandDistributionParameters () const { - return _demandDistributionParameters; - } - - // ///////// Setters ///////// - /** Set the overbooking calculation policy. */ - void setOverbookingPercentage (const FldOverbookingPolicy& iPolicy) { - _policy = iPolicy; - } - - /** Set the overbooking percentage. */ - void setOverbookingPercentage (const double iOverbookingPercentage) { - _overbookingPercentage = iOverbookingPercentage; - } - - /** Set the load factor. */ - void setLoadFactor (const double iLoadFactor) { - _loadFactor = iLoadFactor; - } - - /** Set the No-Show Distribution Parameters. */ - void setNoShowDistributionParameters (const FldDistributionParameters iNoShowDistributionParameters) { - _noShowDistributionParameters = iNoShowDistributionParameters; - } - - /** Set the Cancellation Distribution Parameters. */ - void setCancellationDistributionParameters (const FldDistributionParameters iCancellationDistributionParameters) { - _cancellationDistributionParameters = iCancellationDistributionParameters; - } - - /** Set the Remaining Cancellation Distribution Parameters. */ - void setRemainingCancellationDistributionParameters (const FldDistributionParameters iRemainingCancellationDistributionParameters) { - _remainingCancellationDistributionParameters = - iRemainingCancellationDistributionParameters; - } - - /** Set the Demand Distribution Parameters. */ - void setDemandDistributionParameters (const FldDistributionParameters iDemandDistributionParameters) { - _demandDistributionParameters = iDemandDistributionParameters; - } - - /** Set the capacity. */ - void setCapacity (const unsigned int iCapacity) { - _capacity = iCapacity; - } - - /** Set the net bookings. */ - void setNetBookings (const unsigned int iNetBookings) { - _netBookings = iNetBookings; - } - - - // /////////// - /** This function return the OB% with its standard deviation - following the given choice of method*/ - FldDistributionParameters getOverbookingCalculation () const; - - /** This function calculates the OB% by the heuristic method */ - FldDistributionParameters calculateHeuristic() const; - - /** This function calculates the OB% by the cost-based method */ - FldDistributionParameters calculateRiskBased() const; - - /** This function calculates the OB% by the service level policies */ - FldDistributionParameters calculateServiceLevel() const; - - /** This function calculates the OB% by the Hybrid policy*/ - FldDistributionParameters calculateHybridPolicy() const; - - - public: - // ///////// Display methods //////// - /** Dump a Business Object into an output stream. - @param ostream& the output stream. */ - void toStream (std::ostream&) const; - - /** Read a Business Object from an input stream. - @param istream& the input stream. */ - void fromStream (std::istream&); - - /** Get the serialised version of the Place object. */ - std::string toString() const; - - /** Get a string describing the whole key (differentiating two objects - at any level). */ - const std::string describeKey() const; - - /** Get a string describing the short key (differentiating two objects - at the same level). */ - const std::string describeShortKey() const; - - /** Display the full Place context. */ - const std::string display() const; - - /** Display a short Place context. */ - const std::string shortDisplay() const; - - - private: - /** Constructors. - <br>Protected to force the use of the Factory. */ - Overbooking (); - Overbooking (const Overbooking&); - Overbooking (const FldOverbookingPolicy&); - - /** Destructor. */ - virtual ~Overbooking(); - - - private: - /** Calculate the booking limit. */ - double calculateBookingLimit () const; - - /** Calculate the normal probability. */ - double probabilityNormal (const int, const double, const double) const; - - /** Calculate the binomial probability. */ - double binomialProbability_F_b_s (const double, - const int, const int) const; - /** Calculate the first service level. */ - double serviceLevel1 (const double, const int, const int) const; - - /** Calculate the fraction of service level 2. */ - double fractionServiceLevel2 (const double , const int , const int) const; - - - private: - // /////// Attributes ////////// - /** Overbooking Calculation Policy. */ - FldOverbookingPolicy _policy; - - /** Overbooking percentage. */ - double _overbookingPercentage; - - /** Capacity. */ - unsigned int _capacity; - - /** Net Bookings. */ - unsigned int _netBookings; - - /** Load Factor. */ - double _loadFactor; - - /** No-Show Distribution Parameters. */ - FldDistributionParameters _noShowDistributionParameters; - - /** Cancellation Distribution Parameters. */ - FldDistributionParameters _cancellationDistributionParameters; - - /** Remaining Cancellation Distribution Parameters. */ - FldDistributionParameters _remainingCancellationDistributionParameters; - - /** Demand Distribution Parameters. */ - FldDistributionParameters _demandDistributionParameters; - }; -} - -#endif // __RMOL_OVERBOOKING_HPP +#ifndef __RMOL_OVERBOOKING_HPP +#define __RMOL_OVERBOOKING_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iostream> +#include <vector> +// RMOL +#include <rmol/field/FldDistributionParameters.hpp> +#include <rmol/field/FldOverbookingPolicy.hpp> +#include <rmol/bom/DistributionParameterList.hpp> +#include <rmol/bom/BomAbstract.hpp> + +namespace RMOL { + + /** Class holding the algorithms for the optimisation of the + overbooking controls. */ + class Overbooking : public BomAbstract { + /** Friend Classes + <br>Those classes need to access the internal attributes of this object + in order to construct and initialise it.*/ + friend class FacOverbooking; + + public: + // ///////// Getters ///////// + /** Get the overbooking calculation policy. */ + const FldOverbookingPolicy& getPolicy () const { + return _policy; + } + + /** Get the overbooking percentage. */ + double getOverbookingPercentage () const { + return _overbookingPercentage; + } + + /** Get the load factor. */ + double getLoadFactor () const { + return _loadFactor; + } + + /** Get the capacity. */ + unsigned int getCapacity () const { + return _capacity; + } + + /** Get the net bookings. */ + unsigned int getNetBookings () const { + return _netBookings; + } + + + /** Get the No-Show Distribution Parameters. */ + FldDistributionParameters getNoShowDistributionParameters () const { + return _noShowDistributionParameters; + } + + /** Get the Cancellation Distribution Parameters. */ + FldDistributionParameters getCancellationDistributionParameters () const { + return _cancellationDistributionParameters; + } + + /** Get the Remaining Cancellation Distribution Parameters. */ + FldDistributionParameters getRemainingCancellationDistributionParameters () const { + return _remainingCancellationDistributionParameters; + } + + /** Get the Demand Distribution Parameters. */ + FldDistributionParameters getDemandDistributionParameters () const { + return _demandDistributionParameters; + } + + // ///////// Setters ///////// + /** Set the overbooking calculation policy. */ + void setOverbookingPercentage (const FldOverbookingPolicy& iPolicy) { + _policy = iPolicy; + } + + /** Set the overbooking percentage. */ + void setOverbookingPercentage (const double iOverbookingPercentage) { + _overbookingPercentage = iOverbookingPercentage; + } + + /** Set the load factor. */ + void setLoadFactor (const double iLoadFactor) { + _loadFactor = iLoadFactor; + } + + /** Set the No-Show Distribution Parameters. */ + void setNoShowDistributionParameters (const FldDistributionParameters iNoShowDistributionParameters) { + _noShowDistributionParameters = iNoShowDistributionParameters; + } + + /** Set the Cancellation Distribution Parameters. */ + void setCancellationDistributionParameters (const FldDistributionParameters iCancellationDistributionParameters) { + _cancellationDistributionParameters = iCancellationDistributionParameters; + } + + /** Set the Remaining Cancellation Distribution Parameters. */ + void setRemainingCancellationDistributionParameters (const FldDistributionParameters iRemainingCancellationDistributionParameters) { + _remainingCancellationDistributionParameters = + iRemainingCancellationDistributionParameters; + } + + /** Set the Demand Distribution Parameters. */ + void setDemandDistributionParameters (const FldDistributionParameters iDemandDistributionParameters) { + _demandDistributionParameters = iDemandDistributionParameters; + } + + /** Set the capacity. */ + void setCapacity (const unsigned int iCapacity) { + _capacity = iCapacity; + } + + /** Set the net bookings. */ + void setNetBookings (const unsigned int iNetBookings) { + _netBookings = iNetBookings; + } + + + // /////////// + /** This function return the OB% with its standard deviation + following the given choice of method*/ + FldDistributionParameters getOverbookingCalculation () const; + + /** This function calculates the OB% by the heuristic method */ + FldDistributionParameters calculateHeuristic() const; + + /** This function calculates the OB% by the cost-based method */ + FldDistributionParameters calculateRiskBased() const; + + /** This function calculates the OB% by the service level policies */ + FldDistributionParameters calculateServiceLevel() const; + + /** This function calculates the OB% by the Hybrid policy*/ + FldDistributionParameters calculateHybridPolicy() const; + + + public: + // ///////// Display methods //////// + /** Dump a Business Object into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream&) const; + + /** Read a Business Object from an input stream. + @param istream& the input stream. */ + void fromStream (std::istream&); + + /** Get the serialised version of the Place object. */ + std::string toString() const; + + /** Get a string describing the whole key (differentiating two objects + at any level). */ + const std::string describeKey() const; + + /** Get a string describing the short key (differentiating two objects + at the same level). */ + const std::string describeShortKey() const; + + /** Display the full Place context. */ + const std::string display() const; + + /** Display a short Place context. */ + const std::string shortDisplay() const; + + + private: + /** Constructors. + <br>Protected to force the use of the Factory. */ + Overbooking (); + Overbooking (const Overbooking&); + Overbooking (const FldOverbookingPolicy&); + + /** Destructor. */ + virtual ~Overbooking(); + + + private: + /** Calculate the booking limit. */ + double calculateBookingLimit () const; + + /** Calculate the normal probability. */ + double probabilityNormal (const int, const double, const double) const; + + /** Calculate the binomial probability. */ + double binomialProbability_F_b_s (const double, + const int, const int) const; + /** Calculate the first service level. */ + double serviceLevel1 (const double, const int, const int) const; + + /** Calculate the fraction of service level 2. */ + double fractionServiceLevel2 (const double , const int , const int) const; + + + private: + // /////// Attributes ////////// + /** Overbooking Calculation Policy. */ + FldOverbookingPolicy _policy; + + /** Overbooking percentage. */ + double _overbookingPercentage; + + /** Capacity. */ + unsigned int _capacity; + + /** Net Bookings. */ + unsigned int _netBookings; + + /** Load Factor. */ + double _loadFactor; + + /** No-Show Distribution Parameters. */ + FldDistributionParameters _noShowDistributionParameters; + + /** Cancellation Distribution Parameters. */ + FldDistributionParameters _cancellationDistributionParameters; + + /** Remaining Cancellation Distribution Parameters. */ + FldDistributionParameters _remainingCancellationDistributionParameters; + + /** Demand Distribution Parameters. */ + FldDistributionParameters _demandDistributionParameters; + }; +} + +#endif // __RMOL_OVERBOOKING_HPP Modified: trunk/rmol/rmol/field/FldOverbookingPolicy.cpp =================================================================== --- trunk/rmol/rmol/field/FldOverbookingPolicy.cpp 2009-03-20 17:03:01 UTC (rev 179) +++ trunk/rmol/rmol/field/FldOverbookingPolicy.cpp 2009-03-22 16:47:07 UTC (rev 180) @@ -1,44 +1,44 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -#include <rmol/field/FldOverbookingPolicy.hpp> - -namespace RMOL { - - // ////////////////////////////////////////////////////////////////////// - const std::string FldOverbookingPolicy:: - _labels[FldOverbookingPolicy::LAST_VALUE] = {"HEUR", "RISK", "SL1", "SL2", - "HYBRID"}; - - // ////////////////////////////////////////////////////////////////////// - FldOverbookingPolicy:: - FldOverbookingPolicy (const FldOverbookingPolicy& iPolicy) : - _policy (iPolicy.getPolicy()) { - } - - // ////////////////////////////////////////////////////////////////////// - FldOverbookingPolicy:: - FldOverbookingPolicy (const EN_Policy iPolicy) : - _policy (iPolicy) { - } - - // ////////////////////////////////////////////////////////////////////// - FldOverbookingPolicy::~FldOverbookingPolicy() { - } - - // ////////////////////////////////////////////////////////////////////// - const std::string& FldOverbookingPolicy:: - getLabel (const FldOverbookingPolicy::EN_Policy& iPolicy) { - return FldOverbookingPolicy::_labels[iPolicy]; - } - - // ////////////////////////////////////////////////////////////////////// - void FldOverbookingPolicy::toStream (std::ostream& ioOut) const { - ioOut << getLabel (_policy); - } - - // ////////////////////////////////////////////////////////////////////// - void FldOverbookingPolicy::fromStream (std::istream& ioIn) { - } - -} +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +#include <rmol/field/FldOverbookingPolicy.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + const std::string FldOverbookingPolicy:: + _labels[FldOverbookingPolicy::LAST_VALUE] = {"HEUR", "RISK", "SL1", "SL2", + "HYBRID"}; + + // ////////////////////////////////////////////////////////////////////// + FldOverbookingPolicy:: + FldOverbookingPolicy (const FldOverbookingPolicy& iPolicy) : + _policy (iPolicy.getPolicy()) { + } + + // ////////////////////////////////////////////////////////////////////// + FldOverbookingPolicy:: + FldOverbookingPolicy (const EN_Policy iPolicy) : + _policy (iPolicy) { + } + + // ////////////////////////////////////////////////////////////////////// + FldOverbookingPolicy::~FldOverbookingPolicy() { + } + + // ////////////////////////////////////////////////////////////////////// + const std::string& FldOverbookingPolicy:: + getLabel (const FldOverbookingPolicy::EN_Policy& iPolicy) { + return FldOverbookingPolicy::_labels[iPolicy]; + } + + // ////////////////////////////////////////////////////////////////////// + void FldOverbookingPolicy::toStream (std::ostream& ioOut) const { + ioOut << getLabel (_policy); + } + + // ////////////////////////////////////////////////////////////////////// + void FldOverbookingPolicy::fromStream (std::istream& ioIn) { + } + +} Modified: trunk/rmol/rmol/field/FldOverbookingPolicy.hpp =================================================================== --- trunk/rmol/rmol/field/FldOverbookingPolicy.hpp 2009-03-20 17:03:01 UTC (rev 179) +++ trunk/rmol/rmol/field/FldOverbookingPolicy.hpp 2009-03-22 16:47:07 UTC (rev 180) @@ -1,69 +1,69 @@ -#ifndef __RMOL_FIELD_FLDOVERBOOKING_POLICY_HPP -#define __RMOL_FIELD_FLDOVERBOOKING_POLICY_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <string> -// RMOL -#include <rmol/field/FldAbstract.hpp> - -namespace RMOL { - - /** Class wrapping the policy for the overbooking calculation. */ - class FldOverbookingPolicy : public FldAbstract { - public: - typedef enum { - HEUR = 0, // Heuristic - RISK, // Risk-Based - SL1, // Service-Level 1 - SL2, // Service-Level 2 - HYBRID, // Hybrid - LAST_VALUE - } EN_Policy; - - /** Get the label (BOM type) as a string. */ - static const std::string& getLabel (const EN_Policy&); - - // Getters - /** Getter for the mean value. */ - EN_Policy getPolicy() const { - return _policy; - } - - // Setters - /** Setter for the mean value. */ - void setPolicy (const EN_Policy& iPolicy) { - _policy = iPolicy; - }... [truncated message content] |
From: <qua...@us...> - 2009-04-24 08:25:10
|
Revision: 197 http://rmol.svn.sourceforge.net/rmol/?rev=197&view=rev Author: quannaus Date: 2009-04-24 08:25:09 +0000 (Fri, 24 Apr 2009) Log Message: ----------- Improved EMSR algorithm running time. Modified Paths: -------------- trunk/rmol/rmol/RMOL_Types.hpp trunk/rmol/rmol/bom/Emsr.cpp trunk/rmol/rmol/bom/EmsrUtils.hpp trunk/rmol/rmol/command/Optimiser.cpp trunk/rmol/rmol/command/Optimiser.hpp trunk/rmol/rmol/service/RMOL_Service.cpp Modified: trunk/rmol/rmol/RMOL_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Types.hpp 2009-04-23 17:25:20 UTC (rev 196) +++ trunk/rmol/rmol/RMOL_Types.hpp 2009-04-24 08:25:09 UTC (rev 197) @@ -57,8 +57,8 @@ <br> It is a vector of double. */ typedef std::vector<double> BidPriceVector_T; - /** Define the list of EMSR values for the EMSR algorith. */ - typedef std::list<double> EmsrValueList_T; + /** Define the list of EMSR values for the EMSR algorithm. */ + typedef std::vector<double> EmsrValueList_T; /** Define the vector of booking limits. <br> It is a vector of double. */ Modified: trunk/rmol/rmol/bom/Emsr.cpp =================================================================== --- trunk/rmol/rmol/bom/Emsr.cpp 2009-04-23 17:25:20 UTC (rev 196) +++ trunk/rmol/rmol/bom/Emsr.cpp 2009-04-24 08:25:09 UTC (rev 197) @@ -7,6 +7,7 @@ #include <iostream> #include <cmath> #include <list> +#include <algorithm> // RMOL #include <rmol/bom/VariateList.hpp> #include <rmol/bom/Gaussian.hpp> @@ -46,15 +47,14 @@ } // Sort the EMSR values from high to low. - lEmsrValueList.sort(); - lEmsrValueList.reverse(); + std::sort(lEmsrValueList.rbegin(), lEmsrValueList.rend()); // Sanity check const int lEmsrValueListSize = lEmsrValueList.size(); assert (lEmsrValueListSize >= lCabinCapacity); // Copy the EMSR sorted values to the BPV. - EmsrValueList_T::iterator currentValue = lEmsrValueList.begin(); + EmsrValueList_T::const_iterator currentValue = lEmsrValueList.begin(); for (int j = 0; j < lCabinCapacity; ++j, ++currentValue) { const double bidPrice = *currentValue; ioBidPriceVector.push_back(bidPrice); @@ -119,35 +119,6 @@ // Set the booking limit for class/bucket j+1. nextBucket.setCumulatedBookingLimit (lBookingLimit); } - - /* - // Number of classes/buckets: n - const short nbOfClasses = ioBucketHolder.getSize(); - for (int s = 1; s <= iCabinCapacity; s++){ - double maxEmsrValue = 0.0; - int highestBucket = 1; - - for(ioBucketHolder.begin(); - ioBucketHolder.hasNotReachedEnd(); - ioBucketHolder.iterate()){ - Bucket& currentBucket = ioBucketHolder.getCurrentBucket(); - - // Compute EMSR value of the seat #s for class j - double emsrForsj=0; - // Evaluate if this class j has the highest EMSR value for - // seat #s. If so, maxEMSRValue is the EMSR value of j, and - // j becomes temporarily the highest class. - - if(emsrForsj >= maxEmsrValue){ - maxEmsrValue = emsrForsj; - ioBucketHolder.tag(); - } - } - - Bucket& theHighestBucket = ioBucketHolder.getTaggedBucket(); - theHighestBucket._protection += 1.0; - } - */ } // ////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/bom/EmsrUtils.hpp =================================================================== --- trunk/rmol/rmol/bom/EmsrUtils.hpp 2009-04-23 17:25:20 UTC (rev 196) +++ trunk/rmol/rmol/bom/EmsrUtils.hpp 2009-04-24 08:25:09 UTC (rev 197) @@ -24,4 +24,4 @@ static const double computeEmsrValue (double, Bucket&); }; } -#endif +#endif //__RMOL_EMSRUTILS_HPP Modified: trunk/rmol/rmol/command/Optimiser.cpp =================================================================== --- trunk/rmol/rmol/command/Optimiser.cpp 2009-04-23 17:25:20 UTC (rev 196) +++ trunk/rmol/rmol/command/Optimiser.cpp 2009-04-24 08:25:09 UTC (rev 197) @@ -8,6 +8,8 @@ #include <cmath> #include <iomanip> // RMOL +#include <rmol/basic/BasChronometer.hpp> +#include <rmol/bom/StudyStatManager.hpp> #include <rmol/bom/BucketHolder.hpp> //#include <rmol/bom/Resource.hpp> #include <rmol/bom/MCOptimiser.hpp> @@ -67,6 +69,8 @@ BucketHolder& ioBucketHolder, BidPriceVector_T& ioBidPriceVector, StudyStatManager& ioStudyStatManager) { + BasChronometer lMCIntegrationBasChrono; + lMCIntegrationBasChrono.start(); // Retrieve the BucketHolder // BucketHolder& ioBucketHolder = ioResource.getBucketHolder(); @@ -97,6 +101,9 @@ aPartialSumHolderHolder, ioBidPriceVector, ioStudyStatManager); + const double lMCIntegrationTime = lMCIntegrationBasChrono.elapsed(); + ioStudyStatManager.addMeasure ("MCIntegrationRunningTime", + lMCIntegrationTime); } // ////////////////////////////////////////////////////////////////////// @@ -129,6 +136,21 @@ // ////////////////////////////////////////////////////////////////////// void Optimiser:: + heuristicOptimisationByEmsr (const ResourceCapacity_T iCabinCapacity, + BucketHolder& ioBucketHolder, + BidPriceVector_T& ioBidPriceVector, + StudyStatManager& ioStudyStatManager) { + BasChronometer lEMRSBasChrono; + lEMRSBasChrono.start(); + Emsr::heuristicOptimisationByEmsr (iCabinCapacity, + ioBucketHolder, + ioBidPriceVector); + const double lEMRSTime = lEMRSBasChrono.elapsed(); + ioStudyStatManager.addMeasure ("EMSRRunningTime", lEMRSTime); + } + + // ////////////////////////////////////////////////////////////////////// + void Optimiser:: heuristicOptimisationByEmsrA (const ResourceCapacity_T iCabinCapacity, BucketHolder& ioBucketHolder) { Emsr::heuristicOptimisationByEmsrA (iCabinCapacity, ioBucketHolder); Modified: trunk/rmol/rmol/command/Optimiser.hpp =================================================================== --- trunk/rmol/rmol/command/Optimiser.hpp 2009-04-23 17:25:20 UTC (rev 196) +++ trunk/rmol/rmol/command/Optimiser.hpp 2009-04-24 08:25:09 UTC (rev 197) @@ -54,7 +54,7 @@ BucketHolder&); /** - EMRS-a algorithm. + EMRS algorithm. <br>The cabin capacity is used to a double to allow for some overbooking. */ @@ -63,13 +63,20 @@ BidPriceVector_T&); /** + EMRS algorithm with StudyStatManager. + */ + static void heuristicOptimisationByEmsr (const ResourceCapacity_T, + BucketHolder&, BidPriceVector_T&, + StudyStatManager&); + + /** EMRS-a algorithm. <br>The cabin capacity is used to a double to allow for some overbooking. */ static void heuristicOptimisationByEmsrA (const ResourceCapacity_T, BucketHolder&); - + /** EMRS-b algorithm. <br>The cabin capacity is used to a double to allow for some Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-04-23 17:25:20 UTC (rev 196) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2009-04-24 08:25:09 UTC (rev 197) @@ -180,21 +180,34 @@ BucketHolder* ioBucketHolder_ptr = _rmolServiceContext->getBucketHolder(); assert (ioBucketHolder_ptr != NULL); BidPriceVector_T lBidPriceVector; - - Optimiser::heuristicOptimisationByEmsr (iCapacity, *ioBucketHolder_ptr, - lBidPriceVector); - + + StudyStatManager* lStudyStatManager_ptr = + _rmolServiceContext->getStudyStatManager(); + + if (lStudyStatManager_ptr == NULL) { + Optimiser::heuristicOptimisationByEmsr (iCapacity, *ioBucketHolder_ptr, + lBidPriceVector); + } else { + Optimiser::heuristicOptimisationByEmsr (iCapacity, *ioBucketHolder_ptr, + lBidPriceVector, + *lStudyStatManager_ptr); + } + // DEBUG RMOL_LOG_DEBUG (ioBucketHolder_ptr->display()); + std::ostringstream logStream; + logStream << "Bid-Price Vector (BPV): "; + unsigned int size = lBidPriceVector.size(); - // std::cout << "Bid-Price Vector (BPV): "; - // unsigned int size = lBidPriceVector.size(); + for (unsigned int i = 0; i < size; ++i) { + const double bidPrice = lBidPriceVector.at(i); + logStream << std::fixed << std::setprecision (2) << bidPrice << " "; + } + RMOL_LOG_DEBUG (logStream.str()); - // for (unsigned int i = 0; i < size; ++i) { - // const double bidPrice = lBidPriceVector.at(i); - // std::cout << std::fixed << std::setprecision (2) << bidPrice << " "; - // } - // std::cout << std::endl; + if (lStudyStatManager_ptr != NULL) { + RMOL_LOG_DEBUG (lStudyStatManager_ptr->describe()); + } } // ////////////////////////////////////////////////////////////////////// This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-05-06 16:46:17
|
Revision: 212 http://rmol.svn.sourceforge.net/rmol/?rev=212&view=rev Author: dkchoe Date: 2009-05-06 16:46:02 +0000 (Wed, 06 May 2009) Log Message: ----------- Implemented EMSR-a with sell-up algorithm (Annie's first contribution to RMOL :) ) Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/RMOL_Types.hpp trunk/rmol/rmol/basic/BasConst.cpp trunk/rmol/rmol/basic/BasConst_General.hpp trunk/rmol/rmol/bom/Emsr.cpp trunk/rmol/rmol/bom/Emsr.hpp trunk/rmol/rmol/bom/EmsrUtils.cpp trunk/rmol/rmol/bom/EmsrUtils.hpp trunk/rmol/rmol/command/Optimiser.cpp trunk/rmol/rmol/command/Optimiser.hpp trunk/rmol/rmol/service/RMOL_Service.cpp Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/RMOL_Service.hpp 2009-05-06 16:46:02 UTC (rev 212) @@ -62,6 +62,15 @@ /** Single resource optimization that uses EMSR-a heuristic and returns a vector of cumulated booking limits. */ void heuristicOptimisationByEmsrA (BidPriceVector_T&, BookingLimitVector_T&); + + /** Single resource optimization with sellup using EMSR-a heuristic. */ + void heuristicOptimisationByEmsrAwithSellup (SellupProbabilityVector_T&); + + /** Single resource optimization with sellup that uses EMSR-a heuristic and + returns a vector of cumulated booking limits. */ + void heuristicOptimisationByEmsrAwithSellup (SellupProbabilityVector_T&, + BidPriceVector_T&, + BookingLimitVector_T&); /** Single resource optimization using EMSR-b heuristic. */ void heuristicOptimisationByEmsrB (); Modified: trunk/rmol/rmol/RMOL_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Types.hpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/RMOL_Types.hpp 2009-05-06 16:46:02 UTC (rev 212) @@ -64,5 +64,7 @@ <br> It is a vector of double. */ typedef std::vector<double> BookingLimitVector_T; + /** Define the sellup probability vector applicable to EMSR*/ + typedef std::vector<double> SellupProbabilityVector_T; } #endif // __RMOL_RMOL_TYPES_HPP Modified: trunk/rmol/rmol/basic/BasConst.cpp =================================================================== --- trunk/rmol/rmol/basic/BasConst.cpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/basic/BasConst.cpp 2009-05-06 16:46:02 UTC (rev 212) @@ -15,6 +15,9 @@ the Dynamic Programming algorithm (100 means that the precision will be 0.01). */ const int DEFAULT_PRECISION = 10; + + /** Default epsilon value to qualify a denominator */ + const double DEFAULT_EPSILON = 0.0001; /** Default value for the load factor used for overbooking calculation. */ const double DEFAULT_OVERBOOKING_LOAD_FACTOR = 0.0; Modified: trunk/rmol/rmol/basic/BasConst_General.hpp =================================================================== --- trunk/rmol/rmol/basic/BasConst_General.hpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/basic/BasConst_General.hpp 2009-05-06 16:46:02 UTC (rev 212) @@ -14,5 +14,8 @@ /** Default value for the precision of the integral computation in the Dynamic Programming algorithm. */ extern const int DEFAULT_PRECISION; + + /** Default epsilon value to qualify a denominator */ + extern const double DEFAULT_EPSILON; } #endif // __RMOL_BAS_BASCONST_GENERAL_HPP Modified: trunk/rmol/rmol/bom/Emsr.cpp =================================================================== --- trunk/rmol/rmol/bom/Emsr.cpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/bom/Emsr.cpp 2009-05-06 16:46:02 UTC (rev 212) @@ -122,6 +122,64 @@ } // ////////////////////////////////////////////////////////////////// + void Emsr::heuristicOptimisationByEmsrAwithSellup + (const ResourceCapacity_T iCabinCapacity, + BucketHolder& ioBucketHolder, + SellupProbabilityVector_T& iSellupProbabilityVector){ + + // Number of classes/Buckets: n + const short nbOfBuckets = ioBucketHolder.getSize(); + + // Set the booking limit of the highest class to the cabin capacity + ioBucketHolder.begin(); + Bucket& highestBucket = ioBucketHolder.getCurrentBucket(); + highestBucket.setCumulatedBookingLimit (iCabinCapacity); + + // Set the booking limit for the rest n-1 classes + // by iterating on the classes/Buckets from 1 to n-1 + for (short j=1; j <= nbOfBuckets-1; j++, ioBucketHolder.iterate()) { + // Get the next class/bucket (the next high fare class) + Bucket& nextBucket = ioBucketHolder.getNextBucket(); + + // Get the probability of sell-up from nextBucket to the next higher + double sellupProbability = iSellupProbabilityVector[j]; + + // Initialize protection level for the current class j + double lProtectionLevel = 0.0; + + // Sum the protection levels for each higher fare class + ioBucketHolder.begin(); + for (short k=1; k<=j; k++) { + Bucket& higherBucket = ioBucketHolder.getCurrentBucket(); + + double lPRotectionLevelAgainstAHigherBucket = 0.0; + + if (k == j) { + lPRotectionLevelAgainstAHigherBucket = + EmsrUtils::computeProtectionLevelwithSellup + (higherBucket, nextBucket, sellupProbability); + } else { + lPRotectionLevelAgainstAHigherBucket = + EmsrUtils::computeProtectionLevel (higherBucket, nextBucket); + ioBucketHolder.iterate(); + } + + lProtectionLevel += lPRotectionLevelAgainstAHigherBucket; + } + + // Set cumulated protection level for class j + Bucket& currentBucket = ioBucketHolder.getCurrentBucket(); + currentBucket.setCumulatedProtection (lProtectionLevel); + + // Compute the booking limit for the class j+1 (can be negative) + const double lBookingLimit = iCabinCapacity - lProtectionLevel; + + // Set the booking limit for class j+1 + nextBucket.setCumulatedBookingLimit (lBookingLimit); + } + } + + // ////////////////////////////////////////////////////////////////// void Emsr:: heuristicOptimisationByEmsrB (const ResourceCapacity_T iCabinCapacity, BucketHolder& ioBucketHolder, Modified: trunk/rmol/rmol/bom/Emsr.hpp =================================================================== --- trunk/rmol/rmol/bom/Emsr.hpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/bom/Emsr.hpp 2009-05-06 16:46:02 UTC (rev 212) @@ -44,6 +44,13 @@ BucketHolder&); /** + Compute the optimal booking limits & protection limits for a set of + buckets/classes + */ + static void heuristicOptimisationByEmsrAwithSellup + (const ResourceCapacity_T, BucketHolder&, SellupProbabilityVector_T&); + + /** Complute the protection levels and booking limites by using the EMSR-b algorithm. Modified: trunk/rmol/rmol/bom/EmsrUtils.cpp =================================================================== --- trunk/rmol/rmol/bom/EmsrUtils.cpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/bom/EmsrUtils.cpp 2009-05-06 16:46:02 UTC (rev 212) @@ -9,6 +9,7 @@ // RMOL #include <rmol/bom/EmsrUtils.hpp> #include <rmol/bom/Bucket.hpp> +#include <rmol/basic/BasConst_General.hpp> namespace RMOL { // //////////////////////////////////////////////////////////////////// @@ -60,6 +61,29 @@ } // //////////////////////////////////////////////////////////////////// + const double EmsrUtils::computeProtectionLevelwithSellup (Bucket& iHigherBucket, + Bucket& iBucket, + double iSellupFactor){ + // Retrieve the mean and the standard deviation of the higher + // class(es)/bucket(s) depending EMSR-a or EMSR-b + // and the average yield of each input classes/buckets + const double lMean = iHigherBucket.getMean(); + const double lSD = iHigherBucket.getStandardDeviation(); + const double lHigherBucketYield = iHigherBucket.getAverageYield(); + const double lBucketYield = iBucket.getAverageYield(); + assert (lHigherBucketYield > DEFAULT_EPSILON); + assert (1-iSellupFactor > DEFAULT_EPSILON); + + // compute the protection level for the higher class/bucket + const double lProtectionLevel = + lMean + + gsl_cdf_gaussian_Pinv((lHigherBucketYield-lBucketYield)/ + lHigherBucketYield*(1-iSellupFactor),lSD); + + return lProtectionLevel; + } + + // //////////////////////////////////////////////////////////////////// const double EmsrUtils::computeEmsrValue (double iCapacity, Bucket& ioBucket) { // Retrive the average yield, mean and standard deviation of the // demand of the class/bucket. Modified: trunk/rmol/rmol/bom/EmsrUtils.hpp =================================================================== --- trunk/rmol/rmol/bom/EmsrUtils.hpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/bom/EmsrUtils.hpp 2009-05-06 16:46:02 UTC (rev 212) @@ -20,6 +20,9 @@ /** Compute the protection level using the Little-Wood formular. */ static const double computeProtectionLevel (Bucket&, Bucket&); + /** Compute the protection level with sell up factor */ + static const double computeProtectionLevelwithSellup (Bucket&, Bucket&, double); + /** Compute the EMSR value of a class/bucket. */ static const double computeEmsrValue (double, Bucket&); }; Modified: trunk/rmol/rmol/command/Optimiser.cpp =================================================================== --- trunk/rmol/rmol/command/Optimiser.cpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/command/Optimiser.cpp 2009-05-06 16:46:02 UTC (rev 212) @@ -157,6 +157,16 @@ } // ////////////////////////////////////////////////////////////////////// + void Optimiser::heuristicOptimisationByEmsrAwithSellup + (const ResourceCapacity_T iCabinCapacity, + BucketHolder& ioBucketHolder, + SellupProbabilityVector_T& iSellupProbabilityVector) { + Emsr::heuristicOptimisationByEmsrAwithSellup (iCabinCapacity, + ioBucketHolder, + iSellupProbabilityVector); + } + + // ////////////////////////////////////////////////////////////////////// void Optimiser:: heuristicOptimisationByEmsrB (const ResourceCapacity_T iCabinCapacity, BucketHolder& ioBucketHolder) { Modified: trunk/rmol/rmol/command/Optimiser.hpp =================================================================== --- trunk/rmol/rmol/command/Optimiser.hpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/command/Optimiser.hpp 2009-05-06 16:46:02 UTC (rev 212) @@ -77,6 +77,16 @@ static void heuristicOptimisationByEmsrA (const ResourceCapacity_T, BucketHolder&); + /** EMSR-a with sellup probability algorithm. + It is an implementation of the algorithm given by + Belobaba & Weatherford in the article + "Comparing decision rules that incorporate customer diversion in + perishable asset revenue management situations", Decision Sciences, + 1996. + */ + static void heuristicOptimisationByEmsrAwithSellup (const ResourceCapacity_T, + BucketHolder&, + SellupProbabilityVector_T&); /** EMRS-b algorithm. <br>The cabin capacity is used to a double to allow for some Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-05-05 11:58:12 UTC (rev 211) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2009-05-06 16:46:02 UTC (rev 212) @@ -261,6 +261,46 @@ } // ////////////////////////////////////////////////////////////////////// + void RMOL_Service::heuristicOptimisationByEmsrAwithSellup + (SellupProbabilityVector_T& iSellupProbabilityVector) { + + assert (_rmolServiceContext != NULL); + const double iCapacity = _rmolServiceContext->getCapacity(); + BucketHolder* ioBucketHolder_ptr = + _rmolServiceContext->getBucketHolder(); + assert (ioBucketHolder_ptr != NULL); + + Optimiser:: + heuristicOptimisationByEmsrAwithSellup (iCapacity, + *ioBucketHolder_ptr, + iSellupProbabilityVector); + + // DEBUG + RMOL_LOG_DEBUG (ioBucketHolder_ptr->display()); + } + + // ////////////////////////////////////////////////////////////////////// + void RMOL_Service::heuristicOptimisationByEmsrAwithSellup + (SellupProbabilityVector_T& iSellupProbabilityVector, + BidPriceVector_T& ioBidPriceVector, + BookingLimitVector_T& ioBookingLimitVector) { + + assert (_rmolServiceContext != NULL); + const double iCapacity = _rmolServiceContext->getCapacity(); + BucketHolder* ioBucketHolder_ptr = + _rmolServiceContext->getBucketHolder(); + assert (ioBucketHolder_ptr != NULL); + + Optimiser:: + heuristicOptimisationByEmsrAwithSellup (iCapacity, + *ioBucketHolder_ptr, + iSellupProbabilityVector); + + // Fill up booking limit vector + ioBucketHolder_ptr->fillup (ioBookingLimitVector); + } + + // ////////////////////////////////////////////////////////////////////// void RMOL_Service::heuristicOptimisationByEmsrB () { assert (_rmolServiceContext != NULL); const double iCapacity = _rmolServiceContext->getCapacity(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-08-18 17:42:35
|
Revision: 237 http://rmol.svn.sourceforge.net/rmol/?rev=237&view=rev Author: dkchoe Date: 2009-08-18 17:42:18 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Added a function to get Q-yield (the lowest avg yield in the given BucketHolder Modified Paths: -------------- trunk/rmol/rmol/RMOL_Types.hpp trunk/rmol/rmol/bom/BucketHolder.cpp trunk/rmol/rmol/bom/BucketHolder.hpp trunk/rmol/rmol/command/sources.mk Added Paths: ----------- trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Forecaster.hpp Modified: trunk/rmol/rmol/RMOL_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Types.hpp 2009-07-14 13:24:26 UTC (rev 236) +++ trunk/rmol/rmol/RMOL_Types.hpp 2009-08-18 17:42:18 UTC (rev 237) @@ -73,5 +73,20 @@ /** Define the sellup probability vector applicable to EMSR*/ typedef std::vector<double> SellupProbabilityVector_T; + + /** Define the holder of sellup factors (used for computing Q-eq bookings)*/ + typedef std::vector<double> SellupFactorHolder_T; + + /** Define the historical booking data of a flight date in the order of + the classes in the BucketHolder + eg. + BucketHolder=[Q;M;B;Y], OrderedHistoricalBookingVector_T=[10;5;0;0] + 5 corresponds to bookings of class M of a similar flight */ + typedef std::vector<double> OrderedHistoricalBookingVector_T; + + /** Define the holder of historical booking vectors */ + typedef std::vector<OrderedHistoricalBookingVector_T> + HistoricalBookingVectorHolder_T; + } #endif // __RMOL_RMOL_TYPES_HPP Modified: trunk/rmol/rmol/bom/BucketHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/BucketHolder.cpp 2009-07-14 13:24:26 UTC (rev 236) +++ trunk/rmol/rmol/bom/BucketHolder.cpp 2009-08-18 17:42:18 UTC (rev 237) @@ -14,14 +14,14 @@ // ////////////////////////////////////////////////////////////////////// BucketHolder::BucketHolder () : - _cabinCapacity (100.0), - _totalMeanDemand (0.0), _demandFactor (0.0), _optimalRevenue (0.0) { + _cabinCapacity (100.0), _totalMeanDemand (0.0), _demandFactor (0.0), + _optimalRevenue (0.0) { } // ////////////////////////////////////////////////////////////////////// BucketHolder::BucketHolder (const double iCabinCapacity) : - _cabinCapacity (iCabinCapacity), - _totalMeanDemand (0.0), _demandFactor (0.0), _optimalRevenue (0.0) { + _cabinCapacity (iCabinCapacity), _totalMeanDemand (0.0), + _demandFactor (0.0), _optimalRevenue (0.0) { } // ////////////////////////////////////////////////////////////////////// @@ -51,7 +51,8 @@ std::ostringstream oStr; oStr << describeShortKey() << ", " << _totalMeanDemand - << ", " << _demandFactor << ", " << _optimalRevenue + << ", " << _demandFactor + << ", " << _optimalRevenue << std::endl; return oStr.str(); @@ -92,7 +93,8 @@ oStr << "Cabin Capacity = " << _cabinCapacity << "; Total Mean Demand = " << _totalMeanDemand << "; Demand Factor = " << _demandFactor - << "; Optimal Revenue = " << _optimalRevenue << std::endl; + << "; Optimal Revenue = " << _optimalRevenue + << std::endl; return oStr.str(); } @@ -232,6 +234,27 @@ } // ////////////////////////////////////////////////////////////////////// + const double BucketHolder::getLowestAverageYield () { + double oLowestAvgYield = 0.0; + + const short nbOfBuckets = getSize(); + assert (nbOfBuckets != 0); + + begin(); + Bucket& lFirstBucket = getCurrentBucket(); + oLowestAvgYield = lFirstBucket.getAverageYield(); + + for (short j = 1; j < nbOfBuckets; ++j, iterate()) { + Bucket& lNextBucket = getNextBucket(); + double lNextBucketAvgYield = lNextBucket.getAverageYield(); + if (lNextBucketAvgYield < oLowestAvgYield){ + oLowestAvgYield = lNextBucketAvgYield; + } + } + return oLowestAvgYield; + } + + // ////////////////////////////////////////////////////////////////////// void BucketHolder::recalculate () { // Re-calculate the booking limits calculateProtectionAndBookingLimits(); Modified: trunk/rmol/rmol/bom/BucketHolder.hpp =================================================================== --- trunk/rmol/rmol/bom/BucketHolder.hpp 2009-07-14 13:24:26 UTC (rev 236) +++ trunk/rmol/rmol/bom/BucketHolder.hpp 2009-08-18 17:42:18 UTC (rev 237) @@ -81,6 +81,8 @@ - the booking limits and cumulated booking limits. */ void recalculate (); + const double getLowestAverageYield (); + public: // ///////// Display methods //////// /** Dump a Business Object into an output stream. Added: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp (rev 0) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-08-18 17:42:18 UTC (rev 237) @@ -0,0 +1,23 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL +#include <rmol/bom/BucketHolder.hpp> +#include <rmol/bom/Bucket.hpp> +#include <rmol/command/Forecaster.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + void Forecaster::qEquivalentBookingCalculation + (BucketHolder& ioBucketHolder, + SellupFactorHolder_T& iSellupFactorHolder, + HistoricalBookingVectorHolder_T& iHistoricalBookingVectorHolder){ + + const double qYield = ioBucketHolder.getLowestAverageYield (); + + + + } + +} Added: trunk/rmol/rmol/command/Forecaster.hpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.hpp (rev 0) +++ trunk/rmol/rmol/command/Forecaster.hpp 2009-08-18 17:42:18 UTC (rev 237) @@ -0,0 +1,41 @@ +#ifndef __RMOL_COMMAND_FORECASTER_HPP +#define __RMOL_COMMAND_FORECASTER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL +#include <rmol/RMOL_Types.hpp> + +namespace RMOL { + + /** Forward declarations. */ + class BucketHolder; + // class StudyStatManager; + + /** Class wrapping the principal forecasting algorithms and + some accessory algorithms for demand forecasting. */ + class Forecaster { + public: + + /** + An accessory algorithm for demand forecasting. + + Calculate Q-equivalent bookings for the given group of + classes/buckets/fare points using the given + sell-up factors. + + Q-equivalent bookings are, by definition, + + SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} + where + ProbSellup_{bucket i} = + EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) + */ + static void qEquivalentBookingCalculation + (BucketHolder&, + SellupFactorHolder_T&, + HistoricalBookingVectorHolder_T&); + }; +} +#endif // __RMOL_COMMAND_FORECASTER_HPP Modified: trunk/rmol/rmol/command/sources.mk =================================================================== --- trunk/rmol/rmol/command/sources.mk 2009-07-14 13:24:26 UTC (rev 236) +++ trunk/rmol/rmol/command/sources.mk 2009-08-18 17:42:18 UTC (rev 237) @@ -1,4 +1,6 @@ cmd_h_sources = $(top_srcdir)/rmol/command/FileMgr.hpp \ - $(top_srcdir)/rmol/command/Optimiser.hpp + $(top_srcdir)/rmol/command/Optimiser.hpp \ + $(top_srcdir)/rmol/command/Forecaster.hpp cmd_cc_sources = $(top_srcdir)/rmol/command/FileMgr.cpp \ - $(top_srcdir)/rmol/command/Optimiser.cpp + $(top_srcdir)/rmol/command/Optimiser.cpp \ + $(top_srcdir)/rmol/command/Forecaster.cpp \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-08-27 08:15:00
|
Revision: 238 http://rmol.svn.sourceforge.net/rmol/?rev=238&view=rev Author: dkchoe Date: 2009-08-27 08:14:53 +0000 (Thu, 27 Aug 2009) Log Message: ----------- Added rmol service that doesn't require cabin capacity as input argument; Added Historical booking related structs(to be used for unconstraining); Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/RMOL_Types.hpp trunk/rmol/rmol/bom/sources.mk trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Forecaster.hpp trunk/rmol/rmol/service/RMOL_Service.cpp Added Paths: ----------- trunk/rmol/rmol/bom/HistoricalBooking.cpp trunk/rmol/rmol/bom/HistoricalBooking.hpp trunk/rmol/rmol/bom/HistoricalBookingHolder.cpp trunk/rmol/rmol/bom/HistoricalBookingHolder.hpp trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.cpp trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.hpp trunk/rmol/rmol/bom/StructAbstract.hpp Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2009-08-18 17:42:18 UTC (rev 237) +++ trunk/rmol/rmol/RMOL_Service.hpp 2009-08-27 08:14:53 UTC (rev 238) @@ -18,6 +18,8 @@ class RMOL_Service { public: /** Constructor. */ + RMOL_Service (std::ostream& ioLogStream); + RMOL_Service (std::ostream& ioLogStream, const ResourceCapacity_T iResourceCapacity); /** Destructor. */ @@ -117,6 +119,8 @@ RMOL_Service (const RMOL_Service&); /** Initialise. */ + void init (std::ostream& ioLogStream); + void init (std::ostream& ioLogStream, const ResourceCapacity_T iResourceCapacity); Modified: trunk/rmol/rmol/RMOL_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Types.hpp 2009-08-18 17:42:18 UTC (rev 237) +++ trunk/rmol/rmol/RMOL_Types.hpp 2009-08-27 08:14:53 UTC (rev 238) @@ -77,16 +77,19 @@ /** Define the holder of sellup factors (used for computing Q-eq bookings)*/ typedef std::vector<double> SellupFactorHolder_T; - /** Define the historical booking data of a flight date in the order of - the classes in the BucketHolder - eg. - BucketHolder=[Q;M;B;Y], OrderedHistoricalBookingVector_T=[10;5;0;0] - 5 corresponds to bookings of class M of a similar flight */ - typedef std::vector<double> OrderedHistoricalBookingVector_T; +// /** Define the historical booking data of a flight date in the order of +// the classes in the BucketHolder +// eg. +// BucketHolder=[Q;M;B;Y], OrderedHistoricalBookingVector_T=[10;5;0;0] +// 5 corresponds to bookings of class M of a similar flight */ +// typedef std::vector<double> OrderedHistoricalBookingVector_T; - /** Define the holder of historical booking vectors */ - typedef std::vector<OrderedHistoricalBookingVector_T> - HistoricalBookingVectorHolder_T; +// /** Define the holder of historical booking vectors */ +// typedef std::vector<HistoricalBookingHolder> +// HistoricalBookingHolderHolder_T; + /** Define the holder of Q-equivalent booking values*/ + typedef std::vector<double> HolderOfQEquivalentBookingsPerSimilarFlight_T; + } #endif // __RMOL_RMOL_TYPES_HPP Added: trunk/rmol/rmol/bom/HistoricalBooking.cpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalBooking.cpp (rev 0) +++ trunk/rmol/rmol/bom/HistoricalBooking.cpp 2009-08-27 08:14:53 UTC (rev 238) @@ -0,0 +1,61 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// C +#include <assert.h> +// STL +#include <iostream> +#include <iomanip> +// RMU +#include <rmol/bom/HistoricalBooking.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + HistoricalBooking::HistoricalBooking () : + _numberOfBookings (0.0),_unconstrainedDemand (0.0), _flag (false) { + } + + // ////////////////////////////////////////////////////////////////////// + void HistoricalBooking::setParameters + (const double iNumberOfBookings, const bool iFlag) { + _numberOfBookings = iNumberOfBookings; + _unconstrainedDemand = iNumberOfBookings; + _flag = iFlag; + } + + // ////////////////////////////////////////////////////////////////////// + HistoricalBooking::HistoricalBooking + (const HistoricalBooking& iHistoricalBooking) : + _numberOfBookings (iHistoricalBooking.getNumberOfBookings()), + _unconstrainedDemand (iHistoricalBooking.getUnconstrainedDemand()), + _flag (iHistoricalBooking.getFlag()) { + } + + // ////////////////////////////////////////////////////////////////////// + HistoricalBooking::~HistoricalBooking() { + } + + // ////////////////////////////////////////////////////////////////////// + const std::string HistoricalBooking::describe() const { + std::ostringstream ostr; + ostr << "Struct of hitorical booking, unconstrained demand and flag of " + << "censorship for a FlightDate/Class."; + + return ostr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + void HistoricalBooking::toStream (std::ostream& ioOut) const { + const double bj = getNumberOfBookings(); + const double uj = getUnconstrainedDemand(); + const bool fj = getFlag(); + ioOut << std::fixed << std::setprecision (2) + << bj << "; " << uj << "; " << fj << std::endl; + } + + // ////////////////////////////////////////////////////////////////////// + void HistoricalBooking::display () const { + toStream (std::cout); + } +} Added: trunk/rmol/rmol/bom/HistoricalBooking.hpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalBooking.hpp (rev 0) +++ trunk/rmol/rmol/bom/HistoricalBooking.hpp 2009-08-27 08:14:53 UTC (rev 238) @@ -0,0 +1,73 @@ +#ifndef __RMOL_BOM_HISTORICALBOOKING_HPP +#define __RMOL_BOM_HISTORICALBOOKING_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL +#include <rmol/bom/StructAbstract.hpp> + +namespace RMOL { + + /** HistoricalBooking for a given class and the flag of censorship. + */ + struct HistoricalBooking : public StructAbstract { + + public: + // Getters + /** Getter for the booking. */ + const double& getNumberOfBookings() const { + return _numberOfBookings; + } + /** Getter for the unconstrained bookings. */ + const double& getUnconstrainedDemand() const { + return _unconstrainedDemand; + } + /** Getter for the flag of censorship: "false" means that the bookings + are not censored. */ + const bool& getFlag() const { + return _flag; + } + + /** Setter for the unconstraining demand. */ + void setUnconstrainedDemand (const double iDemand) { + _unconstrainedDemand = iDemand; + } + + /** Setter for all parameters (no of bkgs, flag). */ + void setParameters (const double, const bool); + + /** Dump a Business Object into an output stream. + @param ostream& the output stream + @return ostream& the output stream. */ + void toStream (std::ostream& ioOut) const; + + // ///////// Display Methods ////////// + /** Give a description of the structure (for display purposes). */ + const std::string describe() const; + + /** Display on standard output. */ + void display () const; + + /** Destructors. */ + virtual ~HistoricalBooking(); + + public: + /** Constructors. + <br>Protected to force the use of the Factory. */ + HistoricalBooking (); + + HistoricalBooking (const HistoricalBooking&); + + private: + /** Number of historical bookings. */ + double _numberOfBookings; + + /** Unconstrained historical bookings. */ + double _unconstrainedDemand; + + /** Flag of censorship. */ + bool _flag; + }; +} +#endif // __RMOL_BOM_HISTORICALBOOKING_HPP Added: trunk/rmol/rmol/bom/HistoricalBookingHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalBookingHolder.cpp (rev 0) +++ trunk/rmol/rmol/bom/HistoricalBookingHolder.cpp 2009-08-27 08:14:53 UTC (rev 238) @@ -0,0 +1,277 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// GSL Random Number Generation +// (GSL Reference Manual, version 1.7, Chapter 19) +#include <gsl/gsl_cdf.h> +#include <gsl/gsl_randist.h> +// C +#include <assert.h> +#include <math.h> +// STL +#include <iostream> +#include <iomanip> +#include <cmath> +// RMU +#include <rmol/bom/HistoricalBooking.hpp> +#include <rmol/bom/HistoricalBookingHolder.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////// + HistoricalBookingHolder::HistoricalBookingHolder () { + } + + // ////////////////////////////////////////////////////////////////// + HistoricalBookingHolder::~HistoricalBookingHolder () { + _historicalBookingVector.clear(); + } + + // ////////////////////////////////////////////////////////////////// + const short HistoricalBookingHolder::getNumberOfFlights () const { + return _historicalBookingVector.size(); + } + + // ////////////////////////////////////////////////////////////////// + const short HistoricalBookingHolder::getNumberOfUncensoredData () const { + short lResult = 0; + const short lSize = _historicalBookingVector.size(); + + for (short ite = 0; ite < lSize; ++ite) { + const bool lFlag = _historicalBookingVector.at(ite).getFlag (); + if (lFlag == false) { + ++ lResult; + } + } + + return lResult; + } + + // ////////////////////////////////////////////////////////////////// + const double HistoricalBookingHolder:: + getNumberOfUncensoredBookings () const { + double lResult = 0; + const short lSize = _historicalBookingVector.size(); + + for (short ite = 0; ite < lSize; ++ite) { + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(ite); + const bool lFlag = lHistorialBooking.getFlag (); + if (lFlag == false) { + const double lBooking = + lHistorialBooking.getNumberOfBookings (); + lResult += lBooking; + } + } + + return lResult; + } + + // ////////////////////////////////////////////////////////////////// + const double HistoricalBookingHolder::getUncensoredStandardDeviation + (const double iMeanOfUncensoredBookings, const short iNumberOfUncensoredData) + const { + + double lResult = 0; + const short lSize = _historicalBookingVector.size(); + + for (short ite = 0; ite < lSize; ++ite) { + const bool lFlag = _historicalBookingVector.at(ite).getFlag (); + if (lFlag == false) { + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(ite); + + const double lBooking = + lHistorialBooking.getNumberOfBookings (); + + lResult += (lBooking - iMeanOfUncensoredBookings) + * (lBooking - iMeanOfUncensoredBookings); + } + } + lResult /= (iNumberOfUncensoredData - 1); + lResult = sqrt (lResult); + + return lResult; + } + + // ////////////////////////////////////////////////////////////////// + const double HistoricalBookingHolder::getMeanDemand () const { + double lResult = 0; + const short lSize = _historicalBookingVector.size(); + + for (short ite = 0; ite < lSize; ++ite) { + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(ite); + + const double lDemand = + lHistorialBooking.getUnconstrainedDemand (); + + lResult += static_cast<double>(lDemand); + } + + lResult /= lSize; + + return lResult; + } + + // ////////////////////////////////////////////////////////////////// + const double HistoricalBookingHolder::getStandardDeviation + (const double iMeanDemand) const { + double lResult = 0; + const short lSize = _historicalBookingVector.size(); + + for (short ite = 0; ite < lSize; ++ite) { + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(ite); + + const double lDemand = + lHistorialBooking.getUnconstrainedDemand (); + + const double lDoubleDemand = static_cast<double> (lDemand); + lResult += (lDoubleDemand - iMeanDemand) * (lDoubleDemand - iMeanDemand); + } + + lResult /= (lSize - 1); + + lResult = sqrt (lResult); + + return lResult; + } + + // ////////////////////////////////////////////////////////////////// + const std::vector<bool> HistoricalBookingHolder:: + getListOfToBeUnconstrainedFlags () const { + std::vector<bool> lResult; + const short lSize = _historicalBookingVector.size(); + + for (short ite = 0; ite < lSize; ++ite) { + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(ite); + const bool lFlag = lHistorialBooking.getFlag (); + if (lFlag == true) { + lResult.push_back(true); + } + else { + lResult.push_back(false); + } + } + + return lResult; + } + + // ////////////////////////////////////////////////////////////////// + const double HistoricalBookingHolder:: + getHistoricalBooking (const short i) const { + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(i); + double lResult = lHistorialBooking.getNumberOfBookings(); + return lResult; + } + + // ////////////////////////////////////////////////////////////////// + const double HistoricalBookingHolder:: + getUnconstrainedDemand (const short i) const { + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(i); + double lResult = lHistorialBooking.getUnconstrainedDemand(); + return lResult; + } + + // ////////////////////////////////////////////////////////////////// + void HistoricalBookingHolder::setUnconstrainedDemand + (const double iExpectedDemand, const short i) { + _historicalBookingVector.at(i).setUnconstrainedDemand(iExpectedDemand); + } + + // ////////////////////////////////////////////////////////////////////// + const double HistoricalBookingHolder::calculateExpectedDemand + (const double iMean, const double iSD, + const short i, const double iDemand) const { + + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(i); + const double lBooking = static_cast <double> + (lHistorialBooking.getNumberOfBookings()); + double e, d1, d2; + /* + e = - (lBooking - iMean) * (lBooking - iMean) * 0.625 / (iSD * iSD); + e = exp (e); + + // Prevent e to be too close to 0: that can cause d1 = 0. + //if (e < 0.01) { + // return iDemand; + //} + + double s = sqrt (1 - e); + + if (lBooking >= iMean) { + d1 = 0.5 * (1 - s); + } + else { + d1 = 0.5 * (1 + s); + } + */ + + d1 = gsl_cdf_gaussian_Q (lBooking - iMean, iSD); + + e = - (lBooking - iMean) * (lBooking - iMean) * 0.5 / (iSD * iSD); + e = exp (e); + + d2 = e * iSD / sqrt(2 * 3.14159265); + + // std::cout << "d1, d2 = " << d1 << " " << d2 << std::endl; + + if (d1 == 0) { + return iDemand; + } + + const double lDemand = + static_cast<double> (iMean + d2/d1); + + return lDemand; + } + + // ////////////////////////////////////////////////////////////////// + void HistoricalBookingHolder::addHistoricalBooking + (const HistoricalBooking iHistoricalBooking) { + _historicalBookingVector.push_back(iHistoricalBooking); + } + + // ////////////////////////////////////////////////////////////////// + void HistoricalBookingHolder::toStream (std::ostream& ioOut) const { + const short lSize = _historicalBookingVector.size(); + + ioOut << "Historical Booking; Unconstrained Demand; Flag" << std::endl; + + for (short ite = 0; ite < lSize; ++ite) { + const HistoricalBooking lHistorialBooking = + _historicalBookingVector.at(ite); + + const double lBooking = + lHistorialBooking.getNumberOfBookings(); + + const double lDemand = + lHistorialBooking.getUnconstrainedDemand(); + + const bool lFlag = lHistorialBooking.getFlag(); + + ioOut << lBooking << " " + << lDemand << " " + << lFlag << std::endl; + } + } + + // ////////////////////////////////////////////////////////////////////// + const std::string HistoricalBookingHolder::describe() const { + std::ostringstream ostr; + ostr << "Holder of HistoricalBooking structs."; + + return ostr.str(); + } + + // ////////////////////////////////////////////////////////////////// + void HistoricalBookingHolder::display() const { + toStream (std::cout); + } + +} Added: trunk/rmol/rmol/bom/HistoricalBookingHolder.hpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalBookingHolder.hpp (rev 0) +++ trunk/rmol/rmol/bom/HistoricalBookingHolder.hpp 2009-08-27 08:14:53 UTC (rev 238) @@ -0,0 +1,103 @@ +#ifndef __RMOL_BOM_HISTORICALBOOKINGHOLDER_HPP +#define __RMOL_BOM_HISTORICALBOOKINGHOLDER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iostream> +#include <vector> +// RMOL +#include <rmol/RMOL_Types.hpp> +#include <rmol/bom/StructAbstract.hpp> + +namespace RMOL { + + /** Forward declaration. */ + struct HistoricalBooking; + + /** Define a vector (ordered list) of N HistoricalBookings. */ + typedef std::vector<HistoricalBooking> HistoricalBookingVector_T; + + /** Holder of a HistoricalBookingList object (for memory allocation and + recollection purposes). */ + struct HistoricalBookingHolder : public StructAbstract { + + public: + // ////// Getters ////// + /** Get number of flights. */ + const short getNumberOfFlights () const; + + /** Get number of uncensored booking data. */ + const short getNumberOfUncensoredData () const; + + /** Get number of uncensored bookings. */ + const double getNumberOfUncensoredBookings () const; + + /** Get standard deviation of uncensored bookings. */ + const double getUncensoredStandardDeviation + (const double iMeanOfUncensoredBookings, + const short iNumberOfUncensoredData) const; + + /** Get mean of historical demand. */ + const double getMeanDemand () const; + + /** Get standard deviation of demand. */ + const double getStandardDeviation (const double) const; + + /** Get the list of flags of need to be unconstrained. */ + const std::vector<bool> getListOfToBeUnconstrainedFlags() const; + + /** Get the historical booking of the (i+1)-th flight. */ + const double getHistoricalBooking (const short i) const; + + /** Get the unconstraining demand of the (i+1)-th flight. */ + const double getUnconstrainedDemand (const short i) const; + + /** Get the unconstraining demand of the first flight. */ + const double getUnconstrainedDemandOnFirstElement () const { + return getUnconstrainedDemand (0); + } + + /** Calculate the expected demand. */ + const double calculateExpectedDemand (const double, + const double, + const short, + const double) const; + + /** Set the expected historical demand of the (i+1)-th flight. */ + void setUnconstrainedDemand (const double iExpectedDemand, + const short i); + + /** Add a HistoricalBooking object to the holder. */ + void addHistoricalBooking (const HistoricalBooking iHistoricalBooking); + + /** Dump a Business Object into an output stream. + @param ostream& the output stream + @return ostream& the output stream. */ + void toStream (std::ostream& ioOut) const; + + // ///////// Display Methods ////////// + /** Give a description of the structure (for display purposes). */ + const std::string describe() const; + + /** Display on standard output. */ + void display () const; + + /** Destructor. */ + virtual ~HistoricalBookingHolder(); + + public: + /** Constructor. + <br>Protected to force the use of the Factory. */ + HistoricalBookingHolder (); + + private: + + /** The list of (N) buckets/classes. */ + HistoricalBookingVector_T _historicalBookingVector; + + }; +} +#endif // __RMOL_BOM_HISTORICALBOOKINGHOLDER_HPP + Added: trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.cpp (rev 0) +++ trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.cpp 2009-08-27 08:14:53 UTC (rev 238) @@ -0,0 +1,276 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// GSL Random Number Generation (GSL Reference Manual, version 1.7, Chapter 19) +#include <gsl/gsl_cdf.h> +#include <gsl/gsl_randist.h> +// C +#include <assert.h> +#include <math.h> +// STL +#include <iostream> +#include <iomanip> +#include <cmath> +// RMU +#include <rmol/bom/HistoricalBookingHolder.hpp> +#include <rmol/bom/HistoricalBookingHolderHolder.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////// + HistoricalBookingHolderHolder::HistoricalBookingHolderHolder () { + } + + // ////////////////////////////////////////////////////////////////// + HistoricalBookingHolderHolder::~HistoricalBookingHolderHolder () { + _historicalBookingHolderHolder.clear(); + } + + // ////////////////////////////////////////////////////////////////// + const int HistoricalBookingHolderHolder::getNumberOfSimilarFlights () + const { + return _historicalBookingHolderHolder.size(); + } + +// // ////////////////////////////////////////////////////////////////// +// const short HistoricalBookingHolderHolder::getNumberOfUncensoredData () const { +// short lResult = 0; +// const short lSize = _historicalBookingHolderHolder.size(); + +// for (short ite = 0; ite < lSize; ++ite) { +// const bool lFlag = _historicalBookingHolderHolder.at(ite).getFlag (); +// if (lFlag == false) { +// ++ lResult; +// } +// } + +// return lResult; +// } + +// // ////////////////////////////////////////////////////////////////// +// const double HistoricalBookingHolderHolder:: +// getNumberOfUncensoredBookings () const { +// double lResult = 0; +// const short lSize = _historicalBookingHolderHolder.size(); + +// for (short ite = 0; ite < lSize; ++ite) { +// const HistoricalBooking lHistorialBooking = +// _historicalBookingHolderHolder.at(ite); +// const bool lFlag = lHistorialBooking.getFlag (); +// if (lFlag == false) { +// const double lBooking = +// lHistorialBooking.getNumberOfBookings (); +// lResult += lBooking; +// } +// } + +// return lResult; +// } + +// // ////////////////////////////////////////////////////////////////// +// const double HistoricalBookingHolderHolder::getUncensoredStandardDeviation +// (const double iMeanOfUncensoredBookings, const short iNumberOfUncensoredData) +// const { + +// double lResult = 0; +// const short lSize = _historicalBookingHolderHolder.size(); + +// for (short ite = 0; ite < lSize; ++ite) { +// const bool lFlag = _historicalBookingHolderHolder.at(ite).getFlag (); +// if (lFlag == false) { +// const HistoricalBooking lHistorialBooking = +// _historicalBookingHolderHolder.at(ite); + +// const double lBooking = +// lHistorialBooking.getNumberOfBookings (); + +// lResult += (lBooking - iMeanOfUncensoredBookings) +// * (lBooking - iMeanOfUncensoredBookings); +// } +// } +// lResult /= (iNumberOfUncensoredData - 1); +// lResult = sqrt (lResult); + +// return lResult; +// } + +// // ////////////////////////////////////////////////////////////////// +// const double HistoricalBookingHolderHolder::getMeanDemand () const { +// double lResult = 0; +// const short lSize = _historicalBookingHolderHolder.size(); + +// for (short ite = 0; ite < lSize; ++ite) { +// const HistoricalBooking lHistorialBooking = +// _historicalBookingHolderHolder.at(ite); + +// const double lDemand = +// lHistorialBooking.getUnconstrainedDemand (); + +// lResult += static_cast<double>(lDemand); +// } + +// lResult /= lSize; + +// return lResult; +// } + +// // ////////////////////////////////////////////////////////////////// +// const double HistoricalBookingHolderHolder::getStandardDeviation +// (const double iMeanDemand) const { +// double lResult = 0; +// const short lSize = _historicalBookingHolderHolder.size(); + +// for (short ite = 0; ite < lSize; ++ite) { +// const HistoricalBooking lHistorialBooking = +// _historicalBookingHolderHolder.at(ite); + +// const double lDemand = +// lHistorialBooking.getUnconstrainedDemand (); + +// const double lDoubleDemand = static_cast<double> (lDemand); +// lResult += (lDoubleDemand - iMeanDemand) * (lDoubleDemand - iMeanDemand); +// } + +// lResult /= (lSize - 1); + +// lResult = sqrt (lResult); + +// return lResult; +// } + +// // ////////////////////////////////////////////////////////////////// +// const std::vector<bool> HistoricalBookingHolderHolder:: +// getListOfToBeUnconstrainedFlags () const { +// std::vector<bool> lResult; +// const short lSize = _historicalBookingHolderHolder.size(); + +// for (short ite = 0; ite < lSize; ++ite) { +// const HistoricalBooking lHistorialBooking = +// _historicalBookingHolderHolder.at(ite); +// const bool lFlag = lHistorialBooking.getFlag (); +// if (lFlag == true) { +// lResult.push_back(true); +// } +// else { +// lResult.push_back(false); +// } +// } + +// return lResult; +// } + + // ////////////////////////////////////////////////////////////////// +// HistoricalBookingHolder& HistoricalBookingHolderHolder:: +// getHistoricalBookingVector (const int i) const { +// const HistoricalBookingHolder lHistoricalBookingVector = +// _historicalBookingHolderHolder.at(i); +// return lHistoricalBookingVector; +// } + +// // ////////////////////////////////////////////////////////////////// +// const double HistoricalBookingHolderHolder:: +// getUnconstrainedDemand (const short i) const { +// const HistoricalBooking lHistorialBooking = +// _historicalBookingHolderHolder.at(i); +// double lResult = lHistorialBooking.getUnconstrainedDemand(); +// return lResult; +// } + +// // ////////////////////////////////////////////////////////////////// +// void HistoricalBookingHolderHolder::setUnconstrainedDemand +// (const double iExpectedDemand, const short i) { +// _historicalBookingHolderHolder.at(i).setUnconstrainedDemand(iExpectedDemand); +// } + +// // ////////////////////////////////////////////////////////////////////// +// const double HistoricalBookingHolderHolder::calculateExpectedDemand +// (const double iMean, const double iSD, +// const short i, const double iDemand) const { + +// const HistoricalBooking lHistorialBooking = +// _historicalBookingHolderHolder.at(i); +// const double lBooking = static_cast <double> +// (lHistorialBooking.getNumberOfBookings()); +// double e, d1, d2; +// /* +// e = - (lBooking - iMean) * (lBooking - iMean) * 0.625 / (iSD * iSD); +// e = exp (e); + +// // Prevent e to be too close to 0: that can cause d1 = 0. +// //if (e < 0.01) { +// // return iDemand; +// //} + +// double s = sqrt (1 - e); + +// if (lBooking >= iMean) { +// d1 = 0.5 * (1 - s); +// } +// else { +// d1 = 0.5 * (1 + s); +// } +// */ + +// d1 = gsl_cdf_gaussian_Q (lBooking - iMean, iSD); + +// e = - (lBooking - iMean) * (lBooking - iMean) * 0.5 / (iSD * iSD); +// e = exp (e); + +// d2 = e * iSD / sqrt(2 * 3.14159265); + +// // std::cout << "d1, d2 = " << d1 << " " << d2 << std::endl; + +// if (d1 == 0) { +// return iDemand; +// } + +// const double lDemand = +// static_cast<double> (iMean + d2/d1); + +// return lDemand; +// } + +// // ////////////////////////////////////////////////////////////////// +// void HistoricalBookingHolderHolder::addHistoricalBooking +// (const HistoricalBooking iHistoricalBooking) { +// _historicalBookingHolderHolder.push_back(iHistoricalBooking); +// } + +// // ////////////////////////////////////////////////////////////////// +// void HistoricalBookingHolderHolder::toStream (std::ostream& ioOut) const { +// const short lSize = _historicalBookingHolderHolder.size(); + +// ioOut << "Historical Booking; Unconstrained Demand; Flag" << std::endl; + +// for (short ite = 0; ite < lSize; ++ite) { +// const HistoricalBooking lHistorialBooking = +// _historicalBookingHolderHolder.at(ite); + +// const double lBooking = +// lHistorialBooking.getNumberOfBookings(); + +// const double lDemand = +// lHistorialBooking.getUnconstrainedDemand(); + +// const bool lFlag = lHistorialBooking.getFlag(); + +// ioOut << lBooking << " " +// << lDemand << " " +// << lFlag << std::endl; +// } +// } + +// // ////////////////////////////////////////////////////////////////////// +// const std::string HistoricalBookingHolderHolder::describe() const { +// std::ostringstream ostr; +// ostr << "Holder of HistoricalBooking structs."; + +// return ostr.str(); +// } + +// // ////////////////////////////////////////////////////////////////// +// void HistoricalBookingHolderHolder::display() const { +// toStream (std::cout); +// } + +} Added: trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.hpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.hpp (rev 0) +++ trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.hpp 2009-08-27 08:14:53 UTC (rev 238) @@ -0,0 +1,104 @@ +#ifndef __RMOL_BOM_HISTORICALBOOKINGVECTORHOLDER_HPP +#define __RMOL_BOM_HISTORICALBOOKINGVECTORHOLDER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iostream> +#include <vector> +// RMOL +// #include <rmol/RMOL_Types.hpp> +#include <rmol/bom/StructAbstract.hpp> + +namespace RMOL { + + /** Forward declaration. */ + struct HistoricalBookingHolder; + + /** Define a vector (ordered list) of N HistoricalBookings. */ + typedef std::vector<HistoricalBookingHolder> + HistoricalBookingHolderHolder_T; + + /** Holder of a HistoricalBookingList object (for memory allocation and + recollection purposes). */ + struct HistoricalBookingHolderHolder : public StructAbstract { + + public: + // ////// Getters ////// + /** Get number of similar flights. */ + const int getNumberOfSimilarFlights () const; + +// /** Get number of uncensored booking data. */ +// const short getNumberOfUncensoredData () const; + +// /** Get number of uncensored bookings. */ +// const double getNumberOfUncensoredBookings () const; + +// /** Get standard deviation of uncensored bookings. */ +// const double getUncensoredStandardDeviation +// (const double iMeanOfUncensoredBookings, +// const short iNumberOfUncensoredData) const; + +// /** Get mean of historical demand. */ +// const double getMeanDemand () const; + +// /** Get standard deviation of demand. */ +// const double getStandardDeviation (const double) const; + +// /** Get the list of flags of need to be unconstrained. */ +// const std::vector<bool> getListOfToBeUnconstrainedFlags() const; + + /** Get the historical booking Vector of the i-th similar flight. */ +// HistoricalBookingHolder& getHistoricalBookingVector (const int i) const; + +// /** Get the unconstraining demand of the (i+1)-th flight. */ +// const double getUnconstrainedDemand (const short i) const; + +// /** Get the unconstraining demand of the first flight. */ +// const double getUnconstrainedDemandOnFirstElement () const { +// return getUnconstrainedDemand (0); +// } + +// /** Calculate the expected demand. */ +// const double calculateExpectedDemand (const double, +// const double, +// const short, +// const double) const; + +// /** Set the expected historical demand of the (i+1)-th flight. */ +// void setUnconstrainedDemand (const double iExpectedDemand, +// const short i); + +// /** Add a HistoricalBooking object to the holder. */ +// void addHistoricalBooking (const HistoricalBooking iHistoricalBooking); + +// /** Dump a Business Object into an output stream. +// @param ostream& the output stream +// @return ostream& the output stream. */ +// void toStream (std::ostream& ioOut) const; + +// // ///////// Display Methods ////////// +// /** Give a description of the structure (for display purposes). */ +// const std::string describe() const; + +// /** Display on standard output. */ +// void display () const; + + /** Destructor. */ + virtual ~HistoricalBookingHolderHolder(); + + public: + /** Constructor. + <br>Protected to force the use of the Factory. */ + HistoricalBookingHolderHolder (); + + private: + + /** The list of (N) similar flights. */ + HistoricalBookingHolderHolder_T _historicalBookingHolderHolder; + + }; +} +#endif // __RMOL_BOM_HISTORICALBOOKINGVECTORHOLDER_HPP + Added: trunk/rmol/rmol/bom/StructAbstract.hpp =================================================================== --- trunk/rmol/rmol/bom/StructAbstract.hpp (rev 0) +++ trunk/rmol/rmol/bom/StructAbstract.hpp 2009-08-27 08:14:53 UTC (rev 238) @@ -0,0 +1,84 @@ +#ifndef __RMOL_BOM_STRUCTABSTRACT_HPP +#define __RMOL_BOM_STRUCTABSTRACT_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iostream> +#include <sstream> + +namespace RMOL { + + /** Base class for the Structures of the Business Object Model (BOM) + layer. */ + struct StructAbstract { + public: + + /** Destructor. */ + virtual ~StructAbstract() {} + + /** Dump a Business Object into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream& ioOut) const { + ioOut << describe(); + } + + /** Read a Business Object from an input stream. + @param istream& the input stream. */ + virtual void fromStream (std::istream& ioIn) {} + + /** Display of the structure. */ + virtual const std::string describe() const = 0; + + protected: + /** Protected Default Constructor to ensure this class is abtract. */ + StructAbstract() {} + }; +} + +/** + Piece of code given by Nicolai M. Josuttis, Section 13.12.1 "Implementing + Output Operators" (p653) of his book "The C++ Standard Library: A Tutorial + and Reference", published by Addison-Wesley. +*/ +template <class charT, class traits> +inline +std::basic_ostream<charT, traits>& +operator<< (std::basic_ostream<charT, traits>& ioOut, + const RMOL::StructAbstract& iStruct) { + /** + string stream: + - with same format + - without special field width + */ + std::basic_ostringstream<charT,traits> ostr; + ostr.copyfmt (ioOut); + ostr.width (0); + + // Fill string stream + iStruct.toStream (ostr); + + // Print string stream + ioOut << ostr.str(); + + return ioOut; +} + +/** + Piece of code given by Nicolai M. Josuttis, Section 13.12.1 "Implementing + Output Operators" (pp655-657) of his book "The C++ Standard Library: + A Tutorial and Reference", published by Addison-Wesley. +*/ +template <class charT, class traits> +inline +std::basic_istream<charT, traits>& +operator>> (std::basic_istream<charT, traits>& ioIn, + RMOL::StructAbstract& ioStruct) { + // Fill the Structure object with the input stream. + ioStruct.fromStream (ioIn); + return ioIn; + +} + +#endif // __RMOL_BOM_STRUCTABSTRACT_HPP Modified: trunk/rmol/rmol/bom/sources.mk =================================================================== --- trunk/rmol/rmol/bom/sources.mk 2009-08-18 17:42:18 UTC (rev 237) +++ trunk/rmol/rmol/bom/sources.mk 2009-08-27 08:14:53 UTC (rev 238) @@ -1,10 +1,14 @@ bom_h_sources = $(top_srcdir)/rmol/bom/BomAbstract.hpp \ + $(top_srcdir)/rmol/bom/StructAbstract.hpp \ $(top_srcdir)/rmol/bom/Bucket.hpp \ $(top_srcdir)/rmol/bom/BucketList.hpp \ $(top_srcdir)/rmol/bom/BucketHolder.hpp \ $(top_srcdir)/rmol/bom/Demand.hpp \ $(top_srcdir)/rmol/bom/DistributionParameterList.hpp \ $(top_srcdir)/rmol/bom/Gaussian.hpp \ + $(top_srcdir)/rmol/bom/HistoricalBooking.hpp \ + $(top_srcdir)/rmol/bom/HistoricalBookingHolder.hpp \ + $(top_srcdir)/rmol/bom/HistoricalBookingHolderHolder.hpp \ $(top_srcdir)/rmol/bom/PartialSumList.hpp \ $(top_srcdir)/rmol/bom/VariateList.hpp \ $(top_srcdir)/rmol/bom/PartialSumHolder.hpp \ @@ -24,6 +28,9 @@ $(top_srcdir)/rmol/bom/BucketHolder.cpp \ $(top_srcdir)/rmol/bom/Demand.cpp \ $(top_srcdir)/rmol/bom/Gaussian.cpp \ + $(top_srcdir)/rmol/bom/HistoricalBooking.cpp \ + $(top_srcdir)/rmol/bom/HistoricalBookingHolder.cpp \ + $(top_srcdir)/rmol/bom/HistoricalBookingHolderHolder.cpp \ $(top_srcdir)/rmol/bom/PartialSumHolder.cpp \ $(top_srcdir)/rmol/bom/PartialSumHolderHolder.cpp \ $(top_srcdir)/rmol/bom/Emsr.cpp \ Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2009-08-18 17:42:18 UTC (rev 237) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-08-27 08:14:53 UTC (rev 238) @@ -1,23 +1,74 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +#include <math.h> // RMOL +#include <rmol/bom/Bucket.hpp> #include <rmol/bom/BucketHolder.hpp> -#include <rmol/bom/Bucket.hpp> +#include <rmol/bom/HistoricalBooking.hpp> +#include <rmol/bom/HistoricalBookingHolder.hpp> +#include <rmol/bom/HistoricalBookingHolderHolder.hpp> #include <rmol/command/Forecaster.hpp> namespace RMOL { // ////////////////////////////////////////////////////////////////////// void Forecaster::qEquivalentBookingCalculation - (BucketHolder& ioBucketHolder, - SellupFactorHolder_T& iSellupFactorHolder, - HistoricalBookingVectorHolder_T& iHistoricalBookingVectorHolder){ + (BucketHolder& ioBucketHolder, + SellupFactorHolder_T& iSellupFactorHolder, + HistoricalBookingHolderHolder& iHistoricalBookingHolderHolder, + HolderOfQEquivalentBookingsPerSimilarFlight_T& + oQEquivalentBookingsPerSimilarFlight){ + // Get the lowest yield of the given buckets const double qYield = ioBucketHolder.getLowestAverageYield (); + // Get the number of Buckets + const double nbOfBuckets = ioBucketHolder.getSize(); + // Initialize a vector for sell-up probabilities + std::vector<double> lSellupProbabilityVector; + /** Sell-up probability calculator */ + // Compute sell-up probability for each bucket and store it in a vector + short j = 0; + for (ioBucketHolder.begin(); + ioBucketHolder.hasNotReachedEnd(); + ioBucketHolder.iterate()) { + Bucket& lCurrentBucket = ioBucketHolder.getCurrentBucket(); + const double lYield = lCurrentBucket.getAverageYield(); + const double probSellup = + exp(-iSellupFactorHolder.at(j) *lYield/qYield); + lSellupProbabilityVector.push_back(probSellup); + j++; + } + +// /** Q-equivqlent booking calculator */ +// // Compute total Q-equivalent bookings +// for (int j = 0; +// j < iHistoricalBookingHolderHolder.getNumberOfSimilarFlights(); +// j++) { + +// HistoricalBookingHolder& lHistoricalBookingHolder = +// iHistoricalBookingHolderHolder.at(j); + +// double qEquivqlentBooking = 0.0; +// for (short k = 0; k < nbOfBuckets; k++) { +// HistoricalBooking& lHistoricalBooking = +// lCurrentHistoricalBookingVector.getHistoricalBooking(k); +// const double& lHBValue = lHistoricalBooking.getNumberOfBookings(); +// qEquivqlentBooking = qEquivqlentBooking + +// lHBValue * lSellupProbabilityVector[k]; +// } + +// oQEquivalentBookingsPerSimilarFlight.push_back(qEquivqlentBooking); +// } + +// // SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} +// // where +// // ProbSellup_{bucket i} = +// // EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) + } - + } Modified: trunk/rmol/rmol/command/Forecaster.hpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.hpp 2009-08-18 17:42:18 UTC (rev 237) +++ trunk/rmol/rmol/command/Forecaster.hpp 2009-08-27 08:14:53 UTC (rev 238) @@ -6,11 +6,12 @@ // ////////////////////////////////////////////////////////////////////// // RMOL #include <rmol/RMOL_Types.hpp> - +#include <rmol/bom/HistoricalBookingHolderHolder.hpp> namespace RMOL { /** Forward declarations. */ class BucketHolder; + struct HistoricalBookingHolderHolder; // class StudyStatManager; /** Class wrapping the principal forecasting algorithms and @@ -35,7 +36,8 @@ static void qEquivalentBookingCalculation (BucketHolder&, SellupFactorHolder_T&, - HistoricalBookingVectorHolder_T&); + HistoricalBookingHolderHolder&, + HolderOfQEquivalentBookingsPerSimilarFlight_T&); }; } #endif // __RMOL_COMMAND_FORECASTER_HPP Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-08-18 17:42:18 UTC (rev 237) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2009-08-27 08:14:53 UTC (rev 238) @@ -34,6 +34,12 @@ } // ////////////////////////////////////////////////////////////////////// + RMOL_Service::RMOL_Service (std::ostream& ioLogStream) { + // Initialise the context + init (ioLogStream); + } + + // ////////////////////////////////////////////////////////////////////// RMOL_Service::RMOL_Service (std::ostream& ioLogStream, const ResourceCapacity_T iResourceCapacity) { // Initialise the context @@ -45,6 +51,17 @@ } // ////////////////////////////////////////////////////////////////////// + void RMOL_Service::init (std::ostream& ioLogStream) { + // Set the log file + logInit (LOG::DEBUG, ioLogStream); + + // Initialise the context + RMOL_ServiceContext& lRMOL_ServiceContext = + FacRmolServiceContext::instance().create (); + _rmolServiceContext = &lRMOL_ServiceContext; + } + + // ////////////////////////////////////////////////////////////////////// void RMOL_Service::init (std::ostream& ioLogStream, const ResourceCapacity_T iResourceCapacity) { // Set the log file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-08-27 17:57:26
|
Revision: 239 http://rmol.svn.sourceforge.net/rmol/?rev=239&view=rev Author: dkchoe Date: 2009-08-27 17:57:15 +0000 (Thu, 27 Aug 2009) Log Message: ----------- Added (empty) interfaces for unconstraining & forecasting algorithms; Added objects used for calculating Sellup probability and Q-eq bookings Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/bom/sources.mk trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Forecaster.hpp trunk/rmol/rmol/command/sources.mk trunk/rmol/rmol/service/RMOL_Service.cpp Added Paths: ----------- trunk/rmol/rmol/bom/QEquivalentBookingCalculator.cpp trunk/rmol/rmol/bom/QEquivalentBookingCalculator.hpp trunk/rmol/rmol/bom/SellupProbabilityCalculator.cpp trunk/rmol/rmol/bom/SellupProbabilityCalculator.hpp trunk/rmol/rmol/command/Unconstrainer.cpp trunk/rmol/rmol/command/Unconstrainer.hpp Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2009-08-27 08:14:53 UTC (rev 238) +++ trunk/rmol/rmol/RMOL_Service.hpp 2009-08-27 17:57:15 UTC (rev 239) @@ -113,6 +113,12 @@ network optimisation. */ void legOptimisationByMC (BidPriceVector_T&, BookingLimitVector_T&); + /** Demand unconstraining by Expectation Maximization */ + void demandUnconstrainingByExpectationMaximization (); + + /** Demand forecast using Q-Forecasting */ + void demandForecastByQForecasting (); + private: /** Default Constructors. */ RMOL_Service (); Added: trunk/rmol/rmol/bom/QEquivalentBookingCalculator.cpp =================================================================== --- trunk/rmol/rmol/bom/QEquivalentBookingCalculator.cpp (rev 0) +++ trunk/rmol/rmol/bom/QEquivalentBookingCalculator.cpp 2009-08-27 17:57:15 UTC (rev 239) @@ -0,0 +1,49 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cmath> +// RMOL Bom +#include <rmol/bom/Bucket.hpp> +#include <rmol/bom/BucketHolder.hpp> +#include <rmol/bom/QEquivalentBookingCalculator.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + void QEquivalentBookingCalculator::calculateQEquivalentBooking + (HistoricalBookingHolderHolder& iHistoricalBookingHolderHolder, + SellupProbabilityVector_T& iSellupProbabilityVector, + HolderOfQEquivalentBookingsPerSimilarFlight_T& + oHolderOfQEquivalentBookingsPerSimilarFlight) { + +// // Get the number of Buckets +// const double nbOfBuckets = ioBucketHolder.getSize(); + +// for (int j = 0; +// j < iHistoricalBookingHolderHolder.getNumberOfSimilarFlights(); +// j++) { + +// HistoricalBookingHolder& lHistoricalBookingHolder = +// iHistoricalBookingHolderHolder.at(j); + +// double qEquivalentBooking = 0.0; +// for (short k = 0; k < nbOfBuckets; k++) { +// HistoricalBooking& lHistoricalBooking = +// lCurrentHistoricalBookingVector.getHistoricalBooking(k); +// const double& lHBValue = lHistoricalBooking.getNumberOfBookings(); +// qEquivqlentBooking = qEquivqlentBooking + +// lHBValue * lSellupProbabilityVector[k]; +// } + +// oQEquivalentBookingsPerSimilarFlight.push_back(qEquivqlentBooking); +// } + +// // SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} +// // where +// // ProbSellup_{bucket i} = +// // EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) + + + } +} Added: trunk/rmol/rmol/bom/QEquivalentBookingCalculator.hpp =================================================================== --- trunk/rmol/rmol/bom/QEquivalentBookingCalculator.hpp (rev 0) +++ trunk/rmol/rmol/bom/QEquivalentBookingCalculator.hpp 2009-08-27 17:57:15 UTC (rev 239) @@ -0,0 +1,33 @@ +#ifndef __RMOL_BOM_QEQUIVQLENTBOOKINGCALCULATOR_HPP +#define __RMOL_BOM_QEQUIVQLENTBOOKINGCALCULATOR_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL Bom +#include <rmol/bom/BomAbstract.hpp> +#include <rmol/RMOL_Types.hpp> + +namespace RMOL { + + // Forward declaration + struct HistoricalBookingHolderHolder; + + /** Accessary Class for Sellup considered forecast methods. */ + class QEquivalentBookingCalculator : public BomAbstract { + + public: + + /** Calculate Q-equivalent bookings probability for given sell-up + probabilities.<br> + The formular was proposed by Belobaba and Hopperstad: + Algorithms for Revenue Management in Unrestricted Fare Markets, + AGIFORS, Auckland, New Zealand, Jan 2004 */ + static void calculateQEquivalentBooking + (HistoricalBookingHolderHolder&, + SellupProbabilityVector_T&, + HolderOfQEquivalentBookingsPerSimilarFlight_T&); + }; + +} +#endif // __RMOL_BOM_QEQUIVQLENTBOOKINGCALCULATOR_HPP Added: trunk/rmol/rmol/bom/SellupProbabilityCalculator.cpp =================================================================== --- trunk/rmol/rmol/bom/SellupProbabilityCalculator.cpp (rev 0) +++ trunk/rmol/rmol/bom/SellupProbabilityCalculator.cpp 2009-08-27 17:57:15 UTC (rev 239) @@ -0,0 +1,32 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cmath> +// RMOL Bom +#include <rmol/bom/Bucket.hpp> +#include <rmol/bom/BucketHolder.hpp> +#include <rmol/bom/SellupProbabilityCalculator.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + void SellupProbabilityCalculator::calculateSellupProbability + (BucketHolder& iBucketHolder, + const double iQYield, + const SellupFactorHolder_T& iSellupFactorHolder, + SellupProbabilityVector_T& ioSellupProbabilityVector) { + // Compute sell-up probability for each bucket and store it in a vector + short j = 0; + for (iBucketHolder.begin(); + iBucketHolder.hasNotReachedEnd(); + iBucketHolder.iterate()) { + Bucket& lCurrentBucket = iBucketHolder.getCurrentBucket(); + const double lYield = lCurrentBucket.getAverageYield(); + const double probSellup = + exp(-iSellupFactorHolder.at(j) *lYield/iQYield); + ioSellupProbabilityVector.push_back(probSellup); + j++; + } + } +} Added: trunk/rmol/rmol/bom/SellupProbabilityCalculator.hpp =================================================================== --- trunk/rmol/rmol/bom/SellupProbabilityCalculator.hpp (rev 0) +++ trunk/rmol/rmol/bom/SellupProbabilityCalculator.hpp 2009-08-27 17:57:15 UTC (rev 239) @@ -0,0 +1,32 @@ +#ifndef __RMOL_BOM_SELLUPPROBABILITYCALCULATOR_HPP +#define __RMOL_BOM_SELLUPPROBABILITYCALCULATOR_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL Bom +#include <rmol/bom/BomAbstract.hpp> + +namespace RMOL { + + // Forward declaration + class BucketHolder; + + /** Accessary Class for Sellup considered forecast methods. */ + class SellupProbabilityCalculator : public BomAbstract { + + public: + + /** Calculate sell-up probability for given sell-up factor, + and yield ratio between the sell-up occurs.<br> + The formular was proposed by Belobaba and Hopperstad: + Algorithms for Revenue Management in Unrestricted Fare Markets, + AGIFORS, Auckland, New Zealand, Jan 2004 */ + static void calculateSellupProbability (BucketHolder&, + const double iQYield, + const SellupFactorHolder_T&, + SellupProbabilityVector_T&); + }; + +} +#endif // __RMOL_BOM_SELLUPPROBABILITYCALCULATOR_HPP Modified: trunk/rmol/rmol/bom/sources.mk =================================================================== --- trunk/rmol/rmol/bom/sources.mk 2009-08-27 08:14:53 UTC (rev 238) +++ trunk/rmol/rmol/bom/sources.mk 2009-08-27 17:57:15 UTC (rev 239) @@ -22,7 +22,9 @@ $(top_srcdir)/rmol/bom/MAForecast.hpp \ $(top_srcdir)/rmol/bom/StatAggregatorStruct.hpp \ $(top_srcdir)/rmol/bom/StatAggregatorStructList.hpp \ - $(top_srcdir)/rmol/bom/StudyStatManager.hpp + $(top_srcdir)/rmol/bom/StudyStatManager.hpp \ + $(top_srcdir)/rmol/bom/SellupProbabilityCalculator.hpp \ + $(top_srcdir)/rmol/bom/QEquivalentBookingCalculator.hpp bom_cc_sources = $(top_srcdir)/rmol/bom/BomAbstract.cpp \ $(top_srcdir)/rmol/bom/Bucket.cpp \ $(top_srcdir)/rmol/bom/BucketHolder.cpp \ @@ -40,5 +42,6 @@ $(top_srcdir)/rmol/bom/DPOptimiser.cpp \ $(top_srcdir)/rmol/bom/MAForecast.cpp \ $(top_srcdir)/rmol/bom/StatAggregatorStruct.cpp \ - $(top_srcdir)/rmol/bom/StudyStatManager.cpp - + $(top_srcdir)/rmol/bom/StudyStatManager.cpp \ + $(top_srcdir)/rmol/bom/SellupProbabilityCalculator.cpp \ + $(top_srcdir)/rmol/bom/QEquivalentBookingCalculator.cpp \ No newline at end of file Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2009-08-27 08:14:53 UTC (rev 238) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-08-27 17:57:15 UTC (rev 239) @@ -8,6 +8,8 @@ #include <rmol/bom/HistoricalBooking.hpp> #include <rmol/bom/HistoricalBookingHolder.hpp> #include <rmol/bom/HistoricalBookingHolderHolder.hpp> +#include <rmol/bom/SellupProbabilityCalculator.hpp> +#include <rmol/bom/QEquivalentBookingCalculator.hpp> #include <rmol/command/Forecaster.hpp> namespace RMOL { @@ -23,52 +25,28 @@ // Get the lowest yield of the given buckets const double qYield = ioBucketHolder.getLowestAverageYield (); - // Get the number of Buckets - const double nbOfBuckets = ioBucketHolder.getSize(); - // Initialize a vector for sell-up probabilities std::vector<double> lSellupProbabilityVector; - /** Sell-up probability calculator */ // Compute sell-up probability for each bucket and store it in a vector - short j = 0; - for (ioBucketHolder.begin(); - ioBucketHolder.hasNotReachedEnd(); - ioBucketHolder.iterate()) { - Bucket& lCurrentBucket = ioBucketHolder.getCurrentBucket(); - const double lYield = lCurrentBucket.getAverageYield(); - const double probSellup = - exp(-iSellupFactorHolder.at(j) *lYield/qYield); - lSellupProbabilityVector.push_back(probSellup); - j++; - } + SellupProbabilityCalculator::calculateSellupProbability + (ioBucketHolder, qYield, iSellupFactorHolder, lSellupProbabilityVector); -// /** Q-equivqlent booking calculator */ -// // Compute total Q-equivalent bookings -// for (int j = 0; -// j < iHistoricalBookingHolderHolder.getNumberOfSimilarFlights(); -// j++) { + // Compute total Q-equivalent bookings + QEquivalentBookingCalculator::calculateQEquivalentBooking + (iHistoricalBookingHolderHolder, + lSellupProbabilityVector, + oQEquivalentBookingsPerSimilarFlight); + } -// HistoricalBookingHolder& lHistoricalBookingHolder = -// iHistoricalBookingHolderHolder.at(j); + // ////////////////////////////////////////////////////////////////////// + void Forecaster::demandForecastByQForecasting () { + // qEquivalentBookingCalculation + // (BucketHolder& ioBucketHolder, + // SellupFactorHolder_T& iSellupFactorHolder, + // HistoricalBookingHolderHolder& iHistoricalBookingHolderHolder, + // HolderOfQEquivalentBookingsPerSimilarFlight_T& + // oQEquivalentBookingsPerSimilarFlight); -// double qEquivqlentBooking = 0.0; -// for (short k = 0; k < nbOfBuckets; k++) { -// HistoricalBooking& lHistoricalBooking = -// lCurrentHistoricalBookingVector.getHistoricalBooking(k); -// const double& lHBValue = lHistoricalBooking.getNumberOfBookings(); -// qEquivqlentBooking = qEquivqlentBooking + -// lHBValue * lSellupProbabilityVector[k]; -// } - -// oQEquivalentBookingsPerSimilarFlight.push_back(qEquivqlentBooking); -// } - -// // SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} -// // where -// // ProbSellup_{bucket i} = -// // EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) - } - } Modified: trunk/rmol/rmol/command/Forecaster.hpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.hpp 2009-08-27 08:14:53 UTC (rev 238) +++ trunk/rmol/rmol/command/Forecaster.hpp 2009-08-27 17:57:15 UTC (rev 239) @@ -6,7 +6,7 @@ // ////////////////////////////////////////////////////////////////////// // RMOL #include <rmol/RMOL_Types.hpp> -#include <rmol/bom/HistoricalBookingHolderHolder.hpp> + namespace RMOL { /** Forward declarations. */ @@ -38,6 +38,12 @@ SellupFactorHolder_T&, HistoricalBookingHolderHolder&, HolderOfQEquivalentBookingsPerSimilarFlight_T&); + + /** A forecasting method developed by Belobaba and Hopperstad: + Algorithms for Revenue Management in Unrestricted Fare Markets, + AGIFORS, Auckland, New Zealand, Jan 2004 + */ + static void demandForecastByQForecasting (); }; } #endif // __RMOL_COMMAND_FORECASTER_HPP Added: trunk/rmol/rmol/command/Unconstrainer.cpp =================================================================== --- trunk/rmol/rmol/command/Unconstrainer.cpp (rev 0) +++ trunk/rmol/rmol/command/Unconstrainer.cpp 2009-08-27 17:57:15 UTC (rev 239) @@ -0,0 +1,20 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL +#include <rmol/command/Unconstrainer.hpp> +// #include <rmol/bom/Bucket.hpp> +// #include <rmol/bom/BucketHolder.hpp> +// #include <rmol/bom/HistoricalBooking.hpp> +// #include <rmol/bom/HistoricalBookingHolder.hpp> +// #include <rmol/bom/HistoricalBookingHolderHolder.hpp> + + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + void Unconstrainer::demandUnconstrainByExpectationMaximization () { } + + // ////////////////////////////////////////////////////////////////////// + +} Added: trunk/rmol/rmol/command/Unconstrainer.hpp =================================================================== --- trunk/rmol/rmol/command/Unconstrainer.hpp (rev 0) +++ trunk/rmol/rmol/command/Unconstrainer.hpp 2009-08-27 17:57:15 UTC (rev 239) @@ -0,0 +1,28 @@ +#ifndef __RMOL_COMMAND_UNCONSTRAINER_HPP +#define __RMOL_COMMAND_UNCONSTRAINER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL +#include <rmol/RMOL_Types.hpp> + +namespace RMOL { + + /** Forward declarations. */ + class BucketHolder; + struct HistoricalBookingHolderHolder; + + /** Class wrapping the principal unconstraining algorithms and + some accessory algorithms. */ + class Unconstrainer { + public: + + /** A sensored-demand unconstraining method based on + Expectation Maximization algorithm.<br> + Reference: K.T. Talluri and G.Van Ryzin, + The Theory and Practice of Revenue Management. */ + static void demandUnconstrainByExpectationMaximization (); + }; +} +#endif // __RMOL_COMMAND_UNCONSTRAINER_HPP Modified: trunk/rmol/rmol/command/sources.mk =================================================================== --- trunk/rmol/rmol/command/sources.mk 2009-08-27 08:14:53 UTC (rev 238) +++ trunk/rmol/rmol/command/sources.mk 2009-08-27 17:57:15 UTC (rev 239) @@ -1,6 +1,8 @@ cmd_h_sources = $(top_srcdir)/rmol/command/FileMgr.hpp \ $(top_srcdir)/rmol/command/Optimiser.hpp \ + $(top_srcdir)/rmol/command/Unconstrainer.hpp \ $(top_srcdir)/rmol/command/Forecaster.hpp cmd_cc_sources = $(top_srcdir)/rmol/command/FileMgr.cpp \ $(top_srcdir)/rmol/command/Optimiser.cpp \ + $(top_srcdir)/rmol/command/Unconstrainer.cpp \ $(top_srcdir)/rmol/command/Forecaster.cpp \ No newline at end of file Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-08-27 08:14:53 UTC (rev 238) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2009-08-27 17:57:15 UTC (rev 239) @@ -17,6 +17,7 @@ #include <rmol/bom/StudyStatManager.hpp> #include <rmol/factory/FacRmolServiceContext.hpp> #include <rmol/command/Optimiser.hpp> +#include <rmol/command/Forecaster.hpp> #include <rmol/service/RMOL_ServiceContext.hpp> #include <rmol/service/Logger.hpp> #include <rmol/RMOL_Service.hpp> @@ -426,5 +427,33 @@ // Fill up booking vector oBucketHolder_ptr->fillup (ioBookingLimitVector); } + + // /////////////////////////////////////////////////////////////////////// + void demandUnconstrainingByExpectationMaximization () { + + // DEBUG + std::ostringstream logStream; + logStream << "Testing demand unconstraining by Expectation Maximization"; + RMOL_LOG_DEBUG (logStream.str()); + + } + + // /////////////////////////////////////////////////////////////////////// + void RMOL_Service::demandForecastByQForecasting () { + assert (_rmolServiceContext != NULL); + const BucketHolder* oBucketHolder_ptr = _rmolServiceContext->getBucketHolder(); + assert (oBucketHolder_ptr != NULL); + + // TO-DO + Forecaster::demandForecastByQForecasting (); + + // DEBUG + RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); + + std::ostringstream logStream; + logStream << "Testing Demand Forecasting by Q-Forecasting"; + RMOL_LOG_DEBUG (logStream.str()); + + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-09-02 17:14:24
|
Revision: 240 http://rmol.svn.sourceforge.net/rmol/?rev=240&view=rev Author: dkchoe Date: 2009-09-02 17:14:10 +0000 (Wed, 02 Sep 2009) Log Message: ----------- Defined types related to forecaster: SimilarFlightsDemandList_T and ForecastedDemandParameterList_T which are respectively the input and output of a forecasting algorithm Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Forecaster.hpp trunk/rmol/rmol/command/sources.mk trunk/rmol/rmol/service/RMOL_Service.cpp Added Paths: ----------- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp Added: trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp (rev 0) +++ trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-09-02 17:14:10 UTC (rev 240) @@ -0,0 +1,26 @@ +#ifndef __RMOL_RMOL_FORECASTER_TYPES_HPP +#define __RMOL_RMOL_FORECASTER_TYPES_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <vector> +#include <map> + +namespace RMOL { + + // //////// Type definitions ///////// + + /** Define the map of a class code - segment (origine/destination) + and a vector of (unconstrained) demand of the similar flight-dates. */ + typedef std::map<std::string, std::vector<double> > + SimilarFlightsDemandList_T; + + /** Define the holder of forecasted demand parameters (mean, std. deviation) + per booking class. Each row contains [class key, [mean, s.d.]] */ + typedef std::map<std::string, std::vector<double> > + ForecastedDemandParameterList_T; + +} +#endif // __RMOL_RMOL_FORECASTER_TYPES_HPP Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2009-08-27 17:57:15 UTC (rev 239) +++ trunk/rmol/rmol/RMOL_Service.hpp 2009-09-02 17:14:10 UTC (rev 240) @@ -8,6 +8,7 @@ #include <string> // RMOL #include <rmol/RMOL_Types.hpp> +#include <rmol/RMOL_FORECASTER_Types.hpp> namespace RMOL { @@ -116,8 +117,12 @@ /** Demand unconstraining by Expectation Maximization */ void demandUnconstrainingByExpectationMaximization (); + /** Demand forecast using Q-Forecasting [used in unit tests] */ + void demandForecastByQForecasting (SimilarFlightsDemandList_T&); + /** Demand forecast using Q-Forecasting */ - void demandForecastByQForecasting (); + void demandForecastByQForecasting (SimilarFlightsDemandList_T&, + ForecastedDemandParameterList_T&); private: /** Default Constructors. */ Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2009-08-27 17:57:15 UTC (rev 239) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-09-02 17:14:10 UTC (rev 240) @@ -40,13 +40,14 @@ } // ////////////////////////////////////////////////////////////////////// - void Forecaster::demandForecastByQForecasting () { - // qEquivalentBookingCalculation - // (BucketHolder& ioBucketHolder, - // SellupFactorHolder_T& iSellupFactorHolder, - // HistoricalBookingHolderHolder& iHistoricalBookingHolderHolder, - // HolderOfQEquivalentBookingsPerSimilarFlight_T& - // oQEquivalentBookingsPerSimilarFlight); + void Forecaster::demandForecastByQForecasting + (SimilarFlightsDemandList_T& iSimilarFlightsDemandList, + ForecastedDemandParameterList_T& oForecastedDemandParameterList) { + // Run Q-Forecasting algorithm + // 1. Obtain forecasted Q-eqivalent demand mean and s.d.(mu_Q, sigma_Q) + // 2. Partition to each class + // E(alpha x Q)=alpha x mu_Q, S.D.(alpha x Q) = |alpha| X sigma_Q + } } Modified: trunk/rmol/rmol/command/Forecaster.hpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.hpp 2009-08-27 17:57:15 UTC (rev 239) +++ trunk/rmol/rmol/command/Forecaster.hpp 2009-09-02 17:14:10 UTC (rev 240) @@ -6,6 +6,7 @@ // ////////////////////////////////////////////////////////////////////// // RMOL #include <rmol/RMOL_Types.hpp> +#include <rmol/RMOL_FORECASTER_Types.hpp> namespace RMOL { @@ -43,7 +44,8 @@ Algorithms for Revenue Management in Unrestricted Fare Markets, AGIFORS, Auckland, New Zealand, Jan 2004 */ - static void demandForecastByQForecasting (); + static void demandForecastByQForecasting (SimilarFlightsDemandList_T&, + ForecastedDemandParameterList_T&); }; } #endif // __RMOL_COMMAND_FORECASTER_HPP Modified: trunk/rmol/rmol/command/sources.mk =================================================================== --- trunk/rmol/rmol/command/sources.mk 2009-08-27 17:57:15 UTC (rev 239) +++ trunk/rmol/rmol/command/sources.mk 2009-09-02 17:14:10 UTC (rev 240) @@ -4,5 +4,5 @@ $(top_srcdir)/rmol/command/Forecaster.hpp cmd_cc_sources = $(top_srcdir)/rmol/command/FileMgr.cpp \ $(top_srcdir)/rmol/command/Optimiser.cpp \ - $(top_srcdir)/rmol/command/Unconstrainer.cpp \ - $(top_srcdir)/rmol/command/Forecaster.cpp \ No newline at end of file + $(top_srcdir)/rmol/command/Unconstrainer.cpp \ + $(top_srcdir)/rmol/command/Forecaster.cpp \ No newline at end of file Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-08-27 17:57:15 UTC (rev 239) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2009-09-02 17:14:10 UTC (rev 240) @@ -439,21 +439,61 @@ } // /////////////////////////////////////////////////////////////////////// - void RMOL_Service::demandForecastByQForecasting () { - assert (_rmolServiceContext != NULL); - const BucketHolder* oBucketHolder_ptr = _rmolServiceContext->getBucketHolder(); - assert (oBucketHolder_ptr != NULL); + void RMOL_Service::demandForecastByQForecasting + (SimilarFlightsDemandList_T& iSimilarFlightsDemandList) { +// assert (_rmolServiceContext != NULL); +// const BucketHolder* oBucketHolder_ptr = _rmolServiceContext->getBucketHolder(); +// assert (oBucketHolder_ptr != NULL); - // TO-DO - Forecaster::demandForecastByQForecasting (); + // Declare forecaster output holder + ForecastedDemandParameterList_T lForecastedDemandParameterList; + + // Make an element of a ForecastedDemandParameterList_T. It is needed + // to use the reference of lForecastedDemandParameterList as an + // input argument. + double lMean = 0.0; + double lSD = 0.0; + std::vector<double> lForecastedDemandParameters; + lForecastedDemandParameters.push_back(lMean); + lForecastedDemandParameters.push_back(lSD); + + // Instantiate the forecaster output holder with the element created above + lForecastedDemandParameterList.insert + (std::map<std::string, std::vector<double> >:: + value_type("YNCELHR", lForecastedDemandParameters)); + + ForecastedDemandParameterList_T& lForecastedDemandParameterList_ref = + lForecastedDemandParameterList; + + // Run Q-Forecasting algorithm + Forecaster::demandForecastByQForecasting (iSimilarFlightsDemandList, + lForecastedDemandParameterList_ref); // DEBUG - RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); - +// RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); std::ostringstream logStream; logStream << "Testing Demand Forecasting by Q-Forecasting"; RMOL_LOG_DEBUG (logStream.str()); } + + // /////////////////////////////////////////////////////////////////////// + void RMOL_Service::demandForecastByQForecasting + (SimilarFlightsDemandList_T& iSimilarFlightsDemandList, + ForecastedDemandParameterList_T& oForecastedDemandParameterList) { + assert (_rmolServiceContext != NULL); + const BucketHolder* oBucketHolder_ptr = + _rmolServiceContext->getBucketHolder(); + assert (oBucketHolder_ptr != NULL); + + // TO-DO + Forecaster::demandForecastByQForecasting (iSimilarFlightsDemandList, + oForecastedDemandParameterList); + + // Fill in the forecasted demand parameters + + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-09-16 17:26:35
|
Revision: 248 http://rmol.svn.sourceforge.net/rmol/?rev=248&view=rev Author: dkchoe Date: 2009-09-16 17:26:27 +0000 (Wed, 16 Sep 2009) Log Message: ----------- [Q-Forecaster] Merged a few BOMs into QForecaster object; Added Utility struct which should include common operations for C++ standard objects(e.g. vector) Modified Paths: -------------- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/bom/sources.mk trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Forecaster.hpp trunk/rmol/rmol/command/sources.mk trunk/rmol/rmol/service/RMOL_Service.cpp Added Paths: ----------- trunk/rmol/rmol/bom/QForecaster.cpp trunk/rmol/rmol/bom/QForecaster.hpp trunk/rmol/rmol/command/Utilities.cpp trunk/rmol/rmol/command/Utilities.hpp Removed Paths: ------------- trunk/rmol/rmol/bom/QEquivalentBookingCalculator.cpp trunk/rmol/rmol/bom/QEquivalentBookingCalculator.hpp trunk/rmol/rmol/bom/SellupProbabilityCalculator.cpp trunk/rmol/rmol/bom/SellupProbabilityCalculator.hpp Modified: trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-09-16 17:26:27 UTC (rev 248) @@ -18,9 +18,9 @@ SimilarFlightsDemandList_T; /** Define the holder of forecasted demand parameters (mean, std. deviation) - per booking class. Each row contains [class key, [mean, s.d.]] */ - typedef std::map<std::string, std::vector<double> > - ForecastedDemandParameterList_T; + per booking class. The order of the parameters corresponds to the vector + inputs resulted the parameters themselves.*/ + typedef std::vector<double> ForecastedDemandParameterList_T; /** Define a vector of fares. */ typedef std::vector<double> PriceHolder_T; Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/RMOL_Service.hpp 2009-09-16 17:26:27 UTC (rev 248) @@ -124,7 +124,8 @@ /** Demand forecast using Q-Forecasting */ void demandForecastByQForecasting (ForecastedDemandParameterList_T, HistoricalDataHolderHolder_T&, - PriceHolder_T&); + PriceHolder_T&, + SellupFactorHolder_T&); private: /** Default Constructors. */ Deleted: trunk/rmol/rmol/bom/QEquivalentBookingCalculator.cpp =================================================================== --- trunk/rmol/rmol/bom/QEquivalentBookingCalculator.cpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/bom/QEquivalentBookingCalculator.cpp 2009-09-16 17:26:27 UTC (rev 248) @@ -1,49 +0,0 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <cmath> -// RMOL Bom -#include <rmol/bom/Bucket.hpp> -#include <rmol/bom/BucketHolder.hpp> -#include <rmol/bom/QEquivalentBookingCalculator.hpp> - -namespace RMOL { - - // ////////////////////////////////////////////////////////////////////// - void QEquivalentBookingCalculator::calculateQEquivalentBooking - (HistoricalBookingHolderHolder& iHistoricalBookingHolderHolder, - SellupProbabilityVector_T& iSellupProbabilityVector, - HolderOfQEquivalentBookingsPerSimilarFlight_T& - oHolderOfQEquivalentBookingsPerSimilarFlight) { - -// // Get the number of Buckets -// const double nbOfBuckets = ioBucketHolder.getSize(); - -// for (int j = 0; -// j < iHistoricalBookingHolderHolder.getNumberOfSimilarFlights(); -// j++) { - -// HistoricalBookingHolder& lHistoricalBookingHolder = -// iHistoricalBookingHolderHolder.at(j); - -// double qEquivalentBooking = 0.0; -// for (short k = 0; k < nbOfBuckets; k++) { -// HistoricalBooking& lHistoricalBooking = -// lCurrentHistoricalBookingVector.getHistoricalBooking(k); -// const double& lHBValue = lHistoricalBooking.getNumberOfBookings(); -// qEquivqlentBooking = qEquivqlentBooking + -// lHBValue * lSellupProbabilityVector[k]; -// } - -// oQEquivalentBookingsPerSimilarFlight.push_back(qEquivqlentBooking); -// } - -// // SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} -// // where -// // ProbSellup_{bucket i} = -// // EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) - - - } -} Deleted: trunk/rmol/rmol/bom/QEquivalentBookingCalculator.hpp =================================================================== --- trunk/rmol/rmol/bom/QEquivalentBookingCalculator.hpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/bom/QEquivalentBookingCalculator.hpp 2009-09-16 17:26:27 UTC (rev 248) @@ -1,33 +0,0 @@ -#ifndef __RMOL_BOM_QEQUIVQLENTBOOKINGCALCULATOR_HPP -#define __RMOL_BOM_QEQUIVQLENTBOOKINGCALCULATOR_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// RMOL Bom -#include <rmol/bom/BomAbstract.hpp> -#include <rmol/RMOL_Types.hpp> - -namespace RMOL { - - // Forward declaration - struct HistoricalBookingHolderHolder; - - /** Accessary Class for Sellup considered forecast methods. */ - class QEquivalentBookingCalculator : public BomAbstract { - - public: - - /** Calculate Q-equivalent bookings probability for given sell-up - probabilities.<br> - The formular was proposed by Belobaba and Hopperstad: - Algorithms for Revenue Management in Unrestricted Fare Markets, - AGIFORS, Auckland, New Zealand, Jan 2004 */ - static void calculateQEquivalentBooking - (HistoricalBookingHolderHolder&, - SellupProbabilityVector_T&, - HolderOfQEquivalentBookingsPerSimilarFlight_T&); - }; - -} -#endif // __RMOL_BOM_QEQUIVQLENTBOOKINGCALCULATOR_HPP Added: trunk/rmol/rmol/bom/QForecaster.cpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.cpp (rev 0) +++ trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-16 17:26:27 UTC (rev 248) @@ -0,0 +1,32 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cmath> +// RMOL Bom +#include <rmol/bom/Bucket.hpp> +#include <rmol/bom/BucketHolder.hpp> +#include <rmol/bom/QForecaster.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + void QForecaster::calculateSellupProbability + (BucketHolder& iBucketHolder, + const double iQYield, + const SellupFactorHolder_T& iSellupFactorHolder, + SellupProbabilityVector_T& ioSellupProbabilityVector) { + // Compute sell-up probability for each bucket and store it in a vector + short j = 0; + for (iBucketHolder.begin(); + iBucketHolder.hasNotReachedEnd(); + iBucketHolder.iterate()) { + Bucket& lCurrentBucket = iBucketHolder.getCurrentBucket(); + const double lYield = lCurrentBucket.getAverageYield(); + const double probSellup = + exp(-iSellupFactorHolder.at(j) *lYield/iQYield); + ioSellupProbabilityVector.push_back(probSellup); + j++; + } + } +} Added: trunk/rmol/rmol/bom/QForecaster.hpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.hpp (rev 0) +++ trunk/rmol/rmol/bom/QForecaster.hpp 2009-09-16 17:26:27 UTC (rev 248) @@ -0,0 +1,32 @@ +#ifndef __RMOL_BOM_QFORECASTER_HPP +#define __RMOL_BOM_QFORECASTER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL Bom +#include <rmol/bom/BomAbstract.hpp> + +namespace RMOL { + + // Forward declaration + class BucketHolder; + + /** Accessary Class for Sellup considered forecast methods. */ + class QForecaster : public BomAbstract { + + public: + + /** Calculate sell-up probability for given sell-up factor, + and yield ratio between the sell-up occurs.<br> + The formular was proposed by Belobaba and Hopperstad: + Algorithms for Revenue Management in Unrestricted Fare Markets, + AGIFORS, Auckland, New Zealand, Jan 2004 */ + static void calculateSellupProbability (BucketHolder&, + const double iQYield, + const SellupFactorHolder_T&, + SellupProbabilityVector_T&); + }; + +} +#endif // __RMOL_BOM_QFORECASTER_HPP Deleted: trunk/rmol/rmol/bom/SellupProbabilityCalculator.cpp =================================================================== --- trunk/rmol/rmol/bom/SellupProbabilityCalculator.cpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/bom/SellupProbabilityCalculator.cpp 2009-09-16 17:26:27 UTC (rev 248) @@ -1,32 +0,0 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <cmath> -// RMOL Bom -#include <rmol/bom/Bucket.hpp> -#include <rmol/bom/BucketHolder.hpp> -#include <rmol/bom/SellupProbabilityCalculator.hpp> - -namespace RMOL { - - // ////////////////////////////////////////////////////////////////////// - void SellupProbabilityCalculator::calculateSellupProbability - (BucketHolder& iBucketHolder, - const double iQYield, - const SellupFactorHolder_T& iSellupFactorHolder, - SellupProbabilityVector_T& ioSellupProbabilityVector) { - // Compute sell-up probability for each bucket and store it in a vector - short j = 0; - for (iBucketHolder.begin(); - iBucketHolder.hasNotReachedEnd(); - iBucketHolder.iterate()) { - Bucket& lCurrentBucket = iBucketHolder.getCurrentBucket(); - const double lYield = lCurrentBucket.getAverageYield(); - const double probSellup = - exp(-iSellupFactorHolder.at(j) *lYield/iQYield); - ioSellupProbabilityVector.push_back(probSellup); - j++; - } - } -} Deleted: trunk/rmol/rmol/bom/SellupProbabilityCalculator.hpp =================================================================== --- trunk/rmol/rmol/bom/SellupProbabilityCalculator.hpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/bom/SellupProbabilityCalculator.hpp 2009-09-16 17:26:27 UTC (rev 248) @@ -1,32 +0,0 @@ -#ifndef __RMOL_BOM_SELLUPPROBABILITYCALCULATOR_HPP -#define __RMOL_BOM_SELLUPPROBABILITYCALCULATOR_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// RMOL Bom -#include <rmol/bom/BomAbstract.hpp> - -namespace RMOL { - - // Forward declaration - class BucketHolder; - - /** Accessary Class for Sellup considered forecast methods. */ - class SellupProbabilityCalculator : public BomAbstract { - - public: - - /** Calculate sell-up probability for given sell-up factor, - and yield ratio between the sell-up occurs.<br> - The formular was proposed by Belobaba and Hopperstad: - Algorithms for Revenue Management in Unrestricted Fare Markets, - AGIFORS, Auckland, New Zealand, Jan 2004 */ - static void calculateSellupProbability (BucketHolder&, - const double iQYield, - const SellupFactorHolder_T&, - SellupProbabilityVector_T&); - }; - -} -#endif // __RMOL_BOM_SELLUPPROBABILITYCALCULATOR_HPP Modified: trunk/rmol/rmol/bom/sources.mk =================================================================== --- trunk/rmol/rmol/bom/sources.mk 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/bom/sources.mk 2009-09-16 17:26:27 UTC (rev 248) @@ -22,8 +22,7 @@ $(top_srcdir)/rmol/bom/StatAggregatorStruct.hpp \ $(top_srcdir)/rmol/bom/StatAggregatorStructList.hpp \ $(top_srcdir)/rmol/bom/StudyStatManager.hpp \ - $(top_srcdir)/rmol/bom/SellupProbabilityCalculator.hpp \ - $(top_srcdir)/rmol/bom/QEquivalentBookingCalculator.hpp + $(top_srcdir)/rmol/bom/QForecaster.hpp bom_cc_sources = $(top_srcdir)/rmol/bom/BomAbstract.cpp \ $(top_srcdir)/rmol/bom/Bucket.cpp \ $(top_srcdir)/rmol/bom/BucketHolder.cpp \ @@ -41,5 +40,4 @@ $(top_srcdir)/rmol/bom/MAForecast.cpp \ $(top_srcdir)/rmol/bom/StatAggregatorStruct.cpp \ $(top_srcdir)/rmol/bom/StudyStatManager.cpp \ - $(top_srcdir)/rmol/bom/SellupProbabilityCalculator.cpp \ - $(top_srcdir)/rmol/bom/QEquivalentBookingCalculator.cpp \ No newline at end of file + $(top_srcdir)/rmol/bom/QForecaster.cpp \ No newline at end of file Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-09-16 17:26:27 UTC (rev 248) @@ -8,9 +8,9 @@ #include <rmol/bom/HistoricalBooking.hpp> #include <rmol/bom/HistoricalBookingHolder.hpp> #include <rmol/bom/HistoricalBookingHolderHolder.hpp> -#include <rmol/bom/SellupProbabilityCalculator.hpp> -#include <rmol/bom/QEquivalentBookingCalculator.hpp> +#include <rmol/bom/QForecaster.hpp> #include <rmol/command/Forecaster.hpp> +#include <rmol/command/Utilities.hpp> namespace RMOL { @@ -29,27 +29,41 @@ std::vector<double> lSellupProbabilityVector; // Compute sell-up probability for each bucket and store it in a vector - SellupProbabilityCalculator::calculateSellupProbability + QForecaster::calculateSellupProbability (ioBucketHolder, qYield, iSellupFactorHolder, lSellupProbabilityVector); // Compute total Q-equivalent bookings - QEquivalentBookingCalculator::calculateQEquivalentBooking - (iHistoricalBookingHolderHolder, - lSellupProbabilityVector, - oQEquivalentBookingsPerSimilarFlight); + // QEquivalentBookingCalculator::calculateQEquivalentBooking + // (iHistoricalBookingHolderHolder, + // lSellupProbabilityVector, + // oQEquivalentBookingsPerSimilarFlight); } // ////////////////////////////////////////////////////////////////////// void Forecaster::demandForecastByQForecasting (ForecastedDemandParameterList_T oForecastedDemandParameterList, HistoricalDataHolderHolder_T& iHistoricalDataHolderHolder, - PriceHolder_T& iPriceHolder) { + PriceHolder_T& iPriceHolder, + SellupFactorHolder_T& iSellupFactorHolder) { // Run Q-Forecasting algorithm // 1. Obtain forecasted Q-eqivalent demand mean and s.d.(mu_Q, sigma_Q) // 2. Partition to each class // E(alpha x Q)=alpha x mu_Q, S.D.(alpha x Q) = |alpha| X sigma_Q - //qEquivalentDemandCalculation(); + // TODO: Find the class with the lowest yield + const double iQYield = Utilities::minimumElementOfAVector(iPriceHolder); + // // TODO: Initialize a vector for sell-up probabilities + // std::vector<double> lSellupProbabilityVector; + + // // TODO: Compute sell-up probability for each class/bucket & store it in a vector + // QForecaster::calculateSellupProbability + // (lSellupProbabilityVector, iQYield, iPriceHolder, iSellupFactorHolder); + + // // TODO: Q-equivalent demand calculation + // QForecaster::calculateQEquivalentDemandParametersAndPartition + // (oForecastedDemandParameterList, + // iHistoricalDataHolderHolder, lSellupProbabilityVector); + } } Modified: trunk/rmol/rmol/command/Forecaster.hpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.hpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/command/Forecaster.hpp 2009-09-16 17:26:27 UTC (rev 248) @@ -53,20 +53,23 @@ where ProbSellup_{bucket i} = EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) - static void qEquivalentBookingCalculation - (BucketHolder&, - SellupFactorHolder_T&, - HistoricalBookingHolderHolder&, + + static void qEquivalentDemandCalculation + (SellupFactorHolder_T&, + HistoricalDataHolderHolder&, HolderOfQEquivalentDemandsPerSimilarFlight_T&); - */ + */ /** A forecasting method developed by Belobaba and Hopperstad: Algorithms for Revenue Management in Unrestricted Fare Markets, AGIFORS, Auckland, New Zealand, Jan 2004 - */ + NOTES: Inputs are supposed to be appropriately ordered so that + i-th element of the PriceHolder is the price associated to the + i-th element of the HistoricalDataHolderHolder. */ static void demandForecastByQForecasting (ForecastedDemandParameterList_T, HistoricalDataHolderHolder_T&, - PriceHolder_T&); + PriceHolder_T&, + SellupFactorHolder_T&); }; } #endif // __RMOL_COMMAND_FORECASTER_HPP Added: trunk/rmol/rmol/command/Utilities.cpp =================================================================== --- trunk/rmol/rmol/command/Utilities.cpp (rev 0) +++ trunk/rmol/rmol/command/Utilities.cpp 2009-09-16 17:26:27 UTC (rev 248) @@ -0,0 +1,23 @@ + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +//STL +#include <algorithm> +#include <assert.h> +// RMOL +#include <rmol/command/Utilities.hpp> + +namespace RMOL { + + // ///////////////////////////////////////////////////////////////////// + const double Utilities::minimumElementOfAVector (std::vector<double> iVector) { + + assert(!iVector.empty()); + std::vector<double>::iterator pos = min_element (iVector.begin(), + iVector.end()); + return *pos; + + } + +} Added: trunk/rmol/rmol/command/Utilities.hpp =================================================================== --- trunk/rmol/rmol/command/Utilities.hpp (rev 0) +++ trunk/rmol/rmol/command/Utilities.hpp 2009-09-16 17:26:27 UTC (rev 248) @@ -0,0 +1,17 @@ +#ifndef __RMOL_COMMAND_UTILITIES_HPP +#define __RMOL_COMMAND_UTILITIES_HPP +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <vector> + +namespace RMOL { + + struct Utilities { + static const double minimumElementOfAVector(std::vector<double>); + }; + +} + +#endif // __RMOL_COMMAND_UTILITIES_HPP Modified: trunk/rmol/rmol/command/sources.mk =================================================================== --- trunk/rmol/rmol/command/sources.mk 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/command/sources.mk 2009-09-16 17:26:27 UTC (rev 248) @@ -1,8 +1,10 @@ cmd_h_sources = $(top_srcdir)/rmol/command/FileMgr.hpp \ $(top_srcdir)/rmol/command/Optimiser.hpp \ $(top_srcdir)/rmol/command/Unconstrainer.hpp \ - $(top_srcdir)/rmol/command/Forecaster.hpp + $(top_srcdir)/rmol/command/Forecaster.hpp \ + $(top_srcdir)/rmol/command/Utilities.hpp cmd_cc_sources = $(top_srcdir)/rmol/command/FileMgr.cpp \ $(top_srcdir)/rmol/command/Optimiser.cpp \ $(top_srcdir)/rmol/command/Unconstrainer.cpp \ - $(top_srcdir)/rmol/command/Forecaster.cpp \ No newline at end of file + $(top_srcdir)/rmol/command/Forecaster.cpp \ + $(top_srcdir)/rmol/command/Utilities.cpp \ No newline at end of file Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-09-15 17:49:05 UTC (rev 247) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2009-09-16 17:26:27 UTC (rev 248) @@ -480,7 +480,8 @@ void RMOL_Service::demandForecastByQForecasting (ForecastedDemandParameterList_T oForecastedDemandParameterList, HistoricalDataHolderHolder_T& iHistoricalDataHolderHolder, - PriceHolder_T& iPriceHolder) { + PriceHolder_T& iPriceHolder, + SellupFactorHolder_T& iSellupFactorHolder) { // assert (_rmolServiceContext != NULL); // const BucketHolder* oBucketHolder_ptr = // _rmolServiceContext->getBucketHolder(); @@ -489,7 +490,8 @@ // TO-DO Forecaster::demandForecastByQForecasting (oForecastedDemandParameterList, iHistoricalDataHolderHolder, - iPriceHolder); + iPriceHolder, + iSellupFactorHolder); // Fill in the forecasted demand parameters This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-09-17 16:05:24
|
Revision: 251 http://rmol.svn.sourceforge.net/rmol/?rev=251&view=rev Author: dkchoe Date: 2009-09-17 16:05:07 +0000 (Thu, 17 Sep 2009) Log Message: ----------- [Q-Forecaster] Added sell-probability calculator; Updated Q-eq demand calculator (to be continued) Modified Paths: -------------- trunk/rmol/rmol/bom/QForecaster.cpp trunk/rmol/rmol/bom/QForecaster.hpp trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Utilities.cpp trunk/rmol/rmol/command/Utilities.hpp Modified: trunk/rmol/rmol/bom/QForecaster.cpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-17 16:03:43 UTC (rev 250) +++ trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-17 16:05:07 UTC (rev 251) @@ -7,6 +7,7 @@ #include <rmol/bom/Bucket.hpp> #include <rmol/bom/BucketHolder.hpp> #include <rmol/bom/QForecaster.hpp> +#include <rmol/command/Utilities.hpp> namespace RMOL { @@ -29,4 +30,44 @@ j++; } } + + // ////////////////////////////////////////////////////////////////////// + void QForecaster::calculateSellupProbability + (SellupProbabilityVector_T& ioSellupProbabilityVector, const double iQYield, + PriceHolder_T& iPriceHolder, SellupFactorHolder_T& iSellupFactorHolder) { + ioSellupProbabilityVector.clear(); + for (unsigned short j=0; j < iPriceHolder.size(); j++){ + const double lYield = iPriceHolder.at(j); + const double probSellup = + exp(-iSellupFactorHolder.at(j) *lYield/iQYield); + ioSellupProbabilityVector.push_back(probSellup); + } + } + + // ////////////////////////////////////////////////////////////////////// + void QForecaster::calculateQEquivalentDemandParametersAndPartition + (ForecastedDemandParameterList_T oForecastedDemandParameterList, + HistoricalDataHolderHolder_T& iHistoricalDataHolderHolder, + SellupProbabilityVector_T& lSellupProbabilityVector) { + // 1. Calculate Q-equivalent demand parameters + // Initialize a holder for Q-equivalent Demands + std::vector<double> lQEquivalentDemandHolder + (lSellupProbabilityVector.size(), 0); + + for (unsigned int j = 0; j < iHistoricalDataHolderHolder.size(); j++) { + // Retrieve HistoricalDataHolder which are the data of the same product + // over different dates + std::vector<double>& lHistoricalDataHolder = + iHistoricalDataHolderHolder.at(j); + double lSellupProbability = lSellupProbabilityVector.at(j); + Utilities::MultiplyAValueToAVector (lHistoricalDataHolder, + 1/lSellupProbability); + // TODO: Collect historical data by date + Utilities::AddTwoVectors(lQEquivalentDemandHolder, lHistoricalDataHolder); + } + + // 2. Partition the Q-eq demand to each class/bucket + + } + } Modified: trunk/rmol/rmol/bom/QForecaster.hpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.hpp 2009-09-17 16:03:43 UTC (rev 250) +++ trunk/rmol/rmol/bom/QForecaster.hpp 2009-09-17 16:05:07 UTC (rev 251) @@ -6,6 +6,7 @@ // ////////////////////////////////////////////////////////////////////// // RMOL Bom #include <rmol/bom/BomAbstract.hpp> +#include <rmol/RMOL_FORECASTER_Types.hpp> namespace RMOL { @@ -26,7 +27,21 @@ const double iQYield, const SellupFactorHolder_T&, SellupProbabilityVector_T&); + + /** The same method as the above but taking price data directly + instead of through BucketHolder. */ + static void calculateSellupProbability (SellupProbabilityVector_T&, + const double iQYield, + PriceHolder_T&, + SellupFactorHolder_T&); + + /** Calculate Q-equivalent demand distribution parameters and + partition it to each class/bucket. */ + static void calculateQEquivalentDemandParametersAndPartition + (ForecastedDemandParameterList_T, + HistoricalDataHolderHolder_T&, + SellupProbabilityVector_T&); + }; - } #endif // __RMOL_BOM_QFORECASTER_HPP Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2009-09-17 16:03:43 UTC (rev 250) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-09-17 16:05:07 UTC (rev 251) @@ -50,20 +50,22 @@ // 2. Partition to each class // E(alpha x Q)=alpha x mu_Q, S.D.(alpha x Q) = |alpha| X sigma_Q - // TODO: Find the class with the lowest yield - const double iQYield = Utilities::minimumElementOfAVector(iPriceHolder); + // Find the class with the lowest yield + double lQYield; + Utilities::getMinimumElement (lQYield, iPriceHolder); - // // TODO: Initialize a vector for sell-up probabilities - // std::vector<double> lSellupProbabilityVector; + // Initialize a vector for sell-up probabilities + std::vector<double> lSellupProbabilityVector; - // // TODO: Compute sell-up probability for each class/bucket & store it in a vector - // QForecaster::calculateSellupProbability - // (lSellupProbabilityVector, iQYield, iPriceHolder, iSellupFactorHolder); + // Compute sell-up probability for each class/bucket & store it in a vector + QForecaster::calculateSellupProbability + (lSellupProbabilityVector, lQYield, iPriceHolder, iSellupFactorHolder); - // // TODO: Q-equivalent demand calculation - // QForecaster::calculateQEquivalentDemandParametersAndPartition - // (oForecastedDemandParameterList, - // iHistoricalDataHolderHolder, lSellupProbabilityVector); + // Calculate Q-equivalent demand distribution parameters and + // partition it to each class/bucket + QForecaster::calculateQEquivalentDemandParametersAndPartition + (oForecastedDemandParameterList, + iHistoricalDataHolderHolder, lSellupProbabilityVector); } } Modified: trunk/rmol/rmol/command/Utilities.cpp =================================================================== --- trunk/rmol/rmol/command/Utilities.cpp 2009-09-17 16:03:43 UTC (rev 250) +++ trunk/rmol/rmol/command/Utilities.cpp 2009-09-17 16:05:07 UTC (rev 251) @@ -4,6 +4,8 @@ // ////////////////////////////////////////////////////////////////////// //STL #include <algorithm> +#include <numeric> +#include <math.h> #include <assert.h> // RMOL #include <rmol/command/Utilities.hpp> @@ -11,13 +13,68 @@ namespace RMOL { // ///////////////////////////////////////////////////////////////////// - const double Utilities::minimumElementOfAVector (std::vector<double> iVector) { + void Utilities::getMinimumElement (double oMinValue, + std::vector<double>& iVector) { assert(!iVector.empty()); std::vector<double>::iterator pos = min_element (iVector.begin(), iVector.end()); - return *pos; + oMinValue = *pos; } + // ///////////////////////////////////////////////////////////////////// + void Utilities::getMean (double oMean, std::vector<double>& iVector) { + assert(!iVector.empty()); + double lSum = std::accumulate(iVector.begin(), iVector.end(),0); + oMean = lSum/iVector.size(); + + } + + // ///////////////////////////////////////////////////////////////////// + void Utilities::getStandardDeviation (double oSD, std::vector<double>& iVector, + double iMean) { + assert(iMean > 0); + + const unsigned int lSize = iVector.size(); + assert(lSize > 0); + + double lSD = 0; + for (unsigned int j = 0; j < lSize; j++) { + const double lElement = iVector.at(j); + lSD += (lElement - iMean) * (lElement - iMean); + } + lSD /= (lSize - 1); + oSD = sqrt(lSD); + } + + // ///////////////////////////////////////////////////////////////////// + void Utilities::AddAValueToAVector (std::vector<double>& ioVector, + double iValue){ + const unsigned int lSize = ioVector.size(); + assert(lSize > 0); + + for (unsigned int j = 0; j < lSize; j++) { + ioVector[j] = ioVector.at(j) + iValue; + } + } + + // ///////////////////////////////////////////////////////////////////// + void Utilities::MultiplyAValueToAVector (std::vector<double>& ioVector, + double iValue) { + const unsigned int lSize = ioVector.size(); + assert(lSize > 0); + + for (unsigned int j = 0; j < lSize; j++) { + ioVector[j] = ioVector.at(j) * iValue; + } + } + + // ///////////////////////////////////////////////////////////////////// + static void AddTwoVectors (std::vector<double>& ioVector, + std::vector<double>& iVector) { + // std::transform (ioVector.begin(), ioVector.end(), iVector.begin(), iVector.end(),) + } + + } Modified: trunk/rmol/rmol/command/Utilities.hpp =================================================================== --- trunk/rmol/rmol/command/Utilities.hpp 2009-09-17 16:03:43 UTC (rev 250) +++ trunk/rmol/rmol/command/Utilities.hpp 2009-09-17 16:05:07 UTC (rev 251) @@ -9,7 +9,30 @@ namespace RMOL { struct Utilities { - static const double minimumElementOfAVector(std::vector<double>); + + /** Returns the minimum element of a given vector*/ + static void getMinimumElement (double oMinValue, std::vector<double>&); + + /** Return mean for the given elements of a vector. */ + static void getMean (double oMean, std::vector<double>&); + + /** Return standard deviation for the given elements of a vector and + the precomputed mean. */ + static void getStandardDeviation (double oSD, std::vector<double>&, + double iMean); + + /** Return the input vector after adding a value. */ + static void AddAValueToAVector (std::vector<double>& ioVector, + double iValue); + + /** Return the input vector after multiplying a value. */ + static void MultiplyAValueToAVector (std::vector<double>& ioVector, + double iValue); + + /** Return an input vector after adding the other input vector. */ + static void AddTwoVectors (std::vector<double>& ioVector, + std::vector<double>& iVector); + }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-09-18 16:10:49
|
Revision: 255 http://rmol.svn.sourceforge.net/rmol/?rev=255&view=rev Author: dkchoe Date: 2009-09-18 16:10:41 +0000 (Fri, 18 Sep 2009) Log Message: ----------- Methods that compute Q-equivalent demand distribution parameters have been added. Partition to each classes are to be done; Methods that compute Q-equivalent demand distribution parameters have been added. Partition to each classes are to be done. Modified Paths: -------------- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp trunk/rmol/rmol/RMOL_Types.hpp trunk/rmol/rmol/bom/QForecaster.cpp trunk/rmol/rmol/bom/QForecaster.hpp trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Forecaster.hpp trunk/rmol/rmol/command/Utilities.cpp trunk/rmol/rmol/command/Utilities.hpp Modified: trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-09-17 16:30:38 UTC (rev 254) +++ trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-09-18 16:10:41 UTC (rev 255) @@ -30,6 +30,9 @@ /** Define vector of historical data vector*/ typedef std::vector< std::vector<double> > HistoricalDataHolderHolder_T; + + /** Define a holder for Q-equivalent demand parameters. */ + typedef std::vector<double> QEquivalentDemandParameterHolder_T; } #endif // __RMOL_RMOL_FORECASTER_TYPES_HPP Modified: trunk/rmol/rmol/RMOL_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Types.hpp 2009-09-17 16:30:38 UTC (rev 254) +++ trunk/rmol/rmol/RMOL_Types.hpp 2009-09-18 16:10:41 UTC (rev 255) @@ -88,8 +88,8 @@ // typedef std::vector<HistoricalBookingHolder> // HistoricalBookingHolderHolder_T; - /** Define the holder of Q-equivalent booking values*/ - typedef std::vector<double> HolderOfQEquivalentBookingsPerSimilarFlight_T; + // /** Define the holder of Q-equivalent booking values*/ + // typedef std::vector<double> HolderOfQEquivalentBookingsPerSimilarFlight_T; } #endif // __RMOL_RMOL_TYPES_HPP Modified: trunk/rmol/rmol/bom/QForecaster.cpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-17 16:30:38 UTC (rev 254) +++ trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-18 16:10:41 UTC (rev 255) @@ -11,63 +11,78 @@ namespace RMOL { - // ////////////////////////////////////////////////////////////////////// - void QForecaster::calculateSellupProbability - (BucketHolder& iBucketHolder, - const double iQYield, - const SellupFactorHolder_T& iSellupFactorHolder, - SellupProbabilityVector_T& ioSellupProbabilityVector) { - // Compute sell-up probability for each bucket and store it in a vector - short j = 0; - for (iBucketHolder.begin(); - iBucketHolder.hasNotReachedEnd(); - iBucketHolder.iterate()) { - Bucket& lCurrentBucket = iBucketHolder.getCurrentBucket(); - const double lYield = lCurrentBucket.getAverageYield(); - const double probSellup = - exp(-iSellupFactorHolder.at(j) *lYield/iQYield); - ioSellupProbabilityVector.push_back(probSellup); - j++; - } - } + // // ////////////////////////////////////////////////////////////////////// + // void QForecaster::calculateSellupProbability + // (BucketHolder& iBucketHolder, + // const double iQYield, + // const SellupFactorHolder_T& iSellupFactorHolder, + // SellupProbabilityVector_T& ioSellupProbabilityVector) { + // // Compute sell-up probability for each bucket and store it in a vector + // short j = 0; + // for (iBucketHolder.begin(); + // iBucketHolder.hasNotReachedEnd(); + // iBucketHolder.iterate()) { + // Bucket& lCurrentBucket = iBucketHolder.getCurrentBucket(); + // const double lYield = lCurrentBucket.getAverageYield(); + // const double probSellup = + // exp(-iSellupFactorHolder.at(j) *lYield/iQYield); + // ioSellupProbabilityVector.push_back(probSellup); + // j++; + // } + // } // ////////////////////////////////////////////////////////////////////// void QForecaster::calculateSellupProbability - (SellupProbabilityVector_T& ioSellupProbabilityVector, const double iQYield, + (SellupProbabilityVector_T* ioSellupProbabilityVector, double* iPtrQYield, PriceHolder_T& iPriceHolder, SellupFactorHolder_T& iSellupFactorHolder) { - ioSellupProbabilityVector.clear(); - for (unsigned short j=0; j < iPriceHolder.size(); j++){ + ioSellupProbabilityVector->clear(); + for (unsigned short j = 0; j < iPriceHolder.size(); j++){ const double lYield = iPriceHolder.at(j); const double probSellup = - exp(-iSellupFactorHolder.at(j) *lYield/iQYield); - ioSellupProbabilityVector.push_back(probSellup); + exp(-iSellupFactorHolder.at(j) * lYield / (*iPtrQYield)); + ioSellupProbabilityVector->push_back(probSellup); } } // ////////////////////////////////////////////////////////////////////// - void QForecaster::calculateQEquivalentDemandParametersAndPartition - (ForecastedDemandParameterList_T oForecastedDemandParameterList, + void QForecaster::calculateQEquivalentDemandParameters + (QEquivalentDemandParameterHolder_T* ioQEquivalentDemandParameterHolder, HistoricalDataHolderHolder_T& iHistoricalDataHolderHolder, - SellupProbabilityVector_T& lSellupProbabilityVector) { + SellupProbabilityVector_T* lSellupProbabilityVector) { // 1. Calculate Q-equivalent demand parameters // Initialize a holder for Q-equivalent Demands - std::vector<double> lQEquivalentDemandHolder - (lSellupProbabilityVector.size(), 0); + std::vector<double> aZeroVector (lSellupProbabilityVector->size(), 0); + std::vector<double>& lQEquivalentDemandHolder = aZeroVector; for (unsigned int j = 0; j < iHistoricalDataHolderHolder.size(); j++) { // Retrieve HistoricalDataHolder which are the data of the same product // over different dates std::vector<double>& lHistoricalDataHolder = iHistoricalDataHolderHolder.at(j); - double lSellupProbability = lSellupProbabilityVector.at(j); + double lSellupProbability = lSellupProbabilityVector->at(j); + + // Apply sellup probability to historical data Utilities::MultiplyAValueToAVector (lHistoricalDataHolder, 1/lSellupProbability); - // TODO: Collect historical data by date - Utilities::AddTwoVectors(lQEquivalentDemandHolder, lHistoricalDataHolder); + + // Collect historical data by date + Utilities::AddTwoVectors (lQEquivalentDemandHolder, + lHistoricalDataHolder); } - // 2. Partition the Q-eq demand to each class/bucket + // 2. Compute Q-equivalent demand mean and standard deviation + Utilities::getMeanAndStandardDeviation (ioQEquivalentDemandParameterHolder, + lQEquivalentDemandHolder); + } + + // ////////////////////////////////////////////////////////////////////// + void QForecaster::partitionQEquivalentDemandParameters + (ForecastedDemandParameterList_T, + QEquivalentDemandParameterHolder_T*, + SellupProbabilityVector_T*) { + } + } Modified: trunk/rmol/rmol/bom/QForecaster.hpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.hpp 2009-09-17 16:30:38 UTC (rev 254) +++ trunk/rmol/rmol/bom/QForecaster.hpp 2009-09-18 16:10:41 UTC (rev 255) @@ -18,30 +18,37 @@ public: - /** Calculate sell-up probability for given sell-up factor, - and yield ratio between the sell-up occurs.<br> - The formular was proposed by Belobaba and Hopperstad: - Algorithms for Revenue Management in Unrestricted Fare Markets, - AGIFORS, Auckland, New Zealand, Jan 2004 */ - static void calculateSellupProbability (BucketHolder&, - const double iQYield, - const SellupFactorHolder_T&, - SellupProbabilityVector_T&); + // /** Calculate sell-up probability for given sell-up factor, + // and yield ratio between the sell-up occurs.<br> + // The formular was proposed by Belobaba and Hopperstad: + // Algorithms for Revenue Management in Unrestricted Fare Markets, + // AGIFORS, Auckland, New Zealand, Jan 2004 */ + // static void calculateSellupProbability (BucketHolder&, + // const double iQYield, + // const SellupFactorHolder_T&, + // SellupProbabilityVector_T&); /** The same method as the above but taking price data directly instead of through BucketHolder. */ - static void calculateSellupProbability (SellupProbabilityVector_T&, - const double iQYield, + static void calculateSellupProbability (SellupProbabilityVector_T*, + double* iPtrQYield, PriceHolder_T&, SellupFactorHolder_T&); /** Calculate Q-equivalent demand distribution parameters and partition it to each class/bucket. */ - static void calculateQEquivalentDemandParametersAndPartition - (ForecastedDemandParameterList_T, - HistoricalDataHolderHolder_T&, - SellupProbabilityVector_T&); + static void calculateQEquivalentDemandParameters + (QEquivalentDemandParameterHolder_T*, + HistoricalDataHolderHolder_T&, + SellupProbabilityVector_T*); + /** Calculate Q-equivalent demand distribution parameters and + partition it to each class/bucket. */ + static void partitionQEquivalentDemandParameters + (ForecastedDemandParameterList_T, + QEquivalentDemandParameterHolder_T*, + SellupProbabilityVector_T*); + }; } #endif // __RMOL_BOM_QFORECASTER_HPP Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2009-09-17 16:30:38 UTC (rev 254) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-09-18 16:10:41 UTC (rev 255) @@ -14,30 +14,30 @@ namespace RMOL { - // ////////////////////////////////////////////////////////////////////// - void Forecaster::qEquivalentBookingCalculation - (BucketHolder& ioBucketHolder, - SellupFactorHolder_T& iSellupFactorHolder, - HistoricalBookingHolderHolder& iHistoricalBookingHolderHolder, - HolderOfQEquivalentBookingsPerSimilarFlight_T& - oQEquivalentBookingsPerSimilarFlight){ + // // ////////////////////////////////////////////////////////////////////// + // void Forecaster::qEquivalentBookingCalculation + // (BucketHolder& ioBucketHolder, + // SellupFactorHolder_T& iSellupFactorHolder, + // HistoricalBookingHolderHolder& iHistoricalBookingHolderHolder, + // HolderOfQEquivalentBookingsPerSimilarFlight_T& + // oQEquivalentBookingsPerSimilarFlight){ - // Get the lowest yield of the given buckets - const double qYield = ioBucketHolder.getLowestAverageYield (); + // // Get the lowest yield of the given buckets + // const double qYield = ioBucketHolder.getLowestAverageYield (); - // Initialize a vector for sell-up probabilities - std::vector<double> lSellupProbabilityVector; + // // Initialize a vector for sell-up probabilities + // std::vector<double> lSellupProbabilityVector; - // Compute sell-up probability for each bucket and store it in a vector - QForecaster::calculateSellupProbability - (ioBucketHolder, qYield, iSellupFactorHolder, lSellupProbabilityVector); + // // Compute sell-up probability for each bucket and store it in a vector + // QForecaster::calculateSellupProbability + // (ioBucketHolder, qYield, iSellupFactorHolder, lSellupProbabilityVector); - // Compute total Q-equivalent bookings - // QEquivalentBookingCalculator::calculateQEquivalentBooking - // (iHistoricalBookingHolderHolder, - // lSellupProbabilityVector, - // oQEquivalentBookingsPerSimilarFlight); - } + // // Compute total Q-equivalent bookings + // // QEquivalentBookingCalculator::calculateQEquivalentBooking + // // (iHistoricalBookingHolderHolder, + // // lSellupProbabilityVector, + // // oQEquivalentBookingsPerSimilarFlight); + // } // ////////////////////////////////////////////////////////////////////// void Forecaster::demandForecastByQForecasting @@ -51,21 +51,29 @@ // E(alpha x Q)=alpha x mu_Q, S.D.(alpha x Q) = |alpha| X sigma_Q // Find the class with the lowest yield - double lQYield; - Utilities::getMinimumElement (lQYield, iPriceHolder); + double* ptrQYield; + Utilities::getMinimumElement (ptrQYield, iPriceHolder); - // Initialize a vector for sell-up probabilities - std::vector<double> lSellupProbabilityVector; + // Initialize a holder for sell-up probabilities + SellupProbabilityVector_T* lSellupProbabilityVector; // Compute sell-up probability for each class/bucket & store it in a vector QForecaster::calculateSellupProbability - (lSellupProbabilityVector, lQYield, iPriceHolder, iSellupFactorHolder); + (lSellupProbabilityVector, ptrQYield, iPriceHolder, iSellupFactorHolder); + // Initialize a holder for Q-equivalent Demand Parameters + QEquivalentDemandParameterHolder_T* lQEquivalentDemandParameterHolder; + + // Calculate Q-equivalent demand distribution parameters. + QForecaster::calculateQEquivalentDemandParameters + (lQEquivalentDemandParameterHolder, iHistoricalDataHolderHolder, + lSellupProbabilityVector); + // Calculate Q-equivalent demand distribution parameters and // partition it to each class/bucket - QForecaster::calculateQEquivalentDemandParametersAndPartition - (oForecastedDemandParameterList, - iHistoricalDataHolderHolder, lSellupProbabilityVector); + QForecaster::partitionQEquivalentDemandParameters + (oForecastedDemandParameterList, lQEquivalentDemandParameterHolder, + lSellupProbabilityVector); } } Modified: trunk/rmol/rmol/command/Forecaster.hpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.hpp 2009-09-17 16:30:38 UTC (rev 254) +++ trunk/rmol/rmol/command/Forecaster.hpp 2009-09-18 16:10:41 UTC (rev 255) @@ -11,54 +11,53 @@ namespace RMOL { /** Forward declarations. */ - class BucketHolder; - struct HistoricalBookingHolderHolder; - // class StudyStatManager; + // // class BucketHolder; + // // struct HistoricalBookingHolderHolder; /** Class wrapping the principal forecasting algorithms and some accessory algorithms for demand forecasting. */ class Forecaster { public: - /** - An accessory algorithm for demand forecasting. + // // /** + // // An accessory algorithm for demand forecasting. - Calculate Q-equivalent bookings for the given group of - classes/buckets/fare points using the given - sell-up factors. + // // Calculate Q-equivalent bookings for the given group of + // // classes/buckets/fare points using the given + // // sell-up factors. - Q-equivalent bookings are, by definition, + // // Q-equivalent bookings are, by definition, - SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} - where - ProbSellup_{bucket i} = - EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) - */ - static void qEquivalentBookingCalculation - (BucketHolder&, - SellupFactorHolder_T&, - HistoricalBookingHolderHolder&, - HolderOfQEquivalentBookingsPerSimilarFlight_T&); + // // SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} + // // where + // // ProbSellup_{bucket i} = + // // EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) + // // */ + // // static void qEquivalentBookingCalculation + // // (BucketHolder&, + // // SellupFactorHolder_T&, + // // HistoricalBookingHolderHolder&, + // // HolderOfQEquivalentBookingsPerSimilarFlight_T&); - /** - An accessory algorithm for demand forecasting. + // /** + // An accessory algorithm for demand forecasting. - Calculate Q-equivalent demands for the given group of - classes/buckets/fare points using the given - sell-up factors. + // Calculate Q-equivalent demands for the given group of + // classes/buckets/fare points using the given + // sell-up factors. - Q-equivalent demands are, by definition, + // Q-equivalent demands are, by definition, - SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} - where - ProbSellup_{bucket i} = - EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) + // SUM_{buckets} histBooking_{bucket i} / ProbSellup_{bucket i} + // where + // ProbSellup_{bucket i} = + // EXP(-sellupfactor*(yield_{bucket i}/lowest yield_{buckets})) - static void qEquivalentDemandCalculation - (SellupFactorHolder_T&, - HistoricalDataHolderHolder&, - HolderOfQEquivalentDemandsPerSimilarFlight_T&); - */ + // static void qEquivalentDemandCalculation + // (SellupFactorHolder_T&, + // HistoricalDataHolderHolder&, + // HolderOfQEquivalentDemandsPerSimilarFlight_T&); + // */ /** A forecasting method developed by Belobaba and Hopperstad: Algorithms for Revenue Management in Unrestricted Fare Markets, Modified: trunk/rmol/rmol/command/Utilities.cpp =================================================================== --- trunk/rmol/rmol/command/Utilities.cpp 2009-09-17 16:30:38 UTC (rev 254) +++ trunk/rmol/rmol/command/Utilities.cpp 2009-09-18 16:10:41 UTC (rev 255) @@ -7,24 +7,25 @@ #include <numeric> #include <math.h> #include <assert.h> +#include <functional> // RMOL #include <rmol/command/Utilities.hpp> namespace RMOL { // ///////////////////////////////////////////////////////////////////// - void Utilities::getMinimumElement (double oMinValue, + void Utilities::getMinimumElement (double* oMinValue, std::vector<double>& iVector) { assert(!iVector.empty()); std::vector<double>::iterator pos = min_element (iVector.begin(), iVector.end()); - oMinValue = *pos; + *oMinValue = *pos; } // ///////////////////////////////////////////////////////////////////// - void Utilities::getMean (double oMean, std::vector<double>& iVector) { + void Utilities::getMean (double& oMean, std::vector<double>& iVector) { assert(!iVector.empty()); double lSum = std::accumulate(iVector.begin(), iVector.end(),0); oMean = lSum/iVector.size(); @@ -32,8 +33,9 @@ } // ///////////////////////////////////////////////////////////////////// - void Utilities::getStandardDeviation (double oSD, std::vector<double>& iVector, - double iMean) { + void Utilities::getStandardDeviation (double& oSD, + std::vector<double>& iVector, + double& iMean) { assert(iMean > 0); const unsigned int lSize = iVector.size(); @@ -49,8 +51,31 @@ } // ///////////////////////////////////////////////////////////////////// + void Utilities::getMeanAndStandardDeviation (std::vector<double>* ioMean_SD, + std::vector<double>& iVector) { + const unsigned int lSize = iVector.size(); + assert(lSize > 0); + + ioMean_SD->clear(); + + // Mean + double lSum = std::accumulate(iVector.begin(), iVector.end(), 0); + double lMean = lSum/lSize; + ioMean_SD->push_back(lMean); + + //Standard Deviation + double lSD = 0; + for (unsigned int j = 0; j < lSize; j++) { + const double lDeviation = iVector.at(j); + lSD += lDeviation * lDeviation; + } + lSD /= (lSize - 1); + ioMean_SD->push_back(sqrt(lSD)); + } + + // ///////////////////////////////////////////////////////////////////// void Utilities::AddAValueToAVector (std::vector<double>& ioVector, - double iValue){ + double iValue){ const unsigned int lSize = ioVector.size(); assert(lSize > 0); @@ -71,10 +96,12 @@ } // ///////////////////////////////////////////////////////////////////// - static void AddTwoVectors (std::vector<double>& ioVector, + void Utilities::AddTwoVectors (std::vector<double>& ioVector, std::vector<double>& iVector) { - // std::transform (ioVector.begin(), ioVector.end(), iVector.begin(), iVector.end(),) + std::transform (ioVector.begin(), ioVector.end(), + iVector.begin(), + ioVector.begin(), + std::plus<double>()); } - } Modified: trunk/rmol/rmol/command/Utilities.hpp =================================================================== --- trunk/rmol/rmol/command/Utilities.hpp 2009-09-17 16:30:38 UTC (rev 254) +++ trunk/rmol/rmol/command/Utilities.hpp 2009-09-18 16:10:41 UTC (rev 255) @@ -11,16 +11,20 @@ struct Utilities { /** Returns the minimum element of a given vector*/ - static void getMinimumElement (double oMinValue, std::vector<double>&); + static void getMinimumElement (double* oMinValue, std::vector<double>&); /** Return mean for the given elements of a vector. */ - static void getMean (double oMean, std::vector<double>&); + static void getMean (double& oMean, std::vector<double>&); /** Return standard deviation for the given elements of a vector and - the precomputed mean. */ - static void getStandardDeviation (double oSD, std::vector<double>&, - double iMean); + precomputed mean. */ + static void getStandardDeviation (double& oSD, std::vector<double>&, + double& iMean); + /** Return mean & standard deviation for given elements of a vector. */ + static void getMeanAndStandardDeviation (std::vector<double>* ioMean_SD, + std::vector<double>&); + /** Return the input vector after adding a value. */ static void AddAValueToAVector (std::vector<double>& ioVector, double iValue); @@ -29,7 +33,7 @@ static void MultiplyAValueToAVector (std::vector<double>& ioVector, double iValue); - /** Return an input vector after adding the other input vector. */ + /** Return first input vector after adding 2nd input vector to it. */ static void AddTwoVectors (std::vector<double>& ioVector, std::vector<double>& iVector); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-09-21 15:12:16
|
Revision: 256 http://rmol.svn.sourceforge.net/rmol/?rev=256&view=rev Author: dkchoe Date: 2009-09-21 15:12:10 +0000 (Mon, 21 Sep 2009) Log Message: ----------- [Q-Forecaster] Added a function that partitions Q-eq demand to each class Modified Paths: -------------- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp trunk/rmol/rmol/bom/QForecaster.cpp Modified: trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-09-18 16:10:41 UTC (rev 255) +++ trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-09-21 15:12:10 UTC (rev 256) @@ -12,15 +12,15 @@ // //////// Type definitions ///////// - /** Define the map of a class code - segment (origine/destination) - and a vector of (unconstrained) demand of the similar flight-dates. */ - typedef std::map<std::string, std::vector<double> > - SimilarFlightsDemandList_T; + // /** Define the map of a class code - segment (origine/destination) + // and a vector of (unconstrained) demand of the similar flight-dates. */ + // typedef std::map<std::string, std::vector<double> > + // SimilarFlightsDemandList_T; /** Define the holder of forecasted demand parameters (mean, std. deviation) per booking class. The order of the parameters corresponds to the vector inputs resulted the parameters themselves.*/ - typedef std::vector<double> ForecastedDemandParameterList_T; + typedef std::vector< std::vector<double> > ForecastedDemandParameterList_T; /** Define a vector of fares. */ typedef std::vector<double> PriceHolder_T; Modified: trunk/rmol/rmol/bom/QForecaster.cpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-18 16:10:41 UTC (rev 255) +++ trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-21 15:12:10 UTC (rev 256) @@ -3,6 +3,8 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <cmath> +#include <algorithm> +#include <numeric> // RMOL Bom #include <rmol/bom/Bucket.hpp> #include <rmol/bom/BucketHolder.hpp> @@ -77,11 +79,52 @@ // ////////////////////////////////////////////////////////////////////// void QForecaster::partitionQEquivalentDemandParameters - (ForecastedDemandParameterList_T, - QEquivalentDemandParameterHolder_T*, - SellupProbabilityVector_T*) { - + (ForecastedDemandParameterList_T oForecastedDemandParameterList, + QEquivalentDemandParameterHolder_T* iQEquivalentDemandParameterHolder, + SellupProbabilityVector_T* iSellupProbabilityVector) { + unsigned int noOfClasses = iSellupProbabilityVector->size(); + + // Sort sellup probabilities in increasing order and copy into a vector + std::vector<double> lSortedSellupProbabilityVector(noOfClasses); + std::partial_sort_copy (iSellupProbabilityVector->begin(), + iSellupProbabilityVector->end(), + lSortedSellupProbabilityVector.begin(), + lSortedSellupProbabilityVector.end()); + + // Compute the probability to sell-up to class i but not i-1 (class + // with the next higher fare) and copy into a vector + std::vector<double> lSellupProbabilityDifferenceVector(noOfClasses); + adjacent_difference (lSortedSellupProbabilityVector.begin(), + lSortedSellupProbabilityVector.end(), + lSellupProbabilityDifferenceVector.begin()); + + // Partition Q-equivalent demand mean and S.D. into each class + oForecastedDemandParameterList.clear(); + for (unsigned short k=0; k < noOfClasses; k++) { + // Locate the current sell-up probability in the sorted one + std::vector<double>::iterator pos = + std::lower_bound (lSortedSellupProbabilityVector.begin(), + lSortedSellupProbabilityVector.end(), + iSellupProbabilityVector->at(k)); + int posOfCurrentSellupProbInSortedVector = + std::distance(lSortedSellupProbabilityVector.begin(), pos); + + // Find the corresponding sell-up probability difference + double correspondingSellupProbability = + lSellupProbabilityDifferenceVector.at( + posOfCurrentSellupProbInSortedVector); + + // Compute mean and S.D. of each class + // class mean = Q-eq mean * sell-up prob difference + // class S.D. = Q-eq S.D. * sell-up prob difference + oForecastedDemandParameterList.push_back + (*iQEquivalentDemandParameterHolder); + std::vector<double>& forecastedDemandParameters = + oForecastedDemandParameterList.at(k); + Utilities::MultiplyAValueToAVector (forecastedDemandParameters, + correspondingSellupProbability); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-09-22 08:47:17
|
Revision: 257 http://rmol.svn.sourceforge.net/rmol/?rev=257&view=rev Author: dkchoe Date: 2009-09-22 08:47:08 +0000 (Tue, 22 Sep 2009) Log Message: ----------- [Q-Forecaster] Cleaned up the code (Replaced pointers with references) Modified Paths: -------------- trunk/rmol/rmol/bom/QForecaster.cpp trunk/rmol/rmol/bom/QForecaster.hpp trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Utilities.cpp trunk/rmol/rmol/command/Utilities.hpp Modified: trunk/rmol/rmol/bom/QForecaster.cpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-21 15:12:10 UTC (rev 256) +++ trunk/rmol/rmol/bom/QForecaster.cpp 2009-09-22 08:47:08 UTC (rev 257) @@ -35,33 +35,34 @@ // ////////////////////////////////////////////////////////////////////// void QForecaster::calculateSellupProbability - (SellupProbabilityVector_T* ioSellupProbabilityVector, double* iPtrQYield, + (SellupProbabilityVector_T& ioSellupProbabilityVector, double& iQYield, PriceHolder_T& iPriceHolder, SellupFactorHolder_T& iSellupFactorHolder) { - ioSellupProbabilityVector->clear(); + ioSellupProbabilityVector.clear(); for (unsigned short j = 0; j < iPriceHolder.size(); j++){ const double lYield = iPriceHolder.at(j); const double probSellup = - exp(-iSellupFactorHolder.at(j) * lYield / (*iPtrQYield)); - ioSellupProbabilityVector->push_back(probSellup); + exp(-iSellupFactorHolder.at(j) * lYield / (iQYield)); + ioSellupProbabilityVector.push_back(probSellup); } } // ////////////////////////////////////////////////////////////////////// void QForecaster::calculateQEquivalentDemandParameters - (QEquivalentDemandParameterHolder_T* ioQEquivalentDemandParameterHolder, + (QEquivalentDemandParameterHolder_T& ioQEquivalentDemandParameterHolder, HistoricalDataHolderHolder_T& iHistoricalDataHolderHolder, - SellupProbabilityVector_T* lSellupProbabilityVector) { + SellupProbabilityVector_T& iSellupProbabilityVector) { // 1. Calculate Q-equivalent demand parameters // Initialize a holder for Q-equivalent Demands - std::vector<double> aZeroVector (lSellupProbabilityVector->size(), 0); - std::vector<double>& lQEquivalentDemandHolder = aZeroVector; + // std::vector<double> aZeroVector (iSellupProbabilityVector.size(), 0); + // std::vector<double>& lQEquivalentDemandHolder = aZeroVector; + std::vector<double> lQEquivalentDemandHolder; for (unsigned int j = 0; j < iHistoricalDataHolderHolder.size(); j++) { // Retrieve HistoricalDataHolder which are the data of the same product // over different dates std::vector<double>& lHistoricalDataHolder = iHistoricalDataHolderHolder.at(j); - double lSellupProbability = lSellupProbabilityVector->at(j); + double lSellupProbability = iSellupProbabilityVector.at(j); // Apply sellup probability to historical data Utilities::MultiplyAValueToAVector (lHistoricalDataHolder, @@ -79,16 +80,16 @@ // ////////////////////////////////////////////////////////////////////// void QForecaster::partitionQEquivalentDemandParameters - (ForecastedDemandParameterList_T oForecastedDemandParameterList, - QEquivalentDemandParameterHolder_T* iQEquivalentDemandParameterHolder, - SellupProbabilityVector_T* iSellupProbabilityVector) { + (ForecastedDemandParameterList_T& ioForecastedDemandParameterList, + QEquivalentDemandParameterHolder_T& iQEquivalentDemandParameterHolder, + SellupProbabilityVector_T& iSellupProbabilityVector) { - unsigned int noOfClasses = iSellupProbabilityVector->size(); + unsigned int noOfClasses = iSellupProbabilityVector.size(); // Sort sellup probabilities in increasing order and copy into a vector std::vector<double> lSortedSellupProbabilityVector(noOfClasses); - std::partial_sort_copy (iSellupProbabilityVector->begin(), - iSellupProbabilityVector->end(), + std::partial_sort_copy (iSellupProbabilityVector.begin(), + iSellupProbabilityVector.end(), lSortedSellupProbabilityVector.begin(), lSortedSellupProbabilityVector.end()); @@ -100,13 +101,13 @@ lSellupProbabilityDifferenceVector.begin()); // Partition Q-equivalent demand mean and S.D. into each class - oForecastedDemandParameterList.clear(); + ioForecastedDemandParameterList.clear(); for (unsigned short k=0; k < noOfClasses; k++) { // Locate the current sell-up probability in the sorted one std::vector<double>::iterator pos = std::lower_bound (lSortedSellupProbabilityVector.begin(), lSortedSellupProbabilityVector.end(), - iSellupProbabilityVector->at(k)); + iSellupProbabilityVector.at(k)); int posOfCurrentSellupProbInSortedVector = std::distance(lSortedSellupProbabilityVector.begin(), pos); @@ -118,10 +119,10 @@ // Compute mean and S.D. of each class // class mean = Q-eq mean * sell-up prob difference // class S.D. = Q-eq S.D. * sell-up prob difference - oForecastedDemandParameterList.push_back - (*iQEquivalentDemandParameterHolder); + ioForecastedDemandParameterList.push_back + (iQEquivalentDemandParameterHolder); std::vector<double>& forecastedDemandParameters = - oForecastedDemandParameterList.at(k); + ioForecastedDemandParameterList.at(k); Utilities::MultiplyAValueToAVector (forecastedDemandParameters, correspondingSellupProbability); } Modified: trunk/rmol/rmol/bom/QForecaster.hpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.hpp 2009-09-21 15:12:10 UTC (rev 256) +++ trunk/rmol/rmol/bom/QForecaster.hpp 2009-09-22 08:47:08 UTC (rev 257) @@ -30,24 +30,24 @@ /** The same method as the above but taking price data directly instead of through BucketHolder. */ - static void calculateSellupProbability (SellupProbabilityVector_T*, - double* iPtrQYield, + static void calculateSellupProbability (SellupProbabilityVector_T&, + double& iQYield, PriceHolder_T&, SellupFactorHolder_T&); /** Calculate Q-equivalent demand distribution parameters and partition it to each class/bucket. */ static void calculateQEquivalentDemandParameters - (QEquivalentDemandParameterHolder_T*, + (QEquivalentDemandParameterHolder_T&, HistoricalDataHolderHolder_T&, - SellupProbabilityVector_T*); + SellupProbabilityVector_T&); /** Calculate Q-equivalent demand distribution parameters and partition it to each class/bucket. */ static void partitionQEquivalentDemandParameters - (ForecastedDemandParameterList_T, - QEquivalentDemandParameterHolder_T*, - SellupProbabilityVector_T*); + (ForecastedDemandParameterList_T&, + QEquivalentDemandParameterHolder_T&, + SellupProbabilityVector_T&); }; } Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2009-09-21 15:12:10 UTC (rev 256) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-09-22 08:47:08 UTC (rev 257) @@ -51,29 +51,29 @@ // E(alpha x Q)=alpha x mu_Q, S.D.(alpha x Q) = |alpha| X sigma_Q // Find the class with the lowest yield - double* ptrQYield; - Utilities::getMinimumElement (ptrQYield, iPriceHolder); + double lQYield; + Utilities::getMinimumElement (lQYield, iPriceHolder); // Initialize a holder for sell-up probabilities - SellupProbabilityVector_T* lSellupProbabilityVector; + SellupProbabilityVector_T lSellupProbabilityVector; // Compute sell-up probability for each class/bucket & store it in a vector QForecaster::calculateSellupProbability - (lSellupProbabilityVector, ptrQYield, iPriceHolder, iSellupFactorHolder); + (lSellupProbabilityVector, lQYield, iPriceHolder, iSellupFactorHolder); // Initialize a holder for Q-equivalent Demand Parameters - QEquivalentDemandParameterHolder_T* lQEquivalentDemandParameterHolder; + QEquivalentDemandParameterHolder_T lQEquivalentDemandParameterHolder; // Calculate Q-equivalent demand distribution parameters. QForecaster::calculateQEquivalentDemandParameters - (lQEquivalentDemandParameterHolder, iHistoricalDataHolderHolder, - lSellupProbabilityVector); + (lQEquivalentDemandParameterHolder, iHistoricalDataHolderHolder, + lSellupProbabilityVector); // Calculate Q-equivalent demand distribution parameters and // partition it to each class/bucket - QForecaster::partitionQEquivalentDemandParameters - (oForecastedDemandParameterList, lQEquivalentDemandParameterHolder, - lSellupProbabilityVector); + //QForecaster::partitionQEquivalentDemandParameters + // (oForecastedDemandParameterList, lQEquivalentDemandParameterHolder, + // lSellupProbabilityVector); } } Modified: trunk/rmol/rmol/command/Utilities.cpp =================================================================== --- trunk/rmol/rmol/command/Utilities.cpp 2009-09-21 15:12:10 UTC (rev 256) +++ trunk/rmol/rmol/command/Utilities.cpp 2009-09-22 08:47:08 UTC (rev 257) @@ -14,13 +14,13 @@ namespace RMOL { // ///////////////////////////////////////////////////////////////////// - void Utilities::getMinimumElement (double* oMinValue, + void Utilities::getMinimumElement (double& oMinValue, std::vector<double>& iVector) { assert(!iVector.empty()); std::vector<double>::iterator pos = min_element (iVector.begin(), iVector.end()); - *oMinValue = *pos; + oMinValue = *pos; } @@ -51,17 +51,17 @@ } // ///////////////////////////////////////////////////////////////////// - void Utilities::getMeanAndStandardDeviation (std::vector<double>* ioMean_SD, + void Utilities::getMeanAndStandardDeviation (std::vector<double>& ioMean_SD, std::vector<double>& iVector) { const unsigned int lSize = iVector.size(); assert(lSize > 0); - ioMean_SD->clear(); + ioMean_SD.clear(); // Mean double lSum = std::accumulate(iVector.begin(), iVector.end(), 0); double lMean = lSum/lSize; - ioMean_SD->push_back(lMean); + ioMean_SD.push_back(lMean); //Standard Deviation double lSD = 0; @@ -70,7 +70,7 @@ lSD += lDeviation * lDeviation; } lSD /= (lSize - 1); - ioMean_SD->push_back(sqrt(lSD)); + ioMean_SD.push_back(sqrt(lSD)); } // ///////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/command/Utilities.hpp =================================================================== --- trunk/rmol/rmol/command/Utilities.hpp 2009-09-21 15:12:10 UTC (rev 256) +++ trunk/rmol/rmol/command/Utilities.hpp 2009-09-22 08:47:08 UTC (rev 257) @@ -11,7 +11,7 @@ struct Utilities { /** Returns the minimum element of a given vector*/ - static void getMinimumElement (double* oMinValue, std::vector<double>&); + static void getMinimumElement (double& oMinValue, std::vector<double>&); /** Return mean for the given elements of a vector. */ static void getMean (double& oMean, std::vector<double>&); @@ -22,7 +22,7 @@ double& iMean); /** Return mean & standard deviation for given elements of a vector. */ - static void getMeanAndStandardDeviation (std::vector<double>* ioMean_SD, + static void getMeanAndStandardDeviation (std::vector<double>& ioMean_SD, std::vector<double>&); /** Return the input vector after adding a value. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <qua...@us...> - 2009-09-25 13:04:29
|
Revision: 259 http://rmol.svn.sourceforge.net/rmol/?rev=259&view=rev Author: quannaus Date: 2009-09-25 13:04:14 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Added ProtectionLevel_T in RMOL_Types, removed some unnessary print screen. Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/RMOL_Types.hpp trunk/rmol/rmol/bom/BucketHolder.cpp trunk/rmol/rmol/bom/BucketHolder.hpp trunk/rmol/rmol/bom/MCOptimiser.cpp trunk/rmol/rmol/service/RMOL_Service.cpp Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2009-09-25 08:49:35 UTC (rev 258) +++ trunk/rmol/rmol/RMOL_Service.hpp 2009-09-25 13:04:14 UTC (rev 259) @@ -66,6 +66,7 @@ /** Single resource optimization that uses Monte-Carlo algorithm and returns a vector of cumulated booking limits. */ void optimalOptimisationByMCIntegration (const int K, + ProtectionLevelVector_T&, BidPriceVector_T&, BookingLimitVector_T&); @@ -74,21 +75,25 @@ /** Single resource optimization that uses dynamic programming and returns a vector of cumulated booking limits. */ - void optimalOptimisationByDP (BookingLimitVector_T&); + void optimalOptimisationByDP(ProtectionLevelVector_T&,BookingLimitVector_T&); /** Single resource optimization using EMSR heuristic. */ void heuristicOptimisationByEmsr (); /** Single resource optimization that uses EMSR heuristic and returns a bid-price vector and a vector of cumulated booking limits. */ - void heuristicOptimisationByEmsr (BidPriceVector_T&, BookingLimitVector_T&); + void heuristicOptimisationByEmsr (BidPriceVector_T&, + ProtectionLevelVector_T&, + BookingLimitVector_T&); /** Single resource optimization using EMSR-a heuristic. */ void heuristicOptimisationByEmsrA (); /** Single resource optimization that uses EMSR-a heuristic and returns a vector of cumulated booking limits. */ - void heuristicOptimisationByEmsrA (BidPriceVector_T&, BookingLimitVector_T&); + void heuristicOptimisationByEmsrA (BidPriceVector_T&, + ProtectionLevelVector_T&, + BookingLimitVector_T&); /** Single resource optimization with sellup using EMSR-a heuristic. */ void heuristicOptimisationByEmsrAwithSellup (SellupProbabilityVector_T&); @@ -96,6 +101,7 @@ /** Single resource optimization with sellup that uses EMSR-a heuristic and returns a vector of cumulated booking limits. */ void heuristicOptimisationByEmsrAwithSellup (SellupProbabilityVector_T&, + ProtectionLevelVector_T&, BidPriceVector_T&, BookingLimitVector_T&); @@ -104,7 +110,9 @@ /** Single resource optimization that uses EMSR-b heuristic and returns a vector of cumulated booking limits. */ - void heuristicOptimisationByEmsrB (BidPriceVector_T&, BookingLimitVector_T&); + void heuristicOptimisationByEmsrB (BidPriceVector_T&, + ProtectionLevelVector_T&, + BookingLimitVector_T&); /** Leg optimisation using Monte-Carlo Integration as a step in network optimisation. */ @@ -112,7 +120,9 @@ /** Leg optimisation using Monte-Carlo Integration as a step in network optimisation. */ - void legOptimisationByMC (BidPriceVector_T&, BookingLimitVector_T&); + void legOptimisationByMC (BidPriceVector_T&, + ProtectionLevelVector_T&, + BookingLimitVector_T&); /** Demand unconstraining by Expectation Maximization */ void demandUnconstrainingByExpectationMaximization (); Modified: trunk/rmol/rmol/RMOL_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Types.hpp 2009-09-25 08:49:35 UTC (rev 258) +++ trunk/rmol/rmol/RMOL_Types.hpp 2009-09-25 13:04:14 UTC (rev 259) @@ -53,6 +53,10 @@ <br>It is a double, as it allows for overbooking. */ typedef double BookingLimit_T; + /** Define the Protection Level. + <br>It is a double, as it allows for overbooking. */ + typedef double ProtectionLevel_T; + /** Define the number of products.*/ typedef const unsigned int NumberOfProducts_T; @@ -70,6 +74,10 @@ <br> It is a vector of double. */ typedef std::vector<double> BookingLimitVector_T; + /** Define the vector of protection levels. + <br> It is a vector of double. */ + typedef std::vector<double> ProtectionLevelVector_T; + /** Define the vector of generated demand (for MC integration use). <br> It is a vector of double. */ typedef std::vector<double> GeneratedDemandVector_T; Modified: trunk/rmol/rmol/bom/BucketHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/BucketHolder.cpp 2009-09-25 08:49:35 UTC (rev 258) +++ trunk/rmol/rmol/bom/BucketHolder.cpp 2009-09-25 13:04:14 UTC (rev 259) @@ -265,15 +265,20 @@ // ////////////////////////////////////////////////////////////////////// void BucketHolder:: - fillup (BookingLimitVector_T& ioBookingLimitVector) const { + fillup (ProtectionLevelVector_T& ioProtectionLevelVector, + BookingLimitVector_T& ioBookingLimitVector) const { BucketList_T::const_iterator itBucket = _bucketList.begin(); for (short j=1; itBucket != _bucketList.end(); itBucket++, j++) { const Bucket* currentBucket_ptr = *itBucket; assert (currentBucket_ptr != NULL); + + const ProtectionLevel_T lCumulatedProtection = + currentBucket_ptr->getCumulatedProtection(); + ioProtectionLevelVector.push_back (lCumulatedProtection); const double lCumulatedBookingLimit = currentBucket_ptr->getCumulatedBookingLimit(); - ioBookingLimitVector.push_back(lCumulatedBookingLimit); + ioBookingLimitVector.push_back (lCumulatedBookingLimit); } } Modified: trunk/rmol/rmol/bom/BucketHolder.hpp =================================================================== --- trunk/rmol/rmol/bom/BucketHolder.hpp 2009-09-25 08:49:35 UTC (rev 258) +++ trunk/rmol/rmol/bom/BucketHolder.hpp 2009-09-25 13:04:14 UTC (rev 259) @@ -47,8 +47,9 @@ current bucket is the first one, the function returns 0.0. */ const double getPreviousCumulatedProtection () const; - /** Fill up the vector of cumulated booking limits. */ - void fillup (BookingLimitVector_T&) const; + /** Fill up the vector of cumulated booking limits and the vector + of cumulated protection levels. */ + void fillup (ProtectionLevelVector_T&, BookingLimitVector_T&) const; /** Get the current element (bucket/class). */ Bucket& getCurrentBucket () const; Modified: trunk/rmol/rmol/bom/MCOptimiser.cpp =================================================================== --- trunk/rmol/rmol/bom/MCOptimiser.cpp 2009-09-25 08:49:35 UTC (rev 258) +++ trunk/rmol/rmol/bom/MCOptimiser.cpp 2009-09-25 13:04:14 UTC (rev 259) @@ -140,9 +140,10 @@ const double ljdouble = std::floor (Kj * (pj - pj1) / pj); lj = static_cast<int> (ljdouble); - /** DEBUG - RMOL_LOG_DEBUG ("p(j+1)/p(j) = " << pj1 / pj << ", lj = " << lj - << ", Kj = " << Kj << " => " << Kj - lj << " points above y(j)"); + /** DEBUG + RMOL_LOG_DEBUG ("p(j+1)/p(j) = " << pj1 / pj << ", lj = " << lj + << ", Kj = " << Kj << " => " << Kj - lj + << " points above y(j)"); */ /** Consistency check. */ @@ -379,14 +380,11 @@ const double ljdouble = std::floor (Kj * (pj - pj1) / pj); lj = static_cast<int> (ljdouble); - // DEBUG - std::cout << "l" << j << " = " << lj << std::endl; - - /** DEBUG + /** DEBUG RMOL_LOG_DEBUG ("p(j+1)/p(j) = " << pj1 / pj << ", lj = " << lj << ", Kj = " << Kj << " => " << Kj - lj << " points above y(j)"); */ - + /** Consistency check. */ assert (lj >= 1 && lj < Kj); Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-09-25 08:49:35 UTC (rev 258) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2009-09-25 13:04:14 UTC (rev 259) @@ -185,10 +185,10 @@ } // ////////////////////////////////////////////////////////////////////// - void RMOL_Service:: - optimalOptimisationByMCIntegration(const int K, - BidPriceVector_T& ioBidPriceVector, - BookingLimitVector_T& ioBookingLimitVector){ + void RMOL_Service::optimalOptimisationByMCIntegration + (const int K, ProtectionLevelVector_T& ioProtectionLevelVector, + BidPriceVector_T& ioBidPriceVector, + BookingLimitVector_T& ioBookingLimitVector){ assert (_rmolServiceContext != NULL); const double iCapacity = _rmolServiceContext->getCapacity(); @@ -200,7 +200,7 @@ ioBidPriceVector); // Fill up booking vector - oBucketHolder_ptr->fillup (ioBookingLimitVector); + oBucketHolder_ptr->fillup (ioProtectionLevelVector, ioBookingLimitVector); } // ////////////////////////////////////////////////////////////////////// @@ -220,7 +220,8 @@ // ////////////////////////////////////////////////////////////////////// void RMOL_Service:: - optimalOptimisationByDP (BookingLimitVector_T& ioBookingLimitVector) { + optimalOptimisationByDP (ProtectionLevelVector_T& ioProtectionLevelVector, + BookingLimitVector_T& ioBookingLimitVector) { assert (_rmolServiceContext != NULL); const double iCapacity = _rmolServiceContext->getCapacity(); @@ -230,7 +231,7 @@ Optimiser::optimalOptimisationByDP (iCapacity, *oBucketHolder_ptr); // Fill up booking vector - oBucketHolder_ptr->fillup (ioBookingLimitVector); + oBucketHolder_ptr->fillup (ioProtectionLevelVector, ioBookingLimitVector); } // ////////////////////////////////////////////////////////////////////// @@ -273,6 +274,7 @@ // ////////////////////////////////////////////////////////////////////// void RMOL_Service:: heuristicOptimisationByEmsr (BidPriceVector_T& ioBidPriceVector, + ProtectionLevelVector_T& ioProtectionLevelVector, BookingLimitVector_T& ioBookingLimitVector) { assert (_rmolServiceContext != NULL); const double iCapacity = _rmolServiceContext->getCapacity(); @@ -282,14 +284,7 @@ Optimiser::heuristicOptimisationByEmsr (iCapacity, *oBucketHolder_ptr, ioBidPriceVector); - // Update the booking limit vector. - for (oBucketHolder_ptr->begin(); oBucketHolder_ptr->hasNotReachedEnd(); - oBucketHolder_ptr->iterate()) { - Bucket& currentBucket = oBucketHolder_ptr->getCurrentBucket(); - const double lBookingLimit = currentBucket.getCumulatedBookingLimit(); - ioBookingLimitVector.push_back (lBookingLimit); - } - + oBucketHolder_ptr->fillup (ioProtectionLevelVector, ioBookingLimitVector); } // ////////////////////////////////////////////////////////////////////// @@ -308,6 +303,7 @@ // ////////////////////////////////////////////////////////////////////// void RMOL_Service:: heuristicOptimisationByEmsrA (BidPriceVector_T& ioBidPriceVector, + ProtectionLevelVector_T& ioProtectionLevelVector, BookingLimitVector_T& ioBookingLimitVector) { assert (_rmolServiceContext != NULL); const double iCapacity = _rmolServiceContext->getCapacity(); @@ -317,7 +313,7 @@ Optimiser::heuristicOptimisationByEmsrA (iCapacity, *oBucketHolder_ptr); // Fill up booking vector - oBucketHolder_ptr->fillup (ioBookingLimitVector); + oBucketHolder_ptr->fillup (ioProtectionLevelVector, ioBookingLimitVector); } // ////////////////////////////////////////////////////////////////////// @@ -343,6 +339,7 @@ void RMOL_Service::heuristicOptimisationByEmsrAwithSellup (SellupProbabilityVector_T& iSellupProbabilityVector, BidPriceVector_T& ioBidPriceVector, + ProtectionLevelVector_T& ioProtectionLevelVector, BookingLimitVector_T& ioBookingLimitVector) { assert (_rmolServiceContext != NULL); @@ -357,7 +354,7 @@ iSellupProbabilityVector); // Fill up booking limit vector - ioBucketHolder_ptr->fillup (ioBookingLimitVector); + ioBucketHolder_ptr->fillup (ioProtectionLevelVector, ioBookingLimitVector); } // ////////////////////////////////////////////////////////////////////// @@ -376,6 +373,7 @@ // ////////////////////////////////////////////////////////////////////// void RMOL_Service:: heuristicOptimisationByEmsrB (BidPriceVector_T& ioBidPriceVector, + ProtectionLevelVector_T& ioProtectionLevelVector, BookingLimitVector_T& ioBookingLimitVector) { assert (_rmolServiceContext != NULL); const double iCapacity = _rmolServiceContext->getCapacity(); @@ -385,7 +383,7 @@ Optimiser::heuristicOptimisationByEmsrB (iCapacity, *oBucketHolder_ptr); // Fill up booking vector - oBucketHolder_ptr->fillup (ioBookingLimitVector); + oBucketHolder_ptr->fillup (ioProtectionLevelVector, ioBookingLimitVector); } // /////////////////////////////////////////////////////////////////////// @@ -415,6 +413,7 @@ // /////////////////////////////////////////////////////////////////////// void RMOL_Service:: legOptimisationByMC (BidPriceVector_T& ioBidPriceVector, + ProtectionLevelVector_T& ioProtectionLevelVector, BookingLimitVector_T& ioBookingLimitVector) { assert (_rmolServiceContext != NULL); const ResourceCapacity_T iCapacity = _rmolServiceContext->getCapacity(); @@ -425,7 +424,7 @@ ioBidPriceVector); // Fill up booking vector - oBucketHolder_ptr->fillup (ioBookingLimitVector); + oBucketHolder_ptr->fillup (ioProtectionLevelVector, ioBookingLimitVector); } // /////////////////////////////////////////////////////////////////////// This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-09-30 17:00:07
|
Revision: 264 http://rmol.svn.sourceforge.net/rmol/?rev=264&view=rev Author: dkchoe Date: 2009-09-30 16:59:52 +0000 (Wed, 30 Sep 2009) Log Message: ----------- Added Expectation Maximization data unconstraining algorithm; Calculation of expected value of censored data is to be done Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/RMOL_Types.hpp trunk/rmol/rmol/basic/BasConst.cpp trunk/rmol/rmol/basic/BasConst_General.hpp trunk/rmol/rmol/bom/sources.mk trunk/rmol/rmol/command/Unconstrainer.cpp trunk/rmol/rmol/command/Unconstrainer.hpp trunk/rmol/rmol/command/Utilities.cpp trunk/rmol/rmol/command/Utilities.hpp trunk/rmol/rmol/core/sources.mk trunk/rmol/rmol/service/RMOL_Service.cpp Added Paths: ----------- trunk/rmol/rmol/RMOL_UNCONSTRAINER_Types.hpp trunk/rmol/rmol/RMOL_UTILITY_Types.hpp trunk/rmol/rmol/bom/ExpectationMaximization.cpp trunk/rmol/rmol/bom/ExpectationMaximization.hpp Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/RMOL_Service.hpp 2009-09-30 16:59:52 UTC (rev 264) @@ -124,8 +124,8 @@ ProtectionLevelVector_T&, BookingLimitVector_T&); - /** Demand unconstraining by Expectation Maximization */ - void demandUnconstrainingByExpectationMaximization (); + /** Data unconstraining by Expectation Maximization */ + void dataUnconstrainingByExpectationMaximization (); /** Demand forecast using Q-Forecasting */ void demandForecastByQForecasting (ForecastedDemandParameterList_T&, Modified: trunk/rmol/rmol/RMOL_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Types.hpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/RMOL_Types.hpp 2009-09-30 16:59:52 UTC (rev 264) @@ -94,19 +94,6 @@ /** Define the holder of sellup factors (used for computing Q-eq bookings)*/ typedef std::vector<double> SellupFactorHolder_T; -// /** Define the historical booking data of a flight date in the order of -// the classes in the BucketHolder -// eg. -// BucketHolder=[Q;M;B;Y], OrderedHistoricalBookingVector_T=[10;5;0;0] -// 5 corresponds to bookings of class M of a similar flight */ -// typedef std::vector<double> OrderedHistoricalBookingVector_T; -// /** Define the holder of historical booking vectors */ -// typedef std::vector<HistoricalBookingHolder> -// HistoricalBookingHolderHolder_T; - - // /** Define the holder of Q-equivalent booking values*/ - // typedef std::vector<double> HolderOfQEquivalentBookingsPerSimilarFlight_T; - } #endif // __RMOL_RMOL_TYPES_HPP Added: trunk/rmol/rmol/RMOL_UNCONSTRAINER_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_UNCONSTRAINER_Types.hpp (rev 0) +++ trunk/rmol/rmol/RMOL_UNCONSTRAINER_Types.hpp 2009-09-30 16:59:52 UTC (rev 264) @@ -0,0 +1,22 @@ +#ifndef __RMOL_RMOL_UNCONSTRAINER_TYPES_HPP +#define __RMOL_RMOL_UNCONSTRAINER_TYPES_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <vector> + + +namespace RMOL { + + // //////// Type definitions ///////// + + /** Define a holder of constrained data.*/ + typedef std::vector<double> ConstrainedDataHolder_T; + + /** Define a holder of unconstrained data*/ + typedef std::vector<double> UnconstrainedDataHolder_T; + +} +#endif // __RMOL_RMOL_UNCONSTRAINER_TYPES_HPP Added: trunk/rmol/rmol/RMOL_UTILITY_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_UTILITY_Types.hpp (rev 0) +++ trunk/rmol/rmol/RMOL_UTILITY_Types.hpp 2009-09-30 16:59:52 UTC (rev 264) @@ -0,0 +1,23 @@ +#ifndef __RMOL_RMOL_UTILITY_TYPES_HPP +#define __RMOL_RMOL_UTILITY_TYPES_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// + +namespace RMOL { + + // //////// Type definitions ///////// + + /** Define a stopping criterion. */ + typedef double StoppingCriterion_T; + + /** Define a mean type. */ + typedef double Mean_T; + + /** Define a standard deviation type. */ + typedef double StandardDeviation_T; + + +} +#endif // __RMOL_RMOL_UTILITY_TYPES_HPP Modified: trunk/rmol/rmol/basic/BasConst.cpp =================================================================== --- trunk/rmol/rmol/basic/BasConst.cpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/basic/BasConst.cpp 2009-09-30 16:59:52 UTC (rev 264) @@ -18,7 +18,13 @@ /** Default epsilon value to qualify a denominator */ const double DEFAULT_EPSILON = 0.0001; + + /** Default stopping value for an iterative algorithm. */ + const double DEFAULT_STOPPING_CRITERION = 0.01; + /** Default negative value used to initialze a double variable. */ + const double DEFAULT_INITIALIZER_DOUBLE_NEGATIVE = -10.0; + /** Default value for the load factor used for overbooking calculation. */ const double DEFAULT_OVERBOOKING_LOAD_FACTOR = 0.0; Modified: trunk/rmol/rmol/basic/BasConst_General.hpp =================================================================== --- trunk/rmol/rmol/basic/BasConst_General.hpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/basic/BasConst_General.hpp 2009-09-30 16:59:52 UTC (rev 264) @@ -17,5 +17,12 @@ /** Default epsilon value to qualify a denominator */ extern const double DEFAULT_EPSILON; + + /** Default stopping value for an iterative algorithm. */ + extern const double DEFAULT_STOPPING_CRITERION; + + /** Default negative value used to initialze a double variable. */ + extern const double DEFAULT_INITIALIZER_DOUBLE_NEGATIVE; + } #endif // __RMOL_BAS_BASCONST_GENERAL_HPP Added: trunk/rmol/rmol/bom/ExpectationMaximization.cpp =================================================================== --- trunk/rmol/rmol/bom/ExpectationMaximization.cpp (rev 0) +++ trunk/rmol/rmol/bom/ExpectationMaximization.cpp 2009-09-30 16:59:52 UTC (rev 264) @@ -0,0 +1,93 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +# include <math.h> +// RMOL +#include <rmol/service/Logger.hpp> +#include <rmol/basic/BasConst_General.hpp> +#include <rmol/command/Utilities.hpp> +#include <rmol/bom/ExpectationMaximization.hpp> + +namespace RMOL { + + // ////////////////////////////////////////////////////////////////////// + void ExpectationMaximization::unconstrainData + (ConstrainedDataHolder_T& ioConstrainedDataHolder, + UnconstrainedDataHolder_T& iUnconstrainedDataHolder, + StoppingCriterion_T& iStoppingCriterion) { + + if (iStoppingCriterion <= 0) { + iStoppingCriterion = DEFAULT_STOPPING_CRITERION; + } + + const unsigned int NoOfConstrainededData = + ioConstrainedDataHolder.size(); + const unsigned int NoOfUnconstrainedData = + iUnconstrainedDataHolder.size(); + + // Unconstraining process + if (NoOfUnconstrainedData > 0) { + Mean_T lCompleteDataMean = 0.0; + StandardDeviation_T lCompleteDataSD = 0.0; + double lSumOfUnconstrainedData, lSqErrorOfUnconstrainedData = 0.0; + double lTotalNumberOfData = NoOfConstrainededData + + NoOfUnconstrainedData; + // Mean and S.D. of unconstrained data + Utilities::sumUpElements (lSumOfUnconstrainedData, + iUnconstrainedDataHolder); + lCompleteDataMean = lSumOfUnconstrainedData / NoOfUnconstrainedData; + Utilities::getSquaredError (lSqErrorOfUnconstrainedData, + iUnconstrainedDataHolder, lCompleteDataMean); + lCompleteDataSD = sqrt(lSqErrorOfUnconstrainedData / + (NoOfUnconstrainedData-1)); + + // If there are constrained data + if (NoOfConstrainededData > 0) { + double lEstimatedMean, lEstimatedSD, lSqErrorOfConstrainedData = + DEFAULT_INITIALIZER_DOUBLE_NEGATIVE; + + do { + if (lEstimatedMean != DEFAULT_INITIALIZER_DOUBLE_NEGATIVE) { + lCompleteDataMean = lEstimatedMean; + lCompleteDataSD = lEstimatedSD; + } + + // TO-DO: Expectation step + expectedValueOfNormallyDistributedConstrainedData + (ioConstrainedDataHolder, lCompleteDataMean, lCompleteDataSD); + // Maximization step + // Mean + Utilities::sumUpElements (lEstimatedMean, ioConstrainedDataHolder); + lEstimatedMean = (lEstimatedMean + lSumOfUnconstrainedData) / + lTotalNumberOfData; + // S.D. + Utilities::getSquaredError (lSqErrorOfUnconstrainedData, + iUnconstrainedDataHolder, lEstimatedMean); + Utilities::getSquaredError (lSqErrorOfConstrainedData, + ioConstrainedDataHolder, lEstimatedMean); + lEstimatedSD = sqrt((lSqErrorOfUnconstrainedData + + lSqErrorOfConstrainedData) / (lTotalNumberOfData-1)); + } while ( fabs(lCompleteDataMean - lEstimatedMean ) > iStoppingCriterion ); + // If should mean and s.d. of unconstrained data be outputed + // lCompleteDataMean = lEstimatedMean; lCompleteDataSD = lEstimatedSD; + } + // Job finished as all are unconstrained or nothing to be unconstrained + } + else { + RMOL_LOG_ERROR ("At least one unconstrained data is required to " + << "correct constrained data with Expectation " + << "Maximization algorithm."); + } + + } + + // ////////////////////////////////////////////////////////////////////// + void ExpectationMaximization:: + expectedValueOfNormallyDistributedConstrainedData + (ConstrainedDataHolder_T& ioConstrainedDataHolder, + Mean_T& iMean, StandardDeviation_T& iSD) { + + } + +} Added: trunk/rmol/rmol/bom/ExpectationMaximization.hpp =================================================================== --- trunk/rmol/rmol/bom/ExpectationMaximization.hpp (rev 0) +++ trunk/rmol/rmol/bom/ExpectationMaximization.hpp 2009-09-30 16:59:52 UTC (rev 264) @@ -0,0 +1,27 @@ +#ifndef __RMOL_BOM_EXPECTATION_MAXIMIZATION_HPP +#define __RMOL_BOM_EXPECTATION_MAXIMIZATION_HPP + + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// RMOL +#include <rmol/RMOL_UNCONSTRAINER_Types.hpp> +#include <rmol/RMOL_UTILITY_Types.hpp> + +namespace RMOL { + + class ExpectationMaximization { + public : + static void unconstrainData + (ConstrainedDataHolder_T& ioConstrainedDataHolder, + UnconstrainedDataHolder_T& iUnconstrainedDataHolder, + StoppingCriterion_T& iStoppingCriterion); + + static void expectedValueOfNormallyDistributedConstrainedData + (ConstrainedDataHolder_T& ioConstrainedDataHolder, + Mean_T&, StandardDeviation_T&); + + }; +} +#endif // __RMOL_BOM_EXPECTATION_MAXIMIZATION_HPP Modified: trunk/rmol/rmol/bom/sources.mk =================================================================== --- trunk/rmol/rmol/bom/sources.mk 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/bom/sources.mk 2009-09-30 16:59:52 UTC (rev 264) @@ -22,10 +22,8 @@ $(top_srcdir)/rmol/bom/StatAggregatorStruct.hpp \ $(top_srcdir)/rmol/bom/StatAggregatorStructList.hpp \ $(top_srcdir)/rmol/bom/StudyStatManager.hpp \ - $(top_srcdir)/rmol/bom/HistoricalBooking.hpp \ - $(top_srcdir)/rmol/bom/HistoricalBookingHolder.hpp \ - $(top_srcdir)/rmol/bom/HistoricalBookingHolderHolder.hpp \ - $(top_srcdir)/rmol/bom/QForecaster.hpp + $(top_srcdir)/rmol/bom/ExpectationMaximization.hpp \ + $(top_srcdir)/rmol/bom/QForecaster.hpp bom_cc_sources = $(top_srcdir)/rmol/bom/BomAbstract.cpp \ $(top_srcdir)/rmol/bom/Bucket.cpp \ $(top_srcdir)/rmol/bom/BucketHolder.cpp \ @@ -43,4 +41,5 @@ $(top_srcdir)/rmol/bom/MAForecast.cpp \ $(top_srcdir)/rmol/bom/StatAggregatorStruct.cpp \ $(top_srcdir)/rmol/bom/StudyStatManager.cpp \ + $(top_srcdir)/rmol/bom/ExpectationMaximization.cpp \ $(top_srcdir)/rmol/bom/QForecaster.cpp Modified: trunk/rmol/rmol/command/Unconstrainer.cpp =================================================================== --- trunk/rmol/rmol/command/Unconstrainer.cpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/command/Unconstrainer.cpp 2009-09-30 16:59:52 UTC (rev 264) @@ -1,20 +1,44 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +// STL +#include <iostream> +// #include <fstream> // RMOL +#include <rmol/service/Logger.hpp> +#include <rmol/RMOL_UNCONSTRAINER_Types.hpp> +#include <rmol/command/Utilities.hpp> #include <rmol/command/Unconstrainer.hpp> -// #include <rmol/bom/Bucket.hpp> -// #include <rmol/bom/BucketHolder.hpp> -// #include <rmol/bom/HistoricalBooking.hpp> -// #include <rmol/bom/HistoricalBookingHolder.hpp> -// #include <rmol/bom/HistoricalBookingHolderHolder.hpp> +#include <rmol/bom/ExpectationMaximization.hpp> - namespace RMOL { // ////////////////////////////////////////////////////////////////////// - void Unconstrainer::demandUnconstrainByExpectationMaximization () { } + void Unconstrainer::dataUnconstrainByExpectationMaximization + (ConstrainedDataHolder_T& ioConstrainedDataHolder, + UnconstrainedDataHolder_T& iUnconstrainedDataHolder, + StoppingCriterion_T& iStoppingCriterion) { + + // Debug message + std::ostringstream oDebugStr; + oDebugStr << "Before unconstraining, the constrained Data are " + << Utilities::vectorToString(ioConstrainedDataHolder) << "." + << "Unconstrained Data are " + << Utilities::vectorToString(iUnconstrainedDataHolder) + << "." ; + // Unconstrain + ExpectationMaximization::unconstrainData + (ioConstrainedDataHolder, iUnconstrainedDataHolder, iStoppingCriterion); + + // Debug message + oDebugStr << "After unconstraining, the constrained Data are " + << Utilities::vectorToString(ioConstrainedDataHolder) << "."; + + RMOL_LOG_DEBUG (oDebugStr.str()); + + } + // ////////////////////////////////////////////////////////////////////// } Modified: trunk/rmol/rmol/command/Unconstrainer.hpp =================================================================== --- trunk/rmol/rmol/command/Unconstrainer.hpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/command/Unconstrainer.hpp 2009-09-30 16:59:52 UTC (rev 264) @@ -5,14 +5,11 @@ // Import section // ////////////////////////////////////////////////////////////////////// // RMOL -#include <rmol/RMOL_Types.hpp> +#include <rmol/RMOL_UNCONSTRAINER_Types.hpp> +#include <rmol/RMOL_UTILITY_Types.hpp> namespace RMOL { - /** Forward declarations. */ - class BucketHolder; - struct HistoricalBookingHolderHolder; - /** Class wrapping the principal unconstraining algorithms and some accessory algorithms. */ class Unconstrainer { @@ -22,7 +19,9 @@ Expectation Maximization algorithm.<br> Reference: K.T. Talluri and G.Van Ryzin, The Theory and Practice of Revenue Management. */ - static void demandUnconstrainByExpectationMaximization (); + static void dataUnconstrainByExpectationMaximization + (ConstrainedDataHolder_T&, UnconstrainedDataHolder_T&, StoppingCriterion_T&); + }; } #endif // __RMOL_COMMAND_UNCONSTRAINER_HPP Modified: trunk/rmol/rmol/command/Utilities.cpp =================================================================== --- trunk/rmol/rmol/command/Utilities.cpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/command/Utilities.cpp 2009-09-30 16:59:52 UTC (rev 264) @@ -12,7 +12,7 @@ #include <functional> // RMOL #include <rmol/command/Utilities.hpp> - +#include <rmol/service/Logger.hpp> namespace RMOL { // ///////////////////////////////////////////////////////////////////// @@ -27,6 +27,16 @@ } // ///////////////////////////////////////////////////////////////////// + void Utilities::sumUpElements (double& oSum, std::vector<double>& iVector) + { + const unsigned int lSize = iVector.size(); + if (lSize > 0) { + oSum = std::accumulate(iVector.begin(), iVector.end(),0); + } + else {RMOL_LOG_ERROR ("There is no element to sum up.");} + } + + // ///////////////////////////////////////////////////////////////////// void Utilities::getMean (double& oMean, std::vector<double>& iVector) { assert(!iVector.empty()); double lSum = std::accumulate(iVector.begin(), iVector.end(),0); @@ -35,6 +45,24 @@ } // ///////////////////////////////////////////////////////////////////// + void Utilities::getSquaredError (double& oSquaredError, + std::vector<double>& iVector, + double& iMean) { + if (iMean < 0) {RMOL_LOG_ERROR ("Negative mean is not expected.");} + else { + const unsigned int lSize = iVector.size(); + if (lSize > 0) { + oSquaredError = 0.0; + for (unsigned int j = 0; j < lSize; j++) { + const double lError = iVector.at(j) - iMean; + oSquaredError += lError * lError; + } + } + else {RMOL_LOG_ERROR ("No value to compute the squared error");} + } + } + + // ///////////////////////////////////////////////////////////////////// void Utilities::getStandardDeviation (double& oSD, std::vector<double>& iVector, double& iMean) { @@ -110,7 +138,22 @@ ioVector.at(k) = ioVector.at(k) + iVector.at(k); } } + // ///////////////////////////////////////////////////////////////////// + static void appendAVectorToAnother (std::vector<double>& ioVector, + std::vector<double>& iVector) { + ioVector.insert(ioVector.end(), iVector.begin(), iVector.end()); + } + + // // ///////////////////////////////////////////////////////////////////// + // static void overwriteAVectorWithAnotherFromAPosition + // (std::vector<double>& ioVector, + // std::vector<double>& iVector, + // std::vector<double>::iterator fromThisPosition) { + // ioVector.insert(ioVector.end(), iVector.begin(), iVector.end()); + // } + + // ///////////////////////////////////////////////////////////////////// std::string Utilities::vectorToString (std::vector<double>& iVector) { std::ostringstream oStr; for (unsigned int k = 0; k < iVector.size(); k++) { Modified: trunk/rmol/rmol/command/Utilities.hpp =================================================================== --- trunk/rmol/rmol/command/Utilities.hpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/command/Utilities.hpp 2009-09-30 16:59:52 UTC (rev 264) @@ -5,6 +5,7 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <vector> +#include <string> namespace RMOL { @@ -13,9 +14,17 @@ /** Returns the minimum element of a given vector*/ static void getMinimumElement (double& oMinValue, std::vector<double>&); + /** Return the sum of all elements of a given vector*/ + static void sumUpElements (double& oSum, std::vector<double>&); + /** Return mean for the given elements of a vector. */ static void getMean (double& oMean, std::vector<double>&); + /** Return squared error. */ + static void getSquaredError (double& oSquaredError, + std::vector<double>&, + double& iMean); + /** Return standard deviation for the given elements of a vector and precomputed mean. */ static void getStandardDeviation (double& oSD, std::vector<double>&, @@ -37,6 +46,10 @@ static void addTwoVectors (std::vector<double>& ioVector, std::vector<double>& iVector); + /** Return a vector after appending another vector at the end. */ + static void appendAVectorToAnother (std::vector<double>& ioVector, + std::vector<double>& iVector); + /** Return a string constructed by the elements of a vector. */ static std::string vectorToString (std::vector<double>& iVector); Modified: trunk/rmol/rmol/core/sources.mk =================================================================== --- trunk/rmol/rmol/core/sources.mk 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/core/sources.mk 2009-09-30 16:59:52 UTC (rev 264) @@ -1,4 +1,6 @@ service_h_sources = $(top_srcdir)/rmol/RMOL_Types.hpp \ $(top_srcdir)/rmol/RMOL_Service.hpp \ - $(top_srcdir)/rmol/RMOL_FORECASTER_Types.hpp + $(top_srcdir)/rmol/RMOL_FORECASTER_Types.hpp \ + $(top_srcdir)/rmol/RMOL_UNCONSTRAINER_Types.hpp \ + $(top_srcdir)/rmol/RMOL_UTILITY_Types.hpp service_cc_sources = Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-09-28 17:48:30 UTC (rev 263) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2009-09-30 16:59:52 UTC (rev 264) @@ -428,11 +428,11 @@ } // /////////////////////////////////////////////////////////////////////// - void demandUnconstrainingByExpectationMaximization () { + void dataUnconstrainingByExpectationMaximization () { // DEBUG std::ostringstream logStream; - logStream << "Testing demand unconstraining by Expectation Maximization"; + logStream << "Testing data unconstraining by Expectation Maximization"; RMOL_LOG_DEBUG (logStream.str()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dk...@us...> - 2009-10-05 13:07:08
|
Revision: 267 http://rmol.svn.sourceforge.net/rmol/?rev=267&view=rev Author: dkchoe Date: 2009-10-05 13:06:51 +0000 (Mon, 05 Oct 2009) Log Message: ----------- Used vector iterators and some code clean-up Modified Paths: -------------- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp trunk/rmol/rmol/RMOL_UTILITY_Types.hpp trunk/rmol/rmol/bom/ExpectationMaximization.cpp trunk/rmol/rmol/bom/QForecaster.cpp trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Utilities.cpp trunk/rmol/rmol/command/Utilities.hpp Modified: trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-10-02 09:38:34 UTC (rev 266) +++ trunk/rmol/rmol/RMOL_FORECASTER_Types.hpp 2009-10-05 13:06:51 UTC (rev 267) @@ -32,7 +32,7 @@ typedef std::vector<double> HistoricalDataHolder_T; /** Define vector of historical data vector*/ - typedef std::vector< std::vector<double> > HistoricalDataHolderHolder_T; + typedef std::vector<HistoricalDataHolder_T> HistoricalDataHolderHolder_T; /** Define a holder for Q-equivalent demand parameters. */ typedef std::vector<double> QEquivalentDemandParameterHolder_T; Modified: trunk/rmol/rmol/RMOL_UTILITY_Types.hpp =================================================================== --- trunk/rmol/rmol/RMOL_UTILITY_Types.hpp 2009-10-02 09:38:34 UTC (rev 266) +++ trunk/rmol/rmol/RMOL_UTILITY_Types.hpp 2009-10-05 13:06:51 UTC (rev 267) @@ -18,6 +18,7 @@ /** Define a standard deviation type. */ typedef double StandardDeviation_T; - + /** Define a position in a vector. */ + typedef int PositionInAVector_T; } #endif // __RMOL_RMOL_UTILITY_TYPES_HPP Modified: trunk/rmol/rmol/bom/ExpectationMaximization.cpp =================================================================== --- trunk/rmol/rmol/bom/ExpectationMaximization.cpp 2009-10-02 09:38:34 UTC (rev 266) +++ trunk/rmol/rmol/bom/ExpectationMaximization.cpp 2009-10-05 13:06:51 UTC (rev 267) @@ -40,8 +40,9 @@ Utilities::sumUpElements (lSumOfUnconstrainedData, iUnconstrainedDataHolder); lCompleteDataMean = lSumOfUnconstrainedData / NoOfUnconstrainedData; - Utilities::getSquaredError (lSqErrorOfUnconstrainedData, - iUnconstrainedDataHolder, lCompleteDataMean); + Utilities::updateSquaredError (lSqErrorOfUnconstrainedData, + iUnconstrainedDataHolder, + lCompleteDataMean); lCompleteDataSD = sqrt(lSqErrorOfUnconstrainedData / (NoOfUnconstrainedData-1)); @@ -74,11 +75,12 @@ lEstimatedMean = (lEstimatedMean + lSumOfUnconstrainedData) / lTotalNumberOfData; // S.D. - Utilities::getSquaredError (lSqErrorOfUnconstrainedData, - iUnconstrainedDataHolder, lEstimatedMean); - Utilities::getSquaredError (lSqErrorOfConstrainedData, - lUnconstrainedDataDuringIteration, - lEstimatedMean); + Utilities::updateSquaredError (lSqErrorOfUnconstrainedData, + iUnconstrainedDataHolder, + lEstimatedMean); + Utilities::updateSquaredError (lSqErrorOfConstrainedData, + lUnconstrainedDataDuringIteration, + lEstimatedMean); lEstimatedSD = sqrt((lSqErrorOfUnconstrainedData + lSqErrorOfConstrainedData) / (lTotalNumberOfData-1)); Modified: trunk/rmol/rmol/bom/QForecaster.cpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.cpp 2009-10-02 09:38:34 UTC (rev 266) +++ trunk/rmol/rmol/bom/QForecaster.cpp 2009-10-05 13:06:51 UTC (rev 267) @@ -5,11 +5,10 @@ #include <cmath> #include <algorithm> #include <numeric> -#include <iostream> +#include <sstream> #include <fstream> // RMOL -// #include <rmol/bom/Bucket.hpp> -// #include <rmol/bom/BucketHolder.hpp> +#include <rmol/RMOL_UTILITY_Types.hpp> #include <rmol/bom/QForecaster.hpp> #include <rmol/command/Utilities.hpp> #include <rmol/service/Logger.hpp> @@ -44,7 +43,7 @@ for (unsigned short j = 0; j < iPriceHolder.size(); j++){ const double lYield = iPriceHolder.at(j); const double probSellup = - exp(-iSellupFactorHolder.at(j) * (lYield / iQYield - 1)); + std::exp(-iSellupFactorHolder.at(j) * (lYield / iQYield - 1)); ioSellupProbabilityVector.push_back(probSellup); } } @@ -61,22 +60,27 @@ // 1. Calculate Q-equivalent demand parameters // Initialize a holder for Q-equivalent Demands - // std::vector<double> aZeroVector (iSellupProbabilityVector.size(), 0); - // std::vector<double>& lQEquivalentDemandHolder = aZeroVector; - - // Initialize 0 vector with the size of a data holder + // 0 vector with the size of a data holder + HistoricalDataHolder_T aHistoricalDataHolder = + iHistoricalDataHolderHolder.at(0); QEquivalentDemandHolder_T lQEquivalentDemandHolder - (iHistoricalDataHolderHolder.at(0).size(), 0); - for (unsigned int j = 0; j < iHistoricalDataHolderHolder.size(); j++) { + (aHistoricalDataHolder.size(), 0); + // Index + unsigned int j = 0; + std::vector<HistoricalDataHolder_T>::iterator itHDHolderHolder; + for (itHDHolderHolder = iHistoricalDataHolderHolder.begin(); + itHDHolderHolder != iHistoricalDataHolderHolder.end(); + ++itHDHolderHolder, ++j) { // Retrieve HistoricalDataHolder which are the data of the same product // over different dates - HistoricalDataHolder_T lHistoricalDataHolder = - iHistoricalDataHolderHolder.at(j); - double lSellupProbability = iSellupProbabilityVector.at(j); + HistoricalDataHolder_T lHistoricalDataHolder = *itHDHolderHolder; + const SellupProbability_T lSellupProbability = + iSellupProbabilityVector.at(j); + const double lQDemandRate = static_cast<double> (1/lSellupProbability); // Apply sellup probability to historical data Utilities::multiplyAValueToAVector (lHistoricalDataHolder, - 1/lSellupProbability); + lQDemandRate); oDebugStr << "Q-equivalent demand of a product for each date " << Utilities::vectorToString (lHistoricalDataHolder); @@ -88,7 +92,7 @@ << Utilities::vectorToString (lQEquivalentDemandHolder); // 2. Compute Q-equivalent demand mean and standard deviation - Utilities::getMeanAndStandardDeviation (ioQEquivalentDemandParameterHolder, + Utilities::updateMeanAndStandardDeviation (ioQEquivalentDemandParameterHolder, lQEquivalentDemandHolder); RMOL_LOG_DEBUG (oDebugStr.str()); } @@ -99,7 +103,7 @@ QEquivalentDemandParameterHolder_T& iQEquivalentDemandParameterHolder, SellupProbabilityVector_T& iSellupProbabilityVector) { - NumberOfProducts_T noOfClasses = iSellupProbabilityVector.size(); + const NumberOfProducts_T noOfClasses = iSellupProbabilityVector.size(); // Sort sellup probabilities in increasing order and copy into a vector SellupProbabilityVector_T lSortedSellupProbabilityVector(noOfClasses); @@ -111,23 +115,29 @@ // Compute the probability to sell-up to class i but not i-1 (class // with the next higher fare) and copy into a vector SellupProbabilityVector_T lSellupProbabilityDifferenceVector(noOfClasses); - adjacent_difference (lSortedSellupProbabilityVector.begin(), + std::adjacent_difference (lSortedSellupProbabilityVector.begin(), lSortedSellupProbabilityVector.end(), lSellupProbabilityDifferenceVector.begin()); // Partition Q-equivalent demand mean and S.D. into each class + unsigned int k = 0; ioForecastedDemandParameterList.clear(); - for (unsigned int k=0; k < noOfClasses; k++) { + SellupProbabilityVector_T::iterator itSellupProbabilityVector; + for (itSellupProbabilityVector = iSellupProbabilityVector.begin(); + itSellupProbabilityVector != iSellupProbabilityVector.end(); + ++itSellupProbabilityVector, ++k) { // Locate the current sell-up probability in the sorted one + SellupProbability_T sellupProbabilityInUnsortedVector = + *itSellupProbabilityVector; SellupProbabilityVector_T::iterator pos = std::lower_bound (lSortedSellupProbabilityVector.begin(), lSortedSellupProbabilityVector.end(), - iSellupProbabilityVector.at(k)); - const int posOfCurrentSellupProbInSortedVector = + sellupProbabilityInUnsortedVector); + const PositionInAVector_T posOfCurrentSellupProbInSortedVector = std::distance(lSortedSellupProbabilityVector.begin(), pos); // Find the corresponding sell-up probability difference - SellupProbability_T correspondingSellupProbability = + const SellupProbability_T correspondingSellupProbability = lSellupProbabilityDifferenceVector.at( posOfCurrentSellupProbInSortedVector); @@ -137,7 +147,7 @@ ioForecastedDemandParameterList.push_back (iQEquivalentDemandParameterHolder); ForecastedDemandParameters_T& lForecastedDemandParameters = - ioForecastedDemandParameterList.at(k); + ioForecastedDemandParameterList.at(k); Utilities::multiplyAValueToAVector (lForecastedDemandParameters, correspondingSellupProbability); } Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2009-10-02 09:38:34 UTC (rev 266) +++ trunk/rmol/rmol/command/Forecaster.cpp 2009-10-05 13:06:51 UTC (rev 267) @@ -1,16 +1,12 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -#include <math.h> +// STL +#include <cmath> #include <string> -#include <iostream> +#include <sstream> #include <fstream> // RMOL -// #include <rmol/bom/Bucket.hpp> -// #include <rmol/bom/BucketHolder.hpp> -// #include <rmol/bom/HistoricalBooking.hpp> -// #include <rmol/bom/HistoricalBookingHolder.hpp> -// #include <rmol/bom/HistoricalBookingHolderHolder.hpp> #include <rmol/bom/QForecaster.hpp> #include <rmol/command/Forecaster.hpp> #include <rmol/command/Utilities.hpp> @@ -57,15 +53,15 @@ // Debug std::ostringstream oDebugStr; oDebugStr << "Prices are " - << Utilities::vectorToString(iPriceHolder) << "\n" + << Utilities::vectorToString(iPriceHolder) << std::endl << "Sell up factors are " - << Utilities::vectorToString(iSellupFactorHolder) << "\n"; + << Utilities::vectorToString(iSellupFactorHolder) << std::endl; // Find the class with the lowest yield double lQYield; - Utilities::getMinimumElement (lQYield, iPriceHolder); + Utilities::updateMinimumElement (lQYield, iPriceHolder); // Debug - oDebugStr << "The minimum yield is " << lQYield << "\n"; + oDebugStr << "The minimum yield is " << lQYield << std::endl; // Initialize a holder for sell-up probabilities SellupProbabilityVector_T lSellupProbabilityVector; @@ -74,7 +70,7 @@ (lSellupProbabilityVector, lQYield, iPriceHolder, iSellupFactorHolder); // Debug oDebugStr << "Sell-up Probabilities are " - << Utilities::vectorToString (lSellupProbabilityVector) << "\n"; + << Utilities::vectorToString (lSellupProbabilityVector) << std::endl; // Initialize a holder for Q-equivalent Demand Parameters QEquivalentDemandParameterHolder_T lQEquivalentDemandParameterHolder; @@ -85,7 +81,7 @@ // Debug oDebugStr << "Q-equivalent demand parameters [mean, SD] = " << Utilities::vectorToString (lQEquivalentDemandParameterHolder) - << "\n"; + << std::endl; // Calculate Q-equivalent demand distribution parameters and // partition it to each class/bucket @@ -93,8 +89,11 @@ (ioForecastedDemandParameterList, lQEquivalentDemandParameterHolder, lSellupProbabilityVector); // debug - for (unsigned int k = 0; k < ioForecastedDemandParameterList.size(); k++) { - std::vector<double> lMeanAndSDOfAClass = ioForecastedDemandParameterList.at(k); + ForecastedDemandParameterList_T::iterator itForecastedDemandParameterList; + for (itForecastedDemandParameterList = ioForecastedDemandParameterList.begin(); + itForecastedDemandParameterList != ioForecastedDemandParameterList.end(); + ++itForecastedDemandParameterList) { + std::vector<double> lMeanAndSDOfAClass = *itForecastedDemandParameterList; oDebugStr << "Q-equivalent distribution parameters per class " << Utilities::vectorToString (lMeanAndSDOfAClass); } Modified: trunk/rmol/rmol/command/Utilities.cpp =================================================================== --- trunk/rmol/rmol/command/Utilities.cpp 2009-10-02 09:38:34 UTC (rev 266) +++ trunk/rmol/rmol/command/Utilities.cpp 2009-10-05 13:06:51 UTC (rev 267) @@ -7,8 +7,8 @@ #include <string> #include <sstream> #include <numeric> -#include <math.h> -#include <assert.h> +#include <cmath> +#include <cassert> #include <functional> // RMOL #include <rmol/command/Utilities.hpp> @@ -16,7 +16,7 @@ namespace RMOL { // ///////////////////////////////////////////////////////////////////// - void Utilities::getMinimumElement (double& oMinValue, + void Utilities::updateMinimumElement (double& oMinValue, std::vector<double>& iVector) { assert(!iVector.empty()); @@ -37,7 +37,7 @@ } // ///////////////////////////////////////////////////////////////////// - void Utilities::getMean (double& oMean, std::vector<double>& iVector) { + void Utilities::updateMean (double& oMean, std::vector<double>& iVector) { assert(!iVector.empty()); double lSum = std::accumulate(iVector.begin(), iVector.end(),0); oMean = lSum/iVector.size(); @@ -45,25 +45,31 @@ } // ///////////////////////////////////////////////////////////////////// - void Utilities::getSquaredError (double& oSquaredError, + void Utilities::updateSquaredError (double& oSquaredError, std::vector<double>& iVector, double& iMean) { - if (iMean < 0) {RMOL_LOG_ERROR ("Negative mean is not expected.");} - else { + if (iMean < 0) { + RMOL_LOG_ERROR ("Negative mean is not expected."); + + } else { const unsigned int lSize = iVector.size(); + if (lSize > 0) { oSquaredError = 0.0; + for (unsigned int j = 0; j < lSize; j++) { const double lError = iVector.at(j) - iMean; oSquaredError += lError * lError; } - } - else {RMOL_LOG_ERROR ("No value to compute the squared error");} + + } else { + RMOL_LOG_ERROR ("No value to compute the squared error"); + } } } // ///////////////////////////////////////////////////////////////////// - void Utilities::getStandardDeviation (double& oSD, + void Utilities::updateStandardDeviation (double& oSD, std::vector<double>& iVector, double& iMean) { assert(iMean > 0); @@ -81,7 +87,8 @@ } // ///////////////////////////////////////////////////////////////////// - void Utilities::getMeanAndStandardDeviation (std::vector<double>& ioMean_SD, + void Utilities::updateMeanAndStandardDeviation + (std::vector<double>& ioMean_SD, std::vector<double>& iVector) { const unsigned int lSize = iVector.size(); assert(lSize > 0); Modified: trunk/rmol/rmol/command/Utilities.hpp =================================================================== --- trunk/rmol/rmol/command/Utilities.hpp 2009-10-02 09:38:34 UTC (rev 266) +++ trunk/rmol/rmol/command/Utilities.hpp 2009-10-05 13:06:51 UTC (rev 267) @@ -12,27 +12,28 @@ struct Utilities { /** Returns the minimum element of a given vector*/ - static void getMinimumElement (double& oMinValue, std::vector<double>&); + static void updateMinimumElement (double& oMinValue, + std::vector<double>&); /** Return the sum of all elements of a given vector*/ static void sumUpElements (double& oSum, std::vector<double>&); /** Return mean for the given elements of a vector. */ - static void getMean (double& oMean, std::vector<double>&); + static void updateMean (double& oMean, std::vector<double>&); /** Return squared error. */ - static void getSquaredError (double& oSquaredError, - std::vector<double>&, - double& iMean); + static void updateSquaredError (double& oSquaredError, + std::vector<double>&, + double& iMean); /** Return standard deviation for the given elements of a vector and precomputed mean. */ - static void getStandardDeviation (double& oSD, std::vector<double>&, - double& iMean); + static void updateStandardDeviation (double& oSD, std::vector<double>&, + double& iMean); /** Return mean & standard deviation for given elements of a vector. */ - static void getMeanAndStandardDeviation (std::vector<double>& ioMean_SD, - std::vector<double>&); + static void updateMeanAndStandardDeviation (std::vector<double>& ioMean_SD, + std::vector<double>&); /** Return the input vector after adding a value. */ static void addAValueToAVector (std::vector<double>& ioVector, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2009-12-23 14:53:06
|
Revision: 277 http://rmol.svn.sourceforge.net/rmol/?rev=277&view=rev Author: denis_arnaud Date: 2009-12-23 14:52:54 +0000 (Wed, 23 Dec 2009) Log Message: ----------- [Build] Explicitly set the package name to 'rmol', in order to allow embedded building of the rmol library. Modified Paths: -------------- trunk/rmol/rmol/batches/Makefile.am trunk/rmol/rmol/config/Makefile.am trunk/rmol/rmol/core/Makefile.am Modified: trunk/rmol/rmol/batches/Makefile.am =================================================================== --- trunk/rmol/rmol/batches/Makefile.am 2009-10-09 09:30:33 UTC (rev 276) +++ trunk/rmol/rmol/batches/Makefile.am 2009-12-23 14:52:54 UTC (rev 277) @@ -13,4 +13,4 @@ rmol_CXXFLAGS = $(BOOST_CFLAGS) #rmol_LDADD = rmol_LDFLAGS = $(BOOST_PROGRAM_OPTIONS_LIB) \ - $(top_builddir)/@PACKAGE@/core/lib@PACKAGE@.la + $(top_builddir)/rmol/core/librmol.la Modified: trunk/rmol/rmol/config/Makefile.am =================================================================== --- trunk/rmol/rmol/config/Makefile.am 2009-10-09 09:30:33 UTC (rev 276) +++ trunk/rmol/rmol/config/Makefile.am 2009-12-23 14:52:54 UTC (rev 277) @@ -1,3 +1,4 @@ +# rmol/config include $(top_srcdir)/Makefile.common ## Source directory @@ -2,16 +3,16 @@ -DISTCLEANFILES = @PACKAGE@-paths.hpp +DISTCLEANFILES = rmol-paths.hpp MAINTAINERCLEANFILES = Makefile.in -EXTRA_DIST = @PACKAGE@-paths.hpp +EXTRA_DIST = rmol-paths.hpp # Targets -all-local: @PACKAGE@-paths.hpp +all-local: rmol-paths.hpp -@PACKAGE@-paths.hpp: Makefile - @echo '#ifndef __@PACKAGE_NAME@_PATHS_HPP' > $@ - @echo '#define __@PACKAGE_NAME@_PATHS_HPP' >> $@ - @echo '#define PACKAGE "@PACKAGE@"' >> $@ - @echo '#define PACKAGE_NAME "@PACKAGE_NAME@"' >> $@ +rmol-paths.hpp: Makefile + @echo '#ifndef __RMOL_PATHS_HPP' > $@ + @echo '#define __RMOL_PATHS_HPP' >> $@ + @echo '#define PACKAGE "rmol"' >> $@ + @echo '#define PACKAGE_NAME "RMOL"' >> $@ @echo '#define PACKAGE_VERSION "@VERSION@"' >> $@ @@ -22,4 +23,4 @@ @echo '#define LIBEXECDIR "$(libexecdir)"' >> $@ @echo '#define DATADIR "$(datadir)"' >> $@ @echo '#define DOCDIR "$(docdir)"' >> $@ - @echo '#endif // __@PACKAGE_NAME@_PATHS_HPP' >> $@ + @echo '#endif // __RMOL_PATHS_HPP' >> $@ Modified: trunk/rmol/rmol/core/Makefile.am =================================================================== --- trunk/rmol/rmol/core/Makefile.am 2009-10-09 09:30:33 UTC (rev 276) +++ trunk/rmol/rmol/core/Makefile.am 2009-12-23 14:52:54 UTC (rev 277) @@ -9,16 +9,16 @@ # Library -lib_LTLIBRARIES = lib@PACKAGE@.la +lib_LTLIBRARIES = librmol.la -lib@PACKAGE@_la_SOURCES = $(service_h_sources) $(service_cc_sources) -lib@PACKAGE@_la_LIBADD = \ - $(top_builddir)/@PACKAGE@/basic/libbas.la \ - $(top_builddir)/@PACKAGE@/field/libfld.la \ - $(top_builddir)/@PACKAGE@/bom/libbom.la \ - $(top_builddir)/@PACKAGE@/factory/libfac.la \ - $(top_builddir)/@PACKAGE@/command/libcmd.la \ - $(top_builddir)/@PACKAGE@/service/libsvc.la -lib@PACKAGE@_la_LDFLAGS = \ +librmol_la_SOURCES = $(service_h_sources) $(service_cc_sources) +librmol_la_LIBADD = \ + $(top_builddir)/rmol/basic/libbas.la \ + $(top_builddir)/rmol/field/libfld.la \ + $(top_builddir)/rmol/bom/libbom.la \ + $(top_builddir)/rmol/factory/libfac.la \ + $(top_builddir)/rmol/command/libcmd.la \ + $(top_builddir)/rmol/service/libsvc.la +librmol_la_LDFLAGS = \ $(BOOST_DATE_TIME_LIB) $(BOOST_PROGRAM_OPTIONS_LIB) \ $(GSL_LIBS) -version-info $(GENERIC_LIBRARY_VERSION) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-01-20 16:41:44
|
Revision: 283 http://rmol.svn.sourceforge.net/rmol/?rev=283&view=rev Author: denis_arnaud Date: 2010-01-20 16:41:38 +0000 (Wed, 20 Jan 2010) Log Message: ----------- [Dev] Removed the BasChronometer class, as it is now given by the StdAir library. Modified Paths: -------------- trunk/rmol/rmol/basic/sources.mk trunk/rmol/rmol/service/RMOL_Service.cpp Removed Paths: ------------- trunk/rmol/rmol/basic/BasChronometer.cpp trunk/rmol/rmol/basic/BasChronometer.hpp Deleted: trunk/rmol/rmol/basic/BasChronometer.cpp =================================================================== --- trunk/rmol/rmol/basic/BasChronometer.cpp 2009-12-29 13:24:06 UTC (rev 282) +++ trunk/rmol/rmol/basic/BasChronometer.cpp 2010-01-20 16:41:38 UTC (rev 283) @@ -1,50 +0,0 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> -// Rmol -#include <rmol/basic/BasChronometer.hpp> -#include <rmol/service/Logger.hpp> - -namespace RMOL { - - // ////////////////////////////////////////////////////////////////////// - BasChronometer::BasChronometer () : _startTimeLaunched (false) { - } - - // ////////////////////////////////////////////////////////////////////// - void BasChronometer::start () { - // Get the time-stamp of now, and store it for later use - _startTime = boost::posix_time::microsec_clock::local_time(); - - // Update the boolean which states whether the chronometer - // is launched - _startTimeLaunched = true; - } - - // ////////////////////////////////////////////////////////////////////// - double BasChronometer::elapsed () const { - assert (_startTimeLaunched == true); - - // Get the time-stamp of now - const boost::posix_time::ptime lStopTime = - boost::posix_time::microsec_clock::local_time(); - - // Calculate the time elapsed since the last time-stamp - const boost::posix_time::time_duration lElapsedTime = - lStopTime - _startTime; - - // Derived the corresponding number of milliseconds - const double lElapsedTimeInMicroSeconds = - static_cast<const double> (lElapsedTime.total_microseconds()); - - /*RMOL_LOG_DEBUG ("Elapsed: " << lElapsedTime - << "; (micros): " - << lElapsedTimeInMicroSeconds / 1e6);*/ - - // The elapsed time given in return is expressed in seconds - return (lElapsedTimeInMicroSeconds / 1e6); - } - -} Deleted: trunk/rmol/rmol/basic/BasChronometer.hpp =================================================================== --- trunk/rmol/rmol/basic/BasChronometer.hpp 2009-12-29 13:24:06 UTC (rev 282) +++ trunk/rmol/rmol/basic/BasChronometer.hpp 2010-01-20 16:41:38 UTC (rev 283) @@ -1,40 +0,0 @@ -#ifndef __RMOL_COM_BAS_BASCHRONOMETER_HPP -#define __RMOL_COM_BAS_BASCHRONOMETER_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// Boost Date-Time (http://boost.org/doc/html/date_time/posix_time.html) -#include <boost/date_time/posix_time/posix_time.hpp> - -namespace RMOL { - - /** Structure allowing measuring the time elapsed between two events. */ - struct BasChronometer { - /** Constructor. */ - BasChronometer(); - - /** Start the chronometer from the local time - <br>The elapsed time given is the one elapsed since the start - is launched. */ - void start (); - - /** Get the start time. */ - std::string getStart () const { - return boost::posix_time::to_simple_string (_startTime); - } - - /** Return the time elapsed since the structure has been instanciated. - <br>That elapsed time is expressed in seconds. */ - double elapsed () const; - - private: - /** Start time. */ - boost::posix_time::ptime _startTime; - - /** Boolean which states whether the chronometer is started or not.*/ - bool _startTimeLaunched; - }; - -} -#endif // __RMOL_COM_BAS_BASCHRONOMETER_HPP Modified: trunk/rmol/rmol/basic/sources.mk =================================================================== --- trunk/rmol/rmol/basic/sources.mk 2009-12-29 13:24:06 UTC (rev 282) +++ trunk/rmol/rmol/basic/sources.mk 2010-01-20 16:41:38 UTC (rev 283) @@ -1,6 +1,4 @@ bas_h_sources = $(top_srcdir)/rmol/basic/BasConst_General.hpp \ $(top_srcdir)/rmol/basic/BasConst_Overbooking.hpp \ - $(top_srcdir)/rmol/basic/BasConst_RMOL_Service.hpp \ - $(top_srcdir)/rmol/basic/BasChronometer.hpp -bas_cc_sources = $(top_srcdir)/rmol/basic/BasConst.cpp \ - $(top_srcdir)/rmol/basic/BasChronometer.cpp + $(top_srcdir)/rmol/basic/BasConst_RMOL_Service.hpp +bas_cc_sources = $(top_srcdir)/rmol/basic/BasConst.cpp Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2009-12-29 13:24:06 UTC (rev 282) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2010-01-20 16:41:38 UTC (rev 283) @@ -1,12 +1,13 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> // STL +#include <cassert> #include <iomanip> #include <sstream> #include <iostream> +// StdAir +#include <stdair/basic/BasChronometer.hpp> // RMOL #include <rmol/basic/BasConst_RMOL_Service.hpp> #include <rmol/field/FldYieldRange.hpp> @@ -152,11 +153,14 @@ const double iCapacity = _rmolServiceContext->getCapacity(); BucketHolder* oBucketHolder_ptr = _rmolServiceContext->getBucketHolder(); assert (oBucketHolder_ptr != NULL); + BidPriceVector_T lBidPriceVector; - StudyStatManager* lStudyStatManager_ptr = _rmolServiceContext->getStudyStatManager(); + stdair::BasChronometer lOptimisationChronometer; + lOptimisationChronometer.start(); + if (lStudyStatManager_ptr == NULL) { Optimiser::optimalOptimisationByMCIntegration (K, iCapacity, *oBucketHolder_ptr, @@ -167,8 +171,13 @@ lBidPriceVector, *lStudyStatManager_ptr); } + + const double lOptimisationMeasure = lOptimisationChronometer.elapsed(); + // DEBUG - RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); + RMOL_LOG_DEBUG ("Optimisation by Monte-Carlo performed in " + << lOptimisationMeasure); + RMOL_LOG_DEBUG ("Resulting buckets: " << oBucketHolder_ptr->display()); std::ostringstream logStream; logStream << "Bid-Price Vector (BPV): "; @@ -452,6 +461,5 @@ iSellupFactorHolder); } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-01-20 16:51:25
|
Revision: 284 http://rmol.svn.sourceforge.net/rmol/?rev=284&view=rev Author: denis_arnaud Date: 2010-01-20 16:51:17 +0000 (Wed, 20 Jan 2010) Log Message: ----------- [Dev] Removed the BasChronometer class, as it is now given by the StdAir library. Modified Paths: -------------- trunk/rmol/rmol/bom/MCOptimiser.cpp trunk/rmol/rmol/command/Optimiser.cpp trunk/rmol/rmol/core/Makefile.am Modified: trunk/rmol/rmol/bom/MCOptimiser.cpp =================================================================== --- trunk/rmol/rmol/bom/MCOptimiser.cpp 2010-01-20 16:41:38 UTC (rev 283) +++ trunk/rmol/rmol/bom/MCOptimiser.cpp 2010-01-20 16:51:17 UTC (rev 284) @@ -1,15 +1,15 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> // STL +#include <cassert> #include <string> #include <fstream> #include <sstream> #include <cmath> +// StdAir +#include <stdair/basic/BasChronometer.hpp> // RMOL -#include <rmol/basic/BasChronometer.hpp> #include <rmol/bom/StudyStatManager.hpp> #include <rmol/bom/VariateList.hpp> #include <rmol/bom/Gaussian.hpp> @@ -259,9 +259,9 @@ // Retrieve the BucketHolder // BucketHolder& ioBucketHolder = ioResource.getBucketHolder(); - BasChronometer lDrawBasChronometer; - BasChronometer lSortBasChronometer; - BasChronometer lBVPCalculationBasChronometer; + stdair::BasChronometer lDrawBasChronometer; + stdair::BasChronometer lSortBasChronometer; + stdair::BasChronometer lBVPCalculationBasChronometer; // Number of classes/buckets: n const short nbOfClasses = ioBucketHolder.getSize(); Modified: trunk/rmol/rmol/command/Optimiser.cpp =================================================================== --- trunk/rmol/rmol/command/Optimiser.cpp 2010-01-20 16:41:38 UTC (rev 283) +++ trunk/rmol/rmol/command/Optimiser.cpp 2010-01-20 16:51:17 UTC (rev 284) @@ -1,14 +1,14 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> // STL +#include <cassert> //#include <cmath> #include <sstream> #include <iomanip> +// StdAir +#include <stdair/basic/BasChronometer.hpp> // RMOL -#include <rmol/basic/BasChronometer.hpp> #include <rmol/field/FldYieldRange.hpp> #include <rmol/field/FldDistributionParameters.hpp> #include <rmol/bom/StudyStatManager.hpp> @@ -70,7 +70,7 @@ BucketHolder& ioBucketHolder, BidPriceVector_T& ioBidPriceVector, StudyStatManager& ioStudyStatManager) { - BasChronometer lMCIntegrationBasChrono; + stdair::BasChronometer lMCIntegrationBasChrono; lMCIntegrationBasChrono.start(); // Retrieve the BucketHolder // BucketHolder& ioBucketHolder = ioResource.getBucketHolder(); @@ -153,7 +153,7 @@ BucketHolder& ioBucketHolder, BidPriceVector_T& ioBidPriceVector, StudyStatManager& ioStudyStatManager) { - BasChronometer lEMRSBasChrono; + stdair::BasChronometer lEMRSBasChrono; lEMRSBasChrono.start(); Emsr::heuristicOptimisationByEmsr (iCabinCapacity, ioBucketHolder, Modified: trunk/rmol/rmol/core/Makefile.am =================================================================== --- trunk/rmol/rmol/core/Makefile.am 2010-01-20 16:41:38 UTC (rev 283) +++ trunk/rmol/rmol/core/Makefile.am 2010-01-20 16:51:17 UTC (rev 284) @@ -21,4 +21,5 @@ $(top_builddir)/rmol/service/libsvc.la librmol_la_LDFLAGS = \ $(BOOST_DATE_TIME_LIB) $(BOOST_PROGRAM_OPTIONS_LIB) \ + $(top_builddir)/stdair/core/libstdair.la \ $(GSL_LIBS) -version-info $(GENERIC_LIBRARY_VERSION) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-01-21 19:33:24
|
Revision: 289 http://rmol.svn.sourceforge.net/rmol/?rev=289&view=rev Author: denis_arnaud Date: 2010-01-21 19:33:17 +0000 (Thu, 21 Jan 2010) Log Message: ----------- [Dev] The log output stream initialisation has been moved into the StdAir library. Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/batches/rmol.cpp trunk/rmol/rmol/bom/DPOptimiser.cpp trunk/rmol/rmol/bom/ExpectationMaximization.cpp trunk/rmol/rmol/bom/MCOptimiser.cpp trunk/rmol/rmol/bom/QForecaster.cpp trunk/rmol/rmol/bom/StatAggregatorStruct.cpp trunk/rmol/rmol/bom/StudyStatManager.cpp trunk/rmol/rmol/command/FileMgr.cpp trunk/rmol/rmol/command/Forecaster.cpp trunk/rmol/rmol/command/Optimiser.cpp trunk/rmol/rmol/command/Unconstrainer.cpp trunk/rmol/rmol/command/Utilities.cpp trunk/rmol/rmol/factory/FacStudyStatManager.cpp trunk/rmol/rmol/factory/FacSupervisor.cpp trunk/rmol/rmol/factory/FacSupervisor.hpp trunk/rmol/rmol/service/RMOL_Service.cpp trunk/rmol/rmol/service/sources.mk Removed Paths: ------------- trunk/rmol/rmol/service/Logger.cpp trunk/rmol/rmol/service/Logger.hpp Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/RMOL_Service.hpp 2010-01-21 19:33:17 UTC (rev 289) @@ -6,6 +6,9 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <string> +// StdAir +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/BasLogParams.hpp> // RMOL #include <rmol/RMOL_Types.hpp> #include <rmol/RMOL_FORECASTER_Types.hpp> @@ -20,48 +23,7 @@ /** Interface for the RMOL Services. */ class RMOL_Service { public: - /** Constructor. */ - RMOL_Service (std::ostream& ioLogStream); - - RMOL_Service (std::ostream& ioLogStream, - const ResourceCapacity_T iResourceCapacity); - /** Destructor. */ - ~RMOL_Service(); - - /** Set up the StudyStatManager. */ - void setUpStudyStatManager (); - - /** Set the cabin availability. */ - void setResourceCapacity (const ResourceCapacity_T iResourceCapacity); - - /** Add a bucket to the context. */ - void addBucket (const double iYieldRange, const double iDemandMean, - const double iDemandStandardDev); - - /** Add a bucket to the context. */ - void addBucket (const double iYieldRange, const double iDemandMean, - const double iDemandStandardDev, - GeneratedDemandVector_T* ioGeneratedDemandVector); - - /** Generate demand for a given (Gaussian) distribution. */ - GeneratedDemandVector_T* generateDemand (const int K, - const double& iMean, - const double& iDeviation); - - /** Sum the two generated demand vectors . */ - GeneratedDemandVector_T* generateDemand (GeneratedDemandVector_T*, - GeneratedDemandVector_T*); - - /** Read the input data from a file. */ - void readFromInputFile (const std::string& iInputFileName); - - /** Build the context with the generated demand for Monte-Carlo - Integration algorithm. */ - void buildContextForMC (const int K); - - /** Clear the context (cabin capacity, bucket holder). */ - void reset (); - + // /////////// Business Methods ///////////// /** Single resource optimization using the Monte Carlo algorithm. */ void optimalOptimisationByMCIntegration (const int K); @@ -138,20 +100,103 @@ PriceHolder_T&, SellupFactorHolder_T&); + + // ////////// Constructors and destructors ////////// + /** Constructor. + <br>The init() method is called; see the corresponding documentation + for more details. + <br>Moreover, a reference on an output stream is given, so + that log outputs can be directed onto that stream. + @param const stdair::BasLogParams& Parameters for the output log + stream. */ + RMOL_Service (const stdair::BasLogParams&); + + /** Constructor. + <br>The init() method is called; see the corresponding documentation + for more details. + <br>Moreover, as no reference on any output stream is given, + it is assumed that the StdAir log service has already been + initialised with the proper log output stream by some other + methods in the calling chain (for instance, when the RMOL_Service + is itself being initialised by another library service such as + AIRINV_Service). */ + RMOL_Service (); + + /** Constructor. + <br>The init() method is called; see the corresponding documentation + for more details. + <br>Moreover, a reference on an output stream is given, so + that log outputs can be directed onto that stream. + @param const stdair::BasLogParams& Parameters for the output log stream. + @param const ResourceCapacity_T Capacity of the resource to optimise. */ + RMOL_Service (const stdair::BasLogParams&, const ResourceCapacity_T); + + /** Constructor. + <br>The init() method is called; see the corresponding documentation + for more details. + <br>Moreover, as no reference on any output stream is given, + it is assumed that the StdAir log service has already been + initialised with the proper log output stream by some other + methods in the calling chain (for instance, when the RMOL_Service + is itself being initialised by another library service such as + AIRINV_Service). + @param const ResourceCapacity_T Capacity of the resource to optimise. */ + RMOL_Service (const ResourceCapacity_T); + + /** Destructor. */ + ~RMOL_Service(); + + + // //////// Initialisation support methods /////////// + /** Set up the StudyStatManager. */ + void setUpStudyStatManager (); + + /** Set the cabin availability. */ + void setResourceCapacity (const ResourceCapacity_T iResourceCapacity); + + /** Add a bucket to the context. */ + void addBucket (const double iYieldRange, const double iDemandMean, + const double iDemandStandardDev); + + /** Add a bucket to the context. */ + void addBucket (const double iYieldRange, const double iDemandMean, + const double iDemandStandardDev, + GeneratedDemandVector_T* ioGeneratedDemandVector); + + /** Generate demand for a given (Gaussian) distribution. */ + GeneratedDemandVector_T* generateDemand (const int K, + const double& iMean, + const double& iDeviation); + + /** Sum the two generated demand vectors . */ + GeneratedDemandVector_T* generateDemand (GeneratedDemandVector_T*, + GeneratedDemandVector_T*); + + /** Read the input data from a file. */ + void readFromInputFile (const std::string& iInputFileName); + + /** Build the context with the generated demand for Monte-Carlo + Integration algorithm. */ + void buildContextForMC (const int K); + + /** Clear the context (cabin capacity, bucket holder). */ + void reset (); + + private: /** Default Constructors. */ - RMOL_Service (); RMOL_Service (const RMOL_Service&); + /** Initialise the log. */ + void logInit (const stdair::BasLogParams&); + /** Initialise. */ - void init (std::ostream& ioLogStream); + void init (); - void init (std::ostream& ioLogStream, - const ResourceCapacity_T iResourceCapacity); + /** Initialise. + @param const ResourceCapacity_T Capacity of the resource to optimise. */ + void init (const ResourceCapacity_T); - /** Initilise the log. */ - void logInit (const LOG::EN_LogLevel iLogLevel, std::ostream& ioLogStream); - /** Finaliser. */ void finalise (); Modified: trunk/rmol/rmol/batches/rmol.cpp =================================================================== --- trunk/rmol/rmol/batches/rmol.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/batches/rmol.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -224,7 +224,8 @@ logOutputFile.clear(); // Initialise the list of classes/buckets - RMOL::RMOL_Service rmolService (logOutputFile, lCapacity); + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + RMOL::RMOL_Service rmolService (lLogParams, lCapacity); rmolService.setUpStudyStatManager(); if (hasInputFile) { Modified: trunk/rmol/rmol/bom/DPOptimiser.cpp =================================================================== --- trunk/rmol/rmol/bom/DPOptimiser.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/bom/DPOptimiser.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -4,18 +4,18 @@ // GSL Random Number Generation (GSL Reference Manual, version 1.7, Chapter 19) #include <gsl/gsl_cdf.h> #include <gsl/gsl_randist.h> -// C -#include <assert.h> // STL +#include <cassert> #include <sstream> #include <vector> #include <cmath> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/basic/BasConst_General.hpp> #include <rmol/bom/DPOptimiser.hpp> #include <rmol/bom/Bucket.hpp> #include <rmol/bom/BucketHolder.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -159,7 +159,7 @@ ostr << currentGradient << std::endl << "x = " << x << std::endl << "class: " << currentBucketIndex << std::endl; - RMOL_LOG_DEBUG (ostr.str()); + STDAIR_LOG_DEBUG (ostr.str()); } /* @@ -183,7 +183,7 @@ } // DEBUG - RMOL_LOG_DEBUG ("Vmaxindex = " << currentMERVector.back()); + STDAIR_LOG_DEBUG ("Vmaxindex = " << currentMERVector.back()); MERVectorHolder.push_back (currentMERVector); Modified: trunk/rmol/rmol/bom/ExpectationMaximization.cpp =================================================================== --- trunk/rmol/rmol/bom/ExpectationMaximization.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/bom/ExpectationMaximization.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -1,16 +1,17 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -//GSL +// GSL #include <gsl/gsl_cdf.h> // STL -#include <math.h> +#include <cassert> +#include <cmath> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL -#include <rmol/service/Logger.hpp> #include <rmol/basic/BasConst_General.hpp> #include <rmol/command/Utilities.hpp> #include <rmol/bom/ExpectationMaximization.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -65,7 +66,7 @@ lCompleteDataMean, lCompleteDataSD); // Debug - RMOL_LOG_DEBUG ("\nUnconstrained data: " + STDAIR_LOG_DEBUG ("\nUnconstrained data: " << Utilities::vectorToString (lUnconstrainedDataDuringIteration)); // Maximization step @@ -85,7 +86,7 @@ lSqErrorOfConstrainedData) / (lTotalNumberOfData-1)); // Debug - RMOL_LOG_DEBUG ("\nEstimated Mean: " << lEstimatedMean + STDAIR_LOG_DEBUG ("\nEstimated Mean: " << lEstimatedMean << "\nnEstimated s.d.: " << lEstimatedSD); } while(fabs(lCompleteDataMean - lEstimatedMean ) > iStoppingCriterion @@ -97,13 +98,12 @@ ioConstrainedDataHolder = lUnconstrainedDataDuringIteration; } // Job finished as all are unconstrained or nothing to be unconstrained + + } else { + STDAIR_LOG_ERROR ("At least one unconstrained data is required to " + << "correct constrained data with Expectation " + << "Maximization algorithm."); } - else { - RMOL_LOG_ERROR ("At least one unconstrained data is required to " - << "correct constrained data with Expectation " - << "Maximization algorithm."); - } - } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/bom/MCOptimiser.cpp =================================================================== --- trunk/rmol/rmol/bom/MCOptimiser.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/bom/MCOptimiser.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -9,6 +9,7 @@ #include <cmath> // StdAir #include <stdair/basic/BasChronometer.hpp> +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/bom/StudyStatManager.hpp> #include <rmol/bom/VariateList.hpp> @@ -19,7 +20,6 @@ #include <rmol/bom/PartialSumHolderHolder.hpp> //#include <rmol/bom/Resource.hpp> #include <rmol/bom/MCOptimiser.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -78,7 +78,7 @@ const Gaussian gaussianDemandGenerator (aDistribParams); /** DEBUG - RMOL_LOG_DEBUG ("[" << j << "]: " << Kj << " values with N ( " + STDAIR_LOG_DEBUG ("[" << j << "]: " << Kj << " values with N ( " << aDistribParams.getMean() << ", " << aDistribParams.getStandardDeviation() << ")."); */ @@ -113,7 +113,7 @@ currentPartialSumList.addPartialSum (sjk); /* DEBUG - RMOL_LOG_DEBUG ("d(" << j << ", " << k << "); " << djk + STDAIR_LOG_DEBUG ("d(" << j << ", " << k << "); " << djk << "; S'(" << j-1 << ", " << lj+k << "); " << spjm1lpk << "; S(" << j << ", " << k << "); " << sjk); */ @@ -141,7 +141,7 @@ lj = static_cast<int> (ljdouble); /** DEBUG - RMOL_LOG_DEBUG ("p(j+1)/p(j) = " << pj1 / pj << ", lj = " << lj + STDAIR_LOG_DEBUG ("p(j+1)/p(j) = " << pj1 / pj << ", lj = " << lj << ", Kj = " << Kj << " => " << Kj - lj << " points above y(j)"); */ @@ -158,7 +158,7 @@ const double yj = (sjl + sjlp1) / 2; /** DEBUG - RMOL_LOG_DEBUG ("S(j,l) = " << sjl << ", S(j,l+1) = " << sjlp1 + STDAIR_LOG_DEBUG ("S(j,l) = " << sjl << ", S(j,l+1) = " << sjlp1 << ", y(j) = " << yj); */ @@ -311,7 +311,7 @@ const Gaussian gaussianDemandGenerator (aDistribParams); /** DEBUG - RMOL_LOG_DEBUG ("[" << j << "]: " << Kj << " values with N ( " + STDAIR_LOG_DEBUG ("[" << j << "]: " << Kj << " values with N ( " << aDistribParams.getMean() << ", " << aDistribParams.getStandardDeviation() << ")."); */ @@ -347,7 +347,7 @@ currentPartialSumList.addPartialSum (sjk); /* DEBUG - RMOL_LOG_DEBUG ("d(" << j << ", " << k << "); " << djk + STDAIR_LOG_DEBUG ("d(" << j << ", " << k << "); " << djk << "; S'(" << j-1 << ", " << lj+k << "); " << spjm1lpk << "; S(" << j << ", " << k << "); " << sjk); */ @@ -381,7 +381,7 @@ lj = static_cast<int> (ljdouble); /** DEBUG - RMOL_LOG_DEBUG ("p(j+1)/p(j) = " << pj1 / pj << ", lj = " << lj + STDAIR_LOG_DEBUG ("p(j+1)/p(j) = " << pj1 / pj << ", lj = " << lj << ", Kj = " << Kj << " => " << Kj - lj << " points above y(j)"); */ @@ -397,7 +397,7 @@ const double yj = (sjl + sjlp1) / 2; /** DEBUG - RMOL_LOG_DEBUG ("S(j,l) = " << sjl << ", S(j,l+1) = " << sjlp1 + STDAIR_LOG_DEBUG ("S(j,l) = " << sjl << ", S(j,l+1) = " << sjlp1 << ", y(j) = " << yj); */ Modified: trunk/rmol/rmol/bom/QForecaster.cpp =================================================================== --- trunk/rmol/rmol/bom/QForecaster.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/bom/QForecaster.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -7,11 +7,12 @@ #include <numeric> #include <sstream> #include <fstream> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/RMOL_UTILITY_Types.hpp> #include <rmol/bom/QForecaster.hpp> #include <rmol/command/Utilities.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -93,8 +94,10 @@ // 2. Compute Q-equivalent demand mean and standard deviation Utilities::updateMeanAndStandardDeviation (ioQEquivalentDemandParameterHolder, - lQEquivalentDemandHolder); - RMOL_LOG_DEBUG (oDebugStr.str()); + lQEquivalentDemandHolder); + + // DEBUG + STDAIR_LOG_DEBUG (oDebugStr.str()); } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/bom/StatAggregatorStruct.cpp =================================================================== --- trunk/rmol/rmol/bom/StatAggregatorStruct.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/bom/StatAggregatorStruct.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -1,15 +1,14 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> // STL +#include <cassert> #include <sstream> #include <limits> -#include <stdexcept> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/bom/StatAggregatorStruct.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -62,7 +61,7 @@ // ////////////////////////////////////////////////////////////////////// void StatAggregatorStruct_T::display() const { - RMOL_LOG_DEBUG (describe()); + STDAIR_LOG_DEBUG (describe()); } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/bom/StudyStatManager.cpp =================================================================== --- trunk/rmol/rmol/bom/StudyStatManager.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/bom/StudyStatManager.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -1,13 +1,13 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> // STL +#include <cassert> #include <sstream> #include <limits> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL Common -#include <rmol/service/Logger.hpp> #include <rmol/bom/StatAggregatorStruct.hpp> #include <rmol/bom/StudyStatManager.hpp> @@ -59,7 +59,8 @@ // Reset formatting flags of stream ostr.flags (oldFlags); - RMOL_LOG_DEBUG (ostr.str()); + // DEBUG + STDAIR_LOG_DEBUG (ostr.str()); } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/command/FileMgr.cpp =================================================================== --- trunk/rmol/rmol/command/FileMgr.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/command/FileMgr.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -2,10 +2,12 @@ // Import section // ////////////////////////////////////////////////////////////////////// // STL -#include <iostream> +#include <ostream> #include <istream> #include <sstream> #include <fstream> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/field/FldYieldRange.hpp> #include <rmol/field/FldDistributionParameters.hpp> @@ -16,7 +18,6 @@ #include <rmol/factory/FacBucket.hpp> #include <rmol/factory/FacBucketHolder.hpp> #include <rmol/command/FileMgr.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -27,7 +28,7 @@ // Open the input file std::ifstream inputFile (iInputFileName.c_str()); if (! inputFile) { - RMOL_LOG_ERROR ("Can not open input file \"" << iInputFileName << "\""); + STDAIR_LOG_ERROR ("Can not open input file \"" << iInputFileName << "\""); throw new FileNotFoundException(); } Modified: trunk/rmol/rmol/command/Forecaster.cpp =================================================================== --- trunk/rmol/rmol/command/Forecaster.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/command/Forecaster.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -2,15 +2,13 @@ // Import section // ////////////////////////////////////////////////////////////////////// // STL -#include <cmath> -#include <string> -#include <sstream> -#include <fstream> +#include <cassert> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/bom/QForecaster.hpp> #include <rmol/command/Forecaster.hpp> #include <rmol/command/Utilities.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -97,6 +95,8 @@ oDebugStr << "Q-equivalent distribution parameters per class " << Utilities::vectorToString (lMeanAndSDOfAClass); } - RMOL_LOG_DEBUG(oDebugStr.str()); + + // DEBUG + STDAIR_LOG_DEBUG(oDebugStr.str()); } } Modified: trunk/rmol/rmol/command/Optimiser.cpp =================================================================== --- trunk/rmol/rmol/command/Optimiser.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/command/Optimiser.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -3,11 +3,10 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <cassert> -//#include <cmath> #include <sstream> -#include <iomanip> // StdAir #include <stdair/basic/BasChronometer.hpp> +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/field/FldYieldRange.hpp> #include <rmol/field/FldDistributionParameters.hpp> @@ -22,7 +21,6 @@ #include <rmol/factory/FacDemand.hpp> #include <rmol/factory/FacBucket.hpp> #include <rmol/command/Optimiser.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -134,7 +132,8 @@ // Reset formatting flags of stream ostr.flags (oldFlags); - RMOL_LOG_DEBUG (ostr.str()); + // DEBUG + STDAIR_LOG_DEBUG (ostr.str()); } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/command/Unconstrainer.cpp =================================================================== --- trunk/rmol/rmol/command/Unconstrainer.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/command/Unconstrainer.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -2,10 +2,10 @@ // Import section // ////////////////////////////////////////////////////////////////////// // STL -#include <iostream> -// #include <fstream> +#include <cassert> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL -#include <rmol/service/Logger.hpp> #include <rmol/RMOL_UNCONSTRAINER_Types.hpp> #include <rmol/command/Utilities.hpp> #include <rmol/command/Unconstrainer.hpp> @@ -34,10 +34,8 @@ oDebugStr << "After unconstraining, the constrained data became " << Utilities::vectorToString(ioConstrainedDataHolder); - RMOL_LOG_DEBUG (oDebugStr.str()); - + // DEBUG + STDAIR_LOG_DEBUG (oDebugStr.str()); } - // ////////////////////////////////////////////////////////////////////// - } Modified: trunk/rmol/rmol/command/Utilities.cpp =================================================================== --- trunk/rmol/rmol/command/Utilities.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/command/Utilities.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -2,22 +2,20 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -//STL -#include <algorithm> +// STL +#include <cassert> #include <string> -#include <sstream> #include <numeric> -#include <cmath> -#include <cassert> -#include <functional> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/command/Utilities.hpp> -#include <rmol/service/Logger.hpp> + namespace RMOL { // ///////////////////////////////////////////////////////////////////// void Utilities::updateMinimumElement (double& oMinValue, - std::vector<double>& iVector) { + std::vector<double>& iVector) { assert(!iVector.empty()); std::vector<double>::iterator pos = min_element (iVector.begin(), @@ -33,7 +31,7 @@ if (lSize > 0) { oSum = std::accumulate(iVector.begin(), iVector.end(), 0.0); } - else {RMOL_LOG_ERROR ("There is no element to sum up.");} + else {STDAIR_LOG_ERROR ("There is no element to sum up.");} } // ///////////////////////////////////////////////////////////////////// @@ -49,7 +47,7 @@ std::vector<double>& iVector, double& iMean) { if (iMean < 0) { - RMOL_LOG_ERROR ("Negative mean is not expected."); + STDAIR_LOG_ERROR ("Negative mean is not expected."); } else { const unsigned int lSize = iVector.size(); @@ -63,7 +61,7 @@ } } else { - RMOL_LOG_ERROR ("No value to compute the squared error"); + STDAIR_LOG_ERROR ("No value to compute the squared error"); } } } Modified: trunk/rmol/rmol/factory/FacStudyStatManager.cpp =================================================================== --- trunk/rmol/rmol/factory/FacStudyStatManager.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/factory/FacStudyStatManager.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -1,13 +1,14 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> +// STL +#include <cassert> +// StdAir +//#include <stdair/service/Logger.hpp> // RMOL #include <rmol/bom/StudyStatManager.hpp> #include <rmol/factory/FacSupervisor.hpp> #include <rmol/factory/FacStudyStatManager.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { Modified: trunk/rmol/rmol/factory/FacSupervisor.cpp =================================================================== --- trunk/rmol/rmol/factory/FacSupervisor.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/factory/FacSupervisor.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -7,7 +7,6 @@ #include <rmol/factory/FacBomAbstract.hpp> #include <rmol/factory/FacServiceAbstract.hpp> #include <rmol/factory/FacSupervisor.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -34,15 +33,9 @@ } // ////////////////////////////////////////////////////////////////////// - void FacSupervisor::registerLoggerService (Logger* ioLogger_ptr) { - _logger = ioLogger_ptr; - } - - // ////////////////////////////////////////////////////////////////////// FacSupervisor::~FacSupervisor() { cleanBomLayer(); cleanServiceLayer(); - cleanLoggerService(); } // ////////////////////////////////////////////////////////////////////// @@ -74,16 +67,10 @@ } // ////////////////////////////////////////////////////////////////////// - void FacSupervisor::cleanLoggerService() { - delete _logger; _logger = NULL; - } - - // ////////////////////////////////////////////////////////////////////// void FacSupervisor::cleanFactory () { if (_instance != NULL) { _instance->cleanBomLayer(); _instance->cleanServiceLayer(); - _instance->cleanLoggerService(); } delete (_instance); _instance = NULL; } Modified: trunk/rmol/rmol/factory/FacSupervisor.hpp =================================================================== --- trunk/rmol/rmol/factory/FacSupervisor.hpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/factory/FacSupervisor.hpp 2010-01-21 19:33:17 UTC (rev 289) @@ -12,7 +12,6 @@ // Forward declarations class FacBomAbstract; class FacServiceAbstract; - class Logger; /** Singleton class to register and clean all Factories. */ class FacSupervisor { @@ -39,16 +38,6 @@ @param FacServiceAbstract& the concrete Factory to register. */ void registerServiceFactory (FacServiceAbstract*); - /** Register a newly instantiated concrete factory for the - Logger object. In fact, as the Logger object - follows the singleton pattern, the concrete factory is the - Logger object itself. - <br>When a concrete Factory is firstly instantiated this - factory have to register itself to the FacSupervisor. - @param FacServiceAbstract& the concrete Factory to - register. */ - void registerLoggerService (Logger*); - /** Clean all created object. <br>Call the clean method of all the instantiated factories for the Bom layer. */ @@ -59,9 +48,6 @@ for the Service layer. */ void cleanServiceLayer(); - /** Delete the Logger object. */ - void cleanLoggerService(); - /** Clean the static instance. <br> The singleton is deleted.*/ static void cleanFactory (); @@ -84,15 +70,12 @@ /** The unique instance.*/ static FacSupervisor* _instance; - /** Logger (singleton) instance. */ - Logger* _logger; - /** List of instantiated factories for the Bom layer. */ BomFactoryPool_T _bomPool; /** List of instantiated factories for the Service layer. */ ServiceFactoryPool_T _svcPool; - }; + } #endif // __RMOL_FAC_FACSUPERVISOR_HPP Deleted: trunk/rmol/rmol/service/Logger.cpp =================================================================== --- trunk/rmol/rmol/service/Logger.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/service/Logger.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -1,66 +0,0 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> -// STL -#include <iostream> -// Rmol Logger -#include <rmol/factory/FacSupervisor.hpp> -#include <rmol/service/Logger.hpp> - -namespace RMOL { - - Logger* Logger::_instance = NULL; - - // ////////////////////////////////////////////////////////////////////// - Logger::Logger () : _logStream (&std::cout) { - assert (false); - } - - // ////////////////////////////////////////////////////////////////////// - Logger::Logger (const Logger&) : _logStream (&std::cout) { - assert (false); - } - - // ////////////////////////////////////////////////////////////////////// - Logger::Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream) - : _level (iLevel), _logStream (&ioLogStream) { - } - - // ////////////////////////////////////////////////////////////////////// - Logger::~Logger () { - _logStream = NULL; - } - - // ////////////////////////////////////////////////////////////////////// - LOG::EN_LogLevel Logger::getLogLevel() { - return _level; - } - - // ////////////////////////////////////////////////////////////////////// - std::ostream& Logger::getLogStream() { - assert (_logStream != NULL); - return *_logStream; - } - - // ////////////////////////////////////////////////////////////////////// - void Logger::setLogParameters (const LOG::EN_LogLevel iLogLevel, - std::ostream& ioLogStream) { - _level = iLogLevel; - _logStream = &ioLogStream; - } - - // ////////////////////////////////////////////////////////////////////// - Logger& Logger::instance() { - if (_instance == NULL) { - _instance = new Logger (LOG::DEBUG, std::cout); - - assert (_instance != NULL); - - FacSupervisor::instance().registerLoggerService (_instance); - } - return *_instance; - } - -} Deleted: trunk/rmol/rmol/service/Logger.hpp =================================================================== --- trunk/rmol/rmol/service/Logger.hpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/service/Logger.hpp 2010-01-21 19:33:17 UTC (rev 289) @@ -1,95 +0,0 @@ -#ifndef __RMOL_SVC_LOGGER_HPP -#define __RMOL_SVC_LOGGER_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> -// STL -#include <sstream> -#include <string> -// RMOL -#include <rmol/RMOL_Types.hpp> - -// /////////////// LOG MACROS ///////////////// -#define RMOL_LOG_CORE(iLevel, iToBeLogged) \ - { std::ostringstream ostr; ostr << iToBeLogged; \ - RMOL::Logger::instance().log (iLevel, __LINE__, __FILE__, ostr.str()); } - -#define RMOL_LOG_CRITICAL(iToBeLogged) \ - RMOL_LOG_CORE (RMOL::LOG::CRITICAL, iToBeLogged) - -#define RMOL_LOG_ERROR(iToBeLogged) \ - RMOL_LOG_CORE (RMOL::LOG::ERROR, iToBeLogged) - -#define RMOL_LOG_NOTIFICATION(iToBeLogged) \ - RMOL_LOG_CORE (RMOL::LOG::NOTIFICATION, iToBeLogged) - -#define RMOL_LOG_WARNING(iToBeLogged) \ - RMOL_LOG_CORE (RMOL::LOG::WARNING, iToBeLogged) - -#define RMOL_LOG_DEBUG(iToBeLogged) \ - RMOL_LOG_CORE (RMOL::LOG::DEBUG, iToBeLogged) - -#define RMOL_LOG_VERBOSE(iToBeLogged) \ - RMOL_LOG_CORE (RMOL::LOG::VERBOSE, iToBeLogged) -// /////////// (END OF) LOG MACROS ///////////// - - -namespace RMOL { - - /** Class holding the stream for logs. - <br>Note that the error logs are seen as standard output logs, - but with a higher level of visibility. */ - class Logger { - // Friend classes - friend class FacSupervisor; - public: - - /** Main log entry. */ - template <typename T> - void log (const LOG::EN_LogLevel iLevel, const int iLineNumber, - const std::string& iFileName, const T& iToBeLogged) { - if (iLevel <= _level) { - assert (_logStream != NULL); - *_logStream << iFileName << ":" << iLineNumber - << ": " << iToBeLogged << std::endl; - } - } - - /** Get the log level. */ - LOG::EN_LogLevel getLogLevel(); - - /** get the log stream. */ - std::ostream& getLogStream(); - - /** Set the logger parameters (level and stream). */ - void setLogParameters (const LOG::EN_LogLevel iLogLevel, - std::ostream& ioLogStream); - - /** Returns a current Logger instance.*/ - static Logger& instance(); - - private: - /** Default constructors are private so that only the required - constructor can be used. */ - Logger (); - Logger (const Logger&); - Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream); - /** Destructor. */ - ~Logger (); - - private: - /** Log level. */ - LOG::EN_LogLevel _level; - - /** Stream dedicated to the logs. */ - std::ostream* _logStream; - - /** Instance object.*/ - static Logger* _instance; - }; - -} -#endif // __RMOL_SVC_LOGGER_HPP Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2010-01-21 19:33:17 UTC (rev 289) @@ -3,11 +3,11 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <cassert> -#include <iomanip> -#include <sstream> -#include <iostream> // StdAir #include <stdair/basic/BasChronometer.hpp> +#include <stdair/basic/BasFileMgr.hpp> +#include <stdair/bom/BomManager.hpp> // for display() +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/basic/BasConst_RMOL_Service.hpp> #include <rmol/field/FldYieldRange.hpp> @@ -21,32 +21,44 @@ #include <rmol/command/Unconstrainer.hpp> #include <rmol/command/Forecaster.hpp> #include <rmol/service/RMOL_ServiceContext.hpp> -#include <rmol/service/Logger.hpp> #include <rmol/RMOL_Service.hpp> namespace RMOL { // ////////////////////////////////////////////////////////////////////// - RMOL_Service::RMOL_Service () : + RMOL_Service::RMOL_Service (const RMOL_Service& iService) : _rmolServiceContext (NULL) { + assert (false); } // ////////////////////////////////////////////////////////////////////// - RMOL_Service::RMOL_Service (const RMOL_Service& iService) : - _rmolServiceContext (iService._rmolServiceContext) { + RMOL_Service::RMOL_Service (const stdair::BasLogParams& iLogParams) : + _rmolServiceContext (NULL) { + + // Set the log file + logInit (iLogParams); + + // Initialise the (remaining of the) context + init (); } // ////////////////////////////////////////////////////////////////////// - RMOL_Service::RMOL_Service (std::ostream& ioLogStream) { + RMOL_Service::RMOL_Service () : + _rmolServiceContext (NULL) { // Initialise the context - init (ioLogStream); + init (); } // ////////////////////////////////////////////////////////////////////// - RMOL_Service::RMOL_Service (std::ostream& ioLogStream, - const ResourceCapacity_T iResourceCapacity) { - // Initialise the context - init (ioLogStream, iResourceCapacity); + RMOL_Service::RMOL_Service (const stdair::BasLogParams& iLogParams, + const ResourceCapacity_T iResourceCapacity) : + _rmolServiceContext (NULL) { + + // Set the log file + logInit (iLogParams); + + // Initialise the (remaining of the) context + init (iResourceCapacity); } // ////////////////////////////////////////////////////////////////////// @@ -54,10 +66,12 @@ } // ////////////////////////////////////////////////////////////////////// - void RMOL_Service::init (std::ostream& ioLogStream) { - // Set the log file - logInit (LOG::DEBUG, ioLogStream); + void RMOL_Service::logInit (const stdair::BasLogParams& iLogParams) { + stdair::Logger::init (iLogParams); + } + // ////////////////////////////////////////////////////////////////////// + void RMOL_Service::init () { // Initialise the context RMOL_ServiceContext& lRMOL_ServiceContext = FacRmolServiceContext::instance().create (); @@ -65,11 +79,7 @@ } // ////////////////////////////////////////////////////////////////////// - void RMOL_Service::init (std::ostream& ioLogStream, - const ResourceCapacity_T iResourceCapacity) { - // Set the log file - logInit (LOG::DEBUG, ioLogStream); - + void RMOL_Service::init (const ResourceCapacity_T iResourceCapacity) { // Initialise the context RMOL_ServiceContext& lRMOL_ServiceContext = FacRmolServiceContext::instance().create (iResourceCapacity); @@ -77,12 +87,6 @@ } // ////////////////////////////////////////////////////////////////////// - void RMOL_Service::logInit (const LOG::EN_LogLevel iLogLevel, - std::ostream& ioLogOutputFile) { - Logger::instance().setLogParameters (iLogLevel, ioLogOutputFile); - } - - // ////////////////////////////////////////////////////////////////////// void RMOL_Service::setUpStudyStatManager () { assert (_rmolServiceContext != NULL); _rmolServiceContext->setUpStudyStatManager (); @@ -129,6 +133,15 @@ // ////////////////////////////////////////////////////////////////////// void RMOL_Service::readFromInputFile (const std::string& iInputFileName) { + // Check that the file path given as input corresponds to an actual file + const bool doesExistAndIsReadable = + stdair::BasFileMgr::doesExistAndIsReadable (iInputFileName); + if (doesExistAndIsReadable == false) { + STDAIR_LOG_ERROR ("The input file, '" << iInputFileName + << "', can not be retrieved on the file-system"); + throw FileNotFoundException(); + } + assert (_rmolServiceContext != NULL); _rmolServiceContext->readFromInputFile (iInputFileName); } @@ -175,9 +188,9 @@ const double lOptimisationMeasure = lOptimisationChronometer.elapsed(); // DEBUG - RMOL_LOG_DEBUG ("Optimisation by Monte-Carlo performed in " + STDAIR_LOG_DEBUG ("Optimisation by Monte-Carlo performed in " << lOptimisationMeasure); - RMOL_LOG_DEBUG ("Resulting buckets: " << oBucketHolder_ptr->display()); + STDAIR_LOG_DEBUG ("Resulting buckets: " << oBucketHolder_ptr->display()); std::ostringstream logStream; logStream << "Bid-Price Vector (BPV): "; @@ -187,10 +200,10 @@ const double bidPrice = lBidPriceVector.at(i); logStream << std::fixed << std::setprecision (2) << bidPrice << " "; } - RMOL_LOG_DEBUG (logStream.str()); + STDAIR_LOG_DEBUG (logStream.str()); if (lStudyStatManager_ptr != NULL) { - RMOL_LOG_DEBUG (lStudyStatManager_ptr->describe()); + STDAIR_LOG_DEBUG (lStudyStatManager_ptr->describe()); } } @@ -225,7 +238,7 @@ Optimiser::optimalOptimisationByDP (iCapacity, *oBucketHolder_ptr); // DEBUG - RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); + STDAIR_LOG_DEBUG (oBucketHolder_ptr->display()); } // ////////////////////////////////////////////////////////////////////// @@ -265,7 +278,7 @@ } // DEBUG - RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); + STDAIR_LOG_DEBUG (oBucketHolder_ptr->display()); std::ostringstream logStream; logStream << "Bid-Price Vector (BPV): "; unsigned int size = lBidPriceVector.size(); @@ -274,10 +287,10 @@ const double bidPrice = lBidPriceVector.at(i); logStream << std::fixed << std::setprecision (2) << bidPrice << " "; } - RMOL_LOG_DEBUG (logStream.str()); + STDAIR_LOG_DEBUG (logStream.str()); if (lStudyStatManager_ptr != NULL) { - RMOL_LOG_DEBUG (lStudyStatManager_ptr->describe()); + STDAIR_LOG_DEBUG (lStudyStatManager_ptr->describe()); } } @@ -307,7 +320,7 @@ Optimiser::heuristicOptimisationByEmsrA (iCapacity, *oBucketHolder_ptr); // DEBUG - RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); + STDAIR_LOG_DEBUG (oBucketHolder_ptr->display()); } // ////////////////////////////////////////////////////////////////////// @@ -342,7 +355,7 @@ iSellupProbabilityVector); // DEBUG - RMOL_LOG_DEBUG (ioBucketHolder_ptr->display()); + STDAIR_LOG_DEBUG (ioBucketHolder_ptr->display()); } // ////////////////////////////////////////////////////////////////////// @@ -377,7 +390,7 @@ Optimiser::heuristicOptimisationByEmsrB (iCapacity, *oBucketHolder_ptr); // DEBUG - RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); + STDAIR_LOG_DEBUG (oBucketHolder_ptr->display()); } // ////////////////////////////////////////////////////////////////////// @@ -397,7 +410,7 @@ } // /////////////////////////////////////////////////////////////////////// - void RMOL_Service:: legOptimisationByMC () { + void RMOL_Service::legOptimisationByMC () { assert (_rmolServiceContext != NULL); const ResourceCapacity_T iCapacity = _rmolServiceContext->getCapacity(); BucketHolder* oBucketHolder_ptr = _rmolServiceContext->getBucketHolder(); @@ -408,7 +421,7 @@ lBidPriceVector); // DEBUG - RMOL_LOG_DEBUG (oBucketHolder_ptr->display()); + STDAIR_LOG_DEBUG (oBucketHolder_ptr->display()); std::ostringstream logStream; logStream << "Bid-Price Vector (BPV): "; unsigned int size = lBidPriceVector.size(); @@ -417,7 +430,9 @@ const double bidPrice = lBidPriceVector.at(i); logStream << std::fixed << std::setprecision (2) << bidPrice << " "; } - RMOL_LOG_DEBUG (logStream.str()); + + // DEBUG + STDAIR_LOG_DEBUG (logStream.str()); } // /////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/service/sources.mk =================================================================== --- trunk/rmol/rmol/service/sources.mk 2010-01-20 20:10:23 UTC (rev 288) +++ trunk/rmol/rmol/service/sources.mk 2010-01-21 19:33:17 UTC (rev 289) @@ -1,7 +1,5 @@ svc_h_sources = $(top_srcdir)/rmol/service/ServiceAbstract.hpp \ - $(top_srcdir)/rmol/service/RMOL_ServiceContext.hpp \ - $(top_srcdir)/rmol/service/Logger.hpp + $(top_srcdir)/rmol/service/RMOL_ServiceContext.hpp svc_cc_sources = $(top_srcdir)/rmol/service/ServiceAbstract.cpp \ $(top_srcdir)/rmol/service/RMOL_ServiceContext.cpp \ - $(top_srcdir)/rmol/service/Logger.cpp \ $(top_srcdir)/rmol/service/RMOL_Service.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-01-21 20:03:46
|
Revision: 291 http://rmol.svn.sourceforge.net/rmol/?rev=291&view=rev Author: denis_arnaud Date: 2010-01-21 20:03:39 +0000 (Thu, 21 Jan 2010) Log Message: ----------- [Dev] The initialisation now requires an airline code. Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/basic/BasConst.cpp trunk/rmol/rmol/basic/BasConst_RMOL_Service.hpp trunk/rmol/rmol/batches/rmol.cpp trunk/rmol/rmol/factory/FacRmolServiceContext.cpp trunk/rmol/rmol/factory/FacRmolServiceContext.hpp trunk/rmol/rmol/service/RMOL_Service.cpp trunk/rmol/rmol/service/RMOL_ServiceContext.cpp trunk/rmol/rmol/service/RMOL_ServiceContext.hpp Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/RMOL_Service.hpp 2010-01-21 20:03:39 UTC (rev 291) @@ -108,8 +108,9 @@ <br>Moreover, a reference on an output stream is given, so that log outputs can be directed onto that stream. @param const stdair::BasLogParams& Parameters for the output log - stream. */ - RMOL_Service (const stdair::BasLogParams&); + stream. + @param AirlineCode_T& Code of the owner airline. */ + RMOL_Service (const stdair::BasLogParams&, const stdair::AirlineCode_T&); /** Constructor. <br>The init() method is called; see the corresponding documentation @@ -119,8 +120,9 @@ initialised with the proper log output stream by some other methods in the calling chain (for instance, when the RMOL_Service is itself being initialised by another library service such as - AIRINV_Service). */ - RMOL_Service (); + AIRINV_Service). + @param AirlineCode_T& Code of the owner airline. */ + RMOL_Service (const stdair::AirlineCode_T&); /** Constructor. <br>The init() method is called; see the corresponding documentation @@ -128,8 +130,10 @@ <br>Moreover, a reference on an output stream is given, so that log outputs can be directed onto that stream. @param const stdair::BasLogParams& Parameters for the output log stream. + @param AirlineCode_T& Code of the owner airline. @param const ResourceCapacity_T Capacity of the resource to optimise. */ - RMOL_Service (const stdair::BasLogParams&, const ResourceCapacity_T); + RMOL_Service (const stdair::BasLogParams&, const stdair::AirlineCode_T&, + const ResourceCapacity_T); /** Constructor. <br>The init() method is called; see the corresponding documentation @@ -140,8 +144,9 @@ methods in the calling chain (for instance, when the RMOL_Service is itself being initialised by another library service such as AIRINV_Service). + @param AirlineCode_T& Code of the owner airline. @param const ResourceCapacity_T Capacity of the resource to optimise. */ - RMOL_Service (const ResourceCapacity_T); + RMOL_Service (const stdair::AirlineCode_T&, const ResourceCapacity_T); /** Destructor. */ ~RMOL_Service(); @@ -184,18 +189,23 @@ private: - /** Default Constructors. */ + // /////// Construction and Destruction helper methods /////// + /** Default constructor. */ + RMOL_Service (); + /** Default copy constructor. */ RMOL_Service (const RMOL_Service&); /** Initialise the log. */ void logInit (const stdair::BasLogParams&); - /** Initialise. */ - void init (); + /** Initialise. + @param AirlineCode_T& Code of the owner airline. */ + void init (const stdair::AirlineCode_T&); /** Initialise. + @param AirlineCode_T& Code of the owner airline. @param const ResourceCapacity_T Capacity of the resource to optimise. */ - void init (const ResourceCapacity_T); + void init (const stdair::AirlineCode_T&, const ResourceCapacity_T); /** Finaliser. */ void finalise (); Modified: trunk/rmol/rmol/basic/BasConst.cpp =================================================================== --- trunk/rmol/rmol/basic/BasConst.cpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/basic/BasConst.cpp 2010-01-21 20:03:39 UTC (rev 291) @@ -1,3 +1,6 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// #include <rmol/basic/BasConst_General.hpp> #include <rmol/basic/BasConst_Overbooking.hpp> #include <rmol/basic/BasConst_RMOL_Service.hpp> @@ -4,6 +7,9 @@ namespace RMOL { + /** Default airline code for the RMOL_Service. */ + const stdair::AirlineCode_T DEFAULT_RMOL_SERVICE_AIRLINE_CODE = "BA"; + /** Default capacity for the RMOL_Service. */ const double DEFAULT_RMOL_SERVICE_CAPACITY = 1.0; Modified: trunk/rmol/rmol/basic/BasConst_RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/basic/BasConst_RMOL_Service.hpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/basic/BasConst_RMOL_Service.hpp 2010-01-21 20:03:39 UTC (rev 291) @@ -6,11 +6,16 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <vector> +// StdAir +#include <stdair/STDAIR_Types.hpp> // RMOL #include <rmol/RMOL_Types.hpp> namespace RMOL { + /** Default airline code for the RMOL_Service. */ + extern const stdair::AirlineCode_T DEFAULT_RMOL_SERVICE_AIRLINE_CODE; + /** Default capacity for the RMOL_Service. */ extern const double DEFAULT_RMOL_SERVICE_CAPACITY; Modified: trunk/rmol/rmol/batches/rmol.cpp =================================================================== --- trunk/rmol/rmol/batches/rmol.cpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/batches/rmol.cpp 2010-01-21 20:03:39 UTC (rev 291) @@ -225,7 +225,8 @@ // Initialise the list of classes/buckets const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); - RMOL::RMOL_Service rmolService (lLogParams, lCapacity); + const stdair::AirlineCode_T lAirlineCode ("BA"); + RMOL::RMOL_Service rmolService (lLogParams, lAirlineCode, lCapacity); rmolService.setUpStudyStatManager(); if (hasInputFile) { Modified: trunk/rmol/rmol/factory/FacRmolServiceContext.cpp =================================================================== --- trunk/rmol/rmol/factory/FacRmolServiceContext.cpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/factory/FacRmolServiceContext.cpp 2010-01-21 20:03:39 UTC (rev 291) @@ -1,8 +1,8 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> +// STL +#include <cassert> // RMOL #include <rmol/service/RMOL_ServiceContext.hpp> #include <rmol/factory/FacSupervisor.hpp> @@ -30,10 +30,11 @@ } // ////////////////////////////////////////////////////////////////////// - RMOL_ServiceContext& FacRmolServiceContext::create () { + RMOL_ServiceContext& FacRmolServiceContext:: + create (const stdair::AirlineCode_T& iAirlineCode) { RMOL_ServiceContext* aServiceContext_ptr = NULL; - aServiceContext_ptr = new RMOL_ServiceContext (); + aServiceContext_ptr = new RMOL_ServiceContext (iAirlineCode); assert (aServiceContext_ptr != NULL); // The new object is added to the Bom pool @@ -44,10 +45,12 @@ // ////////////////////////////////////////////////////////////////////// RMOL_ServiceContext& FacRmolServiceContext:: - create (const ResourceCapacity_T iResourceCapacity) { + create (const stdair::AirlineCode_T& iAirlineCode, + const ResourceCapacity_T iResourceCapacity) { RMOL_ServiceContext* aServiceContext_ptr = NULL; - aServiceContext_ptr = new RMOL_ServiceContext (iResourceCapacity); + aServiceContext_ptr = new RMOL_ServiceContext (iAirlineCode, + iResourceCapacity); assert (aServiceContext_ptr != NULL); // The new object is added to the Bom pool Modified: trunk/rmol/rmol/factory/FacRmolServiceContext.hpp =================================================================== --- trunk/rmol/rmol/factory/FacRmolServiceContext.hpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/factory/FacRmolServiceContext.hpp 2010-01-21 20:03:39 UTC (rev 291) @@ -4,6 +4,8 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +// StdAir +#include <stdair/STDAIR_Types.hpp> // RMOL #include <rmol/RMOL_Types.hpp> #include <rmol/factory/FacServiceAbstract.hpp> @@ -30,12 +32,13 @@ /** Create a new ServiceContext object. <br>This new object is added to the list of instantiated objects. @return ServiceContext& The newly created object. */ - RMOL_ServiceContext& create (); + RMOL_ServiceContext& create (const stdair::AirlineCode_T&); /** Create a new ServiceContext object. <br>This new object is added to the list of instantiated objects. @return ServiceContext& The newly created object. */ - RMOL_ServiceContext& create (const ResourceCapacity_T iResourceCapacity); + RMOL_ServiceContext& create (const stdair::AirlineCode_T&, + const ResourceCapacity_T); protected: Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2010-01-21 20:03:39 UTC (rev 291) @@ -26,31 +26,39 @@ namespace RMOL { // ////////////////////////////////////////////////////////////////////// + RMOL_Service::RMOL_Service () : _rmolServiceContext (NULL) { + assert (false); + } + + // ////////////////////////////////////////////////////////////////////// RMOL_Service::RMOL_Service (const RMOL_Service& iService) : _rmolServiceContext (NULL) { assert (false); } // ////////////////////////////////////////////////////////////////////// - RMOL_Service::RMOL_Service (const stdair::BasLogParams& iLogParams) : + RMOL_Service::RMOL_Service (const stdair::BasLogParams& iLogParams, + const stdair::AirlineCode_T& iAirlineCode) : _rmolServiceContext (NULL) { // Set the log file logInit (iLogParams); // Initialise the (remaining of the) context - init (); + init (iAirlineCode); } // ////////////////////////////////////////////////////////////////////// - RMOL_Service::RMOL_Service () : + RMOL_Service::RMOL_Service (const stdair::AirlineCode_T& iAirlineCode) : _rmolServiceContext (NULL) { + // Initialise the context - init (); + init (iAirlineCode); } // ////////////////////////////////////////////////////////////////////// RMOL_Service::RMOL_Service (const stdair::BasLogParams& iLogParams, + const stdair::AirlineCode_T& iAirlineCode, const ResourceCapacity_T iResourceCapacity) : _rmolServiceContext (NULL) { @@ -58,7 +66,7 @@ logInit (iLogParams); // Initialise the (remaining of the) context - init (iResourceCapacity); + init (iAirlineCode, iResourceCapacity); } // ////////////////////////////////////////////////////////////////////// @@ -71,18 +79,19 @@ } // ////////////////////////////////////////////////////////////////////// - void RMOL_Service::init () { + void RMOL_Service::init (const stdair::AirlineCode_T& iAirlineCode) { // Initialise the context RMOL_ServiceContext& lRMOL_ServiceContext = - FacRmolServiceContext::instance().create (); + FacRmolServiceContext::instance().create (iAirlineCode); _rmolServiceContext = &lRMOL_ServiceContext; } // ////////////////////////////////////////////////////////////////////// - void RMOL_Service::init (const ResourceCapacity_T iResourceCapacity) { + void RMOL_Service::init (const stdair::AirlineCode_T& iAirlineCode, + const ResourceCapacity_T iResourceCapacity) { // Initialise the context RMOL_ServiceContext& lRMOL_ServiceContext = - FacRmolServiceContext::instance().create (iResourceCapacity); + FacRmolServiceContext::instance().create (iAirlineCode, iResourceCapacity); _rmolServiceContext = &lRMOL_ServiceContext; } Modified: trunk/rmol/rmol/service/RMOL_ServiceContext.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_ServiceContext.cpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/service/RMOL_ServiceContext.cpp 2010-01-21 20:03:39 UTC (rev 291) @@ -1,8 +1,8 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> +// STL +#include <cassert> // RMOL #include <rmol/basic/BasConst_RMOL_Service.hpp> #include <rmol/field/FldYieldRange.hpp> @@ -23,30 +23,36 @@ namespace RMOL { // ////////////////////////////////////////////////////////////////////// - RMOL_ServiceContext:: - RMOL_ServiceContext (const ResourceCapacity_T iResourceCapacity) : - _bucketHolder (NULL), _capacity (iResourceCapacity), - _studyStatManager (NULL), - _generatedDemandVectorHolder (DEFAULT_GENERATED_DEMAND_VECTOR_HOLDER) { - init (iResourceCapacity); + RMOL_ServiceContext::RMOL_ServiceContext () : + _bucketHolder (NULL), _studyStatManager (NULL) { + assert (false); } // ////////////////////////////////////////////////////////////////////// - RMOL_ServiceContext::RMOL_ServiceContext () : - _bucketHolder (NULL), _capacity (DEFAULT_RMOL_SERVICE_CAPACITY), - _studyStatManager (NULL), + RMOL_ServiceContext::RMOL_ServiceContext (const RMOL_ServiceContext&) : + _bucketHolder (NULL), _studyStatManager (NULL) { + assert (false); + } + + // ////////////////////////////////////////////////////////////////////// + RMOL_ServiceContext:: + RMOL_ServiceContext (const stdair::AirlineCode_T& iAirlineCode) : + _bucketHolder (NULL), _studyStatManager (NULL), + _airlineCode (iAirlineCode), _capacity (DEFAULT_RMOL_SERVICE_CAPACITY), _generatedDemandVectorHolder (DEFAULT_GENERATED_DEMAND_VECTOR_HOLDER) { init (DEFAULT_RMOL_SERVICE_CAPACITY); } // ////////////////////////////////////////////////////////////////////// - RMOL_ServiceContext::RMOL_ServiceContext (const RMOL_ServiceContext&) : - _bucketHolder (NULL), _capacity (DEFAULT_RMOL_SERVICE_CAPACITY), - _studyStatManager (NULL), + RMOL_ServiceContext:: + RMOL_ServiceContext (const stdair::AirlineCode_T& iAirlineCode, + const ResourceCapacity_T iResourceCapacity) : + _bucketHolder (NULL), _studyStatManager (NULL), + _airlineCode (iAirlineCode), _capacity (iResourceCapacity), _generatedDemandVectorHolder (DEFAULT_GENERATED_DEMAND_VECTOR_HOLDER) { - init (DEFAULT_RMOL_SERVICE_CAPACITY); + init (iResourceCapacity); } - + // ////////////////////////////////////////////////////////////////////// RMOL_ServiceContext::~RMOL_ServiceContext() { } Modified: trunk/rmol/rmol/service/RMOL_ServiceContext.hpp =================================================================== --- trunk/rmol/rmol/service/RMOL_ServiceContext.hpp 2010-01-21 19:33:33 UTC (rev 290) +++ trunk/rmol/rmol/service/RMOL_ServiceContext.hpp 2010-01-21 20:03:39 UTC (rev 291) @@ -6,6 +6,8 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <string> +// StdAir +#include <stdair/STDAIR_Types.hpp> // RMOL #include <rmol/RMOL_Types.hpp> #include <rmol/service/ServiceAbstract.hpp> @@ -24,17 +26,42 @@ friend class RMOL_Service; friend class FacRmolServiceContext; + public: + // ///////// Getters ////////// + /** Get the airline code. */ + const stdair::AirlineCode_T& getAirlineCode () const { + return _airlineCode; + } + + + // ///////// Setters ////////// + /** Set the airline code. */ + void setAirlineCode (const stdair::AirlineCode_T& iAirlineCode) { + _airlineCode = iAirlineCode; + } + + + public: + /** Set up the StudyStatManager. */ + void setUpStudyStatManager (); + + private: + // /////// Construction / initialisation //////// /** Constructors. */ RMOL_ServiceContext (); RMOL_ServiceContext (const RMOL_ServiceContext&); - RMOL_ServiceContext (const ResourceCapacity_T iResourceCapacity); - void init (const ResourceCapacity_T iResourceCapacity); + RMOL_ServiceContext (const stdair::AirlineCode_T&); + RMOL_ServiceContext (const stdair::AirlineCode_T&, const ResourceCapacity_T); + void init (const ResourceCapacity_T); + /** Initialise the StudyStatManager. */ void initStudyStatManager (); + /** Destructor. */ ~RMOL_ServiceContext(); + /** Set the cabin availability. */ void setResourceCapacity (const ResourceCapacity_T iResourceCapacity); @@ -86,20 +113,21 @@ return _capacity; } - public: - /** Set up the StudyStatManager. */ - void setUpStudyStatManager (); private: + // //////////// Attributes ////////////////// /** Internal pointer on BucketHolder. */ BucketHolder* _bucketHolder; + /** Statistic Manager. */ + StudyStatManager* _studyStatManager; + + /** Code of the airline owner of the revenue management system. */ + stdair::AirlineCode_T _airlineCode; + /** Resource Capacity. */ ResourceCapacity_T _capacity; - /** Statistic Manager. */ - StudyStatManager* _studyStatManager; - /** Holder of the generated demand vectors. */ GeneratedDemandVectorHolder_T _generatedDemandVectorHolder; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-01-22 19:47:45
|
Revision: 295 http://rmol.svn.sourceforge.net/rmol/?rev=295&view=rev Author: denis_arnaud Date: 2010-01-22 19:47:28 +0000 (Fri, 22 Jan 2010) Log Message: ----------- [Dev] Added a STDAIR_Service, wrapper around both the static Logger instance and the stdair::FacSupervisor one. Modified Paths: -------------- trunk/rmol/rmol/RMOL_Service.hpp trunk/rmol/rmol/service/RMOL_Service.cpp trunk/rmol/rmol/service/RMOL_ServiceContext.hpp Modified: trunk/rmol/rmol/RMOL_Service.hpp =================================================================== --- trunk/rmol/rmol/RMOL_Service.hpp 2010-01-21 23:31:28 UTC (rev 294) +++ trunk/rmol/rmol/RMOL_Service.hpp 2010-01-22 19:47:28 UTC (rev 295) @@ -195,9 +195,21 @@ /** Default copy constructor. */ RMOL_Service (const RMOL_Service&); - /** Initialise the log. */ - void logInit (const stdair::BasLogParams&); + /** Initialise the (RMOL) service context (i.e., the + RMOL_ServiceContext object). + @param AirlineCode_T& Code of the owner airline. */ + void initServiceContext (const stdair::AirlineCode_T&); + /** Initialise the (RMOL) service context (i.e., the + RMOL_ServiceContext object). + @param AirlineCode_T& Code of the owner airline. + @param const ResourceCapacity_T Capacity of the resource to optimise. */ + void initServiceContext (const stdair::AirlineCode_T&, + const ResourceCapacity_T); + + /** Initialise the STDAIR service (including the log service). */ + void initStdAirService (const stdair::BasLogParams&); + /** Initialise. @param AirlineCode_T& Code of the owner airline. */ void init (const stdair::AirlineCode_T&); Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2010-01-21 23:31:28 UTC (rev 294) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2010-01-22 19:47:28 UTC (rev 295) @@ -7,8 +7,8 @@ #include <stdair/basic/BasChronometer.hpp> #include <stdair/basic/BasFileMgr.hpp> #include <stdair/bom/BomManager.hpp> // for display() -#include <stdair/factory/FacSupervisor.hpp> #include <stdair/service/Logger.hpp> +#include <stdair/STDAIR_Service.hpp> // RMOL #include <rmol/basic/BasConst_RMOL_Service.hpp> #include <rmol/field/FldYieldRange.hpp> @@ -17,6 +17,7 @@ #include <rmol/bom/Bucket.hpp> #include <rmol/bom/BucketHolder.hpp> #include <rmol/bom/StudyStatManager.hpp> +#include <rmol/factory/FacSupervisor.hpp> #include <rmol/factory/FacRmolServiceContext.hpp> #include <rmol/command/Optimiser.hpp> #include <rmol/command/Unconstrainer.hpp> @@ -42,9 +43,12 @@ const stdair::AirlineCode_T& iAirlineCode) : _rmolServiceContext (NULL) { - // Set the log file - logInit (iLogParams); + // Initialise the service context + initServiceContext (iAirlineCode); + // Initialise the STDAIR service handler + initStdAirService (iLogParams); + // Initialise the (remaining of the) context init (iAirlineCode); } @@ -63,39 +67,63 @@ const ResourceCapacity_T iResourceCapacity) : _rmolServiceContext (NULL) { - // Set the log file - logInit (iLogParams); - + // Initialise the service context + initServiceContext (iAirlineCode, iResourceCapacity); + + // Initialise the STDAIR service handler + initStdAirService (iLogParams); + // Initialise the (remaining of the) context init (iAirlineCode, iResourceCapacity); } // ////////////////////////////////////////////////////////////////////// RMOL_Service::~RMOL_Service () { - // Clean all the StdAir objects, including the log service - stdair::FacSupervisor::cleanFactory(); + // Clean all the RMOL-scoped objects + FacSupervisor::cleanFactory(); } // ////////////////////////////////////////////////////////////////////// - void RMOL_Service::logInit (const stdair::BasLogParams& iLogParams) { - stdair::Logger::init (iLogParams); + void RMOL_Service:: + initServiceContext (const stdair::AirlineCode_T& iAirlineCode) { + // Initialise the service context + RMOL_ServiceContext& lRMOL_ServiceContext = + FacRmolServiceContext::instance().create (iAirlineCode); + _rmolServiceContext = &lRMOL_ServiceContext; } // ////////////////////////////////////////////////////////////////////// - void RMOL_Service::init (const stdair::AirlineCode_T& iAirlineCode) { - // Initialise the context + void RMOL_Service:: + initServiceContext (const stdair::AirlineCode_T& iAirlineCode, + const ResourceCapacity_T iResourceCapacity) { + // Initialise the service context RMOL_ServiceContext& lRMOL_ServiceContext = - FacRmolServiceContext::instance().create (iAirlineCode); + FacRmolServiceContext::instance().create (iAirlineCode, iResourceCapacity); _rmolServiceContext = &lRMOL_ServiceContext; } // ////////////////////////////////////////////////////////////////////// + void RMOL_Service:: + initStdAirService (const stdair::BasLogParams& iLogParams) { + assert (_rmolServiceContext != NULL); + + // Initialise the STDAIR service handler + // Note that the track on the object memory is kept thanks to the Boost + // Smart Pointers component. + STDAIR_ServicePtr_T lSTDAIR_Service = + STDAIR_ServicePtr_T (new stdair::STDAIR_Service (iLogParams)); + + // Store the STDAIR service object within the (RMOL) service context + _rmolServiceContext->setSTDAIR_Service (lSTDAIR_Service); + } + + // ////////////////////////////////////////////////////////////////////// + void RMOL_Service::init (const stdair::AirlineCode_T& iAirlineCode) { + } + + // ////////////////////////////////////////////////////////////////////// void RMOL_Service::init (const stdair::AirlineCode_T& iAirlineCode, const ResourceCapacity_T iResourceCapacity) { - // Initialise the context - RMOL_ServiceContext& lRMOL_ServiceContext = - FacRmolServiceContext::instance().create (iAirlineCode, iResourceCapacity); - _rmolServiceContext = &lRMOL_ServiceContext; } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/rmol/service/RMOL_ServiceContext.hpp =================================================================== --- trunk/rmol/rmol/service/RMOL_ServiceContext.hpp 2010-01-21 23:31:28 UTC (rev 294) +++ trunk/rmol/rmol/service/RMOL_ServiceContext.hpp 2010-01-22 19:47:28 UTC (rev 295) @@ -6,18 +6,29 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <string> +// Boost +#include <boost/shared_ptr.hpp> // StdAir #include <stdair/STDAIR_Types.hpp> // RMOL #include <rmol/RMOL_Types.hpp> #include <rmol/service/ServiceAbstract.hpp> +// Forward declarations +namespace stdair { + class STDAIR_Service; +} + namespace RMOL { /** Forward declaration. */ class BucketHolder; class StudyStatManager; + /** Pointer on the STDAIR Service handler. */ + typedef boost::shared_ptr<stdair::STDAIR_Service> STDAIR_ServicePtr_T; + + /** Inner class holding the context for the RMOL Service object. */ class RMOL_ServiceContext : public ServiceAbstract { /** The RMOL_Service class should be the sole class to get access to @@ -61,7 +72,12 @@ /** Destructor. */ ~RMOL_ServiceContext(); - + private: + /** Set the pointer on the STDAIR service handler. */ + void setSTDAIR_Service (STDAIR_ServicePtr_T ioSTDAIR_ServicePtr) { + _stdairService = ioSTDAIR_ServicePtr; + } + /** Set the cabin availability. */ void setResourceCapacity (const ResourceCapacity_T iResourceCapacity); @@ -115,6 +131,12 @@ private: + // ///////////// Children //////////// + /** Standard Airline (StdAir) Service Handler. */ + STDAIR_ServicePtr_T _stdairService; + + + private: // //////////// Attributes ////////////////// /** Internal pointer on BucketHolder. */ BucketHolder* _bucketHolder; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-08-07 16:11:43
|
Revision: 326 http://rmol.svn.sourceforge.net/rmol/?rev=326&view=rev Author: denis_arnaud Date: 2010-08-07 16:11:37 +0000 (Sat, 07 Aug 2010) Log Message: ----------- [Dev] Added the 'built-in' command-line option, which now works. Modified Paths: -------------- trunk/rmol/rmol/batches/rmol.cpp trunk/rmol/rmol/bom/BucketHolder.cpp trunk/rmol/rmol/service/RMOL_Service.cpp Modified: trunk/rmol/rmol/batches/rmol.cpp =================================================================== --- trunk/rmol/rmol/batches/rmol.cpp 2010-08-07 09:37:43 UTC (rev 325) +++ trunk/rmol/rmol/batches/rmol.cpp 2010-08-07 16:11:37 UTC (rev 326) @@ -1,6 +1,5 @@ -// C -#include <assert.h> // STL +#include <cassert> #include <iostream> #include <sstream> #include <fstream> @@ -9,6 +8,8 @@ #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/program_options.hpp> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/RMOL_Service.hpp> #include <rmol/config/rmol-paths.hpp> @@ -18,6 +19,10 @@ /** Default name and location for the log file. */ const std::string K_RMOL_DEFAULT_LOG_FILENAME ("rmol.log"); +/** Default for the input type. It can be either built-in or provided by an + input file. That latter must then be given with the -i/--input option. */ +const bool K_RMOL_DEFAULT_BUILT_IN_INPUT = false; + /** Default name and location for the (CSV) input file. */ const std::string K_RMOL_DEFAULT_INPUT_FILENAME ("../../test/samples/rm01.csv"); @@ -67,9 +72,12 @@ int readConfiguration(int argc, char* argv[], int& ioRandomDraws, double& ioCapacity, RMOL::SellupProbabilityVector_T& ioSellupProbabilityVector, - short& ioMethod, std::string& ioInputFilename, - std::string& ioLogFilename) { + short& ioMethod, bool& ioIsBuiltin, + std::string& ioInputFilename, std::string& ioLogFilename){ + // Default for the built-in input + ioIsBuiltin = K_RMOL_DEFAULT_BUILT_IN_INPUT; + // Initialise the sell-up probability vector with default values initDefaultValuesForSellupProbabilityVector (ioSellupProbabilityVector); @@ -96,6 +104,8 @@ ("method,m", boost::program_options::value<short>(&ioMethod)->default_value(K_RMOL_DEFAULT_METHOD), "Revenue Management method to be used (0 = Monte-Carlo, 1 = Dynamic Programming, 2 = EMSR, 3 = EMSR-a, 4 = EMSR-b, 5 = EMSR-a with sell up probability)") + ("builtin,b", + "The cabin set up can be either built-in or parsed from an input file. That latter must then be given with the -i/--input option") ("input,i", boost::program_options::value< std::string >(&ioInputFilename)->default_value(K_RMOL_DEFAULT_INPUT_FILENAME), "(CVS) input file for the demand distributions") @@ -149,11 +159,19 @@ return K_RMOL_EARLY_RETURN_STATUS; } - if (vm.count ("input")) { - ioInputFilename = vm["input"].as< std::string >(); - std::cout << "Input filename is: " << ioInputFilename << std::endl; + if (vm.count ("builtin")) { + ioIsBuiltin = true; } + const std::string isBuiltinStr = (ioIsBuiltin == true)?"yes":"no"; + std::cout << "The BOM should be built-in? " << isBuiltinStr << std::endl; + if (ioIsBuiltin == false) { + if (vm.count ("input")) { + ioInputFilename = vm["input"].as< std::string >(); + std::cout << "Input filename is: " << ioInputFilename << std::endl; + } + } + if (vm.count ("log")) { ioLogFilename = vm["log"].as< std::string >(); std::cout << "Log filename is: " << ioLogFilename << std::endl; @@ -195,6 +213,9 @@ // 2 = EMSR, 3 = EMSR-a, 4 = EMSR-b, 5 = EMSR-a with sell up probability) short lMethod = 0; + // Built-in + bool isBuiltin; + // Input file name std::string lInputFilename; @@ -204,19 +225,13 @@ // Call the command-line option parser const int lOptionParserStatus = readConfiguration (argc, argv, lRandomDraws, lCapacity, - lSellupProbabilityVector, lMethod, lInputFilename, - lLogFilename); + lSellupProbabilityVector, lMethod, + isBuiltin, lInputFilename, lLogFilename); if (lOptionParserStatus == K_RMOL_EARLY_RETURN_STATUS) { return 0; } - // Check wether or not a (CSV) input file should be read - bool hasInputFile = false; - if (lInputFilename.empty() == false) { - hasInputFile = true; - } - // Set the log parameters std::ofstream logOutputFile; // Open and clean the log outputfile @@ -229,24 +244,32 @@ RMOL::RMOL_Service rmolService (lLogParams, lAirlineCode, lCapacity); rmolService.setUpStudyStatManager(); - if (hasInputFile) { - // Read the input file - rmolService.readFromInputFile (lInputFilename); - - } else { + if (isBuiltin == true) { // No input file has been provided. So, process a sample. + + // DEBUG + STDAIR_LOG_DEBUG ("rmol will build the BOM tree from built-in specifications."); // STEP 0. // List of demand distribution parameters (mean and standard deviation) - // Class/bucket 1: N (20, 9), p1 = 100 - rmolService.addBucket (100.0, 20, 9); + // Class/bucket 1: p1 = 110, N (15, 9) + rmolService.addBucket (110.0, 15, 9); - // Class/bucket 2: N (45, 12), p2 = 70 - rmolService.addBucket (70.0, 45, 12); + // Class/bucket 2: p2 = 75, N (40, 12) + rmolService.addBucket (75.0, 40, 12); - // Class/bucket 3: no need to define a demand distribution, p3 = 42 - rmolService.addBucket (42.0, 0, 0); + // Class/bucket 3: p3 = 48, no need to define a demand distribution + // (it can be considered very big) + rmolService.addBucket (48.0, 0, 0); + + } else { + // DEBUG + STDAIR_LOG_DEBUG ("rmol will parse " << lInputFilename + << " and build the corresponding BOM tree."); + + // Parse the input file + rmolService.readFromInputFile (lInputFilename); } switch (lMethod) { Modified: trunk/rmol/rmol/bom/BucketHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/BucketHolder.cpp 2010-08-07 09:37:43 UTC (rev 325) +++ trunk/rmol/rmol/bom/BucketHolder.cpp 2010-08-07 16:11:37 UTC (rev 326) @@ -77,10 +77,11 @@ // ////////////////////////////////////////////////////////////////////// const std::string BucketHolder::display() const { std::ostringstream oStr; - oStr << shortDisplay(); + oStr << shortDisplay() << std::endl; + // Generate a CSV (Comma Separated Values) output oStr << "Class; Price; Mean; Std Dev; Protection; Cum. Protection; Cum. Bkg Limit; " - << std::endl; + << std::endl; BucketList_T::const_iterator itBucket = _bucketList.begin(); for (short j=1; itBucket != _bucketList.end(); itBucket++, j++) { Modified: trunk/rmol/rmol/service/RMOL_Service.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_Service.cpp 2010-08-07 09:37:43 UTC (rev 325) +++ trunk/rmol/rmol/service/RMOL_Service.cpp 2010-08-07 16:11:37 UTC (rev 326) @@ -229,7 +229,7 @@ // DEBUG STDAIR_LOG_DEBUG ("Optimisation by Monte-Carlo performed in " - << lOptimisationMeasure); + << lOptimisationMeasure); STDAIR_LOG_DEBUG ("Resulting buckets: " << oBucketHolder_ptr->display()); std::ostringstream logStream; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-09-27 11:36:32
|
Revision: 338 http://rmol.svn.sourceforge.net/rmol/?rev=338&view=rev Author: denis_arnaud Date: 2010-09-27 11:36:24 +0000 (Mon, 27 Sep 2010) Log Message: ----------- [Dev] Replaced calls to the GSL (GNU Scientific Library) by Boost.Math. Modified Paths: -------------- trunk/rmol/rmol/bom/DPOptimiser.cpp trunk/rmol/rmol/bom/EmsrUtils.cpp trunk/rmol/rmol/bom/ExpectationMaximization.cpp trunk/rmol/rmol/bom/Gaussian.cpp trunk/rmol/rmol/bom/Gaussian.hpp trunk/rmol/rmol/bom/HistoricalBookingHolder.cpp trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.cpp trunk/rmol/rmol/bom/HistoricalDataHolder.cpp trunk/rmol/rmol/bom/HistoricalDataHolderHolder.cpp trunk/rmol/rmol/bom/MCOptimiser.cpp trunk/rmol/rmol/bom/Makefile.am trunk/rmol/rmol/bom/Overbooking.cpp trunk/rmol/rmol/core/Makefile.am trunk/rmol/rmol/service/RMOL_ServiceContext.cpp Modified: trunk/rmol/rmol/bom/DPOptimiser.cpp =================================================================== --- trunk/rmol/rmol/bom/DPOptimiser.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/DPOptimiser.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,14 +1,13 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL Random Number Generation (GSL Reference Manual, version 1.7, Chapter 19) -#include <gsl/gsl_cdf.h> -#include <gsl/gsl_randist.h> // STL #include <cassert> #include <sstream> #include <vector> #include <cmath> +// Boost Math +#include <boost/math/distributions/normal.hpp> // StdAir #include <stdair/service/Logger.hpp> // RMOL @@ -55,7 +54,7 @@ const double meanDemand = currentBucket.getMean(); const double SDDemand = currentBucket.getStandardDeviation(); const double currentYield = currentBucket.getAverageYield(); - const double errorFactor = 1;//gsl_cdf_gaussian_Q (-meanDemand, SDDemand); + const double errorFactor = 1.0; Bucket& nextBucket = ioBucketHolder.getNextBucket(); const double nextYield = nextBucket.getAverageYield(); @@ -63,23 +62,27 @@ // For x <= currentProtection (y_(j-1)), V_j(x) = V_(j-1)(x). for (int x = 0; x <= currentProtection; ++x) { const double MERValue = MERVectorHolder.at(currentBucketIndex-1).at(x); - currentMERVector.push_back(MERValue); + currentMERVector.push_back (MERValue); } + + // + boost::math::normal lNormalDistribution (meanDemand, SDDemand); // Vector of gaussian pdf values. std::vector<double> pdfVector; for (int s = 0; s <= maxValue - currentProtection; ++s) { const double pdfValue = - gsl_ran_gaussian_pdf (s/DEFAULT_PRECISION - meanDemand, SDDemand); - pdfVector.push_back(pdfValue); + boost::math::pdf (lNormalDistribution, s/DEFAULT_PRECISION); + pdfVector.push_back (pdfValue); } // Vector of gaussian cdf values. std::vector<double> cdfVector; for (int s = 0; s <= maxValue - currentProtection; ++s) { const double cdfValue = - cdfGaussianQ (s/DEFAULT_PRECISION - meanDemand, SDDemand); - cdfVector.push_back(cdfValue); + boost::math::cdf (boost::math::complement (lNormalDistribution, + s/DEFAULT_PRECISION)); + cdfVector.push_back (cdfValue); } // Compute V_j(x) for x > currentProtection (y_(j-1)). @@ -88,31 +91,31 @@ // Compute the first integral in the V_j(x) formulation (see // the memo of Jerome Contant). - const double power1 = - 0.5 * meanDemand * meanDemand / - (SDDemand * SDDemand); + const double power1 = + - 0.5 * meanDemand * meanDemand / (SDDemand * SDDemand); const double e1 = std::exp (power1); const double power2 = - - 0.5 * (lowerBound / DEFAULT_PRECISION - meanDemand) * - (lowerBound / DEFAULT_PRECISION - meanDemand) / - (SDDemand * SDDemand); - const double e2 = exp (power2); - /* - const double integralResult1 = currentYield * - ((e1 - e2) * SDDemand / sqrt (2 * 3.14159265) + - meanDemand * gsl_cdf_gaussian_Q (-meanDemand, SDDemand) - - meanDemand * gsl_cdf_gaussian_Q (lowerBound / DEFAULT_PRECISION - meanDemand, SDDemand)); - */ - const double integralResult1 = currentYield * - ((e1 - e2) * SDDemand / sqrt (2 * 3.14159265) + - meanDemand * cdfGaussianQ (-meanDemand, SDDemand) - - meanDemand * cdfGaussianQ (lowerBound / DEFAULT_PRECISION - meanDemand, SDDemand)); + - 0.5 * (lowerBound / DEFAULT_PRECISION - meanDemand) + * (lowerBound / DEFAULT_PRECISION - meanDemand) + / (SDDemand * SDDemand); + const double e2 = std::exp (power2); + + const double cdfValue0 = + boost::math::cdf (boost::math::complement (lNormalDistribution, + 0.0)); + const double cdfValue1 = + boost::math::cdf(boost::math::complement(lNormalDistribution, + lowerBound/DEFAULT_PRECISION)); + const double integralResult1 = currentYield + * ((e1 - e2) * SDDemand / sqrt (2 * 3.14159265) + + meanDemand * (cdfValue0 - cdfValue1)); double integralResult2 = 0.0; for (int s = 0; s < lowerBound; ++s) { const double partialResult = - 2 * MERVectorHolder.at(currentBucketIndex-1).at(x-s) * - pdfVector.at(s); + 2 * MERVectorHolder.at(currentBucketIndex-1).at(x-s) + * pdfVector.at(s); integralResult2 += partialResult; } @@ -139,11 +142,13 @@ // Compute the second integral in the V_j(x) formulation (see // the memo of Jerome Contant). const double constCoefOfSecondElement = - currentYield * lowerBound / DEFAULT_PRECISION + - MERVectorHolder.at(currentBucketIndex-1).at(currentProtection); - const double secondElement = constCoefOfSecondElement * - //gsl_cdf_gaussian_Q(lowerBound / DEFAULT_PRECISION - meanDemand, SDDemand); - cdfGaussianQ (lowerBound / DEFAULT_PRECISION - meanDemand, SDDemand); + currentYield * lowerBound / DEFAULT_PRECISION + + MERVectorHolder.at(currentBucketIndex-1).at(currentProtection); + + const double secondElement = constCoefOfSecondElement + * boost::math::cdf(boost::math::complement(lNormalDistribution, + lowerBound/DEFAULT_PRECISION)); + const double MERValue = (firstElement + secondElement) / errorFactor; @@ -200,20 +205,4 @@ } } - // //////////////////////////////////////////////////////////////////// - double DPOptimiser::cdfGaussianQ (const double c, const double sd) { - const double power = - c * c * 0.625 / (sd * sd); - const double e = std::sqrt (1 - std::exp (power)); - double result = 0.0; - - if (c >= 0) { - result = 0.5 * (1 - e); - - } else { - result = 0.5 * (1 + e); - } - - return result; - } - } Modified: trunk/rmol/rmol/bom/EmsrUtils.cpp =================================================================== --- trunk/rmol/rmol/bom/EmsrUtils.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/EmsrUtils.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,11 +1,11 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL Random Number Generation (GSL Reference Manual, version 1.7, Chapter 19) -#include <gsl/gsl_cdf.h> -// C -#include <math.h> -#include <assert.h> +// STL +#include <cassert> +#include <cmath> +// Boost Math +#include <boost/math/distributions/normal.hpp> // RMOL #include <rmol/bom/EmsrUtils.hpp> #include <rmol/bom/Bucket.hpp> @@ -53,17 +53,24 @@ const double lNextYield = ioNextBucket.getAverageYield(); assert (lAggreatedYield != 0); - // Compute the protection for the aggregated class/bucket - const double lProtection = - lMean + gsl_cdf_gaussian_Qinv (lNextYield/lAggreatedYield, lSD); + // Compute the yield ratio between the higher bucket and the current one + const double lYieldRatio = lNextYield / lAggreatedYield; + + /** Compute the protection for the aggregated class/bucket. + <br>Note: The inverse cdf is the quantile function (see also + http://en.wikipedia.org/wiki/Quantile_function). */ + boost::math::normal lNormalDistribution (lMean, lSD); + const double lProtection = + boost::math::quantile (boost::math::complement (lNormalDistribution, + lYieldRatio)); return lProtection; } // //////////////////////////////////////////////////////////////////// - const double EmsrUtils::computeProtectionLevelwithSellup (Bucket& iHigherBucket, - Bucket& iBucket, - double iSellupFactor){ + const double EmsrUtils:: + computeProtectionLevelwithSellup (Bucket& iHigherBucket, Bucket& iBucket, + double iSellupFactor) { // Retrieve the mean and the standard deviation of the higher // class(es)/bucket(s) depending EMSR-a or EMSR-b // and the average yield of each input classes/buckets @@ -74,25 +81,34 @@ assert (lHigherBucketYield > DEFAULT_EPSILON); assert (1-iSellupFactor > DEFAULT_EPSILON); - // compute the protection level for the higher class/bucket - const double lProtectionLevel = - lMean + - gsl_cdf_gaussian_Pinv((lHigherBucketYield-lBucketYield)/ - (lHigherBucketYield*(1-iSellupFactor)),lSD); - + // Compute the yield ratio + const double lYieldRatio = (lHigherBucketYield - lBucketYield) + / (lHigherBucketYield * (1 - iSellupFactor)); + + /** Compute the protection for the for the higher class/bucket. + <br>Note: The inverse cdf is the quantile function (see also + http://en.wikipedia.org/wiki/Quantile_function). */ + boost::math::normal lNormalDistribution (lMean, lSD); + const double lProtectionLevel = boost::math::quantile (lNormalDistribution, + lYieldRatio); + return lProtectionLevel; } // //////////////////////////////////////////////////////////////////// - const double EmsrUtils::computeEmsrValue (double iCapacity, Bucket& ioBucket) { - // Retrive the average yield, mean and standard deviation of the + const double EmsrUtils::computeEmsrValue (double iCapacity, + Bucket& ioBucket) { + // Retrieve the average yield, mean and standard deviation of the // demand of the class/bucket. const double lMean = ioBucket.getMean(); const double lSD = ioBucket.getStandardDeviation(); const double lYield = ioBucket.getAverageYield(); // Compute the EMSR value = lYield * Pr (demand >= iCapacity). - const double emsrValue = lYield * gsl_cdf_gaussian_Q(iCapacity-lMean, lSD); + boost::math::normal lNormalDistribution (lMean, lSD); + const double emsrValue = + lYield * boost::math::cdf (boost::math::complement (lNormalDistribution, + iCapacity)); return emsrValue; } Modified: trunk/rmol/rmol/bom/ExpectationMaximization.cpp =================================================================== --- trunk/rmol/rmol/bom/ExpectationMaximization.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/ExpectationMaximization.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,11 +1,11 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL -#include <gsl/gsl_cdf.h> // STL #include <cassert> #include <cmath> +// Boost Math +#include <boost/math/distributions/normal.hpp> // StdAir #include <stdair/service/Logger.hpp> // RMOL @@ -125,18 +125,21 @@ */ double e, d1, d2; const double lerror = kthCensoredData - iMean; - d1 = gsl_cdf_gaussian_Q (lerror, iSD); - e = - (lerror) * (lerror) * 0.5 / (iSD * iSD); - d2 = exp(e) * iSD / sqrt(2 * 3.14159265); + + // + boost::math::normal lNormalDistribution (iMean, iSD); + d1 = boost::math::cdf (boost::math::complement (lNormalDistribution, + kthCensoredData)); + e = -lerror*lerror * 0.5 / (iSD*iSD); + d2 = exp(e) * iSD / sqrt (2 * 3.14159265); if (d1 < DEFAULT_EPSILON) { - ioUnconstrainedDataHolder.push_back(kthCensoredData); + ioUnconstrainedDataHolder.push_back (kthCensoredData); + + } else { + ioUnconstrainedDataHolder.push_back (iMean + d2/d1); } - else { - ioUnconstrainedDataHolder.push_back(iMean + d2/d1); - } } } - // ////////////////////////////////////////////////////////////////////// } Modified: trunk/rmol/rmol/bom/Gaussian.cpp =================================================================== --- trunk/rmol/rmol/bom/Gaussian.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/Gaussian.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -2,76 +2,46 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL Random Number Distributions (GSL Reference Manual, version 1.7, -// Chapter 19) -#include <gsl/gsl_randist.h> // RMOL #include <rmol/bom/Gaussian.hpp> namespace RMOL { // ////////////////////////////////////////////////////////////////////// - Gaussian::Gaussian () : - _rngTypePtr (gsl_rng_default), _rngPtr (NULL), - _params (FldDistributionParameters()) { - initRandomGenerator(); + Gaussian::Gaussian (const FldDistributionParameters& iParams) + : _seed (42u), _generator (42u), + _normalDistribution (iParams.getMean(), iParams.getStandardDeviation()), + _normalDistributionGenerator (_generator, _normalDistribution) { + init(); } // ////////////////////////////////////////////////////////////////////// - Gaussian::Gaussian (const Gaussian& iGaussian) : - _rngTypePtr (gsl_rng_default), _rngPtr (NULL), - _params (iGaussian.getDistributionParameters()) { - initRandomGenerator(); + void Gaussian::init() { } // ////////////////////////////////////////////////////////////////////// - Gaussian::Gaussian (const FldDistributionParameters& iParams) : - _rngTypePtr (gsl_rng_default), _rngPtr (NULL), - _params (FldDistributionParameters (iParams.getMean(), - iParams.getStandardDeviation())) { - initRandomGenerator(); - } - - // ////////////////////////////////////////////////////////////////////// Gaussian::~Gaussian() { // Release the memory for the random generator - gsl_rng_free (_rngPtr); } // ////////////////////////////////////////////////////////////////////// double Gaussian::getMean() const { - return _params.getMean(); + return _normalDistribution.mean(); } // ////////////////////////////////////////////////////////////////////// double Gaussian::getStandardDeviation() const { - return _params.getStandardDeviation(); + return _normalDistribution.sigma(); } - // ////////////////////////////////////////////////////////////////////// double Gaussian::getVariance() const { - return _params.getVariance(); + return (_normalDistribution.sigma() * _normalDistribution.sigma()); } // ////////////////////////////////////////////////////////////////////// - void Gaussian::initRandomGenerator () { - // Initialise the Random Generator - gsl_rng_env_setup (); - - // Allocate the memory for the random generator - _rngPtr = gsl_rng_alloc (_rngTypePtr); - } - - // ////////////////////////////////////////////////////////////////////// - double Gaussian::generateVariate () const { - - const double mean = getMean(); - const double standardDeviation = getStandardDeviation(); - - double result = gsl_ran_gaussian (_rngPtr, standardDeviation); - result += mean; - + double Gaussian::generateVariate() { + const double result = _normalDistributionGenerator(); return result; } Modified: trunk/rmol/rmol/bom/Gaussian.hpp =================================================================== --- trunk/rmol/rmol/bom/Gaussian.hpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/Gaussian.hpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,36 +1,61 @@ -#ifndef __RMOL_GAUSSIAN_HPP -#define __RMOL_GAUSSIAN_HPP +#ifndef __RMOL_BOM_GAUSSIAN_HPP +#define __RMOL_BOM_GAUSSIAN_HPP // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL Random Number Generation (GSL Reference Manual, version 1.7, Chapter 17) -#include <gsl/gsl_rng.h> +// Boost Random +#include <boost/random/linear_congruential.hpp> +#include <boost/random/normal_distribution.hpp> +#include <boost/random/variate_generator.hpp> // RMOL #include <rmol/field/FldDistributionParameters.hpp> namespace RMOL { - /** Gaussian Distribution-based Utilities. */ + // ////////// Type definitions ////////// + /** Type definition for the random generator seed. + <br>That seed must be unsigned, otherwise the wrong overload may be + selected when using mt19937 as the base_generator_type. */ + typedef unsigned int random_generator_seed_type; + + + /** Wrapper around a random generator following a normal distribution. */ class Gaussian { + private: + // ////////// Type definitions ////////// + /** Type definition for a random number generator base (mt19937). */ + typedef boost::minstd_rand base_generator_type; + + /** Type definiton for the normal distribution (characteristics). */ + typedef boost::normal_distribution<> normal_dist_type; + + /** Type definition for the normal distribution random generator. */ + typedef boost::variate_generator<base_generator_type&, + normal_dist_type> normal_gen_type; + public: - /** Constructors. */ + /** Constructor with mean and sigma (standard deviation) for + the normal Distribution. + <br>See also + http://www.boost.org/doc/libs/1_44_0/doc/html/boost/normal_distribution.html */ + Gaussian (const FldDistributionParameters&); + + /** Destructor. */ + ~Gaussian(); + + private: + /** Default constructors. + <br>They are kept private so that the class can be instantiated only + with the public constructor. */ Gaussian (); Gaussian (const Gaussian&); - /** Constructor with mean and standard deviation of - the Gaussian Distribution. */ - Gaussian (const FldDistributionParameters&); - /** Destructors. */ - virtual ~Gaussian(); - - // Getters - /** Getter for the parameters for the Gaussian distribution (i.e., - mean and standard deviation). */ - const FldDistributionParameters& getDistributionParameters() const { - return _params; - } + /** Initialise the random generator. */ + void init(); + public: + // /////////////////// Getters ////////////////// /** Getter for the mean value. */ double getMean() const; @@ -43,20 +68,21 @@ /** Generate a Gaussian random variate (following the Gaussian distribution). */ - double generateVariate () const; + double generateVariate(); private: - // Wrapper on GSL Random Generators (type and generator) - const gsl_rng_type* _rngTypePtr; - gsl_rng* _rngPtr; + /** Seed of the random generator. */ + const random_generator_seed_type _seed; - // Gaussian distribution characteristics - FldDistributionParameters _params; + /** Base for the random generator. */ + base_generator_type _generator; - private: - // Initialise the Random Generator - void initRandomGenerator(); + /** Normal distribution. */ + normal_dist_type _normalDistribution; + + /** Random generator for the normal distribution. */ + normal_gen_type _normalDistributionGenerator; }; } -#endif // __RMOL_GAUSSIAN_HPP +#endif // __RMOL_BOM_GAUSSIAN_HPP Modified: trunk/rmol/rmol/bom/HistoricalBookingHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalBookingHolder.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/HistoricalBookingHolder.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,18 +1,14 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL Random Number Generation -// (GSL Reference Manual, version 1.7, Chapter 19) -#include <gsl/gsl_cdf.h> -#include <gsl/gsl_randist.h> -// C -#include <assert.h> -#include <math.h> // STL +#include <cassert> #include <iostream> #include <iomanip> #include <cmath> -// RMU +// Boost Math +#include <boost/math/distributions/normal.hpp> +// RMOL #include <rmol/bom/HistoricalBooking.hpp> #include <rmol/bom/HistoricalBookingHolder.hpp> @@ -211,13 +207,15 @@ d1 = 0.5 * (1 + s); } */ + + // + boost::math::normal lNormalDistribution (iMean, iSD); + d1 = boost::math::cdf (boost::math::complement (lBooking, _capacity)); - d1 = gsl_cdf_gaussian_Q (lBooking - iMean, iSD); - e = - (lBooking - iMean) * (lBooking - iMean) * 0.5 / (iSD * iSD); e = exp (e); - d2 = e * iSD / sqrt(2 * 3.14159265); + d2 = e * iSD / sqrt (2 * 3.14159265); // std::cout << "d1, d2 = " << d1 << " " << d2 << std::endl; Modified: trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/HistoricalBookingHolderHolder.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,17 +1,14 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL Random Number Generation (GSL Reference Manual, version 1.7, Chapter 19) -#include <gsl/gsl_cdf.h> -#include <gsl/gsl_randist.h> -// C -#include <assert.h> -#include <math.h> // STL +#include <cassert> #include <iostream> #include <iomanip> #include <cmath> -// RMU +// Boost Math +#include <boost/math/distributions/normal.hpp> +// RMOL #include <rmol/bom/HistoricalBookingHolder.hpp> #include <rmol/bom/HistoricalBookingHolderHolder.hpp> @@ -210,9 +207,9 @@ // d1 = 0.5 * (1 + s); // } // */ - -// d1 = gsl_cdf_gaussian_Q (lBooking - iMean, iSD); - +// +// boost::math::normal lNormalDistribution (iMean, iSD); +// d1 = boost::math::cdf (boost::math::complement (lBooking, _capacity)); // e = - (lBooking - iMean) * (lBooking - iMean) * 0.5 / (iSD * iSD); // e = exp (e); Modified: trunk/rmol/rmol/bom/HistoricalDataHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalDataHolder.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/HistoricalDataHolder.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,17 +1,11 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL Random Number Generation -// (GSL Reference Manual, version 1.7, Chapter 19) -#include <gsl/gsl_cdf.h> -#include <gsl/gsl_randist.h> -// C -#include <assert.h> -#include <math.h> // STL +#include <cassert> #include <iostream> //#include <iomanip> -//#include <cmath> +#include <cmath> // RMU #include <rmol/bom/HistoricalDataHolder.hpp> Modified: trunk/rmol/rmol/bom/HistoricalDataHolderHolder.cpp =================================================================== --- trunk/rmol/rmol/bom/HistoricalDataHolderHolder.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/HistoricalDataHolderHolder.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,18 +1,12 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// GSL Random Number Generation -// (GSL Reference Manual, version 1.7, Chapter 19) -// #include <gsl/gsl_cdf.h> -// #include <gsl/gsl_randist.h> -// C -// #include <assert.h> -// #include <math.h> // STL + #include <cassert> #include <iostream> -#include <iomanip> -// #include <cmath> -// RMU +//#include <iomanip> +//#include <cmath> +// RMOL #include <rmol/bom/HistoricalDataHolder.hpp> #include <rmol/bom/HistoricalDataHolderHolder.hpp> Modified: trunk/rmol/rmol/bom/MCOptimiser.cpp =================================================================== --- trunk/rmol/rmol/bom/MCOptimiser.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/MCOptimiser.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -4,9 +4,7 @@ // STL #include <cassert> #include <string> -#include <fstream> #include <sstream> -#include <cmath> // StdAir #include <stdair/basic/BasChronometer.hpp> #include <stdair/service/Logger.hpp> @@ -75,7 +73,7 @@ */ const FldDistributionParameters& aDistribParams = currentBucket.getDistributionParameters(); - const Gaussian gaussianDemandGenerator (aDistribParams); + Gaussian gaussianDemandGenerator (aDistribParams); /** DEBUG STDAIR_LOG_DEBUG ("[" << j << "]: " << Kj << " values with N ( " @@ -208,7 +206,7 @@ // STEP 1. const FldDistributionParameters& aDistribParams = currentBucket.getDistributionParameters(); - const Gaussian gaussianDemandGenerator (aDistribParams); + Gaussian gaussianDemandGenerator (aDistribParams); VariateList_T aVariateList; @@ -308,7 +306,7 @@ */ const FldDistributionParameters& aDistribParams = currentBucket.getDistributionParameters(); - const Gaussian gaussianDemandGenerator (aDistribParams); + Gaussian gaussianDemandGenerator (aDistribParams); /** DEBUG STDAIR_LOG_DEBUG ("[" << j << "]: " << Kj << " values with N ( " @@ -452,7 +450,7 @@ // STEP 1. const FldDistributionParameters& aDistribParams = currentBucket.getDistributionParameters(); - const Gaussian gaussianDemandGenerator (aDistribParams); + Gaussian gaussianDemandGenerator (aDistribParams); VariateList_T aVariateList; Modified: trunk/rmol/rmol/bom/Makefile.am =================================================================== --- trunk/rmol/rmol/bom/Makefile.am 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/Makefile.am 2010-09-27 11:36:24 UTC (rev 338) @@ -6,8 +6,8 @@ noinst_LTLIBRARIES = librmolbom.la librmolbom_la_SOURCES = $(rmol_bom_h_sources) $(rmol_bom_cc_sources) -librmolbom_la_CXXFLAGS = $(GSL_CFLAGS) $(BOOST_CFLAGS) $(STDAIR_CFLAGS) -librmolbom_la_LDFLAGS = $(GSL_LIBS) +librmolbom_la_CXXFLAGS = $(BOOST_CFLAGS) $(STDAIR_CFLAGS) +librmolbom_la_LDFLAGS = # #pkgincludedir = $(includedir)/@PACKAGE@/bom Modified: trunk/rmol/rmol/bom/Overbooking.cpp =================================================================== --- trunk/rmol/rmol/bom/Overbooking.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/bom/Overbooking.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -1,16 +1,14 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> // STL -#include <iostream> -// GSL -#include <gsl/gsl_sys.h> -#include <gsl/gsl_math.h> -#include <gsl/gsl_sf.h> -#include <gsl/gsl_randist.h> -#include <gsl/gsl_cdf.h> +#include <cassert> +// Boost Math +#include <boost/math/special_functions/pow.hpp> +#include <boost/math/special_functions/powm1.hpp> +#include <boost/math/special_functions/round.hpp> +#include <boost/math/distributions/binomial.hpp> +#include <boost/math/distributions/normal.hpp> // RMOL #include <rmol/basic/BasConst_Overbooking.hpp> #include <rmol/bom/Overbooking.hpp> @@ -335,9 +333,13 @@ const double lDemandStdDev = _demandDistributionParameters.getStandardDeviation(); + boost::math::normal lNormalDistribution (lDemandMean, + lDemandStdDev); + // Algorithm double pNormal = - gsl_cdf_gaussian_Q (_capacity - lDemandMean, lDemandStdDev); + boost::math::cdf (boost::math::complement (lNormalDistribution, + _capacity)); // double pNormal = probabilityNormal (CAPACITY, DEMAND_AVERAGE, // DEMAND_DEVIATION); @@ -348,20 +350,22 @@ } assert (PRICE_OVER_DENIED_COST < 1 - pNormal); - pNormal = gsl_cdf_gaussian_Q (_capacity - 1 - lDemandMean, - lDemandStdDev); + pNormal = + boost::math::cdf (boost::math::complement (lNormalDistribution, + _capacity - 1)); // pNormal = probabilityNormal (CAPACITY-1, DEMAND_AVERAGE, // DEMAND_DEVIATION); const double lNoShowMean = _noShowDistributionParameters.getMean(); - - double lProbability = (1 - pNormal) - * gsl_sf_pow_int (lNoShowMean, _capacity); + double lProbability = + (1 - pNormal) * (boost::math::powm1 (lNoShowMean, _capacity) + 1); + int counter = 1; - while ((lProbability < PRICE_OVER_DENIED_COST) && (counter < 100)) { - counter++; + while (lProbability < PRICE_OVER_DENIED_COST && counter < 100) { + ++counter; + if (resultBookingLimit >= MAX_BOOKING_LIMIT) { return resultBookingLimit; @@ -371,7 +375,9 @@ const unsigned int b = static_cast<unsigned int> (resultBookingLimit); - pNormal = gsl_cdf_gaussian_Q (b + 1 - lDemandMean, lDemandStdDev); + pNormal = + boost::math::cdf (boost::math::complement (lNormalDistribution, + b + 1)); // pNormal = probabilityNormal (b+1, DEMAND_AVERAGE, DEMAND_DEVIATION); @@ -380,51 +386,30 @@ // assert (b >= 0); (derived from the other two) - // The cumulated probability that the number of shows exceeds - // the leg/cabin physical capacity - lProbability += (1+pNormal) - * lNoShowMean * gsl_ran_binomial_pdf (_capacity-1, lNoShowMean, b); - + /** + The probability that the number of shows exceeds the leg/cabin + physical capacity follows a binomial distribution, with the following + parameters:<br> + <ul> + <li>"Probability of success (== no-show)": p == lNoShowMean</li> + <li>"Number of trials (== bookings)": n == b</li> + <li>"Number of successes (no-shows)": k == _capacity - 1</li> + </ul> */ + boost::math::binomial lBinomialDistribution (lNoShowMean, b); + lProbability += (1 + pNormal) * lNoShowMean + * boost::math::pdf (lBinomialDistribution, _capacity-1); } return resultBookingLimit; } - // Private useful functions, some of them are to be replaced by gsl - // library's functions + // Private useful functions // ////////////////////////////////////////////////////////////////////// - //to be deleted, already available in gsl lib - //cumulated binomial probability - double Overbooking::probabilityNormal (const int b, const double average, - const double sdeviation) const { - double resultCdf = 0.0; - for (int i=0; i < b+1 ; i++) { - resultCdf += 1 /( sqrt(2 * M_PI) ) - * gsl_sf_exp (-1* (gsl_sf_pow_int(i-average, 2)) / (2*sdeviation)); - } - return resultCdf; - } - - // ////////////////////////////////////////////////////////////////////// - - // to be deleted, already available in gsl lib, gsl_ran_binomial_pdf(unsigned int k, double SHOW_RATE, unsigned int b) - double Overbooking::binomialProbability_F_b_s (const double iShowRate, - const int b, - const int k) const { - double Factorials = gsl_sf_fact(b)/gsl_sf_fact(k)/gsl_sf_fact(b-k); - double f = Factorials* - gsl_sf_pow_int(iShowRate, k)*gsl_sf_pow_int(1-iShowRate, b-k) ; - - return f; - } - // pSHOW_RATEbability to deny one or more services // ////////////////////////////////////////////////////////////////////// - - ////////////// Private functions for Servive level policies///////////// // service level 1 : cumulated probability of having no-shows @@ -432,10 +417,21 @@ // ////////////////////////////////////////////////////////////////////// double Overbooking::serviceLevel1 (const double iShowRate, - const int b, const int C) const { - double resultProbability = 1.0; - for (int i = 1; i<=C; i++) { - resultProbability -= gsl_ran_binomial_pdf (i, iShowRate, b);} + const int b, const int iCapacity) const { + + /** + The probability that the number of shows exceeds the leg/cabin + physical capacity follows a binomial distribution, with the following + parameters:<br> + <ul> + <li>"Probability of success (== no-show)": p == iShowRate</li> + <li>"Number of trials (== bookings)": n == b</li> + <li>"Number of successes (no-shows)": k == iCapacity</li> + </ul> */ + boost::math::binomial lBinomialDistribution (iShowRate, b); + const double resultProbability = + boost::math::cdf (lBinomialDistribution, iCapacity); + return resultProbability; } Modified: trunk/rmol/rmol/core/Makefile.am =================================================================== --- trunk/rmol/rmol/core/Makefile.am 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/core/Makefile.am 2010-09-27 11:36:24 UTC (rev 338) @@ -22,6 +22,6 @@ $(top_builddir)/rmol/service/librmolsvc.la librmol_la_LDFLAGS = \ $(BOOST_DATE_TIME_LIB) $(BOOST_PROGRAM_OPTIONS_LIB) \ - $(BOOST_FILESYSTEM_LIB) $(STDAIR_LIBS) $(GSL_LIBS) \ + $(BOOST_FILESYSTEM_LIB) $(STDAIR_LIBS) \ -version-info $(GENERIC_LIBRARY_VERSION) Modified: trunk/rmol/rmol/service/RMOL_ServiceContext.cpp =================================================================== --- trunk/rmol/rmol/service/RMOL_ServiceContext.cpp 2010-09-13 18:56:50 UTC (rev 337) +++ trunk/rmol/rmol/service/RMOL_ServiceContext.cpp 2010-09-27 11:36:24 UTC (rev 338) @@ -120,11 +120,11 @@ lDemandVector.reserve (K); const FldDistributionParameters aDistributionParam = FldDistributionParameters (iMean, iDeviation); - const Gaussian gaussianDemandGenerator (aDistributionParam); + Gaussian gaussianDemandGenerator (aDistributionParam); // Generate K numbers for (int i = 0; i < K; ++i) { - const double lGeneratedDemand = gaussianDemandGenerator.generateVariate (); + const double lGeneratedDemand= gaussianDemandGenerator.generateVariate (); lDemandVector.push_back (lGeneratedDemand); } @@ -137,17 +137,26 @@ GeneratedDemandVector_T* ioSecondVector) { if (ioFirstVector == NULL || ioSecondVector == NULL) { return NULL; + } else { + assert (ioFirstVector != NULL); + assert (ioSecondVector != NULL); + const unsigned int K = ioFirstVector->size(); assert (K == ioSecondVector->size()); + _generatedDemandVectorHolder.push_back (DEFAULT_GENERATED_DEMAND_VECTOR); GeneratedDemandVectorHolder_T::reverse_iterator itLastVector = _generatedDemandVectorHolder.rbegin(); + GeneratedDemandVector_T& lDemandVector = *itLastVector; lDemandVector.reserve (K); - for (unsigned int i = 0; i < K; ++i) { - const double lGeneratedDemand = - ioFirstVector->at(i) + ioSecondVector->at(i); + GeneratedDemandVector_T::const_iterator itFirst = ioFirstVector->begin(); + GeneratedDemandVector_T::const_iterator itSecond= ioSecondVector->begin(); + for ( ; itFirst != ioFirstVector->end(); ++itFirst, ++itSecond) { + const double& lFirst = *itFirst; + const double& lSecond = *itSecond; + const double lGeneratedDemand = lFirst + lSecond; lDemandVector.push_back (lGeneratedDemand); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |