14 #define BOOST_TEST_DYN_LINK 15 #define BOOST_TEST_MAIN 16 #define BOOST_TEST_MODULE DemandGenerationTest 17 #include <boost/test/unit_test.hpp> 18 #include <boost/version.hpp> 20 #include <stdair/stdair_basic_types.hpp> 21 #include <stdair/basic/BasConst_General.hpp> 22 #include <stdair/basic/BasLogParams.hpp> 23 #include <stdair/basic/BasDBParams.hpp> 24 #include <stdair/basic/BasFileMgr.hpp> 25 #include <stdair/basic/ProgressStatusSet.hpp> 26 #include <stdair/bom/EventStruct.hpp> 27 #include <stdair/bom/BookingRequestStruct.hpp> 28 #include <stdair/service/Logger.hpp> 35 namespace boost_utf = boost::unit_test;
38 std::ofstream utfReportStream (
"DemandGenerationTestSuite_utfresults.xml");
43 struct UnitTestConfig {
46 boost_utf::unit_test_log.set_stream (utfReportStream);
47 #if BOOST_VERSION >= 105900 48 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
50 boost_utf::unit_test_log.set_format (boost_utf::XML);
52 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
62 typedef std::pair<stdair::Count_T, stdair::Count_T> NbOfEventsPair_T;
63 typedef std::map<
const stdair::DemandStreamKeyStr_T,
64 NbOfEventsPair_T> NbOfEventsByDemandStreamMap_T;
70 void testDemandGenerationHelper (
const unsigned short iTestFlag,
71 const stdair::Filename_T& iDemandInputFilename,
72 const stdair::DemandGenerationMethod& iDemandGenerationMethod,
73 const bool isBuiltin) {
76 const stdair::RandomSeed_T lRandomSeed = stdair::DEFAULT_RANDOM_SEED;
79 std::ostringstream oStr;
80 oStr <<
"DemandGenerationTestSuite_" << iTestFlag <<
".log";
81 const stdair::Filename_T lLogFilename (oStr.str());
84 std::ofstream logOutputFile;
86 logOutputFile.open (lLogFilename.c_str());
87 logOutputFile.clear();
90 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
102 NbOfEventsByDemandStreamMap_T lNbOfEventsMap;
105 stdair::Count_T lRefExpectedNbOfEvents (0);
106 stdair::Count_T lRefActualNbOfEvents (0);
109 if (isBuiltin ==
true) {
112 trademgenService.buildSampleBom();
114 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
115 value_type (
"SIN-BKK 2010-Feb-08 Y",
116 NbOfEventsPair_T (4, 60)));
117 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
118 value_type (
"BKK-HKG 2010-Feb-08 Y",
119 NbOfEventsPair_T (4, 60)));
120 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
121 value_type (
"SIN-HKG 2010-Feb-08 Y",
122 NbOfEventsPair_T (4, 60)));
125 lRefExpectedNbOfEvents = 180;
126 lRefActualNbOfEvents = 186;
132 trademgenService.parseAndLoad (lDemandFilePath);
134 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
135 value_type (
"SIN-HND 2010-Feb-08 Y",
136 NbOfEventsPair_T (1, 10)));
137 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
138 value_type (
"SIN-HND 2010-Feb-09 Y",
139 NbOfEventsPair_T (1, 10)));
140 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
141 value_type (
"SIN-BKK 2010-Feb-08 Y",
142 NbOfEventsPair_T (1, 10)));
143 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
144 value_type (
"SIN-BKK 2010-Feb-09 Y",
145 NbOfEventsPair_T (1, 10)));
148 lRefExpectedNbOfEvents = 40;
149 lRefActualNbOfEvents = 40;
154 const stdair::Count_T& lExpectedNbOfEventsToBeGenerated =
155 trademgenService.getExpectedTotalNumberOfRequestsToBeGenerated();
157 BOOST_CHECK_EQUAL (lRefExpectedNbOfEvents,
158 std::floor (lExpectedNbOfEventsToBeGenerated));
160 BOOST_CHECK_MESSAGE (lRefExpectedNbOfEvents ==
161 std::floor (lExpectedNbOfEventsToBeGenerated),
162 "Expected total number of requests to be generated: " 163 << lExpectedNbOfEventsToBeGenerated
165 << std::floor (lExpectedNbOfEventsToBeGenerated)
166 <<
"). Reference value: " << lRefExpectedNbOfEvents);
173 const stdair::Count_T& lActualNbOfEventsToBeGenerated =
174 trademgenService.generateFirstRequests(iDemandGenerationMethod);
177 STDAIR_LOG_DEBUG (
"Expected number of events: " 178 << lExpectedNbOfEventsToBeGenerated <<
", actual: " 179 << lActualNbOfEventsToBeGenerated);
182 BOOST_CHECK_EQUAL (lRefActualNbOfEvents, lActualNbOfEventsToBeGenerated);
184 BOOST_CHECK_MESSAGE (lRefActualNbOfEvents == lActualNbOfEventsToBeGenerated,
185 "Actual total number of requests to be generated: " 186 << lExpectedNbOfEventsToBeGenerated
188 << std::floor (lExpectedNbOfEventsToBeGenerated)
189 <<
"). Reference value: " << lRefActualNbOfEvents);
192 const bool isQueueDone = trademgenService.isQueueDone();
193 BOOST_REQUIRE_MESSAGE (isQueueDone ==
false,
194 "The event queue should not be empty.");
203 stdair::Count_T idx = 1;
204 while (trademgenService.isQueueDone() ==
false) {
207 stdair::EventStruct lEventStruct;
208 stdair::ProgressStatusSet lPPS = trademgenService.popEvent (lEventStruct);
211 STDAIR_LOG_DEBUG (
"Poped event: '" << lEventStruct.describe() <<
"'.");
214 const stdair::BookingRequestStruct& lPoppedRequest =
215 lEventStruct.getBookingRequest();
218 STDAIR_LOG_DEBUG (
"Poped booking request: '" 219 << lPoppedRequest.describe() <<
"'.");
222 const stdair::DemandGeneratorKey_T& lDemandStreamKey =
223 lPoppedRequest.getDemandGeneratorKey();
226 const NbOfEventsByDemandStreamMap_T::iterator itNbOfEventsMap =
227 lNbOfEventsMap.find (lDemandStreamKey);
228 BOOST_REQUIRE_MESSAGE (itNbOfEventsMap != lNbOfEventsMap.end(),
229 "The demand stream key '" << lDemandStreamKey
230 <<
"' is not expected in that test");
241 const NbOfEventsPair_T& lNbOfEventsPair = itNbOfEventsMap->second;
242 stdair::Count_T lCurrentNbOfEvents = lNbOfEventsPair.first;
243 const stdair::Count_T& lExpectedTotalNbOfEvents = lNbOfEventsPair.second;
246 const bool stillHavingRequestsToBeGenerated = trademgenService.
247 stillHavingRequestsToBeGenerated (lDemandStreamKey, lPPS,
248 iDemandGenerationMethod);
256 if (lCurrentNbOfEvents == 1) {
262 const stdair::ProgressStatus& lDemandStreamProgressStatus =
263 lPPS.getSpecificGeneratorStatus();
264 const stdair::Count_T& lNbOfRequests =
265 lDemandStreamProgressStatus.getExpectedNb();
267 BOOST_CHECK_EQUAL (lNbOfRequests, lExpectedTotalNbOfEvents);
268 BOOST_CHECK_MESSAGE (lNbOfRequests == lExpectedTotalNbOfEvents,
269 "[" << lDemandStreamKey
270 <<
"] Total number of requests to be generated: " 271 << lNbOfRequests <<
"). Expected value: " 272 << lExpectedTotalNbOfEvents);
276 STDAIR_LOG_DEBUG (
"=> [" << lDemandStreamKey <<
"][" << lCurrentNbOfEvents
277 <<
"/" << lExpectedTotalNbOfEvents
278 <<
"] is now processed. " 279 <<
"Still generate events for that demand stream? " 280 << stillHavingRequestsToBeGenerated);
284 if (stillHavingRequestsToBeGenerated ==
true) {
285 const stdair::BookingRequestPtr_T lNextRequest_ptr =
286 trademgenService.generateNextRequest (lDemandStreamKey,
287 iDemandGenerationMethod);
288 assert (lNextRequest_ptr != NULL);
295 const stdair::Duration_T lDuration =
296 lNextRequest_ptr->getRequestDateTime()
297 - lPoppedRequest.getRequestDateTime();
298 BOOST_REQUIRE_GT (lDuration.total_milliseconds(), 0);
299 BOOST_REQUIRE_MESSAGE (lDuration.total_milliseconds() > 0,
300 "[" << lDemandStreamKey
301 <<
"] The date-time of the generated event (" 302 << lNextRequest_ptr->getRequestDateTime()
303 <<
") is lower than the date-time " 304 <<
"of the current event (" 305 << lPoppedRequest.getRequestDateTime() <<
")");
308 STDAIR_LOG_DEBUG (
"[" << lDemandStreamKey <<
"][" << lCurrentNbOfEvents
309 <<
"/" << lExpectedTotalNbOfEvents
310 <<
"] Added request: '" << lNextRequest_ptr->describe()
311 <<
"'. Is queue done? " 312 << trademgenService.isQueueDone());
315 ++lCurrentNbOfEvents;
316 itNbOfEventsMap->second = NbOfEventsPair_T (lCurrentNbOfEvents,
317 lExpectedTotalNbOfEvents);
326 if (iDemandGenerationMethod == stdair::DemandGenerationMethod::STA_ORD) {
328 BOOST_CHECK_EQUAL (idx, lRefActualNbOfEvents);
329 BOOST_CHECK_MESSAGE (idx == lRefActualNbOfEvents,
330 "The total actual number of events is " 331 << lRefActualNbOfEvents <<
", but " << idx
332 <<
" events have been generated");
337 trademgenService.reset();
340 STDAIR_LOG_DEBUG (
"End of the simulation");
343 logOutputFile.close();
351 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
354 BOOST_AUTO_TEST_SUITE (master_test_suite)
359 BOOST_AUTO_TEST_CASE (trademgen_simple_simulation_test) {
365 const stdair::DemandGenerationMethod lDemandGenerationMethod (stdair::DemandGenerationMethod::STA_ORD);
368 const bool isBuiltin =
false;
369 BOOST_CHECK_NO_THROW (testDemandGenerationHelper(0,
371 lDemandGenerationMethod,
379 BOOST_AUTO_TEST_CASE (trademgen_missing_input_file_test) {
385 const stdair::DemandGenerationMethod lDemandGenerationMethod (stdair::DemandGenerationMethod::STA_ORD);
388 const bool isBuiltin =
false;
389 BOOST_CHECK_THROW (testDemandGenerationHelper(1,
391 lDemandGenerationMethod,
400 BOOST_AUTO_TEST_CASE (trademgen_default_bom_simulation_test) {
403 const stdair::DemandGenerationMethod lDemandGenerationMethod (stdair::DemandGenerationMethod::STA_ORD);
406 const bool isBuiltin =
true;
407 BOOST_CHECK_NO_THROW (testDemandGenerationHelper(2,
409 lDemandGenerationMethod,
417 BOOST_AUTO_TEST_CASE (trademgen_poisson_process_test) {
420 const stdair::DemandGenerationMethod lDemandGenerationMethod (stdair::DemandGenerationMethod::POI_PRO);
423 const bool isBuiltin =
true;
424 BOOST_CHECK_NO_THROW (testDemandGenerationHelper(3,
426 lDemandGenerationMethod,
432 BOOST_AUTO_TEST_SUITE_END()
class holding the services related to Travel Demand Generation.
#define STDAIR_SAMPLE_DIR