TvlSim Logo  1.01.6
C++ Simulated Travel-Oriented Distribution System Library
Loading...
Searching...
No Matches
TVLSIM_Service.cpp
Go to the documentation of this file.
1
2// //////////////////////////////////////////////////////////////////////
3// Import section
4// //////////////////////////////////////////////////////////////////////
5// STL
6#include <cassert>
7// Boost
8#include <boost/make_shared.hpp>
9// SOCI
10#if defined(SOCI_HEADERS_BURIED)
11#include <soci/core/soci.h>
12#else // SOCI_HEADERS_BURIED
13#include <soci/soci.h>
14#endif // SOCI_HEADERS_BURIED
15// StdAir
16#include <stdair/stdair_json.hpp>
17#include <stdair/stdair_file.hpp>
18#include <stdair/basic/BasConst_General.hpp>
19#include <stdair/basic/BasChronometer.hpp>
20#include <stdair/basic/JSonCommand.hpp>
21#include <stdair/bom/BomManager.hpp>
22#include <stdair/bom/BomRoot.hpp>
23#include <stdair/bom/AirlineStruct.hpp>
24#include <stdair/bom/BookingRequestStruct.hpp>
25#include <stdair/bom/BomJSONImport.hpp>
26#include <stdair/command/DBManagerForAirlines.hpp>
27#include <stdair/service/FacSupervisor.hpp>
28#include <stdair/service/Logger.hpp>
29#include <stdair/service/DBSessionManager.hpp>
30#include <stdair/STDAIR_Service.hpp>
31// SEvMgr
32#include <sevmgr/SEVMGR_Service.hpp>
33// Distribution
34#include <simcrs/SIMCRS_Service.hpp>
35// TraDemGen
36#include <trademgen/TRADEMGEN_Service.hpp>
37// TravelCCM
38#include <travelccm/TRAVELCCM_Service.hpp>
39// Dsim
49
50namespace TVLSIM {
51
52 // //////////////////////////////////////////////////////////////////////
53 TVLSIM_Service::TVLSIM_Service () : _tvlsimServiceContext (NULL) {
54 assert (false);
55 }
56
57 // //////////////////////////////////////////////////////////////////////
58 TVLSIM_Service::TVLSIM_Service (const TVLSIM_Service& iService) {
59 assert (false);
60 }
61
62 // //////////////////////////////////////////////////////////////////////
63 TVLSIM_Service::TVLSIM_Service
64 (const stdair::BasLogParams& iLogParams,
65 const stdair::Date_T& iStartDate,
66 const stdair::Date_T& iEndDate,
67 const stdair::RandomSeed_T& iRandomSeed,
68 const stdair::DemandGenerationMethod& iDemandGenerationMethod,
69 const NbOfRuns_T& iNbOfRuns)
70 : _tvlsimServiceContext (NULL) {
71
72 // Initialise the StdAir service handler
73 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
74 initStdAirService (iLogParams);
75
76 // Initialise the service context
77 initServiceContext ();
78
79 // Add the StdAir service context to the TvlSim service context
80 // \note TvlSim owns the StdAir service resources here.
81 const bool ownStdairService = true;
82 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
83
84 // Init Config
85 initConfig (iStartDate, iEndDate, iRandomSeed,
86 iDemandGenerationMethod, iNbOfRuns);
87
88 // Initalise the SEVMGR service.
89 initSEVMGRService();
90
91 // Initalise the TraDemGen service.
92 initTRADEMGENService ();
93
94 // Initalise the TravelCCM service.
95 initTRAVELCCMService();
96
97 // Initalise the SimCRS service, itself initialising AirInv, AirTSP
98 // and SimFQT.
99 initSIMCRSService();
100
101 // Initialise the (remaining of the) context
102 initDsimService();
103 }
104
105 // //////////////////////////////////////////////////////////////////////
106 TVLSIM_Service::TVLSIM_Service
107 (const stdair::BasLogParams& iLogParams,
108 const stdair::BasDBParams& iDBParams,
109 const stdair::Date_T& iStartDate,
110 const stdair::Date_T& iEndDate,
111 const stdair::RandomSeed_T& iRandomSeed,
112 const stdair::DemandGenerationMethod& iDemandGenerationMethod,
113 const NbOfRuns_T& iNbOfRuns)
114 : _tvlsimServiceContext (NULL) {
115
116 // Initialise the StdAir service handler
117 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
118 initStdAirService (iLogParams, iDBParams);
119
120 // Initialise the service context
121 initServiceContext ();
122
123 // Add the StdAir service context to the TvlSim service context
124 // \note TvlSim owns the StdAir service resources here.
125 const bool ownStdairService = true;
126 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
127
128 // Init Config
129 initConfig (iStartDate, iEndDate, iRandomSeed,
130 iDemandGenerationMethod, iNbOfRuns);
131
132 // Initalise the SEVMGR service.
133 initSEVMGRService();
134
135 // Initalise the TraDemGen service.
136 initTRADEMGENService ();
137
138 // Initalise the TravelCCM service.
139 initTRAVELCCMService();
140
141 // Initalise the SimCRS service, itself initialising AirInv, AirTSP
142 // and SimFQT.
143 initSIMCRSService();
144
145 // Initialise the (remaining of the) context
146 initDsimService();
147 }
148
149 // //////////////////////////////////////////////////////////////////////
150 TVLSIM_Service::TVLSIM_Service
151 (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
152 const stdair::Date_T& iStartDate,
153 const stdair::Date_T& iEndDate,
154 const stdair::RandomSeed_T& iRandomSeed,
155 const stdair::DemandGenerationMethod& iDemandGenerationMethod,
156 const NbOfRuns_T& iNbOfRuns)
157 : _tvlsimServiceContext (NULL) {
158
159 // Initialise the service context
160 initServiceContext ();
161
162 // Store the STDAIR service object within the (AIRINV) service context
163 // \note AirInv does not own the STDAIR service resources here.
164 const bool doesNotOwnStdairService = false;
165 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
166
167 // Init Config
168 initConfig (iStartDate, iEndDate, iRandomSeed,
169 iDemandGenerationMethod, iNbOfRuns);
170
171 // Initalise the SEVMGR service.
172 initSEVMGRService();
173
174 // Initalise the TraDemGen service.
175 initTRADEMGENService ();
176
177 // Initalise the TravelCCM service.
178 initTRAVELCCMService();
179
180 // Initalise the SimCRS service, itself initialising AirInv, AirTSP
181 // and SimFQT.
182 initSIMCRSService();
183
184 // Initialise the (remaining of the) context
185 initDsimService();
186 }
187
188 // //////////////////////////////////////////////////////////////////////
190 // Delete/Clean all the objects from memory
191 finalise();
192 }
193
194 // //////////////////////////////////////////////////////////////////////
195 void TVLSIM_Service::finalise() {
196 assert (_tvlsimServiceContext != NULL);
197 // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
198 _tvlsimServiceContext->reset();
199 }
200
201 // ////////////////////////////////////////////////////////////////////
202 void TVLSIM_Service::initServiceContext () {
203
204 // Initialise the context
205 TVLSIM_ServiceContext& lTVLSIM_ServiceContext =
207 _tvlsimServiceContext = &lTVLSIM_ServiceContext;
208 }
209
210 // ////////////////////////////////////////////////////////////////////
211 void TVLSIM_Service::
212 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
213 const bool iOwnStdairService) {
214
215 // Retrieve the Dsim service context
216 assert (_tvlsimServiceContext != NULL);
217 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
218
219 // Store the StdAir service object within the (TvlSim) service context
220 lTVLSIM_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
221 iOwnStdairService);
222 }
223
224 // //////////////////////////////////////////////////////////////////////
225 stdair::STDAIR_ServicePtr_T TVLSIM_Service::
226 initStdAirService (const stdair::BasLogParams& iLogParams) {
227
235 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
236 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
237
238 return lSTDAIR_Service_ptr;
239 }
240
241 // //////////////////////////////////////////////////////////////////////
242 stdair::STDAIR_ServicePtr_T TVLSIM_Service::
243 initStdAirService (const stdair::BasLogParams& iLogParams,
244 const stdair::BasDBParams& iDBParams) {
245
253 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
254 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
255
256 return lSTDAIR_Service_ptr;
257 }
258
259 // ////////////////////////////////////////////////////////////////////
260 void TVLSIM_Service::initSEVMGRService() {
261
262 // Retrieve the Dsim service context
263 assert (_tvlsimServiceContext != NULL);
264 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
265
266 // Retrieve the StdAir service context
267 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
268 lTVLSIM_ServiceContext.getSTDAIR_ServicePtr();
269
277 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
278 boost::make_shared<SEVMGR::SEVMGR_Service> (lSTDAIR_Service_ptr);
279
280 // Store the SEVMGR service object within the (TvlSim) service context
281 lTVLSIM_ServiceContext.setSEVMGR_Service (lSEVMGR_Service_ptr);
282 }
283
284
285 // ////////////////////////////////////////////////////////////////////
286 void TVLSIM_Service::initSIMCRSService() {
287
288 // Retrieve the Dsim service context
289 assert (_tvlsimServiceContext != NULL);
290 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
291
292 // Retrieve the StdAir service context
293 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
294 lTVLSIM_ServiceContext.getSTDAIR_ServicePtr();
295
296 // Retrieve the StdAir service context
297 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
298 lTVLSIM_ServiceContext.getSEVMGR_ServicePtr();
299
300 // Look for the CRS code
301 SIMCRS::CRSCode_T lCRSCode ("1S");
302 lSTDAIR_Service_ptr->exportConfigValue<SIMCRS::CRSCode_T> (lCRSCode,
303 "CRS.code");
304
312 SIMCRS::SIMCRS_ServicePtr_T lSIMCRS_Service_ptr =
313 boost::make_shared<SIMCRS::SIMCRS_Service> (lSTDAIR_Service_ptr,
314 lSEVMGR_Service_ptr,
315 lCRSCode);
316
317 // Store the SIMCRS service object within the (TvlSim) service context
318 lTVLSIM_ServiceContext.setSIMCRS_Service (lSIMCRS_Service_ptr);
319 }
320
321 // ////////////////////////////////////////////////////////////////////
322 void TVLSIM_Service::initTRADEMGENService () {
323
324 // Retrieve the Dsim service context
325 assert (_tvlsimServiceContext != NULL);
326 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
327
328 // Retrieve the StdAir service context
329 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
330 lTVLSIM_ServiceContext.getSTDAIR_ServicePtr();
331
332 // Retrieve the StdAir service context
333 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
334 lTVLSIM_ServiceContext.getSEVMGR_ServicePtr();
335
336 // Look for the random seed in the configuration
337 stdair::RandomSeed_T lRandomSeed (stdair::DEFAULT_RANDOM_SEED);
338 const bool hasSeedBeenRetrieved =
339 lSTDAIR_Service_ptr->exportConfigValue<stdair::RandomSeed_T> (lRandomSeed,
340 "random.seed");
341 assert (hasSeedBeenRetrieved == true);
342
350 TRADEMGEN::TRADEMGEN_ServicePtr_T lTRADEMGEN_Service_ptr =
351 boost::make_shared<TRADEMGEN::TRADEMGEN_Service> (lSTDAIR_Service_ptr,
352 lSEVMGR_Service_ptr,
353 lRandomSeed);
354
355 // Store the TRADEMGEN service object within the (TvlSim) service context
356 lTVLSIM_ServiceContext.setTRADEMGEN_Service (lTRADEMGEN_Service_ptr);
357 }
358
359 // ////////////////////////////////////////////////////////////////////
360 void TVLSIM_Service::initTRAVELCCMService() {
361
362 // Retrieve the Dsim service context
363 assert (_tvlsimServiceContext != NULL);
364 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
365
366 // Retrieve the StdAir service context
367 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
368 lTVLSIM_ServiceContext.getSTDAIR_ServicePtr();
369
377 TRAVELCCM::TRAVELCCM_ServicePtr_T lTRAVELCCM_Service_ptr =
378 boost::make_shared<TRAVELCCM::TRAVELCCM_Service> (lSTDAIR_Service_ptr);
379
380 // Store the TRAVELCCM service object within the (TvlSim) service context
381 lTVLSIM_ServiceContext.setTRAVELCCM_Service (lTRAVELCCM_Service_ptr);
382 }
383
384 // //////////////////////////////////////////////////////////////////////
385 void TVLSIM_Service::initDsimService() {
386 // Do nothing at this stage. A sample BOM tree may be built by
387 // calling the buildSampleBom() method
388 }
389
390 // //////////////////////////////////////////////////////////////////////
391 void TVLSIM_Service::
392 initConfig (const stdair::Date_T& iStartDate,
393 const stdair::Date_T& iEndDate,
394 const stdair::RandomSeed_T& iRandomSeed,
395 const stdair::DemandGenerationMethod& iDemandGenerationMethod,
396 const NbOfRuns_T& iNbOfRuns) {
397
398 // Retrieve the TvlSim service context
399 if (_tvlsimServiceContext == NULL) {
400 throw stdair::NonInitialisedServiceException ("The TvlSim service "
401 "has not been initialised");
402 }
403 assert (_tvlsimServiceContext != NULL);
404 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
405
406 // Retrieve the StdAir service object from the (TVLSIM) service context
407 stdair::STDAIR_Service& lSTDAIR_Service =
408 lTVLSIM_ServiceContext.getSTDAIR_Service();
409
410 // Load the input config parameters and try to retrieve the input config
411 // files.
412 ConfigImport::importINI (lSTDAIR_Service, iStartDate, iEndDate,
413 iRandomSeed, iDemandGenerationMethod, iNbOfRuns);
414
415 // Retrieve the Simulation Status
416 SimulationStatus& lSimulationStatus =
417 lTVLSIM_ServiceContext.getSimulationStatus();
418
419 // Update the simulation status with the correct start date, end date and
420 // number of runs
421 ConfigExport::updateSimulationStatus (lSTDAIR_Service, lSimulationStatus,
422 iStartDate, iEndDate, iNbOfRuns);
423
424 }
425
426 // //////////////////////////////////////////////////////////////////////
428
429 // Retrieve the TvlSim service context
430 if (_tvlsimServiceContext == NULL) {
431 throw stdair::NonInitialisedServiceException ("The TvlSim service "
432 "has not been initialised");
433 }
434 assert (_tvlsimServiceContext != NULL);
435
436 // Retrieve the TvlSim service context and whether it owns the Stdair
437 // service
438 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
439 const bool doesOwnStdairService =
440 lTVLSIM_ServiceContext.getOwnStdairServiceFlag();
441
448 if (doesOwnStdairService == true) {
449 // Retrieve the StdAir service object from the (TvlSim) service context
450 /*
451 stdair::STDAIR_Service& lSTDAIR_Service =
452 lTVLSIM_ServiceContext.getSTDAIR_Service();
453 */
454
455 //
456 //lSTDAIR_Service.cleanBomLayer();
457 }
458
476 }
477
478 // ////////////////////////////////////////////////////////////////////
480 setInputFiles (const stdair::ScheduleFilePath& iScheduleInputFilename,
481 const stdair::ODFilePath& iODInputFilename,
482 const stdair::FRAT5FilePath& iFRAT5InputFilename,
483 const stdair::FFDisutilityFilePath& iFFDisutilityInputFilename,
484 const AIRRAC::YieldFilePath& iYieldInputFilepath,
485 const SIMFQT::FareFilePath& iFareInputFilepath,
486 const TRADEMGEN::DemandFilePath& iDemandFilepath) {
487
488 // Retrieve the TvlSim service context
489 if (_tvlsimServiceContext == NULL) {
490 throw stdair::NonInitialisedServiceException ("The TvlSim service "
491 "has not been initialised");
492 }
493 assert (_tvlsimServiceContext != NULL);
494
495 // Retrieve the TvlSim service context and whether it owns the Stdair
496 // service
497 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
498
499 // Retrieve the StdAir service object from the (TVLSIM) service context
500 stdair::STDAIR_Service& lSTDAIR_Service =
501 lTVLSIM_ServiceContext.getSTDAIR_Service();
502
503 // Load the file names into the configuration holder
504 ConfigImport::importFiles (lSTDAIR_Service, iScheduleInputFilename,
505 iODInputFilename, iFRAT5InputFilename,
506 iFFDisutilityInputFilename, iYieldInputFilepath,
507 iFareInputFilepath, iDemandFilepath);
508
509 }
510
511 // ////////////////////////////////////////////////////////////////////
513 parseAndLoad () {
514
515 // Retrieve the TvlSim service context
516 if (_tvlsimServiceContext == NULL) {
517 throw stdair::NonInitialisedServiceException ("The TvlSim service "
518 "has not been initialised");
519 }
520 assert (_tvlsimServiceContext != NULL);
521
522 // Retrieve the TvlSim service context and whether it owns the Stdair
523 // service
524 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
525 const bool doesOwnStdairService =
526 lTVLSIM_ServiceContext.getOwnStdairServiceFlag();
527
528 // Retrieve the StdAir service object from the (TVLSIM) service context
529 stdair::STDAIR_Service& lSTDAIR_Service =
530 lTVLSIM_ServiceContext.getSTDAIR_Service();
531
532 // Look for the input files in the configuration holder
533 stdair::Filename_T lFilename ("");
534 const bool hasScheduleFileBeenRetrieved =
535 lSTDAIR_Service.exportConfigValue<stdair::Filename_T> (lFilename,
536 "input.schedule");
537 assert (hasScheduleFileBeenRetrieved == true);
538 const stdair::ScheduleFilePath lScheduleInputFilename (lFilename);
539 const bool hasODFileBeenRetrieved =
540 lSTDAIR_Service.exportConfigValue<stdair::Filename_T> (lFilename,
541 "input.ond");
542 assert (hasODFileBeenRetrieved == true);
543 const stdair::ODFilePath lODInputFilename (lFilename);
544 const bool hasFrat5FileBeenRetrieved =
545 lSTDAIR_Service.exportConfigValue<stdair::Filename_T> (lFilename,
546 "input.frat5");
547 assert (hasFrat5FileBeenRetrieved == true);
548 const stdair::FRAT5FilePath lFRAT5InputFilename (lFilename);
549 const bool hasFFdisutilityFileBeenRetrieved =
550 lSTDAIR_Service.exportConfigValue<stdair::Filename_T> (lFilename,
551 "input.ffdisutility");
552 assert (hasFFdisutilityFileBeenRetrieved == true);
553 const stdair::FFDisutilityFilePath lFFDisutilityInputFilename (lFilename);
554 const bool hasYieldFileBeenRetrieved =
555 lSTDAIR_Service.exportConfigValue<stdair::Filename_T> (lFilename,
556 "input.yield");
557 assert (hasYieldFileBeenRetrieved == true);
558 const AIRRAC::YieldFilePath lYieldInputFilepath (lFilename);
559 const bool hasFareFileBeenRetrieved =
560 lSTDAIR_Service.exportConfigValue<stdair::Filename_T> (lFilename,
561 "input.fare");
562 assert (hasFareFileBeenRetrieved == true);
563 const SIMFQT::FareFilePath lFareInputFilepath (lFilename);
564 const bool hasDemandFileBeenRetrieved =
565 lSTDAIR_Service.exportConfigValue<stdair::Filename_T> (lFilename,
566 "input.demand");
567 assert (hasDemandFileBeenRetrieved == true);
568 const TRADEMGEN::DemandFilePath lDemandFilepath (lFilename);
569
577 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
578 lTVLSIM_ServiceContext.getSIMCRS_Service();
579 lSIMCRS_Service.parseAndLoad (lScheduleInputFilename, lODInputFilename,
580 lFRAT5InputFilename,
581 lFFDisutilityInputFilename,
582 lYieldInputFilepath, lFareInputFilepath);
583
587 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
588 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
589 lTRADEMGEN_Service.parseAndLoad (lDemandFilepath);
590
595 // Retrieve the persistent BOM root object.
596 stdair::BomRoot& lPersistentBomRoot =
597 lSTDAIR_Service.getPersistentBomRoot();
598 buildComplementaryLinks (lPersistentBomRoot);
599
604 if (doesOwnStdairService == true) {
605 //
606 clonePersistentBom ();
607 }
608
612 SimulationStatus& lSimulationStatus =
613 lTVLSIM_ServiceContext.getSimulationStatus();
614 Simulator::updateStatus(lTRADEMGEN_Service, stdair::EventType::BKG_REQ,
615 lSimulationStatus);
616 }
617
618 // ////////////////////////////////////////////////////////////////////
620
621 // Retrieve the TvlSim service context
622 if (_tvlsimServiceContext == NULL) {
623 throw stdair::NonInitialisedServiceException ("The TvlSim service "
624 "has not been initialised");
625 }
626 assert (_tvlsimServiceContext != NULL);
627
628 // Retrieve the TvlSim service context and whether it owns the Stdair
629 // service
630 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
631 const bool doesOwnStdairService =
632 lTVLSIM_ServiceContext.getOwnStdairServiceFlag();
633
634 // Retrieve the StdAir service object from the (TvlSim) service context
635 stdair::STDAIR_Service& lSTDAIR_Service =
636 lTVLSIM_ServiceContext.getSTDAIR_Service();
637
638 // Retrieve the persistent BOM root object.
639 stdair::BomRoot& lPersistentBomRoot =
640 lSTDAIR_Service.getPersistentBomRoot();
641
646 if (doesOwnStdairService == true) {
647 //
648 lSTDAIR_Service.buildSampleBom();
649 }
650
659 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
660 lTVLSIM_ServiceContext.getSIMCRS_Service();
661 lSIMCRS_Service.buildSampleBom();
662
667 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
668 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
669 lTRADEMGEN_Service.buildSampleBom();
670
671 // Update the Simulation Status
672 SimulationStatus& lSimulationStatus =
673 lTVLSIM_ServiceContext.getSimulationStatus();
674 Simulator::updateStatus(lTRADEMGEN_Service, stdair::EventType::BKG_REQ,
675 lSimulationStatus);
676
681 TRAVELCCM::TRAVELCCM_Service& lTRAVELCCM_Service =
682 lTVLSIM_ServiceContext.getTRAVELCCM_Service();
683 lTRAVELCCM_Service.buildSampleBom();
684
689 buildComplementaryLinks (lPersistentBomRoot);
690
695 if (doesOwnStdairService == true) {
696 //
697 clonePersistentBom ();
698 }
699 }
700
701 // ////////////////////////////////////////////////////////////////////
702 void TVLSIM_Service::clonePersistentBom () {
703
704 // Retrieve the TvlSim service context
705 if (_tvlsimServiceContext == NULL) {
706 throw stdair::NonInitialisedServiceException ("The TvlSim service "
707 "has not been initialised");
708 }
709 assert (_tvlsimServiceContext != NULL);
710
711 // Retrieve the TvlSim service context and whether it owns the Stdair
712 // service
713 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
714 const bool doesOwnStdairService =
715 lTVLSIM_ServiceContext.getOwnStdairServiceFlag();
716
717 // Retrieve the StdAir service object from the (TvlSim) service context
718 stdair::STDAIR_Service& lSTDAIR_Service =
719 lTVLSIM_ServiceContext.getSTDAIR_Service();
720
725 if (doesOwnStdairService == true) {
726 //
727 lSTDAIR_Service.clonePersistentBom ();
728 }
729
738 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
739 lTVLSIM_ServiceContext.getSIMCRS_Service();
740 lSIMCRS_Service.clonePersistentBom ();
741
746 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
747 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
748 lTRADEMGEN_Service.clonePersistentBom ();
749
754 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
755 buildComplementaryLinks (lBomRoot);
756
757 }
758
759 // ////////////////////////////////////////////////////////////////////
760 void TVLSIM_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
761 // Currently, no more things to do by TVLSIM at that stage.
762 }
763
764 // //////////////////////////////////////////////////////////////////////
766 buildSampleTravelSolutions(stdair::TravelSolutionList_T& ioTravelSolutionList){
767
768 // Retrieve the TvlSim service context
769 if (_tvlsimServiceContext == NULL) {
770 throw stdair::NonInitialisedServiceException ("The TvlSim service "
771 "has not been initialised");
772 }
773 assert (_tvlsimServiceContext != NULL);
774
775 // Retrieve the StdAir service object from the (AirTSP) service context
776 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
777 stdair::STDAIR_Service& lSTDAIR_Service =
778 lTVLSIM_ServiceContext.getSTDAIR_Service();
779
780 // Delegate the BOM building to the dedicated service
781 lSTDAIR_Service.buildSampleTravelSolutions (ioTravelSolutionList);
782 }
783
784 // //////////////////////////////////////////////////////////////////////
785 stdair::BookingRequestStruct TVLSIM_Service::
786 buildSampleBookingRequest (const bool isForCRS) {
787
788 // Retrieve the TvlSim service context
789 if (_tvlsimServiceContext == NULL) {
790 throw stdair::NonInitialisedServiceException ("The TvlSim service "
791 "has not been initialised");
792 }
793 assert (_tvlsimServiceContext != NULL);
794
795 // Retrieve the StdAir service object from the (AirTSP) service context
796 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
797 stdair::STDAIR_Service& lSTDAIR_Service =
798 lTVLSIM_ServiceContext.getSTDAIR_Service();
799
800 // Delegate the BOM building to the dedicated service
801 return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
802 }
803
804 // ////////////////////////////////////////////////////////////////////
805 bool TVLSIM_Service::sell (const std::string& iSegmentDateKey,
806 const stdair::ClassCode_T& iClassCode,
807 const stdair::PartySize_T& iPartySize) {
808
809 // Retrieve the TvlSim service context
810 if (_tvlsimServiceContext == NULL) {
811 throw stdair::NonInitialisedServiceException ("The TvlSim service "
812 "has not been initialised");
813 }
814 assert (_tvlsimServiceContext != NULL);
815
816 // Retrieve the SimCRS service object from the (TvlSim) service context
817 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
818 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
819 lTVLSIM_ServiceContext.getSIMCRS_Service();
820
821 // Delegate the BOM display to the dedicated service
822 return lSIMCRS_Service.sell (iSegmentDateKey, iClassCode,
823 iPartySize);
824 }
825
826 // ////////////////////////////////////////////////////////////////////
828 jsonHandler (const stdair::JSONString& iJSONString) {
829
830 // Retrieve the TvlSim service context
831 if (_tvlsimServiceContext == NULL) {
832 throw stdair::NonInitialisedServiceException ("The TvlSim service "
833 "has not been initialised");
834 }
835 assert (_tvlsimServiceContext != NULL);
836 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
837
838 //
839 // Extract from the JSON-ified string the command
840 //
841 stdair::JSonCommand::EN_JSonCommand lEN_JSonCommand;
842 const bool hasCommandBeenRetrieved =
843 stdair::BomJSONImport::jsonImportCommand (iJSONString,
844 lEN_JSonCommand);
845
846 if (hasCommandBeenRetrieved == false) {
847 // Return an error JSON-ified string
848 std::ostringstream oErrorStream;
849 oErrorStream << "{\"error\": \"Wrong JSON-ified string: "
850 << "the command is not understood.\"}";
851 return oErrorStream.str();
852 }
853 assert (hasCommandBeenRetrieved == true);
854
855 //
856 // Dispatch the command to the right JSon service handler
857 //
858 switch (lEN_JSonCommand) {
859 case stdair::JSonCommand::FLIGHT_DATE:
860 case stdair::JSonCommand::LIST:{
861
862 // Get a reference on the SIMCRS service handler
863 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
864 lTVLSIM_ServiceContext.getSIMCRS_Service();
865
866 return lSIMCRS_Service.jsonHandler (iJSONString);
867 }
868 case stdair::JSonCommand::EVENT_LIST:{
869
870 // Get a reference on the TRADEMGEN service handler
871 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
872 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
873
874 return lTRADEMGEN_Service.jsonHandler (iJSONString);
875 }
876 case stdair::JSonCommand::BREAK_POINT:{
877 return jsonBreakPointHandler (iJSONString);
878 }
879 case stdair::JSonCommand::RUN:{
880 return jsonRunHandler (iJSONString);
881 }
882 case stdair::JSonCommand::RESET:{
883 reset();
884 // Return a JSON-ified string
885 std::ostringstream oStream;
886 oStream << "{\"done\": \"1\"}";
887 return oStream.str();
888 }
889 case stdair::JSonCommand::STATUS:{
890 // Get a reference on the Simulation Status
891 SimulationStatus& lSimulationStatus =
892 lTVLSIM_ServiceContext.getSimulationStatus();
893 std::ostringstream oStream;
894 BomJSONExport::jsonExportSimulationStatus(oStream, lSimulationStatus);
895 return oStream.str();
896 }
897 case stdair::JSonCommand::CONFIG:{
898 // Retrieve the StdAir service object from the (TvlSim) service context
899 stdair::STDAIR_Service& lSTDAIR_Service =
900 lTVLSIM_ServiceContext.getSTDAIR_Service();
901 // Try to import the JSON-ified string
902 lSTDAIR_Service.jsonImportConfiguration (iJSONString);
903 // Display the new configuration tree
904 return lSTDAIR_Service.jsonExportConfiguration();
905 }
906 default: {
907 // Return an Error string
908 std::ostringstream lErrorCmdMessage;
909 const std::string& lCommandStr =
910 stdair::JSonCommand::getLabel(lEN_JSonCommand);
911 lErrorCmdMessage << "{\"error\": \"The command '" << lCommandStr
912 << "' is not handled by the TvlSim service.\"}";
913 return lErrorCmdMessage.str();
914 break;
915 }
916 }
917
918 // Return an error JSON-ified string
919 assert (false);
920 std::string lJSONDump ("{\"error\": \"Wrong JSON-ified string\"}");
921 return lJSONDump;
922 }
923
924 // ////////////////////////////////////////////////////////////////////
925 std::string TVLSIM_Service::
926 jsonBreakPointHandler (const stdair::JSONString& iJSONString) {
927
928 stdair::BreakPointList_T lBreakPointList;
929
930 const bool hasBreakPointListBeenRetrieved =
931 stdair::BomJSONImport::jsonImportBreakPoints(iJSONString,
932 lBreakPointList);
933
934 if (hasBreakPointListBeenRetrieved == false) {
935 // Return an error JSON-ified string
936 std::ostringstream oErrorStream;
937 oErrorStream << "{\"error\": \"Wrong JSON-ified string: "
938 << "the break point list is not understood.\"}";
939 return oErrorStream.str();
940 }
941 assert (hasBreakPointListBeenRetrieved == true);
942
943 const stdair::Count_T lBreakPointsListSize =
944 lBreakPointList.size();
945 const stdair::Count_T lNumberOfBreakPointsAdded =
946 initBreakPointEvents (lBreakPointList);
947
948 // Return a JSON-ified string
949 std::ostringstream oStream;
950 if (lNumberOfBreakPointsAdded != lBreakPointsListSize) {
951 oStream << "{\"failed: \"" << lNumberOfBreakPointsAdded << "\"}";
952 } else {
953 oStream << "{\"done\": \"" << lBreakPointList.size() << "\"}";
954 }
955 return oStream.str();
956 }
957
958 // ////////////////////////////////////////////////////////////////////
959 std::string TVLSIM_Service::
960 jsonRunHandler (const stdair::JSONString& iJSONString) {
961
962 // Retrieve the TvlSim service context
963 if (_tvlsimServiceContext == NULL) {
964 throw stdair::NonInitialisedServiceException ("The TvlSim service "
965 "has not been initialised");
966 }
967 assert (_tvlsimServiceContext != NULL);
968 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
969
970 // Launch the simulation
971 simulate ();
972
973 // Get a reference on the Simulation Status
974 SimulationStatus& lSimulationStatus =
975 lTVLSIM_ServiceContext.getSimulationStatus();
976
977 // Return a JSON-ified string
978 std::ostringstream oStream;
979 oStream << "{\"done\": \""
980 << lSimulationStatus.getCurrentDate() << "\"}";
981 return oStream.str();
982 }
983
984 // ////////////////////////////////////////////////////////////////////
985 const stdair::Count_T TVLSIM_Service::
986 initBreakPointEvents(const stdair::BreakPointList_T& iBreakPointList) {
987 // Retrieve the TvlSim service context
988 if (_tvlsimServiceContext == NULL) {
989 throw stdair::NonInitialisedServiceException ("The TvlSim service "
990 "has not been initialised");
991 }
992 assert (_tvlsimServiceContext != NULL);
993 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
994
995 // Get a reference on the TRADEMGEN service handler
996 const TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
997 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
998
999 // Retrieve the SEvMgr service context
1000 SEVMGR::SEVMGR_Service& lSEVMGR_Service =
1001 lTVLSIM_ServiceContext.getSEVMGR_Service();
1002
1003 // Get a reference on the Simulation Status
1004 SimulationStatus& lSimulationStatus =
1005 lTVLSIM_ServiceContext.getSimulationStatus();
1006
1007 return Simulator::initialiseBreakPoint (lTRADEMGEN_Service,
1008 lSEVMGR_Service,
1009 iBreakPointList,
1010 lSimulationStatus);
1011
1012 }
1013
1014 // ////////////////////////////////////////////////////////////////////
1016 // Retrieve the TvlSim service context
1017 if (_tvlsimServiceContext == NULL) {
1018 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1019 "has not been initialised");
1020 }
1021 assert (_tvlsimServiceContext != NULL);
1022 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1023
1024 // Get a reference on the Simulation Status
1025 SimulationStatus& lSimulationStatus =
1026 lTVLSIM_ServiceContext.getSimulationStatus();
1027
1028 // Retrieve the simulation parameters
1029 const stdair::Date_T& lStartDate = lSimulationStatus.getStartDate();
1030 const stdair::Date_T& lEndDate = lSimulationStatus.getEndDate();
1031
1032 // Get a reference on the SIMCRS service handler
1033 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
1034 lTVLSIM_ServiceContext.getSIMCRS_Service();
1035
1036 lSIMCRS_Service.initSnapshotAndRMEvents (lStartDate, lEndDate);
1037
1038 // Get a reference on the TRADEMGEN service handler
1039 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
1040 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
1041
1042 // Update the Simulation Status
1043 Simulator::updateStatus(lTRADEMGEN_Service, stdair::EventType::RM,
1044 lSimulationStatus);
1045 Simulator::updateStatus(lTRADEMGEN_Service, stdair::EventType::SNAPSHOT,
1046 lSimulationStatus);
1047
1048 }
1049
1050 // //////////////////////////////////////////////////////////////////////
1051 std::string TVLSIM_Service::csvDisplay() const {
1052
1053 // Retrieve the TvlSim service context
1054 if (_tvlsimServiceContext == NULL) {
1055 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1056 "has not been initialised");
1057 }
1058 assert (_tvlsimServiceContext != NULL);
1059
1060 // Retrieve the StdAir service object from the (TvlSim) service context
1061 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1062 stdair::STDAIR_Service& lSTDAIR_Service =
1063 lTVLSIM_ServiceContext.getSTDAIR_Service();
1064 const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
1065
1066 // Delegate the BOM building to the dedicated service
1067 return lSTDAIR_Service.csvDisplay(lBomRoot);
1068 }
1069
1070 // //////////////////////////////////////////////////////////////////////
1071 std::string TVLSIM_Service::listEvents () const {
1072
1073 // Retrieve the TvlSim service context
1074 if (_tvlsimServiceContext == NULL) {
1075 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1076 "has not been initialised");
1077 }
1078 assert (_tvlsimServiceContext != NULL);
1079
1080 // Retrieve the TraDemGen service object from the (TvlSim) service context
1081 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1082
1083 // Get a reference on the TRADEMGEN service handler
1084 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
1085 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
1086
1087 // Delegate the BOM building to the dedicated service
1088 return lTRADEMGEN_Service.list ();
1089
1090 }
1091
1092 // //////////////////////////////////////////////////////////////////////
1094 listEvents (const stdair::EventType::EN_EventType& iEventType) const {
1095
1096 // Retrieve the TvlSim service context
1097 if (_tvlsimServiceContext == NULL) {
1098 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1099 "has not been initialised");
1100 }
1101 assert (_tvlsimServiceContext != NULL);
1102
1103 // Retrieve the TraDemGen service object from the (TvlSim) service context
1104 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1105
1106 // Get a reference on the TRADEMGEN service handler
1107 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
1108 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
1109
1110 // Delegate the BOM building to the dedicated service
1111 return lTRADEMGEN_Service.list (iEventType);
1112
1113 }
1114
1115 // ////////////////////////////////////////////////////////////////////
1117 list (const stdair::AirlineCode_T& iAirlineCode,
1118 const stdair::FlightNumber_T& iFlightNumber) const {
1119
1120 // Retrieve the TvlSim service context
1121 if (_tvlsimServiceContext == NULL) {
1122 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1123 "has not been initialised");
1124 }
1125 assert (_tvlsimServiceContext != NULL);
1126
1127 // Retrieve the SimCRS service object from the (TvlSim) service context
1128 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1129 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
1130 lTVLSIM_ServiceContext.getSIMCRS_Service();
1131
1132 // Delegate the BOM display to the dedicated service
1133 return lSIMCRS_Service.list (iAirlineCode, iFlightNumber);
1134 }
1135
1136 // ////////////////////////////////////////////////////////////////////
1138 csvDisplay (const stdair::AirlineCode_T& iAirlineCode,
1139 const stdair::FlightNumber_T& iFlightNumber,
1140 const stdair::Date_T& iDepartureDate) const {
1141
1142 // Retrieve the TvlSim service context
1143 if (_tvlsimServiceContext == NULL) {
1144 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1145 "has not been initialised");
1146 }
1147 assert (_tvlsimServiceContext != NULL);
1148
1149 // Retrieve the SimCRS service object from the (TvlSim) service context
1150 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1151 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
1152 lTVLSIM_ServiceContext.getSIMCRS_Service();
1153
1154 // Delegate the BOM display to the dedicated service
1155 return lSIMCRS_Service.csvDisplay (iAirlineCode, iFlightNumber,
1156 iDepartureDate);
1157 }
1158
1159 // ////////////////////////////////////////////////////////////////////
1161
1162 // Retrieve the TvlSim service context
1163 if (_tvlsimServiceContext == NULL) {
1164 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1165 "has not been initialised");
1166 }
1167 assert (_tvlsimServiceContext != NULL);
1168
1169 // Retrieve the StdAir service object from the (TvlSim) service context
1170 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1171
1172 // TODO: gsabatier
1173 // Reset everything except break points
1174 // Get a reference on the TRADEMGEN service handler
1175 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
1176 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
1177 // Reset the TRADEMGEN service
1178 lTRADEMGEN_Service.reset();
1179
1180 // TODO
1181 // Get a reference on the SIMCRS service handler
1187 // TODO
1188 // Get a reference on the TRAVELCCM service handler
1194 // Reset the simulation status object
1195 SimulationStatus& lSimulationStatus =
1196 lTVLSIM_ServiceContext.getSimulationStatus();
1197 lSimulationStatus.reset();
1198
1199 // Re-init Snapshot and RMEvents
1201
1202 // Clone again the persistent BOM tree
1203 clonePersistentBom ();
1204
1205 }
1206
1207 // ////////////////////////////////////////////////////////////////////
1208 void TVLSIM_Service::prepareNewRun() {
1209
1210 // Retrieve the TvlSim service context
1211 if (_tvlsimServiceContext == NULL) {
1212 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1213 "has not been initialised");
1214 }
1215 assert (_tvlsimServiceContext != NULL);
1216
1217 // Retrieve the StdAir service object from the (TvlSim) service context
1218 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1219
1220 // Get a reference on the TRADEMGEN service handler
1221 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
1222 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
1223 // Reset the TRADEMGEN service
1224 lTRADEMGEN_Service.reset();
1225
1226 // TODO
1227 // Get a reference on the SIMCRS service handler
1233 // TODO
1234 // Get a reference on the TRAVELCCM service handler
1240 // Prepare a new run in the simulation status object
1241 SimulationStatus& lSimulationStatus =
1242 lTVLSIM_ServiceContext.getSimulationStatus();
1243 lSimulationStatus.prepareNewRun();
1244
1245 // Re-init Snapshot and RMEvents
1247
1248 }
1249
1250 // //////////////////////////////////////////////////////////////////////
1252
1253 // Retrieve the TvlSim service context
1254 if (_tvlsimServiceContext == NULL) {
1255 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1256 "has not been initialised");
1257 }
1258 assert (_tvlsimServiceContext != NULL);
1259
1260 // Retrieve the StdAir service object from the (TvlSim) service context
1261 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1262
1263 // Get a reference on the Simulation Status
1264 const SimulationStatus& lSimulationStatus =
1265 lTVLSIM_ServiceContext.getSimulationStatus();
1266
1267 return lSimulationStatus.describe();
1268 }
1269
1270 // //////////////////////////////////////////////////////////////////////
1272 simulate () {
1273
1274 // Retrieve the TvlSim service context
1275 if (_tvlsimServiceContext == NULL) {
1276 throw stdair::NonInitialisedServiceException ("The TvlSim service has not "
1277 "been initialised");
1278 }
1279 assert (_tvlsimServiceContext != NULL);
1280 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1281
1282 // Get a reference on the Simulation Status
1283 SimulationStatus& lSimulationStatus =
1284 lTVLSIM_ServiceContext.getSimulationStatus();
1285
1286 // Get a reference on the SIMCRS service handler
1287 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
1288 lTVLSIM_ServiceContext.getSIMCRS_Service();
1289
1290 // Get a reference on the TRADEMGEN service handler
1291 TRADEMGEN::TRADEMGEN_Service& lTRADEMGEN_Service =
1292 lTVLSIM_ServiceContext.getTRADEMGEN_Service();
1293
1294 // Get a reference on the TRAVELCCM service handler
1295 TRAVELCCM::TRAVELCCM_Service& lTRAVELCCM_Service =
1296 lTVLSIM_ServiceContext.getTRAVELCCM_Service();
1297
1298 // Get a reference on the STDAIR service handler
1299 stdair::STDAIR_Service& lSTDAIR_Service =
1300 lTVLSIM_ServiceContext.getSTDAIR_Service();
1301
1302 // Extract the demand generation method from the config holder
1303 char lChar;
1304 const bool hasDemandGenMethodBeenRetrieved =
1305 lSTDAIR_Service.exportConfigValue<char> (lChar,
1306 "demand generation.method");
1307 assert (hasDemandGenMethodBeenRetrieved == true);
1308 const stdair::DemandGenerationMethod lDemandGenerationMethod (lChar);
1309
1310 // Get the number of the current run
1311 while (lSimulationStatus.isTheSimulationDone() == false) {
1312
1313 if (lSimulationStatus.getMode() == SimulationMode::DONE) {
1314 prepareNewRun();
1315 }
1316
1317 const NbOfRuns_T& lCurrentRun = lSimulationStatus.getCurrentRun();
1318
1319 // DEBUG
1320 lSimulationStatus.displayStartStatusMessage();
1321 STDAIR_LOG_DEBUG ("Simulation[" << lCurrentRun << "] begins"
1322 << " - " << lTVLSIM_ServiceContext.display());
1323
1324 // Delegate the bookings to the dedicated command
1325 stdair::BasChronometer lSimulationChronometer;
1326 lSimulationChronometer.start();
1327 Simulator::simulate (lSIMCRS_Service, lTRADEMGEN_Service,
1328 lTRAVELCCM_Service, lSTDAIR_Service,
1329 lSimulationStatus, lDemandGenerationMethod);
1330 const double lSimulationMeasure = lSimulationChronometer.elapsed();
1331
1332 // DEBUG
1333 lSimulationStatus.displayEndStatusMessage();
1334 STDAIR_LOG_DEBUG ("Simulation[" << lCurrentRun << "] ends: " << lSimulationMeasure
1335 << " - " << lTVLSIM_ServiceContext.display());
1336
1337 if (lSimulationStatus.getMode() == SimulationMode::BREAK) {
1338 return;
1339 }
1340 }
1341 }
1342
1343 // //////////////////////////////////////////////////////////////////////
1345
1346 // Retrieve the TvlSim service context
1347 if (_tvlsimServiceContext == NULL) {
1348 throw stdair::NonInitialisedServiceException ("The TvlSim service has not "
1349 "been initialised");
1350 }
1351 assert (_tvlsimServiceContext != NULL);
1352 //TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1353
1354 // Get the date-time for the present time
1355 boost::posix_time::ptime lNowDateTime =
1356 boost::posix_time::second_clock::local_time();
1357 //boost::gregorian::date lNowDate = lNowDateTime.date();
1358
1359 // DEBUG
1360 STDAIR_LOG_DEBUG (std::endl
1361 << "==================================================="
1362 << std::endl
1363 << lNowDateTime);
1364
1365 // Delegate the query execution to the dedicated command
1366 stdair::BasChronometer lDsimChronometer;
1367 lDsimChronometer.start();
1368
1369 // Retrieve the database session handler
1370 stdair::DBSession_T& lDBSession =
1371 stdair::DBSessionManager::instance().getDBSession();
1372
1373 // Prepare and execute the select statement
1374 stdair::AirlineStruct lAirline;
1375 stdair::DBRequestStatement_T lSelectStatement (lDBSession);
1376 stdair::DBManagerForAirlines::prepareSelectStatement (lDBSession,
1377 lSelectStatement,
1378 lAirline);
1379
1380 // Prepare the SQL request corresponding to the select statement
1381 bool hasStillData = true;
1382 unsigned int idx = 0;
1383 while (hasStillData == true) {
1384 hasStillData =
1385 stdair::DBManagerForAirlines::iterateOnStatement (lSelectStatement,
1386 lAirline);
1387
1388 // DEBUG
1389 STDAIR_LOG_DEBUG ("[" << idx << "]: " << lAirline);
1390
1391 // Iteration
1392 ++idx;
1393 }
1394
1395 const double lDsimMeasure = lDsimChronometer.elapsed();
1396
1397 // DEBUG
1398 STDAIR_LOG_DEBUG ("Sample service for Dsim: " << lDsimMeasure);
1399 }
1400
1401 // //////////////////////////////////////////////////////////////////////
1402 std::string TVLSIM_Service::configDisplay () const {
1403
1404 // Retrieve the TvlSim service context
1405 if (_tvlsimServiceContext == NULL) {
1406 throw stdair::NonInitialisedServiceException ("The TvlSim service "
1407 "has not been initialised");
1408 }
1409 assert (_tvlsimServiceContext != NULL);
1410 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1411
1412 // Retrieve the StdAir service object from the (TVLSIM) service context
1413 stdair::STDAIR_Service& lSTDAIR_Service =
1414 lTVLSIM_ServiceContext.getSTDAIR_Service();
1415
1416 // Display (dump in the returned string) the configuration.
1417 return lSTDAIR_Service.configDisplay ();
1418 }
1419
1420
1421 // ////////////////////////////////////////////////////////////////////
1422 void TVLSIM_Service::optimise (const stdair::RMEventStruct& iRMEvent) {
1423
1424 // Retrieve the TvlSim service context
1425 if (_tvlsimServiceContext == NULL) {
1426 throw stdair::NonInitialisedServiceException ("The TvlSim service has not "
1427 "been initialised");
1428 }
1429 assert (_tvlsimServiceContext != NULL);
1430 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1431
1432 // Get a reference on the SIMCRS service handler
1433 SIMCRS::SIMCRS_Service& lSIMCRS_Service =
1434 lTVLSIM_ServiceContext.getSIMCRS_Service();
1435
1436 // Call the dedicated service
1437 lSIMCRS_Service.optimise (iRMEvent);
1438 }
1439
1440 // ////////////////////////////////////////////////////////////////////
1442
1443 // Retrieve the TvlSim service context
1444 if (_tvlsimServiceContext == NULL) {
1445 throw stdair::NonInitialisedServiceException ("The TvlSim service has not "
1446 "been initialised");
1447 }
1448 assert (_tvlsimServiceContext != NULL);
1449 TVLSIM_ServiceContext& lTVLSIM_ServiceContext = *_tvlsimServiceContext;
1450
1451 return lTVLSIM_ServiceContext.getSimulationStatus();
1452
1453 }
1454}
static void jsonExportSimulationStatus(std::ostream &, const SimulationStatus &)
static void updateSimulationStatus(stdair::STDAIR_Service &, SimulationStatus &, const stdair::Date_T &iStartDate, const stdair::Date_T &iEndDate, const NbOfRuns_T &)
static void importINI(stdair::STDAIR_Service &, const stdair::Date_T &iStartDate, const stdair::Date_T &iEndDate, const stdair::RandomSeed_T &, const stdair::DemandGenerationMethod &, const NbOfRuns_T &)
static void importFiles(stdair::STDAIR_Service &, const stdair::ScheduleFilePath &, const stdair::ODFilePath &, const stdair::FRAT5FilePath &, const stdair::FFDisutilityFilePath &, const AIRRAC::YieldFilePath &, const SIMFQT::FareFilePath &, const TRADEMGEN::DemandFilePath &)
static FacDsimServiceContext & instance()
Class holding the context of the Dsim services.
stdair::BookingRequestStruct buildSampleBookingRequest(const bool isForCRS=false)
std::string jsonHandler(const stdair::JSONString &)
void buildSampleTravelSolutions(stdair::TravelSolutionList_T &)
std::string csvDisplay() const
void optimise(const stdair::RMEventStruct &)
void displayAirlineListFromDB() const
void setInputFiles(const stdair::ScheduleFilePath &, const stdair::ODFilePath &, const stdair::FRAT5FilePath &, const stdair::FFDisutilityFilePath &, const AIRRAC::YieldFilePath &, const SIMFQT::FareFilePath &, const TRADEMGEN::DemandFilePath &)
std::string simulationStatusDisplay() const
const stdair::Count_T initBreakPointEvents(const stdair::BreakPointList_T &)
bool sell(const std::string &iSegmentDateKey, const stdair::ClassCode_T &, const stdair::PartySize_T &)
std::string configDisplay() const
std::string list(const stdair::AirlineCode_T &iAirlineCode="all", const stdair::FlightNumber_T &iFlightNumber=0) const
const SimulationStatus & getSimulationStatus()
std::string listEvents() const
unsigned int NbOfRuns_T
unsigned int NbOfRuns_T
Definition simulate.cpp:28
const stdair::Date_T & getEndDate() const
SimulationMode::EN_SimulationMode getMode() const
const std::string describe() const
const stdair::Date_T & getStartDate() const
const NbOfRuns_T & getCurrentRun() const