47 #include "../../Algos/AlgoStopReasons.hpp"
48 #include "../../Algos/CacheInterface.hpp"
49 #include "../../Algos/EvcInterface.hpp"
50 #include "../../Algos/SubproblemManager.hpp"
51 #include "../../Algos/Mads/GMesh.hpp"
52 #include "../../Algos/Mads/MadsInitialization.hpp"
53 #include "../../Cache/CacheBase.hpp"
54 #include "../../Output/OutputQueue.hpp"
58 void NOMAD::MadsInitialization::init()
60 _name = NOMAD::Initialization::getName();
64 bool NOMAD::MadsInitialization::runImp()
66 _initialMesh = std::make_shared<NOMAD::GMesh>(_pbParams);
68 bool doContinue = ! _stopReasons->checkTerminate();
73 doContinue = ! _stopReasons->checkTerminate();
79 void NOMAD::MadsInitialization::validateX0s()
const
82 size_t n = _pbParams->getAttributeValue<
size_t>(
"DIMENSION");
83 bool validX0available =
false;
86 for (
size_t x0index = 0; x0index < x0s.size(); x0index++)
88 auto x0 = x0s[x0index];
89 if (!x0.isComplete() || x0.size() != n)
91 err +=
"Initialization: eval_x0s: Invalid X0 " + x0.display() +
".";
95 validX0available =
true;
103 AddOutputWarning(err);
109 size_t cacheSize = NOMAD::CacheBase::getInstance()->size();
112 err +=
" Hint: Try not setting X0 so that the cache is used (";
113 err += std::to_string(cacheSize) +
" points)";
117 err +=
". Cache is empty.";
119 throw NOMAD::Exception(__FILE__, __LINE__, err);
125 bool NOMAD::MadsInitialization::eval_x0s()
135 NOMAD::CacheInterface cacheInterface(
this);
136 NOMAD::EvcInterface evcInterface(
this);
137 auto evc = evcInterface.getEvaluatorControl();
138 auto evalType = evc->getEvalType();
142 for (
size_t x0index = 0; x0index < x0s.size(); x0index++)
144 auto x0 = x0s[x0index];
145 NOMAD::EvalPoint evalPointX0(x0);
146 evalPointSet.insert(evalPointX0);
152 evcInterface.keepPointsThatNeedEval(evalPointSet,
false);
155 auto previousOpportunism = evc->getOpportunisticEval();
156 evc->setOpportunisticEval(
false);
157 evc->unlockQueue(
false);
161 evcInterface.startEvaluation();
164 evc->setOpportunisticEval(previousOpportunism);
166 bool x0Failed =
true;
170 auto evaluatedPoints = evcInterface.retrieveAllEvaluatedPoints();
171 std::vector<NOMAD::EvalPoint> evalPointX0s;
173 if (_stopReasons->checkTerminate())
180 NOMAD::EvalPoint evalPointX0(x0);
183 bool x0Found =
findInList(x0, evaluatedPoints, evalPointX0);
188 x0Found = evcInterface.findInBarrier(x0, evalPointX0);
194 if (evc->getUseCache())
197 x0Found = (cacheInterface.find(x0, evalPointX0, evalType) > 0);
202 x0Found = (cacheInterface.find(x0, evalPointX0) > 0);
207 if (x0Found && evalPointX0.isEvalOk(evalType))
211 evalPointX0s.push_back(evalPointX0);
220 auto madsStopReason = NOMAD::AlgoStopReasons<NOMAD::MadsStopType>::get(_stopReasons);
221 madsStopReason->set(NOMAD::MadsStopType::X0_FAIL);
225 auto x0Full = x0.makeFullSpacePointFromFixed(NOMAD::SubproblemManager::getSubFixedVariable(
this));
226 AddOutputError(
"X0 evaluation failed for X0 = " + x0Full.display());
232 for (
auto evalPointX0 : evalPointX0s)
236 s += (NOMAD::EvalType::BB == evalType) ? evalPointX0.display() : evalPointX0.displayAll();
242 auto hMax = _runParams->getAttributeValue<NOMAD::Double>(
"H_MAX_0");
243 _barrier = std::make_shared<NOMAD::Barrier>(hMax, NOMAD::SubproblemManager::getSubFixedVariable(
this), evalType, evalPointX0s);
246 NOMAD::OutputQueue::Flush();