本文整理汇总了C++中LinearSolver::addConstraint方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearSolver::addConstraint方法的具体用法?C++ LinearSolver::addConstraint怎么用?C++ LinearSolver::addConstraint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinearSolver
的用法示例。
在下文中一共展示了LinearSolver::addConstraint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: linearization
int LinearRelaxFixed::linearization(const IntervalVector& box, LinearSolver& lp_solver) {
int num=0;
for (int i=0; i<A.nb_rows(); i++) {
try {
lp_solver.addConstraint(A[i],LEQ,b[i]);
num++;
} catch (LPException&) { }
}
return num;
}
示例2: X_Linearization
//.........这里部分代码省略.........
/*
case GREEDY7:
//select the coin nearest to the loup
if(goal_ctr!=-1 && Dimension(Optimizer::global_optimizer())>0){
// if(j==0)cout<< Optimizer::global_optimizer()<<end;
inf_x=(abs(Optimizer::global_optimizer()(j+1)-Inf(savebox(j+1))) <
abs(Optimizer::global_optimizer()(j+1)-Sup(savebox(j+1))))? true:false;
}else{
inf_x=(rand()%2==0);
}
break;
*/
/*
case GREEDY6:
save=space.box;
fh_inf, fh_sup;
D=Diam(savebox(j+1));
space.box=Mid(space.box);
space.box(j+1)=Inf(savebox(j+1));
fh_inf=Mid(sys.ctr(ctr).eval(space));
space.box(j+1)=Sup(savebox(j+1));
fh_sup=Mid(sys.ctr(ctr).eval(space));
if (op == LEQ || op== LT)
inf_x=((fh_sup-fh_inf)/(REAL)(n-1) - 0.5*D*(Inf(G(j+1))+Sup(G(j+1))) > 0)? false:true;
else
inf_x=((fh_sup-fh_inf)/(REAL)(n-1) - 0.5*D*(Inf(G(j+1))+Sup(G(j+1))) < 0)? false:true;
last_rnd[j]=inf_x? 0:1;
space.box=save;
break;
case GREEDY5:
save=space.box;
fh_inf, fh_sup;
D=Diam(savebox(j+1));
space.box=Mid(space.box);
space.box(j+1)=Inf(savebox(j+1));
fh_inf=Mid(sys.ctr(ctr).eval(space));
space.box(j+1)=Sup(savebox(j+1));
fh_sup=Mid(sys.ctr(ctr).eval(space));
if (op == LEQ || op== LT)
inf_x=(fh_sup-fh_inf - 0.5*D*(Inf(G(j+1))+Sup(G(j+1))) > 0)? false:true;
else
inf_x=(fh_sup-fh_inf - 0.5*D*(Inf(G(j+1))+Sup(G(j+1))) < 0)? false:true;
last_rnd[j]=inf_x? 0:1;
space.box=save;
break;
*/
default:
last_rnd[j] = rand();
inf_x = (last_rnd[j] % 2 == 0);
break;
}
// cout << " j " << j << " " << savebox[j] << G[j] << endl;
box[j]=inf_x? savebox[j].lb():savebox[j].ub();
Interval a = ((inf_x && (op == LEQ || op== LT)) ||
(!inf_x && (op == GEQ || op== GT))) ? G[j].lb() : G[j].ub();
row1[j] = a.mid();
ev -= a*box[j];
}
// cout << " ev " << ev << endl;
/* used in BEST not implemented in v2.0
if(corner) delete[] corner;
*/
ev+= sys.ctrs[ctr].f.eval(box);
if(id_point==0) nb_nonlinear_vars=nonlinear_var;
for(int j=0;j<n;j++)
tot_ev+=row1[j]*savebox[j]; //natural evaluation of the left side of the linear constraint
bool added=false;
if (op == LEQ || op == LT) {
//g(xb) + a1' x1 + ... + an xn <= 0
if(tot_ev.lb()>(-ev).ub())
throw EmptyBoxException(); // the constraint is not satisfied
if((-ev).ub()<tot_ev.ub()) { // otherwise the constraint is satisfied for any point in the box
lp_solver.addConstraint( row1, LEQ, (-ev).ub());
added=true;
}
} else {
if(tot_ev.ub()<(-ev).lb())
throw EmptyBoxException();
if ((-ev).lb()>tot_ev.lb()) {
lp_solver.addConstraint( row1, GEQ, (-ev).lb() );
added=true;
}
}
//box=savebox;
return (added)? 1:0;
}