22 _currentNbOfBookings (0),
23 _totalNbOfBookings (0),
24 _totalElapsedTime (0),
25 _estimatedRemainingTime (0),
26 _currentElapsedTime (0),
27 _currentEstimatedRemainingTime (0),
28 _simulationMode(
's') {
39 _currentNbOfBookings (0),
40 _totalNbOfBookings (0),
41 _totalElapsedTime (0),
42 _estimatedRemainingTime (0),
43 _currentElapsedTime (0),
44 _currentEstimatedRemainingTime (0),
45 _simulationMode (
's') {
50 : _key (iSimulationStatus._key),
51 _startDate (iSimulationStatus._startDate),
52 _currentDate (iSimulationStatus._currentDate),
53 _endDate (iSimulationStatus._endDate),
54 _totalNumberOfRuns (iSimulationStatus._totalNumberOfRuns),
55 _currentRun (iSimulationStatus._currentRun),
56 _currentNbOfBookings (iSimulationStatus._currentNbOfBookings),
57 _totalNbOfBookings (iSimulationStatus._totalNbOfBookings),
58 _totalElapsedTime (iSimulationStatus._totalElapsedTime),
59 _estimatedRemainingTime (iSimulationStatus._estimatedRemainingTime),
60 _currentElapsedTime (iSimulationStatus._currentElapsedTime),
61 _currentEstimatedRemainingTime (iSimulationStatus._currentEstimatedRemainingTime),
62 _simulationMode(iSimulationStatus.getSimulationMode()) {
76 _currentProgressStatus = iProgressStatus;
85 if (_currentRun >= _totalNumberOfRuns) {
86 isTheSimulationDone =
true;
101 const stdair::ProgressStatus& iProgressStatus,
102 const double& iEventMeasure) {
104 const stdair::Count_T lNbOfActualEventsOfSuchType =
105 iProgressStatus.getActualNb();
106 const stdair::Count_T lNbOfCurrentEventsOfSuchType =
107 iProgressStatus.getCurrentNb();
108 const stdair::Count_T lNbOfRemainingEventsOfSuchType =
109 lNbOfActualEventsOfSuchType - lNbOfCurrentEventsOfSuchType;
110 stdair::Count_T lPreviousNbOfActualEventsOfSuchType = 0;
111 stdair::Count_T lPreviousNbOfCurrentEventsOfSuchType = 0;
115 SEVMGR::ProgressStatusMap_T::iterator itProgressStatus =
116 _progressStatusMap.find (iType);
117 if (itProgressStatus == _progressStatusMap.end()) {
118 const bool hasInsertBeenSuccessful =
119 _progressStatusMap.insert (SEVMGR::ProgressStatusMap_T::
120 value_type (iType, iProgressStatus)).second;
122 if (hasInsertBeenSuccessful ==
false) {
123 STDAIR_LOG_ERROR (
"No progress_status can be inserted "
124 <<
"for the following event type: "
125 << stdair::EventType::getLabel(iType) <<
".");
126 throw stdair::EventException (
"No progress_status can be inserted "
127 "for the following event type: "
128 + stdair::EventType::getLabel(iType));
131 stdair::ProgressStatus& lProgressStatus = itProgressStatus->second;
132 lPreviousNbOfActualEventsOfSuchType = lProgressStatus.getActualNb();
133 lPreviousNbOfCurrentEventsOfSuchType = lProgressStatus.getCurrentNb();
134 lProgressStatus = iProgressStatus;
138 _currentElapsedTime += iEventMeasure;
142 ChronometerMap_T::iterator itChronometer =
143 _chronometerMap.find (iType);
144 if (itChronometer == _chronometerMap.end()) {
145 const bool hasInsertBeenSuccessful =
147 value_type (iType, iEventMeasure)).second;
149 if (hasInsertBeenSuccessful ==
false) {
150 STDAIR_LOG_ERROR (
"No chronometer can be inserted "
151 <<
"for the following event type: "
152 << stdair::EventType::getLabel(iType) <<
".");
153 throw stdair::EventException (
"No chronometer can be inserted for the "
154 "following event type: "
155 + stdair::EventType::getLabel(iType));
157 _currentEstimatedRemainingTime +=
158 lNbOfRemainingEventsOfSuchType*iEventMeasure;
161 double& lChronometer = itChronometer->second;
162 const stdair::Count_T lPreviousNbOfRemainingEventsOfSuchType =
163 lPreviousNbOfActualEventsOfSuchType -
164 lPreviousNbOfCurrentEventsOfSuchType;
165 if (lPreviousNbOfCurrentEventsOfSuchType > 0) {
166 _currentEstimatedRemainingTime -=
167 lPreviousNbOfRemainingEventsOfSuchType*
168 lChronometer/lPreviousNbOfCurrentEventsOfSuchType;
170 if (lNbOfCurrentEventsOfSuchType > 0) {
171 lChronometer += iEventMeasure;
172 _currentEstimatedRemainingTime += lNbOfRemainingEventsOfSuchType*
173 lChronometer/lNbOfCurrentEventsOfSuchType;
175 _currentEstimatedRemainingTime =
176 std::max(_currentEstimatedRemainingTime, 0.0);
180 _totalElapsedTime = _currentElapsedTime
182 *(_currentElapsedTime + _currentEstimatedRemainingTime);
183 _estimatedRemainingTime = _currentEstimatedRemainingTime
184 + (_totalNumberOfRuns - _currentRun)
185 *(_currentElapsedTime + _currentEstimatedRemainingTime);
192 _currentNbOfBookings += iPartySize;
193 _totalNbOfBookings += iPartySize;
200 _totalNbOfBookings -= _currentNbOfBookings;
203 _estimatedRemainingTime =
204 (_currentElapsedTime + _currentEstimatedRemainingTime)
205 *(_totalNumberOfRuns - _currentRun + 1);
206 _totalElapsedTime -= _currentElapsedTime;
220 _currentDate = _startDate;
223 _currentNbOfBookings = 0;
226 _currentElapsedTime = 0;
227 _currentEstimatedRemainingTime = 0;
230 _currentProgressStatus.reset();
231 _progressStatusMap.clear();
232 _chronometerMap.clear();
242 std::ostringstream oStr;
244 switch (_simulationMode.
getMode()) {
248 oStr <<
"Simulation";
249 if (_totalNumberOfRuns > 1) {
250 oStr <<
" [" <<_currentRun <<
"/" << _totalNumberOfRuns <<
"]";
252 oStr <<
" is starting..." << std::endl;
253 std::cout << oStr.str() << std::endl;
254 STDAIR_LOG_DEBUG (oStr.str());
260 oStr <<
"Resuming the Simulation ";
261 if (_totalNumberOfRuns > 1) {
262 oStr <<
"[" <<_currentRun <<
"/" << _totalNumberOfRuns <<
"]"
265 std::cout << oStr.str() << std::endl;
266 STDAIR_LOG_DEBUG (oStr.str());
278 std::ostringstream oStr;
280 switch (_simulationMode.
getMode()) {
283 oStr <<
"Simulation";
284 if (_totalNumberOfRuns > 1) {
285 oStr <<
" [" <<_currentRun <<
"/" << _totalNumberOfRuns <<
"]";
287 oStr <<
" has ended." << std::endl;
288 std::cout << oStr.str() << std::endl;
289 STDAIR_LOG_DEBUG (oStr.str());
295 std::cout <<
"The simulation has stopped on '" << _currentDate
296 <<
"': break point encountered.\n" <<
describe() << std::endl;
297 STDAIR_LOG_DEBUG (
"Break point encountered\n" <<
describe());
309 std::ostringstream oStr;
314 if (_totalNumberOfRuns > 1) {
318 oStr <<
"Simulation composed of " << _totalNumberOfRuns <<
" runs."
320 oStr <<
"\nTotal number of bookings: " << _totalNbOfBookings
321 <<
"\n\nElapsed time: "
322 << std::setprecision (2) << std::fixed << _totalElapsedTime <<
" s"
323 <<
"\nEstimated remaining time: "
324 << _estimatedRemainingTime <<
" s"
333 if (lRunNumberToDisplay > _totalNumberOfRuns) {
334 lRunNumberToDisplay--;
336 oStr <<
"Current Run (" << lRunNumberToDisplay
337 <<
"/" << _totalNumberOfRuns <<
")"
343 oStr <<
"\nStart Date ---- Current Date ---- End Date\n"
344 << _startDate <<
" " << _currentDate
345 <<
" " << _endDate << std::endl;
350 std::string lEventTypeStr =
"All";
351 describeHelper(lEventTypeStr);
352 oStr <<
"\n\n----------------- Progress statuses ----------------"
353 <<
"\n " << lEventTypeStr << _currentProgressStatus.toString()
354 <<
"\n----------------------------------------------------";
359 std::string lOptionalStr;
360 SEVMGR::ProgressStatusMap_T::const_iterator itPS =
361 _progressStatusMap.begin();
362 while (itPS != _progressStatusMap.end()) {
363 const stdair::EventType::EN_EventType& lType = itPS->first;
364 const stdair::ProgressStatus& lProgressStatus = itPS->second;
365 lEventTypeStr = stdair::EventType::getLabel(lType);
366 describeHelper(lEventTypeStr);
367 oStr <<
"\n " << lEventTypeStr << lProgressStatus.toString();
369 lOptionalStr =
"\n----------------------------------------------------";
371 oStr << lOptionalStr << std::endl;
376 oStr <<
"\nTotal number of bookings: "
377 << _currentNbOfBookings
378 <<
"\n\nElapsed time: "
379 << std::setprecision (2) << std::fixed << _currentElapsedTime <<
" s"
380 <<
"\nEstimated remaining time: "
381 << _currentEstimatedRemainingTime <<
" s"
387 void SimulationStatus::describeHelper(std::string& ioEventTypeName)
const {
388 ioEventTypeName +=
" Events:";
389 const std::size_t lSizeBeforePercent (30);
390 ioEventTypeName.resize (lSizeBeforePercent,
' ');