Skip to content

Commit

Permalink
Small fixes after feedback from expert users
Browse files Browse the repository at this point in the history
  • Loading branch information
Viviane Rochon Montplaisir committed Dec 19, 2019
1 parent 3fcc7f5 commit 722e42c
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 76 deletions.
4 changes: 2 additions & 2 deletions examples/basic/batch/example1/bb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ int main (int argc, char **argv)
f -= (sum1 -2*prod1) / std::abs(sqrt(sum3));
}
// Scale
if (!isnan(f))
if (!std::isnan(f))
{
f *= 1e-5;
}

eval_ok = !isnan(f);
eval_ok = !std::isnan(f);

g3 = - (f + 2000);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Algos/MainStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void NOMAD::MainStep::printNumThreads() const
bool NOMAD::MainStep::detectPhaseOne()
{
bool hasEBConstraints = false;
bool hasNoFeas = true;
bool hasNoFeas = !NOMAD::CacheBase::getInstance()->hasFeas();

auto bbOutputTypeList = _allParams->getEvalParams()->getAttributeValue<NOMAD::BBOutputTypeList>("BB_OUTPUT_TYPE");
if (std::find(bbOutputTypeList.begin(), bbOutputTypeList.end(), NOMAD::BBOutputType::EB)
Expand All @@ -468,8 +468,6 @@ bool NOMAD::MainStep::detectPhaseOne()
hasEBConstraints = true;
}

hasNoFeas = !NOMAD::CacheBase::getInstance()->hasFeas();

return hasEBConstraints && hasNoFeas;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Algos/NelderMead/NMReflective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ void NOMAD::NMReflective::generateTrialPoints ()
// Determine the centroid of Y
std::set<NOMAD::EvalPoint>::iterator it;
std::set<NOMAD::EvalPoint>::iterator itBeforeEnd = _nmY->end();
itBeforeEnd--;
--itBeforeEnd;
int i=0;
NOMAD::Point yc(n,0);
for ( it = _nmY->begin() ; it != itBeforeEnd ; it++,i++)
for (it = _nmY->begin() ; it != itBeforeEnd ; ++it, i++)
{
AddOutputInfo("y" + std::to_string(i) + ": " + (*it).display() );
for (size_t k = 0 ; k < n ; ++k )
Expand Down Expand Up @@ -483,7 +483,7 @@ bool NOMAD::NMReflective::insertInYBest( const NOMAD::Point & x1 , const NOMAD::
bool x2EvalOK = ( X2.getEvalStatus(evalType) == NOMAD::EvalStatusType::EVAL_OK );

std::set<NOMAD::EvalPoint>::iterator itYn = _nmY->end();
itYn--;
--itYn;

AddOutputDebug("Insertion/Deletion of points in Y: ");

Expand Down
11 changes: 5 additions & 6 deletions src/Algos/Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,17 @@ void NOMAD::Projection::projectPoint(const NOMAD::EvalPoint& oraclePoint)
AddOutputInfo(subStepName, true, false);

NOMAD::EvalPointSet trySet;
size_t nbCachePoints;

NOMAD::CacheInterface cacheInterface(this);
std::vector<NOMAD::EvalPoint> evalPointList;
size_t nbCachePoints = cacheInterface.getAllPoints(evalPointList);

for (auto index : _indexSet)
{
// Compute perturbation
auto perturbation = computePerturbation(oraclePoint, index);

// Loop on points of the cache
NOMAD::CacheInterface cacheInterface(this);
std::vector<NOMAD::EvalPoint> evalPointList;
nbCachePoints = cacheInterface.getAllPoints(evalPointList);

for (auto xRef : evalPointList)
{
auto xTry = buildProjectionTrialPoint(xRef, perturbation);
Expand All @@ -199,7 +198,7 @@ void NOMAD::Projection::projectPoint(const NOMAD::EvalPoint& oraclePoint)

s = std::to_string(_indexSet.size()) + " perturbation vectors";
NOMAD::OutputQueue::Add(s, _displayLevel);
s = std::to_string(nbCachePoints) + " perturbation vectors";
s = std::to_string(nbCachePoints) + " cache points";
NOMAD::OutputQueue::Add(s, _displayLevel);
s = std::to_string(trySet.size()) + " projection candidates";
NOMAD::OutputQueue::Add(s, _displayLevel);
Expand Down
28 changes: 12 additions & 16 deletions src/Algos/SgtelibModel/SgtelibModelFilterCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool NOMAD::SgtelibModelFilterCache::runImp()

// Get used methods from parameter
const size_t methodMax = 10;
bool useMethod[methodMax];
bool useMethod[methodMax] = { false };
size_t nbMethods = 0;
std::string filterParam = _runParams->getAttributeValue<std::string>("SGTELIB_MODEL_FILTER");
for (size_t i = 0; i < methodMax; i++)
Expand All @@ -123,10 +123,6 @@ bool NOMAD::SgtelibModelFilterCache::runImp()
useMethod[i] = true;
nbMethods++;
}
else
{
useMethod[i] = false;
}
}

// Display info
Expand Down Expand Up @@ -389,7 +385,6 @@ int NOMAD::SgtelibModelFilterCache::applyMethod(NOMAD::FilterSelectionMethod met
double dmin = 0;
double dmax = 0;
int nmax = 0;
int ni = -1;
double deltaMNorm = 0;
if (_modelAlgo->getDeltaMNorm().isDefined())
{
Expand Down Expand Up @@ -431,6 +426,7 @@ int NOMAD::SgtelibModelFilterCache::applyMethod(NOMAD::FilterSelectionMethod met

case NOMAD::FilterSelectionMethod::METHOD_BEST_MIN_DIST:
// Select the best point but with a minimum distance to points already selected
// dmin is 0 at this point
s = "dmin = " + NOMAD::Double(dmin).display();
NOMAD::OutputQueue::Add(s, _displayLevel);
for (size_t i = 0; i < nbSgte; i++)
Expand All @@ -445,15 +441,15 @@ int NOMAD::SgtelibModelFilterCache::applyMethod(NOMAD::FilterSelectionMethod met
iSelect = static_cast<int>(i);
}
}
}
if (-1 != iSelect)
{
s = "d = " + NOMAD::Double(_DTX[iSelect]).display();
NOMAD::OutputQueue::Add(s, _displayLevel);
s = "h select = " + NOMAD::Double(hmin).display();
NOMAD::OutputQueue::Add(s, _displayLevel);
if (-1 != iSelect)
{
s = "d = " + NOMAD::Double(_DTX[iSelect]).display();
NOMAD::OutputQueue::Add(s, _displayLevel);
s = "h select = " + NOMAD::Double(hmin).display();
NOMAD::OutputQueue::Add(s, _displayLevel);

dmin = _DTX[iSelect] + deltaMNorm;
dmin = std::max(dmin, _DTX[iSelect] + deltaMNorm);
}
}
break;

Expand Down Expand Up @@ -486,7 +482,7 @@ int NOMAD::SgtelibModelFilterCache::applyMethod(NOMAD::FilterSelectionMethod met
{
if ( (!_keep[i]) && (_distIsolation[i] > 0) )
{
ni = _nIsolation[i];
int ni = _nIsolation[i];
// If criteria undef, then compute.
if (-1 == ni)
{
Expand Down Expand Up @@ -519,7 +515,7 @@ int NOMAD::SgtelibModelFilterCache::applyMethod(NOMAD::FilterSelectionMethod met
{
if ( (!_keep[i]) && (_DTX[i] > 0) )
{
ni = _nDensity[i];
int ni = _nDensity[i];
// If criteria undef, then compute.
if (-1 == ni)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Algos/SgtelibModel/SgtelibModelMegaIteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ bool NOMAD::SgtelibModelMegaIteration::runImp()
else
{
// DEBUG - ensure OPPORTUNISM is off.
NOMAD::EvcInterface evcInterface(this);
auto evcParams = evcInterface.getEvaluatorControl()->getEvaluatorControlParams();
auto evcParams = NOMAD::EvcInterface::getEvaluatorControl()->getEvaluatorControlParams();
auto previousOpportunism = evcParams->getAttributeValue<bool>("OPPORTUNISTIC_EVAL");
if (previousOpportunism)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/CacheSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool NOMAD::CacheSet::smartInsert(const NOMAD::EvalPoint &evalPoint,
}

bool inserted = false;
bool doEval = true;
bool doEval;
std::pair<EvalPointSet::iterator,bool> ret; // Return of the insert()
#ifdef _OPENMP
omp_set_lock(&_cacheLock);
Expand Down
45 changes: 26 additions & 19 deletions src/Eval/BBOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ NOMAD::Double NOMAD::BBOutput::getObjective(const NOMAD::BBOutputTypeList &bbOut
NOMAD::ArrayOfString array(_rawBBO);
NOMAD::Double obj;

checkSizeMatch(bbOutputType, array);

for (size_t i = 0; i < array.size(); i++)
if (checkSizeMatch(bbOutputType))
{
if (NOMAD::BBOutputType::OBJ == bbOutputType[i])
for (size_t i = 0; i < array.size(); i++)
{
obj.atof(array[i]);
break;
if (NOMAD::BBOutputType::OBJ == bbOutputType[i])
{
obj.atof(array[i]);
break;
}
}
}
return obj;
Expand All @@ -116,17 +117,18 @@ NOMAD::ArrayOfDouble NOMAD::BBOutput::getConstraints(const NOMAD::BBOutputTypeLi
NOMAD::ArrayOfString array(_rawBBO);
NOMAD::ArrayOfDouble constraints;

checkSizeMatch(bbOutputType, array);

for (size_t i = 0; i < array.size(); i++)
if (checkSizeMatch(bbOutputType))
{
if ( NOMAD::BBOutputTypeIsConstraint(bbOutputType[i]) )
for (size_t i = 0; i < array.size(); i++)
{
NOMAD::Double d;
d.atof(array[i]);
size_t constrSize = constraints.size();
constraints.resize(constrSize + 1);
constraints[constrSize] = d;
if ( NOMAD::BBOutputTypeIsConstraint(bbOutputType[i]) )
{
NOMAD::Double d;
d.atof(array[i]);
size_t constrSize = constraints.size();
constraints.resize(constrSize + 1);
constraints[constrSize] = d;
}
}
}

Expand All @@ -151,10 +153,12 @@ NOMAD::ArrayOfDouble NOMAD::BBOutput::getBBOAsArrayOfDouble() const

// Helper function.
// Verify that the given output type list has the same size as the raw output.
// Throw an exception if this is not the case.
void NOMAD::BBOutput::checkSizeMatch(const NOMAD::BBOutputTypeList &bbOutputType,
const NOMAD::ArrayOfString &array) const
// Show an error, and return false, if this is not the case.
bool NOMAD::BBOutput::checkSizeMatch(const NOMAD::BBOutputTypeList &bbOutputType) const
{
bool ret = true;
NOMAD::ArrayOfString array(_rawBBO);

if (bbOutputType.size() != array.size())
{
std::string err = "Error: Parameter BB_OUTPUT_TYPE has " + NOMAD::itos(bbOutputType.size());
Expand All @@ -171,8 +175,11 @@ void NOMAD::BBOutput::checkSizeMatch(const NOMAD::BBOutputTypeList &bbOutputType
}
err += ":\n";
err += _rawBBO;
throw NOMAD::Exception(__FILE__, __LINE__, err);
std::cerr << err << std::endl;
ret = false;
}

return ret;
}


Expand Down
11 changes: 4 additions & 7 deletions src/Eval/BBOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,14 @@ class BBOutput {
/// Display
void display (std::ostream & out) const;

private:
/// Helper functions that can trigger exception.
/**
Exception is triggered if the BBOutputList and
the ArrayOfString have inconsistent size.
Verify if the BBOutputList and the ArrayOfString have consistent size.
A warning is displayed if this is not the case.
\param bbOutputType The list of blackbox output type -- \b IN.
\param array The array of string -- \b IN.
\return \c true if the sizes match
*/
void checkSizeMatch(const BBOutputTypeList &bbOutputType,
const ArrayOfString &array) const;
bool checkSizeMatch(const BBOutputTypeList &bbOutputType) const;

};

Expand Down
14 changes: 10 additions & 4 deletions src/Eval/Eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ NOMAD::Eval::Eval(std::shared_ptr<NOMAD::EvalParameters> params,
auto bbOutputType = params->getAttributeValue<NOMAD::BBOutputTypeList>("BB_OUTPUT_TYPE");



// Note: if bbOutput is not eval_ok, then _f and _h end up undefined Doubles.
_f = computeF(bbOutputType);

// Set H
setH (_computeH(*this, bbOutputType) );
setH (_computeH(*this, bbOutputType));
_toBeRecomputed = false;

if (_bbOutput.getEvalOk() && _f.isDefined())
Expand Down Expand Up @@ -349,8 +348,15 @@ void NOMAD::Eval::setBBOutputAndRecompute(const NOMAD::BBOutput& bbOutput,
const NOMAD::BBOutputTypeList& bbOutputType)
{
setBBOutput(bbOutput);
setF(computeF(bbOutputType));
setH(_computeH(*this, bbOutputType));
if (!bbOutput.checkSizeMatch(bbOutputType))
{
_evalStatus = NOMAD::EvalStatusType::EVAL_ERROR;
}
else
{
setF(computeF(bbOutputType));
setH(_computeH(*this, bbOutputType));
}
toRecompute(false);
}

Expand Down
28 changes: 25 additions & 3 deletions src/Eval/EvalPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ void NOMAD::EvalPoint::setBBO(const std::string &bbo,
{
switch (evalType)
{
// Create new Eval
case NOMAD::EvalType::SGTE:
_evalSgte = NOMAD::EvalUPtr(new NOMAD::Eval());
break;
Expand All @@ -516,7 +517,14 @@ void NOMAD::EvalPoint::setBBO(const std::string &bbo,
eval = getEval(evalType);
}

eval->setBBO(bbo, bboutputtypes, evalOk);
if (nullptr == eval)
{
throw NOMAD::Exception(__FILE__, __LINE__, "EvalPoint::setBBO: Could not create new Eval");
}
else
{
eval->setBBO(bbo, bboutputtypes, evalOk);
}

}

Expand Down Expand Up @@ -551,7 +559,14 @@ void NOMAD::EvalPoint::setBBO(const NOMAD::BBOutput& bbo,
}
eval = getEval(evalType);
}
eval->setBBOutput(bbo);
if (nullptr == eval)
{
throw NOMAD::Exception(__FILE__, __LINE__, "EvalPoint::setBBO: Could not create new Eval");
}
else
{
eval->setBBOutput(bbo);
}
}


Expand Down Expand Up @@ -589,7 +604,14 @@ void NOMAD::EvalPoint::setEvalStatus(const NOMAD::EvalStatusType &evalStatus,
eval = getEval(evalType);
}

eval->setEvalStatus(evalStatus);
if (nullptr == eval)
{
throw NOMAD::Exception(__FILE__, __LINE__, "EvalPoint::setEvalStatus: Could not create new Eval");
}
else
{
eval->setEvalStatus(evalStatus);
}
}


Expand Down
Loading

0 comments on commit 722e42c

Please sign in to comment.