BD_Factory::BD_Factory(const MitsosSIP& sip, BD_Factory::problem_type problem) : sip(sip), problem(problem), new_vars(problem==ORA? sip.n_arg +1 : sip.n_arg) { // add "x" variable varcopy(sip.vars,new_vars); if (problem==ORA) { // add "eta" variable new_vars.set_ref(sip.n_arg, ExprSymbol::new_("eta",Dim::scalar())); // initial domain of eta is computed dynamically // see solve_ORA(...) add_var(new_vars, cart_prod(sip.var_init_domain, IntervalVector(1))); } else { add_var(new_vars, sip.var_init_domain); } };
void SetImage::pave(const IntervalVector& x, double epsilon) { Linside.clear(); Lboundary.clear(); PdcImageSubset p_fin(f,x,p_in); assert(x.size()==n); stack<IntervalVector> Ldomain; IntervalVector xtilde(n); IntervalVector ytilde(n); LargestFirst lf(epsilon); Ldomain.push(x); while (! Ldomain.empty()) { xtilde = Ldomain.top(); Ldomain.pop(); c_out.contract(xtilde); if (xtilde.is_empty()) { continue; } // use natural extension ytilde=f.eval_vector(xtilde); // improve with centered form ytilde&=f.eval_vector(xtilde.mid())+f.jacobian(xtilde)*(xtilde-xtilde.mid()); if (p_in.test(xtilde)==YES && p_fin.test(cart_prod(xtilde,ytilde))==YES) Linside.push_back(ytilde); else if (xtilde.max_diam()<=epsilon) Lboundary.push_back(ytilde); else { pair<IntervalVector,IntervalVector> boxes=lf.bisect(xtilde); Ldomain.push(boxes.first); Ldomain.push(boxes.second); } } }
void CtcKhunTucker::contract(IntervalVector& box) { if (df==NULL) return; // if (sys.nb_ctr==0) { // if (box.is_strict_interior_subset(sys.box)) { // // for unconstrained optimization we benefit from a cheap // // contraction with gradient=0, before running Newton. // // if (nb_var==1) // df->backward(Interval::ZERO,box); // else // df->backward(IntervalVector(nb_var,Interval::ZERO),box); // } // } // // if (box.is_empty()) return; //if (box.max_diam()>1e-1) return; // do we need a threshold? // ========================================================================================= BitSet active=sys.active_ctrs(box); FncKhunTucker fjf(sys,df,dg,box,BitSet::all(sys.nb_ctr)); //active); // we consider that Newton will not succeed if there are more // than n active constraints. if ((fjf.eq.empty() && fjf.nb_mult > sys.nb_var+1) || (!fjf.eq.empty() && fjf.nb_mult > sys.nb_var)) { //cout << fjf.nb_mult << endl; too_many_active++; return; } IntervalVector lambda=fjf.multiplier_domain(); IntervalVector old_lambda(lambda); int *pr; int *pc=new int[fjf.nb_mult]; IntervalMatrix A(fjf.eq.empty() ? sys.nb_var+1 : sys.nb_var, fjf.nb_mult); if (fjf.eq.empty()) { A.put(0,0, fjf.gradients(box)); A.put(sys.nb_var, 0, Vector::ones(fjf.nb_mult), true); // normalization equation pr = new int[sys.nb_var+1]; // selected rows } else { A = fjf.gradients(box); pr = new int[sys.nb_var]; // selected rows } IntervalMatrix LU(A); bool preprocess_success=false; try { IntervalMatrix A2(fjf.nb_mult, fjf.nb_mult); // if (A.nb_rows()>A.nb_cols()) { //cout << "A=" << A << endl; interval_LU(A,LU,pr,pc); lu_OK++; //cout << "LU success\n"; // } else // cout << "bypass LU\n"; Vector b2=Vector::zeros(fjf.nb_mult); for (int i=0; i<fjf.nb_mult; i++) { A2.set_row(i, A.row(pr[i])); if (pr[i]==sys.nb_var) // right-hand side of normalization is 1 b2[i]=1; } //cout << "\n\nA2=" << A2 << endl; precond(A2); //cout << "precond success\n"; precond_OK++; gauss_seidel(A2,b2,lambda); double maxdiam=0; for (int i=0; i<A.nb_rows(); i++) { double d=A.row(i).max_diam(); if (d>maxdiam) maxdiam=d; } if (old_lambda.rel_distance(lambda)>0.1 //&& maxdiam<10 && lambda[1].lb()>0 ) { preprocess_success=true; } if (lambda.is_empty()) { box.set_empty(); return; } } catch(SingularMatrixException&) { } delete[] pr; delete[] pc; if (!preprocess_success) return; CtcNewton newton(fjf,1); IntervalVector full_box = cart_prod(box, lambda); // ========================================================================================= // CtcNewton newton(fjc.f,1); // // IntervalVector full_box = cart_prod(box, IntervalVector(fjc.M+fjc.R+fjc.K+1,Interval(0,1))); // // full_box.put(fjc.n+fjc.M+fjc.R+1,IntervalVector(fjc.K,Interval::ZERO)); // ========================================================================================= IntervalVector save(full_box); newton.contract(full_box); if (full_box.is_empty()) { if (preprocess_success) newton_OK_preproc_OK++; else newton_OK_preproc_KO++; box.set_empty(); } else { if (save.subvector(0,sys.nb_var-1)!=full_box.subvector(0,sys.nb_var-1)) { if (preprocess_success) newton_OK_preproc_OK++; else newton_OK_preproc_KO++; box = full_box.subvector(0,sys.nb_var-1); } else { if (preprocess_success) { newton_KO_preproc_OK++; } else newton_KO_preproc_KO++; } } // ========================================================================================= }