当前位置: 首页>>代码示例>>C++>>正文


C++ Eval_Point::set_eval_status方法代码示例

本文整理汇总了C++中nomad::Eval_Point::set_eval_status方法的典型用法代码示例。如果您正苦于以下问题:C++ Eval_Point::set_eval_status方法的具体用法?C++ Eval_Point::set_eval_status怎么用?C++ Eval_Point::set_eval_status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nomad::Eval_Point的用法示例。


在下文中一共展示了Eval_Point::set_eval_status方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

/*--------------------------------------------*/
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;
}
开发者ID:TheLoutre,项目名称:nomad,代码行数:76,代码来源:TGP_Model.cpp

示例2:

/*-----------------------------------------------------------------*/
void NOMAD::Cache::update ( NOMAD::Eval_Point       & cache_x ,
                           const NOMAD::Eval_Point & x         ) const
{
    const NOMAD::Point & bbo_x = x.get_bb_outputs();
    
    if ( &cache_x == &x         ||
        !x.is_eval_ok()        ||
        !cache_x.is_in_cache() ||
        bbo_x.empty()          ||
        cache_x != x              )
        return;
    
    // check the eval types:
    if ( x.get_eval_type      () != _eval_type ||
        cache_x.get_eval_type() != _eval_type    )
        throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ ,
                                         "NOMAD::Cache:update(): problem with the eval. types" );
    
    const NOMAD::Point & bbo_cache_x = cache_x.get_bb_outputs();
    int                  m           = bbo_cache_x.size();
    
    _sizeof -= cache_x.size_of();
    
    // if the current point could not evaluate and x did,
    // or if the number of bb outputs is different, we set cache_x = x:
    if ( !cache_x.is_eval_ok() || m != bbo_x.size() )
    {
        cache_x.set_eval_status ( NOMAD::EVAL_OK     );
        cache_x.set_bb_output   ( bbo_x              );
        cache_x.set_signature   ( x.get_signature () );
        cache_x.set_direction   ( x.get_direction () );
        
        _sizeof += cache_x.size_of();
        return;
    }
    
    // we complete _bb_outputs:
    int c1 = 0;
    int c2 = 0;
    
    for ( int i = 0 ; i < m ; ++i ) {
        
        if ( bbo_cache_x[i].is_defined() )
            ++c1;
        
        if ( bbo_x[i].is_defined() )
            ++c2;
        
        if ( !bbo_cache_x[i].is_defined() && bbo_x[i].is_defined() )
            cache_x.set_bb_output ( i , bbo_x[i] );
    }
    
    // the two points are 'eval_ok' and have comparable outputs:
    // we select the best as the one with the more defined bb_outputs:
    if ( c2 > c1 ) {
        cache_x.set_signature  ( x.get_signature () );
        cache_x.set_direction  ( x.get_direction () );
        
    }
    
    _sizeof += cache_x.size_of();
}
开发者ID:OpenSolver,项目名称:OpenSolverNomadLib,代码行数:63,代码来源:Cache.cpp

示例3: Exception

    /*-------------------------------------------------------------------*/
    bool NOMAD::Evaluator::eval_x ( NOMAD::Eval_Point	& x          ,
                                   const NOMAD::Double	& h_max      ,
                                   bool					& count_eval   ) const
    {
        count_eval = false;
        
        if ( _bb_exe.empty() || !x.is_complete() )
            throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ ,
                                    "Evaluator: no BB_EXE is defined (blackbox executable names)" );
        
        bool sgte = x.get_eval_type() == NOMAD::SGTE;
        if ( sgte && _sgte_exe.empty() )
            throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ ,
                                    "Evaluator: no SGTE_EXE is defined (surrogate executable names)" );
        
        int         pid     = NOMAD::get_pid();
        int         seed    = _p.get_seed();
        std::string tmp_dir = _p.get_tmp_dir();
        
        std::ostringstream oss;
        oss << "." << seed;
        if ( pid != seed )
            oss << "." << pid;
        oss << "." << x.get_tag() << ".";
        const std::string & sint = oss.str();
        
        // for the parallel version: no need to include the process rank in the names
        // as the point tags are unique for all the processes: each process creates
        // its own points and uses Eval_Point::set_tag()
        
        // blackbox input file writing:
        // ----------------------------
        std::string bb_input_file_name =
        tmp_dir + NOMAD::BLACKBOX_INPUT_FILE_PREFIX
        + sint + NOMAD::BLACKBOX_INPUT_FILE_EXT;
        
        std::string bb_output_file_name =
        tmp_dir + NOMAD::BLACKBOX_OUTPUT_FILE_PREFIX
        + sint + NOMAD::BLACKBOX_OUTPUT_FILE_EXT;
        
        std::ofstream fout ( bb_input_file_name.c_str() );
        if ( fout.fail() )
        {
            std::string err = "could not create file blackbox input file " + bb_input_file_name + ". \n \n #### Please check that write permission are granted for the working directory. #### ";
            throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err );
       }
        
        // include seed:
        if ( _p.get_bb_input_include_seed() )
            fout << seed << " ";
        
        // include tag:
        if ( _p.get_bb_input_include_tag() )
            fout << x.get_tag() << " ";
        
        fout.setf ( std::ios::fixed );
        fout.precision ( NOMAD::DISPLAY_PRECISION_BB );
        x.Point::display ( fout , " " , -1 , -1 );
        fout << std::endl;
        
        fout.close();
        
        if ( fout.fail() )
            return false;
        
        x.set_eval_status ( NOMAD::EVAL_IN_PROGRESS );
        
        std::string   cmd , bb_exe;
        std::ifstream fin;
        bool          failed;
        NOMAD::Double d;
        int           j , nbbok;
        int           ibbo = 0;
        
        // system call to evaluate the blackbox:
        // -------------------------------------
        size_t bn = _bb_exe.size();
        for ( size_t k = 0 ; k < bn ; ++k )
        {
            
            // executable name:
            bb_exe = ( sgte ) ? _sgte_exe[k] : _bb_exe[k];
            
            // system command:
            cmd = bb_exe + " " + bb_input_file_name;
            
            // redirection ? if no, the blackbox has to create
            // the output file 'bb_output_file_name':
            if ( _p.get_bb_redirection() )
                cmd += " > " + bb_output_file_name;
            
#ifdef DEBUG
#ifdef USE_MPI
            int rank;
            MPI_Comm_rank ( MPI_COMM_WORLD, &rank);
            _p.out() << "command(rank=" << rank
            << ") = \'" << cmd << "\'" << std::endl;
#else
            _p.out() << "command=\'" << cmd << "\'" << std::endl;
//.........这里部分代码省略.........
开发者ID:OpenSolver,项目名称:OpenSolverNomadLib,代码行数:101,代码来源:Evaluator.cpp


注:本文中的nomad::Eval_Point::set_eval_status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。