From: <qua...@us...> - 2010-02-08 16:32:16
|
Revision: 124 http://stdair.svn.sourceforge.net/stdair/?rev=124&view=rev Author: quannaus Date: 2010-02-08 16:32:09 +0000 (Mon, 08 Feb 2010) Log Message: ----------- [Dev] Added the objects for trademgen use. Still need to refine the code. Modified Paths: -------------- trunk/stdair/stdair/STDAIR_Types.hpp trunk/stdair/stdair/basic/BasConst.cpp trunk/stdair/stdair/basic/BasConst_General.hpp trunk/stdair/stdair/basic/sources.mk trunk/stdair/stdair/bom/BookingRequestStruct.cpp trunk/stdair/stdair/bom/BookingRequestStruct.hpp trunk/stdair/stdair/bom/sources.mk Added Paths: ----------- trunk/stdair/stdair/basic/CategoricalAttribute.hpp trunk/stdair/stdair/basic/ContinuousAttribute.hpp trunk/stdair/stdair/basic/DemandCharacteristics.cpp trunk/stdair/stdair/basic/DemandCharacteristics.hpp trunk/stdair/stdair/basic/DemandDistribution.cpp trunk/stdair/stdair/basic/DemandDistribution.hpp trunk/stdair/stdair/basic/RandomGeneration.cpp trunk/stdair/stdair/basic/RandomGeneration.hpp trunk/stdair/stdair/basic/RandomGenerationContext.cpp trunk/stdair/stdair/basic/RandomGenerationContext.hpp trunk/stdair/stdair/bom/DemandStream.cpp trunk/stdair/stdair/bom/DemandStream.hpp trunk/stdair/stdair/bom/EventQueue.cpp trunk/stdair/stdair/bom/EventQueue.hpp trunk/stdair/stdair/bom/EventStruct.cpp trunk/stdair/stdair/bom/EventStruct.hpp Modified: trunk/stdair/stdair/STDAIR_Types.hpp =================================================================== --- trunk/stdair/stdair/STDAIR_Types.hpp 2010-02-08 09:22:21 UTC (rev 123) +++ trunk/stdair/stdair/STDAIR_Types.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -7,7 +7,10 @@ // STL #include <string> #include <vector> +#include <list> #include <map> +// Boost Random +#include <boost/random/linear_congruential.hpp> // Boost (Extended STL) #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/posix_time/posix_time.hpp> @@ -123,6 +126,9 @@ /** Define the Duration (e.g., elapsed in-flight time). */ typedef boost::posix_time::time_duration Duration_T; + /** Time */ + typedef boost::posix_time::time_duration Time_T; + /** Define an accurate time (date +time). */ typedef boost::posix_time::ptime DateTime_T; @@ -388,6 +394,56 @@ /** Pointer on the STDAIR Service handler. */ typedef boost::shared_ptr<STDAIR_Service> STDAIR_ServicePtr_T; + + // ////////////////////////////////////////////////////////////////////// + // Random generation + /** Seed for the random generation, so that it can be reproductible. */ + typedef unsigned long int RandomSeed_T; + /** Random number generator. */ + typedef boost::minstd_rand BaseGenerator_T; + + // ////////////////////////////////////////////////////////////////////// + // Probability + /** Probability */ + typedef float Probability_T; + + // ////////////////////////////////////////////////////////////////////// + // Date / Time + /** Time duration in (integer) number of seconds */ + typedef long int IntDuration_T; + + /** Duration in (float) number of time units */ + typedef float FloatDuration_T; + + // ////////////////////////////////////////////////////////////////////// + // Basic types + /** Event type */ + typedef std::string EventType_T; + + /** Count */ + typedef int Count_T; + + /** Location code */ + typedef std::string LocationCode_T; + + /** Airport code */ + typedef LocationCode_T AirportCode_T; + + /** City code */ + typedef LocationCode_T CityCode_T; + + /** Trip type */ + typedef std::string TripType_T; + + /** Monetary value */ + typedef double MonetaryValue_T; + + /** Real number */ + typedef double RealNumber_T; + + // ////////////////////////////////////////////////////////////////////// + // Demand + typedef int DemandStreamKey_T; } #endif // __STDAIR_STDAIR_TYPES_HPP Modified: trunk/stdair/stdair/basic/BasConst.cpp =================================================================== --- trunk/stdair/stdair/basic/BasConst.cpp 2010-02-08 09:22:21 UTC (rev 123) +++ trunk/stdair/stdair/basic/BasConst.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -129,22 +129,18 @@ const DateOffSet_T DEFAULT_DATE_OFFSET (0); // // //////// General /////// - // /** Default update date for the General. */ - // const Date_T DEFAULT_WORLD_SCHEDULE_UPDATE_DATE (2007, - // boost::gregorian::Jan, - // 1); + /** Default update date for the General. */ + const Date_T DEFAULT_DATE (2007, boost::gregorian::Jan, 1); + /** Default update date&time. */ + const DateTime_T DEFAULT_DATETIME (DEFAULT_DATE, NULL_BOOST_TIME_DURATION); - // // //////// WholeDemand /////// - // /** Default update date for the WholeDemand. */ - // const Date_T DEFAULT_WHOLE_DEMAND_UPDATE_DATE (2007, - // boost::gregorian::Jan, - // 1); + /** Number of seconds in one day */ + const Count_T SECONDS_IN_ONE_DAY = 86000; + + /** Number of milliseconds in one second */ + const Count_T MILLISECONDS_IN_ONE_SECOND = 1000; - // /** Default update date&time. */ - // const DateTime_T DEFAULT_DEMAND_DATETIME (DEFAULT_WHOLE_DEMAND_UPDATE_DATE, - // NULL_BOOST_TIME_DURATION); - // //////// Fare Rules /////// /** Default saturdayStay value (false). */ const SaturdayStay_T DEFAULT_SATURDAY_STAY = false; Modified: trunk/stdair/stdair/basic/BasConst_General.hpp =================================================================== --- trunk/stdair/stdair/basic/BasConst_General.hpp 2010-02-08 09:22:21 UTC (rev 123) +++ trunk/stdair/stdair/basic/BasConst_General.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -36,5 +36,16 @@ /** Default booking rate for OnD bookings over overall class bookings. */ extern const BookingRatio_T DEFAULT_OND_BOOKING_RATE; + /** Number of seconds in one day */ + extern const Count_T SECONDS_IN_ONE_DAY; + + /** Number of milliseconds in one second */ + extern const Count_T MILLISECONDS_IN_ONE_SECOND; + + /** Default update date for the General. */ + extern const Date_T DEFAULT_DATE; + + /** Default update date&time. */ + extern const DateTime_T DEFAULT_DATETIME; } #endif // __STDAIR_BAS_BASCONST_GENERAL_HPP Added: trunk/stdair/stdair/basic/CategoricalAttribute.hpp =================================================================== --- trunk/stdair/stdair/basic/CategoricalAttribute.hpp (rev 0) +++ trunk/stdair/stdair/basic/CategoricalAttribute.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,98 @@ +#ifndef __STDAIR_BAS_CATEGORICALATTRIBUTE_HPP +#define __STDAIR_BAS_CATEGORICALATTRIBUTE_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <map> +#include <iosfwd> +// STDAIR +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + /** Class modeling the distribution of values that can be taken by a + categorical attribute. */ + template <class T> + struct CategoricalAttribute { + + public: + // ///////////// Getters /////////// + /** Get the probability mass function. */ + const std::map<T,Probability_T>& getProbabilityMassFunction() const { + return _probability_mass_function; + } + + /** Get the inverse cumulative distribution. */ + const std::map<Probability_T, T>& getInverseCumulativeDistribution () const { + return _inverse_cumulative_distribution; + } + + // ///////////// Setters /////////// + /** Set the probability mass function */ + void setProbabilityMassFunction (const std::map<T, Probability_T>& iProbabilityMassFunction) { + _probability_mass_function = iProbabilityMassFunction; + determineInverseCumulativeDistributionFromProbabilityMassFunction(); + } + + public: + // /////////////// Business Methods ////////// + /** Get value from inverse cumulative distribution. */ + T getValue(Probability_T iCumulativeProbability) { + return _inverse_cumulative_distribution.lower_bound(iCumulativeProbability)->second; + } + + public: + // ////////////// Display Support Methods ////////// + /** Display inverse cumulative distribution */ + void displayInverseCumulativeDistribution (std::ostream& ioStream) const { + for (typename std::map<Probability_T, T>::const_iterator it = _inverse_cumulative_distribution.begin(); + it != _inverse_cumulative_distribution.end(); ++it) { + ioStream << "cumulative prob: " << it->first + << " value: " << it->second << std::endl; + } + } + + public: + // ////////// Constructors and destructors ///////// + /** Constructor by default */ + CategoricalAttribute (const std::map<T, Probability_T>& iProbabilityMassFunction) + : _probability_mass_function (iProbabilityMassFunction) { + determineInverseCumulativeDistributionFromProbabilityMassFunction(); + } + + /** Destructor */ + virtual ~CategoricalAttribute () { } + + private: + /** Default constructors. */ + CategoricalAttribute (); + CategoricalAttribute (const CategoricalAttribute&); + + /** Determine inverse cumulative distribution from probability mass function (initialisation). */ + void determineInverseCumulativeDistributionFromProbabilityMassFunction () { + Probability_T cumulative_probability_so_far = 0.0; + for (typename std::map<T, Probability_T>::const_iterator itProbabilityMassFunction = _probability_mass_function.begin(); + itProbabilityMassFunction != _probability_mass_function.end(); + ++itProbabilityMassFunction) { + Probability_T attribute_probability_mass = itProbabilityMassFunction->second; + if (attribute_probability_mass > 0) { + T attribute_value = itProbabilityMassFunction->first; + cumulative_probability_so_far += attribute_probability_mass; + _inverse_cumulative_distribution[cumulative_probability_so_far] = attribute_value; + } + } + } + + private: + // ////////// Attributes ////////// + /** Probability mass function */ + std::map<T, Probability_T> _probability_mass_function; + + /** Inverse cumulative distribution */ + std::map<Probability_T, T> _inverse_cumulative_distribution; + + }; +} +#endif // __STDAIR_BAS_CATEGORICALATTRIBUTE_HPP Added: trunk/stdair/stdair/basic/ContinuousAttribute.hpp =================================================================== --- trunk/stdair/stdair/basic/ContinuousAttribute.hpp (rev 0) +++ trunk/stdair/stdair/basic/ContinuousAttribute.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,143 @@ +#ifndef __STDAIR_BAS_CONTINUOUSATTRIBUTE_HPP +#define __STDAIR_BAS_CONTINUOUSATTRIBUTE_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> +#include <map> +// STDAIR +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + /** Class modeling the distribution of values that can be taken by a + continuous attribute. */ + template <class T> + struct ContinuousAttribute { + public: + // ///////////// Getters /////////// + /** Get the cumulative distribution. */ + const std::multimap<T,Probability_T>& getCumulativeDistribution() const { + return _cumulativeDistribution; + } + + /** Get the inverse cumulative distribution. */ + const std::multimap<Probability_T, T>& + getInverseCumulativeDistribution () const { + return _inverseCumulativeDistribution; + } + + public: + // ///////////// Setters /////////// + /** Set the cumulative distribution */ + void setCumulativeDistribution (const std::multimap<T, Probability_T>& iCumulativeDistribution) { + _cumulativeDistribution = iCumulativeDistribution; + determineInverseCumulativeDistributionFromCumulativeDistribution(); + } + + public: + // /////////////// Business Methods ////////// + /** Get value from inverse cumulative distribution. */ + const T getValue(const Probability_T& iCumulativeProbability) const { + typename std::multimap<Probability_T, T>::const_iterator it = + _inverseCumulativeDistribution.lower_bound (iCumulativeProbability); + + Probability_T cumulativeProbabilityNextPoint = it->first; + T valueNextPoint = it->second; + + if (it == _inverseCumulativeDistribution.begin()) { + std::cout << "hello" << std::endl; + return valueNextPoint; + } + --it; + + Probability_T cumulativeProbabilityPreviousPoint = it->first; + T valuePreviousPoint = it->second; + if (cumulativeProbabilityNextPoint == cumulativeProbabilityPreviousPoint) { + //std::cout << "hlelo2" << std::endl; + return valuePreviousPoint; + } + + //std::cout << "cumulativeProbabilityPreviousPoint: " << cumulativeProbabilityPreviousPoint << std::endl; + //std::cout << "cumulativeProbabilityNextPoint: " << cumulativeProbabilityNextPoint << std::endl; + //std::cout << "valuePreviousPoint: " << valuePreviousPoint << std::endl; + //std::cout << "valueNextPoint: " << valueNextPoint << std::endl; + + return valuePreviousPoint + (valueNextPoint - valuePreviousPoint) + * (iCumulativeProbability - cumulativeProbabilityPreviousPoint) + / (cumulativeProbabilityNextPoint - cumulativeProbabilityPreviousPoint); + } + + public: + // ////////////// Display Support Methods ////////// + /** Display cumulative distribution */ + std::string displayCumulativeDistribution() const { + std::ostringstream oStr; + for (typename std::multimap<T, Probability_T>::const_iterator it = + _cumulativeDistribution.begin(); + it != _cumulativeDistribution.end(); ++it) { + oStr << "value: " << it->first + << " cumulative probability: " << it->second << std::endl; + } + return oStr.str(); + } + + /** Display inverse cumulative distribution */ + std::string displayInverseCumulativeDistribution() const { + std::ostringstream oStr; + for (typename std::multimap<Probability_T, T>::const_iterator it = + _inverseCumulativeDistribution.begin(); + it != _inverseCumulativeDistribution.end(); ++it) { + oStr << "cumulative prob: " << it->first + << " value: " << it->second << std::endl; + } + return oStr.str(); + } + + public: + // ////////// Constructors and destructors ///////// + /** Constructor by default */ + ContinuousAttribute () { } + + /** Constructor */ + ContinuousAttribute (const std::multimap<T, Probability_T>& iCumulativeDistribution) : _cumulativeDistribution (iCumulativeDistribution) { + determineInverseCumulativeDistributionFromCumulativeDistribution(); + } + + /** Copy constructor */ + ContinuousAttribute (const ContinuousAttribute& iContinuousAttribute) + : _cumulativeDistribution (iContinuousAttribute._cumulativeDistribution), + _inverseCumulativeDistribution (iContinuousAttribute._inverseCumulativeDistribution) { + } + + /** Destructor */ + virtual ~ContinuousAttribute () { } + + /** Determine inverse cumulative distribution from cumulative + distribution (initialisation). */ + void determineInverseCumulativeDistributionFromCumulativeDistribution () { + for (typename std::multimap<T, Probability_T>::iterator itCumulativeDistribution = + _cumulativeDistribution.begin(); + itCumulativeDistribution != _cumulativeDistribution.end(); + ++itCumulativeDistribution) { + _inverseCumulativeDistribution. + insert ( std::pair<float, float> (itCumulativeDistribution->second, + itCumulativeDistribution->first) ); + } + } + + private: + // ////////// Attributes ////////// + + /** Cumulative distribution */ + std::multimap<T, Probability_T> _cumulativeDistribution; + + /** Inverse cumulative distribution */ + std::multimap<Probability_T, T> _inverseCumulativeDistribution; + + }; + +} +#endif // __STDAIR_BAS_CONTINUOUSATTRIBUTE_HPP Added: trunk/stdair/stdair/basic/DemandCharacteristics.cpp =================================================================== --- trunk/stdair/stdair/basic/DemandCharacteristics.cpp (rev 0) +++ trunk/stdair/stdair/basic/DemandCharacteristics.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,50 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <sstream> +// STDAIR +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/DemandCharacteristics.hpp> + +namespace stdair { + + // ///////////////////////////////////////////////////// + DemandCharacteristics::DemandCharacteristics () + : _origin ("") { + } + + // ///////////////////////////////////////////////////// + DemandCharacteristics::~DemandCharacteristics () { + } + + // ///////////////////////////////////////////////////// + DemandCharacteristics:: + DemandCharacteristics (const DemandCharacteristics& iDemandCharacteristics) { + _origin = iDemandCharacteristics._origin; + _preferredDepartureDate = iDemandCharacteristics._preferredDepartureDate; + _arrivalPattern = iDemandCharacteristics._arrivalPattern; + } + + // ///////////////////////////////////////////////////// + std::string DemandCharacteristics::display() const { + std::ostringstream oStr; + + // + oStr << "****************** Demand characteristics ******************"; + oStr << "Origin ........................... : " + << _origin << std::endl; + oStr << "Preferred departure date ......... : " + << _preferredDepartureDate << std::endl; + oStr << "Arrival pattern (days from departure, proportion):" + << std::endl; + + // + oStr << _arrivalPattern.displayCumulativeDistribution(); + + return oStr.str(); + } + +} + Added: trunk/stdair/stdair/basic/DemandCharacteristics.hpp =================================================================== --- trunk/stdair/stdair/basic/DemandCharacteristics.hpp (rev 0) +++ trunk/stdair/stdair/basic/DemandCharacteristics.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,92 @@ +#ifndef __STDAIR_BAS_DEMAND_CHARACTERISTICS_HPP +#define __STDAIR_BAS_DEMAND_CHARACTERISTICS_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> +// STDAIR +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/ContinuousAttribute.hpp> + +namespace stdair { + + /** Class modeling the characteristics of a demand type. */ + struct DemandCharacteristics { + public: + + // ///////////// Getters /////////// + /** Get the origin. */ + const LocationCode_T& getOrigin() const { + return _origin; + } + + /** Get the preferred departure date. */ + const Date_T& getPreferredDepartureDate() const { + return _preferredDepartureDate; + } + + /** Get the arrival pattern. */ + const ContinuousAttribute<FloatDuration_T>& getArrivalPattern() const { + return _arrivalPattern; + } + + public: + // ///////////// Setters /////////// + /** Set the origin. */ + void setOrigin (const LocationCode_T& iOrigin) { + _origin = iOrigin; + } + + /** Set the preferred departure date. */ + void setPreferredDepartureDate (const Date_T& iPreferredDepartureDate) { + _preferredDepartureDate = iPreferredDepartureDate; + } + + /** Set the arrival pattern. */ + void setArrivalPattern (const ContinuousAttribute<FloatDuration_T>& iArrivalPattern) { + _arrivalPattern = iArrivalPattern; + } + + public: + // ////////////// Display Support Methods ////////// + /** Display demand characteristics */ + std::string display() const; + + + public: + // ////////// Constructors and destructors ///////// + /** Constructor by default */ + DemandCharacteristics (); + + /** Copy constructor */ + DemandCharacteristics (const DemandCharacteristics&); // Should be private, but well... + + /** Destructor */ + virtual ~DemandCharacteristics (); + + + private: + // ////////// Attributes ////////// + /** Origin */ + LocationCode_T _origin; + + /** Preferred departure date */ + Date_T _preferredDepartureDate; + + /** Arrival pattern (cumulative distribution of timing of arrival + of requests (negative number of days between departure date + and request date)*/ + ContinuousAttribute<FloatDuration_T> _arrivalPattern; + + /** Trip type probability mass */ + //CategoricalAttribute<TripType_T> _tripTypeProbabilityMass; + + /** Willingness-to-pay cumulative distribution */ + //ContinuousAttribute<MonetaryValue_T> _willingnessToPayCumulativeDistribution; + + }; + +} +#endif // __STDAIR_BAS_DEMAND_CHARACTERISTICS_HPP Added: trunk/stdair/stdair/basic/DemandDistribution.cpp =================================================================== --- trunk/stdair/stdair/basic/DemandDistribution.cpp (rev 0) +++ trunk/stdair/stdair/basic/DemandDistribution.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,44 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <sstream> +// STDAIR +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/DemandDistribution.hpp> + +namespace stdair { + + // ///////////////////////////////////////////////////// + DemandDistribution::DemandDistribution () { + } + + // ///////////////////////////////////////////////////// + DemandDistribution::~DemandDistribution () { + } + + // ///////////////////////////////////////////////////// + DemandDistribution:: + DemandDistribution (const DemandDistribution& iDemandDistribution) { + _meanNumberOfRequests = iDemandDistribution._meanNumberOfRequests; + _standardDeviationNumberOfRequests = + iDemandDistribution._standardDeviationNumberOfRequests; + } + + // ///////////////////////////////////////////////////// + std::string DemandDistribution::display() const { + std::ostringstream oStr; + + oStr << "****************** Demand distribution ******************" + << std::endl; + oStr << "Mean number of requests .......... : " + << _meanNumberOfRequests << std::endl; + oStr << "Std dev of number of requests .... : " + << _standardDeviationNumberOfRequests << std::endl; + + return oStr.str(); + } + +} + Added: trunk/stdair/stdair/basic/DemandDistribution.hpp =================================================================== --- trunk/stdair/stdair/basic/DemandDistribution.hpp (rev 0) +++ trunk/stdair/stdair/basic/DemandDistribution.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,70 @@ +#ifndef __STDAIR_BAS_DEMAND_DISTRIBUTION_HPP +#define __STDAIR_BAS_DEMAND_DISTRIBUTION_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> +// STDAIR +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/ContinuousAttribute.hpp> + +namespace stdair { + + /** Class modeling the distribution of a demand type. */ + struct DemandDistribution { + public: + + // ///////////// Getters /////////// + /** Get the mean number of requests. */ + const RealNumber_T& getMeanNumberOfRequests() const { + return _meanNumberOfRequests; + } + + /** Get the standard deviation of number of requests. */ + const RealNumber_T& getStandardDeviationNumberOfRequests() const { + return _standardDeviationNumberOfRequests; + } + + public: + // ///////////// Setters /////////// + /** Set the mean number of requests. */ + void setMeanNumberOfRequests (const RealNumber_T& iMean) { + _meanNumberOfRequests = iMean; + } + + /** Set the standard deviation of number of requests. */ + void setStandardDeviationNumberOfRequests (const RealNumber_T& iStandardDeviation) { + _standardDeviationNumberOfRequests = iStandardDeviation; + } + + public: + // ////////////// Display Support Methods ////////// + /** Display demand distribution */ + std::string display() const; + + + public: + // ////////// Constructors and destructors ///////// + /** Constructor by default */ + DemandDistribution (); + + /** Copy constructor */ + DemandDistribution (const DemandDistribution&); // Should be private, but well... + + /** Destructor */ + virtual ~DemandDistribution (); + + + private: + // ////////// Attributes ////////// + /** Mean number of requests */ + RealNumber_T _meanNumberOfRequests; + + /** Standard deviation of number of requests */ + RealNumber_T _standardDeviationNumberOfRequests; + }; + +} +#endif // __STDAIR_BAS_DEMAND_DISTRIBUTION_HPP Added: trunk/stdair/stdair/basic/RandomGeneration.cpp =================================================================== --- trunk/stdair/stdair/basic/RandomGeneration.cpp (rev 0) +++ trunk/stdair/stdair/basic/RandomGeneration.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,50 @@ +// STL +#include <cassert> +#include <iostream> +// Boost +#include <boost/math/distributions/normal.hpp> +//STDAIR +#include <stdair/basic/RandomGeneration.hpp> + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + RandomGeneration::RandomGeneration (const RandomSeed_T& iSeed) + : _seed (iSeed), _generator (iSeed), + _uniformGenerator (_generator, boost::uniform_real<> (0, 1)) { + init (); + } + + // ////////////////////////////////////////////////////////////////////// + RandomGeneration::~RandomGeneration () { + } + + // ////////////////////////////////////////////////////////////////////// + void RandomGeneration::init () { + } + + // ////////////////////////////////////////////////////////////////////// + RealNumber_T RandomGeneration::generateUniform01 () { + const RealNumber_T lVariateUnif = _uniformGenerator(); + return lVariateUnif; + } + + // ////////////////////////////////////////////////////////////////////// + RealNumber_T RandomGeneration:: + generateUniform (const RealNumber_T& iMinValue, const RealNumber_T& iMaxValue){ + const RealNumber_T lVariateUnif = + iMinValue + _uniformGenerator() * (iMaxValue - iMinValue); + return lVariateUnif; + } + + // ////////////////////////////////////////////////////////////////////// + RealNumber_T RandomGeneration:: + generateNormal (const RealNumber_T& mu, const RealNumber_T& sigma) { + const Probability_T lVariateUnif = generateUniform01 (); + const boost::math::normal lNormal (mu, sigma); + const RealNumber_T lRealNumberOfRequestsToBeGenerated = + boost::math::quantile(lNormal, lVariateUnif); + + return lRealNumberOfRequestsToBeGenerated; + } +} Added: trunk/stdair/stdair/basic/RandomGeneration.hpp =================================================================== --- trunk/stdair/stdair/basic/RandomGeneration.hpp (rev 0) +++ trunk/stdair/stdair/basic/RandomGeneration.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,74 @@ +#ifndef __STDAIR_BAS_BOM_RANDOMGENERATION_HPP +#define __STDAIR_BAS_BOM_RANDOMGENERATION_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// Boost Random +#include <boost/random/uniform_real.hpp> +#include <boost/random/variate_generator.hpp> +// STDAIR +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + /** Random generator. */ + struct RandomGeneration { + public: + // ///////////// Getters /////////// + /** Get the seed of the random generator. */ + const RandomSeed_T& getSeed () const { + return _seed; + } + + // //////////// Business Methods ///////////// + /** 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. */ + 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. */ + RealNumber_T generateNormal (const RealNumber_T&, const RealNumber_T&); + + public: + // ////////// Constructors and destructors ///////// + /** Constructor. */ + RandomGeneration (const RandomSeed_T&); + + /** Destructor. */ + virtual ~RandomGeneration (); + + private: + /** 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 + exclusive). */ + void init (); + + + private: + // ////////// Attributes ////////// + /** The seed of the random generator. + <br>The seed is unsigned, otherwise the wrong overload may be + selected when using mt19937 as the boost::base_generator_type. */ + RandomSeed_T _seed; + + /** Random number generator engine. + <br>The random number generator is currently based on boost::minstd_rand. + Alternates are boost::mt19937, boost::ecuyer1988. */ + BaseGenerator_T _generator; + + /** Random number generator. + <br>It is initialized with a reproducible seed and a uniform + distribution. */ + boost::variate_generator<BaseGenerator_T&, + boost::uniform_real<> > _uniformGenerator; + }; + +} +#endif // __STDAIR_BAS_BOM_RANDOMGENERATION_HPP Added: trunk/stdair/stdair/basic/RandomGenerationContext.cpp =================================================================== --- trunk/stdair/stdair/basic/RandomGenerationContext.cpp (rev 0) +++ trunk/stdair/stdair/basic/RandomGenerationContext.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,26 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iosfwd> +// STDAIR +#include <stdair/basic/RandomGenerationContext.hpp> + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + RandomGenerationContext::RandomGenerationContext () + : _cumulativeProbabilitySoFar (0.0), + _numberOfRequestsGeneratedSoFar (0) { + } + + // ////////////////////////////////////////////////////////////////////// + RandomGenerationContext::~RandomGenerationContext () { + } + + // ////////////////////////////////////////////////////////////////////// + void RandomGenerationContext::incrementGeneratedRequestsCounter () { + _numberOfRequestsGeneratedSoFar++; + } + +} Added: trunk/stdair/stdair/basic/RandomGenerationContext.hpp =================================================================== --- trunk/stdair/stdair/basic/RandomGenerationContext.hpp (rev 0) +++ trunk/stdair/stdair/basic/RandomGenerationContext.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,70 @@ +#ifndef __STDAIR_BAS_RANDOM_GENERATION_CONTEXT_HPP +#define __STDAIR_BAS_RANDOM_GENERATION_CONTEXT_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iosfwd> +// STDAIR +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + /** Structure holding the context necessary for demand random generation. */ + struct RandomGenerationContext { + + public: + // ///////////// Getters /////////// + /** Get the cumulative probability of arrival pattern for last + request generated so far. */ + const Probability_T& getCumulativeProbabilitySoFar () const { + return _cumulativeProbabilitySoFar; + } + + /** Get the number of requests generated so far. */ + const Count_T& getNumberOfRequestsGeneratedSoFar() const { + return _numberOfRequestsGeneratedSoFar; + } + + /** Set the cumulative probability of arrival pattern for last + request generated so far. */ + void setCumulativeProbabilitySoFar (const Probability_T& iCumulativeProbability) { + _cumulativeProbabilitySoFar = iCumulativeProbability; + } + + /** Set the number of requests generated so far. */ + void setNumberOfRequestsGeneratedSoFar (const Count_T& iNumberOfRequests) { + _numberOfRequestsGeneratedSoFar = iNumberOfRequests; + } + + public: + // ////////// Constructors and destructors ///////// + /** Constructor by default */ + RandomGenerationContext (); + + /** Destructor */ + virtual ~RandomGenerationContext (); + + public: + // /////////////// Business Methods ////////// + /** Increment counter of requests generated so far */ + void incrementGeneratedRequestsCounter (); + + private: + /** Default constructors. */ + RandomGenerationContext (const RandomGenerationContext&); + + private: + // ////////// Attributes ////////// + /** Cumulative probability in arrival pattern for last request + generated so far (needed for sequential generation)*/ + Probability_T _cumulativeProbabilitySoFar; + + /** Number of requests generated so far */ + Count_T _numberOfRequestsGeneratedSoFar; + + }; + +} +#endif // __STDAIR_BAS_RANDOM_GENERATION_CONTEXT_HPP Modified: trunk/stdair/stdair/basic/sources.mk =================================================================== --- trunk/stdair/stdair/basic/sources.mk 2010-02-08 09:22:21 UTC (rev 123) +++ trunk/stdair/stdair/basic/sources.mk 2010-02-08 16:32:09 UTC (rev 124) @@ -10,10 +10,20 @@ $(top_srcdir)/stdair/basic/BasChronometer.hpp \ $(top_srcdir)/stdair/basic/BasFileMgr.hpp \ $(top_srcdir)/stdair/basic/BasLogParams.hpp \ - $(top_srcdir)/stdair/basic/BasDBParams.hpp + $(top_srcdir)/stdair/basic/BasDBParams.hpp \ + $(top_srcdir)/stdair/basic/ContinuousAttribute.hpp \ + $(top_srcdir)/stdair/basic/CategoricalAttribute.hpp \ + $(top_srcdir)/stdair/basic/DemandCharacteristics.hpp \ + $(top_srcdir)/stdair/basic/DemandDistribution.hpp \ + $(top_srcdir)/stdair/basic/RandomGeneration.hpp \ + $(top_srcdir)/stdair/basic/RandomGenerationContext.hpp bas_cc_sources = \ $(top_srcdir)/stdair/basic/BasConst.cpp \ $(top_srcdir)/stdair/basic/BasChronometer.cpp \ $(top_srcdir)/stdair/basic/BasFileMgr.cpp \ $(top_srcdir)/stdair/basic/BasLogParams.cpp \ - $(top_srcdir)/stdair/basic/BasDBParams.cpp + $(top_srcdir)/stdair/basic/BasDBParams.cpp \ + $(top_srcdir)/stdair/basic/DemandCharacteristics.cpp \ + $(top_srcdir)/stdair/basic/DemandDistribution.cpp \ + $(top_srcdir)/stdair/basic/RandomGeneration.cpp \ + $(top_srcdir)/stdair/basic/RandomGenerationContext.cpp Modified: trunk/stdair/stdair/bom/BookingRequestStruct.cpp =================================================================== --- trunk/stdair/stdair/bom/BookingRequestStruct.cpp 2010-02-08 09:22:21 UTC (rev 123) +++ trunk/stdair/stdair/bom/BookingRequestStruct.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -12,17 +12,27 @@ namespace stdair { // ////////////////////////////////////////////////////////////////////// + BookingRequestStruct::BookingRequestStruct () { + } + + // ////////////////////////////////////////////////////////////////////// BookingRequestStruct::BookingRequestStruct (const AirportCode_T& iOrigin, const AirportCode_T& iDestination, const Date_T& iDepartureDate, + const DateTime_T& iRequestDateTime, const PassengerType_T& iPaxType, const NbOfSeats_T& iPartySize) : _origin (iOrigin), _destination (iDestination), - _departureDate (iDepartureDate), _paxType (iPaxType), - _partySize (iPartySize) { + _preferredDepartureDate (iDepartureDate), + _requestDateTime (iRequestDateTime), + _paxType (iPaxType), _partySize (iPartySize) { } - + // ////////////////////////////////////////////////////////////////////// + BookingRequestStruct::~BookingRequestStruct () { + } + + // ////////////////////////////////////////////////////////////////////// void BookingRequestStruct::toStream (std::ostream& ioOut) const { ioOut << describe(); } @@ -34,8 +44,8 @@ // ////////////////////////////////////////////////////////////////////// const std::string BookingRequestStruct::describe() const { std::ostringstream oStr; - oStr << _origin << " - " << _destination << " " << _departureDate - << " " << _paxType << " " << _partySize; + oStr << _origin << " - " << _destination << " " << _preferredDepartureDate + << " " << _requestDateTime << " " << _paxType << " " << _partySize; return oStr.str(); } Modified: trunk/stdair/stdair/bom/BookingRequestStruct.hpp =================================================================== --- trunk/stdair/stdair/bom/BookingRequestStruct.hpp 2010-02-08 09:22:21 UTC (rev 123) +++ trunk/stdair/stdair/bom/BookingRequestStruct.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -28,10 +28,15 @@ } /** Get the requested departure date. */ - const Date_T& getDepartureDate() const { - return _departureDate; + const Date_T& getPreferedDepartureDate() const { + return _preferredDepartureDate; } + /** Get the request datetime. */ + const DateTime_T& getRequestDateTime() const { + return _requestDateTime; + } + /** Get the passenger type. */ const PassengerType_T& getPaxType() const { return _paxType; @@ -55,10 +60,15 @@ } /** Set the requested departure date. */ - void setDepartureDate (const Date_T& iDepartureDate) { - _departureDate = iDepartureDate; + void setPreferredDepartureDate (const Date_T& iDepartureDate) { + _preferredDepartureDate = iDepartureDate; } - + + /** Set the request datetime */ + void setRequestDateTime (const DateTime_T& iRequestDateTime) { + _requestDateTime = iRequestDateTime; + } + /** Set the passenger type. */ void setPaxType (const PassengerType_T& iPaxType) { _paxType = iPaxType; @@ -84,9 +94,11 @@ public: // /////////////// Constructors and Destructors ///////////////// + BookingRequestStruct (); BookingRequestStruct (const AirportCode_T&, const AirportCode_T&, - const Date_T&, const PassengerType_T&, - const NbOfSeats_T&); + const Date_T&, const DateTime_T&, + const PassengerType_T&, const NbOfSeats_T&); + ~BookingRequestStruct(); private: @@ -96,10 +108,13 @@ /** Destination. */ AirportCode_T _destination; - + /** Departure date. */ - Date_T _departureDate; + Date_T _preferredDepartureDate; + /** Request datetime */ + DateTime_T _requestDateTime; + /** Passenger type. */ PassengerType_T _paxType; Added: trunk/stdair/stdair/bom/DemandStream.cpp =================================================================== --- trunk/stdair/stdair/bom/DemandStream.cpp (rev 0) +++ trunk/stdair/stdair/bom/DemandStream.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,132 @@ +// ////////////////////////////////////////////////////////////////////// +// 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; + } + + // ////////////////////////////////////////////////////////////////////// + bool DemandStream::generateNext (BookingRequestStruct& ioRequest) { + // Check whether enough requests have already been generated + const Count_T lNbOfRequestsGeneratedSoFar = + _randomGenerationContext.getNumberOfRequestsGeneratedSoFar (); + const Count_T lRemainingNumberOfRequestsToBeGenerated = + _totalNumberOfRequestsToBeGenerated - lNbOfRequestsGeneratedSoFar; + + if (lRemainingNumberOfRequestsToBeGenerated <= 0) { + return false; + } + // DEBUG + STDAIR_LOG_DEBUG ("Here"); + + // Origin + ioRequest.setOrigin (_demandCharacteristics.getOrigin ()); + + // Preferred departure date + const Date_T lPreferredDepartureDate = + _demandCharacteristics.getPreferredDepartureDate (); + ioRequest.setPreferredDepartureDate (lPreferredDepartureDate); + + // Request datetime, determined from departure date and arrival pattern + // Sequential generation + const Probability_T lCumulativeProbabilitySoFar = + _randomGenerationContext.getCumulativeProbabilitySoFar (); + + const Probability_T lVariate = + _requestDateTimeRandomGenerator.generateUniform01 (); + + const Probability_T lCumulativeProbabilityThisRequest = + 1.0 - (1.0 - lCumulativeProbabilitySoFar) * pow(1 - lVariate, 1.0 / static_cast<float> (lRemainingNumberOfRequestsToBeGenerated)); + + const FloatDuration_T lNumberOfDaysBetweenDepartureAndThisRequest = + _demandCharacteristics.getArrivalPattern().getValue (lCumulativeProbabilityThisRequest); + + // convert the number of days in number of seconds + number of milliseconds + const FloatDuration_T lNumberOfSeconds = + lNumberOfDaysBetweenDepartureAndThisRequest*static_cast<float> (SECONDS_IN_ONE_DAY); + + const IntDuration_T lIntNumberOfSeconds = floor(lNumberOfSeconds); + + const FloatDuration_T lNumberOfMilliseconds = + (lNumberOfSeconds - lIntNumberOfSeconds) * static_cast<float> (MILLISECONDS_IN_ONE_SECOND); + + const IntDuration_T lIntNumberOfMilliseconds = + floor(lNumberOfMilliseconds) + 1; // +1 is a trick to ensure that the next event is strictly later than the current one + + const Duration_T lDifferenceBetweenDepartureAndThisRequest = + boost::posix_time::seconds(lIntNumberOfSeconds) + boost::posix_time::millisec(lIntNumberOfMilliseconds); + + const Time_T lHardcodedReferenceDepartureTime = boost::posix_time::hours(8); + +const DateTime_T lDepartureDateTime = + boost::posix_time::ptime(lPreferredDepartureDate, lHardcodedReferenceDepartureTime); + + const DateTime_T lDateTimeThisRequest = + lDepartureDateTime + lDifferenceBetweenDepartureAndThisRequest; + ioRequest.setRequestDateTime (lDateTimeThisRequest); + + // Update random generation context + _randomGenerationContext.setCumulativeProbabilitySoFar (lCumulativeProbabilityThisRequest); + _randomGenerationContext.incrementGeneratedRequestsCounter (); + + return true; + + } + +} Added: trunk/stdair/stdair/bom/DemandStream.hpp =================================================================== --- trunk/stdair/stdair/bom/DemandStream.hpp (rev 0) +++ trunk/stdair/stdair/bom/DemandStream.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,94 @@ +#ifndef __STDAIR_BAS_DEMAND_STREAM_HPP +#define __STDAIR_BAS_DEMAND_STREAM_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// 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/BookingRequestStruct.hpp> + +namespace stdair { + + /** Class modeling a demand stream. */ + class DemandStream { + + 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; + } + + public: + // ///////////// Setters /////////// + /** Set the demand characteristics */ + void setKey (const DemandStreamKey_T& iKey) { + _key = iKey; + } + + public: + // /////////////// Business Methods ////////// + /** Generate the next request. */ + bool generateNext (BookingRequestStruct&); + + public: + // ////////// Constructors and destructors ///////// + /** Constructor by default */ + DemandStream (const DemandStreamKey_T&, const DemandCharacteristics&, + const DemandDistribution&, const RandomSeed_T&, + const RandomSeed_T&, const RandomSeed_T&); + + /** Destructor */ + virtual ~DemandStream (); + + private: + /** Default constructors. */ + DemandStream (); + DemandStream (const DemandStream&); + + /** Initialization. */ + void init(); + + private: + // ////////// 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_BAS_DEMAND_STREAM_HPP Added: trunk/stdair/stdair/bom/EventQueue.cpp =================================================================== --- trunk/stdair/stdair/bom/EventQueue.cpp (rev 0) +++ trunk/stdair/stdair/bom/EventQueue.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,87 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STDAIR +#include <stdair/bom/EventQueue.hpp> + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + EventQueue::EventQueue (const DateTime_T& iEarliestDateTime) { + // Earliest time is necessary in order to set _currentEvent + // "before" any event. Without it, _currentEvent would need to be + // set to the first event, the first an event is added + EventStruct lEarliestEvent (iEarliestDateTime); + _eventList.insert(EventListElement_T (iEarliestDateTime, lEarliestEvent)); + _currentEvent = _eventList.begin (); + } + + // ////////////////////////////////////////////////////////////////////// + EventQueue::~EventQueue () { + } + + // ////////////////////////////////////////////////////////////////////// + EventStruct* EventQueue::popEvent () { + EventStruct* oEventStruct_ptr = NULL; + if (!isQueueDone ()) { + ++_currentEvent; + oEventStruct_ptr = &(_currentEvent->second); + } + return oEventStruct_ptr; + } + + // ////////////////////////////////////////////////////////////////////// + void EventQueue::addEvent (const EventStruct& iEventStruct) { + DateTime_T lEventDateTime = iEventStruct.getEventDateTime (); + _eventList.insert( std::pair<DateTime_T, EventStruct> (lEventDateTime, iEventStruct) ); + } + + // ////////////////////////////////////////////////////////////////////// + const bool EventQueue::isQueueDone () const { + bool oFlagDone = false; + if (_currentEvent == _eventList.end ()) { + oFlagDone = true; + } else { + EventList_T::iterator lNextEvent = _currentEvent; + ++lNextEvent; + if (lNextEvent == _eventList.end ()) { + oFlagDone = true; + } + } + return oFlagDone; + } + + // ////////////////////////////////////////////////////////////////////// + const Count_T EventQueue::getQueueSize () const { + if (_eventList.empty ()) { + return 0; + } else { + return _eventList.size (); + } + } + + // ////////////////////////////////////////////////////////////////////// + const bool EventQueue::isQueueEmpty () const { + return _eventList.empty (); + } + + // ////////////////////////////////////////////////////////////////////// + const Count_T EventQueue::getPositionOfCurrent () const { + int i = 0; + bool flag = false; + for (EventList_T::const_iterator it = _eventList.begin (); + it != _eventList.end (); ++it) { + if (it == _currentEvent) { + flag = true; + break; + } + ++i; + } + if (flag) { + return i; + } else { + return -1; + } + } + +} Added: trunk/stdair/stdair/bom/EventQueue.hpp =================================================================== --- trunk/stdair/stdair/bom/EventQueue.hpp (rev 0) +++ trunk/stdair/stdair/bom/EventQueue.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,73 @@ +#ifndef __STDAIR_BAS_EVENTQUEUE_HPP +#define __STDAIR_BAS_EVENTQUEUE_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STDAIR +#include <stdair/STDAIR_Types.hpp> +#include <stdair/bom/EventStruct.hpp> + +namespace stdair { + + /** Event queue. */ + class EventQueue { + + public: + typedef std::pair<DateTime_T, EventStruct> EventListElement_T; + typedef std::multimap<DateTime_T, EventStruct> EventList_T; + + public: + // ///////////// Getters /////////// + // /** Get the event type */ + //const EventType_T& getEventType () const { + // return _eventType; + //} + + public: + // ////////// Constructors and destructors ///////// + /** Constructor. */ + EventQueue (const DateTime_T&); + + /** Destructor. */ + virtual ~EventQueue (); + + public: + // ////////// Business methods ///////// + /** Pop event */ + EventStruct* popEvent (); + + /** Add event */ + void addEvent (const EventStruct&); + + /** Is queue done */ + const bool isQueueDone () const; + + + // ////////// Debug methods ///////// + /** Queue size */ + const Count_T getQueueSize () const; + + /** Is queue empty */ + const bool isQueueEmpty () const; + + /** Get position of current */ + const Count_T getPositionOfCurrent () const; + + private: + /** Default constructors. */ + EventQueue (const EventQueue&); + + private: + // ////////// Attributes ////////// + + /** Event list */ + EventList_T _eventList; + + /** Pointer to current event */ + EventList_T::iterator _currentEvent; + + }; + +} +#endif // __STDAIR_BAS_EVENTQUEUE_HPP Added: trunk/stdair/stdair/bom/EventStruct.cpp =================================================================== --- trunk/stdair/stdair/bom/EventStruct.cpp (rev 0) +++ trunk/stdair/stdair/bom/EventStruct.cpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,43 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STDAIR +#include <stdair/bom/BookingRequestStruct.hpp> +#include <stdair/bom/EventStruct.hpp> + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + EventStruct:: + EventStruct(const EventType_T& iEventType, const DateTime_T& iDateTime, + DemandStream& ioDemandStream, BookingRequestStruct* const iRequest) + : _eventType (iEventType), + _eventDateTime (iDateTime), + _demandStream (&ioDemandStream), + _request (NULL) { + if (iEventType == "Request") { + _request = iRequest; + } + } + + // ////////////////////////////////////////////////////////////////////// + EventStruct:: + EventStruct (const EventStruct& iEventStruct) + : _eventType (iEventStruct._eventType), + _eventDateTime (iEventStruct._eventDateTime), + _demandStream (iEventStruct._demandStream), + _request (iEventStruct._request) { + } + + // ////////////////////////////////////////////////////////////////////// + EventStruct::EventStruct (const DateTime_T& iDateTime) + : _eventType (""), + _eventDateTime (iDateTime), + _request (NULL) { + } + + // ////////////////////////////////////////////////////////////////////// + EventStruct::~EventStruct () { + } + +} Added: trunk/stdair/stdair/bom/EventStruct.hpp =================================================================== --- trunk/stdair/stdair/bom/EventStruct.hpp (rev 0) +++ trunk/stdair/stdair/bom/EventStruct.hpp 2010-02-08 16:32:09 UTC (rev 124) @@ -0,0 +1,78 @@ +#ifndef __STDAIR_BAS_EVENTSTRUCT_HPP +#define __STDAIR_BAS_EVENTSTRUCT_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STDAIR +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + /** Forward declaration */ + struct BookingRequestStruct; + class DemandStream; + + /** Event struct. */ + struct EventStruct { + + public: + // ///////////// Getters /////////// + /** Get the event type */ + const EventType_T& getEventType () const { + return _eventType; + } + + /** Get the event datetime */ + const DateTime_T& getEventDateTime () const { + return _eventDateTime; + } + + /** Get the pointer Request event. */ + const BookingRequestStruct* getPointerToRequestEvent () const { + return _request; + } + + /** Get the demand stream of the event. */ + DemandStream& getDemandStream () const { + assert (_demandStream != NULL); + return *_demandStream; + } + + public: + // ////////// Constructors and destructors ///////// + /** Constructor. */ + EventStruct (const EventType_T&, const DateTime_T&, + DemandStream&, BookingRequestStruct* const); + EventStruct (const DateTime_T&); + + /** Copy constructor. */ + EventStruct (const EventStruct&); + + /** Destructor. */ + virtual ~EventStruct (); + + private: + /** Default constructors. */ + EventStruct (); + + + private: + // ////////// Attributes ////////// + + /** Event type */ + EventType_T _eventType; + + /** Event datetime */ + DateTime_T _eventDateTime; + + /** The demand stream which generated this event. */ + DemandStream* _demandStream; + + /** Pointer to Request event */ + BookingRequestStruct* _request; + + }; + +} +#endif // __STDAIR_BAS_EVENTSTRUCT_HPP Modified: trunk/stdair/stdair/bom/sources.mk =================================================================== --- trunk/stdair/stdair/bom/sources.mk 2010-02-08 09:22:21 UTC (rev 123) +++ trunk/stdair/stdair/bom/sources.mk 2010-02-08 16:32:09 UTC (rev 124) @@ -86,6 +86,9 @@ $(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/EventStruct.hpp \ + $(top_srcdir)/stdair/bom/EventQueue.hpp \ $(top_srcdir)/stdair/bom/BomManager.hpp bom_cc_sources = \ $(top_srcdir)/stdair/bom/BomRootKey.cpp \ @@ -135,4 +138,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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |