From: <qua...@us...> - 2010-10-04 09:11:57
|
Revision: 340 http://stdair.svn.sourceforge.net/stdair/?rev=340&view=rev Author: quannaus Date: 2010-10-04 09:11:49 +0000 (Mon, 04 Oct 2010) Log Message: ----------- [dev-temporary] Added a generator of random seeds for trademgen, should be moved in trademgen module later. Modified Paths: -------------- trunk/stdair/stdair/STDAIR_Types.hpp trunk/stdair/stdair/basic/BasConst.cpp trunk/stdair/stdair/bom/BomRoot.cpp trunk/stdair/stdair/bom/BomRoot.hpp trunk/stdair/stdair/bom/EventQueue.cpp trunk/stdair/stdair/bom/EventStruct.cpp trunk/stdair/stdair/bom/EventStruct.hpp trunk/stdair/stdair/bom/EventTypes.hpp Modified: trunk/stdair/stdair/STDAIR_Types.hpp =================================================================== --- trunk/stdair/stdair/STDAIR_Types.hpp 2010-10-03 19:51:11 UTC (rev 339) +++ trunk/stdair/stdair/STDAIR_Types.hpp 2010-10-04 09:11:49 UTC (rev 340) @@ -429,6 +429,9 @@ // Date / Time /** Time duration in (integer) number of seconds */ typedef long int IntDuration_T; + + /** Time duration in (long long integer) number of milliseconds */ + typedef long long int LongDuration_T; /** Duration in (float) number of time units */ typedef float FloatDuration_T; Modified: trunk/stdair/stdair/basic/BasConst.cpp =================================================================== --- trunk/stdair/stdair/basic/BasConst.cpp 2010-10-03 19:51:11 UTC (rev 339) +++ trunk/stdair/stdair/basic/BasConst.cpp 2010-10-04 09:11:49 UTC (rev 340) @@ -50,7 +50,7 @@ // // //////// General /////// /** Default date for the General. */ - const Date_T DEFAULT_DATE (2007, boost::gregorian::Jan, 1); + const Date_T DEFAULT_DATE (2010, boost::gregorian::Jan, 1); /** Default date&time. */ const DateTime_T DEFAULT_DATETIME (DEFAULT_DATE, NULL_BOOST_TIME_DURATION); Modified: trunk/stdair/stdair/bom/BomRoot.cpp =================================================================== --- trunk/stdair/stdair/bom/BomRoot.cpp 2010-10-03 19:51:11 UTC (rev 339) +++ trunk/stdair/stdair/bom/BomRoot.cpp 2010-10-04 09:11:49 UTC (rev 340) @@ -4,12 +4,15 @@ // STL #include <cassert> // STDAIR +#include <stdair/basic/BasConst_General.hpp> #include <stdair/bom/BomRoot.hpp> namespace stdair { // //////////////////////////////////////////////////////////////////// - BomRoot::BomRoot (const Key_T& iKey) : _key (iKey) { + BomRoot::BomRoot (const Key_T& iKey) + : _key (iKey), _seed (DEFAULT_RANDOM_SEED), _generator (_seed), + _uniformGenerator (_generator, boost::uniform_real<> (0, 1)) { } // //////////////////////////////////////////////////////////////////// @@ -23,4 +26,11 @@ return oStr.str(); } + // //////////////////////////////////////////////////////////////////// + RandomSeed_T BomRoot::generateSeed () { + RealNumber_T lVariateUnif = _uniformGenerator() * 1e9; + RandomSeed_T oSeed = static_cast<RandomSeed_T> (lVariateUnif); + return oSeed; + } + } Modified: trunk/stdair/stdair/bom/BomRoot.hpp =================================================================== --- trunk/stdair/stdair/bom/BomRoot.hpp 2010-10-03 19:51:11 UTC (rev 339) +++ trunk/stdair/stdair/bom/BomRoot.hpp 2010-10-04 09:11:49 UTC (rev 340) @@ -4,6 +4,9 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +// Boost Random +#include <boost/random/uniform_real.hpp> +#include <boost/random/variate_generator.hpp> // STDAIR #include <stdair/bom/BomAbstract.hpp> #include <stdair/bom/BomRootKey.hpp> @@ -51,6 +54,14 @@ // Attributes Key_T _key; HolderMap_T _holderMap; + + // TEST + stdair::RandomSeed_T _seed; + stdair::BaseGenerator_T _generator; + boost::variate_generator<stdair::BaseGenerator_T&, + boost::uniform_real<> > _uniformGenerator; + public: + RandomSeed_T generateSeed (); }; } Modified: trunk/stdair/stdair/bom/EventQueue.cpp =================================================================== --- trunk/stdair/stdair/bom/EventQueue.cpp 2010-10-03 19:51:11 UTC (rev 339) +++ trunk/stdair/stdair/bom/EventQueue.cpp 2010-10-04 09:11:49 UTC (rev 340) @@ -23,13 +23,13 @@ // ////////////////////////////////////////////////////////////////////// void EventQueue::addEvent (EventStruct& ioEventStruct) { - const DateTime_T& lEventDateTime = ioEventStruct.getEventDateTime (); const bool insertionSucceeded = - _eventList.insert (EventListElement_T (lEventDateTime, ioEventStruct)).second; + _eventList.insert (EventListElement_T (ioEventStruct._eventTimestamp, + ioEventStruct)).second; // If the insertion is not succeded. if (insertionSucceeded == false) { - ioEventStruct.moveForwardInTime(); + ++ioEventStruct._eventTimestamp; addEvent (ioEventStruct); } } Modified: trunk/stdair/stdair/bom/EventStruct.cpp =================================================================== --- trunk/stdair/stdair/bom/EventStruct.cpp 2010-10-03 19:51:11 UTC (rev 339) +++ trunk/stdair/stdair/bom/EventStruct.cpp 2010-10-04 09:11:49 UTC (rev 340) @@ -10,36 +10,29 @@ // ////////////////////////////////////////////////////////////////////// EventStruct:: - EventStruct(const EventType_T& iEventType, const DateTime_T& iDateTime, - const DemandStreamKeyStr_T& iDemandStreamKey, - BookingRequestPtr_T ioRequestPtr) - : _eventType (iEventType), _eventDateTime (iDateTime), - _demandStreamKey (iDemandStreamKey) { + EventStruct (const EventType_T& iEventType, + const DemandStreamKeyStr_T& iDemandStreamKey, + BookingRequestPtr_T ioRequestPtr) + : _eventType (iEventType), _demandStreamKey (iDemandStreamKey) { _request = ioRequestPtr; + + // Compute the number of seconds between iDateTime and DEFAULT_DATETIME. + assert (ioRequestPtr != NULL); + Duration_T lDuration = ioRequestPtr->getRequestDateTime() - DEFAULT_DATETIME; + _eventTimestamp = lDuration.total_milliseconds(); } // ////////////////////////////////////////////////////////////////////// EventStruct:: EventStruct (const EventStruct& iEventStruct) : _eventType (iEventStruct._eventType), - _eventDateTime (iEventStruct._eventDateTime), + _eventTimestamp (iEventStruct._eventTimestamp), _demandStreamKey (iEventStruct._demandStreamKey) { _request = iEventStruct._request; } // ////////////////////////////////////////////////////////////////////// - EventStruct::EventStruct (const DateTime_T& iDateTime) - : _eventType (""), _eventDateTime (iDateTime), - _demandStreamKey ("") { - } - - // ////////////////////////////////////////////////////////////////////// EventStruct::~EventStruct () { } - // //////////////////////////////////////////////////////////////////// - void EventStruct::moveForwardInTime () { - _eventDateTime += DEFAULT_EPSILON_DURATION; - } - } Modified: trunk/stdair/stdair/bom/EventStruct.hpp =================================================================== --- trunk/stdair/stdair/bom/EventStruct.hpp 2010-10-03 19:51:11 UTC (rev 339) +++ trunk/stdair/stdair/bom/EventStruct.hpp 2010-10-04 09:11:49 UTC (rev 340) @@ -12,7 +12,8 @@ /** Event struct. */ struct EventStruct { - + friend struct EventQueue; + public: // ///////////// Getters /////////// /** Get the event type */ @@ -20,11 +21,6 @@ return _eventType; } - /** Get the event datetime */ - const DateTime_T& getEventDateTime () const { - return _eventDateTime; - } - /** Get the Request event. */ const BookingRequestStruct& getBookingRequest () const { assert (_request != NULL); @@ -35,34 +31,28 @@ const DemandStreamKeyStr_T& getDemandStreamKey () const { return _demandStreamKey; } - - public: - // ///////////////// Business Methods ///////////////// - /** Move the event forward in time by one nanosecond. */ - void moveForwardInTime (); public: // ////////// Constructors and destructors ///////// /** Constructor. */ - EventStruct (const EventType_T&, const DateTime_T&, - const DemandStreamKeyStr_T&, BookingRequestPtr_T); - EventStruct (const DateTime_T&); + EventStruct (const EventType_T&, const DemandStreamKeyStr_T&, + BookingRequestPtr_T); /** Copy constructor. */ EventStruct (const EventStruct&); /** Destructor. */ ~EventStruct (); - private: /** Default constructors. */ EventStruct (); - private: // ////////// Attributes ////////// /** Event type */ EventType_T _eventType; - /** Event datetime */ - DateTime_T _eventDateTime; + /** Reprentative timestamp of the event, which is the number of + milliseconds between the event date-time and the default + date-time (2010-01-01 00:00:00) */ + LongDuration_T _eventTimestamp; /** The demand stream which generated this event. */ DemandStreamKeyStr_T _demandStreamKey; /** Pointer to Request event */ Modified: trunk/stdair/stdair/bom/EventTypes.hpp =================================================================== --- trunk/stdair/stdair/bom/EventTypes.hpp 2010-10-03 19:51:11 UTC (rev 339) +++ trunk/stdair/stdair/bom/EventTypes.hpp 2010-10-04 09:11:49 UTC (rev 340) @@ -16,10 +16,10 @@ struct EventStruct; // Define a list of events. - typedef std::map<const DateTime_T, EventStruct> EventList_T; + typedef std::map<const LongDuration_T, EventStruct> EventList_T; // Define an element of a event list. - typedef std::pair<const DateTime_T, EventStruct> EventListElement_T; + typedef std::pair<const LongDuration_T, EventStruct> EventListElement_T; } #endif // __STDAIR_BOM_EVENTTYPES_HPP This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |