10 #include <boost/make_shared.hpp>
12 #include <stdair/basic/BasConst_General.hpp>
13 #include <stdair/basic/BasConst_Inventory.hpp>
14 #include <stdair/basic/BasConst_Request.hpp>
15 #include <stdair/bom/BookingRequestStruct.hpp>
16 #include <stdair/service/Logger.hpp>
24 DemandStream::DemandStream()
25 : _key (stdair::DEFAULT_ORIGIN, stdair::DEFAULT_DESTINATION,
26 stdair::DEFAULT_DEPARTURE_DATE, stdair::DEFAULT_CABIN_CODE),
39 _firstDateTimeRequest (true) {
44 DemandStream::DemandStream (
const DemandStream&)
45 : _key (stdair::DEFAULT_ORIGIN, stdair::DEFAULT_DESTINATION,
46 stdair::DEFAULT_DEPARTURE_DATE, stdair::DEFAULT_CABIN_CODE),
59 _firstDateTimeRequest (true) {
64 DemandStream::DemandStream (
const Key_T& iKey) :
74 std::ostringstream oStr;
87 const stdair::ChangeFeesRatio_T& iChangeFeeProb,
88 const stdair::Disutility_T& iChangeFeeDisutility,
89 const stdair::NonRefundableRatio_T& iNonRefundableProb,
90 const stdair::Disutility_T& iNonRefundableDisutility,
92 const stdair::WTP_T& iMinWTP,
95 stdair::BaseGenerator_T& ioSharedGenerator,
96 const stdair::RandomSeed_T& iRequestDateTimeSeed,
97 const stdair::RandomSeed_T& iDemandCharacteristicsSeed,
101 iChannelProbMass, iTripTypeProbMass,
102 iStayDurationProbMass, iFrequentFlyerProbMass,
103 iChangeFeeProb, iChangeFeeDisutility,
104 iNonRefundableProb, iNonRefundableDisutility,
105 iPreferredDepartureTimeContinuousDistribution,
106 iMinWTP, iValueOfTimeContinuousDistribution);
115 init (ioSharedGenerator);
120 std::ostringstream oStr;
122 oStr <<
"Demand stream key: " <<
_key.
toString() << std::endl;
137 oStr <<
"Random generator for date-time: "
139 oStr <<
"Random generator for demand characteristics: "
149 void DemandStream::init (stdair::BaseGenerator_T& ioSharedGenerator) {
153 const stdair::RealNumber_T lSigma =
156 stdair::NormalDistribution_T lDistrib (lMu, lSigma);
157 stdair::NormalGenerator_T lNormalGen (ioSharedGenerator, lDistrib);
159 const stdair::RealNumber_T lRealNumberOfRequestsToBeGenerated =lNormalGen();
161 const stdair::NbOfRequests_T lIntegerNumberOfRequestsToBeGenerated =
162 std::floor (lRealNumberOfRequestsToBeGenerated + 0.5);
166 _stillHavingRequestsToBeGenerated =
true;
167 _firstDateTimeRequest =
true;
174 const stdair::DemandGenerationMethod::EN_DemandGenerationMethod& lENDemandGenerationMethod =
175 iDemandGenerationMethod.getMethod();
176 if (lENDemandGenerationMethod == stdair::DemandGenerationMethod::STA_ORD) {
177 bool hasStillHavingRequestsToBeGenerated =
true;
180 const stdair::Count_T lNbOfRequestsGeneratedSoFar =
183 const stdair::Count_T lRemainingNumberOfRequestsToBeGenerated =
186 if (lRemainingNumberOfRequestsToBeGenerated <= 0) {
187 hasStillHavingRequestsToBeGenerated =
false;
190 return hasStillHavingRequestsToBeGenerated;
192 return _stillHavingRequestsToBeGenerated;
203 const stdair::Time_T lHardcodedReferenceDepartureTime =
204 boost::posix_time::hours (8);
207 const stdair::DateTime_T lDepartureDateTime =
209 lHardcodedReferenceDepartureTime);
212 if (_firstDateTimeRequest) {
213 const stdair::Probability_T lProbabilityFirstRequest = 0;
217 _dateTimeLastRequest =
218 lArrivalPattern.
getValue (lProbabilityFirstRequest);
220 _firstDateTimeRequest =
false;
224 assert (_firstDateTimeRequest ==
false);
231 _stillHavingRequestsToBeGenerated =
false;
234 const stdair::Duration_T lDifferenceBetweenDepartureAndThisLowerBound =
239 const stdair::DateTime_T oDateTimeThisRequest =
240 lDepartureDateTime + lDifferenceBetweenDepartureAndThisLowerBound;
242 return oDateTimeThisRequest;
246 stdair::FloatDuration_T lUpperBound =
254 lDailyRate *= lDemandMean;
257 const stdair::FloatDuration_T lExponentialVariable =
261 const stdair::FloatDuration_T lDateTimeThisRequest =
262 _dateTimeLastRequest + lExponentialVariable;
264 stdair::DateTime_T oDateTimeThisRequest;
267 if (lDateTimeThisRequest < lUpperBound) {
270 const stdair::Duration_T lDifferenceBetweenDepartureAndThisRequest =
274 oDateTimeThisRequest = lDepartureDateTime
275 + lDifferenceBetweenDepartureAndThisRequest;
278 _dateTimeLastRequest = lDateTimeThisRequest;
283 const double lRefDateTimeThisRequest = lDateTimeThisRequest + double(28800.001/86400.0);
284 STDAIR_LOG_NOTIFICATION (boost::gregorian::to_iso_string(
_key.
getPreferredDepartureDate()) <<
";" << std::setprecision(10) << lRefDateTimeThisRequest);
289 _dateTimeLastRequest = lUpperBound;
295 return oDateTimeThisRequest;
323 const stdair::Count_T& lNbOfRequestsGeneratedSoFar =
328 const stdair::Count_T lRemainingNumberOfRequestsToBeGenerated =
332 assert (lRemainingNumberOfRequestsToBeGenerated > 0);
336 const double lRemainingRate =
337 1.0 /
static_cast<double> (lRemainingNumberOfRequestsToBeGenerated);
341 const stdair::Probability_T& lCumulativeProbabilitySoFar =
343 const stdair::Probability_T lComplementOfCumulativeProbabilitySoFar =
344 1.0 - lCumulativeProbabilitySoFar;
349 double lFactor = std::pow (1.0 - lVariate, lRemainingRate);
350 if (lFactor >= 1.0 - 1e-6){
351 lFactor = 1.0 - 1e-6;
357 const stdair::Probability_T lCumulativeProbabilityThisRequest =
358 1.0 - lComplementOfCumulativeProbabilitySoFar * lFactor;
363 const stdair::FloatDuration_T lNumberOfDaysBetweenDepartureAndThisRequest =
366 const stdair::Duration_T lDifferenceBetweenDepartureAndThisRequest =
369 const stdair::Time_T lHardcodedReferenceDepartureTime =
370 boost::posix_time::hours (8);
372 const stdair::DateTime_T lDepartureDateTime =
374 lHardcodedReferenceDepartureTime);
377 const stdair::DateTime_T oDateTimeThisRequest =
378 lDepartureDateTime + lDifferenceBetweenDepartureAndThisRequest;
391 double lRefNumberOfDaysBetweenDepartureAndThisRequest =
392 lNumberOfDaysBetweenDepartureAndThisRequest + double(1.0/3.0);
393 STDAIR_LOG_NOTIFICATION (boost::gregorian::to_iso_string(
_key.
getPreferredDepartureDate()) <<
";" << std::setprecision(10) << lRefNumberOfDaysBetweenDepartureAndThisRequest);
395 return oDateTimeThisRequest;
404 const stdair::FloatDuration_T lNumberOfSeconds =
405 iNumberOfDays * stdair::SECONDS_IN_ONE_DAY;
408 const stdair::IntDuration_T lIntNumberOfSeconds =
409 std::floor (lNumberOfSeconds);
412 const stdair::FloatDuration_T lNumberOfMilliseconds =
413 (lNumberOfSeconds - lIntNumberOfSeconds)
414 * stdair::MILLISECONDS_IN_ONE_SECOND;
418 const stdair::IntDuration_T lIntNumberOfMilliseconds =
419 std::floor (lNumberOfMilliseconds) + 1;
422 const stdair::Duration_T lDifferenceBetweenDepartureAndThisRequest =
423 boost::posix_time::seconds (lIntNumberOfSeconds)
424 + boost::posix_time::millisec (lIntNumberOfMilliseconds);
426 return lDifferenceBetweenDepartureAndThisRequest;
442 const stdair::Probability_T lVariate =
451 const stdair::Probability_T lVariate =
460 const stdair::Probability_T lVariate =
469 const stdair::Probability_T lVariate =
478 const stdair::Probability_T lVariate =
489 const stdair::Probability_T lVariate =
500 const stdair::Probability_T lVariate =
503 _preferredDepartureTimeCumulativeDistribution.getValue (lVariate);
505 const stdair::Duration_T oTime = boost::posix_time::seconds (lNbOfSeconds);
513 const stdair::Date_T& iDepartureDate,
514 const stdair::DateTime_T& iDateTimeThisRequest,
515 const stdair::DayDuration_T& iDurationOfStay) {
516 const stdair::Date_T lDateThisRequest = iDateTimeThisRequest.date();
517 const stdair::DateOffset_T lAP = iDepartureDate - lDateThisRequest;
518 const stdair::DayDuration_T lAPInDays = lAP.days();
520 stdair::RealNumber_T lProb = -lAPInDays;
521 stdair::RealNumber_T lFrat5Coef =
525 * (1.0 + (lFrat5Coef - 1.0) * log(ioGenerator()) / log(0.5));
533 const stdair::Probability_T lVariate =
542 const stdair::DemandGenerationMethod& iDemandGenerationMethod) {
549 const stdair::Date_T& lPreferredDepartureDate =
554 const stdair::NbOfSeats_T lPartySize = stdair::DEFAULT_PARTY_SIZE;
559 stdair::DateTime_T lDateTimeThisRequest;
560 const stdair::DemandGenerationMethod::EN_DemandGenerationMethod& lENDemandGenerationMethod =
561 iDemandGenerationMethod.getMethod();
562 switch(lENDemandGenerationMethod) {
563 case stdair::DemandGenerationMethod::POI_PRO:
565 case stdair::DemandGenerationMethod::STA_ORD:
567 default: assert (
false);
break;
581 const stdair::Disutility_T lChangeFeeDisutility =
586 const stdair::Disutility_T lNonRefundableDisutility =
589 const stdair::Duration_T lPreferredDepartureTime =
594 const stdair::WTP_T lWTP =
generateWTP (ioGenerator,lPreferredDepartureDate,
595 lDateTimeThisRequest,lStayDuration);
601 stdair::BookingRequestStruct lBookingRequestStruct (
describeKey(), lOrigin,
603 lPreferredDepartureDate,
604 lDateTimeThisRequest,
605 lPreferredCabin, lPartySize,
606 lChannelLabel, lTripType,
607 lStayDuration, lFrequentFlyer,
608 lPreferredDepartureTime,
609 lWTP, lValueOfTime, lChangeFees,
610 lChangeFeeDisutility, lNonRefundable,
611 lNonRefundableDisutility);
613 stdair::BookingRequestPtr_T oBookingRequest_ptr =
614 boost::make_shared<stdair::BookingRequestStruct> (lBookingRequestStruct);
619 return oBookingRequest_ptr;
625 init (ioSharedGenerator);