AirTSP Logo  1.01.13
C++ Simulated Airline Travel Solution Provider (TSP) Library
Loading...
Searching...
No Matches
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// AirTSP
24
25namespace AIRTSP {
26
27 // ////////////////////////////////////////////////////////////////////
28 void SegmentPathProvider::
29 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
30 const stdair::BomRoot& iBomRoot,
31 const stdair::BookingRequestStruct& iBookingRequest) {
32 // Retrieve the reachable universe object corresponding to the
33 // origin of the booking request.
34 const stdair::AirportCode_T& lOrigin = iBookingRequest.getOrigin ();
35 const ReachableUniverse* lReachableUniverse_ptr =
36 stdair::BomManager::getObjectPtr<ReachableUniverse> (iBomRoot, lOrigin);
37 if (lReachableUniverse_ptr != NULL) {
38 buildSegmentPathList (ioTravelSolutionList, *lReachableUniverse_ptr,
39 iBookingRequest);
40 }
41 }
42
43 // ////////////////////////////////////////////////////////////////////
44 void SegmentPathProvider::
45 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
46 const ReachableUniverse& iReachableUniverse,
47 const stdair::BookingRequestStruct& iBookingRequest) {
48 // Retrieve the origin-destination set objet correponding to the
49 // destination of the booking request.
50 const stdair::AirportCode_T& lDestination = iBookingRequest.getDestination();
51 const OriginDestinationSet* lOriginDestinationSet_ptr =
52 stdair::BomManager::getObjectPtr<OriginDestinationSet> (iReachableUniverse,
53 lDestination);
54 if (lOriginDestinationSet_ptr != NULL) {
55 buildSegmentPathList (ioTravelSolutionList, *lOriginDestinationSet_ptr,
56 iBookingRequest);
57 }
58 }
59
60 // ////////////////////////////////////////////////////////////////////
61 void SegmentPathProvider::
62 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
63 const OriginDestinationSet& iOriginDestinationSet,
64 const stdair::BookingRequestStruct& iBookingRequest) {
65 // Retrieve the departure date of the booking request.
66 const stdair::Date_T& lPreferedDepartureDate =
67 iBookingRequest.getPreferedDepartureDate ();
68
69 // Browse the list of segment path periods and find those which content
70 // the prefered departure date.
71 const SegmentPathPeriodList_T& lSegmentPathPeriodList =
72 stdair::BomManager::getList<SegmentPathPeriod> (iOriginDestinationSet);
73 for (SegmentPathPeriodList_T::const_iterator itSegmentPath =
74 lSegmentPathPeriodList.begin ();
75 itSegmentPath != lSegmentPathPeriodList.end (); ++itSegmentPath) {
76 const SegmentPathPeriod* lCurrentSegmentPath_ptr = *itSegmentPath;
77 assert (lCurrentSegmentPath_ptr != NULL);
78 if (lCurrentSegmentPath_ptr->isDepartureDateValid(lPreferedDepartureDate)){
79 const stdair::DateTime_T lRequestDateTime =
80 iBookingRequest.getRequestDateTime();
81 const stdair::Duration_T& lBoardingTime =
82 lCurrentSegmentPath_ptr->getBoardingTime();
83 const stdair::DateTime_T lDepartureDateTime (lPreferedDepartureDate,
84 lBoardingTime);
85 const bool IsDepartureDateValid =
86 ((lRequestDateTime + MINIMUM_TIME_BETWEEN_REQUEST_AND_DEPARTURE) <= lDepartureDateTime);
87 if (IsDepartureDateValid == false) {
88 return;
89 }
90 buildSegmentPathList (ioTravelSolutionList, *lCurrentSegmentPath_ptr,
91 iBookingRequest);
92 }
93 }
94 }
95
96 // ////////////////////////////////////////////////////////////////////
97 void SegmentPathProvider::
98 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
99 const SegmentPathPeriod& iSegmentPathPeriod,
100 const stdair::BookingRequestStruct& iBookingRequest) {
101 // Create a new travel solution.
102 stdair::TravelSolutionStruct lTravelSolution;
103
104 // Browse the list of segments and retrieve the necessary informations
105 // for identifying the corresponding segment-date.
106 const stdair::Date_T& lPreferedDepartureDate =
107 iBookingRequest.getPreferedDepartureDate ();
108 const stdair::SegmentPeriodList_T& lSegmentPeriodList =
109 stdair::BomManager::getList<stdair::SegmentPeriod> (iSegmentPathPeriod);
110 const DateOffsetList_T& lBoardingDateOffsetList =
111 iSegmentPathPeriod.getBoardingDateOffsetList ();
112 assert (lSegmentPeriodList.size() == lBoardingDateOffsetList.size());
113 DateOffsetList_T::const_iterator itOffset = lBoardingDateOffsetList.begin();
114 for (stdair::SegmentPeriodList_T::const_iterator itSegment =
115 lSegmentPeriodList.begin();
116 itSegment != lSegmentPeriodList.end(); ++itSegment) {
117 const stdair::SegmentPeriod* lSegmentPeriod_ptr = *itSegment;
118 assert (lSegmentPeriod_ptr != NULL);
119 const stdair::DateOffset_T& lBoardingDateOffset = *itOffset;
120
121 // Find the corresponding segment-date within the segment period.
122 const stdair::DateOffset_T& lSegmentBoardingDateOffset =
123 lSegmentPeriod_ptr->getBoardingDateOffset();
124 const stdair::Date_T& lReferenceFlightDate = lPreferedDepartureDate
125 + lBoardingDateOffset - lSegmentBoardingDateOffset;
126
127 // Build the whole segment-date key string.
128 const stdair::FlightPeriod& lFlightPeriod =
129 stdair::BomManager::getParent<stdair::FlightPeriod>(*lSegmentPeriod_ptr);
130 const stdair::Inventory& lInventory =
131 stdair::BomManager::getParent<stdair::Inventory> (lFlightPeriod);
132 const stdair::Duration_T lBoardingTime = lSegmentPeriod_ptr->getBoardingTime();
133 std::ostringstream oStr;
134 oStr << lInventory.getAirlineCode()
135 << stdair::DEFAULT_KEY_FLD_DELIMITER
136 << lFlightPeriod.getFlightNumber()
137 << stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
138 << boost::gregorian::to_simple_string (lReferenceFlightDate)
139 << stdair::DEFAULT_KEY_FLD_DELIMITER
140 << lSegmentPeriod_ptr->getBoardingPoint()
141 << stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
142 << lSegmentPeriod_ptr->getOffPoint()
143 << stdair::DEFAULT_KEY_FLD_DELIMITER
144 << lBoardingTime;
145
146 lTravelSolution.addSegment (oStr.str());
147
148 ++itOffset;
149 }
150 ioTravelSolutionList.push_back (lTravelSolution);
151 }
152
153}
Class representing a simple sub-network.
Class representing the root of the schedule-related BOM tree.
Class representing a segment/path.
const stdair::Duration_T MINIMUM_TIME_BETWEEN_REQUEST_AND_DEPARTURE
std::vector< stdair::DateOffset_T > DateOffsetList_T
std::list< SegmentPathPeriod * > SegmentPathPeriodList_T