2 #include "../../Algos/CacheInterface.hpp"
3 #include "../../Algos/EvcInterface.hpp"
5 #include "../../Algos/Mads/GMesh.hpp"
6 #include "../../Algos/Mads/MadsInitialization.hpp"
9 void NOMAD::MadsInitialization::init()
11 _name =
"MadsInitialization";
16 bool NOMAD::MadsInitialization::run()
18 bool doContinue = ! _stopReasons->checkTerminate();
23 doContinue = ! _stopReasons->checkTerminate();
29 void NOMAD::MadsInitialization::validateX0s()
const
32 size_t n = _pbParams->getAttributeValue<
size_t>(
"DIMENSION");
33 bool validX0available =
false;
36 for (
size_t x0index = 0; x0index < x0s.size(); x0index++)
38 auto x0 = x0s[x0index];
39 if (!x0.isComplete() || x0.size() != n)
41 err +=
"Initialization: eval_x0s: Invalid X0 " + x0.display() +
".";
45 validX0available =
true;
53 AddOutputWarning(err);
59 size_t cacheSize = NOMAD::CacheBase::getInstance()->size();
62 err +=
" Hint: Try not setting X0 so that the cache is used (";
63 err += std::to_string(cacheSize) +
" points)";
67 err +=
". Cache is empty.";
69 throw NOMAD::Exception(__FILE__, __LINE__, err);
75 bool NOMAD::MadsInitialization::eval_x0s()
84 NOMAD::CacheInterface cacheInterface(
this);
85 NOMAD::EvcInterface evcInterface(
this);
86 evcInterface.getEvaluatorControl()->lockQueue();
89 for (
size_t x0index = 0; x0index < x0s.size(); x0index++)
91 auto x0 = x0s[x0index];
92 NOMAD::EvalPoint evalPoint_x0(x0);
93 evalPointSet.insert(evalPoint_x0);
99 evcInterface.keepPointsThatNeedEval(evalPointSet,
false);
102 auto evcParams = evcInterface.getEvaluatorControl()->getEvaluatorControlParams();
103 auto previousOpportunism = evcParams->getAttributeValue<
bool>(
"OPPORTUNISTIC_EVAL");
104 evcParams->setAttributeValue(
"OPPORTUNISTIC_EVAL",
false);
105 evcParams->checkAndComply();
107 evcInterface.getEvaluatorControl()->unlockQueue(
false);
111 evcInterface.startEvaluation();
114 evcInterface.getEvaluatorControl()->lockQueue();
115 evcParams->setAttributeValue(
"OPPORTUNISTIC_EVAL", previousOpportunism);
116 evcParams->checkAndComply();
117 evcInterface.getEvaluatorControl()->unlockQueue(
false);
121 NOMAD::EvalPoint evalPoint_x0(x0);
122 cacheInterface.find(x0, evalPoint_x0);
123 if (evalPoint_x0.isEvalOk())
127 AddOutputInfo(
"Using X0: " + evalPoint_x0.display());
131 auto madsStopReason = NOMAD::AlgoStopReasons<NOMAD::MadsStopType>::get( _stopReasons );
132 madsStopReason->set ( NOMAD::MadsStopType::X0_FAIL );
134 AddOutputError(
"X0 evaluation failed for X0 = " + x0.display());
138 NOMAD::OutputQueue::Flush();
std::set< EvalPoint, EvalPointCompare > EvalPointSet
Definition for EvalPointSet.
std::vector< Point > ArrayOfPoint
Representation of a vector of points.