7 #include <stdair/bom/BomRetriever.hpp>
8 #include <stdair/bom/BomManager.hpp>
9 #include <stdair/bom/Inventory.hpp>
10 #include <stdair/bom/FlightDate.hpp>
11 #include <stdair/bom/SegmentDate.hpp>
12 #include <stdair/bom/SegmentCabin.hpp>
13 #include <stdair/bom/FareFamily.hpp>
14 #include <stdair/bom/BookingClass.hpp>
15 #include <stdair/bom/SegmentSnapshotTable.hpp>
16 #include <stdair/bom/TravelSolutionStruct.hpp>
17 #include <stdair/service/Logger.hpp>
18 #include <stdair/bom/LegCabin.hpp>
29 const stdair::FlightDateList_T& lFlightDateList =
30 stdair::BomManager::getList<stdair::FlightDate> (iInventory);
33 for (stdair::FlightDateList_T::const_iterator itFlightDate =
34 lFlightDateList.begin();
35 itFlightDate != lFlightDateList.end(); ++itFlightDate) {
36 const stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate;
37 assert (lCurrentFlightDate_ptr != NULL);
45 const std::string& iFullSegmentDateKey,
46 stdair::TravelSolutionStruct& ioTravelSolution) {
49 stdair::ClassAvailabilityMap_T lClassAvailabilityMap;
52 stdair::ClassObjectIDMap_T lClassObjectIDMap;
55 STDAIR_LOG_DEBUG (iFullSegmentDateKey);
57 stdair::SegmentDate* lSegmentDate_ptr =
58 stdair::BomRetriever::retrieveSegmentDateFromLongKey(iInventory,
60 assert (lSegmentDate_ptr != NULL);
64 const stdair::SegmentCabinList_T& lSegmentCabinList =
65 stdair::BomManager::getList<stdair::SegmentCabin> (*lSegmentDate_ptr);
66 for (stdair::SegmentCabinList_T::const_iterator itCabin =
67 lSegmentCabinList.begin();
68 itCabin != lSegmentCabinList.end(); ++itCabin) {
69 stdair::SegmentCabin* lSegmentCabin_ptr = *itCabin;
70 assert (lSegmentCabin_ptr != NULL);
76 const stdair::BookingClassList_T& lBCList =
77 stdair::BomManager::getList<stdair::BookingClass> (*lSegmentCabin_ptr);
78 for (stdair::BookingClassList_T::const_reverse_iterator itBC =
79 lBCList.rbegin(); itBC != lBCList.rend(); ++itBC) {
80 stdair::BookingClass* lBC_ptr = *itBC;
81 assert (lBC_ptr != NULL);
83 const stdair::Availability_T lAvl = lBC_ptr->getSegmentAvailability();
85 const stdair::ClassCode_T& lClassCode = lBC_ptr->getClassCode();
86 bool insertSuccessful = lClassAvailabilityMap.
87 insert (stdair::ClassAvailabilityMap_T::value_type (lClassCode,
89 assert (insertSuccessful ==
true);
91 stdair::BookingClassID_T lBCID (*lBC_ptr);
92 insertSuccessful = lClassObjectIDMap.
93 insert (stdair::ClassObjectIDMap_T::value_type (lClassCode,
95 assert (insertSuccessful ==
true);
100 ioTravelSolution.addClassAvailabilityMap (lClassAvailabilityMap);
101 ioTravelSolution.addClassObjectIDMap (lClassObjectIDMap);
108 const std::string& iFullSegmentDateKey,
109 stdair::TravelSolutionStruct& ioTravelSolution) {
114 stdair::ClassYieldMap_T lClassYieldMap;
116 stdair::ClassBpvMap_T lClassBpvMap;
119 STDAIR_LOG_DEBUG (iFullSegmentDateKey);
121 stdair::SegmentDate* lSegmentDate_ptr =
122 stdair::BomRetriever::retrieveSegmentDateFromLongKey (iInventory,
123 iFullSegmentDateKey);
124 assert (lSegmentDate_ptr != NULL);
128 const stdair::SegmentCabinList_T& lSegmentCabinList =
129 stdair::BomManager::getList<stdair::SegmentCabin> (*lSegmentDate_ptr);
130 for (stdair::SegmentCabinList_T::const_iterator itCabin =
131 lSegmentCabinList.begin();
132 itCabin != lSegmentCabinList.end(); ++itCabin) {
133 stdair::SegmentCabin* lSegmentCabin_ptr = *itCabin;
134 assert (lSegmentCabin_ptr != NULL);
136 stdair::BidPriceVector_T lBPV;
140 stdair::LegCabinList_T lLegCabinList =
141 stdair::BomManager::getList<stdair::LegCabin> (*lSegmentCabin_ptr);
142 assert (!lLegCabinList.empty());
143 if (lLegCabinList.size() > 1) {
145 stdair::BidPrice_T lBidPriceValue = 0;
146 for (stdair::LegCabinList_T::const_iterator itLC = lLegCabinList.begin();
147 itLC != lLegCabinList.end(); ++itLC) {
148 const stdair::LegCabin* lLegCabin_ptr = *itLC;
149 const stdair::BidPriceVector_T& lLegCabinBPV = lLegCabin_ptr->getBidPriceVector();
150 if (!lLegCabinBPV.empty()) {
151 lBidPriceValue += lLegCabinBPV.back();
155 lBidPriceValue = std::numeric_limits<stdair::BidPrice_T>::max();
159 if (lBidPriceValue < std::numeric_limits<stdair::BidPrice_T>::max()) {
160 lBPV.push_back(lBidPriceValue);
164 const stdair::LegCabin* lLegCabin_ptr = lLegCabinList.front();
165 lBPV = lLegCabin_ptr->getBidPriceVector();
174 const stdair::Availability_T& lAvailabilityPool =
175 lSegmentCabin_ptr->getAvailabilityPool();
178 if (lAvailabilityPool < lBPV.size()) {
179 lBPV.resize(lAvailabilityPool);
184 ioTravelSolution.addBidPriceVector (lBPV);
186 const stdair::BidPriceVectorHolder_T& lBidPriceVectorHolder =
187 ioTravelSolution.getBidPriceVectorHolder();
188 const stdair::BidPriceVectorHolder_T::const_reverse_iterator itBPV =
189 lBidPriceVectorHolder.rbegin();
190 const stdair::BidPriceVector_T& lBpvRef = *itBPV;
192 const stdair::FareFamilyList_T& lFFList =
193 stdair::BomManager::getList<stdair::FareFamily> (*lSegmentCabin_ptr);
194 for (stdair::FareFamilyList_T::const_iterator itFF = lFFList.begin();
195 itFF != lFFList.end(); ++itFF) {
196 const stdair::FareFamily* lFareFamily_ptr = *itFF;
197 assert (lFareFamily_ptr != NULL);
199 const stdair::BookingClassList_T& lBCList =
200 stdair::BomManager::getList<stdair::BookingClass> (*lFareFamily_ptr);
201 for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
202 itBC != lBCList.end(); ++itBC) {
203 const stdair::BookingClass* lBC_ptr = *itBC;
204 assert (lBC_ptr != NULL);
206 const stdair::ClassCode_T& lClassCode = lBC_ptr->getClassCode();
208 const stdair::YieldValue_T lYld = lBC_ptr->getYield() ;
209 const bool insertYieldMapSuccessful = lClassYieldMap.
210 insert (stdair::ClassYieldMap_T::value_type (lClassCode,
212 assert (insertYieldMapSuccessful ==
true);
214 const bool insertBpvMapSuccessful = lClassBpvMap.
215 insert (stdair::ClassBpvMap_T::value_type (lClassCode,
217 assert (insertBpvMapSuccessful ==
true);
227 stdair::BidPrice_T lBpvVal = std::numeric_limits<double>::max();
228 if (lBpvRef.empty() ==
false) {
229 lBpvVal = lBpvRef.back();
233 STDAIR_LOG_DEBUG (
"Class: " << lClassCode
234 <<
", " <<
"Yield: " << lYld <<
", "
235 <<
"Bid price: " << lBpvVal <<
", "
236 <<
"Remaining capacity: " << lAvailabilityPool
237 <<
" Segment date: " << iFullSegmentDateKey);
243 ioTravelSolution.addClassYieldMap (lClassYieldMap);
244 ioTravelSolution.addClassBpvMap (lClassBpvMap);
249 const std::string& iFullSegmentDateKey,
250 const stdair::ClassCode_T& iClassCode,
251 const stdair::PartySize_T& iPartySize) {
252 bool hasSaleBeenSuccessful =
false;
255 STDAIR_LOG_DEBUG (
"Full key: '" << iFullSegmentDateKey
256 <<
"', " << iClassCode);
259 stdair::BookingClass* lBookingClass_ptr =
260 stdair::BomRetriever::retrieveBookingClassFromLongKey(ioInventory,
265 const std::string hasFoundBookingClassStr =
266 (lBookingClass_ptr != NULL)?
"Yes":
"No";
267 STDAIR_LOG_DEBUG (
"Found booking class? " << hasFoundBookingClassStr);
269 if (lBookingClass_ptr != NULL) {
272 hasSaleBeenSuccessful =
275 return hasSaleBeenSuccessful;
278 return hasSaleBeenSuccessful;
283 const stdair::PartySize_T& iPartySize) {
286 stdair::BookingClass& lBookingClass = iClassID.getObject();
289 const bool hasSaleBeenSuccessful =
292 return hasSaleBeenSuccessful;
297 const stdair::PartySize_T& iPartySize) {
300 iBookingClass.sell (iPartySize);
303 stdair::FareFamily& lFareFamily =
304 stdair::BomManager::getParent<stdair::FareFamily> (iBookingClass);
307 stdair::SegmentCabin& lSegmentCabin =
308 stdair::BomManager::getParent<stdair::SegmentCabin> (lFareFamily);
311 stdair::SegmentDate& lSegmentDate =
312 stdair::BomManager::getParent<stdair::SegmentDate,
313 stdair::SegmentCabin> (lSegmentCabin);
316 stdair::FlightDate& lFlightDate =
317 stdair::BomManager::getParent<stdair::FlightDate,
318 stdair::SegmentDate> (lSegmentDate);
329 const std::string& iFullSegmentDateKey,
330 const stdair::ClassCode_T& iClassCode,
331 const stdair::PartySize_T& iPartySize) {
332 bool hasCancellationBeenSuccessful =
false;
335 STDAIR_LOG_DEBUG (
"Full key: '" << iFullSegmentDateKey
336 <<
"', " << iClassCode);
339 stdair::BookingClass* lBookingClass_ptr =
340 stdair::BomRetriever::retrieveBookingClassFromLongKey(ioInventory,
345 const std::string hasFoundBookingClassStr =
346 (lBookingClass_ptr != NULL)?
"Yes":
"No";
347 STDAIR_LOG_DEBUG (
"Found booking class? " << hasFoundBookingClassStr);
349 if (lBookingClass_ptr != NULL) {
352 hasCancellationBeenSuccessful =
353 cancel (*lBookingClass_ptr, iPartySize);
355 return hasCancellationBeenSuccessful;
358 return hasCancellationBeenSuccessful;
363 const stdair::PartySize_T& iPartySize) {
365 stdair::BookingClass& lBookingClass = iClassID.getObject();
368 const bool hasCancellationBeenSuccessful =
369 cancel (lBookingClass, iPartySize);
371 return hasCancellationBeenSuccessful;
376 const stdair::PartySize_T& iPartySize) {
379 iBookingClass.cancel (iPartySize);
382 stdair::FareFamily& lFareFamily =
383 stdair::BomManager::getParent<stdair::FareFamily> (iBookingClass);
386 stdair::SegmentCabin& lSegmentCabin =
387 stdair::BomManager::getParent<stdair::SegmentCabin> (lFareFamily);
390 stdair::SegmentDate& lSegmentDate =
391 stdair::BomManager::getParent<stdair::SegmentDate,
392 stdair::SegmentCabin> (lSegmentCabin);
395 stdair::FlightDate& lFlightDate =
396 stdair::BomManager::getParent<stdair::FlightDate,
397 stdair::SegmentDate> (lSegmentDate);
408 const stdair::DateTime_T& iSnapshotTime) {
411 const stdair::SegmentSnapshotTableList_T& lSegmentSnapshotTableList =
412 stdair::BomManager::getList<stdair::SegmentSnapshotTable> (iInventory);
413 for (stdair::SegmentSnapshotTableList_T::const_iterator itGB =
414 lSegmentSnapshotTableList.begin();
415 itGB != lSegmentSnapshotTableList.end(); ++itGB) {
416 stdair::SegmentSnapshotTable* lSegmentSnapshotTable_ptr = *itGB;