Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006 #include <vector>
00007
00008 #include <stdair/basic/BasConst_Inventory.hpp>
00009 #include <stdair/bom/BomManager.hpp>
00010 #include <stdair/bom/BomRoot.hpp>
00011 #include <stdair/bom/Inventory.hpp>
00012 #include <stdair/bom/FlightPeriod.hpp>
00013 #include <stdair/bom/SegmentPeriod.hpp>
00014 #include <stdair/factory/FacBomManager.hpp>
00015 #include <stdair/service/Logger.hpp>
00016
00017 #include <airsched/bom/ReachableUniverse.hpp>
00018 #include <airsched/bom/OriginDestinationSet.hpp>
00019 #include <airsched/bom/SegmentPathPeriod.hpp>
00020 #include <airsched/command/SegmentPathGenerator.hpp>
00021
00022 namespace AIRSCHED {
00023
00024
00025 void SegmentPathGenerator::
00026 createSegmentPathNetwork (const stdair::BomRoot& iBomRoot) {
00027
00028
00029 const stdair::InventoryList_T& lInventoryList =
00030 stdair::BomManager::getList<stdair::Inventory> (iBomRoot);
00031 for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
00032 itInv != lInventoryList.end(); ++itInv) {
00033 const stdair::Inventory* lCurrentInventory_ptr = *itInv;
00034 assert (lCurrentInventory_ptr != NULL);
00035
00036
00037 createSinglePaths (*lCurrentInventory_ptr);
00038 }
00039
00040
00041
00042 for (stdair::NbOfSegments_T i = 2;
00043 i <= stdair::MAXIMAL_NUMBER_OF_SEGMENTS_IN_OND; ++i) {
00044 buildSegmentPathNetwork (iBomRoot, i);
00045 }
00046 }
00047
00048
00049 void SegmentPathGenerator::
00050 createSinglePaths (const stdair::Inventory& iInventory) {
00051
00052 const stdair::FlightPeriodList_T& lFlightPeriodList =
00053 stdair::BomManager::getList<stdair::FlightPeriod> (iInventory);
00054 for (stdair::FlightPeriodList_T::const_iterator itFlightPeriod =
00055 lFlightPeriodList.begin();
00056 itFlightPeriod != lFlightPeriodList.end(); ++itFlightPeriod) {
00057 const stdair::FlightPeriod* lCurrentFlightPeriod_ptr = *itFlightPeriod;
00058 assert (lCurrentFlightPeriod_ptr != NULL);
00059
00060
00061 createSinglePaths (*lCurrentFlightPeriod_ptr);
00062 }
00063 }
00064
00065
00066 void SegmentPathGenerator::
00067 createSinglePaths (const stdair::FlightPeriod& iFlightPeriod) {
00068
00069 const stdair::SegmentPeriodList_T& lSegmentPeriodList =
00070 stdair::BomManager::getList<stdair::SegmentPeriod> (iFlightPeriod);
00071 for (stdair::SegmentPeriodList_T::const_iterator itSegmentPeriod =
00072 lSegmentPeriodList.begin();
00073 itSegmentPeriod != lSegmentPeriodList.end(); ++itSegmentPeriod) {
00074 stdair::SegmentPeriod* lCurrentSegmentPeriod_ptr = *itSegmentPeriod;
00075 assert (lCurrentSegmentPeriod_ptr != NULL);
00076
00077
00078 createSinglePath (*lCurrentSegmentPeriod_ptr);
00079 }
00080 }
00081
00082
00083 void SegmentPathGenerator::
00084 createSinglePath (stdair::SegmentPeriod& ioSegmentPeriod) {
00085
00086
00087 const stdair::AirportCode_T& lOrigin = ioSegmentPeriod.getBoardingPoint();
00088 const stdair::FlightPeriod& lFlightPeriod =
00089 stdair::BomManager::getParent<stdair::FlightPeriod> (ioSegmentPeriod);
00090 const stdair::Inventory& lInventory =
00091 stdair::BomManager::getParent<stdair::Inventory> (lFlightPeriod);
00092 stdair::BomRoot& lBomRoot =
00093 stdair::BomManager::getParent<stdair::BomRoot> (lInventory);
00094
00095
00096
00097 ReachableUniverse* lReachableUniverse_ptr =
00098 stdair::BomManager::getObjectPtr<ReachableUniverse> (lBomRoot, lOrigin);
00099 if (lReachableUniverse_ptr == NULL) {
00100 ReachableUniverseKey lKey (lOrigin);
00101 lReachableUniverse_ptr =
00102 &stdair::FacBom<ReachableUniverse>::instance().create (lKey);
00103 stdair::FacBomManager::addToListAndMap (lBomRoot, *lReachableUniverse_ptr);
00104 stdair::FacBomManager::linkWithParent (lBomRoot, *lReachableUniverse_ptr);
00105 }
00106 assert (lReachableUniverse_ptr != NULL);
00107
00108
00109 createSinglePath (*lReachableUniverse_ptr, ioSegmentPeriod);
00110 }
00111
00112
00113 void SegmentPathGenerator::
00114 createSinglePath (ReachableUniverse& ioReachableUniverse,
00115 stdair::SegmentPeriod& ioSegmentPeriod) {
00116
00117 const stdair::AirportCode_T& lDestination = ioSegmentPeriod.getOffPoint();
00118
00119
00120
00121 OriginDestinationSet* lOriginDestinationSet_ptr =
00122 stdair::BomManager::getObjectPtr<OriginDestinationSet>(ioReachableUniverse,
00123 lDestination);
00124 if (lOriginDestinationSet_ptr == NULL) {
00125 OriginDestinationSetKey lKey (lDestination);
00126
00127 lOriginDestinationSet_ptr =
00128 &stdair::FacBom<OriginDestinationSet>::instance().create (lKey);
00129 stdair::FacBomManager::addToListAndMap (ioReachableUniverse,
00130 *lOriginDestinationSet_ptr);
00131 stdair::FacBomManager::linkWithParent (ioReachableUniverse,
00132 *lOriginDestinationSet_ptr);
00133 }
00134 assert (lOriginDestinationSet_ptr != NULL);
00135
00136
00137
00138 const stdair::FlightPeriod& lFlightPeriod =
00139 stdair::BomManager::getParent<stdair::FlightPeriod> (ioSegmentPeriod);
00140 const stdair::PeriodStruct& lPeriodOfFlight = lFlightPeriod.getPeriod();
00141
00142
00143
00144 const stdair::DateOffset_T& lBoardingDateOffset =
00145 ioSegmentPeriod.getBoardingDateOffset();
00146
00147 const stdair::PeriodStruct lPeriodOfSegment =
00148 lPeriodOfFlight.addDateOffset (lBoardingDateOffset);
00149
00150 const stdair::Duration_T& lBoardingTime = ioSegmentPeriod.getBoardingTime();
00151 const stdair::Duration_T& lElapsed = ioSegmentPeriod.getElapsedTime();
00152
00153 DateOffsetList_T lDateOffsetList;
00154 const stdair::DateOffset_T lFirstDateOffset (0);
00155 lDateOffsetList.push_back (lFirstDateOffset);
00156
00157 const SegmentPathPeriodKey lSegmentPathKey (lPeriodOfSegment,
00158 lBoardingTime, lElapsed,
00159 lDateOffsetList, 1);
00160
00161 SegmentPathPeriod& lSegmentPathPeriod =
00162 stdair::FacBom<SegmentPathPeriod>::instance().create (lSegmentPathKey);
00163
00170 addSegmentPathPeriod (ioReachableUniverse, lSegmentPathPeriod);
00171
00172
00173
00174 stdair::FacBomManager::addToList (*lOriginDestinationSet_ptr,
00175 lSegmentPathPeriod);
00176 stdair::FacBomManager::linkWithParent (*lOriginDestinationSet_ptr,
00177 lSegmentPathPeriod);
00178
00179
00180
00181 stdair::FacBomManager::addToList (lSegmentPathPeriod,
00182 ioSegmentPeriod);
00183 }
00184
00185
00186 void SegmentPathGenerator::
00187 addSegmentPathPeriod (ReachableUniverse& ioReachableUniverse,
00188 const SegmentPathPeriod& iSegmentPathPeriod) {
00189
00190 const stdair::NbOfSegments_T& lNbOfSegments =
00191 iSegmentPathPeriod.getNbOfSegments();
00192
00193 assert (lNbOfSegments > 0
00194 && lNbOfSegments <= stdair::MAXIMAL_NUMBER_OF_SEGMENTS_IN_OND);
00195
00196
00197
00198
00199 SegmentPathPeriodListList_T& lSegmentPathPeriodListList =
00200 ioReachableUniverse._segmentPathPeriodListList;
00201 while (lSegmentPathPeriodListList.size() < lNbOfSegments) {
00202 SegmentPathPeriodLightList_T lSegmentPathPeriodList;
00203 lSegmentPathPeriodListList.push_back (lSegmentPathPeriodList);
00204 }
00205
00206
00207
00208 SegmentPathPeriodLightList_T& lSegmentPathPeriodList =
00209 lSegmentPathPeriodListList.at (lNbOfSegments-1);
00210
00211
00212 lSegmentPathPeriodList.push_back (&iSegmentPathPeriod);
00213 }
00214
00215
00216 void SegmentPathGenerator::
00217 buildSegmentPathNetwork (const stdair::BomRoot& iBomRoot,
00218 const stdair::NbOfSegments_T& lNbOfSegments) {
00219
00225 const ReachableUniverseList_T& lReachableUniverseList =
00226 stdair::BomManager::getList<ReachableUniverse> (iBomRoot);
00227 for (ReachableUniverseList_T::const_iterator itReachableUniverse =
00228 lReachableUniverseList.begin();
00229 itReachableUniverse != lReachableUniverseList.end();
00230 ++itReachableUniverse) {
00231 ReachableUniverse* lReachableUniverse_ptr = *itReachableUniverse;
00232 assert (lReachableUniverse_ptr != NULL);
00233
00234
00235 buildSegmentPathNetwork (*lReachableUniverse_ptr, lNbOfSegments);
00236 }
00237 }
00238
00239
00240 void SegmentPathGenerator::
00241 buildSegmentPathNetwork (ReachableUniverse& ioReachableUniverse,
00242 const stdair::NbOfSegments_T& iNbOfSegments) {
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 const SegmentPathPeriodListList_T& lSegmentPathPeriodListList =
00262 ioReachableUniverse.getSegmentPathPeriodListList();
00263 const unsigned short lNbOfSegments_m1 = iNbOfSegments - 1;
00264 assert (lNbOfSegments_m1 >= 0);
00265 if (lSegmentPathPeriodListList.size() < lNbOfSegments_m1) {
00266 return;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 const SegmentPathPeriodLightList_T lSegmentPathPeriodLightList_im1 =
00280 lSegmentPathPeriodListList.at (iNbOfSegments-2);
00281
00282
00283
00284
00285
00286
00287
00288
00289 for (SegmentPathPeriodLightList_T::const_iterator itSegmentPathPeriodList =
00290 lSegmentPathPeriodLightList_im1.begin();
00291 itSegmentPathPeriodList != lSegmentPathPeriodLightList_im1.end();
00292 ++itSegmentPathPeriodList) {
00293 const SegmentPathPeriod* lSegmentPathPeriod_im1_ptr =
00294 *itSegmentPathPeriodList;
00295 assert (lSegmentPathPeriod_im1_ptr != NULL);
00296
00297
00298
00299 const stdair::AirportCode_T& lDestination_im1 =
00300 lSegmentPathPeriod_im1_ptr->getDestination();
00301 const stdair::BomRoot& lBomRoot =
00302 stdair::BomManager::getParent<stdair::BomRoot> (ioReachableUniverse);
00303 const ReachableUniverse* lReachableUniverseFromDestination_im1_ptr =
00304 stdair::BomManager::getObjectPtr<ReachableUniverse> (lBomRoot,
00305 lDestination_im1);
00306
00307
00308
00309
00310
00311
00312 if (lReachableUniverseFromDestination_im1_ptr == NULL) {
00313 continue;
00314 }
00315 assert (lReachableUniverseFromDestination_im1_ptr != NULL);
00316
00317
00318
00319 const SegmentPathPeriodListList_T&
00320 lSegmentPathPeriodListListFromDestination_im1 =
00321 lReachableUniverseFromDestination_im1_ptr->
00322 getSegmentPathPeriodListList();
00323 assert (lSegmentPathPeriodListListFromDestination_im1.size() >= 1);
00324
00325
00326
00327
00328
00329 const SegmentPathPeriodLightList_T lSingleSegmentPathPeriodLightListFromDestination_im1 =
00330 lSegmentPathPeriodListListFromDestination_im1.at (0);
00331
00332 for (SegmentPathPeriodLightList_T::const_iterator
00333 itSegmentPathPeriodFromDestination_im1 =
00334 lSingleSegmentPathPeriodLightListFromDestination_im1.begin();
00335 itSegmentPathPeriodFromDestination_im1
00336 != lSingleSegmentPathPeriodLightListFromDestination_im1.end();
00337 ++itSegmentPathPeriodFromDestination_im1) {
00338 const SegmentPathPeriod* lSingleSegmentPathPeriodFromDestination_im1_ptr=
00339 *itSegmentPathPeriodFromDestination_im1;
00340 assert (lSingleSegmentPathPeriodFromDestination_im1_ptr != NULL);
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 SegmentPathPeriodKey lSegmentPathPeriodKey_i =
00355 lSegmentPathPeriod_im1_ptr->connectWithAnotherSegment (*lSingleSegmentPathPeriodFromDestination_im1_ptr);
00356
00357 if (lSegmentPathPeriodKey_i.isValid () == false) {
00358 continue;
00359 }
00360
00361
00362
00363
00364 const stdair::AirportCode_T& lDestination_i =
00365 lSingleSegmentPathPeriodFromDestination_im1_ptr->getDestination();
00366
00367
00368
00369 stdair::SegmentPeriod* lSegmentPeriod_1_ptr =
00370 lSingleSegmentPathPeriodFromDestination_im1_ptr->getFirstSegmentPeriod();
00371 assert (lSegmentPeriod_1_ptr != NULL);
00372
00373
00374
00375 const stdair::FlightPeriod& lFlightPeriod = stdair::BomManager::
00376 getParent<stdair::FlightPeriod> (*lSegmentPeriod_1_ptr);
00377 const stdair::Inventory& lInventory =
00378 stdair::BomManager::getParent<stdair::Inventory> (lFlightPeriod);
00379 const stdair::AirlineCode_T& lAirlineCode_1 =lInventory.getAirlineCode();
00380 stdair::NbOfAirlines_T lNbOfAirlines_i =
00381 lSegmentPathPeriod_im1_ptr->getNbOfAirlines();
00382 if (lSegmentPathPeriod_im1_ptr->isAirlineFlown(lAirlineCode_1) == false){
00383 ++lNbOfAirlines_i;
00384 }
00385 lSegmentPathPeriodKey_i.setNbOfAirlines (lNbOfAirlines_i);
00386
00387
00388 OriginDestinationSet* lOriginDestinationSet_ptr = stdair::BomManager::
00389 getObjectPtr<OriginDestinationSet>(ioReachableUniverse,lDestination_i);
00390 if (lOriginDestinationSet_ptr == NULL) {
00391 OriginDestinationSetKey lKey (lDestination_i);
00392 lOriginDestinationSet_ptr =
00393 &stdair::FacBom<OriginDestinationSet>::instance().create (lKey);
00394 stdair::FacBomManager::addToListAndMap (ioReachableUniverse,
00395 *lOriginDestinationSet_ptr);
00396 stdair::FacBomManager::linkWithParent (ioReachableUniverse,
00397 *lOriginDestinationSet_ptr);
00398 }
00399 assert (lOriginDestinationSet_ptr != NULL);
00400
00401
00402 SegmentPathPeriod& lSegmentPathPeriod_i = stdair::
00403 FacBom<SegmentPathPeriod>::instance().create (lSegmentPathPeriodKey_i);
00404 stdair::FacBomManager::addToList (*lOriginDestinationSet_ptr,
00405 lSegmentPathPeriod_i);
00406 stdair::FacBomManager::linkWithParent (*lOriginDestinationSet_ptr,
00407 lSegmentPathPeriod_i);
00408
00409
00410
00411 stdair::FacBomManager::
00412 cloneHolder<stdair::SegmentPeriod> (lSegmentPathPeriod_i,
00413 *lSegmentPathPeriod_im1_ptr);
00414
00415
00416
00417
00418
00419
00420
00421 stdair::FacBomManager::addToList (lSegmentPathPeriod_i,
00422 *lSegmentPeriod_1_ptr);
00423
00431 addSegmentPathPeriod (ioReachableUniverse, lSegmentPathPeriod_i);
00432 }
00433 }
00434 }
00435 }