本文整理汇总了C++中nomad::Eval_Point类的典型用法代码示例。如果您正苦于以下问题:C++ Eval_Point类的具体用法?C++ Eval_Point怎么用?C++ Eval_Point使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Eval_Point类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eval_x
bool eval_x ( NOMAD::Eval_Point & x ,
const NOMAD::Double & h_max ,
bool & count_eval ) const {
R_CheckUserInterrupt();
double *x0;
int n = x.get_n();
int m = x.get_m();
x0 = (double *)malloc(sizeof(double)*n);
for(int i=0;i<n;i++)
{
x0[i]=x[i].value();
}
double *ret_value = eval_f(m, n, x0);
for(int i=0;i<m;i++)
x.set_bb_output ( i , ret_value[i] ); // objective value
count_eval = true; // count a black-box evaluation
free(x0);
free(ret_value);
return true; // the evaluation succeeded
}
示例2: Exception
/*------------------------------------------------------------------*/
void NOMAD::Phase_One_Evaluator::compute_f(NOMAD::Eval_Point &x) const
{
if (x.get_bb_outputs().size() != _p.get_bb_nb_outputs())
{
std::ostringstream err;
err << "Phase_One_Evaluator::compute_f(x): "
<< "x has a wrong number of blackbox outputs ("
<< x.get_bb_outputs().size() << " != " << _p.get_bb_nb_outputs() << ")";
throw NOMAD::Exception("Phase_One_Evaluator.cpp" , __LINE__ , err.str());
}
// objective value for MADS phase 1: the squared sum of all EB constraint violations
// (each EB constraint has been previously transformed into OBJ values):
const std::list<int> &index_obj = _p.get_index_obj();
const std::list<int>::const_iterator end = index_obj.end();
const NOMAD::Point &bbo = x.get_bb_outputs();
NOMAD::Double h_min = _p.get_h_min();
NOMAD::Double sum = 0.0;
NOMAD::Double v;
for (std::list<int>::const_iterator it = index_obj.begin() ; it != end ; ++it)
{
v = bbo[*it];
if (v > h_min)
sum += v.pow2();
}
x.set_f(sum);
}
示例3:
/*---------------------------------------------------------*/
NOMAD::success_type NOMAD::Barrier::insert_infeasible ( const NOMAD::Eval_Point & x )
{
const NOMAD::Eval_Point * old_bi = get_best_infeasible();
// filter insertion:
// -----------------
bool insert;
filter_insertion ( x , insert );
// filter:
// -------
if ( _p.get_barrier_type() == NOMAD::FILTER )
{
const NOMAD::Eval_Point * bi = get_best_infeasible();
if ( !bi )
return NOMAD::UNSUCCESSFUL;
if ( old_bi )
{
if ( bi->get_h().value() < old_bi->get_h().value() )
return NOMAD::FULL_SUCCESS;
if ( insert )
return NOMAD::PARTIAL_SUCCESS;
return NOMAD::UNSUCCESSFUL;
}
return NOMAD::FULL_SUCCESS;
}
// progressive barrier:
// --------------------
// with PEB constraints, we remember all points that we tried to insert:
if ( _p.get_barrier_type() == NOMAD::PEB_P )
_peb_lop.push_back ( &x );
// first infeasible successes are considered as partial successes
// (improving iterations)
if ( !_ref )
return NOMAD::PARTIAL_SUCCESS;
double hx = x.get_h().value();
double fx = x.get_f().value();
double hr = _ref->get_h().value();
double fr = _ref->get_f().value();
// failure:
if ( hx > hr || ( hx == hr && fx >= fr ) )
return NOMAD::UNSUCCESSFUL;
// partial success:
if ( fx > fr )
return NOMAD::PARTIAL_SUCCESS;
// full success:
return NOMAD::FULL_SUCCESS;
}
示例4: Exception
/*--------------------------------------------------------*/
void NOMAD::Evaluator::compute_f ( NOMAD::Eval_Point & x ) const
{
if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) {
std::ostringstream err;
err << "Evaluator::compute_f(x): x has a wrong number of blackbox outputs ("
<< x.get_bb_outputs().size() << " != "
<< _p.get_bb_nb_outputs() << ")";
throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err.str() );
}
x.set_f ( x.get_bb_outputs()[*(_p.get_index_obj().begin())] );
}
示例5: find
/*-----------------------------------------------------*/
bool NOMAD::Cache::erase ( const NOMAD::Eval_Point & x )
{
// check the eval types:
if ( x.get_eval_type() != _eval_type )
throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ ,
"NOMAD::Cache:erase(x): x.eval_type != cache.eval_type" );
std::set<NOMAD::Cache_Point>::iterator it;
NOMAD::cache_index_type cache_index;
// search in cache:
const NOMAD::Eval_Point * cache_x = find ( x , it , cache_index );
// the point has been found:
if ( cache_x ) {
// remove the point from the list of extern points:
if ( cache_x->get_current_run() || x.get_current_run() ) {
std::list<const NOMAD::Eval_Point*>::const_iterator end2 = _extern_pts.end();
std::list<const NOMAD::Eval_Point*>::iterator it2 = _extern_pts.begin();
while ( it2 != end2 ) {
if ( *it2 == cache_x || *it2 == &x ) {
_extern_pts.erase ( it2 );
break;
}
++it2;
}
}
// erase the point in cache if its address is different from &x:
if ( cache_x != &x )
delete cache_x;
// remove the point from the cache:
_sizeof -= x.size_of();
switch ( cache_index ) {
case NOMAD::CACHE_1:
_cache1.erase ( it );
break;
case NOMAD::CACHE_2:
_cache2.erase ( it );
break;
case NOMAD::CACHE_3:
_cache3.erase ( it );
break;
case NOMAD::UNDEFINED_CACHE:
break;
}
return true;
}
return false;
}
示例6: eval_x
//-----------------------------------------------------------------------------------------------
// evaluates the model
//-----------------------------------------------------------------------------------------------
bool LshNomadEvaluator::eval_x(NOMAD::Eval_Point &x, const NOMAD::Double &h_max, bool &count_eval) const
{
// generating a case from the evaluation point
Case *c = generateCase(x);
CaseQueue *cq = new CaseQueue();
cq->push_back(c);
// sending the case off for evaluation
p_optimizer->sendCasesToOptimizer(cq);
///p_optimizer->runCase(c);
// extracting the objective
x.set_bb_output(0, -c->objectiveValue());
// extracting the constraint values
// the constraints in NOMAD must be on the form: c <= 0
for(int i = 0; i < c->numberOfConstraints(); ++i)
{
double val_input;
double val = c->constraintValue(i);
double max = p_optimizer->runner()->model()->constraints().at(i)->max();
double min = p_optimizer->runner()->model()->constraints().at(i)->min();
if(val > max) val_input = val - max;
else if(val < min) val_input = min - val;
else
{
double u_slack = max - val;
double l_slack = val - min;
val_input = (u_slack > l_slack) ? -u_slack : -l_slack;
}
x.set_bb_output(i+1, val_input);
}
// deleting the case from the heap
delete c;
delete cq;
return true;
}
示例7: Exception
/*---------------------------------------------------------*/
NOMAD::success_type NOMAD::Barrier::insert_feasible ( const NOMAD::Eval_Point & x )
{
Double fx;
Double fx_bf;
if ( _p.get_robust_mads() )
{
if ( x.get_smoothing_status() != NOMAD::SMOOTHING_OK )
return NOMAD::UNSUCCESSFUL;
if ( _best_feasible )
fx_bf = _best_feasible->get_fsmooth();
else
{
_best_feasible = &x;
return NOMAD::FULL_SUCCESS;
}
fx = x.get_fsmooth();
}
else
{
if ( _best_feasible )
fx_bf = _best_feasible->get_f();
else
{
_best_feasible = &x;
return NOMAD::FULL_SUCCESS;
}
fx= x.get_f();
}
if ( !fx.is_defined() || ! fx_bf.is_defined() )
throw NOMAD::Exception ( __FILE__ , __LINE__ ,
"insert_feasible(): one point has no f value" );
if ( fx.value() < fx_bf.value() )
{
_best_feasible = &x;
return NOMAD::FULL_SUCCESS;
}
return NOMAD::UNSUCCESSFUL;
}
示例8: cp
/*------------------------------------------------*/
void NOMAD::Cache::insert ( const NOMAD::Eval_Point & x )
{
// check the eval types:
if ( x.get_eval_type() != _eval_type )
throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ ,
"NOMAD::Cache:insert(x): x.eval_type != cache.eval_type" );
// insertion in _extern_pts:
insert_extern_point ( x );
// insertion in _cache2:
NOMAD::Cache_Point cp ( &x );
_cache2.insert ( cp );
x.set_in_cache ( true );
_sizeof += x.size_of();
}
示例9:
/*---------------------------------------------------------*/
NOMAD::success_type NOMAD::Barrier::insert_feasible ( const NOMAD::Eval_Point & x )
{
if ( !_best_feasible || ( x.get_f().value() < _best_feasible->get_f().value() ) ) {
_best_feasible = &x;
return NOMAD::FULL_SUCCESS;
}
return NOMAD::UNSUCCESSFUL;
}
示例10: Exception
/*--------------------------------------------------------*/
void NOMAD::Evaluator::compute_h ( NOMAD::Eval_Point & x ) const
{
if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) {
std::ostringstream err;
err << "Evaluator::compute_h(x): x has a wrong number of blackbox outputs ("
<< x.get_bb_outputs().size() << " != "
<< _p.get_bb_nb_outputs() << ")";
throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err.str() );
}
int nbo = _p.get_bb_nb_outputs();
const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type();
const NOMAD::Point & bbo = x.get_bb_outputs();
NOMAD::Double h = 0.0 , bboi;
x.set_EB_ok ( true );
for ( int i = 0 ; i < nbo ; ++i ) {
bboi = bbo[i];
if ( bboi.is_defined() &&
(bbot[i] == NOMAD::EB || bbot[i] == NOMAD::PEB_E ) &&
bboi > _p.get_h_min() ) {
h.clear();
x.set_h ( h );
x.set_EB_ok ( false );
return;
}
if ( bboi.is_defined() &&
( bbot[i] == NOMAD::FILTER ||
bbot[i] == NOMAD::PB ||
bbot[i] == NOMAD::PEB_P ) ) {
if ( bboi > _p.get_h_min() ) {
switch ( _p.get_h_norm() ) {
case NOMAD::L1:
h += bboi;
break;
case NOMAD::L2:
h += bboi * bboi;
break;
case NOMAD::LINF:
if ( bboi > h )
h = bboi;
break;
}
}
}
}
if ( _p.get_h_norm() == NOMAD::L2 )
h = h.sqrt();
x.set_h ( h );
}
示例11: if
/*-----------------------------------------------------------------------*/
bool NOMAD::Evaluator::interrupt_evaluations ( const NOMAD::Eval_Point & x ,
const NOMAD::Double & h_max ) const
{
int nbo = _p.get_bb_nb_outputs();
const NOMAD::Point & bbo = x.get_bb_outputs();
const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type();
NOMAD::Double h = 0.0;
bool check_h = h_max.is_defined();
for ( int i = 0 ; i < nbo ; ++i ) {
if ( bbo[i].is_defined() &&
( bbot[i] == NOMAD::EB || bbot[i] == NOMAD::PEB_E ) &&
bbo[i] > _p.get_h_min() )
return true;
if ( check_h && bbo[i].is_defined() &&
(bbot[i] == NOMAD::FILTER ||
bbot[i] == NOMAD::PB ||
bbot[i] == NOMAD::PEB_P ) ) {
if ( bbo[i] > _p.get_h_min() ) {
switch ( _p.get_h_norm() ) {
case NOMAD::L1:
h += bbo[i];
break;
case NOMAD::L2:
h += bbo[i].pow2();
break;
case NOMAD::LINF:
if ( bbo[i] > h )
h = bbo[i];
break;
}
if ( _p.get_h_norm() == NOMAD::L2 ) {
if ( h > h_max.pow2() )
return true;
}
else if ( h > h_max )
return true;
}
}
}
return false;
}
示例12: Insert_Error
/*---------------------------------------------------------*/
void NOMAD::Barrier::insert ( const NOMAD::Eval_Point & x )
{
// we compare the eval types (_SGTE_ or _TRUTH_) of x and *this:
if ( x.get_eval_type() != _eval_type )
throw Barrier::Insert_Error ( "Barrier.cpp" , __LINE__ ,
"insertion of an Eval_Point into the bad Barrier object" );
// basic check:
if ( !x.is_eval_ok() )
{
_one_eval_succ = NOMAD::UNSUCCESSFUL;
return;
}
// pre-filter: if tag(x) is already in the pre-filter,
// then return _UNSUCCESSFUL_:
size_t size_before = _prefilter.size();
_prefilter.insert ( x.get_tag() );
if ( _prefilter.size() == size_before )
{
_one_eval_succ = NOMAD::UNSUCCESSFUL;
return;
}
// insertion in _all_inserted:
_all_inserted.push_back ( &x );
// other checks:
const NOMAD::Double & h = x.get_h();
if ( !x.is_EB_ok () ||
!x.get_f().is_defined () ||
!h.is_defined () ||
h.value() > _h_max.value() )
{
_one_eval_succ = NOMAD::UNSUCCESSFUL;
return;
}
// insert_feasible or insert_infeasible:
_one_eval_succ = ( x.is_feasible ( _p.get_h_min() ) ) ?
insert_feasible ( x ) : insert_infeasible(x);
if ( _one_eval_succ > _success )
_success = _one_eval_succ;
}
示例13: eval_x
bool CMADSEvaluator::eval_x(NOMAD::Eval_Point &_x, const NOMAD::Double &_h_max, bool &_count_eval) const
{
int i,M=pOP->constraintsSize();
NOMAD::Point y(M+2);
ArrayXd op,ep;
op=CMADS::NOMADPoint2ArrayXd(_x);
y[1]=(pOP->evaluate(op,ep))?0.:1.;
y[0]=(pOP->isMinimization())?ep(0):-ep(0);
for ( i=2; i<M+2; i++ ) { y[i]=1.-ep(i-1); }
_x.set_bb_output(y);
bool tohist=true;
for ( i=1; tohist && i<M+2; i++ ) { if ( y[i]>0. ) tohist=false; }
if ( tohist ) {
pOP->writeHistory(op,ep(0));
}
_count_eval=true;
return true;
}
示例14:
/*---------------------------------------------------------------------*/
void NOMAD::Cache::insert_extern_point ( const NOMAD::Eval_Point & x ) const
{
if ( !x.get_current_run() )
_extern_pts.push_front ( &x );
}
示例15: switch
/*---------------------------------------------------------------------*/
NOMAD::Cache_File_Point::Cache_File_Point(const NOMAD::Eval_Point &x)
: _n(x.size()) ,
_m(0) ,
_m_def(0) ,
_coords(NULL) ,
_bbo_def(NULL) ,
_bbo_index(NULL)
{
int i;
// eval_status:
switch (x.get_eval_status())
{
case NOMAD::EVAL_FAIL:
_eval_status = 0;
break;
case NOMAD::EVAL_OK:
_eval_status = 1;
break;
case NOMAD::EVAL_IN_PROGRESS:
_eval_status = 2;
break;
case NOMAD::UNDEFINED_STATUS:
_eval_status = 3;
break;
case NOMAD::EVAL_USER_REJECT:
_eval_status = 3;
break;
}
// inputs:
if (_n > 0)
{
_coords = new double [_n];
for (i = 0 ; i < _n ; ++i)
_coords[i] = x[i].value();
}
else
_n = 0;
// outputs:
const NOMAD::Point &bbo = x.get_bb_outputs();
_m = bbo.size();
if (_m > 0)
{
std::vector<double> vd;
std::vector<int> vi;
for (i = 0 ; i < _m ; ++i)
if (bbo[i].is_defined())
{
vd.push_back(bbo[i].value());
vi.push_back(i);
}
_m_def = static_cast<int>(vd.size());
if (_m_def > 0)
{
_bbo_def = new double [_m_def];
_bbo_index = new int [_m_def];
for (i = 0 ; i < _m_def ; ++i)
{
_bbo_def [i] = vd[i];
_bbo_index[i] = vi[i];
}
}
}
else
_m = 0;
#ifdef MEMORY_DEBUG
++NOMAD::Cache_File_Point::_cardinality;
if (NOMAD::Cache_File_Point::_cardinality >
NOMAD::Cache_File_Point::_max_cardinality)
++NOMAD::Cache_File_Point::_max_cardinality;
#endif
}