$treeview $search $mathjax
AirSched Logo  1.00.0
$projectbrief
$projectbrief
$searchbox

SegmentPathProvider.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <string>
00007 #include <sstream>
00008 // StdAir
00009 #include <stdair/basic/BasConst_BomDisplay.hpp>
00010 #include <stdair/bom/BomManager.hpp>
00011 #include <stdair/bom/BomRoot.hpp>
00012 #include <stdair/bom/Inventory.hpp>
00013 #include <stdair/bom/FlightPeriod.hpp>
00014 #include <stdair/bom/SegmentPeriod.hpp>
00015 #include <stdair/bom/BookingRequestStruct.hpp>
00016 #include <stdair/bom/TravelSolutionStruct.hpp>
00017 #include <stdair/service/Logger.hpp>
00018 // AirSched
00019 #include <airsched/basic/BasConst_General.hpp>
00020 #include <airsched/bom/ReachableUniverse.hpp>
00021 #include <airsched/bom/OriginDestinationSet.hpp>
00022 #include <airsched/bom/SegmentPathPeriod.hpp>
00023 #include <airsched/command/SegmentPathProvider.hpp>
00024 
00025 namespace AIRSCHED {
00026 
00027   // ////////////////////////////////////////////////////////////////////
00028   void SegmentPathProvider::
00029   buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
00030                         const stdair::BomRoot& iBomRoot,
00031                         const stdair::BookingRequestStruct& iBookingRequest) {
00032     // Retrieve  the reachable  universe object  corresponding  to the
00033     // origin of the booking request.
00034     const stdair::AirportCode_T& lOrigin = iBookingRequest.getOrigin ();
00035     const ReachableUniverse* lReachableUniverse_ptr =
00036       stdair::BomManager::getObjectPtr<ReachableUniverse> (iBomRoot, lOrigin);
00037     if (lReachableUniverse_ptr != NULL) {
00038       buildSegmentPathList (ioTravelSolutionList, *lReachableUniverse_ptr,
00039                             iBookingRequest);
00040     }
00041   }
00042 
00043   // ////////////////////////////////////////////////////////////////////
00044   void SegmentPathProvider::
00045   buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
00046                         const ReachableUniverse& iReachableUniverse,
00047                         const stdair::BookingRequestStruct& iBookingRequest) {
00048     // Retrieve the origin-destination set objet correponding to the
00049     // destination of the booking request.
00050     const stdair::AirportCode_T& lDestination = iBookingRequest.getDestination();
00051     const OriginDestinationSet* lOriginDestinationSet_ptr =
00052       stdair::BomManager::getObjectPtr<OriginDestinationSet> (iReachableUniverse,
00053                                                               lDestination);
00054     if (lOriginDestinationSet_ptr != NULL) {
00055       buildSegmentPathList (ioTravelSolutionList, *lOriginDestinationSet_ptr,
00056                             iBookingRequest);
00057     }
00058   }
00059 
00060   // ////////////////////////////////////////////////////////////////////
00061   void SegmentPathProvider::
00062   buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
00063                         const OriginDestinationSet& iOriginDestinationSet,
00064                         const stdair::BookingRequestStruct& iBookingRequest) {
00065     // Retrieve the departure date of the booking request.
00066     const stdair::Date_T& lPreferedDepartureDate =
00067       iBookingRequest.getPreferedDepartureDate ();
00068 
00069     // Browse the list of segment path periods and find those which content
00070     // the prefered departure date.
00071     const SegmentPathPeriodList_T& lSegmentPathPeriodList =
00072       stdair::BomManager::getList<SegmentPathPeriod> (iOriginDestinationSet);
00073     for (SegmentPathPeriodList_T::const_iterator itSegmentPath =
00074            lSegmentPathPeriodList.begin ();
00075          itSegmentPath != lSegmentPathPeriodList.end (); ++itSegmentPath) {
00076       const SegmentPathPeriod* lCurrentSegmentPath_ptr = *itSegmentPath;
00077       assert (lCurrentSegmentPath_ptr != NULL);
00078       if (lCurrentSegmentPath_ptr->isDepartureDateValid(lPreferedDepartureDate)){
00079         const stdair::DateTime_T lRequestDateTime =
00080           iBookingRequest.getRequestDateTime();
00081         const stdair::Duration_T& lBoardingTime =
00082           lCurrentSegmentPath_ptr->getBoardingTime();
00083         const stdair::DateTime_T lDepartureDateTime (lPreferedDepartureDate,
00084                                                      lBoardingTime);
00085         const bool IsDepartureDateValid =
00086           ((lRequestDateTime + MINIMUM_TIME_BETWEEN_REQUEST_AND_DEPARTURE) <= lDepartureDateTime);
00087         if (IsDepartureDateValid == false) {
00088             return;
00089         }
00090         buildSegmentPathList (ioTravelSolutionList, *lCurrentSegmentPath_ptr,
00091                               iBookingRequest);
00092       }
00093     }
00094   } 
00095 
00096   // ////////////////////////////////////////////////////////////////////
00097   void SegmentPathProvider::
00098   buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
00099                         const SegmentPathPeriod& iSegmentPathPeriod,
00100                         const stdair::BookingRequestStruct& iBookingRequest) {
00101     // Create a new travel solution.
00102     stdair::TravelSolutionStruct lTravelSolution;
00103     
00104     // Browse the list of segments and retrieve the necessary informations
00105     // for identifying the corresponding segment-date.
00106     const stdair::Date_T& lPreferedDepartureDate =
00107       iBookingRequest.getPreferedDepartureDate ();
00108     const stdair::SegmentPeriodList_T& lSegmentPeriodList =
00109       stdair::BomManager::getList<stdair::SegmentPeriod> (iSegmentPathPeriod);
00110     const DateOffsetList_T& lBoardingDateOffsetList =
00111       iSegmentPathPeriod.getBoardingDateOffsetList ();
00112     assert (lSegmentPeriodList.size() == lBoardingDateOffsetList.size());
00113     DateOffsetList_T::const_iterator itOffset = lBoardingDateOffsetList.begin();
00114     for (stdair::SegmentPeriodList_T::const_iterator itSegment =
00115            lSegmentPeriodList.begin();
00116          itSegment != lSegmentPeriodList.end(); ++itSegment) {
00117       const stdair::SegmentPeriod* lSegmentPeriod_ptr = *itSegment;
00118       assert (lSegmentPeriod_ptr != NULL);
00119       const stdair::DateOffset_T& lBoardingDateOffset = *itOffset;
00120 
00121       // Find the corresponding segment-date within the segment period.
00122       const stdair::DateOffset_T& lSegmentBoardingDateOffset =
00123         lSegmentPeriod_ptr->getBoardingDateOffset();
00124       const stdair::Date_T& lReferenceFlightDate = lPreferedDepartureDate 
00125         + lBoardingDateOffset - lSegmentBoardingDateOffset;
00126 
00127       // Build the whole segment-date key string.
00128       const stdair::FlightPeriod& lFlightPeriod =
00129         stdair::BomManager::getParent<stdair::FlightPeriod>(*lSegmentPeriod_ptr);
00130       const stdair::Inventory& lInventory =
00131         stdair::BomManager::getParent<stdair::Inventory> (lFlightPeriod);
00132       const stdair::Duration_T lBoardingTime = lSegmentPeriod_ptr->getBoardingTime();
00133       std::ostringstream oStr;
00134       oStr << lInventory.getAirlineCode()
00135            << stdair::DEFAULT_KEY_FLD_DELIMITER
00136            << lFlightPeriod.getFlightNumber()
00137            << stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
00138            << boost::gregorian::to_simple_string (lReferenceFlightDate)
00139            << stdair::DEFAULT_KEY_FLD_DELIMITER
00140            << lSegmentPeriod_ptr->getBoardingPoint()
00141            << stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
00142            << lSegmentPeriod_ptr->getOffPoint()
00143            << stdair::DEFAULT_KEY_FLD_DELIMITER
00144            << lBoardingTime;
00145 
00146       lTravelSolution.addSegment (oStr.str());
00147 
00148       ++itOffset;
00149     }
00150     ioTravelSolutionList.push_back (lTravelSolution);
00151   }
00152 
00153 }