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


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

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


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

示例1: 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);
}
开发者ID:TheLoutre,项目名称:nomad,代码行数:30,代码来源:Phase_One_Evaluator.cpp

示例2: 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())] );
 }
开发者ID:OpenSolver,项目名称:OpenSolverNomadLib,代码行数:13,代码来源:Evaluator.cpp

示例3: Exception

/*-------------------------------------------------------------*/
void NOMAD::Multi_Obj_Evaluator::compute_f ( NOMAD::Eval_Point & x ) const
{
  if ( _i1 < 0 || _i2 < 0 )
    throw NOMAD::Exception ( "Multi_Obj_Evaluator.cpp" , __LINE__ ,
	  "Multi_Obj_Evaluator::compute_f(): no objective indexes defined" );

  int obj_index [2];
  obj_index[0] = _i1;
  obj_index[1] = _i2;

  const NOMAD::Point & bbo = x.get_bb_outputs();

  // a reference is available:
  if ( _ref ) 
  {
      
	  NOMAD::multi_formulation_type mft = _p.get_multi_formulation();
	  
	  if ( mft == NOMAD::UNDEFINED_FORMULATION )
		  throw NOMAD::Exception ( "Multi_Obj_Evaluator.cpp" , __LINE__ ,
								  "Multi_Obj_Evaluator::compute_f(): no formulation type is defined" );
	  
	  // normalized formulation:
	  if ( mft == NOMAD::NORMALIZED || mft == NOMAD::DIST_LINF ) {
		  
		  // f1 - r1:
		  NOMAD::Double d = bbo[obj_index[0]] - (*_ref)[0];
		  
		  // f2 - r2:
		  NOMAD::Double f2mr2 = bbo[obj_index[1]] - (*_ref)[1];
		  
		  // we take the max:
		  if ( f2mr2 > d )
			  d = f2mr2;
		  
		  x.set_f ( d );
	  }
	  
	  // product formulation:
	  else if ( mft == NOMAD::PRODUCT ) {
		  
		  NOMAD::Double prod = 1.0 , ri , fi;
		  
		  for ( int i = 0 ; i < 2 ; ++i ) {
			  
			  ri = (*_ref)[i];
			  fi = bbo[obj_index[i]];
			  
			  if ( fi > ri ) {
				  prod = 0.0;
				  break;
			  }
			  prod = prod * (ri-fi).pow2();
		  }
		  
		  x.set_f ( -prod );
	  }
	  
	  // distance formulation:
	  else {
		  
		  NOMAD::Double d;  
		  NOMAD::Double r1mf1 = (*_ref)[0] - bbo[obj_index[0]];
		  NOMAD::Double r2mf2 = (*_ref)[1] - bbo[obj_index[1]];
		  
		  if ( r1mf1 >= 0.0 && r2mf2 >= 0.0 ) {
			  d = r1mf1.pow2();
			  NOMAD::Double tmp = r2mf2.pow2();
			  if ( tmp < d )
				  d = tmp;
			  d = -d;
		  }
		  else if ( r1mf1 <= 0.0 && r2mf2 <= 0.0 ) {
			  
			  // with L2 norm:
			  if ( mft == NOMAD::DIST_L2 )
				  d = r1mf1.pow2() + r2mf2.pow2();
			  
			  // with L1 norm:
			  else
				  d = (r1mf1.abs() + r2mf2.abs()).pow2();
			  
			  // Linf norm: treated as NORMALIZED
		  }
		  else if ( r1mf1 > 0.0 )
			  d = r2mf2.pow2();
		  else
			  d = r1mf1.pow2();
		  
		  x.set_f ( d );
	  }
  }
    
  // no reference is available (use weights):
  else
    x.set_f ( _w1 * bbo[obj_index[0]] + _w2 * bbo[obj_index[1]] );
}
开发者ID:martinjrobins,项目名称:dakota,代码行数:98,代码来源:Multi_Obj_Evaluator.cpp


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