本文整理汇总了C++中interval::width方法的典型用法代码示例。如果您正苦于以下问题:C++ interval::width方法的具体用法?C++ interval::width怎么用?C++ interval::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interval
的用法示例。
在下文中一共展示了interval::width方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: minimize
// Branch-and-bound minimization algorithm
void minimize(itvfun f, // Function to minimize
const interval& x, // Current bounds for 1st dimension
const interval& y, // Current bounds for 2nd dimension
double threshold, // Threshold at which we should stop splitting
double& min_ub, // Current minimum upper bound
minimizer_list& ml) // List of current minimizers
{
interval fxy = f(x,y);
if (fxy.left() > min_ub) { // Current box cannot contain minimum?
return ;
}
if (fxy.right() < min_ub) { // Current box contains a new minimum?
min_ub = fxy.right();
// Discarding all saved boxes whose minimum lower bound is
// greater than the new minimum upper bound
auto discard_begin = ml.lower_bound(minimizer{0,0,min_ub,0});
#pragma omp critical
ml.erase(discard_begin,ml.end());
}
// Checking whether the input box is small enough to stop searching.
// We can consider the width of one dimension only since a box
// is always split equally along both dimensions
if (x.width() <= threshold) {
// We have potentially a new minimizer
#pragma omp critical
ml.insert(minimizer{x,y,fxy.left(),fxy.right()});
return ;
}
// The box is still large enough => we split it into 4 sub-boxes
// and recursively explore them
interval xl, xr, yl, yr;
split_box(x,y,xl,xr,yl,yr);
#pragma omp parallel
#pragma omp sections
{
#pragma omp section
minimize(f,xl,yl,threshold,min_ub,ml);
#pragma omp section
minimize(f,xl,yr,threshold,min_ub,ml);
#pragma omp section
minimize(f,xr,yl,threshold,min_ub,ml);
#pragma omp section
minimize(f,xr,yr,threshold,min_ub,ml);
}
}