85 const std::string& iDemandGenerationMethodString) {
86 std::ostringstream oStream;
89 const stdair::DemandGenerationMethod
90 iDemandGenerationMethod (iDemandGenerationMethodString);
93 if (_logOutputStream == NULL) {
94 oStream <<
"The log filepath is not valid." << std::endl;
97 assert (_logOutputStream != NULL);
102 *_logOutputStream <<
"Demand generation for " << iNbOfRuns <<
" runs, "
103 <<
"with the following method: "
104 << iDemandGenerationMethod << std::endl;
106 if (_trademgenService == NULL) {
107 oStream <<
"The TraDemGen service has not been initialised, "
108 <<
"i.e., the init() method has not been called "
109 <<
"correctly on the Trademgener object. Please "
110 <<
"check that all the parameters are not empty and "
111 <<
"point to actual files.";
112 *_logOutputStream << oStream.str();
113 return oStream.str();
115 assert (_trademgenService != NULL);
122 const stdair::Count_T& lExpectedNbOfEventsToBeGenerated =
126#if BOOST_VERSION_MACRO >= 107200
127 boost::timer::progress_display
129 boost::progress_display
131 lProgressDisplay (lExpectedNbOfEventsToBeGenerated * iNbOfRuns);
133 for (
NbOfRuns_T runIdx = 1; runIdx <= iNbOfRuns; ++runIdx) {
135 *_logOutputStream <<
"Run number: " << runIdx << std::endl;
141 const stdair::Count_T& lActualNbOfEventsToBeGenerated =
145 *_logOutputStream <<
"[" << runIdx <<
"] Expected: "
146 << lExpectedNbOfEventsToBeGenerated <<
", actual: "
147 << lActualNbOfEventsToBeGenerated << std::endl;
156 while (_trademgenService->
isQueueDone() ==
false) {
159 stdair::EventStruct lEventStruct;
160 stdair::ProgressStatusSet lProgressStatusSet =
161 _trademgenService->
popEvent (lEventStruct);
168 const stdair::BookingRequestStruct& lPoppedRequest =
169 lEventStruct.getBookingRequest();
172 *_logOutputStream <<
"[" << runIdx <<
"] Poped booking request: '"
173 << lPoppedRequest.describe() <<
"'." << std::endl;
179 const stdair::DemandGeneratorKey_T& lDemandStreamKey =
180 lPoppedRequest.getDemandGeneratorKey();
184 const bool stillHavingRequestsToBeGenerated = _trademgenService->
185 stillHavingRequestsToBeGenerated (lDemandStreamKey,
187 iDemandGenerationMethod);
190 *_logOutputStream << lProgressStatusSet.describe() << std::endl;
191 *_logOutputStream <<
"=> [" << lDemandStreamKey
192 <<
"] is now processed. Still generate events "
193 <<
"for that demand stream? "
194 << stillHavingRequestsToBeGenerated << std::endl;
198 if (stillHavingRequestsToBeGenerated ==
true) {
200 stdair::BookingRequestPtr_T lNextRequest_ptr =
202 iDemandGenerationMethod);
204 assert (lNextRequest_ptr != NULL);
207 const stdair::Duration_T lDuration =
208 lNextRequest_ptr->getRequestDateTime()
209 - lPoppedRequest.getRequestDateTime();
210 if (lDuration.total_milliseconds() < 0) {
211 *_logOutputStream <<
"[" << lDemandStreamKey
212 <<
"] The date-time of the generated event ("
213 << lNextRequest_ptr->getRequestDateTime()
214 <<
") is lower than the date-time "
215 <<
"of the current event ("
216 << lPoppedRequest.getRequestDateTime()
222 *_logOutputStream <<
"[" << lDemandStreamKey
223 <<
"] Added request: '"
224 << lNextRequest_ptr->describe()
225 <<
"'. Is queue done? "
230 *_logOutputStream << std::endl;
237 lStatAccumulator (lActualNbOfEventsToBeGenerated);
240 _trademgenService->
reset();
244 *_logOutputStream <<
"End of the demand generation. Following are some "
245 <<
"statistics for the " << iNbOfRuns <<
" runs."
247 std::ostringstream oStatStr;
249 *_logOutputStream << oStatStr.str() << std::endl;
252 const std::string& lBOMStr = _trademgenService->
csvDisplay();
253 *_logOutputStream << lBOMStr << std::endl;
256 *_logOutputStream <<
"TraDemGen output: "
257 << oStream.str() << std::endl;
259 }
catch (
const stdair::RootException& eTrademgenError) {
260 oStream <<
"TraDemGen error: " << eTrademgenError.what() << std::endl;
262 }
catch (
const std::exception& eStdError) {
263 oStream <<
"Error: " << eStdError.what() << std::endl;
266 oStream <<
"Unknown error" << std::endl;
270 oStream <<
"TraDemGen has completed the generation of the booking "
271 <<
"requests. See the log file for more details." << std::endl;
273 return oStream.str();
296 bool init (
const std::string& iLogFilepath,
297 const stdair::RandomSeed_T& iRandomSeed,
const bool isBuiltin,
298 const stdair::Filename_T& iDemandInputFilename) {
299 bool isEverythingOK =
true;
304 const bool isWriteable = (iLogFilepath.empty() ==
false);
306 if (isWriteable ==
false) {
307 isEverythingOK =
false;
308 return isEverythingOK;
312 _logOutputStream =
new std::ofstream;
313 assert (_logOutputStream != NULL);
316 _logOutputStream->open (iLogFilepath.c_str());
317 _logOutputStream->clear();
320 *_logOutputStream <<
"Python wrapper initialisation" << std::endl;
321 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
326 assert (_trademgenService != NULL);
329 if (isBuiltin ==
true) {
342 *_logOutputStream <<
"Python wrapper initialised" << std::endl;
344 }
catch (
const stdair::RootException& eTrademgenError) {
345 *_logOutputStream <<
"Trademgen error: " << eTrademgenError.what()
348 }
catch (
const std::exception& eStdError) {
349 *_logOutputStream <<
"Error: " << eStdError.what() << std::endl;
352 *_logOutputStream <<
"Unknown error" << std::endl;
355 return isEverythingOK;