TraDemGen Logo  1.00.13
C++ Simulated Travel Demand Generation Library
Loading...
Searching...
No Matches
TRADEMGEN_Service.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6#include <sstream>
7// Boost
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
14// StdAir
15#include <stdair/basic/BasChronometer.hpp>
16#include <stdair/basic/BasConst_General.hpp>
17#include <stdair/basic/ProgressStatusSet.hpp>
18#include <stdair/bom/BomRoot.hpp>
19#include <stdair/bom/BookingRequestStruct.hpp>
20#include <stdair/bom/AirlineStruct.hpp>
21#include <stdair/bom/EventStruct.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>
26#include <stdair/factory/FacBomManager.hpp>
27// SEvMgr
28#include <sevmgr/SEVMGR_Service.hpp>
29// TraDemGen
39
40namespace TRADEMGEN {
41
42 // //////////////////////////////////////////////////////////////////////
43 TRADEMGEN_Service::TRADEMGEN_Service() : _trademgenServiceContext (NULL) {
44 assert (false);
45 }
46
47 // //////////////////////////////////////////////////////////////////////
48 TRADEMGEN_Service::TRADEMGEN_Service (const TRADEMGEN_Service& iService)
49 : _trademgenServiceContext (NULL) {
50 assert (false);
51 }
52
53 // //////////////////////////////////////////////////////////////////////
54 TRADEMGEN_Service::TRADEMGEN_Service (const stdair::BasLogParams& iLogParams,
55 const stdair::RandomSeed_T& iRandomSeed)
56 : _trademgenServiceContext (NULL) {
57
58 // Initialise the STDAIR service handler
59 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
60 initStdAirService (iLogParams);
61
62 // Initialise the service context
63 initServiceContext (iRandomSeed);
64
65 // Add the StdAir service context to the TRADEMGEN service context
66 // \note TRADEMGEN owns the STDAIR service resources here.
67 const bool ownStdairService = true;
68 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
69
70 // Initalise the SEvMgr service.
71 initSEVMGRService();
72
73 // Initialise the (remaining of the) context
74 initTrademgenService();
75 }
76
77 // //////////////////////////////////////////////////////////////////////
78 TRADEMGEN_Service::TRADEMGEN_Service (const stdair::BasLogParams& iLogParams,
79 const stdair::BasDBParams& iDBParams,
80 const stdair::RandomSeed_T& iRandomSeed)
81 : _trademgenServiceContext (NULL) {
82
83 // Initialise the STDAIR service handler
84 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
85 initStdAirService (iLogParams, iDBParams);
86
87 // Initialise the service context
88 initServiceContext (iRandomSeed);
89
90 // Add the StdAir service context to the TRADEMGEN service context
91 // \note TRADEMGEN owns the STDAIR service resources here.
92 const bool ownStdairService = true;
93 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
94
95 // Initalise the SEvMgr service.
96 initSEVMGRService();
97
98 // Initialise the (remaining of the) context
99 initTrademgenService();
100 }
101
102 // ////////////////////////////////////////////////////////////////////
103 TRADEMGEN_Service::
104 TRADEMGEN_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
105 SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr,
106 const stdair::RandomSeed_T& iRandomSeed)
107 : _trademgenServiceContext (NULL) {
108
109 // Initialise the service context
110 initServiceContext (iRandomSeed);
111
112 // Add the StdAir service context to the TRADEMGEN service context
113 // \note TraDemGen does not own the STDAIR service resources here.
114 const bool doesNotOwnStdairService = false;
115 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
116
117 //Add the SEvMgr service to the TRADEMGEN service context.
118 addSEVMGRService (ioSEVMGR_Service_ptr);
119
120 // Initialise the context
121 initTrademgenService();
122 }
123
124 // //////////////////////////////////////////////////////////////////////
126 // Delete/Clean all the objects from memory
127 finalise();
128 }
129
130 // ////////////////////////////////////////////////////////////////////
131 void TRADEMGEN_Service::finalise() {
132 assert (_trademgenServiceContext != NULL);
133 // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
134 _trademgenServiceContext->reset();
135 }
136
137 // //////////////////////////////////////////////////////////////////////
138 void TRADEMGEN_Service::
139 initServiceContext (const stdair::RandomSeed_T& iRandomSeed) {
140 // Initialise the service context
141 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
143 _trademgenServiceContext = &lTRADEMGEN_ServiceContext;
144 }
145
146 // ////////////////////////////////////////////////////////////////////
147 void TRADEMGEN_Service::
148 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
149 const bool iOwnStdairService) {
150 // Retrieve the TraDemGen service context
151 assert (_trademgenServiceContext != NULL);
152 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
153 *_trademgenServiceContext;
154
155 // Store the STDAIR service object within the (TRADEMGEN) service context
156 lTRADEMGEN_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
157 iOwnStdairService);
158 }
159
160 // ////////////////////////////////////////////////////////////////////
161 void TRADEMGEN_Service::
162 addSEVMGRService (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr) {
163
164 // Retrieve the TraDemGen service context
165 assert (_trademgenServiceContext != NULL);
166 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
167 *_trademgenServiceContext;
168
169 // Store the STDAIR service object within the (TRADEMGEN) service context
170 lTRADEMGEN_ServiceContext.setSEVMGR_Service (ioSEVMGR_Service_ptr);
171 }
172
173 // //////////////////////////////////////////////////////////////////////
174 stdair::STDAIR_ServicePtr_T TRADEMGEN_Service::
175 initStdAirService (const stdair::BasLogParams& iLogParams,
176 const stdair::BasDBParams& iDBParams) {
177
183 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
184 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
185 assert (lSTDAIR_Service_ptr != NULL);
186
187 return lSTDAIR_Service_ptr;
188 }
189
190 // //////////////////////////////////////////////////////////////////////
191 stdair::STDAIR_ServicePtr_T TRADEMGEN_Service::
192 initStdAirService (const stdair::BasLogParams& iLogParams) {
193
199 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
200 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
201 assert (lSTDAIR_Service_ptr != NULL);
202
203 return lSTDAIR_Service_ptr;
204 }
205
206 // ////////////////////////////////////////////////////////////////////
207 void TRADEMGEN_Service::initSEVMGRService() {
208
209 // Retrieve the TraDemGen service context
210 assert (_trademgenServiceContext != NULL);
211 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
212 *_trademgenServiceContext;
213
214 // Retrieve the StdAir service context
215 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
216 lTRADEMGEN_ServiceContext.getSTDAIR_ServicePtr();
217
225 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
226 boost::make_shared<SEVMGR::SEVMGR_Service> (lSTDAIR_Service_ptr);
227
228 // Store the SEvMgr service object within the (TraDemGen) service context
229 lTRADEMGEN_ServiceContext.setSEVMGR_Service (lSEVMGR_Service_ptr);
230 }
231
232
233 // //////////////////////////////////////////////////////////////////////
234 void TRADEMGEN_Service::initTrademgenService() {
235 // Do nothing at this stage. A sample BOM tree may be built by
236 // calling the buildSampleBom() method
237 }
238
239 // //////////////////////////////////////////////////////////////////////
241 parseAndLoad (const DemandFilePath& iDemandFilePath) {
242
243 // Retrieve the TraDemGen service context
244 if (_trademgenServiceContext == NULL) {
245 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
246 "not been initialised");
247 }
248 assert (_trademgenServiceContext != NULL);
249
250 // Retrieve the TraDemGen service context and whether it owns the Stdair
251 // service
252 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
253 *_trademgenServiceContext;
254 const bool doesOwnStdairService =
255 lTRADEMGEN_ServiceContext.getOwnStdairServiceFlag();
256
257 // Retrieve the StdAir service object from the (TRADEMGEN) service context
258 stdair::STDAIR_Service& lSTDAIR_Service =
259 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
260
261 // Retrieve the persistent BOM root object.
262 stdair::BomRoot& lPersistentBomRoot =
263 lSTDAIR_Service.getPersistentBomRoot();
264
265 // Retrieve the pointer on the SEvMgr service handler.
266 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
267 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
268
269 // Retrieve the shared generator
270 stdair::RandomGeneration& lSharedGenerator =
271 lTRADEMGEN_ServiceContext.getUniformGenerator();
272
273 // Retrieve the default POS distribution
274 const POSProbabilityMass_T& lDefaultPOSProbabilityMass =
275 lTRADEMGEN_ServiceContext.getPOSProbabilityMass();
276
280 stdair::BasChronometer lDemandGeneration; lDemandGeneration.start();
281 DemandParser::generateDemand (iDemandFilePath, lSEVMGR_Service_ptr,
282 lSharedGenerator, lDefaultPOSProbabilityMass);
283 const double lGenerationMeasure = lDemandGeneration.elapsed();
284
290
294 buildComplementaryLinks (lPersistentBomRoot);
295
296 // DEBUG
297 STDAIR_LOG_DEBUG ("Demand generation time: " << lGenerationMeasure);
298
303 if (doesOwnStdairService == true) {
304 //
306 }
307 }
308
309 // ////////////////////////////////////////////////////////////////////
311
312 // Retrieve the TraDemGen service context
313 if (_trademgenServiceContext == NULL) {
314 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
315 "not been initialised");
316 }
317 assert (_trademgenServiceContext != NULL);
318
319 // Retrieve the TraDemGen service context and whether it owns the Stdair
320 // service
321 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
322 *_trademgenServiceContext;
323 const bool doesOwnStdairService =
324 lTRADEMGEN_ServiceContext.getOwnStdairServiceFlag();
325
326 // Retrieve the StdAir service object from the (TraDemGen) service context
327 stdair::STDAIR_Service& lSTDAIR_Service =
328 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
329
330 // Retrieve the persistent BOM root object.
331 stdair::BomRoot& lPersistentBomRoot =
332 lSTDAIR_Service.getPersistentBomRoot();
333
338 if (doesOwnStdairService == true) {
339 //
340 lSTDAIR_Service.buildSampleBom();
341 }
342
348
353 // Retrieve the shared generator
354 stdair::RandomGeneration& lSharedGenerator =
355 lTRADEMGEN_ServiceContext.getUniformGenerator();
356
357 // Retrieve the default POS distribution
358 const POSProbabilityMass_T& lDefaultPOSProbabilityMass =
359 lTRADEMGEN_ServiceContext.getPOSProbabilityMass();
360
361 // Retrieve the pointer on the SEvMgr service handler.
362 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
363 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
364
365 // Delegate the BOM building to the dedicated service
366 DemandManager::buildSampleBom (lSEVMGR_Service_ptr, lSharedGenerator,
367 lDefaultPOSProbabilityMass);
368 // Build the complementary links
369 buildComplementaryLinks (lPersistentBomRoot);
370
375 if (doesOwnStdairService == true) {
376 //
378 }
379 }
380
381 // ////////////////////////////////////////////////////////////////////
383
384 // Retrieve the TraDemGen service context
385 if (_trademgenServiceContext == NULL) {
386 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
387 "not been initialised");
388 }
389 assert (_trademgenServiceContext != NULL);
390
391 // Retrieve the TraDemGen service context and whether it owns the Stdair
392 // service
393 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
394 *_trademgenServiceContext;
395 const bool doesOwnStdairService =
396 lTRADEMGEN_ServiceContext.getOwnStdairServiceFlag();
397
398 // Retrieve the StdAir service object from the (TraDemGen) service context
399 stdair::STDAIR_Service& lSTDAIR_Service =
400 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
401
406 if (doesOwnStdairService == true) {
407 //
408 lSTDAIR_Service.clonePersistentBom ();
409 }
410
414 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
415 buildComplementaryLinks (lBomRoot);
416 }
417
418 // ////////////////////////////////////////////////////////////////////
419 void TRADEMGEN_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
420 // Currently, no more things to do by TRADEMGEN at that stage.
421 }
422
423 // //////////////////////////////////////////////////////////////////////
424 stdair::BookingRequestStruct TRADEMGEN_Service::
425 buildSampleBookingRequest (const bool isForCRS) {
426
427 // Retrieve the TraDemGen service context
428 if (_trademgenServiceContext == NULL) {
429 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
430 "not been initialised");
431 }
432 assert (_trademgenServiceContext != NULL);
433
434 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
435 *_trademgenServiceContext;
436
437 // Retrieve the STDAIR service object from the (TraDemGen) service context
438 stdair::STDAIR_Service& lSTDAIR_Service =
439 lTRADEMGEN_ServiceContext.getSTDAIR_Service();
440
441 // Delegate the BOM building to the dedicated service
442 return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
443 }
444
445 // ////////////////////////////////////////////////////////////////////
447 jsonHandler (const stdair::JSONString& iJSONString) const {
448
449 // Retrieve the TraDemGen service context
450 if (_trademgenServiceContext == NULL) {
451 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
452 "not been initialised");
453 }
454 assert (_trademgenServiceContext != NULL);
455
456 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
457 *_trademgenServiceContext;
458
459 // Retrieve the pointer on the SEvMgr service handler.
460 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
461 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
462
463 return lSEVMGR_Service_ptr->jsonHandler (iJSONString);
464
465 }
466
467 // //////////////////////////////////////////////////////////////////////
468 std::string TRADEMGEN_Service::csvDisplay() const {
469
470 // Retrieve the TraDemGen service context
471 if (_trademgenServiceContext == NULL) {
472 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
473 "not been initialised");
474 }
475 assert (_trademgenServiceContext != NULL);
476
477 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
478 *_trademgenServiceContext;
479
480 // Retrieve the pointer on the SEvMgr service handler.
481 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
482 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
483
484 // Delegate the BOM building to the dedicated service
485 return BomDisplay::csvDisplay (lSEVMGR_Service_ptr);
486
487 }
488
489 // //////////////////////////////////////////////////////////////////////
490 std::string TRADEMGEN_Service::list() const {
491
492 // Retrieve the TraDemGen service context
493 if (_trademgenServiceContext == NULL) {
494 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
495 "not been initialised");
496 }
497 assert (_trademgenServiceContext != NULL);
498
499 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
500 *_trademgenServiceContext;
501
502 // Retrieve the pointer on the SEvMgr service handler.
503 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
504 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
505
506 // Delegate the BOM building to the dedicated service
507 return lSEVMGR_Service_ptr->list ();
508
509 }
510
511 // //////////////////////////////////////////////////////////////////////
513 list(const stdair::EventType::EN_EventType& iEventType) const {
514
515 // Retrieve the TraDemGen service context
516 if (_trademgenServiceContext == NULL) {
517 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
518 "not been initialised");
519 }
520 assert (_trademgenServiceContext != NULL);
521
522 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
523 *_trademgenServiceContext;
524
525 // Retrieve the pointer on the SEvMgr service handler.
526 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
527 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
528
529 // Delegate the BOM building to the dedicated service
530 return lSEVMGR_Service_ptr->list (iEventType);
531
532 }
533
534 // //////////////////////////////////////////////////////////////////////
536
537 // Retrieve the TraDemGen service context
538 if (_trademgenServiceContext == NULL) {
539 throw stdair::NonInitialisedServiceException ("The TraDemGen service has "
540 "not been initialised");
541 }
542 assert (_trademgenServiceContext != NULL);
543 // TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
544 // *_trademgenServiceContext;
545
546 // Get the date-time for the present time
547 boost::posix_time::ptime lNowDateTime =
548 boost::posix_time::second_clock::local_time();
549 //boost::gregorian::date lNowDate = lNowDateTime.date();
550
551 // DEBUG
552 STDAIR_LOG_DEBUG (std::endl
553 << "==================================================="
554 << std::endl
555 << lNowDateTime);
556
557 // Delegate the query execution to the dedicated command
558 stdair::BasChronometer lAirListChronometer;
559 lAirListChronometer.start();
560
561 // Retrieve the database session handler
562 stdair::DBSession_T& lDBSession =
563 stdair::DBSessionManager::instance().getDBSession();
564
565 // Prepare and execute the select statement
566 stdair::AirlineStruct lAirline;
567 stdair::DBRequestStatement_T lSelectStatement (lDBSession);
568 stdair::DBManagerForAirlines::prepareSelectStatement (lDBSession,
569 lSelectStatement,
570 lAirline);
571
572 // Prepare the SQL request corresponding to the select statement
573 bool hasStillData = true;
574 unsigned int idx = 0;
575 while (hasStillData == true) {
576 hasStillData =
577 stdair::DBManagerForAirlines::iterateOnStatement (lSelectStatement,
578 lAirline);
579
580 // DEBUG
581 STDAIR_LOG_DEBUG ("[" << idx << "]: " << lAirline);
582
583 // Iteration
584 ++idx;
585 }
586
587 const double lAirListMeasure = lAirListChronometer.elapsed();
588
589 // DEBUG
590 STDAIR_LOG_DEBUG ("Sample service for airline list retrieval: "
591 << lAirListMeasure);
592 }
593
594 // ////////////////////////////////////////////////////////////////////
595 const stdair::Count_T& TRADEMGEN_Service::
597
598 // Retrieve the TraDemGen service context
599 assert (_trademgenServiceContext != NULL);
600 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
601 *_trademgenServiceContext;
602
603 // Retrieve the SEvMgr service context
604 SEVMGR::SEVMGR_Service& lSEVMGR_Service =
605 lTRADEMGEN_ServiceContext.getSEVMGR_Service();
606
607 // Delegate the call to the dedicated command
608 const stdair::Count_T& oExpectedTotalNumberOfRequestsToBeGenerated =
609 lSEVMGR_Service.getExpectedTotalNumberOfEventsToBeGenerated (stdair::EventType::BKG_REQ);
610
611 //
612 return oExpectedTotalNumberOfRequestsToBeGenerated;
613 }
614
615 // ////////////////////////////////////////////////////////////////////
616 const stdair::Count_T& TRADEMGEN_Service::
618
619 // Retrieve the TraDemGen service context
620 assert (_trademgenServiceContext != NULL);
621 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
622 *_trademgenServiceContext;
623
624 // Retrieve the SEvMgr service context
625 SEVMGR::SEVMGR_Service& lSEVMGR_Service =
626 lTRADEMGEN_ServiceContext.getSEVMGR_Service();
627
628 // Delegate the call to the dedicated command
629 const stdair::Count_T& oActualTotalNumberOfRequestsToBeGenerated =
630 lSEVMGR_Service.getActualTotalNumberOfEventsToBeGenerated (stdair::EventType::BKG_REQ);
631
632 //
633 return oActualTotalNumberOfRequestsToBeGenerated;
634 }
635
636 // ////////////////////////////////////////////////////////////////////
638 stillHavingRequestsToBeGenerated (const stdair::DemandStreamKeyStr_T& iKey,
639 stdair::ProgressStatusSet& ioPSS,
640 const stdair::DemandGenerationMethod& iDemandGenerationMethod) const {
641
642 // Retrieve the TraDemGen service context
643 assert (_trademgenServiceContext != NULL);
644 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
645 *_trademgenServiceContext;
646
647 // Retrieve the pointer on the SEvMgr service handler.
648 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
649 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
650
651 // Delegate the call to the dedicated command
652 const bool oStillHavingRequestsToBeGenerated =
653 DemandManager::stillHavingRequestsToBeGenerated (lSEVMGR_Service_ptr,
654 iKey, ioPSS,
655 iDemandGenerationMethod);
656
657 //
658 return oStillHavingRequestsToBeGenerated;
659 }
660
661 // ////////////////////////////////////////////////////////////////////
662 stdair::Count_T TRADEMGEN_Service::
663 generateFirstRequests (const stdair::DemandGenerationMethod& iDemandGenerationMethod) const {
664
665 // Retrieve the TraDemGen service context
666 assert (_trademgenServiceContext != NULL);
667 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
668 *_trademgenServiceContext;
669
670 // Retrieve the pointer on the SEvMgr service handler.
671 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
672 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
673
674 // Retrieve the random generator
675 stdair::RandomGeneration& lGenerator =
676 lTRADEMGEN_ServiceContext.getUniformGenerator();
677
678 // Delegate the call to the dedicated command
679 const stdair::Count_T& oActualTotalNbOfEvents =
680 DemandManager::generateFirstRequests (lSEVMGR_Service_ptr, lGenerator,
681 iDemandGenerationMethod);
682
683 //
684 return oActualTotalNbOfEvents;
685 }
686
687 // ////////////////////////////////////////////////////////////////////
688 stdair::BookingRequestPtr_T TRADEMGEN_Service::
689 generateNextRequest (const stdair::DemandStreamKeyStr_T& iKey,
690 const stdair::DemandGenerationMethod& iDemandGenerationMethod) const {
691
692 // Retrieve the TraDemGen service context
693 assert (_trademgenServiceContext != NULL);
694 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
695 *_trademgenServiceContext;
696
697 // Retrieve the pointer on the SEvMgr service handler.
698 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
699 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
700
701 // Retrieve the random generator
702 stdair::RandomGeneration& lGenerator =
703 lTRADEMGEN_ServiceContext.getUniformGenerator();
704
705 // Delegate the call to the dedicated command
706 return DemandManager::generateNextRequest (lSEVMGR_Service_ptr,
707 lGenerator, iKey,
708 iDemandGenerationMethod);
709 }
710
711 // ////////////////////////////////////////////////////////////////////
712 stdair::ProgressStatusSet TRADEMGEN_Service::
713 popEvent (stdair::EventStruct& ioEventStruct) const {
714
715 // Retrieve the TraDemGen service context
716 assert (_trademgenServiceContext != NULL);
717 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
718 *_trademgenServiceContext;
719
720 // Retrieve the SEvMgr service context
721 SEVMGR::SEVMGR_Service& lSEVMGR_Service =
722 lTRADEMGEN_ServiceContext.getSEVMGR_Service();
723
724 // Extract the next event from the queue
725 return lSEVMGR_Service.popEvent (ioEventStruct);
726 }
727
728 // ////////////////////////////////////////////////////////////////////
730
731 // Retrieve the TraDemGen service context
732 assert (_trademgenServiceContext != NULL);
733 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
734 *_trademgenServiceContext;
735
736 // Retrieve the SEvMgr service context
737 SEVMGR::SEVMGR_Service& lSEVMGR_Service =
738 lTRADEMGEN_ServiceContext.getSEVMGR_Service();
739
740 // Calculates whether the event queue has been fully emptied
741 const bool isQueueDone = lSEVMGR_Service.isQueueDone();
742
743 //
744 return isQueueDone;
745 }
746
747 // ////////////////////////////////////////////////////////////////////
749 generateCancellation (const stdair::TravelSolutionStruct& iTravelSolution,
750 const stdair::PartySize_T& iPartySize,
751 const stdair::DateTime_T& iRequestTime,
752 const stdair::Date_T& iDepartureDate) const {
753
754 // Retrieve the TraDemGen service context
755 assert (_trademgenServiceContext != NULL);
756 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
757 *_trademgenServiceContext;
758
759 // Retrieve the random generator
760 stdair::RandomGeneration& lGenerator =
761 lTRADEMGEN_ServiceContext.getUniformGenerator();
762
763 // Build an event structure with the default constructor.
764 stdair::EventStruct lEventStruct;
765 stdair::EventStruct& lRefEventStruct = lEventStruct;
766
767 // Generate the cancellation event
768 const bool hasCancellationBeenGenerated =
769 DemandManager::generateCancellation (lGenerator, iTravelSolution,
770 iPartySize, iRequestTime,
771 iDepartureDate, lRefEventStruct);
772
773 // If the cancellation has been not sucessfully gerenerated, return.
774 if (hasCancellationBeenGenerated == false) {
775 return hasCancellationBeenGenerated;
776 }
777 assert (hasCancellationBeenGenerated == true);
778
779 // Retrieve the SEvMgr service context
780 SEVMGR::SEVMGR_Service& lSEVMGR_Service =
781 lTRADEMGEN_ServiceContext.getSEVMGR_Service();
782
790 // Add the gerenerated cancellation event into the queue
791 lSEVMGR_Service.addEvent (lRefEventStruct);
792
793 // Update the status of cancellation events within the event queue.
794 const bool hasProgressStatus =
795 lSEVMGR_Service.hasProgressStatus(stdair::EventType::CX);
796 if (hasProgressStatus == false) {
797 const stdair::Count_T lCancellationNumber = 1;
798 lSEVMGR_Service.addStatus (stdair::EventType::CX, lCancellationNumber);
799 } else {
800 stdair::Count_T lCurrentCancellationNumber =
801 lSEVMGR_Service.getActualTotalNumberOfEventsToBeGenerated (stdair::EventType::CX);
802 lCurrentCancellationNumber++;
803 lSEVMGR_Service.updateStatus (stdair::EventType::CX, lCurrentCancellationNumber);
804 }
805
806 return hasCancellationBeenGenerated;
807
808 }
809
810 // ////////////////////////////////////////////////////////////////////
812
813 // Retrieve the TraDemGen service context
814 assert (_trademgenServiceContext != NULL);
815 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
816 *_trademgenServiceContext;
817
818 // Retrieve the pointer on the SEvMgr service handler.
819 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
820 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
821
822 // Retrieve the shared generator
823 stdair::RandomGeneration& lSharedGenerator =
824 lTRADEMGEN_ServiceContext.getUniformGenerator();
825
826 // Delegate the call to the dedicated command
827 DemandManager::reset (lSEVMGR_Service_ptr,
828 lSharedGenerator.getBaseGenerator());
829 }
830
832 const stdair::ProgressStatus& TRADEMGEN_Service::getProgressStatus() const {
833
834 // Retrieve the TraDemGen service context
835 assert (_trademgenServiceContext != NULL);
836 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
837 *_trademgenServiceContext;
838
839 // Retrieve the pointer on the SEvMgr service handler.
840 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
841 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
842
843 // Delegate the call to the dedicated service
844 return lSEVMGR_Service_ptr->getStatus();
845
846 }
847
849 const stdair::ProgressStatus& TRADEMGEN_Service::
850 getProgressStatus (const stdair::EventType::EN_EventType& iEventType) const {
851
852 // Retrieve the TraDemGen service context
853 assert (_trademgenServiceContext != NULL);
854 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
855 *_trademgenServiceContext;
856
857 // Retrieve the pointer on the SEvMgr service handler.
858 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
859 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
860
861 // Delegate the call to the dedicated service
862 return lSEVMGR_Service_ptr->getStatus(iEventType);
863
864 }
865
868 hasDemandStream (const stdair::DemandStreamKeyStr_T& iDemandStreamKey) const {
869
870 // Retrieve the TraDemGen service context
871 assert (_trademgenServiceContext != NULL);
872 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
873 *_trademgenServiceContext;
874
875 // Retrieve the pointer on the SEvMgr service handler.
876 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
877 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
878
879 // Delegate the call to the dedicated service
880 return lSEVMGR_Service_ptr->hasEventGenerator<DemandStream,
881 stdair::DemandStreamKeyStr_T>(iDemandStreamKey);
882 }
883
886
887 // Retrieve the TraDemGen service context
888 assert (_trademgenServiceContext != NULL);
889 TRADEMGEN_ServiceContext& lTRADEMGEN_ServiceContext =
890 *_trademgenServiceContext;
891
892 // Retrieve the pointer on the SEvMgr service handler.
893 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
894 lTRADEMGEN_ServiceContext.getSEVMGR_ServicePtr();
895
896 // Delegate the call to the dedicated service
897 const DemandStreamList_T lDemandStreamList =
898 lSEVMGR_Service_ptr->getEventGeneratorList<DemandStream>();
899
900 // Output stream to store the display of demand streams.
901 std::ostringstream oStream;
902
903 for (DemandStreamList_T::const_iterator itDemandStream =
904 lDemandStreamList.begin(); itDemandStream !=
905 lDemandStreamList.end(); itDemandStream++) {
906 DemandStream* lDemandStream_ptr = *itDemandStream;
907 assert (lDemandStream_ptr != NULL);
908 oStream << lDemandStream_ptr->describeKey() << std::endl;
909
910 }
911 return oStream.str();
912 }
913
914}
915
916namespace SEVMGR {
917
925
926 // ////////////////////////////////////////////////////////////////////
927 template<class EventGenerator>
928 void SEVMGR_Service::addEventGenerator (EventGenerator& iEventGenerator) const {
929 // Retrieve the StdAir service
930 const stdair::STDAIR_Service& lSTDAIR_Service =
931 this->getSTDAIR_Service();
932
933 // Retrieve the BOM root object instance
934 stdair::BomRoot& lPersistentBomRoot =
935 lSTDAIR_Service.getPersistentBomRoot();
936
937 // Link the DemandStream to its parent (EventQueue)
938 stdair::FacBomManager::linkWithParent (lPersistentBomRoot, iEventGenerator);
939
940 // Add the DemandStream to the dedicated list and map
941 stdair::FacBomManager::addToListAndMap (lPersistentBomRoot,
942 iEventGenerator);
943
944 }
945
946 // ////////////////////////////////////////////////////////////////////
947 template<class EventGenerator, class Key>
948 EventGenerator& SEVMGR_Service::getEventGenerator(const Key& iKey) const {
949
950 // Retrieve the StdAir service
951 const stdair::STDAIR_Service& lSTDAIR_Service =
952 this->getSTDAIR_Service();
953
954 // Retrieve the BOM root object instance
955 stdair::BomRoot& lPersistentBomRoot =
956 lSTDAIR_Service.getPersistentBomRoot();
957
958 // Retrieve the DemandStream which corresponds to the given key.
959 EventGenerator& lEventGenerator =
960 stdair::BomManager::getObject<EventGenerator> (lPersistentBomRoot,
961 iKey);
962
963 return lEventGenerator;
964
965 }
966
967 // ////////////////////////////////////////////////////////////////////
968 template<class EventGenerator, class Key>
969 bool SEVMGR_Service::hasEventGenerator(const Key& iKey) const {
970
971 bool hasEventGenerator = true;
972
973 // Retrieve the StdAir service
974 const stdair::STDAIR_Service& lSTDAIR_Service =
975 this->getSTDAIR_Service();
976
977 // Retrieve the BOM root object instance
978 stdair::BomRoot& lPersistentBomRoot =
979 lSTDAIR_Service.getPersistentBomRoot();
980
981 // Retrieve the DemandStream which corresponds to the given key.
982 EventGenerator* lEventGenerator_ptr =
983 stdair::BomManager::getObjectPtr<EventGenerator> (lPersistentBomRoot,
984 iKey);
985 if (lEventGenerator_ptr == NULL) {
986 hasEventGenerator = false;
987 }
988
989 return hasEventGenerator;
990
991 }
992
993 // ////////////////////////////////////////////////////////////////////
994 template<class EventGenerator>
995 const std::list<EventGenerator*> SEVMGR_Service::getEventGeneratorList() const {
996
997 // Retrieve the StdAir service
998 const stdair::STDAIR_Service& lSTDAIR_Service =
999 this->getSTDAIR_Service();
1000
1001 // Retrieve the BOM root object instance
1002 stdair::BomRoot& lPersistentBomRoot =
1003 lSTDAIR_Service.getPersistentBomRoot();
1004
1005 // Retrieve the DemandStream list
1006 const std::list<EventGenerator*> lEventGeneratorList =
1007 stdair::BomManager::getList<EventGenerator> (lPersistentBomRoot);
1008
1009 return lEventGeneratorList;
1010 }
1011
1012 // ////////////////////////////////////////////////////////////////////
1013 template<class EventGenerator>
1014 bool SEVMGR_Service::hasEventGeneratorList() const {
1015
1016 // Retrieve the StdAir service
1017 const stdair::STDAIR_Service& lSTDAIR_Service =
1018 this->getSTDAIR_Service();
1019
1020 // Retrieve the BOM root object instance
1021 stdair::BomRoot& lPersistentBomRoot =
1022 lSTDAIR_Service.getPersistentBomRoot();
1023
1024 const bool hasListEventGenerator =
1025 stdair::BomManager::hasList<EventGenerator> (lPersistentBomRoot);
1026
1027 return hasListEventGenerator;
1028 }
1029
1030 // ////////////////////////////////////////////////////////////////////
1035 template void SEVMGR_Service::
1036 addEventGenerator<TRADEMGEN::DemandStream> (TRADEMGEN::DemandStream&) const;
1037
1038 template TRADEMGEN::DemandStream& SEVMGR_Service::
1039 getEventGenerator<TRADEMGEN::DemandStream, stdair::DemandStreamKeyStr_T> (const stdair::DemandStreamKeyStr_T&) const;
1040
1041 template bool SEVMGR_Service::
1042 hasEventGenerator<TRADEMGEN::DemandStream, stdair::DemandStreamKeyStr_T> (const stdair::DemandStreamKeyStr_T&) const;
1043
1044 template const TRADEMGEN::DemandStreamList_T SEVMGR_Service::
1045 getEventGeneratorList<TRADEMGEN::DemandStream> () const;
1046
1047 template bool SEVMGR_Service::hasEventGeneratorList<TRADEMGEN::DemandStream>() const;
1048 // ////////////////////////////////////////////////////////////////////
1049
1050}
CategoricalAttributeLite< stdair::AirportCode_T > POSProbabilityMass_T
std::list< DemandStream * > DemandStreamList_T
static std::string csvDisplay(const SEVMGR::SEVMGR_ServicePtr_T)
Class modeling a demand stream.
const std::string describeKey() const
static void generateDemand(const DemandFilePath &, SEVMGR::SEVMGR_ServicePtr_T, stdair::RandomGeneration &, const POSProbabilityMass_T &)
TRADEMGEN_ServiceContext & create(const stdair::RandomSeed_T &)
static FacTRADEMGENServiceContext & instance()
Class holding the context of the Trademgen services.
bool hasDemandStream(const stdair::DemandStreamKeyStr_T &) const
stdair::BookingRequestStruct buildSampleBookingRequest(const bool isForCRS=false)
std::string jsonHandler(const stdair::JSONString &) const
const bool stillHavingRequestsToBeGenerated(const stdair::DemandStreamKeyStr_T &, stdair::ProgressStatusSet &, const stdair::DemandGenerationMethod &) const
std::string displayDemandStream() const
TRADEMGEN_Service(const stdair::BasLogParams &, const stdair::BasDBParams &, const stdair::RandomSeed_T &)
Constructor.
const stdair::Count_T & getActualTotalNumberOfRequestsToBeGenerated() const
void buildComplementaryLinks(stdair::BomRoot &)
const stdair::ProgressStatus & getProgressStatus() const
void parseAndLoad(const DemandFilePath &)
stdair::ProgressStatusSet popEvent(stdair::EventStruct &) const
bool generateCancellation(const stdair::TravelSolutionStruct &, const stdair::PartySize_T &, const stdair::DateTime_T &, const stdair::Date_T &) const
const stdair::Count_T & getExpectedTotalNumberOfRequestsToBeGenerated() const
stdair::Count_T generateFirstRequests(const stdair::DemandGenerationMethod &) const
stdair::BookingRequestPtr_T generateNextRequest(const stdair::DemandStreamKeyStr_T &, const stdair::DemandGenerationMethod &) const