NOMAD Source  Version 4.0.0 Beta
Algorithm.cpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------------*/
2 /* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
3 /* */
4 /* NOMAD - Version 4.0.0 has been created by */
5 /* Viviane Rochon Montplaisir - Polytechnique Montreal */
6 /* Christophe Tribes - Polytechnique Montreal */
7 /* */
8 /* The copyright of NOMAD - version 4.0.0 is owned by */
9 /* Charles Audet - Polytechnique Montreal */
10 /* Sebastien Le Digabel - Polytechnique Montreal */
11 /* Viviane Rochon Montplaisir - Polytechnique Montreal */
12 /* Christophe Tribes - Polytechnique Montreal */
13 /* */
14 /* NOMAD v4 has been funded by Rio Tinto, Hydro-Québec, NSERC (Natural */
15 /* Sciences and Engineering Research Council of Canada), InnovÉÉ (Innovation */
16 /* en Énergie Électrique) and IVADO (The Institute for Data Valorization) */
17 /* */
18 /* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
19 /* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
20 /* and Exxon Mobil. */
21 /* */
22 /* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
23 /* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
24 /* Exxon Mobil. */
25 /* */
26 /* Contact information: */
27 /* Polytechnique Montreal - GERAD */
28 /* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
29 /* e-mail: nomad@gerad.ca */
30 /* */
31 /* This program is free software: you can redistribute it and/or modify it */
32 /* under the terms of the GNU Lesser General Public License as published by */
33 /* the Free Software Foundation, either version 3 of the License, or (at your */
34 /* option) any later version. */
35 /* */
36 /* This program is distributed in the hope that it will be useful, but WITHOUT */
37 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
38 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License */
39 /* for more details. */
40 /* */
41 /* You should have received a copy of the GNU Lesser General Public License */
42 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
43 /* */
44 /* You can find information on the NOMAD software at www.gerad.ca/nomad */
45 /*---------------------------------------------------------------------------------*/
46 
47 #include <signal.h>
48 
49 #include "../Algos/Algorithm.hpp"
50 #include "../Algos/EvcInterface.hpp"
51 #include "../Algos/Mads/SearchMethodBase.hpp"
52 #include "../Algos/SubproblemManager.hpp"
53 #include "../Cache/CacheBase.hpp"
54 #include "../Output/OutputQueue.hpp"
55 #include "../Math/RNG.hpp"
56 #include "../Util/fileutils.hpp"
57 
58 #ifdef TIME_STATS
59 #include "../Algos/Mads/MadsIteration.hpp"
60 #include "../Algos/Mads/Search.hpp"
61 #include "../Util/Clock.hpp"
62 #endif // TIME_STATS
63 
64 #ifdef _OPENMP
65 omp_lock_t NOMAD::Algorithm::_algoCommentLock;
66 #endif // _OPENMP
67 
68 void NOMAD::Algorithm::init()
69 {
70  _name = "AGenericAlgorithmHasNoName";
71 
72  // Verifications that throw Exceptions to the Constructor if not validated.
73  verifyParentNotNull();
74 
75  if (nullptr == _runParams)
76  {
77  throw NOMAD::StepException(__FILE__, __LINE__,
78  "A valid RunParameters must be provided to an Algorithm constructor.", this);
79  }
80 
81  if (nullptr == _pbParams)
82  {
83  throw NOMAD::StepException(__FILE__, __LINE__,
84  "A valid PbParameters must be provided to the Algorithm constructor.", this);
85  }
86 
87  if ( nullptr == _stopReasons )
88  throw NOMAD::StepException(__FILE__, __LINE__,
89  "Valid stop reasons must be provided to the Algorithm constructor.", this);
90 
91 #ifdef _OPENMP
92  omp_init_lock(&_algoCommentLock);
93 #endif // _OPENMP
94 
95  // Check pbParams if needed, ex. if a copy of PbParameters was given to the Algorithm constructor.
96  _pbParams->checkAndComply();
97 
98  // Instantiate generic algorithm termination
99  _termination = std::make_unique<NOMAD::Termination>( this );
100 
101  // Update SubproblemManager
102  NOMAD::Point fullFixedVariable = isRootAlgo() ? _pbParams->getAttributeValue<NOMAD::Point>("FIXED_VARIABLE")
103  : NOMAD::SubproblemManager::getSubFixedVariable(_parentStep);
104 
105  NOMAD::Subproblem subproblem(_pbParams, fullFixedVariable);
106  NOMAD::SubproblemManager::addSubproblem(this, subproblem);
107  _pbParams = subproblem.getPbParams();
108  _pbParams->checkAndComply();
109 
110  /** Step::userInterrupt() will be called if CTRL-C is pressed.
111  * Currently, the main thread will wait for all evaluations to be complete.
112  * \todo Propage interruption to all threads, for all parallel evaluations of blackbox.
113  */
114  signal(SIGINT, userInterrupt);
115  signal(SIGSEGV, debugSegFault);
116 
117 }
118 
119 
120 NOMAD::Algorithm::~Algorithm()
121 {
122  NOMAD::SubproblemManager::removeSubproblem(this);
123 #ifdef _OPENMP
124  omp_destroy_lock(&_algoCommentLock);
125 #endif // _OPENMP
126 }
127 
128 
129 // Set _algoComment, and push the current algo comment to _prevAlgoComment pile.
130 // Do not push an empty string on an empty pile, it is irrelevant.
131 // If force = true, do not set a new algo comment until this comment is reset.
132 void NOMAD::Algorithm::setAlgoComment(const std::string& algoComment, const bool force)
133 {
134  if (isSubAlgo())
135  {
136  auto rootAlgo = const_cast<NOMAD::Algorithm*>(getRootAlgorithm());
137  rootAlgo->setAlgoComment(algoComment, force);
138  }
139  else
140  {
141 #ifdef _OPENMP
142  omp_set_lock(&_algoCommentLock);
143 #endif // _OPENMP
144  if (!_forceAlgoComment)
145  {
146  // Push algo comment to _prevAlgoComment
147  if (!_prevAlgoComment.empty() || !_algoComment.empty())
148  {
149  _prevAlgoComment.push_back(_algoComment);
150  }
151  _algoComment = algoComment;
152  }
153  if (force)
154  {
155  _forceAlgoComment = true;
156  }
157 #ifdef _OPENMP
158  omp_unset_lock(&_algoCommentLock);
159 #endif // _OPENMP
160  }
161 }
162 
163 
164 // Pop the previous algo comment from the _prevAlgoComment pile.
165 void NOMAD::Algorithm::resetPreviousAlgoComment(const bool force)
166 {
167  if (isSubAlgo())
168  {
169  auto rootAlgo = const_cast<NOMAD::Algorithm*>(getRootAlgorithm());
170  rootAlgo->resetPreviousAlgoComment(force);
171  }
172  else
173  {
174 #ifdef _OPENMP
175  omp_set_lock(&_algoCommentLock);
176 #endif // _OPENMP
177  if (!_forceAlgoComment || force)
178  {
179  if (_prevAlgoComment.empty())
180  {
181  _algoComment = "";
182  }
183  else
184  {
185  // Remove last element, simulate a "pop".
186  _algoComment = std::move(_prevAlgoComment[_prevAlgoComment.size()-1]);
187  _prevAlgoComment.erase(_prevAlgoComment.end()-1);
188  }
189  if (_forceAlgoComment)
190  {
191  _forceAlgoComment = false;
192  }
193  }
194 #ifdef _OPENMP
195  omp_unset_lock(&_algoCommentLock);
196 #endif // _OPENMP
197  }
198 }
199 
200 
201 std::string NOMAD::Algorithm::getAlgoComment() const
202 {
203  std::string algoComment;
204  if (isSubAlgo())
205  {
206  algoComment = getRootAlgorithm()->getAlgoComment();
207  }
208  else
209  {
210  algoComment = _algoComment;
211  }
212 
213  return algoComment;
214 }
215 
216 
217 void NOMAD::Algorithm::startImp()
218 {
219 #ifdef TIME_STATS
220  if (isRootAlgo())
221  {
222  _startTime = NOMAD::Clock::getCPUTime();
223  }
224 #endif // TIME_STATS
225  // Comment to appear at the end of stats lines
226  // By default, nothing is added
227  setAlgoComment("");
228 
229  // All stop reasons are reset.
230  _stopReasons->setStarted();
231 
232  // SuccessType is reset
233  _algoSuccessful = false;
234  _algoBestSuccess = NOMAD::SuccessType::NOT_EVALUATED;
235 
236  if (isRootAlgo())
237  {
238  // Update hot restart info
239  readInformationForHotRestart();
240  NOMAD::CacheBase::getInstance()->setStopWaiting(false);
241  }
242 
243  // By default reset the lap counter for BbEval and set the lap maxBbEval to INF
244  NOMAD::EvcInterface::getEvaluatorControl()->resetLapBbEval();
245  NOMAD::EvcInterface::getEvaluatorControl()->setLapMaxBbEval( NOMAD::INF_SIZE_T );
246  NOMAD::EvcInterface::getEvaluatorControl()->resetSgteEval();
247 
248  if (nullptr == _megaIteration)
249  {
250  // Default behavior - not hot restart.
251  // Clear cache hits.
252  // Initialization.
253  // Eval X0s.
254 
255  if (isRootAlgo())
256  {
257  // Ensure we do not count cache hits which may have been read in the cache.
258  NOMAD::CacheBase::resetNbCacheHits();
259  }
260 
261  // Perform algo initialization only when available.
262  if (nullptr != _initialization)
263  {
264  _initialization->start();
265  _initialization->run();
266  _initialization->end();
267  }
268 
269  }
270  else
271  {
272  // Hot restart situation.
273  // We will not need Initialization.
274  auto barrier = _megaIteration->getBarrier();
275 
276  // Update X0s
277  // Use best points.
278  auto bestPoints = barrier->getAllPoints();
279 
281  if (!bestPoints.empty())
282  {
283  std::transform(bestPoints.begin(), bestPoints.end(), std::back_inserter(x0s),
284  [](NOMAD::EvalPoint evalPoint) -> NOMAD::EvalPoint { return evalPoint; });
285 
286  }
287  _pbParams->setAttributeValue<NOMAD::ArrayOfPoint>("X0", x0s);
288  _pbParams->checkAndComply();
289  }
290 }
291 
292 
293 void NOMAD::Algorithm::endImp()
294 {
295  if ( _endDisplay )
296  {
297  displayBestSolutions();
298 #ifdef TIME_STATS
299  if (isRootAlgo())
300  {
301  _totalRealAlgoTime = NOMAD::Clock::getTimeSinceStart();
302  _totalCPUAlgoTime += NOMAD::Clock::getCPUTime() - _startTime;
303  }
304 #endif // TIME_STATS
305 
306  displayEvalCounts();
307  }
308 
309  // Update the SearchMethod success type with best success found.
310  if ( _algoSuccessful )
311  {
312  // The parent can be a SearchMethod (NM-Mads Search) or not (that is NM is a standalone optimization)
313  auto searchMethodConst = dynamic_cast<const NOMAD::SearchMethodBase*>(_parentStep);
314 
315  if (searchMethodConst != nullptr)
316  {
317  auto searchMethod = const_cast<NOMAD::SearchMethodBase*>(searchMethodConst);
318  searchMethod->setSuccessType(_algoBestSuccess);
319  }
320 
321  }
322 
323  // By default reset the lap counter for BbEval and set the lap maxBbEval to INF
324  NOMAD::EvcInterface::getEvaluatorControl()->resetLapBbEval();
325  NOMAD::EvcInterface::getEvaluatorControl()->setLapMaxBbEval( NOMAD::INF_SIZE_T );
326 
327  if (isRootAlgo())
328  {
329  saveInformationForHotRestart();
330  NOMAD::CacheBase::getInstance()->setStopWaiting(true);
331  }
332 
333  // Reset stats comment
334  resetPreviousAlgoComment();
335 }
336 
337 
338 void NOMAD::Algorithm::hotRestartOnUserInterrupt()
339 {
340 #ifdef TIME_STATS
341  if (isRootAlgo())
342  {
343  _totalCPUAlgoTime += NOMAD::Clock::getCPUTime() - _startTime;
344  }
345 #endif // TIME_STATS
346  hotRestartBeginHelper();
347 
348  hotRestartEndHelper();
349 #ifdef TIME_STATS
350  if (isRootAlgo())
351  {
352  _startTime = NOMAD::Clock::getCPUTime();
353  }
354 #endif // TIME_STATS
355 }
356 
357 
358 void NOMAD::Algorithm::saveInformationForHotRestart() const
359 {
360  // If we want to stop completely and then be able to restart
361  // from where we were, we need to save some information on file.
362  //
363  // Issue 372: Maybe we need to write current parameters. If we write them,
364  // ignore initial values, only take latest values down the Parameter tree.
365  // For now, using initial parameters.
366 
367  // Cache file is treated independently from hot restart file.
368  // As long as the cache file name is set, it is written.
369  // This is the behavior of NOMAD 3.
370  std::string cacheFile = NOMAD::CacheBase::getInstance()->getFileName();
371  if (!cacheFile.empty())
372  {
373  NOMAD::CacheBase::getInstance()->write();
374  }
375  if ( _runParams->getAttributeValue<bool>("HOT_RESTART_WRITE_FILES"))
376  {
377  std::cout << "Save information for hot restart." << std::endl;
378  std::cout << "Write hot restart file." << std::endl;
379  NOMAD::write(*this, _runParams->getAttributeValue<std::string>("HOT_RESTART_FILE"));
380  }
381 }
382 
383 
384 void NOMAD::Algorithm::displayBestSolutions() const
385 {
386  std::vector<NOMAD::EvalPoint> evalPointList;
387  // Display best feasible solutions.
388  std::string sFeas;
389  // Output level is very high if there are no parent algorithm
390  // Output level is info if this algorithm is a sub part of another algorithm.
391  NOMAD::OutputLevel outputLevel = isSubAlgo() ? NOMAD::OutputLevel::LEVEL_INFO
392  : NOMAD::OutputLevel::LEVEL_VERY_HIGH;
393  NOMAD::OutputInfo displaySolFeas(_name, sFeas, outputLevel);
394  auto fixedVariable = NOMAD::SubproblemManager::getSubFixedVariable(this);
395 
396  sFeas = "Best feasible solution";
397  auto barrier = getMegaIterationBarrier();
398  if (nullptr != barrier)
399  {
400  evalPointList = barrier->getAllXFeas();
401  NOMAD::convertPointListToFull(evalPointList, fixedVariable);
402  }
403  size_t nbBestFeas = evalPointList.size();
404 
405  if (0 == nbBestFeas)
406  {
407  sFeas += ": Undefined.";
408  displaySolFeas.addMsg(sFeas);
409  }
410  else if (1 == nbBestFeas)
411  {
412  sFeas += ": ";
413  displaySolFeas.addMsgAndSol(sFeas, *evalPointList.begin());
414  }
415  else
416  {
417  sFeas += "s: ";
418  displaySolFeas.addMsgAndSol(sFeas, *evalPointList.begin());
419  }
420 
421 
422  const size_t maxSolCount = 8;
423  if (nbBestFeas > 1)
424  {
425  std::vector<NOMAD::EvalPoint>::const_iterator it;
426  size_t solCount = 0;
427  for (it = evalPointList.begin(); it != evalPointList.end(); ++it)
428  {
429  solCount++;
430  if (evalPointList.begin() == it)
431  {
432  continue; // First element already added
433  }
434  displaySolFeas.addMsgAndSol(" ",*it);
435  if (solCount >= maxSolCount)
436  {
437  // We printed enough solutions already.
438  displaySolFeas.addMsg("... A total of " + std::to_string(evalPointList.size()) + " feasible solutions were found.");
439  break;
440  }
441  }
442  }
443 
444  NOMAD::OutputQueue::Add(std::move(displaySolFeas));
445 
446  evalPointList.clear();
447 
448 
449  // Display best infeasible solutions.
450  std::string sInf;
451  NOMAD::OutputInfo displaySolInf(_name, sInf, outputLevel);
452  sInf = "Best infeasible solution";
453  if (nullptr != barrier)
454  {
455  evalPointList = barrier->getAllXInf();
456  NOMAD::convertPointListToFull(evalPointList, fixedVariable);
457  }
458  size_t nbBestInf = evalPointList.size();
459 
460  if (0 == nbBestInf)
461  {
462  sInf += ": Undefined.";
463  displaySolInf.addMsg(sInf);
464  }
465  else if (1 == nbBestInf)
466  {
467  sInf += ": ";
468  displaySolInf.addMsgAndSol(sInf, *evalPointList.begin());
469  }
470  else
471  {
472  sInf += "s: ";
473  displaySolInf.addMsgAndSol(sInf, *evalPointList.begin());
474  }
475 
476  if (nbBestInf > 1)
477  {
478  size_t solCount = 0;
479  std::vector<NOMAD::EvalPoint>::const_iterator it;
480  for (it = evalPointList.begin(); it != evalPointList.end(); ++it)
481  {
482  solCount++;
483  if (evalPointList.begin() == it)
484  {
485  continue; // First element already added
486  }
487  displaySolInf.addMsgAndSol(" ",(*it));
488  if (solCount >= maxSolCount)
489  {
490  // We printed enough solutions already.
491  displaySolInf.addMsg("... A total of " + std::to_string(evalPointList.size()) + " infeasible solutions were found.");
492  break;
493  }
494  }
495  }
496 
497  NOMAD::OutputQueue::Add(std::move(displaySolInf));
498 }
499 
500 
501 void NOMAD::Algorithm::displayEvalCounts() const
502 {
503  // Display evaluation information
504 
505  // Used to display or not certain values
506  bool isSub = isSubAlgo();
507 
508  // Actual numbers
509  size_t bbEval = NOMAD::EvcInterface::getEvaluatorControl()->getBbEval();
510  size_t lapBbEval = NOMAD::EvcInterface::getEvaluatorControl()->getLapBbEval();
511  size_t nbEval = NOMAD::EvcInterface::getEvaluatorControl()->getNbEval();
512  size_t sgteEval = NOMAD::EvcInterface::getEvaluatorControl()->getSgteEval();
513  size_t totalSgteEval = NOMAD::EvcInterface::getEvaluatorControl()->getTotalSgteEval();
514  size_t nbCacheHits = NOMAD::CacheBase::getNbCacheHits();
515  int nbEvalNoCount = static_cast<int>(nbEval - bbEval - nbCacheHits);
516 
517  // What needs to be shown, according to the counts and to the value of isSub
518  bool showNbEvalNoCount = (nbEvalNoCount > 0);
519  bool showSgteEval = isSub && (sgteEval > 0);
520  bool showTotalSgteEval = (totalSgteEval > 0);
521  bool showNbCacheHits = (nbCacheHits > 0);
522  bool showNbEval = (nbEval > bbEval);
523  bool showLapBbEval = isSub && (bbEval > lapBbEval && lapBbEval > 0);
524 
525  // Output levels will be modulated depending on the counts and on the Algorithm level.
526  NOMAD::OutputLevel outputLevelHigh = isSub ? NOMAD::OutputLevel::LEVEL_INFO
527  : NOMAD::OutputLevel::LEVEL_HIGH;
528  NOMAD::OutputLevel outputLevelNormal = isSub ? NOMAD::OutputLevel::LEVEL_INFO
529  : NOMAD::OutputLevel::LEVEL_NORMAL;
530 
531  // Padding for nice presentation
532  std::string sFeedBbEval, sFeedLapBbEval, sFeedNbEvalNoCount, sFeedSgteEval,
533  sFeedTotalSgteEval, sFeedCacheHits, sFeedNbEval;
534 
535  // Conditional values: showNbEval, showNbEvalNoCount, showLapBbEval
536  if (showLapBbEval) // Longest title
537  {
538  sFeedBbEval += " ";
539  //sFeedLapBbEval += "";
540  sFeedNbEvalNoCount += " ";
541  sFeedSgteEval += " ";
542  sFeedTotalSgteEval += " ";
543  sFeedCacheHits += " ";
544  sFeedNbEval += " ";
545  }
546  else if (showNbEvalNoCount) // Second longest
547  {
548  sFeedBbEval += " ";
549  //sFeedLapBbEval += "";
550  //sFeedNbEvalNoCount += "";
551  sFeedSgteEval += " ";
552  sFeedTotalSgteEval += " ";
553  sFeedCacheHits += " ";
554  sFeedNbEval += " ";
555  }
556  else if (showNbEval) // 3rd longest title
557  {
558  sFeedBbEval += " ";
559  //sFeedLapBbEval += "";
560  //sFeedNbEvalNoCount += "";
561  sFeedSgteEval += " ";
562  sFeedTotalSgteEval += " ";
563  sFeedCacheHits += " ";
564  //sFeedNbEval += "";
565  }
566 
567  std::string sBbEval = "Blackbox evaluations: " + sFeedBbEval + NOMAD::itos(bbEval);
568  std::string sLapBbEval = "Sub-optimization blackbox evaluations: " + sFeedLapBbEval + NOMAD::itos(lapBbEval);
569  std::string sNbEvalNoCount = "Blackbox evaluation (not counting): " + sFeedNbEvalNoCount + NOMAD::itos(nbEvalNoCount);
570  std::string sSgteEval = "Sgte evaluations: " + sFeedSgteEval + NOMAD::itos(sgteEval);
571  std::string sTotalSgteEval = "Total sgte evaluations: " + sFeedTotalSgteEval + NOMAD::itos(totalSgteEval);
572  std::string sCacheHits = "Cache hits: " + sFeedCacheHits + NOMAD::itos(nbCacheHits);
573  std::string sNbEval = "Total number of evaluations: " + sFeedNbEval + NOMAD::itos(nbEval);
574 
575 
576 #ifdef TIME_STATS
577  std::string sTotalRealTime = "Total real time (round s): " + std::to_string(_totalRealAlgoTime);
578  std::string sTotalCPUTime = "Total CPU time (s): " + std::to_string(_totalCPUAlgoTime);
579  #endif // TIME_STATS
580 
581  AddOutputInfo("", outputLevelHigh); // skip line
582  // Always show number of blackbox evaluations
583  AddOutputInfo(sBbEval, outputLevelHigh);
584  // The other values are conditional to the show* booleans
585  if (showLapBbEval)
586  {
587  AddOutputInfo(sLapBbEval, outputLevelNormal);
588  }
589  if (showNbEvalNoCount)
590  {
591  AddOutputInfo(sNbEvalNoCount, outputLevelNormal);
592  }
593  if (showSgteEval)
594  {
595  AddOutputInfo(sSgteEval, outputLevelNormal);
596  }
597  if (showTotalSgteEval)
598  {
599  AddOutputInfo(sTotalSgteEval, outputLevelNormal);
600  }
601  if (showNbCacheHits)
602  {
603  AddOutputInfo(sCacheHits, outputLevelNormal);
604  }
605  if (showNbEval)
606  {
607  AddOutputInfo(sNbEval, outputLevelNormal);
608  }
609 
610 #ifdef TIME_STATS
611  {
612  AddOutputInfo(sTotalRealTime, outputLevelNormal);
613  AddOutputInfo(sTotalCPUTime, outputLevelNormal);
614  }
615 #endif // TIME_STATS
616 }
617 
618 
619 bool NOMAD::Algorithm::isSubAlgo() const
620 {
621  bool isSub = false;
622 
623  auto parentAlgo = getParentOfType<NOMAD::Algorithm*>();
624  if (nullptr != parentAlgo)
625  {
626  isSub = true;
627  }
628 
629  return isSub;
630 }
631 
632 
633 bool NOMAD::Algorithm::terminate(const size_t iteration)
634 {
635  return _termination->terminate(iteration);
636 }
637 
638 
639 void NOMAD::Algorithm::display ( std::ostream& os ) const
640 {
641 
642  os << "MEGA_ITERATION " << std::endl;
643  os << *_megaIteration << std::endl;
644  os << "NB_EVAL " << NOMAD::EvcInterface::getEvaluatorControl()->getNbEval() << std::endl;
645  os << "NB_BB_EVAL " << NOMAD::EvcInterface::getEvaluatorControl()->getBbEval() << std::endl;
646  uint32_t x, y, z;
647  NOMAD::RNG::getPrivateSeed(x, y, z);
648  os << "RNG " << x << " " << y << " " << z << std::endl;
649 
650 }
651 
652 
653 std::ostream& NOMAD::operator<<(std::ostream& os, const NOMAD::Algorithm & mads)
654 {
655  mads.display(os);
656  return os;
657 }
658 
659 
660 void NOMAD::Algorithm::read(std::istream& is)
661 {
662  // Read line by line
663  std::string name;
664 
665  int nbEval = 0, nbBbEval = 0;
666  uint32_t x, y, z;
667 
668  while (is >> name && is.good() && !is.eof())
669  {
670  if ("MEGA_ITERATION" == name)
671  {
672  is >> *_megaIteration;
673  }
674  else if ("NB_EVAL" == name)
675  {
676  is >> nbEval;
677  }
678  else if ("NB_BB_EVAL" == name)
679  {
680  is >> nbBbEval;
681  }
682  else if ("RNG" == name)
683  {
684  is >> x >> y >> z;
685  NOMAD::RNG::setPrivateSeed(x, y, z);
686  }
687  else
688  {
689  // Put back name to istream. Maybe there is a simpler way.
690  for (unsigned i = 0; i < name.size(); i++)
691  {
692  is.unget();
693  }
694  break;
695  }
696  }
697 
698  NOMAD::EvcInterface::getEvaluatorControl()->setBbEval(nbBbEval);
699  NOMAD::EvcInterface::getEvaluatorControl()->setNbEval(nbEval);
700 
701 }
702 
703 
704 std::istream& NOMAD::operator>>(std::istream& is, NOMAD::Algorithm& algo)
705 {
706  algo.read(is);
707  return is;
708 
709 }
ArrayOfPoint
std::vector< Point > ArrayOfPoint
Type definition for the representation of a vector of points.
Definition: ArrayOfPoint.hpp:63
OutputLevel
OutputLevel
Level of output AKA Display degree.
Definition: OutputInfo.hpp:55
uint32_t
unsigned int uint32_t
Definition: defines.hpp:88
write
bool write(const T &info, const std::string &filename)
Definition: fileutils.hpp:147
operator>>
std::istream & operator>>(std::istream &is, Algorithm &algo)
Operator to read parameters used for hot restart.
read
bool read(T &info, const std::string &filename)
Definition: fileutils.hpp:185
operator<<
std::ostream & operator<<(std::ostream &os, const Algorithm &algo)
Operator to write parameters used for hot restart.
convertPointListToFull
void convertPointListToFull(EvalPointList &evalPointList, const Point &fixedVariable)
INF_SIZE_T
const size_t INF_SIZE_T
The infinity for size_t.
Definition: defines.hpp:129
itos
std::string itos(const int i)
Transform an integer into a string.
Definition: utils.cpp:63