本文整理汇总了C++中IntervalVector类的典型用法代码示例。如果您正苦于以下问题:C++ IntervalVector类的具体用法?C++ IntervalVector怎么用?C++ IntervalVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IntervalVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: separate
void SepInverse::separate(IntervalVector& xin, IntervalVector& xout){
assert(xin.size()==f.nb_var() && xout.size() == f.nb_var());
xin &= xout;
Domain tmp=f.eval_domain(xin);
yin.init(Interval::ALL_REALS);
yout.init(Interval::ALL_REALS);
id->backward(tmp, yin);
id->backward(tmp, yout);
s.separate(yin, yout);
if( yin.is_empty())
xin.set_empty();
else
tmp = id->eval_domain(yin);
f.backward(tmp, xin);
if( yout.is_empty())
xout.set_empty();
else
tmp = id->eval_domain(yout);
f.backward(tmp, xout);
}
示例2: midpoint
void midpoint(const IntervalVector& x, Eigen::VectorXd* x_mid)
{
x_mid->resize(x.size());
for (int i = 0; i < x.size(); ++i) {
(*x_mid)[i] = (x[i].get_upper() + x[i].get_lower()) / 2.0;
}
}
示例3: mkSolver
void CtcLMI::mkSolver(ibex::MatrixArray& matrices, const IntervalVector &box)
{
// On modifie F0 en fonction des nouvelles bornes de boite
for (int i = 0; i < box.size(); i++)
{
matrices[0][1 + box.size() + 2 * i][1 + box.size() + 2 * i] = box[i].lb();
matrices[0][1 + box.size() + 2 * i + 1][1 + box.size() + 2 * i + 1] = -box[i].ub();
}
solver.setParameterType(SDPA::PARAMETER_DEFAULT);
solver.setParameterMaxIteration(100);
// solver.setNumThreads(4);
// solver.printParameters(stdout);
solver.inputConstraintNumber(matrices.size());
solver.inputBlockNumber(1);
solver.inputBlockSize(1, matrices[0].nb_cols());
solver.inputBlockType(1, SDPA::SDP);
solver.initializeUpperTriangleSpace();
// solver.inputCVec(1, 0);
// solver.inputCVec(2, -1);
for (int i = 0; i < matrices.size(); i++)
for (int j = 1; j < matrices[i].nb_cols() + 1; j++)
for (int k = 1; k < matrices[i].nb_rows() + 1; k++)
solver.inputElement(i, 1, k, j, matrices[i][k - 1][j - 1]);
}
示例4: catch
void InHC4Revise::ibwd(const Function& f, const Domain& y, IntervalVector& x, const IntervalVector& xin) {
Eval e;
if (!xin.is_empty()) {
e.eval(f,xin);
assert(!f.expr().deco.d->is_empty());
for (int i=0; i<f.nb_nodes(); i++)
*f.node(i).deco.p = *f.node(i).deco.d;
}
else {
for (int i=0; i<f.nb_nodes(); i++)
f.node(i).deco.p->set_empty();
}
e.eval(f,x);
assert(!f.expr().deco.d->is_empty());
*f.expr().deco.d = y;
try {
f.backward<InHC4Revise>(*this);
f.read_arg_domains(x);
} catch(EmptyBoxException&) {
x.set_empty();
}
}
示例5: gauss_seidel
void gauss_seidel(const IntervalMatrix& A, const IntervalVector& b, IntervalVector& x, double ratio) {
int n=(A.nb_rows());
assert(n == (A.nb_cols())); // throw NotSquareMatrixException();
assert(n == (x.size()) && n == (b.size()));
double red;
Interval old, proj, tmp;
do {
red = 0;
for (int i=0; i<n; i++) {
old = x[i];
proj = b[i];
for (int j=0; j<n; j++) if (j!=i) proj -= A[i][j]*x[j];
tmp=A[i][i];
bwd_mul(proj,tmp,x[i]);
if (x[i].is_empty()) { x.set_empty(); return; }
double gain=old.rel_distance(x[i]);
if (gain>red) red=gain;
}
} while (red >= ratio);
}
示例6: gradient
void Function::gradient(const IntervalVector& x, IntervalVector& g) const {
assert(g.size()==nb_var());
assert(x.size()==nb_var());
Gradient().gradient(*this,x,g);
// if (!df) ((Function*) this)->df=new Function(*this,DIFF);
// g=df->eval_vector(x);
}
示例7: assert
void Function::hansen_matrix(const IntervalVector& box, IntervalMatrix& H) const {
int n=nb_var();
int m=expr().dim.vec_size();
assert(H.nb_cols()==n);
assert(box.size()==n);
assert(expr().dim.is_vector());
assert(H.nb_rows()==m);
IntervalVector x=box.mid();
IntervalMatrix J(m,n);
// test!
// int tab[box.size()];
// box.sort_indices(false,tab);
// int var;
for (int var=0; var<n; var++) {
//var=tab[i];
x[var]=box[var];
jacobian(x,J);
H.set_col(var,J.col(var));
}
}
示例8: contract
void CtcPolytopeHull::contract(IntervalVector& box) {
if (!(limit_diam_box.contains(box.max_diam()))) return;
// is it necessary? YES (BNE) Soplex can give false infeasible results with large numbers
// cout << " box before LR " << box << endl;
try {
// Update the bounds the variables
mylinearsolver->initBoundVar(box);
//returns the number of constraints in the linearized system
int cont = lr.linearization(box,mylinearsolver);
if(cont<1) return;
optimizer(box);
// mylinearsolver->writeFile("LP.lp");
// system ("cat LP.lp");
// cout << " box after LR " << box << endl;
mylinearsolver->cleanConst();
}
catch(EmptyBoxException&) {
box.set_empty(); // empty the box before exiting in case of EmptyBoxException
mylinearsolver->cleanConst();
throw EmptyBoxException();
}
}
示例9: inflating_gauss_seidel
bool inflating_gauss_seidel(const IntervalMatrix& A, const IntervalVector& b, IntervalVector& x, double min_dist, double mu_max) {
int n=(A.nb_rows());
assert(n == (A.nb_cols()));
assert(n == (x.size()) && n == (b.size()));
assert(min_dist>0);
//cout << " ====== inflating Gauss-Seidel ========= " << endl;
double red;
IntervalVector xold(n);
Interval proj;
double d=DBL_MAX; // Hausdorff distances between 2 iterations
double dold;
double mu; // ratio of dist(x_k,x_{k-1)) / dist(x_{k-1},x_{k-2}).
do {
dold = d;
xold = x;
for (int i=0; i<n; i++) {
proj = b[i];
for (int j=0; j<n; j++) if (j!=i) proj -= A[i][j]*x[j];
x[i] = proj/A[i][i];
}
d=distance(xold,x);
mu=d/dold;
//cout << " x=" << x << " d=" << d << " mu=" << mu << endl;
} while (mu<mu_max && d>min_dist);
//cout << " ======================================= " << endl;
return (mu<mu_max);
}
示例10: compare
void SetNodeReg::compare(const IntervalVector& root, const IntervalVector& box,const int& type, bool * flag,unsigned int op) {
if(is_leaf()) {
//cout<<"leaf box: "<<root<<"of status: "<<status<<" box: "<<box<<endl;
switch(op){
case 0:
if(status != type){*flag = false;}
break;
case 1:
if(status == type){*flag = true;}
break;
case 2:
if(status == type){*flag = false;}
break;
}
}
else if(((op==0||op==2)&& (*flag)) || (op ==1 && !(*flag))) {
if(root.intersects(right_box(box)))
{right->compare(right_box(root),box,type,flag,op);}
if(root.intersects(left_box(box)))
{left->compare(left_box(root),box,type,flag,op);}
}
return;
}
示例11: print_mma
std::string print_mma(const IntervalVector& iv) {
std::string res = "{";
for(int i = 0; i < iv.size()-1; ++i) {
res += "{" + std::to_string(iv[i].lb()) + ", " + std::to_string(iv[i].ub()) + "}, ";
}
res += "{" + std::to_string(iv[iv.size()-1].lb()) + ", " + std::to_string(iv[iv.size()-1].ub()) + "}}";
return res;
}
示例12: contract
void CtcNewton::contract(IntervalVector& box) {
if (!(box.max_diam()<=ceil)) return;
else newton(f,box,prec,gauss_seidel_ratio);
if (box.is_empty()) {
set_flag(FIXPOINT);
}
}
示例13: volume
double volume(const IntervalVector& x)
{
double vol = 1.0;
for (auto itr = x.begin(); itr != x.end(); ++itr) {
const auto& interval = *itr;
vol *= interval.get_upper() - interval.get_lower();
}
return vol;
}
示例14: almost_eq
bool TestIbex::almost_eq(const IntervalVector& y_actual, const IntervalVector& y_expected, double err) {
if (y_actual.size()!=y_actual.size()) return false;
if (y_actual.is_empty() && y_expected.is_empty()) return true;
for (int i=0; i<y_actual.size(); i++) {
if (!almost_eq(y_actual[i], y_expected[i],err)) return false;
}
return true;
}
示例15: findNeighbor
void SetNodeReg::findNeighbor(const IntervalVector& box,const IntervalVector& nbox,vector<SetNodeReg*> * neigh) {
if(is_leaf()){
if(box.intersects(nbox) && box!=nbox )
neigh->push_back(this);
}
else if(box.intersects(nbox)) {
right->findNeighbor(right_box(box),nbox,neigh);
left->findNeighbor(left_box(box),nbox,neigh);
}
}