本文整理汇总了C++中nomad::Double::round方法的典型用法代码示例。如果您正苦于以下问题:C++ Double::round方法的具体用法?C++ Double::round怎么用?C++ Double::round使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nomad::Double
的用法示例。
在下文中一共展示了Double::round方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rp
/*-----------------------------------------------------------*/
void NOMAD::LH_Search::values_for_var_i ( int p ,
const NOMAD::Double & delta ,
const NOMAD::Double & delta_max ,
const NOMAD::bb_input_type & bbit ,
const NOMAD::Double & lb ,
const NOMAD::Double & ub ,
NOMAD::Point & x ) const
{
// categorical variables have already been treated as fixed variables:
if ( bbit == NOMAD::CATEGORICAL )
return;
int i;
NOMAD::Double v;
NOMAD::Random_Pickup rp (p);
bool rounding = ( bbit != NOMAD::CONTINUOUS );
bool lb_def = lb.is_defined();
bool ub_def = ub.is_defined();
double w = ( ( lb_def && ub_def ) ?
ub.value()-lb.value() : 1.0 ) / p;
// main loop:
for ( i = 0 ; i < p ; ++i )
{
// both bounds exist:
if ( lb_def && ub_def )
v = lb + ( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w;
// one of the bounds does not exist:
else
{
// lb exists, and ub not: mapping [0;1] --> [lb;+INF[
if ( lb_def )
v = lb + 10 * delta_max * sqrt ( - log ( NOMAD::DEFAULT_EPSILON +
( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) );
// lb does not exist:
else
{
// ub exists, and lb not: mapping [0;1] --> ]-INF;ub]
if ( ub_def )
v = ub - delta_max * 10 *
sqrt ( -log ( NOMAD::DEFAULT_EPSILON +
( i +NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) );
// there are no bounds: mapping [0;1] --> ]-INF;+INF[
else
v = (NOMAD::RNG::rand()%2 ? -1.0 : 1.0) * delta_max * 10 *
sqrt ( - log ( NOMAD::DEFAULT_EPSILON +
( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) );
}
}
// rounding:
if ( rounding )
v = v.round();
// projection to mesh (with ref=0):
v.project_to_mesh ( 0.0 , delta , lb , ub );
// affectation + permutation:
x[rp.pickup()] = v;
}
}