Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006
00007 #include <boost/make_shared.hpp>
00008
00009 #include <stdair/basic/BasChronometer.hpp>
00010 #include <stdair/bom/BomDisplay.hpp>
00011 #include <stdair/service/Logger.hpp>
00012 #include <stdair/STDAIR_Service.hpp>
00013
00014 #include <airrac/basic/BasConst_AIRRAC_Service.hpp>
00015 #include <airrac/factory/FacAirracServiceContext.hpp>
00016 #include <airrac/command/YieldParser.hpp>
00017 #include <airrac/command/YieldManager.hpp>
00018 #include <airrac/service/AIRRAC_ServiceContext.hpp>
00019 #include <airrac/AIRRAC_Service.hpp>
00020
00021 namespace AIRRAC {
00022
00023
00024 AIRRAC_Service::AIRRAC_Service() : _airracServiceContext (NULL) {
00025 assert (false);
00026 }
00027
00028
00029 AIRRAC_Service::AIRRAC_Service (const AIRRAC_Service& iService) {
00030 assert (false);
00031 }
00032
00033
00034 AIRRAC_Service::AIRRAC_Service (const stdair::BasLogParams& iLogParams)
00035 : _airracServiceContext (NULL) {
00036
00037
00038 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00039 initStdAirService (iLogParams);
00040
00041
00042 initServiceContext();
00043
00044
00045
00046 const bool ownStdairService = true;
00047 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00048
00049
00050 initAirracService();
00051 }
00052
00053
00054 AIRRAC_Service::AIRRAC_Service (const stdair::BasLogParams& iLogParams,
00055 const stdair::BasDBParams& iDBParams)
00056 : _airracServiceContext (NULL) {
00057
00058
00059 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00060 initStdAirService (iLogParams, iDBParams);
00061
00062
00063 initServiceContext();
00064
00065
00066
00067 const bool ownStdairService = true;
00068 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00069
00070
00071 initAirracService();
00072 }
00073
00074
00075 AIRRAC_Service::
00076 AIRRAC_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
00077 : _airracServiceContext (NULL) {
00078
00079
00080 initServiceContext();
00081
00082
00083
00084 const bool doesNotOwnStdairService = false;
00085 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
00086
00087
00088 initAirracService();
00089 }
00090
00091
00092 AIRRAC_Service::~AIRRAC_Service() {
00093
00094 finalise();
00095 }
00096
00097
00098 void AIRRAC_Service::finalise() {
00099 assert (_airracServiceContext != NULL);
00100
00101 _airracServiceContext->reset();
00102 }
00103
00104
00105 void AIRRAC_Service::initServiceContext() {
00106
00107 AIRRAC_ServiceContext& lAIRRAC_ServiceContext =
00108 FacAirracServiceContext::instance().create();
00109 _airracServiceContext = &lAIRRAC_ServiceContext;
00110 }
00111
00112
00113 stdair::STDAIR_ServicePtr_T AIRRAC_Service::
00114 initStdAirService (const stdair::BasLogParams& iLogParams,
00115 const stdair::BasDBParams& iDBParams) {
00116
00124 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00125 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
00126
00127 return lSTDAIR_Service_ptr;
00128
00129 }
00130
00131
00132 stdair::STDAIR_ServicePtr_T AIRRAC_Service::
00133 initStdAirService (const stdair::BasLogParams& iLogParams) {
00134
00142 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00143 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
00144
00145 return lSTDAIR_Service_ptr;
00146 }
00147
00148
00149 void AIRRAC_Service::
00150 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
00151 const bool iOwnStdairService) {
00152
00153
00154 assert (_airracServiceContext != NULL);
00155 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
00156
00157
00158 lAIRRAC_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
00159 iOwnStdairService);
00160 }
00161
00162
00163 void AIRRAC_Service::initAirracService() {
00164
00165
00166 }
00167
00168
00169 void AIRRAC_Service::
00170 parseAndLoad (const stdair::Filename_T& iYieldInputFilename) {
00171
00172
00173 assert (_airracServiceContext != NULL);
00174 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
00175 stdair::STDAIR_Service& lSTDAIR_Service =
00176 lAIRRAC_ServiceContext.getSTDAIR_Service();
00177 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00178
00179
00180 YieldParser::generateYieldStore (iYieldInputFilename, lBomRoot);
00181 }
00182
00183
00184 void AIRRAC_Service::buildSampleBom() {
00185
00186
00187 if (_airracServiceContext == NULL) {
00188 throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
00189 " been initialised");
00190 }
00191 assert (_airracServiceContext != NULL);
00192
00193
00194
00195 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
00196 const bool doesOwnStdairService =
00197 lAIRRAC_ServiceContext.getOwnStdairServiceFlag();
00198
00199
00200 stdair::STDAIR_Service& lSTDAIR_Service =
00201 lAIRRAC_ServiceContext.getSTDAIR_Service();
00202
00207 if (doesOwnStdairService == true) {
00208
00209 lSTDAIR_Service.buildSampleBom();
00210 }
00211
00227 }
00228
00229
00230 void AIRRAC_Service::
00231 buildSampleTravelSolutions(stdair::TravelSolutionList_T& ioTravelSolutionList){
00232
00233
00234 if (_airracServiceContext == NULL) {
00235 throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
00236 " been initialised");
00237 }
00238 assert (_airracServiceContext != NULL);
00239
00240 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
00241
00242
00243 stdair::STDAIR_Service& lSTDAIR_Service =
00244 lAIRRAC_ServiceContext.getSTDAIR_Service();
00245
00246
00247 lSTDAIR_Service.buildSampleTravelSolutions (ioTravelSolutionList);
00248 }
00249
00250
00251 std::string AIRRAC_Service::csvDisplay() const {
00252
00253
00254 if (_airracServiceContext == NULL) {
00255 throw stdair::NonInitialisedServiceException ("The Airrac service "
00256 "has not been initialised");
00257 }
00258 assert (_airracServiceContext != NULL);
00259
00260 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
00261
00262
00263 stdair::STDAIR_Service& lSTDAIR_Service =
00264 lAIRRAC_ServiceContext.getSTDAIR_Service();
00265
00266
00267
00268 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00269
00270
00271 std::ostringstream oCSVStr;
00272 stdair::BomDisplay::csvSimFQTAirRACDisplay (oCSVStr, lBomRoot);
00273 return oCSVStr.str();
00274
00275 }
00276
00277
00278 std::string AIRRAC_Service::
00279 csvDisplay (const stdair::TravelSolutionList_T& ioTravelSolutionList) const {
00280
00281
00282 if (_airracServiceContext == NULL) {
00283 throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
00284 " been initialised");
00285 }
00286 assert (_airracServiceContext != NULL);
00287
00288
00289 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
00290
00291
00292 stdair::STDAIR_Service& lSTDAIR_Service =
00293 lAIRRAC_ServiceContext.getSTDAIR_Service();
00294
00295
00296 return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
00297 }
00298
00299
00300 void AIRRAC_Service::
00301 calculateYields (stdair::TravelSolutionList_T& ioTravelSolutionList) {
00302
00303
00304 if (_airracServiceContext == NULL) {
00305 throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
00306 " been initialised");
00307 }
00308 assert (_airracServiceContext != NULL);
00309 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
00310
00311
00312 stdair::STDAIR_Service& lSTDAIR_Service =
00313 lAIRRAC_ServiceContext.getSTDAIR_Service();
00314
00315
00316
00317 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00318
00319
00320
00321 stdair::BasChronometer lYieldChronometer;
00322 lYieldChronometer.start();
00323 YieldManager::calculateYield (ioTravelSolutionList, lBomRoot);
00324 const double lYieldMeasure = lYieldChronometer.elapsed();
00325
00326
00327 STDAIR_LOG_DEBUG ("Yield calculation: " << lYieldMeasure << " - "
00328 << lAIRRAC_ServiceContext.display());
00329 }
00330
00331
00332 void AIRRAC_Service::updateYields () {
00333
00334 assert (_airracServiceContext != NULL);
00335 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
00336
00337
00338 stdair::STDAIR_Service& lSTDAIR_Service =
00339 lAIRRAC_ServiceContext.getSTDAIR_Service();
00340
00341
00342
00343 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00344
00345
00346 YieldManager::updateYields (lBomRoot);
00347 }
00348 }