NOMAD Source
Version 4.0.0 Beta
|
Class to control the evaluation of points using a queue. More...
#include <EvaluatorControl.hpp>
Public Member Functions | |
EvaluatorControl (std::shared_ptr< Evaluator > evaluator, const std::shared_ptr< EvaluatorControlGlobalParameters > &evalContGlobalParams, const std::shared_ptr< EvaluatorControlParameters > &evalContParams) | |
Constructor. More... | |
virtual | ~EvaluatorControl () |
Destructor. More... | |
void | addMainThread (const int threadNum, const std::shared_ptr< StopReason< EvalMainThreadStopType >> evalMainThreadStopReason, const std::shared_ptr< Evaluator > &evaluator, const std::shared_ptr< EvaluatorControlParameters > &evalContParams) |
bool | isMainThread (const int threadNum) const |
const std::set< int > & | getMainThreads () const |
int | getNbMainThreads () const |
std::shared_ptr< Evaluator > | setEvaluator (std::shared_ptr< Evaluator > evaluator) |
size_t | getBbEval () const |
Get the number of blackbox evaluations. More... | |
void | setBbEval (const size_t bbEval) |
Set blackbox evaluations number. More... | |
size_t | getBbEvalNotOk () const |
Get the number of blackbox evaluations that are not ok. More... | |
size_t | getFeasBbEval () const |
Get the number of feasible blackbox evaluations. More... | |
size_t | getSgteEval (const int mainThreadNum=-1) const |
void | resetSgteEval (const int mainThreadNum=-1) |
size_t | getTotalSgteEval () const |
size_t | getBbEvalInSubproblem (const int mainThreadNum=-1) const |
void | resetBbEvalInSubproblem (const int mainThreadNum=-1) |
size_t | getBlockEval () const |
Get the number of block evaluations. More... | |
size_t | getIndexSuccBlockEval () const |
Get the index of block evaluations. More... | |
size_t | getNbEval () const |
void | setNbEval (const size_t nbEval) |
Set the number of evaluations. More... | |
size_t | getLapMaxBbEval (const int mainThreadNum) const |
void | setLapMaxBbEval (const size_t maxBbEval) |
void | resetLapBbEval () |
size_t | getLapBbEval (const int threadNum=-1) const |
size_t | getNbPhaseOneSuccess () const |
size_t | getNbRelativeSuccess () const |
size_t | getIndexFeasEval () const |
size_t | getIndexInfeasEval () const |
size_t | getQueueSize (const int mainThreadNum=-1) const |
bool | getDoneWithEval (const int mainThreadNum) const |
void | setDoneWithEval (const int mainThreadNum, const bool doneWithEval) |
void | setBarrier (const std::shared_ptr< Barrier > &barrier) |
const std::shared_ptr< Barrier > & | getBarrier (const int threadNum=-1) const |
void | setBestIncumbent (const int mainThreadNum, const std::shared_ptr< EvalPoint > &bestIncumbent) |
const std::shared_ptr< EvalPoint > & | getBestIncumbent (const int mainThreadNum) const |
void | setComputeSuccessTypeFunction (const ComputeSuccessFunction &computeSuccessFunction) |
void | setUserCompMethod (const std::shared_ptr< ComparePriorityMethod > &compMethod) |
void | setLastSuccessfulDir (const std::shared_ptr< Direction > &dir) |
void | setStopReason (const int mainThreadNum, const EvalMainThreadStopType &s) |
const StopReason< EvalMainThreadStopType > & | getStopReason (const int mainThreadNum) const |
std::string | getStopReasonAsString (const int mainThreadNum) const |
bool | testIf (const EvalMainThreadStopType &s) const |
bool | checkEvalTerminate (const int mainThreadNum) const |
std::vector< EvalPoint > | retrieveAllEvaluatedPoints (const int threadNum=-1) |
Get all points that were just evaluated. This is especially useful when cache is not used. More... | |
void | addEvaluatedPoint (const int threadNum, const EvalPoint &evaluatedPoint) |
bool | remainsEvaluatedPoints (const int threadNum) const |
void | clearEvaluatedPoints (const int threadNum) |
const SuccessType & | getSuccessType (const int threadNum) const |
void | setSuccessType (const int threadNum, const SuccessType &success) |
Double | getHMax (const int threadNum) const |
Get the max infeasibility to keep a point in barrier. More... | |
const std::shared_ptr< EvaluatorControlGlobalParameters > & | getEvaluatorControlGlobalParams () const |
Get the global parameters for *this . More... | |
std::shared_ptr< EvalParameters > | getEvalParams (const int threadNum=-1) const |
Get the Evaluator's parameters. More... | |
bool | getOpportunisticEval (const int mainThreadNum=-1) const |
Get or Set the value of some parameters. More... | |
void | setOpportunisticEval (const bool opportunistic) |
bool | getUseCache (const int mainThreadNum=-1) const |
void | setUseCache (const bool usecache) |
EvalType | getEvalType (const int mainThreadNum=-1) const |
size_t | getMaxBbEvalInSubproblem (const int mainThreadNum=-1) const |
void | setMaxBbEvalInSubproblem (const size_t maxBbEval) |
void | lockQueue () |
Lock the queue. More... | |
void | unlockQueue (const bool doSort=true) |
Unlock the queue. More... | |
bool | addToQueue (const EvalQueuePointPtr &evalQueuePoint) |
Add a single point to the queue. More... | |
bool | popEvalPoint (EvalQueuePointPtr &evalQueuePoint, Evaluator *&evaluator, Double &hMax) |
Get the top point from the queue and pop it. More... | |
bool | popBlock (BlockForEval &block) |
Pop eval points from the queue to fill a block of size BB_MAX_BLOCK_SIZE. More... | |
size_t | clearQueue (const int mainThreadNum, const bool showDebug=false) |
Clear queue. More... | |
void | start () |
Start evaluation. More... | |
SuccessType | run () |
Continuous evaluation - running on all threads simultaneously. More... | |
void | stop () |
Stop evaluation. More... | |
void | restart () |
Restart. More... | |
bool | evalBlock (BlockForEval &block) |
Evaluates a block of points. More... | |
bool | evalSinglePoint (EvalPoint &evalPoint, const int mainThreadNum, const Double &hMax=INF) |
Evaluates a single point. More... | |
std::vector< bool > | evalBlockOfPoints (Block &block, const Evaluator &evaluator, const Double &hMax=INF) |
Evaluates a block of points. More... | |
bool | updateEvalStatusBeforeEval (EvalPoint &evalPoint) |
Updates eval status. More... | |
void | updateEvalStatusAfterEval (EvalPoint &evalPoint, bool evalOk) |
Updates eval status. More... | |
bool | reachedMaxEval () const |
Did we reach one of the evaluation parameters: MAX_EVAL, MAX_BB_EVAL, MAX_BLOCK_EVAL ? More... | |
bool | reachedMaxStepEval (const int mainThreadNum=-1) const |
Did we reach Max LAP, MAX_SGTE_EVAL (temporary max evals)? More... | |
void | debugDisplayQueue () const |
For debugging purposes. Show the contents of the evaluation queue. More... | |
Private Member Functions | |
void | init (std::shared_ptr< Evaluator > evaluator, const std::shared_ptr< EvaluatorControlParameters > &evalContParams) |
Helper for constructor. More... | |
void | destroy () |
Helper for destructor. More... | |
EvcMainThreadInfo & | getMainThreadInfo (const int mainThreadNum=-1) const |
Get the EvcMainThreadInfo associated with this thread number. More... | |
void | computeSuccess (EvalQueuePointPtr evalQueuePoint, const bool evalOk, const Double &hMax) |
Helper function called during evaluation. More... | |
void | sort () |
Sort the queue with respect to the selected sort strategy. Called by unlockQueue(). More... | |
bool | stopMainEval (const int mainThreadNum) const |
Did we reach a stop condition (for a main thread)? More... | |
void | displayDebugWaitingInfo (time_t &lastDisplayed) const |
Debug trace when a thread is waiting. More... | |
void | AddStatsInfo (const BlockForEval &block) const |
Stats Output. More... | |
void | AddDirectToFileInfo (EvalQueuePointPtr evalQueuePoint) const |
History and Solution file output. More... | |
Private Attributes | |
std::shared_ptr< EvaluatorControlGlobalParameters > | _evalContGlobalParams |
The parameters controlling the behavior of the class. More... | |
std::set< int > | _mainThreads |
std::map< int, EvcMainThreadInfo > | _mainThreadInfo |
Info about main threads. More... | |
std::vector< EvalQueuePointPtr > | _evalPointQueue |
The queue of points to be evaluated. More... | |
std::shared_ptr< ComparePriorityMethod > | _userCompMethod |
User-implemented comparison method to sort points before evaluation. More... | |
std::atomic< size_t > | _bbEval |
The number of blackbox evaluations performed. More... | |
std::atomic< size_t > | _bbEvalNotOk |
The number of blackbox evaluations that are not ok. More... | |
std::atomic< size_t > | _feasBBEval |
The number of feasible blackbox evaluations obtained. More... | |
std::atomic< size_t > | _infBBEval |
The number of infeasible blackbox evaluations obtained. More... | |
std::atomic< size_t > | _totalSgteEval |
The total number of sgte evaluations. Used for stats exclusively. More... | |
std::atomic< size_t > | _blockEval |
The number of block evaluations performed. More... | |
std::atomic< size_t > | _indexSuccBlockEval |
The index of the last successfull evaluation block. More... | |
std::atomic< size_t > | _indexBestFeasEval |
The index of the best feasible evaluation. More... | |
std::atomic< size_t > | _indexBestInfeasEval |
The index of the best infeasible evaluation. More... | |
std::atomic< size_t > | _nbEvalSentToEvaluator |
std::atomic< size_t > | _nbRelativeSuccess |
std::atomic< size_t > | _nbPhaseOneSuccess |
bool | _allDoneWithEval |
All evaluations done. The queue can be destroyed. More... | |
Class to control the evaluation of points using a queue.
Definition at line 75 of file EvaluatorControl.hpp.
|
inlineexplicit |
Constructor.
evaluator | The blackbox evaluator – IN. |
evalContGlobalParams | The parameters controlling how the class works – IN. |
evalContParams | The parameters for main threads – IN. |
Definition at line 195 of file EvaluatorControl.hpp.
|
inlinevirtual |
|
private |
History and Solution file output.
void EvaluatorControl::addEvaluatedPoint | ( | const int | threadNum, |
const EvalPoint & | evaluatedPoint | ||
) |
void EvaluatorControl::addMainThread | ( | const int | threadNum, |
const std::shared_ptr< StopReason< EvalMainThreadStopType >> | evalMainThreadStopReason, | ||
const std::shared_ptr< Evaluator > & | evaluator, | ||
const std::shared_ptr< EvaluatorControlParameters > & | evalContParams | ||
) |
|
private |
Stats Output.
bool EvaluatorControl::addToQueue | ( | const EvalQueuePointPtr & | evalQueuePoint | ) |
Add a single point to the queue.
true
if point was inserted in queue bool EvaluatorControl::checkEvalTerminate | ( | const int | mainThreadNum | ) | const |
void EvaluatorControl::clearEvaluatedPoints | ( | const int | threadNum | ) |
size_t EvaluatorControl::clearQueue | ( | const int | mainThreadNum, |
const bool | showDebug = false |
||
) |
Clear queue.
mainThreadNum | Clear points generated by this main thread only, If -1, clear all queue. |
showDebug | If true , print points erased from the queue. |
|
private |
Helper function called during evaluation.
Update EvalQueuePointPtr after evaluation.
evalQueuePoint | The queue point of interest – IN/OUT. |
evalOk | Flag to specific if evaluation was OK – IN. |
hMax | The max infeasibility to keep a point in barrier – IN. |
void EvaluatorControl::debugDisplayQueue | ( | ) | const |
For debugging purposes. Show the contents of the evaluation queue.
|
private |
Helper for destructor.
|
private |
Debug trace when a thread is waiting.
bool EvaluatorControl::evalBlock | ( | BlockForEval & | block | ) |
Evaluates a block of points.
Updates the Eval members of the evaluation points. Also updates the fields specific to EvalQueuePoints.
block | The block of points to evaluate – IN/OUT. |
true
if at least one evaluation worked (evalOk), false
otherwise. std::vector<bool> EvaluatorControl::evalBlockOfPoints | ( | Block & | block, |
const Evaluator & | evaluator, | ||
const Double & | hMax = INF |
||
) |
Evaluates a block of points.
For each point, true
if evaluation worked false
otherwise.
block | The block of points to evaluate – IN/OUT. |
evaluator | Evaluator to be used for all these points |
hMax | The max infeasibilyt to keep a point in barrier – IN. |
bool EvaluatorControl::evalSinglePoint | ( | EvalPoint & | evalPoint, |
const int | mainThreadNum, | ||
const Double & | hMax = INF |
||
) |
Evaluates a single point.
Creates a block with a single point and evaluates it using EvaluatorControl::evalBlockOfPoints().
Updates only the Eval members.
evalPoint | The point to evaluate – IN. |
mainThreadNum | Thread number of the main thread that generated this point |
hMax | The max infeasibility for keeping points in barrier – IN. |
true
if evaluation worked (evalOk), false
otherwise. const std::shared_ptr<Barrier>& EvaluatorControl::getBarrier | ( | const int | threadNum = -1 | ) | const |
|
inline |
size_t EvaluatorControl::getBbEvalInSubproblem | ( | const int | mainThreadNum = -1 | ) | const |
|
inline |
Get the number of blackbox evaluations that are not ok.
Definition at line 253 of file EvaluatorControl.hpp.
const std::shared_ptr<EvalPoint>& EvaluatorControl::getBestIncumbent | ( | const int | mainThreadNum | ) | const |
|
inline |
bool EvaluatorControl::getDoneWithEval | ( | const int | mainThreadNum | ) | const |
std::shared_ptr<EvalParameters> EvaluatorControl::getEvalParams | ( | const int | threadNum = -1 | ) | const |
Get the Evaluator's parameters.
EvalType EvaluatorControl::getEvalType | ( | const int | mainThreadNum = -1 | ) | const |
|
inline |
|
inline |
Get the number of feasible blackbox evaluations.
Definition at line 256 of file EvaluatorControl.hpp.
Double EvaluatorControl::getHMax | ( | const int | threadNum | ) | const |
Get the max infeasibility to keep a point in barrier.
|
inline |
Definition at line 297 of file EvaluatorControl.hpp.
|
inline |
Definition at line 298 of file EvaluatorControl.hpp.
|
inline |
size_t EvaluatorControl::getLapBbEval | ( | const int | threadNum = -1 | ) | const |
size_t EvaluatorControl::getLapMaxBbEval | ( | const int | mainThreadNum | ) | const |
|
private |
Get the EvcMainThreadInfo associated with this thread number.
Get EvcMainThreadInfo associated with this thread number.
mainThreadNum | Main thread number. If -1, use current thread number, assuming it is a main thread. – IN. |
|
inline |
Definition at line 241 of file EvaluatorControl.hpp.
size_t EvaluatorControl::getMaxBbEvalInSubproblem | ( | const int | mainThreadNum = -1 | ) | const |
size_t EvaluatorControl::getNbEval | ( | ) | const |
Get the total number of evaluations. Total number of evaluations, including:
false
|
inline |
Definition at line 242 of file EvaluatorControl.hpp.
|
inline |
Definition at line 295 of file EvaluatorControl.hpp.
|
inline |
Definition at line 296 of file EvaluatorControl.hpp.
bool EvaluatorControl::getOpportunisticEval | ( | const int | mainThreadNum = -1 | ) | const |
Get or Set the value of some parameters.
size_t EvaluatorControl::getQueueSize | ( | const int | mainThreadNum = -1 | ) | const |
size_t EvaluatorControl::getSgteEval | ( | const int | mainThreadNum = -1 | ) | const |
const StopReason<EvalMainThreadStopType>& EvaluatorControl::getStopReason | ( | const int | mainThreadNum | ) | const |
std::string EvaluatorControl::getStopReasonAsString | ( | const int | mainThreadNum | ) | const |
const SuccessType& EvaluatorControl::getSuccessType | ( | const int | threadNum | ) | const |
|
inline |
Definition at line 260 of file EvaluatorControl.hpp.
bool EvaluatorControl::getUseCache | ( | const int | mainThreadNum = -1 | ) | const |
|
private |
Helper for constructor.
|
inline |
Definition at line 239 of file EvaluatorControl.hpp.
void EvaluatorControl::lockQueue | ( | ) |
Lock the queue.
Typically, this is done before adding points.
bool EvaluatorControl::popBlock | ( | BlockForEval & | block | ) |
Pop eval points from the queue to fill a block of size BB_MAX_BLOCK_SIZE.
block | The eval queue point block created – OUTr. |
true
if the block has at least one point, false
otherwise. bool EvaluatorControl::popEvalPoint | ( | EvalQueuePointPtr & | evalQueuePoint, |
Evaluator *& | evaluator, | ||
Double & | hMax | ||
) |
Get the top point from the queue and pop it.
evalQueuePoint | The eval point popped from the queue – OUT. |
evaluator | Evaluator with which this point must be evaluated – IN / OUT |
hMax | hMax for evaluation of this point – IN / OUT |
true
if it worked, false
otherwise. bool EvaluatorControl::reachedMaxEval | ( | ) | const |
Did we reach one of the evaluation parameters: MAX_EVAL, MAX_BB_EVAL, MAX_BLOCK_EVAL ?
bool EvaluatorControl::reachedMaxStepEval | ( | const int | mainThreadNum = -1 | ) | const |
Did we reach Max LAP, MAX_SGTE_EVAL (temporary max evals)?
mainThreadNum | Number of the main thread to update if a stop condition is reached. -1 means use current thread. |
bool EvaluatorControl::remainsEvaluatedPoints | ( | const int | threadNum | ) | const |
void EvaluatorControl::resetBbEvalInSubproblem | ( | const int | mainThreadNum = -1 | ) |
void EvaluatorControl::resetLapBbEval | ( | ) |
void EvaluatorControl::resetSgteEval | ( | const int | mainThreadNum = -1 | ) |
void EvaluatorControl::restart | ( | ) |
Restart.
std::vector<EvalPoint> EvaluatorControl::retrieveAllEvaluatedPoints | ( | const int | threadNum = -1 | ) |
Get all points that were just evaluated. This is especially useful when cache is not used.
SuccessType EvaluatorControl::run | ( | ) |
Continuous evaluation - running on all threads simultaneously.
Stop reasons may be controled by parameters MAX_BB_EVAL, MAX_EVAL, OPPORTUNISTIC_EVAL.
If strategy is opportunistic, stop as soon as a successful point is found.
void EvaluatorControl::setBarrier | ( | const std::shared_ptr< Barrier > & | barrier | ) |
|
inline |
void EvaluatorControl::setBestIncumbent | ( | const int | mainThreadNum, |
const std::shared_ptr< EvalPoint > & | bestIncumbent | ||
) |
void EvaluatorControl::setComputeSuccessTypeFunction | ( | const ComputeSuccessFunction & | computeSuccessFunction | ) |
void EvaluatorControl::setDoneWithEval | ( | const int | mainThreadNum, |
const bool | doneWithEval | ||
) |
void EvaluatorControl::setLapMaxBbEval | ( | const size_t | maxBbEval | ) |
void EvaluatorControl::setLastSuccessfulDir | ( | const std::shared_ptr< Direction > & | dir | ) |
void EvaluatorControl::setMaxBbEvalInSubproblem | ( | const size_t | maxBbEval | ) |
void EvaluatorControl::setNbEval | ( | const size_t | nbEval | ) |
Set the number of evaluations.
Similarly to EvaluatorControl:getNbEval(), the number of cache hits is removed before setting EvaluatorControl::_nbEvalSentToEvaluator.
void EvaluatorControl::setOpportunisticEval | ( | const bool | opportunistic | ) |
void EvaluatorControl::setStopReason | ( | const int | mainThreadNum, |
const EvalMainThreadStopType & | s | ||
) |
void EvaluatorControl::setSuccessType | ( | const int | threadNum, |
const SuccessType & | success | ||
) |
void EvaluatorControl::setUseCache | ( | const bool | usecache | ) |
|
inline |
Definition at line 317 of file EvaluatorControl.hpp.
|
private |
Sort the queue with respect to the selected sort strategy. Called by unlockQueue().
|
inline |
void EvaluatorControl::stop | ( | ) |
Stop evaluation.
|
private |
Did we reach a stop condition (for a main thread)?
mainThreadNum | The main thread number to verify –IN. |
bool EvaluatorControl::testIf | ( | const EvalMainThreadStopType & | s | ) | const |
void EvaluatorControl::unlockQueue | ( | const bool | doSort = true | ) |
Unlock the queue.
We are done adding points. If doSort is true
, the points in the queue are sorted using ComparePriority.
void EvaluatorControl::updateEvalStatusAfterEval | ( | EvalPoint & | evalPoint, |
bool | evalOk | ||
) |
Updates eval status.
Update point's evalStatus, knowing that the evaluation has just ended.
evalPoint | The evalPoint – IN/OUT. |
evalOk | Status of evaluation – IN. |
bool EvaluatorControl::updateEvalStatusBeforeEval | ( | EvalPoint & | evalPoint | ) |
Updates eval status.
Find the point in the cache and update its evalStatus to IN_PROGRESS, knowing that the evaluation is about to start.
evalPoint | The evaluation point – IN/OUT. |
true
if the point must be evaluated, false
otherwise.
|
private |
All evaluations done. The queue can be destroyed.
Definition at line 182 of file EvaluatorControl.hpp.
|
private |
The number of blackbox evaluations performed.
Definition at line 109 of file EvaluatorControl.hpp.
|
private |
The number of blackbox evaluations that are not ok.
Definition at line 118 of file EvaluatorControl.hpp.
|
private |
The number of block evaluations performed.
Definition at line 145 of file EvaluatorControl.hpp.
|
private |
The parameters controlling the behavior of the class.
Definition at line 77 of file EvaluatorControl.hpp.
|
private |
The queue of points to be evaluated.
The queue is implemented as a vector. Points are added at the end of the queue. Points are sorted using ComparePriority which is called in unlockQueue() when the user is done adding points to the queue.
Sorting the queue can also be done by providing another function.
Definition at line 93 of file EvaluatorControl.hpp.
|
private |
The number of feasible blackbox evaluations obtained.
Definition at line 127 of file EvaluatorControl.hpp.
|
private |
The index of the best feasible evaluation.
Definition at line 157 of file EvaluatorControl.hpp.
|
private |
The index of the best infeasible evaluation.
Definition at line 163 of file EvaluatorControl.hpp.
|
private |
The index of the last successfull evaluation block.
Definition at line 151 of file EvaluatorControl.hpp.
|
private |
The number of infeasible blackbox evaluations obtained.
Definition at line 136 of file EvaluatorControl.hpp.
|
mutableprivate |
Info about main threads.
Definition at line 81 of file EvaluatorControl.hpp.
|
private |
Definition at line 79 of file EvaluatorControl.hpp.
|
private |
The number of evaluations performed through this:
false
.Definition at line 170 of file EvaluatorControl.hpp.
|
private |
The number of PhaseOne success evaluations performed through this
.
Definition at line 180 of file EvaluatorControl.hpp.
|
private |
The number of full success evaluations performed through this
.
Definition at line 175 of file EvaluatorControl.hpp.
|
private |
The total number of sgte evaluations. Used for stats exclusively.
Definition at line 139 of file EvaluatorControl.hpp.
|
private |
User-implemented comparison method to sort points before evaluation.
Definition at line 95 of file EvaluatorControl.hpp.