From: <den...@us...> - 2010-01-21 19:34:04
|
Revision: 290 http://rmol.svn.sourceforge.net/rmol/?rev=290&view=rev Author: denis_arnaud Date: 2010-01-21 19:33:33 +0000 (Thu, 21 Jan 2010) Log Message: ----------- [Dev] The log output stream initialisation has been moved into the StdAir library. Modified Paths: -------------- trunk/rmol/test/rmol/ForecasterTestSuite.cpp trunk/rmol/test/rmol/OptimiseTestSuite.cpp trunk/rmol/test/rmol/UnconstrainerTestSuite.cpp trunk/rmol/test/rmol/bomsforforecaster.cpp Modified: trunk/rmol/test/rmol/ForecasterTestSuite.cpp =================================================================== --- trunk/rmol/test/rmol/ForecasterTestSuite.cpp 2010-01-21 19:33:17 UTC (rev 289) +++ trunk/rmol/test/rmol/ForecasterTestSuite.cpp 2010-01-21 19:33:33 UTC (rev 290) @@ -33,7 +33,8 @@ std::ostringstream oDebugStr; // Initialise the RMOL service - RMOL::RMOL_Service rmolService (logOutputFile); + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + RMOL::RMOL_Service rmolService (lLogParams); // A sample historical demand data to be processed by forecaster // Class | Q | M | B | Y | Modified: trunk/rmol/test/rmol/OptimiseTestSuite.cpp =================================================================== --- trunk/rmol/test/rmol/OptimiseTestSuite.cpp 2010-01-21 19:33:17 UTC (rev 289) +++ trunk/rmol/test/rmol/OptimiseTestSuite.cpp 2010-01-21 19:33:33 UTC (rev 290) @@ -41,7 +41,9 @@ logOutputFile.clear(); // Initialise the RMOL service - RMOL::RMOL_Service rmolService (logOutputFile, cabinCapacity); + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + RMOL::RMOL_Service rmolService (lLogParams, cabinCapacity); + rmolService.setUpStudyStatManager(); // Define bid price and booking Limit vectors RMOL::BidPriceVector_T lBidPriceVector; @@ -69,66 +71,70 @@ } switch (METHOD_FLAG) { + case 0 : { + // Calculate the optimal protections by the Monte Carlo + // Integration approach + rmolService.optimalOptimisationByMCIntegration (K); + break; + } + + case 1 : { + // Calculate the optimal protections by DP. + rmolService.optimalOptimisationByDP (); + break; + } + + case 2 : { + // Calculate the Bid-Price Vector by EMSR + rmolService.heuristicOptimisationByEmsr (); + break; + } + + case 3 : { + // Calculate the protections by EMSR-a + // Test the EMSR-a algorithm implementation + rmolService.heuristicOptimisationByEmsrA (lBidPriceVector, + lProtectionLevelVector, + lBookingLimitVector); - case 0 : // Calculate the optimal protections by the Monte Carlo - // Integration approach - { - rmolService.optimalOptimisationByMCIntegration (K); - break; - } - case 1 : // Calculate the optimal protections by DP. - { - rmolService.optimalOptimisationByDP (); - break; + // Return a cumulated booking limit value to test + oExpectedBookingLimit = static_cast<int> (lBookingLimitVector.at(2)); + break; + } + + case 4 : { + // Calculate the protections by EMSR-b + rmolService.heuristicOptimisationByEmsrB (); + break; + } + + case 5 : { + // Calculate the protection by EMSR-a with sellup + // Create an empty sell-up probability vector + std::vector<double> sellupProbabilityVector; + + // Define the sell-up probability to be 20% + const double sampleProbability = 0.2; + + // NOTE: size of sellup vector should be equal to no of buckets - 1 + // TODO: check that with an assertion + const short nbOfSampleBucket = 4; + for (short i = 1; i <= nbOfSampleBucket - 1; i++) { + sellupProbabilityVector.push_back (sampleProbability); } - case 2 : // Calculate the Bid-Price Vector by EMSR - { - rmolService.heuristicOptimisationByEmsr (); - break; - } - case 3 : // Calculate the protections by EMSR-a - { - // Test the EMSR-a algorithm implementation - rmolService.heuristicOptimisationByEmsrA (lBidPriceVector, - lProtectionLevelVector, - lBookingLimitVector); + + // Test the algorithm with the sample sell-up vector + rmolService.heuristicOptimisationByEmsrAwithSellup + (sellupProbabilityVector, lProtectionLevelVector, + lBidPriceVector, lBookingLimitVector); + + // Return a cumulated booking limit value to test + oExpectedBookingLimit = static_cast<int> (lBookingLimitVector.at(2)); + + break; + } - // Return a cumulated booking limit value to test - oExpectedBookingLimit = static_cast<int> (lBookingLimitVector.at(2)); - break; - } - case 4 : // Calculate the protections by EMSR-b - { - rmolService.heuristicOptimisationByEmsrB (); - break; - } - case 5 : // Calculate the protection by EMSR-a with sellup - { - // Create an empty sell-up probability vector - std::vector<double> sellupProbabilityVector; - - // Define the sell-up probability to be 20% - const double sampleProbability = 0.2; - - // NOTE: size of sellup vector should be equal to no of buckets - 1 - // TODO: check that with an assertion - const short nbOfSampleBucket = 4; - for (short i = 1; i <= nbOfSampleBucket - 1; i++) { - sellupProbabilityVector.push_back (sampleProbability); - } - - // Test the algorithm with the sample sell-up vector - rmolService.heuristicOptimisationByEmsrAwithSellup - (sellupProbabilityVector, lProtectionLevelVector, - lBidPriceVector, lBookingLimitVector); - - // Return a cumulated booking limit value to test - oExpectedBookingLimit = static_cast<int> (lBookingLimitVector.at(2)); - - break; - } - - default : rmolService.optimalOptimisationByMCIntegration (K); + default: rmolService.optimalOptimisationByMCIntegration (K); } } catch (const std::exception& stde) { @@ -172,7 +178,7 @@ // EMSR-a void OptimiseTestSuite::testOptimiseEMSRa() { const int lExpectedBookingLimit = testOptimiseHelper(3); - CPPUNIT_ASSERT(lExpectedBookingLimit == 61); + CPPUNIT_ASSERT (lExpectedBookingLimit == 61); } // ////////////////////////////////////////////////////////////////////// Modified: trunk/rmol/test/rmol/UnconstrainerTestSuite.cpp =================================================================== --- trunk/rmol/test/rmol/UnconstrainerTestSuite.cpp 2010-01-21 19:33:17 UTC (rev 289) +++ trunk/rmol/test/rmol/UnconstrainerTestSuite.cpp 2010-01-21 19:33:33 UTC (rev 290) @@ -33,7 +33,8 @@ std::ostringstream oDebugStr; // Initialise the RMOL service - RMOL::RMOL_Service rmolService (logOutputFile); + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + RMOL::RMOL_Service rmolService (lLogParams); // A sample historical booking data to be processed by unconstrainer RMOL::ConstrainedDataHolder_T lConstrainedDataHolder; Modified: trunk/rmol/test/rmol/bomsforforecaster.cpp =================================================================== --- trunk/rmol/test/rmol/bomsforforecaster.cpp 2010-01-21 19:33:17 UTC (rev 289) +++ trunk/rmol/test/rmol/bomsforforecaster.cpp 2010-01-21 19:33:33 UTC (rev 290) @@ -3,14 +3,11 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <cassert> -#include <sstream> #include <fstream> -#include <string> -#include <limits> -// #include <iostream> +// StdAir +#include <stdair/service/Logger.hpp> // RMOL #include <rmol/RMOL_Service.hpp> -#include <rmol/service/Logger.hpp> namespace RMOL { @@ -190,8 +187,11 @@ // Open and clean the log outputfile logOutputFile.open (lLogFilename.c_str()); logOutputFile.clear(); - RMOL::RMOL_Service lRmolService(logOutputFile); + // Initialise the RMOL service + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + RMOL::RMOL_Service lRmolService (lLogParams); + // Register BCDataSet RMOL::BookingClassDataSet lBookingClassDataSet; @@ -202,10 +202,10 @@ RMOL::BookingClassData YClassData (0, 300, 0.3, false); // Display - RMOL_LOG_DEBUG(QClassData.toString()); - RMOL_LOG_DEBUG(MClassData.toString()); - RMOL_LOG_DEBUG(BClassData.toString()); - RMOL_LOG_DEBUG(YClassData.toString()); + STDAIR_LOG_DEBUG(QClassData.toString()); + STDAIR_LOG_DEBUG(MClassData.toString()); + STDAIR_LOG_DEBUG(BClassData.toString()); + STDAIR_LOG_DEBUG(YClassData.toString()); // Add BookingClassData into the BCDataSet lBookingClassDataSet.addBookingClassData (QClassData ); @@ -214,22 +214,24 @@ lBookingClassDataSet.addBookingClassData( YClassData ); //Display - RMOL_LOG_DEBUG( lBookingClassDataSet.toString() ); + STDAIR_LOG_DEBUG( lBookingClassDataSet.toString() ); // Number of classes const unsigned int lNoOfClass = lBookingClassDataSet.getNumberOfClass(); - RMOL_LOG_DEBUG( "Number of Classes: " << lNoOfClass ); + STDAIR_LOG_DEBUG( "Number of Classes: " << lNoOfClass ); // Minimum fare lBookingClassDataSet.updateMinimumFare(); const double lMinFare = lBookingClassDataSet.getMinimumFare(); - RMOL_LOG_DEBUG( "Minimum fare: " << lMinFare ); + STDAIR_LOG_DEBUG( "Minimum fare: " << lMinFare ); // Censorship flag lBookingClassDataSet.updateCensorshipFlag(); const bool lCensorshipFlag = lBookingClassDataSet.getCensorshipFlag(); - RMOL_LOG_DEBUG( "Censorship Flag: " << lCensorshipFlag ); + // DEBUG + STDAIR_LOG_DEBUG ( "Censorship Flag: " << lCensorshipFlag ); + // Close the log output file logOutputFile.close(); return 0; 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:04:06
|
Revision: 292 http://rmol.svn.sourceforge.net/rmol/?rev=292&view=rev Author: denis_arnaud Date: 2010-01-21 20:03:59 +0000 (Thu, 21 Jan 2010) Log Message: ----------- [Dev] The initialisation now requires an airline code. Modified Paths: -------------- trunk/rmol/test/rmol/ForecasterTestSuite.cpp trunk/rmol/test/rmol/OptimiseTestSuite.cpp trunk/rmol/test/rmol/UnconstrainerTestSuite.cpp trunk/rmol/test/rmol/bomsforforecaster.cpp Modified: trunk/rmol/test/rmol/ForecasterTestSuite.cpp =================================================================== --- trunk/rmol/test/rmol/ForecasterTestSuite.cpp 2010-01-21 20:03:39 UTC (rev 291) +++ trunk/rmol/test/rmol/ForecasterTestSuite.cpp 2010-01-21 20:03:59 UTC (rev 292) @@ -34,7 +34,8 @@ // Initialise the RMOL service const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); - RMOL::RMOL_Service rmolService (lLogParams); + const stdair::AirlineCode_T lAirlineCode ("BA"); + RMOL::RMOL_Service rmolService (lLogParams, lAirlineCode); // A sample historical demand data to be processed by forecaster // Class | Q | M | B | Y | Modified: trunk/rmol/test/rmol/OptimiseTestSuite.cpp =================================================================== --- trunk/rmol/test/rmol/OptimiseTestSuite.cpp 2010-01-21 20:03:39 UTC (rev 291) +++ trunk/rmol/test/rmol/OptimiseTestSuite.cpp 2010-01-21 20:03:59 UTC (rev 292) @@ -42,7 +42,8 @@ // Initialise the RMOL service const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); - RMOL::RMOL_Service rmolService (lLogParams, cabinCapacity); + const stdair::AirlineCode_T lAirlineCode ("BA"); + RMOL::RMOL_Service rmolService (lLogParams, lAirlineCode, cabinCapacity); rmolService.setUpStudyStatManager(); // Define bid price and booking Limit vectors Modified: trunk/rmol/test/rmol/UnconstrainerTestSuite.cpp =================================================================== --- trunk/rmol/test/rmol/UnconstrainerTestSuite.cpp 2010-01-21 20:03:39 UTC (rev 291) +++ trunk/rmol/test/rmol/UnconstrainerTestSuite.cpp 2010-01-21 20:03:59 UTC (rev 292) @@ -34,7 +34,8 @@ // Initialise the RMOL service const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); - RMOL::RMOL_Service rmolService (lLogParams); + const stdair::AirlineCode_T lAirlineCode ("BA"); + RMOL::RMOL_Service rmolService (lLogParams, lAirlineCode); // A sample historical booking data to be processed by unconstrainer RMOL::ConstrainedDataHolder_T lConstrainedDataHolder; Modified: trunk/rmol/test/rmol/bomsforforecaster.cpp =================================================================== --- trunk/rmol/test/rmol/bomsforforecaster.cpp 2010-01-21 20:03:39 UTC (rev 291) +++ trunk/rmol/test/rmol/bomsforforecaster.cpp 2010-01-21 20:03:59 UTC (rev 292) @@ -190,7 +190,8 @@ // Initialise the RMOL service const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); - RMOL::RMOL_Service lRmolService (lLogParams); + const stdair::AirlineCode_T lAirlineCode ("BA"); + RMOL::RMOL_Service lRmolService (lLogParams, lAirlineCode); // Register BCDataSet RMOL::BookingClassDataSet lBookingClassDataSet; 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:37:10
|
Revision: 339 http://rmol.svn.sourceforge.net/rmol/?rev=339&view=rev Author: denis_arnaud Date: 2010-09-27 11:37:00 +0000 (Mon, 27 Sep 2010) Log Message: ----------- [Dev] Replaced calls to the GSL (GNU Scientific Library) by Boost.Math. Modified Paths: -------------- trunk/rmol/test/rmol/Makefile.am trunk/rmol/test/rmol/SimulateTestSuite.cpp Property Changed: ---------------- trunk/rmol/test/rmol/ Property changes on: trunk/rmol/test/rmol ___________________________________________________________________ Modified: svn:ignore - .deps .libs Makefile Makefile.in optimise simulate sim.gnumeric OptimiseTestSuite OptimiseTestSuite.log OptimiseTestSuite_results.xml SimulateTestSuite SimulateTestSuite_results.xml rmol.log ForecasterTestSuite ForecasterTestSuite.log ForecasterTestSuite_results.xml UnconstrainerTestSuite UnconstrainerTestSuite.log UnconstrainerTestSuite_results.xml bomsforforecaster bomsforforecaster.log + .deps .libs Makefile Makefile.in optimise simulate sim.gnumeric OptimiseTestSuite OptimiseTestSuite.log OptimiseTestSuite_results.xml SimulateTestSuite SimulateTestSuite.log SimulateTestSuite_results.xml rmol.log ForecasterTestSuite ForecasterTestSuite.log ForecasterTestSuite_results.xml UnconstrainerTestSuite UnconstrainerTestSuite.log UnconstrainerTestSuite_results.xml bomsforforecaster bomsforforecaster.log Modified: trunk/rmol/test/rmol/Makefile.am =================================================================== --- trunk/rmol/test/rmol/Makefile.am 2010-09-27 11:36:24 UTC (rev 338) +++ trunk/rmol/test/rmol/Makefile.am 2010-09-27 11:37:00 UTC (rev 339) @@ -26,10 +26,10 @@ $(top_builddir)/rmol/core/librmol.la SimulateTestSuite_SOURCES = SimulateTestSuite.hpp SimulateTestSuite.cpp -SimulateTestSuite_CXXFLAGS = $(BOOST_CFLAGS) $(GSL_CFLAGS) $(CPPUNIT_CFLAGS) \ +SimulateTestSuite_CXXFLAGS = $(BOOST_CFLAGS) $(CPPUNIT_CFLAGS) \ $(EXTRACC_CFLAGS) $(STDAIR_CFLAGS) SimulateTestSuite_LDADD = -SimulateTestSuite_LDFLAGS = $(BOOST_LIBS) $(GSL_LIBS) $(CPPUNIT_LIBS) \ +SimulateTestSuite_LDFLAGS = $(BOOST_LIBS) $(CPPUNIT_LIBS) \ $(EXTRACC_LIBS) $(STDAIR_LIBS) ForecasterTestSuite_SOURCES = ForecasterTestSuite.hpp ForecasterTestSuite.cpp Modified: trunk/rmol/test/rmol/SimulateTestSuite.cpp =================================================================== --- trunk/rmol/test/rmol/SimulateTestSuite.cpp 2010-09-27 11:36:24 UTC (rev 338) +++ trunk/rmol/test/rmol/SimulateTestSuite.cpp 2010-09-27 11:37:00 UTC (rev 339) @@ -1,64 +1,58 @@ // STL #include <iostream> #include <sstream> -// Boost (Extended STL) +// Boost Date-Time #include <boost/date_time/posix_time/posix_time.hpp> -// GSL Random Number Generation (GSL Reference Manual, version 1.7, Chapter 17) -#include <gsl/gsl_rng.h> -// GSL Random Number Distributions (GSL Reference Manual, version 1.7, -// Chapter 19) -#include <gsl/gsl_randist.h> -// CPPUNIT +// Boost Random +#include <boost/random/linear_congruential.hpp> +#include <boost/random/poisson_distribution.hpp> +#include <boost/random/exponential_distribution.hpp> +#include <boost/random/variate_generator.hpp> +// Boost Math +#include <boost/math/distributions/normal.hpp> +// Extra-CPPUnit #include <extracppunit/CppUnitCore.hpp> // RMOL Test Suite #include <test/rmol/SimulateTestSuite.hpp> -// Random Generator Type -const gsl_rng_type* _rngTypePtr = NULL; +// ////////// Type definitions ////////// +/** Type definition for a random number generator base (mt19937). */ +typedef boost::minstd_rand base_generator_type; -// Random Generator -gsl_rng* _rngExponentialPtr = NULL; -gsl_rng* _rngPoissonPtr = NULL; +/** 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; -// /////////////////////////////////////////////////// -void init () { - // Random Generator type - _rngTypePtr = gsl_rng_default; +/** Type definiton for the Poisson distribution (characteristics). */ +typedef boost::poisson_distribution<> poisson_dist_type; + +/** Type definiton for the exponential distribution (characteristics). */ +typedef boost::exponential_distribution<> exponential_dist_type; + +/** Type definition for the Poisson distribution random generator. */ +typedef boost::variate_generator<base_generator_type&, + poisson_dist_type> poisson_gen_type; - // Initialise the Random Generator - gsl_rng_env_setup (); +/** Type definition for the exponential distribution random generator. */ +typedef boost::variate_generator<base_generator_type&, + exponential_dist_type> exponential_gen_type; - // Allocate the memory for the random generator - _rngExponentialPtr = gsl_rng_alloc (_rngTypePtr); - _rngPoissonPtr = gsl_rng_alloc (_rngTypePtr); -} - -// /////////////////////////////////////////////////// -double generateExponentialVariate (const double iLambda) { - const double lMu = 1/iLambda; - double result = gsl_ran_exponential (_rngExponentialPtr, lMu); - return result; -} - -// /////////////////////////////////////////////////// -double generatePoissonVariate (const double iMu) { - double result = gsl_ran_poisson (_rngPoissonPtr, iMu); - return result; -} - -// /////////////////////////////////////////////////// -void finalise () { - gsl_rng_free (_rngExponentialPtr); - gsl_rng_free (_rngPoissonPtr); -} - // ////////////////////////////////////////////////////////////////////// void testSimulateHelper() { + try { // Output log File std::string lLogFilename ("SimulateTestSuite.log"); + // Set the log parameters + std::ofstream logOutputFile; + + // Open and clean the log outputfile + logOutputFile.open (lLogFilename.c_str()); + logOutputFile.clear(); + // Time duration representing a full day // (i.e., 24h or 1,440 minutes or 86,400 seconds) const boost::posix_time::time_duration kDay (24, 0, 0, 0); @@ -67,15 +61,31 @@ const int kSimulationLength = 365; // Rate, expressed as a number of events per day - // (lambda => mu = 1/ lambda) + // (lambda => mu = 1 / lambda) const double lambda = 10.0; + const double mu = 1 / lambda; // mu = 0.1 (= 2.4h, i.e., in average, an event occurs every 2.4h) // Initialisation of random generators - init(); + /** Base for the random generator. */ + base_generator_type lGenerator (42u); + /** Poisson distribution. */ + exponential_dist_type lExponentialDistribution (mu); + + /** Random generator for the Poisson distribution. */ + exponential_gen_type lExponentialDistributionGenerator (lGenerator, + lExponentialDistribution); + + /** Poisson distribution. */ + poisson_dist_type lPoissonDistribution (lambda); + + /** Random generator for the Poisson distribution. */ + poisson_gen_type lPoissonDistributionGenerator (lGenerator, + lPoissonDistribution); + // Generate k draws - // std::cout << "Event#; Time; " << std::endl; + logOutputFile << "Event#; Time; " << std::endl; for (int i=1; i != kSimulationLength; i++) { // Current time @@ -87,29 +97,29 @@ // Repeat until the current time exceeds 24h (i.e., 86,400 seconds) while (lCurrentTime <= kDay) { const double lExponentialVariateDay = - generateExponentialVariate (lambda); + lExponentialDistributionGenerator(); const long int lExponentialVariateHours = static_cast<long int> (lExponentialVariateDay * 24); const boost::posix_time::time_duration lExponentialVariateSeconds = boost::posix_time::hours (lExponentialVariateHours); // Add an event - lEventNumber++; + ++lEventNumber; // Add the inter-arrival time to the current time lCurrentTime += lExponentialVariateSeconds; - // const double lPoissonVariate = generatePoissonVariate (lambda); - - // std::cout << lEventNumber << "; " << lCurrentTime << "; " << std::endl; + // const double lPoissonVariate = lPoissonDistributionGenerator(); + logOutputFile << lEventNumber << "; " << lCurrentTime << "; " + << std::endl; } } - // Cleaning of random generators - finalise(); - // TODO: check that the average number of events corresponds to the given // input + + // Close the log file + logOutputFile.close(); } catch (const std::exception& stde) { std::cerr << "Standard exception: " << stde.what() << std::endl; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-10-03 16:45:56
|
Revision: 344 http://rmol.svn.sourceforge.net/rmol/?rev=344&view=rev Author: denis_arnaud Date: 2010-10-03 16:45:49 +0000 (Sun, 03 Oct 2010) Log Message: ----------- [Test] The small simulation test has been transfered into the DSim project, within the boost/random sub-directory. Modified Paths: -------------- trunk/rmol/test/rmol/Makefile.am Removed Paths: ------------- trunk/rmol/test/rmol/SimulateTestSuite.cpp trunk/rmol/test/rmol/SimulateTestSuite.hpp Property Changed: ---------------- trunk/rmol/test/rmol/ Property changes on: trunk/rmol/test/rmol ___________________________________________________________________ Modified: svn:ignore - .deps .libs Makefile Makefile.in optimise simulate sim.gnumeric OptimiseTestSuite OptimiseTestSuite.log OptimiseTestSuite_results.xml SimulateTestSuite SimulateTestSuite.log SimulateTestSuite_results.xml rmol.log ForecasterTestSuite ForecasterTestSuite.log ForecasterTestSuite_results.xml UnconstrainerTestSuite UnconstrainerTestSuite.log UnconstrainerTestSuite_results.xml bomsforforecaster bomsforforecaster.log + .deps .libs Makefile Makefile.in optimise simulate sim.gnumeric OptimiseTestSuite OptimiseTestSuite.log OptimiseTestSuite_results.xml ForecasterTestSuite ForecasterTestSuite.log ForecasterTestSuite_results.xml UnconstrainerTestSuite UnconstrainerTestSuite.log UnconstrainerTestSuite_results.xml bomsforforecaster bomsforforecaster.log Modified: trunk/rmol/test/rmol/Makefile.am =================================================================== --- trunk/rmol/test/rmol/Makefile.am 2010-09-29 15:17:31 UTC (rev 343) +++ trunk/rmol/test/rmol/Makefile.am 2010-10-03 16:45:49 UTC (rev 344) @@ -11,8 +11,7 @@ EXTRA_TESTS = bomsforforecaster -STD_CHECKS = OptimiseTestSuite SimulateTestSuite \ - ForecasterTestSuite UnconstrainerTestSuite +STD_CHECKS = OptimiseTestSuite ForecasterTestSuite UnconstrainerTestSuite check_PROGRAMS = $(STD_CHECKS) $(EXTRA_TESTS) TESTS = $(STD_CHECKS) XFAIL_TESTS = #OptimiseTestSuite @@ -25,14 +24,6 @@ $(EXTRACC_LIBS) $(STDAIR_LIBS) \ $(top_builddir)/rmol/core/librmol.la -SimulateTestSuite_SOURCES = SimulateTestSuite.hpp SimulateTestSuite.cpp -SimulateTestSuite_CXXFLAGS = $(BOOST_CFLAGS) $(CPPUNIT_CFLAGS) \ - $(EXTRACC_CFLAGS) $(STDAIR_CFLAGS) -SimulateTestSuite_LDADD = -SimulateTestSuite_LDFLAGS = $(CPPUNIT_LIBS) $(EXTRACC_LIBS) \ - $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) \ - $(STDAIR_LIBS) - ForecasterTestSuite_SOURCES = ForecasterTestSuite.hpp ForecasterTestSuite.cpp ForecasterTestSuite_CXXFLAGS = $(BOOST_CFLAGS) $(CPPUNIT_CFLAGS) \ $(EXTRACC_CFLAGS) $(STDAIR_CFLAGS) Deleted: trunk/rmol/test/rmol/SimulateTestSuite.cpp =================================================================== --- trunk/rmol/test/rmol/SimulateTestSuite.cpp 2010-09-29 15:17:31 UTC (rev 343) +++ trunk/rmol/test/rmol/SimulateTestSuite.cpp 2010-10-03 16:45:49 UTC (rev 344) @@ -1,394 +0,0 @@ -// STL -#include <iostream> -#include <sstream> -// Boost Date-Time -#include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/date_time/gregorian/gregorian.hpp> -// Boost Random -#include <boost/random/linear_congruential.hpp> -#include <boost/random/normal_distribution.hpp> -#include <boost/random/poisson_distribution.hpp> -#include <boost/random/exponential_distribution.hpp> -#include <boost/random/variate_generator.hpp> -// Boost Math -#include <boost/math/distributions/normal.hpp> -#include <boost/math/distributions/weibull.hpp> -// Boost Accumulators -#include <boost/accumulators/accumulators.hpp> -#include <boost/accumulators/statistics.hpp> -// Extra-CPPUnit -#include <extracppunit/CppUnitCore.hpp> -// RMOL Test Suite -#include <test/rmol/SimulateTestSuite.hpp> - -// using namespace boost; -namespace ba = boost::accumulators; - -// ////////// Type definitions ////////// -/** Type definition for a random number generator base (mt19937). */ -typedef boost::minstd_rand base_generator_type; - -/** 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; - -/** Type definiton for the normal distribution (characteristics). */ -typedef boost::normal_distribution<> normal_dist_type; - -/** Type definiton for the Poisson distribution (characteristics). */ -typedef boost::poisson_distribution<> poisson_dist_type; - -/** Type definiton for the exponential distribution (characteristics). */ -typedef boost::exponential_distribution<> exponential_dist_type; - -/** Type definition for the normal distribution random generator. */ -typedef boost::variate_generator<base_generator_type&, - normal_dist_type> normal_gen_type; - -/** Type definition for the Poisson distribution random generator. */ -typedef boost::variate_generator<base_generator_type&, - poisson_dist_type> poisson_gen_type; - -/** Type definition for the exponential distribution random generator. */ -typedef boost::variate_generator<base_generator_type&, - exponential_dist_type> exponential_gen_type; - -/** Type definition to gather statistics. */ -typedef ba::accumulator_set<double, - ba::stats<ba::tag::min, ba::tag::max, - ba::tag::mean (ba::immediate), - ba::tag::sum, - ba::tag::lazy_variance> > stat_acc_type; - -class simulation_exception : public std::exception { -public: - /** Constructor. */ - simulation_exception (const std::string& iWhat) throw() : _what () {} - ~simulation_exception () throw() {} - /** Gives the reason of the exception. */ - const char* what() const throw() { return _what.c_str(); } -private: - std::string _what; -}; - -// /////////////////////////////////////////////////// -double calculateDailyRate (const boost::gregorian::date iStartDate, - const boost::gregorian::date iCurrentDate, - const boost::gregorian::date iEndDate, - const double iFinalDemandMean) { - - /** - Note that the following method of pro-rating the daily rate, from - the final annual demand, may appear cumbersome, as: - 1. We discretise a continuous distribution, just to get a typical - S-curve booking pattern. - 2. We normalise that distribution, so as to get the corresponding - cdf (cumulative distribution function) equal to 1 on [0, infinite[. - 3. Moreover, in reality, we should first fit the parameters of that - S-curve distribution with the corresponding observations. - - Therefore, in the final version, we'll certainly use directly the - discrete distributions corresponding to the observations (historical - date) made beforehand. But as those observations may be difficult - to obtain, the following method is just handy for now. - */ - - /** - The result is the daily rate, expressed as a number of events (per day). - (lambda => mu = 1/ lambda), e.g., lambda = 10 => mu = 0.1 (= 2.4h, - i.e., in average, an event occurs every 2.4h). - */ - double lambda = 0.0001; - - // The first day open to reservation, there is no reservation (lambda = 0) - if (iStartDate == iCurrentDate) { - return lambda; - } - - // Simulation length-time (expressed as a number of days) - const boost::gregorian::date_duration lSimulationLength = - iEndDate - iStartDate; - const int lSimulationLengthInDays = - static_cast<const int> (lSimulationLength.days()); - - // DEBUG - return (iFinalDemandMean / lSimulationLengthInDays); - - // Current length-time (expressed as a number of days) - const boost::gregorian::date_duration lCurrentDuration = - iCurrentDate - iStartDate; - const double lCurrentDurationInDays = - static_cast<const double> (lCurrentDuration.days()); - - /** Ratio on the x-absciss for the Weibull distribution - (see ref: http://www.boost.org/doc/libs/1_44_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/dist_ref/dists/weibull.html). */ - const double lXRatio = 2.0 / lSimulationLengthInDays; - - /** The daily rate is pro-rated/weighted according to the - Weibull distribution (see above for the Boost reference). - The a and b parameters are taken equal to respectively 2 and 3. */ - boost::math::weibull weibull_distribution (2, 3); - const double lCurrentDurationInWeibullX = lCurrentDurationInDays * lXRatio; - const double lPreviousDurationInWeibullX = - (lCurrentDurationInDays - 1.0) * lXRatio; - - /** - There's also a normalisation factor, so as the CDF be equal - to one when x is equal to lSimulationLengthInDays. - Hence, we're looking for a normalisation constant (let's name it nc) - such as: f_pdf (x) = nc . Weibull_pdf (lXRatio . x). - We get: - nc = lXRatio / Weibull_cdf (lXRatio . lSimulationLengthInDays), and: - f_cdf (x) = Weibull_cdf (lXRatio . x) - / Weibull_cdf (lXRatio . lSimulationLengthInDays). - */ - const double lSimulationLengthInWeibullX = lSimulationLengthInDays * lXRatio; - const double lNormalisationConstant = - 1 / boost::math::cdf (weibull_distribution, lSimulationLengthInWeibullX); - // gsl_cdf_weibull_P (lSimulationLengthInWeibullX, 2, 3); - - const double lDailyIncrementalRate = lNormalisationConstant - * (boost::math::cdf (weibull_distribution, lCurrentDurationInWeibullX) - - boost::math::cdf (weibull_distribution, lPreviousDurationInWeibullX)); - - lambda = iFinalDemandMean * lDailyIncrementalRate; - - return lambda; -} - -// ////////////////////////////////////////////////////////////////////// -void testSimulateHelper() { - - // Output log File - std::string lLogFilename ("SimulateTestSuite.log"); - - // Set the log parameters - std::ofstream logOutputFile; - - // Open and clean the log outputfile - logOutputFile.open (lLogFilename.c_str()); - logOutputFile.clear(); - - // Time duration representing a full day - // (i.e., 24h or 1,440 minutes or 86,400 seconds) - const boost::posix_time::time_duration kDay = boost::posix_time::hours(24); - const int kDayInSeconds = static_cast<const int> (kDay.total_seconds()); - const boost::gregorian::date_duration kDayDuration (1); - - // Simulation length (time length) / date range for the simulation - const boost::gregorian::date kStartDate (2007, boost::gregorian::Jan, 1); - const boost::gregorian::date kEndDate (2008, boost::gregorian::Jan, 1); - - // Length of the Simulation (number of runs) - int K = 10; - - // Final demand (i.e., number of passengers) for the given simulated - // flight-date - const double lFinalDemandMean = 300.0; - const double lFinalDemandStandardDeviation = 17.32; - - // Initialisation of random generators - /** Base for the random generator. */ - base_generator_type lGenerator (42u); - - // Statistical accumulators for the respective numbers to watch - stat_acc_type lLambdaSumAcc; - stat_acc_type lTotalEventNumberAcc; - stat_acc_type lGaussianVariateAcc; - - // Total number of events - int lTotalEventNumber = 0; - - // Consistency check: check that the sum of the daily lambdas equals to the - // final demand mean - double lLambdaSum = 0.0; - - // Perform K simulations - for (int i=0; i != K; i++) { - // Re-initialisaton of the current date - boost::gregorian::date lCurrentDate = kStartDate; - - // Generate 1 year of draws - - // Reset the total number of events for the current simulation - lTotalEventNumber = 0; - - // Reset the sum of lambdas - lLambdaSum = 0.0; - - // DEBUG - /* - std::cout << "Start date: " << kStartDate << "; End date: " << kEndDate - << std::endl; - */ - - while (lCurrentDate < kEndDate) { - // Calculate the daily rate of events (bookings) - const double lambda = calculateDailyRate (kStartDate, lCurrentDate, - kEndDate, lFinalDemandMean); - // const double mu = 1 / lambda; - - // DEBUG - /* - std::cout << "Current date: " << lCurrentDate - << "; Final demand mean: " << lFinalDemandMean - << "; Lambda: " << lambda << "; mu: " << mu << std::endl; - */ - - /** Poisson distribution. */ - poisson_dist_type lPoissonDistribution (lambda); - - /** Random generator for the Poisson distribution. */ - poisson_gen_type lPoissonDistributionGenerator (lGenerator, - lPoissonDistribution); - - /** Exponential distribution - <br>Note: Boost.Math exponential distribution takes lambda as - the parameter, whereas the GSL (GNU Scientific Library) takes - mu (== 1/lambda). */ - exponential_dist_type lExponentialDistribution (lambda); - - /** Random generator for the exponential distribution. */ - exponential_gen_type lExponentialDistributionGenerator (lGenerator, - lExponentialDistribution); - - // - lLambdaSum += lambda; - - // Current time - boost::posix_time::time_duration lCurrentTime (0, 0, 0, 0); - - // Current number of events - int lDailyEventNumber = 0; - - // Repeat until the current time exceeds 24h (i.e., 86,400 seconds) - while (lCurrentTime <= kDay) { - // Generate a random variate, expressed in (fractional) day - const double lExponentialVariateInDays = - lExponentialDistributionGenerator(); - - // Convert the variate in a number of seconds - const int lExponentialVariateInSeconds = - static_cast<const int> (lExponentialVariateInDays * kDayInSeconds); - - // Convert the variate in a (Boost typedef) time duration - const boost::posix_time::time_duration lExponentialVariate = - boost::posix_time::seconds (lExponentialVariateInSeconds); - - // Add an event - lDailyEventNumber++; lTotalEventNumber++; - - // Add the inter-arrival time to the current time - lCurrentTime += lExponentialVariate; - - // const double lPoissonVariate = lPoissonDistributionGenerator(); - - /* DEBUG - logOutputFile << lCurrentDate << "; " << lTotalEventNumber << "; " - << lDailyEventNumber << "; " << lCurrentTime << "; " - << std::endl; - */ - } - - // When the booking day is over, there's an additional event - // (the first one made after the booking date) - lTotalEventNumber--; lDailyEventNumber--; - - // DEBUG - /** - logOutputFile << i << "; " << lCurrentDate << "; " << lambda << "; " - << lDailyEventNumber << "; " << lTotalEventNumber << "; " - << std::endl; - */ - - // Add a day - lCurrentDate += kDayDuration; - } - - // Generate a Gaussian variate, just in order to compare the final - // distributions (Gaussian and accumulated Poissonian). - /** Normal distribution. */ - normal_dist_type lNormalDistribution (lFinalDemandMean, - lFinalDemandStandardDeviation); - - /** Random generator for the normal distribution. */ - normal_gen_type lNormalDistributionGenerator (lGenerator, - lNormalDistribution); - - const double lGaussianVariate = lNormalDistributionGenerator(); - - // DEBUG - logOutputFile << "Simulation#; Sum of Lambdas; Total nb of events; " - << "Random draw (following normal law);" << std::endl; - logOutputFile << i << "; " << lLambdaSum << "; " - << lTotalEventNumber << "; " - << lGaussianVariate << "; " << std::endl; - - // Update the statistics - lLambdaSumAcc (lLambdaSum); - lTotalEventNumberAcc (lTotalEventNumber); - lGaussianVariateAcc (lGaussianVariate); - } - - // DEBUG - logOutputFile << "Statistics for sum of Lambdas (min, max, mean, variance);" - << std::endl; - logOutputFile << ba::min (lLambdaSumAcc) << ", " - << ba::max (lLambdaSumAcc) << ", " - << ba::mean (lLambdaSumAcc) << ", " - << ba::variance (lLambdaSumAcc) << "; " << std::endl; - logOutputFile<<"Statistics for total nb of events (min, max, mean, variance);" - << std::endl; - logOutputFile << ba::min (lTotalEventNumberAcc) << ", " - << ba::max (lTotalEventNumberAcc) << ", " - << ba::mean (lTotalEventNumberAcc) << ", " - << ba::variance (lTotalEventNumberAcc) << "; " << std::endl; - logOutputFile << "Statistics for random draws (min, max, mean, variance);" - << std::endl; - logOutputFile << ba::min (lGaussianVariateAcc) << ", " - << ba::max (lGaussianVariateAcc) << ", " - << ba::mean (lGaussianVariateAcc) << ", " - << ba::variance (lGaussianVariateAcc) << "; " - << std::endl; - - // Checking that the number of daily events follows a distribution - if (ba::mean (lTotalEventNumberAcc) - < lFinalDemandMean - lFinalDemandStandardDeviation - || ba::mean (lTotalEventNumberAcc) - > lFinalDemandMean + lFinalDemandStandardDeviation) { - throw simulation_exception ("The mean of the total number of events is not in the expected range"); - } - - // Checking that the random draws follow a normal distribution - if (ba::mean (lGaussianVariateAcc) - < lFinalDemandMean - lFinalDemandStandardDeviation - || ba::mean (lGaussianVariateAcc) - > lFinalDemandMean + lFinalDemandStandardDeviation) { - throw simulation_exception ("The mean of the total number of events is not in the expected range"); - } - - // TODO: check that the average number of events corresponds to the given - // input - - // Close the log file - logOutputFile.close(); -} - -// ////////////////////////////////////////////////////////////////////// -void SimulateTestSuite::testSimulate() { - CPPUNIT_ASSERT_NO_THROW (testSimulateHelper();); -} - -// ////////////////////////////////////////////////////////////////////// -// void SimulateTestSuite::errorCase () { -// CPPUNIT_ASSERT (false); -// } - -// ////////////////////////////////////////////////////////////////////// -SimulateTestSuite::SimulateTestSuite () { - _describeKey << "Running test on RMOL Simulation function"; -} - -// /////////////// M A I N ///////////////// -CPPUNIT_MAIN() Deleted: trunk/rmol/test/rmol/SimulateTestSuite.hpp =================================================================== --- trunk/rmol/test/rmol/SimulateTestSuite.hpp 2010-09-29 15:17:31 UTC (rev 343) +++ trunk/rmol/test/rmol/SimulateTestSuite.hpp 2010-10-03 16:45:49 UTC (rev 344) @@ -1,25 +0,0 @@ -// STL -#include <sstream> -// CPPUNIT -#include <cppunit/extensions/HelperMacros.h> - -class SimulateTestSuite : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE (SimulateTestSuite); - CPPUNIT_TEST (testSimulate); - // CPPUNIT_TEST (errorCase); - CPPUNIT_TEST_SUITE_END (); -public: - - /** Test the Simulation functionality. */ - void testSimulate (); - - /** Test some error detection functionalities. */ - // void errorCase (); - - /** Constructor. */ - SimulateTestSuite (); - -protected: - std::stringstream _describeKey; -}; -CPPUNIT_TEST_SUITE_REGISTRATION (SimulateTestSuite); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |