From: <qua...@us...> - 2010-02-10 10:14:16
|
Revision: 125 http://stdair.svn.sourceforge.net/stdair/?rev=125&view=rev Author: quannaus Date: 2010-02-10 10:14:09 +0000 (Wed, 10 Feb 2010) Log Message: ----------- [dev] Some changes in several objects for the demand generation. Modified Paths: -------------- trunk/stdair/stdair/basic/DemandCharacteristics.cpp trunk/stdair/stdair/basic/DemandCharacteristics.hpp trunk/stdair/stdair/bom/BookingRequestStruct.cpp trunk/stdair/stdair/bom/BookingRequestStruct.hpp trunk/stdair/stdair/bom/DemandStream.cpp trunk/stdair/stdair/bom/DemandStream.hpp trunk/stdair/stdair/bom/EventStruct.cpp trunk/stdair/stdair/bom/EventStruct.hpp trunk/stdair/stdair/factory/FacBomContent.cpp trunk/stdair/stdair/factory/FacBomContent.hpp Modified: trunk/stdair/stdair/basic/DemandCharacteristics.cpp =================================================================== --- trunk/stdair/stdair/basic/DemandCharacteristics.cpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/basic/DemandCharacteristics.cpp 2010-02-10 10:14:09 UTC (rev 125) @@ -21,10 +21,12 @@ // ///////////////////////////////////////////////////// DemandCharacteristics:: - DemandCharacteristics (const DemandCharacteristics& iDemandCharacteristics) { - _origin = iDemandCharacteristics._origin; - _preferredDepartureDate = iDemandCharacteristics._preferredDepartureDate; - _arrivalPattern = iDemandCharacteristics._arrivalPattern; + DemandCharacteristics (const DemandCharacteristics& iDemandCharacteristics) + : _origin (iDemandCharacteristics._origin), + _destination (iDemandCharacteristics._destination), + _preferredDepartureDate (iDemandCharacteristics._preferredDepartureDate), + _paxType (iDemandCharacteristics._paxType), + _arrivalPattern (iDemandCharacteristics._arrivalPattern) { } // ///////////////////////////////////////////////////// Modified: trunk/stdair/stdair/basic/DemandCharacteristics.hpp =================================================================== --- trunk/stdair/stdair/basic/DemandCharacteristics.hpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/basic/DemandCharacteristics.hpp 2010-02-10 10:14:09 UTC (rev 125) @@ -18,14 +18,24 @@ // ///////////// Getters /////////// /** Get the origin. */ - const LocationCode_T& getOrigin() const { + const AirportCode_T& getOrigin() const { return _origin; } + /** Get the destination. */ + const AirportCode_T& getDestination() const { + return _destination; + } + /** Get the preferred departure date. */ const Date_T& getPreferredDepartureDate() const { return _preferredDepartureDate; } + + /** Get the passenger type. */ + const PassengerType_T& getPaxType() const { + return _paxType; + } /** Get the arrival pattern. */ const ContinuousAttribute<FloatDuration_T>& getArrivalPattern() const { @@ -35,15 +45,25 @@ public: // ///////////// Setters /////////// /** Set the origin. */ - void setOrigin (const LocationCode_T& iOrigin) { + void setOrigin (const AirportCode_T& iOrigin) { _origin = iOrigin; } + + /** Set the destination. */ + void setDestination (const AirportCode_T& iDestination) { + _destination = iDestination; + } /** Set the preferred departure date. */ void setPreferredDepartureDate (const Date_T& iPreferredDepartureDate) { _preferredDepartureDate = iPreferredDepartureDate; } + /** Set the passenger type. */ + void setPaxType (const PassengerType_T& iPaxType) { + _paxType = iPaxType; + } + /** Set the arrival pattern. */ void setArrivalPattern (const ContinuousAttribute<FloatDuration_T>& iArrivalPattern) { _arrivalPattern = iArrivalPattern; @@ -70,10 +90,16 @@ private: // ////////// Attributes ////////// /** Origin */ - LocationCode_T _origin; + AirportCode_T _origin; + /** Origin */ + AirportCode_T _destination; + /** Preferred departure date */ Date_T _preferredDepartureDate; + + /** Passenger type. */ + PassengerType_T _paxType; /** Arrival pattern (cumulative distribution of timing of arrival of requests (negative number of days between departure date @@ -81,10 +107,10 @@ ContinuousAttribute<FloatDuration_T> _arrivalPattern; /** Trip type probability mass */ - //CategoricalAttribute<TripType_T> _tripTypeProbabilityMass; + // CategoricalAttribute<TripType_T> _tripTypeProbabilityMass; /** Willingness-to-pay cumulative distribution */ - //ContinuousAttribute<MonetaryValue_T> _willingnessToPayCumulativeDistribution; + // ContinuousAttribute<MonetaryValue_T> _willingnessToPayCumulativeDistribution; }; Modified: trunk/stdair/stdair/bom/BookingRequestStruct.cpp =================================================================== --- trunk/stdair/stdair/bom/BookingRequestStruct.cpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/bom/BookingRequestStruct.cpp 2010-02-10 10:14:09 UTC (rev 125) @@ -10,10 +10,6 @@ #include <stdair/bom/BookingRequestStruct.hpp> namespace stdair { - - // ////////////////////////////////////////////////////////////////////// - BookingRequestStruct::BookingRequestStruct () { - } // ////////////////////////////////////////////////////////////////////// BookingRequestStruct::BookingRequestStruct (const AirportCode_T& iOrigin, Modified: trunk/stdair/stdair/bom/BookingRequestStruct.hpp =================================================================== --- trunk/stdair/stdair/bom/BookingRequestStruct.hpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/bom/BookingRequestStruct.hpp 2010-02-10 10:14:09 UTC (rev 125) @@ -15,6 +15,8 @@ /** Structure holding the elements of a booking request. */ struct BookingRequestStruct : public StructAbstract { + friend class DemandStream; + public: // /////////////// Getters ///////////////// /** Get the requested origin. */ @@ -92,12 +94,15 @@ /** Display of the structure. */ const std::string describe() const; - public: + private : // /////////////// Constructors and Destructors ///////////////// BookingRequestStruct (); + public : BookingRequestStruct (const AirportCode_T&, const AirportCode_T&, const Date_T&, const DateTime_T&, const PassengerType_T&, const NbOfSeats_T&); + BookingRequestStruct (const BookingRequestStruct&); + public: ~BookingRequestStruct(); Modified: trunk/stdair/stdair/bom/DemandStream.cpp =================================================================== --- trunk/stdair/stdair/bom/DemandStream.cpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/bom/DemandStream.cpp 2010-02-10 10:14:09 UTC (rev 125) @@ -60,9 +60,9 @@ } _totalNumberOfRequestsToBeGenerated = lIntegerNumberOfRequestsToBeGenerated; } - - // ////////////////////////////////////////////////////////////////////// - bool DemandStream::generateNext (BookingRequestStruct& ioRequest) { + + // //////////////////////////////////////////////////////////////////// + const bool DemandStream::stillHavingRequestsToBeGenerated () const { // Check whether enough requests have already been generated const Count_T lNbOfRequestsGeneratedSoFar = _randomGenerationContext.getNumberOfRequestsGeneratedSoFar (); @@ -72,17 +72,31 @@ if (lRemainingNumberOfRequestsToBeGenerated <= 0) { return false; } - // DEBUG - STDAIR_LOG_DEBUG ("Here"); + return true; + + } + + // ////////////////////////////////////////////////////////////////////// + BookingRequestPtr_T DemandStream::generateNext () { + // Assert that there are requests to be generated. + const Count_T lNbOfRequestsGeneratedSoFar = + _randomGenerationContext.getNumberOfRequestsGeneratedSoFar (); + const Count_T lRemainingNumberOfRequestsToBeGenerated = + _totalNumberOfRequestsToBeGenerated - lNbOfRequestsGeneratedSoFar; + assert (lRemainingNumberOfRequestsToBeGenerated > 0); + + // Origin - ioRequest.setOrigin (_demandCharacteristics.getOrigin ()); - + const AirportCode_T& lOrigin = _demandCharacteristics.getOrigin (); + // Destination + const AirportCode_T& lDestination = _demandCharacteristics.getDestination (); // Preferred departure date - const Date_T lPreferredDepartureDate = + const Date_T& lPreferredDepartureDate = _demandCharacteristics.getPreferredDepartureDate (); - ioRequest.setPreferredDepartureDate (lPreferredDepartureDate); - + // Passenger type. + const PassengerType_T& lPassengerType = _demandCharacteristics.getPaxType(); + // Request datetime, determined from departure date and arrival pattern // Sequential generation const Probability_T lCumulativeProbabilitySoFar = @@ -99,34 +113,45 @@ // convert the number of days in number of seconds + number of milliseconds const FloatDuration_T lNumberOfSeconds = - lNumberOfDaysBetweenDepartureAndThisRequest*static_cast<float> (SECONDS_IN_ONE_DAY); + 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); + (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 + 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); + 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 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; - + + + // Create the booking request with a hardcoded party size. + BookingRequestPtr_T oBookingRequest_ptr = + BookingRequestPtr_T (new BookingRequestStruct (lOrigin, lDestination, + lPreferredDepartureDate, + lDateTimeThisRequest, + lPassengerType, 1)); + assert (oBookingRequest_ptr != NULL); + return oBookingRequest_ptr; } } Modified: trunk/stdair/stdair/bom/DemandStream.hpp =================================================================== --- trunk/stdair/stdair/bom/DemandStream.hpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/bom/DemandStream.hpp 2010-02-10 10:14:09 UTC (rev 125) @@ -4,6 +4,8 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +// Boost +#include <boost/shared_ptr.hpp> // STL #include <iosfwd> // STDAIR @@ -12,13 +14,19 @@ #include <stdair/basic/DemandDistribution.hpp> #include <stdair/basic/RandomGeneration.hpp> #include <stdair/basic/RandomGenerationContext.hpp> +#include <stdair/bom/BomContent.hpp> #include <stdair/bom/BookingRequestStruct.hpp> namespace stdair { + + // Type definitions. + /** Define the smart pointer to a booking request. */ + typedef boost::shared_ptr<BookingRequestStruct> BookingRequestPtr_T; /** Class modeling a demand stream. */ - class DemandStream { - + class DemandStream : public BomContent { + friend class FacBomContent; + public: // ///////////// Getters /////////// /** Get the key */ @@ -37,13 +45,37 @@ void setKey (const DemandStreamKey_T& iKey) { _key = iKey; } + + 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 ////////// + // /////////////// Business Methods ////////////// + /** Check whether enough requests have already been generated. */ + const bool stillHavingRequestsToBeGenerated () const; + /** Generate the next request. */ - bool generateNext (BookingRequestStruct&); + BookingRequestPtr_T generateNext (); - public: + private: // ////////// Constructors and destructors ///////// /** Constructor by default */ DemandStream (const DemandStreamKey_T&, const DemandCharacteristics&, @@ -53,7 +85,6 @@ /** Destructor */ virtual ~DemandStream (); - private: /** Default constructors. */ DemandStream (); DemandStream (const DemandStream&); Modified: trunk/stdair/stdair/bom/EventStruct.cpp =================================================================== --- trunk/stdair/stdair/bom/EventStruct.cpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/bom/EventStruct.cpp 2010-02-10 10:14:09 UTC (rev 125) @@ -10,14 +10,11 @@ // ////////////////////////////////////////////////////////////////////// EventStruct:: EventStruct(const EventType_T& iEventType, const DateTime_T& iDateTime, - DemandStream& ioDemandStream, BookingRequestStruct* const iRequest) + DemandStream& ioDemandStream, BookingRequestPtr_T ioRequestPtr) : _eventType (iEventType), _eventDateTime (iDateTime), - _demandStream (&ioDemandStream), - _request (NULL) { - if (iEventType == "Request") { - _request = iRequest; - } + _demandStream (&ioDemandStream) { + _request = ioRequestPtr; } // ////////////////////////////////////////////////////////////////////// @@ -25,15 +22,15 @@ EventStruct (const EventStruct& iEventStruct) : _eventType (iEventStruct._eventType), _eventDateTime (iEventStruct._eventDateTime), - _demandStream (iEventStruct._demandStream), - _request (iEventStruct._request) { + _demandStream (iEventStruct._demandStream) { + _request = iEventStruct._request; } // ////////////////////////////////////////////////////////////////////// EventStruct::EventStruct (const DateTime_T& iDateTime) : _eventType (""), _eventDateTime (iDateTime), - _request (NULL) { + _demandStream (NULL) { } // ////////////////////////////////////////////////////////////////////// Modified: trunk/stdair/stdair/bom/EventStruct.hpp =================================================================== --- trunk/stdair/stdair/bom/EventStruct.hpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/bom/EventStruct.hpp 2010-02-10 10:14:09 UTC (rev 125) @@ -4,6 +4,8 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +// Boost +#include <boost/shared_ptr.hpp> // STDAIR #include <stdair/STDAIR_Types.hpp> @@ -12,6 +14,10 @@ /** Forward declaration */ struct BookingRequestStruct; class DemandStream; + + // Type definitions. + /** Define the smart pointer to a booking request. */ + typedef boost::shared_ptr<BookingRequestStruct> BookingRequestPtr_T; /** Event struct. */ struct EventStruct { @@ -28,9 +34,10 @@ return _eventDateTime; } - /** Get the pointer Request event. */ - const BookingRequestStruct* getPointerToRequestEvent () const { - return _request; + /** Get the Request event. */ + const BookingRequestStruct& getBookingRequest () const { + assert (_request != NULL); + return *_request; } /** Get the demand stream of the event. */ @@ -43,7 +50,7 @@ // ////////// Constructors and destructors ///////// /** Constructor. */ EventStruct (const EventType_T&, const DateTime_T&, - DemandStream&, BookingRequestStruct* const); + DemandStream&, BookingRequestPtr_T); EventStruct (const DateTime_T&); /** Copy constructor. */ @@ -70,7 +77,7 @@ DemandStream* _demandStream; /** Pointer to Request event */ - BookingRequestStruct* _request; + BookingRequestPtr_T _request; }; Modified: trunk/stdair/stdair/factory/FacBomContent.cpp =================================================================== --- trunk/stdair/stdair/factory/FacBomContent.cpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/factory/FacBomContent.cpp 2010-02-10 10:14:09 UTC (rev 125) @@ -5,6 +5,7 @@ #include <cassert> // STDAIR #include <stdair/bom/BomStructure.hpp> +#include <stdair/bom/DemandStream.hpp> #include <stdair/bom/BomContent.hpp> #include <stdair/factory/FacSupervisor.hpp> #include <stdair/factory/FacBomContent.hpp> @@ -47,4 +48,27 @@ _instance = NULL; } + // //////////////////////////////////////////////////////////////////// + DemandStream& FacBomContent:: + createDemandStream (const DemandStreamKey_T& iKey, + const DemandCharacteristics& iDemandCharacteristics, + const DemandDistribution& iDemandDistribution, + const RandomSeed_T& iNumberOfRequestsSeed, + const RandomSeed_T& iRequestDateTimeSeed, + const RandomSeed_T& iDemandCharacteristicsSeed) { + DemandStream* aDemandStream_ptr = NULL; + + aDemandStream_ptr = new DemandStream (iKey, iDemandCharacteristics, + iDemandDistribution, + iNumberOfRequestsSeed, + iRequestDateTimeSeed, + iDemandCharacteristicsSeed); + assert (aDemandStream_ptr != NULL); + + // The new object is added to the BOM pool + _contentPool.push_back (aDemandStream_ptr); + + return *aDemandStream_ptr; + } + } Modified: trunk/stdair/stdair/factory/FacBomContent.hpp =================================================================== --- trunk/stdair/stdair/factory/FacBomContent.hpp 2010-02-08 16:32:09 UTC (rev 124) +++ trunk/stdair/stdair/factory/FacBomContent.hpp 2010-02-10 10:14:09 UTC (rev 125) @@ -20,7 +20,10 @@ template<typename BOM> struct BomList_T; class BomStructure; class BomContent; + class DemandStream; struct OptimizerStruct_T; + struct DemandCharacteristics; + struct DemandDistribution; /** Base class for Factory layer. */ class FacBomContent { @@ -169,6 +172,16 @@ ioOutboundPath._flightPathCode = iReferenceOutboundPath._flightPathCode; } + + // ////////////////////////////////////////////////////////////////// + // //////////////////////// Normal Factory ////////////////////////// + // ////////////////////////////////////////////////////////////////// + /** Create the DemandStream object. */ + DemandStream& createDemandStream (const DemandStreamKey_T&, + const DemandCharacteristics&, + const DemandDistribution&, + const RandomSeed_T&, + const RandomSeed_T&, const RandomSeed_T&); public: /** Provide the unique instance. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |