TraDemGen Logo  0.2.2
C++ Simulated Travel Demand Generation Library
DemandManager.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // StdAir
00007 #include <stdair/basic/ProgressStatusSet.hpp>
00008 #include <stdair/bom/BomManager.hpp>
00009 #include <stdair/bom/EventStruct.hpp>
00010 #include <stdair/bom/BookingRequestStruct.hpp>
00011 #include <stdair/bom/EventQueue.hpp>
00012 #include <stdair/bom/TravelSolutionStruct.hpp>
00013 #include <stdair/bom/CancellationStruct.hpp>
00014 #include <stdair/factory/FacBom.hpp>
00015 #include <stdair/factory/FacBomManager.hpp>
00016 #include <stdair/service/Logger.hpp>
00017 // TraDemGen
00018 #include <trademgen/basic/DemandCharacteristics.hpp>
00019 #include <trademgen/basic/DemandDistribution.hpp>
00020 #include <trademgen/bom/DemandStruct.hpp>
00021 #include <trademgen/bom/DemandStream.hpp>
00022 #include <trademgen/command/DemandManager.hpp>
00023 
00024 namespace TRADEMGEN {
00025 
00026   // //////////////////////////////////////////////////////////////////////
00027   void DemandManager::
00028   buildSampleBomStd (stdair::EventQueue& ioEventQueue,
00029                   stdair::RandomGeneration& ioSharedGenerator,
00030                   const POSProbabilityMass_T& iPOSProbMass) {
00031 
00032     // Key of the demand stream
00033     const stdair::AirportCode_T lOrigin ("SIN");
00034     const stdair::AirportCode_T lDestination ("BKK");
00035     const stdair::Date_T lDepDate (2011, 2, 14);
00036     const stdair::CabinCode_T lCabin ("Y");
00037 
00038     //
00039     const DemandStreamKey lDemandStreamKey (lOrigin, lDestination, lDepDate,
00040                                             lCabin);
00041 
00042     // DEBUG
00043     // STDAIR_LOG_DEBUG ("Demand stream key: " << lDemandStreamKey.describe());
00044     
00045     // Distribution for the number of requests
00046     const stdair::MeanValue_T lDemandMean (10.0);
00047     const stdair::StdDevValue_T lDemandStdDev (1.0);
00048     const DemandDistribution lDemandDistribution (lDemandMean, lDemandStdDev);
00049     
00050     // Seed
00051     const stdair::RandomSeed_T& lRequestDateTimeSeed =
00052       generateSeed (ioSharedGenerator);
00053     const stdair::RandomSeed_T& lDemandCharacteristicsSeed =
00054       generateSeed (ioSharedGenerator);
00055 
00056     //
00057     ArrivalPatternCumulativeDistribution_T lDTDProbDist;
00058     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-330,
00059                                                                            0));
00060     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-40,
00061                                                                            0.2));
00062     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-20,
00063                                                                            0.6));
00064     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-1,
00065                                                                            1.0));
00066     //
00067     POSProbabilityMassFunction_T lPOSProbDist;
00068     lPOSProbDist.insert (POSProbabilityMassFunction_T::value_type ("BKK", 0.3));
00069     lPOSProbDist.insert (POSProbabilityMassFunction_T::value_type ("SIN", 0.7));
00070     //
00071     ChannelProbabilityMassFunction_T lChannelProbDist;
00072     lChannelProbDist.insert (ChannelProbabilityMassFunction_T::value_type ("DF",
00073                                                                            0.1));
00074     lChannelProbDist.insert (ChannelProbabilityMassFunction_T::value_type ("DN",
00075                                                                            0.3));
00076     lChannelProbDist.insert (ChannelProbabilityMassFunction_T::value_type ("IF",
00077                                                                            0.4));
00078     lChannelProbDist.insert (ChannelProbabilityMassFunction_T::value_type ("IN",
00079                                                                            0.2));
00080     //
00081     TripTypeProbabilityMassFunction_T lTripProbDist;
00082     lTripProbDist.insert (TripTypeProbabilityMassFunction_T::value_type ("RO",
00083                                                                          0.6));
00084     lTripProbDist.insert (TripTypeProbabilityMassFunction_T::value_type ("RI",
00085                                                                          0.2));
00086     lTripProbDist.insert (TripTypeProbabilityMassFunction_T::value_type ("OW",
00087                                                                          0.2));
00088     //
00089     StayDurationProbabilityMassFunction_T lStayProbDist;
00090     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(0,
00091                                                                            0.1));
00092     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(1,
00093                                                                            0.1));
00094     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(2,
00095                                                                            .15));
00096     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(3,
00097                                                                            .15));
00098     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(4,
00099                                                                            .15));
00100     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(5,
00101                                                                            .35));
00102     //
00103     FrequentFlyerProbabilityMassFunction_T lFFProbDist;
00104     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("P",
00105                                                                           0.01));
00106     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("G",
00107                                                                           0.05));
00108     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("S",
00109                                                                           0.15));
00110     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("M",
00111                                                                           0.3));
00112     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("N",
00113                                                                           0.49));
00114     //
00115     PreferredDepartureTimeContinuousDistribution_T lPrefDepTimeProbDist;
00116     lPrefDepTimeProbDist.
00117       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (6, 0));
00118     lPrefDepTimeProbDist.
00119       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (7,
00120                                                                           0.1));
00121     lPrefDepTimeProbDist.
00122       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (9,
00123                                                                           0.3));
00124     lPrefDepTimeProbDist.
00125       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (17,
00126                                                                           0.4));
00127     lPrefDepTimeProbDist.
00128       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (19,
00129                                                                           0.80));
00130     lPrefDepTimeProbDist.
00131       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (20,
00132                                                                           0.95));
00133     lPrefDepTimeProbDist.
00134       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (22,
00135                                                                           1));
00136     //
00137     ValueOfTimeContinuousDistribution_T lTimeValueProbDist;
00138     lTimeValueProbDist.insert(ValueOfTimeContinuousDistribution_T::value_type(15,
00139                                                                               0));
00140     lTimeValueProbDist.insert(ValueOfTimeContinuousDistribution_T::value_type(60,
00141                                                                               1));
00142 
00143     //
00144     const stdair::WTP_T lWTP (1000.0);
00145 
00146 
00147     // Delegate the call to the dedicated command
00148     DemandStream& lDemandStream = 
00149       createDemandStream (ioEventQueue, lDemandStreamKey, lDTDProbDist,
00150                           lPOSProbDist, lChannelProbDist, lTripProbDist,
00151                           lStayProbDist, lFFProbDist, lPrefDepTimeProbDist,
00152                           lWTP, lTimeValueProbDist, lDemandDistribution,
00153                           ioSharedGenerator.getBaseGenerator(),
00154                           lRequestDateTimeSeed,
00155                           lDemandCharacteristicsSeed, iPOSProbMass);
00156 
00157     // Calculate the expected total number of events for the current
00158     // demand stream
00159     const stdair::NbOfRequests_T& lExpectedTotalNbOfEvents =
00160       lDemandStream.getMeanNumberOfRequests();
00161 
00165     ioEventQueue.addStatus (stdair::EventType::BKG_REQ,
00166                             lExpectedTotalNbOfEvents);
00167   }
00168 
00169   // //////////////////////////////////////////////////////////////////////
00170   DemandStream& DemandManager::createDemandStream
00171   (stdair::EventQueue& ioEventQueue,
00172    const DemandStreamKey& iKey,
00173    const ArrivalPatternCumulativeDistribution_T& iArrivalPattern,
00174    const POSProbabilityMassFunction_T& iPOSProbMass,
00175    const ChannelProbabilityMassFunction_T& iChannelProbMass,
00176    const TripTypeProbabilityMassFunction_T& iTripTypeProbMass,
00177    const StayDurationProbabilityMassFunction_T& iStayDurationProbMass,
00178    const FrequentFlyerProbabilityMassFunction_T& iFrequentFlyerProbMass,
00179    const PreferredDepartureTimeContinuousDistribution_T& iPreferredDepartureTimeContinuousDistribution,
00180    const stdair::WTP_T& iMinWTP,
00181    const ValueOfTimeContinuousDistribution_T& iValueOfTimeContinuousDistribution,
00182    const DemandDistribution& iDemandDistribution,
00183    stdair::BaseGenerator_T&  ioSharedGenerator,
00184    const stdair::RandomSeed_T& iRequestDateTimeSeed,
00185    const stdair::RandomSeed_T& iDemandCharacteristicsSeed,
00186    const POSProbabilityMass_T& iDefaultPOSProbablityMass) {
00187     
00188     DemandStream& oDemandStream =
00189       stdair::FacBom<DemandStream>::instance().create (iKey);
00190 
00191     oDemandStream.setAll (iArrivalPattern, iPOSProbMass,
00192                           iChannelProbMass, iTripTypeProbMass,
00193                           iStayDurationProbMass, iFrequentFlyerProbMass,
00194                           iPreferredDepartureTimeContinuousDistribution,
00195                           iMinWTP, iValueOfTimeContinuousDistribution,
00196                           iDemandDistribution, ioSharedGenerator,
00197                           iRequestDateTimeSeed, iDemandCharacteristicsSeed,
00198                           iDefaultPOSProbablityMass);
00199 
00200     // Link the DemandStream to its parent (EventQueue)
00201     stdair::FacBomManager::linkWithParent (ioEventQueue, oDemandStream);
00202     
00203     // Add the DemandStream to the dedicated list and map
00204     stdair::FacBomManager::addToListAndMap (ioEventQueue, oDemandStream);
00205 
00206     return oDemandStream;
00207   }
00208     
00209   // //////////////////////////////////////////////////////////////////////
00210   void DemandManager::
00211   createDemandCharacteristics (stdair::EventQueue& ioEventQueue,
00212                                stdair::RandomGeneration& ioSharedGenerator,
00213                                const POSProbabilityMass_T& iPOSProbMass,
00214                                const DemandStruct& iDemand) {
00215     stdair::BaseGenerator_T& lSharedGenerator =
00216       ioSharedGenerator.getBaseGenerator();
00217     
00218     // Parse the date period and DoW and generate demand characteristics.
00219     const stdair::DatePeriod_T lDateRange = iDemand._dateRange;
00220     for (boost::gregorian::day_iterator itDate = lDateRange.begin();
00221          itDate != lDateRange.end(); ++itDate) {
00222       const stdair::Date_T& currentDate = *itDate;
00223 
00224       // Retrieve, for the current day, the Day-Of-the-Week (thanks to Boost)
00225       const unsigned short currentDoW = currentDate.day_of_week().as_number();
00226         
00227       // The demand structure stores which Days (-Of-the-Week) are
00228       // active within the week. For each day (Mon., Tue., etc.), a boolean
00229       // states whether the Flight is active for that day.
00230       const stdair::DoWStruct& lDoWList = iDemand._dow;
00231       const bool isDoWActive = lDoWList.getStandardDayOfWeek (currentDoW);
00232 
00233       if (isDoWActive == true) {
00234         const DemandStreamKey lDemandStreamKey (iDemand._origin,
00235                                                 iDemand._destination,
00236                                                 currentDate,
00237                                                 iDemand._prefCabin);
00238         // DEBUG
00239         // STDAIR_LOG_DEBUG ("Demand stream key: " << lDemandStreamKey.describe());
00240         
00241         //
00242         const DemandDistribution lDemandDistribution (iDemand._demandMean,
00243                                                       iDemand._demandStdDev);
00244         
00245         // Seed
00246         const stdair::RandomSeed_T& lRequestDateTimeSeed =
00247           generateSeed (ioSharedGenerator);
00248         const stdair::RandomSeed_T& lDemandCharacteristicsSeed =
00249           generateSeed (ioSharedGenerator);
00250         
00251         // Delegate the call to the dedicated command
00252         DemandStream& lDemandStream = 
00253           createDemandStream (ioEventQueue, lDemandStreamKey,
00254                               iDemand._dtdProbDist, iDemand._posProbDist,
00255                               iDemand._channelProbDist,
00256                               iDemand._tripProbDist,
00257                               iDemand._stayProbDist, iDemand._ffProbDist,
00258                               iDemand._prefDepTimeProbDist,
00259                               iDemand._minWTP,
00260                               iDemand._timeValueProbDist,
00261                               lDemandDistribution, lSharedGenerator,
00262                               lRequestDateTimeSeed,
00263                               lDemandCharacteristicsSeed,
00264                               iPOSProbMass);
00265         
00266         // Calculate the expected total number of events for the current
00267         // demand stream
00268         const stdair::NbOfRequests_T& lExpectedTotalNbOfEvents =
00269           lDemandStream.getMeanNumberOfRequests();
00270         
00275         ioEventQueue.addStatus (stdair::EventType::BKG_REQ,
00276                                 lExpectedTotalNbOfEvents);
00277       }
00278     }
00279   }
00280 
00281   // ////////////////////////////////////////////////////////////////////
00282   stdair::RandomSeed_T DemandManager::
00283   generateSeed (stdair::RandomGeneration& ioSharedGenerator) {
00284     stdair::RealNumber_T lVariateUnif = ioSharedGenerator() * 1e9;
00285     stdair::RandomSeed_T oSeed = static_cast<stdair::RandomSeed_T>(lVariateUnif);
00286     return oSeed;
00287   }
00288   
00289   // ////////////////////////////////////////////////////////////////////
00290   const bool DemandManager::
00291   stillHavingRequestsToBeGenerated (const stdair::EventQueue& iEventQueue,
00292                                     const stdair::DemandStreamKeyStr_T& iKey,
00293                                     stdair::ProgressStatusSet& ioPSS,
00294                                     const stdair::DemandGenerationMethod& iDemandGenerationMethod) {
00295     // Retrieve the DemandStream which corresponds to the given key.
00296     const DemandStream& lDemandStream =
00297       stdair::BomManager::getObject<DemandStream> (iEventQueue, iKey);
00298 
00299     // Retrieve the progress status of the demand stream.
00300     stdair::ProgressStatus
00301       lProgressStatus (lDemandStream.getNumberOfRequestsGeneratedSoFar(),
00302                        lDemandStream.getMeanNumberOfRequests(),
00303                        lDemandStream.getTotalNumberOfRequestsToBeGenerated());
00304     ioPSS.setSpecificGeneratorStatus (lProgressStatus, iKey);
00305     
00306     return lDemandStream.stillHavingRequestsToBeGenerated (iDemandGenerationMethod);
00307   }
00308 
00309   // ////////////////////////////////////////////////////////////////////
00310   stdair::BookingRequestPtr_T DemandManager::
00311   generateNextRequest (stdair::EventQueue& ioEventQueue,
00312                        stdair::RandomGeneration& ioGenerator,
00313                        const stdair::DemandStreamKeyStr_T& iKey,
00314                        const stdair::DemandGenerationMethod& iDemandGenerationMethod) {
00315 
00316     // Retrieve the DemandStream which corresponds to the given key.
00317     DemandStream& lDemandStream = 
00318       stdair::BomManager::getObject<DemandStream> (ioEventQueue, iKey);
00319 
00320     // Generate the next booking request
00321     stdair::BookingRequestPtr_T lBookingRequest =
00322       lDemandStream.generateNextRequest (ioGenerator,
00323                                          iDemandGenerationMethod);
00324 
00325     // Create an event structure
00326     stdair::EventStruct lEventStruct (stdair::EventType::BKG_REQ,
00327                                       lBookingRequest);
00328 
00336     ioEventQueue.addEvent (lEventStruct);
00337     
00338     return lBookingRequest;
00339   }
00340 
00341   // ////////////////////////////////////////////////////////////////////
00342   stdair::Count_T DemandManager::
00343   generateFirstRequests (stdair::EventQueue& ioEventQueue,
00344                          stdair::RandomGeneration& ioGenerator,
00345                          const stdair::DemandGenerationMethod& iDemandGenerationMethod) {
00346 
00347     // Actual total number of events to be generated
00348     stdair::NbOfRequests_T lActualTotalNbOfEvents = 0.0;
00349 
00350     // Retrieve the DemandStream list
00351     const DemandStreamList_T& lDemandStreamList =
00352       stdair::BomManager::getList<DemandStream> (ioEventQueue);
00353 
00354     for (DemandStreamList_T::const_iterator itDemandStream =
00355            lDemandStreamList.begin();
00356          itDemandStream != lDemandStreamList.end(); ++itDemandStream) {
00357       DemandStream* lDemandStream_ptr = *itDemandStream;
00358       assert (lDemandStream_ptr != NULL);
00359 
00360       lDemandStream_ptr->setBoolFirstDateTimeRequest(true);
00361 
00362       // Calculate the expected total number of events for the current
00363       // demand stream
00364       const stdair::NbOfRequests_T& lActualNbOfEvents =
00365         lDemandStream_ptr->getTotalNumberOfRequestsToBeGenerated();
00366       lActualTotalNbOfEvents += lActualNbOfEvents;
00367 
00368       // Retrieve the key of the demand stream
00369       const DemandStreamKey& lKey = lDemandStream_ptr->getKey();
00370 
00371       // Update the progress status for the given event type (i.e.,
00372       // booking request)
00373       ioEventQueue.updateStatus (stdair::EventType::BKG_REQ, lActualNbOfEvents);
00374 
00375       // Check whether there are still booking requests to be generated
00376       const bool stillHavingRequestsToBeGenerated =
00377         lDemandStream_ptr->stillHavingRequestsToBeGenerated (iDemandGenerationMethod);
00378    
00379       if (stillHavingRequestsToBeGenerated) {
00380         // Generate the next event (booking request), and insert it
00381         // into the event queue
00382         generateNextRequest (ioEventQueue, ioGenerator, lKey.toString(),
00383                              iDemandGenerationMethod);
00384       }
00385     }
00386 
00387     // Update the actual total number of events to be generated
00388     ioEventQueue.setActualTotalNbOfEvents (lActualTotalNbOfEvents);
00389 
00390     // Retrieve the actual total number of events to be generated
00391     const stdair::Count_T oTotalNbOfEvents = std::floor (lActualTotalNbOfEvents);
00392 
00393     //
00394     return oTotalNbOfEvents;
00395   }
00396   
00397   // ////////////////////////////////////////////////////////////////////
00398   void DemandManager::reset (stdair::EventQueue& ioEventQueue,
00399                              stdair::BaseGenerator_T& ioShareGenerator) {
00400 
00401     // TODO: check whether it is really necessary to destroy the
00402     // objects manually. Indeed, FacSupervisor::cleanAll() should
00403     // destroy any BOM object.
00404 
00405     // Reset all the DemandStream objects
00406     const DemandStreamList_T& lDemandStreamList =
00407       stdair::BomManager::getList<DemandStream> (ioEventQueue);
00408     for (DemandStreamList_T::const_iterator itDS = lDemandStreamList.begin();
00409          itDS != lDemandStreamList.end(); ++itDS) {
00410       DemandStream* lCurrentDS_ptr = *itDS;
00411       assert (lCurrentDS_ptr != NULL);
00412       
00413       lCurrentDS_ptr->reset (ioShareGenerator);
00414     }
00415     
00423     ioEventQueue.reset();
00424   }
00425   
00426 
00427   // ////////////////////////////////////////////////////////////////////
00428   bool DemandManager::
00429   generateCancellation (stdair::EventQueue& ioEventQueue,
00430                         stdair::RandomGeneration& ioGenerator,
00431                         const stdair::TravelSolutionStruct& iTravelSolution,
00432                         const stdair::PartySize_T& iPartySize,
00433                         const stdair::DateTime_T& iRequestTime,
00434                         const stdair::Date_T& iDepartureDate) {
00435 
00436     // Draw a random number to decide if we generate a
00437     // cancellation. For instance, the probability will be hardcoded.
00438     // The cancellation time will be generated uniformly.
00439     double lRandomNumber = ioGenerator();
00440    
00441     if (lRandomNumber >= 0.5) {
00442       return false;
00443     }
00444     lRandomNumber /= 0.5;
00445 
00446     // Hardcode the latest cancellation time.
00447     const stdair::Time_T lMidNight =
00448       boost::posix_time::hours (0);
00449     const stdair::DateTime_T lDepartureDateTime =
00450       boost::posix_time::ptime (iDepartureDate, lMidNight);
00451 
00452     // Time to departure.
00453     const stdair::Duration_T lTimeToDeparture = lDepartureDateTime-iRequestTime;
00454 
00455     // Cancellation time to departure
00456     const long lTimeToDepartureInSeconds = lTimeToDeparture.total_seconds();
00457     const long lCancellationTimeToDepartureInSeconds =
00458       static_cast<long> (lTimeToDepartureInSeconds * lRandomNumber);
00459     const stdair::Duration_T lCancellationTimeToDeparture (0, 0, lCancellationTimeToDepartureInSeconds);
00460     
00461     // Cancellation time
00462     const stdair::DateTime_T lCancellationTime =
00463       lDepartureDateTime - lCancellationTimeToDeparture;
00464 
00465     // Retrieve the segment path
00466     const stdair::SegmentPath_T lSegmentPath = iTravelSolution.getSegmentPath();
00467     
00468     // Hardcoded class path
00469     const stdair::FareOptionStruct& lChosenFareOption =
00470       iTravelSolution.getChosenFareOption ();
00471     const stdair::ClassList_StringList_T& lClassPath =
00472       lChosenFareOption.getClassPath();
00473     std::ostringstream oStr;
00474     for (stdair::ClassList_StringList_T::const_iterator itClassList =
00475            lClassPath.begin(); itClassList != lClassPath.end(); ++itClassList) {
00476       const stdair::ClassList_String_T& lClassList = *itClassList;
00477       assert (lClassList.size() > 0);
00478       oStr << lClassList.at(0); 
00479     }
00480     const stdair::ClassList_String_T lClassList_String = oStr.str();
00481 
00482     // Create the cancellation.
00483     stdair::CancellationPtr_T lCancellation_ptr =
00484       stdair::CancellationPtr_T
00485       (new stdair::CancellationStruct (lSegmentPath, lClassList_String,
00486                                        iPartySize, lCancellationTime));
00487 
00488     // Create an event structure
00489     stdair::EventStruct lEventStruct (stdair::EventType::CX, lCancellation_ptr);
00490     
00498     ioEventQueue.addEvent (lEventStruct);
00499     
00500     return true;
00501   }
00502   
00503   // //////////////////////////////////////////////////////////////////////
00504   void DemandManager::
00505   buildSampleBom (stdair::EventQueue& ioEventQueue,
00506                   stdair::RandomGeneration& ioSharedGenerator,
00507                   const POSProbabilityMass_T& iPOSProbMass) {
00508 
00509     //
00510     ArrivalPatternCumulativeDistribution_T lDTDProbDist;
00511     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-330,
00512                                                                            0));
00513     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-150,
00514                                                                            0.1));
00515     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-92,
00516                                                                            0.2));
00517     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-55,
00518                                                                            0.3));
00519     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-34,
00520                                                                            0.4));
00521     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-21,
00522                                                                            0.5));
00523     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-12,
00524                                                                            0.6));
00525     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-6,
00526                                                                            0.7));
00527     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-3,
00528                                                                            0.8));
00529     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(-1,
00530                                                                            0.9));
00531     lDTDProbDist.insert(ArrivalPatternCumulativeDistribution_T::value_type(0,
00532                                                                            1.0));
00533 
00534     //
00535     ChannelProbabilityMassFunction_T lChannelProbDist;
00536     lChannelProbDist.insert (ChannelProbabilityMassFunction_T::value_type ("DF",
00537                                                                            0.0));
00538     lChannelProbDist.insert (ChannelProbabilityMassFunction_T::value_type ("DN",
00539                                                                            0.0));
00540     lChannelProbDist.insert (ChannelProbabilityMassFunction_T::value_type ("IF",
00541                                                                            0.0));
00542     lChannelProbDist.insert (ChannelProbabilityMassFunction_T::value_type ("IN",
00543                                                                            1.0));
00544 
00545     //
00546     TripTypeProbabilityMassFunction_T lTripProbDist;
00547     lTripProbDist.insert (TripTypeProbabilityMassFunction_T::value_type ("RO",
00548                                                                          0.0));
00549     lTripProbDist.insert (TripTypeProbabilityMassFunction_T::value_type ("RI",
00550                                                                          0.0));
00551     lTripProbDist.insert (TripTypeProbabilityMassFunction_T::value_type ("OW",
00552                                                                          1.0));
00553 
00554     //
00555     StayDurationProbabilityMassFunction_T lStayProbDist;
00556     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(0,
00557                                                                            0.1));
00558     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(1,
00559                                                                            0.1));
00560     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(2,
00561                                                                            .15));
00562     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(3,
00563                                                                            .15));
00564     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(4,
00565                                                                            .15));
00566     lStayProbDist.insert(StayDurationProbabilityMassFunction_T::value_type(5,
00567                                                                            .35));
00568 
00569     //
00570     FrequentFlyerProbabilityMassFunction_T lFFProbDist;
00571     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("P",
00572                                                                           0.1));
00573     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("G",
00574                                                                           0.01));
00575     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("S",
00576                                                                           0.09));
00577     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("M",
00578                                                                           0.4));
00579     lFFProbDist.insert(FrequentFlyerProbabilityMassFunction_T::value_type("N",
00580                                                                           0.4));
00581 
00582     //
00583     ValueOfTimeContinuousDistribution_T lTimeValueProbDist;
00584     lTimeValueProbDist.insert(ValueOfTimeContinuousDistribution_T::value_type(15,
00585                                                                               0));
00586     lTimeValueProbDist.insert(ValueOfTimeContinuousDistribution_T::value_type(60,
00587                                                                               1));
00588 
00589     /*===================================================================================*/
00590 
00591     // Key of the demand stream
00592     const stdair::AirportCode_T lSINOrigin ("SIN");
00593     const stdair::AirportCode_T lBKKDestination ("BKK");
00594     const stdair::Date_T lDepDate (2010, 2, 8);
00595     const stdair::CabinCode_T lCabin ("Y");
00596 
00597     //
00598     const DemandStreamKey lSINBKKDemandStreamKey (lSINOrigin, lBKKDestination, lDepDate,
00599                                                   lCabin);
00600 
00601     // DEBUG
00602     // STDAIR_LOG_DEBUG ("Demand stream key: " << lDemandStreamKey.describe());
00603     
00604     // Distribution for the number of requests
00605     const stdair::MeanValue_T lSINBKKDemandMean (60.0);
00606     const stdair::StdDevValue_T lSINBKKDemandStdDev (4.0);
00607     const DemandDistribution lSINBKKDemandDistribution (lSINBKKDemandMean, lSINBKKDemandStdDev);
00608     
00609     // Seed
00610     const stdair::RandomSeed_T& lSINBKKRequestDateTimeSeed =
00611       generateSeed (ioSharedGenerator);
00612     const stdair::RandomSeed_T& lSINBKKDemandCharacteristicsSeed =
00613       generateSeed (ioSharedGenerator);
00614 
00615     
00616     //
00617     POSProbabilityMassFunction_T lSINBKKPOSProbDist;    
00618     lSINBKKPOSProbDist.insert (POSProbabilityMassFunction_T::value_type ("SIN", 1.0));
00619     lSINBKKPOSProbDist.insert (POSProbabilityMassFunction_T::value_type ("BKK", 0.0)); 
00620         
00621     //
00622     PreferredDepartureTimeContinuousDistribution_T lSINPrefDepTimeProbDist;
00623     lSINPrefDepTimeProbDist.
00624       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (6, 0));
00625     lSINPrefDepTimeProbDist.
00626       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (8,
00627                                                                           0.7));
00628     lSINPrefDepTimeProbDist.
00629       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (10,
00630                                                                           0.8));
00631     lSINPrefDepTimeProbDist.
00632       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (12,
00633                                                                           0.9));
00634     lSINPrefDepTimeProbDist.
00635       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (14,
00636                                                                           1.0));    
00637 
00638     //
00639     const stdair::WTP_T lSINBKKWTP (400.0);
00640 
00641 
00642     // Delegate the call to the dedicated command
00643     DemandStream& lSINBKKDemandStream = 
00644       createDemandStream (ioEventQueue, lSINBKKDemandStreamKey, lDTDProbDist,
00645                           lSINBKKPOSProbDist, lChannelProbDist, lTripProbDist,
00646                           lStayProbDist, lFFProbDist, lSINPrefDepTimeProbDist,
00647                           lSINBKKWTP, lTimeValueProbDist, lSINBKKDemandDistribution,
00648                           ioSharedGenerator.getBaseGenerator(),
00649                           lSINBKKRequestDateTimeSeed,
00650                           lSINBKKDemandCharacteristicsSeed, iPOSProbMass);
00651 
00652     // Calculate the expected total number of events for the current
00653     // demand stream
00654     const stdair::NbOfRequests_T& lSINBKKExpectedNbOfEvents =
00655       lSINBKKDemandStream.getMeanNumberOfRequests();
00656 
00657     /*===================================================================================*/
00658 
00659     // Key of the demand stream
00660     const stdair::AirportCode_T lBKKOrigin ("BKK");
00661     const stdair::AirportCode_T lHKGDestination ("HKG");
00662 
00663     //
00664     const DemandStreamKey lBKKHKGDemandStreamKey (lBKKOrigin, lHKGDestination, lDepDate,
00665                                                   lCabin);
00666 
00667     // DEBUG
00668     // STDAIR_LOG_DEBUG ("Demand stream key: " << lDemandStreamKey.describe());
00669     
00670     // Distribution for the number of requests
00671     const stdair::MeanValue_T lBKKHKGDemandMean (60.0);
00672     const stdair::StdDevValue_T lBKKHKGDemandStdDev (4.0);
00673     const DemandDistribution lBKKHKGDemandDistribution (lBKKHKGDemandMean, lBKKHKGDemandStdDev);
00674     
00675     // Seed
00676     const stdair::RandomSeed_T& lBKKHKGRequestDateTimeSeed =
00677       generateSeed (ioSharedGenerator);
00678     const stdair::RandomSeed_T& lBKKHKGDemandCharacteristicsSeed =
00679       generateSeed (ioSharedGenerator);
00680 
00681     
00682     //
00683     POSProbabilityMassFunction_T lBKKHKGPOSProbDist;    
00684     lBKKHKGPOSProbDist.insert (POSProbabilityMassFunction_T::value_type ("BKK", 1.0));
00685     lBKKHKGPOSProbDist.insert (POSProbabilityMassFunction_T::value_type ("HKG", 0.0)); 
00686         
00687     //
00688     PreferredDepartureTimeContinuousDistribution_T lBKKPrefDepTimeProbDist;
00689     lBKKPrefDepTimeProbDist.
00690       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (8, 0));
00691     lBKKPrefDepTimeProbDist.
00692       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (10,
00693                                                                           0.2));
00694     lBKKPrefDepTimeProbDist.
00695       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (1,
00696                                                                           0.6));
00697     lBKKPrefDepTimeProbDist.
00698       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (14,
00699                                                                           0.8));
00700     lBKKPrefDepTimeProbDist.
00701       insert (PreferredDepartureTimeContinuousDistribution_T::value_type (16,
00702                                                                           1.0));    
00703 
00704     //
00705     const stdair::WTP_T lBKKHKGWTP (400.0);
00706 
00707 
00708     // Delegate the call to the dedicated command
00709     DemandStream& lBKKHKGDemandStream = 
00710       createDemandStream (ioEventQueue, lBKKHKGDemandStreamKey, lDTDProbDist,
00711                           lBKKHKGPOSProbDist, lChannelProbDist, lTripProbDist,
00712                           lStayProbDist, lFFProbDist, lBKKPrefDepTimeProbDist,
00713                           lBKKHKGWTP, lTimeValueProbDist, lBKKHKGDemandDistribution,
00714                           ioSharedGenerator.getBaseGenerator(),
00715                           lBKKHKGRequestDateTimeSeed,
00716                           lBKKHKGDemandCharacteristicsSeed, iPOSProbMass);
00717 
00718     // Calculate the expected total number of events for the current
00719     // demand stream
00720     const stdair::NbOfRequests_T& lBKKHKGExpectedNbOfEvents =
00721       lBKKHKGDemandStream.getMeanNumberOfRequests();
00722 
00723     /*===================================================================================*/
00724 
00725     // Key of the demand stream
00726 
00727     //
00728     const DemandStreamKey lSINHKGDemandStreamKey (lSINOrigin, lHKGDestination, lDepDate,
00729                                                   lCabin);
00730 
00731     // DEBUG
00732     // STDAIR_LOG_DEBUG ("Demand stream key: " << lDemandStreamKey.describe());
00733     
00734     // Distribution for the number of requests
00735     const stdair::MeanValue_T lSINHKGDemandMean (60.0);
00736     const stdair::StdDevValue_T lSINHKGDemandStdDev (4.0);
00737     const DemandDistribution lSINHKGDemandDistribution (lSINHKGDemandMean, lSINHKGDemandStdDev);
00738     
00739     // Seed
00740     const stdair::RandomSeed_T& lSINHKGRequestDateTimeSeed =
00741       generateSeed (ioSharedGenerator);
00742     const stdair::RandomSeed_T& lSINHKGDemandCharacteristicsSeed =
00743       generateSeed (ioSharedGenerator);
00744 
00745     
00746     //
00747     POSProbabilityMassFunction_T lSINHKGPOSProbDist;    
00748     lSINHKGPOSProbDist.insert (POSProbabilityMassFunction_T::value_type ("SIN", 1.0));
00749     lSINHKGPOSProbDist.insert (POSProbabilityMassFunction_T::value_type ("HKG", 0.0)); 
00750         
00751     //
00752     const stdair::WTP_T lSINHKGWTP (750.0);
00753 
00754 
00755     // Delegate the call to the dedicated command
00756     DemandStream& lSINHKGDemandStream = 
00757       createDemandStream (ioEventQueue, lSINHKGDemandStreamKey, lDTDProbDist,
00758                           lSINHKGPOSProbDist, lChannelProbDist, lTripProbDist,
00759                           lStayProbDist, lFFProbDist, lSINPrefDepTimeProbDist,
00760                           lSINHKGWTP, lTimeValueProbDist, lSINHKGDemandDistribution,
00761                           ioSharedGenerator.getBaseGenerator(),
00762                           lSINHKGRequestDateTimeSeed,
00763                           lSINHKGDemandCharacteristicsSeed, iPOSProbMass);
00764 
00765     // Calculate the expected total number of events for the current
00766     // demand stream
00767     const stdair::NbOfRequests_T& lSINHKGExpectedNbOfEvents =
00768       lSINHKGDemandStream.getMeanNumberOfRequests();
00769 
00770     /*===================================================================================*/
00771 
00775     const stdair::NbOfRequests_T lExpectedTotalNbOfEvents =
00776       lSINBKKExpectedNbOfEvents + lBKKHKGExpectedNbOfEvents + lSINHKGExpectedNbOfEvents;
00777     ioEventQueue.addStatus (stdair::EventType::BKG_REQ,
00778                             lExpectedTotalNbOfEvents);
00779   }
00780 
00781 }