AirSched Logo  0.1.4
C++ Simulated Airline Schedule Manager Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SegmentPathProvider.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <string>
7 #include <sstream>
8 // StdAir
9 #include <stdair/basic/BasConst_BomDisplay.hpp>
10 #include <stdair/bom/BomManager.hpp>
11 #include <stdair/bom/BomRoot.hpp>
12 #include <stdair/bom/Inventory.hpp>
13 #include <stdair/bom/FlightPeriod.hpp>
14 #include <stdair/bom/SegmentPeriod.hpp>
15 #include <stdair/bom/BookingRequestStruct.hpp>
16 #include <stdair/bom/TravelSolutionStruct.hpp>
17 #include <stdair/service/Logger.hpp>
18 // AirSched
23 
24 namespace AIRSCHED {
25 
26  // ////////////////////////////////////////////////////////////////////
27  void SegmentPathProvider::
28  buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
29  const stdair::BomRoot& iBomRoot,
30  const stdair::BookingRequestStruct& iBookingRequest) {
31  // Retrieve the reachable universe object corresponding to the
32  // origin of the booking request.
33  const stdair::AirportCode_T& lOrigin = iBookingRequest.getOrigin ();
34  const ReachableUniverse* lReachableUniverse_ptr =
35  stdair::BomManager::getObjectPtr<ReachableUniverse> (iBomRoot, lOrigin);
36  if (lReachableUniverse_ptr != NULL) {
37  buildSegmentPathList (ioTravelSolutionList, *lReachableUniverse_ptr,
38  iBookingRequest);
39  }
40  }
41 
42  // ////////////////////////////////////////////////////////////////////
43  void SegmentPathProvider::
44  buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
45  const ReachableUniverse& iReachableUniverse,
46  const stdair::BookingRequestStruct& iBookingRequest) {
47  // Retrieve the origin-destination set objet correponding to the
48  // destination of the booking request.
49  const stdair::AirportCode_T& lDestination = iBookingRequest.getDestination();
50  const OriginDestinationSet* lOriginDestinationSet_ptr =
51  stdair::BomManager::getObjectPtr<OriginDestinationSet> (iReachableUniverse,
52  lDestination);
53  if (lOriginDestinationSet_ptr != NULL) {
54  buildSegmentPathList (ioTravelSolutionList, *lOriginDestinationSet_ptr,
55  iBookingRequest);
56  }
57  }
58 
59  // ////////////////////////////////////////////////////////////////////
60  void SegmentPathProvider::
61  buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
62  const OriginDestinationSet& iOriginDestinationSet,
63  const stdair::BookingRequestStruct& iBookingRequest) {
64  // Retrieve the departure date of the booking request.
65  const stdair::Date_T& lPreferedDepartureDate =
66  iBookingRequest.getPreferedDepartureDate ();
67 
68  // Browse the list of segment path periods and find those which content
69  // the prefered departure date.
70  const SegmentPathPeriodList_T& lSegmentPathPeriodList =
71  stdair::BomManager::getList<SegmentPathPeriod> (iOriginDestinationSet);
72  for (SegmentPathPeriodList_T::const_iterator itSegmentPath =
73  lSegmentPathPeriodList.begin ();
74  itSegmentPath != lSegmentPathPeriodList.end (); ++itSegmentPath) {
75  const SegmentPathPeriod* lCurrentSegmentPath_ptr = *itSegmentPath;
76  assert (lCurrentSegmentPath_ptr != NULL);
77  if (lCurrentSegmentPath_ptr->isDepartureDateValid(lPreferedDepartureDate)){
78  buildSegmentPathList (ioTravelSolutionList, *lCurrentSegmentPath_ptr,
79  iBookingRequest);
80  }
81  }
82  }
83 
84  // ////////////////////////////////////////////////////////////////////
85  void SegmentPathProvider::
86  buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
87  const SegmentPathPeriod& iSegmentPathPeriod,
88  const stdair::BookingRequestStruct& iBookingRequest) {
89  // Create a new travel solution.
90  stdair::TravelSolutionStruct lTravelSolution;
91 
92  // Browse the list of segments and retrieve the necessary informations
93  // for identifying the corresponding segment-date.
94  const stdair::Date_T& lPreferedDepartureDate =
95  iBookingRequest.getPreferedDepartureDate ();
96  const stdair::SegmentPeriodList_T& lSegmentPeriodList =
97  stdair::BomManager::getList<stdair::SegmentPeriod> (iSegmentPathPeriod);
98  const DateOffsetList_T& lBoardingDateOffsetList =
99  iSegmentPathPeriod.getBoardingDateOffsetList ();
100  assert (lSegmentPeriodList.size() == lBoardingDateOffsetList.size());
101  DateOffsetList_T::const_iterator itOffset = lBoardingDateOffsetList.begin();
102  for (stdair::SegmentPeriodList_T::const_iterator itSegment =
103  lSegmentPeriodList.begin();
104  itSegment != lSegmentPeriodList.end(); ++itSegment) {
105  const stdair::SegmentPeriod* lSegmentPeriod_ptr = *itSegment;
106  assert (lSegmentPeriod_ptr != NULL);
107  const stdair::DateOffset_T& lBoardingDateOffset = *itOffset;
108 
109  // Find the corresponding segment-date within the segment period.
110  const stdair::DateOffset_T& lSegmentBoardingDateOffset =
111  lSegmentPeriod_ptr->getBoardingDateOffset();
112  const stdair::Date_T& lReferenceFlightDate = lPreferedDepartureDate
113  + lBoardingDateOffset - lSegmentBoardingDateOffset;
114 
115  // Build the whole segment-date key string.
116  const stdair::FlightPeriod& lFlightPeriod =
117  stdair::BomManager::getParent<stdair::FlightPeriod>(*lSegmentPeriod_ptr);
118  const stdair::Inventory& lInventory =
119  stdair::BomManager::getParent<stdair::Inventory> (lFlightPeriod);
120  const stdair::Duration_T lBoardingTime = lSegmentPeriod_ptr->getBoardingTime();
121  std::ostringstream oStr;
122  oStr << lInventory.getAirlineCode()
123  << stdair::DEFAULT_KEY_FLD_DELIMITER
124  << lFlightPeriod.getFlightNumber()
125  << stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
126  << boost::gregorian::to_simple_string (lReferenceFlightDate)
127  << stdair::DEFAULT_KEY_FLD_DELIMITER
128  << lSegmentPeriod_ptr->getBoardingPoint()
129  << stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
130  << lSegmentPeriod_ptr->getOffPoint()
131  << stdair::DEFAULT_KEY_FLD_DELIMITER
132  << lBoardingTime;
133 
134  lTravelSolution.addSegment (oStr.str());
135 
136  ++itOffset;
137  }
138  ioTravelSolutionList.push_back (lTravelSolution);
139  }
140 
141 }