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::unique_ptr< Evaluator > evaluator, const std::shared_ptr< EvaluatorControlParameters > &evalContParams, ComparePriority comp=ComparePriority()) | |
Constructor. More... | |
virtual | ~EvaluatorControl () |
Destructor. More... | |
Evaluator * | getEvaluator () const |
Get the evaluator. More... | |
size_t | getBbEval () const |
Get the number of blackbox evaluations. More... | |
void | setBbEval (const size_t bbEval) |
Set blackbox evaluations number. More... | |
size_t | getBlockEval () const |
Get the number of block evaluations. More... | |
size_t | getNbEval () const |
void | setNbEval (const size_t nbEval) |
Set the number of evaluations. More... | |
void | setLapMaxBbEval (const size_t maxBbEval) |
void | resetLapBbEval (void) |
size_t | getLapBbEval (void) |
size_t | getQueueSize () const |
void | setBarrier (const std::shared_ptr< Barrier > barrier) |
const std::shared_ptr< Barrier > | getBarrier () const |
bool | getOpportunisticEval () const |
Double | getHMax () const |
Get the max infeasibility to keep a point in barrier. More... | |
std::shared_ptr < EvaluatorControlParameters > | getEvaluatorControlParams () const |
Get the parameters for *this . More... | |
void | lockQueue () |
Lock the queue. More... | |
void | unlockQueue (const bool doSort=true) |
Unlock the queue. More... | |
void | addToQueue (const EvalQueuePointPtr &evalQueuePoint) |
Add a single point to the queue. More... | |
bool | popEvalPoint (EvalQueuePointPtr &evalQueuePoint) |
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... | |
void | sort (ComparePriority comp) |
Sort the queue with respect to the comparison function comp. More... | |
void | sort () |
Use the default comparison function _comp. More... | |
void | clearQueue (const bool waitRunning=false, 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 Double &hMax=INF) |
Evaluates a single point. More... | |
std::vector< bool > | evalBlockOfPoints (Block &block, const Double &hMax=INF) |
Evaluates a block of points. More... | |
void | updateEvalStatusBeforeEval (EvalPoint &evalPoint) |
Updates eval status. More... | |
void | updateEvalStatusAfterEval (EvalPoint &evalPoint, bool evalOk) |
Updates eval status. More... | |
bool | reachedMaxEval () |
Did we reach one of the evaluation parameters: MAX_EVAL, MAX_BB_EVAL, MAX_BLOCK_EVAL ? More... | |
bool | reachedMaxStepEval () |
Did we reach max lap eval during a sub-optimization ? More... | |
Private Member Functions | |
void | init () |
Helper for constructor. More... | |
void | destroy () |
Helper for destructor. More... | |
void | computeSuccess (EvalQueuePointPtr evalQueuePoint, const bool evalOk, const Double &hMax) |
Helper function called during evaluation. More... | |
bool | stopMainEval () |
Did we reach a stop condition (for 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... | |
Private Attributes | |
std::unique_ptr< Evaluator > | _evaluator |
The Evaluator for evaluating points. More... | |
std::shared_ptr < EvaluatorControlParameters > | _evalContParams |
The parameters controlling the behavior of the class. More... | |
std::vector< EvalQueuePointPtr > | _evalPointQueue |
The queue of points to be evaluated. More... | |
ComparePriority | _comp |
std::shared_ptr< Barrier > | _barrier |
bool | _opportunisticEval |
Is opportunistic ? More... | |
SuccessType | _success |
Success type of the last run. More... | |
std::atomic< size_t > | _currentlyRunning |
Count number of evaluations currently running. More... | |
std::atomic< size_t > | _bbEval |
The number of blackbox evaluations performed. More... | |
std::atomic< size_t > | _lapMaxBbEval |
The maximum number of blackbox evaluations that can be performed by a sub algorithm. More... | |
std::atomic< size_t > | _lapBbEval |
The number of blackbox evaluations performed by a sub algorithm (reset at algo start). More... | |
std::atomic< size_t > | _blockEval |
The number of block evaluations performed. More... | |
std::atomic< size_t > | _nbEvalSentToEvaluator |
bool | _doneWithEval |
All evaluations done. The queue can be destroyed. More... | |
Class to control the evaluation of points using a queue.
Definition at line 35 of file EvaluatorControl.hpp.
|
inlineexplicit |
Constructor.
evaluator | The blackbox evaluator – IN. |
evalContParams | The parameters controlling how the class works – IN. |
comp | The priority comparison function – IN. |
Definition at line 125 of file EvaluatorControl.hpp.
|
inlinevirtual |
Destructor.
Definition at line 154 of file EvaluatorControl.hpp.
|
private |
Stats Output.
void EvaluatorControl::addToQueue | ( | const EvalQueuePointPtr & | evalQueuePoint | ) |
Add a single point to the queue.
void EvaluatorControl::clearQueue | ( | const bool | waitRunning = false , |
const bool | showDebug = false |
||
) |
Clear queue.
If waitRunning is true
, wait for all currently running blackboxes to end before clearing.
If showDebug is true
, print points remaining in 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. |
|
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. Evaluates a block of points.
For each point, true
if evaluation worked false
otherwise.
block | The block of points to evaluate – IN/OUT. |
hMax | The max infeasibilyt to keep a point in barrier – IN. |
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. |
hMax | The max infeasibility for keeping points in barrier – IN. |
true
if evaluation worked (evalOk), false
otherwise.
|
inline |
Definition at line 200 of file EvaluatorControl.hpp.
|
inline |
Get the number of blackbox evaluations.
Definition at line 167 of file EvaluatorControl.hpp.
|
inline |
Get the number of block evaluations.
Definition at line 173 of file EvaluatorControl.hpp.
|
inline |
Get the evaluator.
Definition at line 164 of file EvaluatorControl.hpp.
|
inline |
Get the parameters for *this
.
Definition at line 211 of file EvaluatorControl.hpp.
|
inline |
Get the max infeasibility to keep a point in barrier.
Definition at line 205 of file EvaluatorControl.hpp.
|
inline |
Definition at line 195 of file EvaluatorControl.hpp.
size_t EvaluatorControl::getNbEval | ( | ) | const |
Get the total number of evaluations. Total number of evaluations, including:
false
|
inline |
Definition at line 202 of file EvaluatorControl.hpp.
|
inline |
Definition at line 197 of file EvaluatorControl.hpp.
|
private |
Helper for constructor.
void EvaluatorControl::lockQueue | ( | ) |
Lock the queue.
Typically, this is done before adding points. It is also used to modify parameters.
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 | ) |
Get the top point from the queue and pop it.
evalQueuePoint | The eval point popped from the queue – OUT. |
true
if it worked, false
otherwise. bool EvaluatorControl::reachedMaxEval | ( | ) |
Did we reach one of the evaluation parameters: MAX_EVAL, MAX_BB_EVAL, MAX_BLOCK_EVAL ?
bool EvaluatorControl::reachedMaxStepEval | ( | ) |
Did we reach max lap eval during a sub-optimization ?
|
inline |
Definition at line 194 of file EvaluatorControl.hpp.
|
inline |
Restart.
Definition at line 282 of file EvaluatorControl.hpp.
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.
|
inline |
Definition at line 199 of file EvaluatorControl.hpp.
|
inline |
Set blackbox evaluations number.
Definition at line 170 of file EvaluatorControl.hpp.
|
inline |
Definition at line 193 of file EvaluatorControl.hpp.
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::sort | ( | ComparePriority | comp | ) |
Sort the queue with respect to the comparison function comp.
|
inline |
Use the default comparison function _comp.
Definition at line 256 of file EvaluatorControl.hpp.
|
inline |
void EvaluatorControl::stop | ( | ) |
Stop evaluation.
|
private |
Did we reach a stop condition (for main thread)?
void EvaluatorControl::unlockQueue | ( | const bool | doSort = true | ) |
Unlock the queue.
We are done adding points, or modify and checking the parameters. If doSort is true
, the points in the queue are sorted using _comp.
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. |
void 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. |
|
private |
Barrier used for the current runs.
Modified only by master thread. Used by all threads.
Definition at line 74 of file EvaluatorControl.hpp.
|
private |
The number of blackbox evaluations performed.
Definition at line 88 of file EvaluatorControl.hpp.
|
private |
The number of block evaluations performed.
Definition at line 106 of file EvaluatorControl.hpp.
|
private |
Definition at line 62 of file EvaluatorControl.hpp.
|
private |
Count number of evaluations currently running.
Definition at line 79 of file EvaluatorControl.hpp.
|
private |
All evaluations done. The queue can be destroyed.
Definition at line 115 of file EvaluatorControl.hpp.
|
private |
The parameters controlling the behavior of the class.
Definition at line 40 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 the _comp() 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 61 of file EvaluatorControl.hpp.
|
private |
The Evaluator for evaluating points.
Definition at line 38 of file EvaluatorControl.hpp.
|
private |
The number of blackbox evaluations performed by a sub algorithm (reset at algo start).
Definition at line 99 of file EvaluatorControl.hpp.
|
private |
The maximum number of blackbox evaluations that can be performed by a sub algorithm.
For now we have a single counter used for a sub-algorithm.
The main counter EvaluatorControl::_bbEval is used for the main algo.
Definition at line 96 of file EvaluatorControl.hpp.
|
private |
The number of evaluations performed through this:
false
.Definition at line 113 of file EvaluatorControl.hpp.
|
private |
Is opportunistic ?
Definition at line 75 of file EvaluatorControl.hpp.
|
private |
Success type of the last run.
Definition at line 77 of file EvaluatorControl.hpp.