8 #include <boost/make_shared.hpp>
9 #if defined(SOCI_HEADERS_BURIED)
10 #include <soci/core/soci.h>
11 #else // SOCI_HEADERS_BURIED
12 #include <soci/soci.h>
13 #endif // SOCI_HEADERS_BURIED
15 #include <stdair/basic/BasChronometer.hpp>
16 #include <stdair/basic/BasConst_General.hpp>
17 #include <stdair/bom/BomRoot.hpp>
18 #include <stdair/bom/BookingRequestStruct.hpp>
19 #include <stdair/bom/AirlineStruct.hpp>
20 #include <stdair/bom/EventStruct.hpp>
21 #include <stdair/bom/EventQueue.hpp>
22 #include <stdair/command/DBManagerForAirlines.hpp>
23 #include <stdair/service/Logger.hpp>
24 #include <stdair/service/DBSessionManager.hpp>
25 #include <stdair/STDAIR_Service.hpp>
39 TRADEMGEN_Service::TRADEMGEN_Service() : _trademgenServiceContext (NULL) {
44 TRADEMGEN_Service::TRADEMGEN_Service (
const TRADEMGEN_Service& iService)
45 : _trademgenServiceContext (NULL) {
50 TRADEMGEN_Service::TRADEMGEN_Service (
const stdair::BasLogParams& iLogParams,
51 const stdair::RandomSeed_T& iRandomSeed)
52 : _trademgenServiceContext (NULL) {
55 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
56 initStdAirService (iLogParams);
59 initServiceContext (iRandomSeed);
63 const bool ownStdairService =
true;
64 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
67 initTrademgenService();
71 TRADEMGEN_Service::TRADEMGEN_Service (
const stdair::BasLogParams& iLogParams,
72 const stdair::BasDBParams& iDBParams,
73 const stdair::RandomSeed_T& iRandomSeed)
74 : _trademgenServiceContext (NULL) {
77 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
78 initStdAirService (iLogParams, iDBParams);
81 initServiceContext (iRandomSeed);
85 const bool ownStdairService =
true;
86 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
89 initTrademgenService();
94 TRADEMGEN_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
95 const stdair::RandomSeed_T& iRandomSeed)
96 : _trademgenServiceContext (NULL) {
99 initServiceContext (iRandomSeed);
103 const bool doesNotOwnStdairService =
false;
104 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
107 initTrademgenService();
117 void TRADEMGEN_Service::finalise() {
118 assert (_trademgenServiceContext != NULL);
120 _trademgenServiceContext->reset();
124 void TRADEMGEN_Service::
125 initServiceContext (
const stdair::RandomSeed_T& iRandomSeed) {
127 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
129 _trademgenServiceContext = &lTRADEMGEN_ServiceContext;
133 void TRADEMGEN_Service::
134 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
135 const bool iOwnStdairService) {
137 assert (_trademgenServiceContext != NULL);
138 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
139 *_trademgenServiceContext;
142 lTRADEMGEN_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
147 stdair::STDAIR_ServicePtr_T TRADEMGEN_Service::
148 initStdAirService (
const stdair::BasLogParams& iLogParams,
149 const stdair::BasDBParams& iDBParams) {
156 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
157 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
158 assert (lSTDAIR_Service_ptr != NULL);
160 return lSTDAIR_Service_ptr;
164 stdair::STDAIR_ServicePtr_T TRADEMGEN_Service::
165 initStdAirService (
const stdair::BasLogParams& iLogParams) {
172 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
173 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
174 assert (lSTDAIR_Service_ptr != NULL);
176 return lSTDAIR_Service_ptr;
180 void TRADEMGEN_Service::initTrademgenService() {
190 assert (_trademgenServiceContext != NULL);
192 *_trademgenServiceContext;
195 stdair::RandomGeneration& lSharedGenerator =
196 lTRADEMGEN_ServiceContext.getUniformGenerator();
200 lTRADEMGEN_ServiceContext.getPOSProbabilityMass();
203 stdair::STDAIR_Service& lSTDAIR_Service =
204 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
207 stdair::EventQueue& lEventQueue = lSTDAIR_Service.getEventQueue();
210 stdair::BasChronometer lDemandGeneration; lDemandGeneration.start();
212 lSharedGenerator, lDefaultPOSProbabilityMass);
213 const double lGenerationMeasure = lDemandGeneration.elapsed();
216 STDAIR_LOG_DEBUG (
"Demand generation time: " << lGenerationMeasure);
223 if (_trademgenServiceContext == NULL) {
224 throw stdair::NonInitialisedServiceException (
"The TraDemGen service has "
225 "not been initialised");
227 assert (_trademgenServiceContext != NULL);
232 *_trademgenServiceContext;
233 const bool doesOwnStdairService =
234 lTRADEMGEN_ServiceContext.getOwnStdairServiceFlag();
237 stdair::STDAIR_Service& lSTDAIR_Service =
238 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
244 if (doesOwnStdairService ==
true) {
246 lSTDAIR_Service.buildSampleBom();
262 stdair::RandomGeneration& lSharedGenerator =
263 lTRADEMGEN_ServiceContext.getUniformGenerator();
267 lTRADEMGEN_ServiceContext.getPOSProbabilityMass();
270 stdair::EventQueue& lEventQueue = lSTDAIR_Service.getEventQueue();
274 lDefaultPOSProbabilityMass);
282 if (_trademgenServiceContext == NULL) {
283 throw stdair::NonInitialisedServiceException (
"The TraDemGen service has "
284 "not been initialised");
286 assert (_trademgenServiceContext != NULL);
289 *_trademgenServiceContext;
292 stdair::STDAIR_Service& lSTDAIR_Service =
293 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
296 return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
303 if (_trademgenServiceContext == NULL) {
304 throw stdair::NonInitialisedServiceException (
"The TraDemGen service has "
305 "not been initialised");
307 assert (_trademgenServiceContext != NULL);
310 *_trademgenServiceContext;
313 stdair::STDAIR_Service& lSTDAIR_Service =
314 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
317 stdair::EventQueue& lEventQueue = lSTDAIR_Service.getEventQueue();
327 if (_trademgenServiceContext == NULL) {
328 throw stdair::NonInitialisedServiceException (
"The TraDemGen service has "
329 "not been initialised");
331 assert (_trademgenServiceContext != NULL);
336 boost::posix_time::ptime lNowDateTime =
337 boost::posix_time::second_clock::local_time();
341 STDAIR_LOG_DEBUG (std::endl
342 <<
"==================================================="
347 stdair::BasChronometer lAirListChronometer;
348 lAirListChronometer.start();
351 stdair::DBSession_T& lDBSession =
352 stdair::DBSessionManager::instance().getDBSession();
355 stdair::AirlineStruct lAirline;
356 stdair::DBRequestStatement_T lSelectStatement (lDBSession);
357 stdair::DBManagerForAirlines::prepareSelectStatement (lDBSession,
362 bool hasStillData =
true;
363 unsigned int idx = 0;
364 while (hasStillData ==
true) {
366 stdair::DBManagerForAirlines::iterateOnStatement (lSelectStatement,
370 STDAIR_LOG_DEBUG (
"[" << idx <<
"]: " << lAirline);
376 const double lAirListMeasure = lAirListChronometer.elapsed();
379 STDAIR_LOG_DEBUG (
"Sample service for airline list retrieval: "
388 assert (_trademgenServiceContext != NULL);
390 *_trademgenServiceContext;
393 stdair::STDAIR_Service& lSTDAIR_Service =
394 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
397 const stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
400 const stdair::Count_T& oExpectedTotalNumberOfRequestsToBeGenerated =
401 lQueue.getExpectedTotalNbOfEvents (stdair::EventType::BKG_REQ);
404 return oExpectedTotalNumberOfRequestsToBeGenerated;
412 assert (_trademgenServiceContext != NULL);
414 *_trademgenServiceContext;
417 stdair::STDAIR_Service& lSTDAIR_Service =
418 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
421 const stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
424 const stdair::Count_T& oActualTotalNumberOfRequestsToBeGenerated =
425 lQueue.getActualTotalNbOfEvents (stdair::EventType::BKG_REQ);
428 return oActualTotalNumberOfRequestsToBeGenerated;
434 stdair::ProgressStatusSet& ioPSS,
435 const stdair::DemandGenerationMethod& iDemandGenerationMethod)
const {
438 assert (_trademgenServiceContext != NULL);
440 *_trademgenServiceContext;
443 stdair::STDAIR_Service& lSTDAIR_Service =
444 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
447 const stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
450 const bool oStillHavingRequestsToBeGenerated =
452 iDemandGenerationMethod);
455 return oStillHavingRequestsToBeGenerated;
463 assert (_trademgenServiceContext != NULL);
465 *_trademgenServiceContext;
468 stdair::STDAIR_Service& lSTDAIR_Service =
469 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
472 stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
475 stdair::RandomGeneration& lGenerator =
476 lTRADEMGEN_ServiceContext.getUniformGenerator();
479 const stdair::Count_T& oActualTotalNbOfEvents =
481 iDemandGenerationMethod);
484 return oActualTotalNbOfEvents;
490 const stdair::DemandGenerationMethod& iDemandGenerationMethod)
const {
493 assert (_trademgenServiceContext != NULL);
495 *_trademgenServiceContext;
498 stdair::STDAIR_Service& lSTDAIR_Service =
499 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
502 stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
505 stdair::RandomGeneration& lGenerator =
506 lTRADEMGEN_ServiceContext.getUniformGenerator();
510 iDemandGenerationMethod);
515 popEvent (stdair::EventStruct& ioEventStruct)
const {
518 assert (_trademgenServiceContext != NULL);
520 *_trademgenServiceContext;
523 stdair::STDAIR_Service& lSTDAIR_Service =
524 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
527 stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
530 return lQueue.popEvent (ioEventStruct);
537 assert (_trademgenServiceContext != NULL);
539 *_trademgenServiceContext;
542 stdair::STDAIR_Service& lSTDAIR_Service =
543 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
546 const stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
558 const stdair::PartySize_T& iPartySize,
559 const stdair::DateTime_T& iRequestTime,
560 const stdair::Date_T& iDepartureDate)
const {
563 assert (_trademgenServiceContext != NULL);
565 *_trademgenServiceContext;
568 stdair::RandomGeneration& lGenerator =
569 lTRADEMGEN_ServiceContext.getUniformGenerator();
572 stdair::STDAIR_Service& lSTDAIR_Service =
573 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
576 stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
579 iTravelSolution, iPartySize,
580 iRequestTime, iDepartureDate);
587 assert (_trademgenServiceContext != NULL);
589 *_trademgenServiceContext;
592 stdair::STDAIR_Service& lSTDAIR_Service =
593 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
595 stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
598 stdair::RandomGeneration& lSharedGenerator =
599 lTRADEMGEN_ServiceContext.getUniformGenerator();