From: <qua...@us...> - 2010-02-11 14:05:05
|
Revision: 127 http://stdair.svn.sourceforge.net/stdair/?rev=127&view=rev Author: quannaus Date: 2010-02-11 12:59:00 +0000 (Thu, 11 Feb 2010) Log Message: ----------- [dev] Re-added DemandStream. Modified Paths: -------------- trunk/stdair/stdair/basic/RandomGeneration.cpp trunk/stdair/stdair/basic/RandomGeneration.hpp trunk/stdair/stdair/bom/BookingRequestTypes.hpp trunk/stdair/stdair/bom/sources.mk trunk/stdair/stdair/factory/FacBomContent.hpp Added Paths: ----------- trunk/stdair/stdair/bom/DemandStream.cpp trunk/stdair/stdair/bom/DemandStream.hpp trunk/stdair/stdair/bom/DemandStreamTypes.hpp Modified: trunk/stdair/stdair/basic/RandomGeneration.cpp =================================================================== --- trunk/stdair/stdair/basic/RandomGeneration.cpp 2010-02-10 17:13:38 UTC (rev 126) +++ trunk/stdair/stdair/basic/RandomGeneration.cpp 2010-02-11 12:59:00 UTC (rev 127) @@ -23,6 +23,13 @@ } // ////////////////////////////////////////////////////////////////////// + RandomGeneration::RandomGeneration () + : _seed (0), _generator (0), + _uniformGenerator (_generator, boost::uniform_real<> (0, 1)) { + assert (false); + } + + // ////////////////////////////////////////////////////////////////////// RandomGeneration::~RandomGeneration () { } Modified: trunk/stdair/stdair/basic/RandomGeneration.hpp =================================================================== --- trunk/stdair/stdair/basic/RandomGeneration.hpp 2010-02-10 17:13:38 UTC (rev 126) +++ trunk/stdair/stdair/basic/RandomGeneration.hpp 2010-02-11 12:59:00 UTC (rev 127) @@ -22,28 +22,30 @@ } // //////////// Business Methods ///////////// - /** Generate a randomized number following a uniform distribution between 0 (included) and 1 (excluded). */ + /** Generate a randomized number following a uniform distribution + between 0 (included) and 1 (excluded). */ RealNumber_T generateUniform01 (); - /** Generate a randomized number following a uniform distribution between a minimum (included) and a maximum (excluded) value. */ + /** Generate a randomized number following a uniform distribution + between a minimum (included) and a maximum (excluded) + value. */ RealNumber_T generateUniform (const RealNumber_T&, const RealNumber_T&); - /** Generate a randomized number following a normal distribution specified by a mean and a standard deviation. */ + /** Generate a randomized number following a normal distribution + specified by a mean and a standard deviation. */ RealNumber_T generateNormal (const RealNumber_T&, const RealNumber_T&); public: // ////////// Constructors and destructors ///////// /** Constructor. */ RandomGeneration (const RandomSeed_T&); - + /** Default constructors. */ + RandomGeneration (); + RandomGeneration (const RandomGeneration&); + /** Destructor. */ virtual ~RandomGeneration (); - public : - /** Default constructors. */ - RandomGeneration (); - RandomGeneration (const RandomGeneration&); - /** Initialize the random generator. <br>A uniform random number distribution is defined, which produces "real" values between 0 and 1 (0 inclusive, 1 Modified: trunk/stdair/stdair/bom/BookingRequestTypes.hpp =================================================================== --- trunk/stdair/stdair/bom/BookingRequestTypes.hpp 2010-02-10 17:13:38 UTC (rev 126) +++ trunk/stdair/stdair/bom/BookingRequestTypes.hpp 2010-02-11 12:59:00 UTC (rev 127) @@ -1,6 +1,6 @@ // ////////////////////////////////////////////////////////////////////// -#ifndef __STDAIR_BOM_BOOKINGCLASSTYPES_HPP -#define __STDAIR_BOM_BOOKINGCLASSTYPES_HPP +#ifndef __STDAIR_BOM_BOOKINGREQUESTTYPES_HPP +#define __STDAIR_BOM_BOOKINGREQUESTTYPES_HPP // ////////////////////////////////////////////////////////////////////// // Import section @@ -18,5 +18,5 @@ typedef boost::shared_ptr<BookingRequestStruct> BookingRequestPtr_T; } -#endif // __STDAIR_BOM_BOOKINGCLASSTYPES_HPP +#endif // __STDAIR_BOM_BOOKINGREQUESTTYPES_HPP Added: trunk/stdair/stdair/bom/DemandStream.cpp =================================================================== --- trunk/stdair/stdair/bom/DemandStream.cpp (rev 0) +++ trunk/stdair/stdair/bom/DemandStream.cpp 2010-02-11 12:59:00 UTC (rev 127) @@ -0,0 +1,66 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <iosfwd> +#include <ostream> +#include <sstream> +// Boost +#include <boost/math/distributions/normal.hpp> +// Math +#include <math.h> +// STDAIR +#include <stdair/basic/BasConst_General.hpp> +#include <stdair/basic/DemandCharacteristics.hpp> +#include <stdair/basic/RandomGeneration.hpp> +#include <stdair/basic/RandomGenerationContext.hpp> +#include <stdair/bom/BookingRequestStruct.hpp> +#include <stdair/bom/DemandStream.hpp> +#include <stdair/service/Logger.hpp> + + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + DemandStream:: + DemandStream (const DemandStreamKey_T& iKey, + const DemandCharacteristics& iDemandCharacteristics, + const DemandDistribution& iDemandDistribution, + const RandomSeed_T& iNumberOfRequestsSeed, + const RandomSeed_T& iRequestDateTimeSeed, + const RandomSeed_T& iDemandCharacteristicsSeed) + : _key (iKey), + _demandCharacteristics (iDemandCharacteristics), + _demandDistribution (iDemandDistribution), + _totalNumberOfRequestsToBeGenerated (0), + _numberOfRequestsRandomGenerator (iNumberOfRequestsSeed), + _requestDateTimeRandomGenerator (iRequestDateTimeSeed), + _demandCharacteristicsRandomGenerator (iDemandCharacteristicsSeed) { + init(); + } + + // ////////////////////////////////////////////////////////////////////// + DemandStream::~DemandStream () { + } + + // ////////////////////////////////////////////////////////////////////// + void DemandStream::init() { + // Generate the number of requests + const RealNumber_T lMu = + _demandDistribution.getMeanNumberOfRequests (); + const RealNumber_T lSigma = + _demandDistribution.getStandardDeviationNumberOfRequests (); + const RealNumber_T lRealNumberOfRequestsToBeGenerated = + _numberOfRequestsRandomGenerator.generateNormal (lMu, lSigma); + Count_T lIntegerNumberOfRequestsToBeGenerated = 0; + if (lRealNumberOfRequestsToBeGenerated < 0.5) { + lIntegerNumberOfRequestsToBeGenerated = 0; + } else { + lIntegerNumberOfRequestsToBeGenerated = + static_cast<Count_T> (lRealNumberOfRequestsToBeGenerated + 0.5); + } + _totalNumberOfRequestsToBeGenerated = lIntegerNumberOfRequestsToBeGenerated; + } + +} Added: trunk/stdair/stdair/bom/DemandStream.hpp =================================================================== --- trunk/stdair/stdair/bom/DemandStream.hpp (rev 0) +++ trunk/stdair/stdair/bom/DemandStream.hpp 2010-02-11 12:59:00 UTC (rev 127) @@ -0,0 +1,229 @@ +#ifndef __STDAIR_BOM_DEMANDSTREAM_HPP +#define __STDAIR_BOM_DEMANDSTREAM_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// Boost +#include <boost/shared_ptr.hpp> +// STL +#include <iosfwd> +// STDAIR +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/DemandCharacteristics.hpp> +#include <stdair/basic/DemandDistribution.hpp> +#include <stdair/basic/RandomGeneration.hpp> +#include <stdair/basic/RandomGenerationContext.hpp> +#include <stdair/bom/BomContent.hpp> +#include <stdair/bom/BookingRequestTypes.hpp> +#include <stdair/bom/DemandStreamTypes.hpp> + +namespace stdair { + + /** Class modeling a demand stream. */ + class DemandStream : public BomContent { + friend class FacBomContent; + + public: + // ///////////// Getters /////////// + /** Get the key */ + const DemandStreamKey_T& getKey () const { + return _key; + } + + /** Get the total number of requests to be generated. */ + const Count_T& getTotalNumberOfRequestsToBeGenerated() const { + return _totalNumberOfRequestsToBeGenerated; + } + + /** Get the origin. */ + const AirportCode_T& getOrigin() const { + return _demandCharacteristics.getOrigin(); + } + + /** Get the destination. */ + const AirportCode_T& getDestination() const { + return _demandCharacteristics.getDestination(); + } + + /** Get the preferred departure date. */ + const Date_T& getPreferredDepartureDate() const { + return _demandCharacteristics.getPreferredDepartureDate(); + } + + /** Get the passenger type. */ + const PassengerType_T& getPaxType() const { + return _demandCharacteristics.getPaxType(); + } + + /** Get the arrival pattern. */ + const ContinuousAttribute<FloatDuration_T>& getArrivalPattern() const { + return _demandCharacteristics.getArrivalPattern(); + } + + /** Get the mean number of requests. */ + const RealNumber_T& getMeanNumberOfRequests() const { + return _demandDistribution.getMeanNumberOfRequests(); + } + + /** Get the standard deviation of number of requests. */ + const RealNumber_T& getStandardDeviationNumberOfRequests() const { + return _demandDistribution.getStandardDeviationNumberOfRequests(); + } + + /** Get the cumulative probability of arrival pattern for last + request generated so far. */ + const Probability_T& getCumulativeProbabilitySoFar () const { + return _randomGenerationContext.getCumulativeProbabilitySoFar(); + } + + /** Get the number of requests generated so far. */ + const Count_T getNumberOfRequestsGeneratedSoFar() const { + return _randomGenerationContext.getCumulativeProbabilitySoFar();; + } + + /** Get the seed of the random generator for the number of requests. */ + const RandomSeed_T& getNumberOfRequestsRandomGeneratorSeed () const { + return _numberOfRequestsRandomGenerator.getSeed(); + } + + /** Get the seed of the random generator for the request datetime. */ + const RandomSeed_T& getRequestDateTimeRandomGeneratorSeed () const { + return _requestDateTimeRandomGenerator.getSeed(); + } + + /** Get the seed of the random generator for the demand characteristics. */ + const RandomSeed_T& getDemandCharacteristicsRandomGeneratorSeed () const { + return _demandCharacteristicsRandomGenerator.getSeed(); + } + + public: + // //////////////// Setters ////////////////// + /** Set the cumulative probability of arrival pattern for last + request generated so far. */ + void setCumulativeProbabilitySoFar (const Probability_T& iCumulativeProbability) { + _randomGenerationContext. + setCumulativeProbabilitySoFar (iCumulativeProbability); + } + + /** Set the number of requests generated so far. */ + void setNumberOfRequestsGeneratedSoFar (const Count_T& iNumberOfRequests) { + _randomGenerationContext. + setNumberOfRequestsGeneratedSoFar (iNumberOfRequests); + } + + public: + // /////////// Display support methods ///////// + /** Dump a Business Object into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream& ioOut) const { ioOut << toString(); } + + /** Read a Business Object from an input stream. + @param istream& the input stream. */ + void fromStream (std::istream& ioIn) { } + + /** Get the serialised version of the Business Object. */ + std::string toString() const { return describeKey(); } + + /** Get a string describing the whole key (differentiating two objects + at any level). */ + const std::string describeKey() const { return std::string (""); } + + /** Get a string describing the short key (differentiating two objects + at the same level). */ + const std::string describeShortKey() const { return std::string (""); } + + + public: + // /////////////// Business Methods ////////// + /** Increment counter of requests generated so far */ + void incrementGeneratedRequestsCounter () { + _randomGenerationContext.incrementGeneratedRequestsCounter(); + } + + + /** Generate a randomized number following a uniform distribution + between 0 (included) and 1 (excluded). */ + RealNumber_T generateUniform01WithNumberOfRequestRandomGenerator () { + return _numberOfRequestsRandomGenerator.generateUniform01(); + } + RealNumber_T generateUniform01WithRequestDateTimeRandomGenerator() { + return _requestDateTimeRandomGenerator.generateUniform01(); + } + RealNumber_T generateUniform01WithDemandCharacteristicsRandomGenerator() { + return _demandCharacteristicsRandomGenerator.generateUniform01(); + } + + /** Generate a randomized number following a uniform distribution + between a minimum (included) and a maximum (excluded) + value. */ + RealNumber_T generateUniformWithNumberOfRequestRandomGenerator (const RealNumber_T& iMinValue, const RealNumber_T& iMaxValue) { + return _numberOfRequestsRandomGenerator.generateUniform (iMinValue, + iMaxValue); + } + RealNumber_T generateUniformWithRequestDateTimeRandomGenerator(const RealNumber_T& iMinValue, const RealNumber_T& iMaxValue) { + return _requestDateTimeRandomGenerator.generateUniform (iMinValue, + iMaxValue); + } + RealNumber_T generateUniformWithDemandCharacteristicsRandomGenerator(const RealNumber_T& iMinValue, const RealNumber_T& iMaxValue) { + return _demandCharacteristicsRandomGenerator.generateUniform (iMinValue, + iMaxValue); + } + + /** Generate a randomized number following a normal distribution + specified by a mean and a standard deviation. */ + RealNumber_T generateNormalWithNumberOfRequestRandomGenerator (const RealNumber_T& mu, const RealNumber_T& sigma) { + return _numberOfRequestsRandomGenerator.generateNormal (mu, sigma); + } + RealNumber_T generateNormalWithRequestDateTimeRandomGenerator(const RealNumber_T& mu, const RealNumber_T& sigma) { + return _requestDateTimeRandomGenerator.generateNormal (mu, sigma); + } + RealNumber_T generateNormalWithDemandCharacteristicsRandomGenerator(const RealNumber_T& mu, const RealNumber_T& sigma) { + return _demandCharacteristicsRandomGenerator.generateNormal (mu, sigma); + } + + protected: + // ////////// Constructors and destructors ///////// + /** Constructor by default */ + DemandStream (const DemandStreamKey_T&, + const DemandCharacteristics&, + const DemandDistribution&, const RandomSeed_T&, + const RandomSeed_T&, const RandomSeed_T&); + /** Default constructors. */ + DemandStream (); + DemandStream (const DemandStream&); + /** Initialization. */ + void init(); + /** Destructor. */ + ~DemandStream (); + + + protected: + // ////////// Attributes ////////// + /** Key */ + DemandStreamKey_T _key; + + /** Demand characteristics */ + DemandCharacteristics _demandCharacteristics; + + /** Demand distribution */ + DemandDistribution _demandDistribution; + + /** Total number of requests to be generated*/ + Count_T _totalNumberOfRequestsToBeGenerated; + + /** Random generation context */ + RandomGenerationContext _randomGenerationContext; + + /** Random generator for number of requests */ + RandomGeneration _numberOfRequestsRandomGenerator; + + /** Random generator for request datetime */ + RandomGeneration _requestDateTimeRandomGenerator; + + /** Random generator for demand characteristics */ + RandomGeneration _demandCharacteristicsRandomGenerator; + }; + +} +#endif // __STDAIR_BOM_DEMANDSTREAM_HPP Added: trunk/stdair/stdair/bom/DemandStreamTypes.hpp =================================================================== --- trunk/stdair/stdair/bom/DemandStreamTypes.hpp (rev 0) +++ trunk/stdair/stdair/bom/DemandStreamTypes.hpp 2010-02-11 12:59:00 UTC (rev 127) @@ -0,0 +1,21 @@ +#ifndef __STDAIR_BOM_DEMANDSTREAMTYPES_HPP +#define __STDAIR_BOM_DEMANDSTREAMTYPES_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <map> +// STDAIR +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + // Forward declaration + class DemandStream; + + /** Define a map of demand strams. */ + typedef std::map<const DemandStreamKey_T, DemandStream*> DemandStreamList_T; + +} +#endif // __STDAIR_BOM_DEMANDSTREAMTYPES_HPP Modified: trunk/stdair/stdair/bom/sources.mk =================================================================== --- trunk/stdair/stdair/bom/sources.mk 2010-02-10 17:13:38 UTC (rev 126) +++ trunk/stdair/stdair/bom/sources.mk 2010-02-11 12:59:00 UTC (rev 127) @@ -86,6 +86,8 @@ $(top_srcdir)/stdair/bom/TravelSolutionTypes.hpp \ $(top_srcdir)/stdair/bom/BookingRequestStruct.hpp \ $(top_srcdir)/stdair/bom/AirlineStruct.hpp \ + $(top_srcdir)/stdair/bom/DemandStream.hpp \ + $(top_srcdir)/stdair/bom/DemandStreamTypes.hpp \ $(top_srcdir)/stdair/bom/EventStruct.hpp \ $(top_srcdir)/stdair/bom/EventQueue.hpp \ $(top_srcdir)/stdair/bom/EventTypes.hpp \ @@ -138,6 +140,7 @@ $(top_srcdir)/stdair/bom/TravelSolutionStruct.cpp \ $(top_srcdir)/stdair/bom/BookingRequestStruct.cpp \ $(top_srcdir)/stdair/bom/AirlineStruct.cpp \ + $(top_srcdir)/stdair/bom/DemandStream.cpp \ $(top_srcdir)/stdair/bom/EventStruct.cpp \ $(top_srcdir)/stdair/bom/EventQueue.cpp \ $(top_srcdir)/stdair/bom/BomManager.cpp Modified: trunk/stdair/stdair/factory/FacBomContent.hpp =================================================================== --- trunk/stdair/stdair/factory/FacBomContent.hpp 2010-02-10 17:13:38 UTC (rev 126) +++ trunk/stdair/stdair/factory/FacBomContent.hpp 2010-02-11 12:59:00 UTC (rev 127) @@ -173,6 +173,29 @@ iReferenceOutboundPath._flightPathCode; } + // ////////////////////////////////////////////////////////////////// + // /////////////////////// Dedicated factories ////////////////////// + // ////////////////////////////////////////////////////////////////// + template <typename DEMAND_STREAM> + DEMAND_STREAM& create (const DemandStreamKey_T& iKey, + const DemandCharacteristics& iDemandCharacteristics, + const DemandDistribution& iDemandDistribution, + const RandomSeed_T& iNumberOfRequestsSeed, + const RandomSeed_T& iRequestDateTimeSeed, + const RandomSeed_T& iDemandCharacteristicsSeed) { + DEMAND_STREAM* aDemandStream_ptr = + new DEMAND_STREAM (iKey, iDemandCharacteristics, iDemandDistribution, + iNumberOfRequestsSeed, iRequestDateTimeSeed, + iDemandCharacteristicsSeed); + assert (aDemandStream_ptr != NULL); + + // The new object is added to the pool of content objects + _contentPool.push_back (aDemandStream_ptr); + + return *aDemandStream_ptr; + } + + public: /** Provide the unique instance. <br>The singleton is instantiated when first used. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |