NOMAD Source  Version 4.0.0 Beta
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvaluatorControl Class Reference

Class to control the evaluation of points using a queue. More...

#include <EvaluatorControl.hpp>

Collaboration diagram for EvaluatorControl:

Public Member Functions

 EvaluatorControl (std::unique_ptr< Evaluator > evaluator, const std::shared_ptr< EvaluatorControlParameters > &evalContParams, ComparePriority comp=ComparePriority())
 Constructor. More...
 
virtual ~EvaluatorControl ()
 Destructor. More...
 
EvaluatorgetEvaluator () 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< BarriergetBarrier () 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...
 

Detailed Description

Class to control the evaluation of points using a queue.

Todo:
Complete the description.

Definition at line 35 of file EvaluatorControl.hpp.

Constructor & Destructor Documentation

EvaluatorControl::EvaluatorControl ( std::unique_ptr< Evaluator evaluator,
const std::shared_ptr< EvaluatorControlParameters > &  evalContParams,
ComparePriority  comp = ComparePriority() 
)
inlineexplicit

Constructor.

Parameters
evaluatorThe blackbox evaluator – IN.
evalContParamsThe parameters controlling how the class works – IN.
compThe priority comparison function – IN.

Definition at line 125 of file EvaluatorControl.hpp.

128  : _evaluator(std::move(evaluator)),
129  _evalContParams(evalContParams),
130 #ifdef USE_PRIORITY_QUEUE
131  _evalPointQueue(comp),
132 #else
133  _evalPointQueue(),
134  _comp(comp),
135 #endif // USE_PRIORITY_QUEUE
136 #ifdef _OPENMP
137  _evalQueueLock(),
138 #endif // _OPENMP
139  _barrier(),
140  _opportunisticEval(false),
143  _bbEval(0),
145  _lapBbEval(0),
146  _blockEval(0),
148  _doneWithEval(false)
149  {
150  init();
151  }
std::atomic< size_t > _nbEvalSentToEvaluator
std::atomic< size_t > _lapBbEval
The number of blackbox evaluations performed by a sub algorithm (reset at algo start).
std::vector< EvalQueuePointPtr > _evalPointQueue
The queue of points to be evaluated.
std::unique_ptr< Evaluator > _evaluator
The Evaluator for evaluating points.
std::atomic< size_t > _bbEval
The number of blackbox evaluations performed.
void init()
Helper for constructor.
std::atomic< size_t > _blockEval
The number of block evaluations performed.
std::shared_ptr< EvaluatorControlParameters > _evalContParams
The parameters controlling the behavior of the class.
std::atomic< size_t > _lapMaxBbEval
The maximum number of blackbox evaluations that can be performed by a sub algorithm.
bool _opportunisticEval
Is opportunistic ?
bool _doneWithEval
All evaluations done. The queue can be destroyed.
std::atomic< size_t > _currentlyRunning
Count number of evaluations currently running.
ComparePriority _comp
std::shared_ptr< Barrier > _barrier
SuccessType _success
Success type of the last run.
const size_t INF_SIZE_T
The infinity for size_t.
Definition: defines.hpp:84
virtual EvaluatorControl::~EvaluatorControl ( )
inlinevirtual

Destructor.

Definition at line 154 of file EvaluatorControl.hpp.

155  {
156  destroy();
157  }
void destroy()
Helper for destructor.

Member Function Documentation

void EvaluatorControl::AddStatsInfo ( const BlockForEval block) const
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.

void EvaluatorControl::computeSuccess ( EvalQueuePointPtr  evalQueuePoint,
const bool  evalOk,
const Double hMax 
)
private

Helper function called during evaluation.

Update EvalQueuePointPtr after evaluation.

Parameters
evalQueuePointThe queue point of interest – IN/OUT.
evalOkFlag to specific if evaluation was OK – IN.
hMaxThe max infeasibility to keep a point in barrier – IN.
void EvaluatorControl::destroy ( )
private

Helper for destructor.

void EvaluatorControl::displayDebugWaitingInfo ( time_t &  lastDisplayed) const
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.

Parameters
blockThe block of points to evaluate – IN/OUT.
Returns
true if at least one evaluation worked (evalOk), false otherwise.
std::vector<bool> EvaluatorControl::evalBlockOfPoints ( Block block,
const Double hMax = INF 
)

Evaluates a block of points.

For each point, true if evaluation worked false otherwise.

Remarks
Updates only the Eval members.
Parameters
blockThe block of points to evaluate – IN/OUT.
hMaxThe max infeasibilyt to keep a point in barrier – IN.
Returns
A vector of booleans, of the same size as block.
bool EvaluatorControl::evalSinglePoint ( EvalPoint evalPoint,
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.

Parameters
evalPointThe point to evaluate – IN.
hMaxThe max infeasibility for keeping points in barrier – IN.
Returns
true if evaluation worked (evalOk), false otherwise.
const std::shared_ptr<Barrier> EvaluatorControl::getBarrier ( ) const
inline

Definition at line 200 of file EvaluatorControl.hpp.

200 { return _barrier; }
std::shared_ptr< Barrier > _barrier
size_t EvaluatorControl::getBbEval ( ) const
inline

Get the number of blackbox evaluations.

Definition at line 167 of file EvaluatorControl.hpp.

167 { return _bbEval; }
std::atomic< size_t > _bbEval
The number of blackbox evaluations performed.
size_t EvaluatorControl::getBlockEval ( ) const
inline

Get the number of block evaluations.

Definition at line 173 of file EvaluatorControl.hpp.

173 { return _blockEval; }
std::atomic< size_t > _blockEval
The number of block evaluations performed.
Evaluator* EvaluatorControl::getEvaluator ( ) const
inline

Get the evaluator.

Definition at line 164 of file EvaluatorControl.hpp.

164 { return _evaluator.get(); }
std::unique_ptr< Evaluator > _evaluator
The Evaluator for evaluating points.
std::shared_ptr<EvaluatorControlParameters> EvaluatorControl::getEvaluatorControlParams ( ) const
inline

Get the parameters for *this.

Definition at line 211 of file EvaluatorControl.hpp.

212  {
213  return _evalContParams;
214  }
std::shared_ptr< EvaluatorControlParameters > _evalContParams
The parameters controlling the behavior of the class.
Double EvaluatorControl::getHMax ( ) const
inline

Get the max infeasibility to keep a point in barrier.

Definition at line 205 of file EvaluatorControl.hpp.

206  {
207  return (nullptr == _barrier) ? INF : _barrier->getHMax();
208  }
const double INF
Infinity.
Definition: defines.hpp:80
std::shared_ptr< Barrier > _barrier
size_t EvaluatorControl::getLapBbEval ( void  )
inline

Definition at line 195 of file EvaluatorControl.hpp.

195 { return _lapBbEval; }
std::atomic< size_t > _lapBbEval
The number of blackbox evaluations performed by a sub algorithm (reset at algo start).
size_t EvaluatorControl::getNbEval ( ) const

Get the total number of evaluations. Total number of evaluations, including:

Note
Member EvaluatorControl:: holds only the first two values. Cache hits are added in this method.
bool EvaluatorControl::getOpportunisticEval ( ) const
inline

Definition at line 202 of file EvaluatorControl.hpp.

202 { return _opportunisticEval; }
bool _opportunisticEval
Is opportunistic ?
size_t EvaluatorControl::getQueueSize ( ) const
inline

Definition at line 197 of file EvaluatorControl.hpp.

197 { return _evalPointQueue.size(); }
std::vector< EvalQueuePointPtr > _evalPointQueue
The queue of points to be evaluated.
void EvaluatorControl::init ( )
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.

Parameters
blockThe eval queue point block created – OUTr.
Returns
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.

Parameters
evalQueuePointThe eval point popped from the queue – OUT.
Returns
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 ?

void EvaluatorControl::resetLapBbEval ( void  )
inline

Definition at line 194 of file EvaluatorControl.hpp.

194 { _lapBbEval = 0; }
std::atomic< size_t > _lapBbEval
The number of blackbox evaluations performed by a sub algorithm (reset at algo start).
void EvaluatorControl::restart ( )
inline

Restart.

Definition at line 282 of file EvaluatorControl.hpp.

282 { _doneWithEval = false; }
bool _doneWithEval
All evaluations done. The queue can be destroyed.
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.

Returns
The success type of the evaluations.
void EvaluatorControl::setBarrier ( const std::shared_ptr< Barrier barrier)
inline

Definition at line 199 of file EvaluatorControl.hpp.

199 { _barrier = barrier; }
std::shared_ptr< Barrier > _barrier
void EvaluatorControl::setBbEval ( const size_t  bbEval)
inline

Set blackbox evaluations number.

Definition at line 170 of file EvaluatorControl.hpp.

170 { _bbEval = bbEval; }
std::atomic< size_t > _bbEval
The number of blackbox evaluations performed.
void EvaluatorControl::setLapMaxBbEval ( const size_t  maxBbEval)
inline

Definition at line 193 of file EvaluatorControl.hpp.

193 { _lapMaxBbEval = maxBbEval; }
std::atomic< size_t > _lapMaxBbEval
The maximum number of blackbox evaluations that can be performed by a sub algorithm.
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.

void EvaluatorControl::sort ( )
inline

Use the default comparison function _comp.

Definition at line 256 of file EvaluatorControl.hpp.

256 { sort(_comp); }
void sort()
Use the default comparison function _comp.
ComparePriority _comp
void EvaluatorControl::start ( )
inline

Start evaluation.

Definition at line 268 of file EvaluatorControl.hpp.

268 {}
void EvaluatorControl::stop ( )

Stop evaluation.

bool EvaluatorControl::stopMainEval ( )
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.

Parameters
evalPointThe evalPoint – IN/OUT.
evalOkStatus 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.

Parameters
evalPointThe evaluation point – IN/OUT.

Member Data Documentation

std::shared_ptr<Barrier> EvaluatorControl::_barrier
private

Barrier used for the current runs.
Modified only by master thread. Used by all threads.

Definition at line 74 of file EvaluatorControl.hpp.

std::atomic<size_t> EvaluatorControl::_bbEval
private

The number of blackbox evaluations performed.

Remarks
Atomic for thread-safety.
Atomic is also supported by OpenMP, but here I find it clearer to declare it atomic from the start.

Definition at line 88 of file EvaluatorControl.hpp.

std::atomic<size_t> EvaluatorControl::_blockEval
private

The number of block evaluations performed.

Remarks
Atomic for thread-safety.

Definition at line 106 of file EvaluatorControl.hpp.

ComparePriority EvaluatorControl::_comp
private

Definition at line 62 of file EvaluatorControl.hpp.

std::atomic<size_t> EvaluatorControl::_currentlyRunning
private

Count number of evaluations currently running.

Definition at line 79 of file EvaluatorControl.hpp.

bool EvaluatorControl::_doneWithEval
private

All evaluations done. The queue can be destroyed.

Definition at line 115 of file EvaluatorControl.hpp.

std::shared_ptr<EvaluatorControlParameters> EvaluatorControl::_evalContParams
private

The parameters controlling the behavior of the class.

Definition at line 40 of file EvaluatorControl.hpp.

std::vector<EvalQueuePointPtr> EvaluatorControl::_evalPointQueue
private

The queue of points to be evaluated.

Todo:
Have means to reorder the queue and change the comparison function during the run.

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.

std::unique_ptr<Evaluator> EvaluatorControl::_evaluator
private

The Evaluator for evaluating points.

Definition at line 38 of file EvaluatorControl.hpp.

std::atomic<size_t> EvaluatorControl::_lapBbEval
private

The number of blackbox evaluations performed by a sub algorithm (reset at algo start).

Definition at line 99 of file EvaluatorControl.hpp.

std::atomic<size_t> EvaluatorControl::_lapMaxBbEval
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.

Remarks
Optionnaly set during Algorithm creation.

Definition at line 96 of file EvaluatorControl.hpp.

std::atomic<size_t> EvaluatorControl::_nbEvalSentToEvaluator
private

The number of evaluations performed through this:

  • Including evaluations for which countEval returned false.
  • Not including cache hits.

Definition at line 113 of file EvaluatorControl.hpp.

bool EvaluatorControl::_opportunisticEval
private

Is opportunistic ?

Definition at line 75 of file EvaluatorControl.hpp.

SuccessType EvaluatorControl::_success
private

Success type of the last run.

Definition at line 77 of file EvaluatorControl.hpp.


The documentation for this class was generated from the following file: