本文整理汇总了C++中nomad::Eval_Point::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Eval_Point::size方法的具体用法?C++ Eval_Point::size怎么用?C++ Eval_Point::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nomad::Eval_Point
的用法示例。
在下文中一共展示了Eval_Point::size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
}
示例2: eval_x
//Function + Constraint Evaluation
bool eval_x(NOMAD::Eval_Point &x, const NOMAD::Double &h_max, bool &count_eval)
{
char errstr[1024];
bool stop = false;
int i, j, n = x.size(), status;
double *xm, *fvals;
mxLogical *sur;
count_eval = true; //mexErrMsgTxt will kill MEX
//Check for Ctrl-C
if (utIsInterruptPending()) {
utSetInterruptPending(false); /* clear Ctrl-C status */
mexPrintf("\nCtrl-C Detected. Exiting NOMAD...\n\n");
count_eval = false;
raise(SIGINT);
return false;
}
//Blackbox / Objective Evaluation
fun->plhs[0] = NULL;
xm = mxGetPr(fun->prhs[fun->xrhs]);
for(i=0;i<n;i++)
xm[i] = x[i].value();
//Add Surrogate if present and requested
if(hasSur) {
sur=mxGetLogicals(fun->prhs[fun->xrhs+1]);
(x.get_eval_type()==NOMAD::SGTE)? *sur=true:*sur=false;
}
//Call MATLAB Objective
try {
status = mexCallMATLAB(1, fun->plhs, fun->nrhs, fun->prhs, fun->f);
}
//Note if these errors occur it is due to errors in MATLAB code, no way to recover?
catch(exception &e) {
sprintf(errstr,"Unrecoverable Error from Objective / Blackbox Callback:\n%sExiting NOMAD...\n\n",e.what());
mexWarnMsgTxt(errstr);
//Force exit
raise(SIGINT);
return false;
}
catch(...) {
mexWarnMsgTxt("Unrecoverable Error from Objective / Blackbox Callback, Exiting NOMAD...\n\n");
//Force exit
raise(SIGINT);
return false;
}
if(status) {
mexWarnMsgTxt("Unrecoverable Error from Objective / Blackbox Callback, Exiting NOMAD...\n\n");
raise(SIGINT);
return false;
}
#ifdef OPTI_VERSION
//Check we got the correct number back
if(mxGetM(fun->plhs[0]) != nobj)
mexErrMsgTxt("Incorrect number of elements returned from the objective function");
//Set Objective (Or multi-objective)
fvals = mxGetPr(fun->plhs[0]);
for(i=0;i<nobj;i++)
x.set_bb_output(i,fvals[i]);
//Constraint Evaluation
if(ncon) {
//Add Surrogate if present and requested
if(hasSur) {
sur=mxGetLogicals(con->prhs[con->xrhs+1]);
(x.get_eval_type()==NOMAD::SGTE)? *sur=true:*sur=false;
}
con->plhs[0] = NULL;
xm = mxGetPr(con->prhs[con->xrhs]);
for(i=0;i<n;i++)
xm[i] = x[i].value();
//Call MATLAB Constraint
try {
status = mexCallMATLAB(1, con->plhs, con->nrhs, con->prhs, con->f);
}
catch(...)
{
mexWarnMsgTxt("Unrecoverable Error from Constraint Callback, Exiting NOMAD...\n\n");
//Force exit
raise(SIGINT);
return false;
}
if(status) {
mexWarnMsgTxt("Unrecoverable Error from Constraint Callback, Exiting NOMAD...\n\n");
raise(SIGINT);
return false;
}
//Check we got the correct number back
if(mxGetM(con->plhs[0]) != ncon)
mexErrMsgTxt("Incorrect number of elements returned from nonlinear constraint function");
//Set Constraints
double *cons = mxGetPr(con->plhs[0]);
for(i=0,j=nobj;i<ncon;i++,j++)
x.set_bb_output(j,cons[i] - con->nlrhs[i]); //subtract nlrhs
// Clean up LHS Ptr
mxDestroyArray(con->plhs[0]);
}
#else //GERAD VERSION
//.........这里部分代码省略.........
示例3:
/*--------------------------------------------*/
bool NOMAD::TGP_Model::predict(NOMAD::Eval_Point &x , bool pred_outside_bnds)
{
if (!_error_str.empty())
return false;
if (!_model_computed)
{
_error_str = "NOMAD::TGP_Model::compute() has not been called";
return false;
}
int i , i0 , ix , m = x.get_m() , nx = x.size();
// reset point outputs:
x.set_eval_status(NOMAD::EVAL_FAIL);
for (i = 0 ; i < m ; ++i)
x.set_bb_output(i , NOMAD::Double());
// check dimensions:
if (m != static_cast<int>(_bbot.size()) ||
(nx != _n0 && nx != _n))
{
_error_str = "predict error: bad x dimensions";
return false;
}
double ZZ , * XX = new double[_n];
// set the coordinates and check the bounds:
for (i = 0 ; i < _n ; ++i)
{
ix = (nx == _n0) ? _fv_index[i] : i;
if (!pred_outside_bnds)
{
i0 = _fv_index[i];
if (x[ix] < _lb[i0] || x[ix] > _ub[i0])
{
delete [] XX;
return false; // this is not an error
}
}
XX[i] = x[ix].value();
}
// predictions (one for each output):
for (i = 0 ; i < m ; ++i)
if (_tgp_models[i])
{
if (!_tgp_models[i]->predict(XX ,
_n ,
ZZ ,
_tgp_rect))
{
std::ostringstream oss;
oss << "predict error: problem with model #" << i;
_error_str = oss.str();
break;
}
x.set_bb_output(i , ZZ);
}
delete [] XX;
if (!_error_str.empty())
{
x.set_eval_status(NOMAD::EVAL_FAIL);
return false;
}
x.set_eval_status(NOMAD::EVAL_OK);
return true;
}