void Manifold::read_signature(ifstream& f) { char* sig=new char[SIGNATURE_LENGTH]; f.read(sig, SIGNATURE_LENGTH*sizeof(char)); if (f.eof()) ibex_error("[manifold]: unexpected end of file."); if (strcmp(sig,SIGNATURE)!=0) ibex_error("[manifold]: not a \"manifold\" file."); read_int(f); // manifold version }
void Manifold::write(const char* filename) const { ofstream f; f.open(filename, ios::out | ios::binary); if (f.fail()) ibex_error("[manifold]: cannot create output file.\n"); write_signature(f); write_int(f,n); write_int(f,m); write_int(f,nb_ineq); write_int(f,status); write_int(f,inner.size()); write_int(f,boundary.size()); write_int(f,unknown.size()); write_int(f,pending.size()); write_double(f,time); write_int(f,nb_cells); for (vector<SolverOutputBox>::const_iterator it=inner.begin(); it!=inner.end(); it++) write_output_box(f,*it); for (vector<SolverOutputBox>::const_iterator it=boundary.begin(); it!=boundary.end(); it++) write_output_box(f,*it); for (vector<SolverOutputBox>::const_iterator it=unknown.begin(); it!=unknown.end(); it++) write_output_box(f,*it); for (vector<SolverOutputBox>::const_iterator it=pending.begin(); it!=pending.end(); it++) write_output_box(f,*it); f.close(); }
void Gradient::jacobian(const Array<Domain>& d, IntervalMatrix& J) { if (!f.expr().dim.is_vector()) { ibex_error("Cannot called \"jacobian\" on a real-valued function"); } int m=f.expr().dim.vec_size(); // calculate the gradient of each component of f for (int i=0; i<m; i++) { const Function* fi=dynamic_cast<const Function*>(&f[i]); if (fi!=NULL) { // if this is a Function object we can // directly calculate the gradient with d fi->deriv_calculator().gradient(d,J[i]); } else { // otherwise we must give a box in argument // TODO add gradient with Array<Domain> in argument // in Function interface? // But, for the moment, cannot happen, because // this function is called by apply_bwd. IntervalVector box(f.nb_var()); load(box,d); f[i].gradient(box,J[i]); if (J[i].is_empty()) { J.set_empty(); return; } } } }
ofstream* CovOptimData::write(const char* filename, const CovOptimData& cov, std::stack<unsigned int>& format_id, std::stack<unsigned int>& format_version) { format_id.push(subformat_number); format_version.push(FORMAT_VERSION); ofstream* f = CovList::write(filename, cov, format_id, format_version); write_vars (*f, cov.var_names()); write_pos_int(*f, cov.optimizer_status()); write_pos_int(*f, (uint32_t) cov.is_extended_space()); write_double (*f, cov.uplo()); write_double (*f, cov.uplo_of_epsboxes()); write_double (*f, cov.loup()); if (!cov.loup_point().is_empty()) { unsigned int nb_var = cov.is_extended_space() ? cov.n-1 : cov.n; // TODO: we assume here that the goal var is n-1 if (cov[0].subvector(0,nb_var-1)!=cov.loup_point()) { ibex_error("[CovOptimData] the first box in the list must be the 'loup-point'."); } write_pos_int(*f, (uint32_t) 1); } else { write_pos_int(*f, (uint32_t) 0); } write_double(*f, cov.time()); write_pos_int (*f, cov.nb_cells()); return f; }
SolverOutputBox Manifold::read_output_box(ifstream& f) { IntervalVector box(n); for (int j=0; j<n; j++) { double lb=read_double(f); double ub=read_double(f); box[j]=Interval(lb,ub); } int _status=read_int(f); if (_status<0 || _status>=4) { ibex_error("[manifold]: bad input file (bad status code)."); } SolverOutputBox sol(n); switch(_status) { case 0: (SolverOutputBox::sol_status&) sol.status = SolverOutputBox::INNER; break; case 1: (SolverOutputBox::sol_status&) sol.status = SolverOutputBox::BOUNDARY; break; case 2: (SolverOutputBox::sol_status&) sol.status = SolverOutputBox::UNKNOWN; break; case 3: (SolverOutputBox::sol_status&) sol.status = SolverOutputBox::PENDING; break; } sol._existence = box; if (m<n) { if (_status<=1) { BitSet params(n); for (int j=0; j<n-m; j++) { int v=read_int(f); if (v<1 || v>n) { ibex_error("[manifold]: bad input file (bad parameter index)"); } params.add(v-1); // index starting from 1 in the raw format } sol.varset = new VarSet(n,params,false); } } return sol; }
void CovOptimData::read_vars(ifstream& f, size_t n, vector<string>& var_names) { char x; for (size_t i=0; i<n; i++) { stringstream s; do { f.read(&x, sizeof(char)); if (f.eof()) ibex_error("[CovManifold]: unexpected end of file."); if (x!='\0') s << x; } while(x!='\0'); var_names.push_back(s.str()); } }
void Manifold::load(const char* filename) { ifstream f; f.open(filename, ios::in | ios::binary); if (f.fail()) ibex_error("[manifold]: cannot open input file.\n"); read_signature(f); if (read_int(f)!=n) ibex_error("[manifold]: bad input file (number of variables does not match)."); if (read_int(f)!=m) ibex_error("[manifold]: bad input file (number of equalities does not match)."); if (read_int(f)!=nb_ineq) ibex_error("[manifold]: bad input file (number of inequalities does not match)."); read_int(f); // status int nb_inner = read_int(f); int nb_boundary = read_int(f); int nb_unknown = read_int(f); int nb_pending = read_int(f); int nb_sols = nb_inner + nb_boundary + nb_unknown + nb_pending; time = read_double(f); nb_cells = read_int(f); IntervalVector box(n); for (int i=0; i<nb_sols; i++) { SolverOutputBox sol = read_output_box(f); switch(sol.status) { case 0: inner.push_back(sol); break; case 1: boundary.push_back(sol); break; case 2: unknown.push_back(sol); break; case 3: pending.push_back(sol); break; } } }
void CtcFirstOrderTest::contract(IntervalVector& box, ContractContext& context) { if(box.size() == 2) { return; } BxpNodeData* node_data = (BxpNodeData*) context.prop[BxpNodeData::id]; if(node_data == nullptr) { ibex_error("CtcFirstOrderTest: BxpNodeData must be set"); } vector<IntervalVector> gradients; for (int i = 0; i < system_.normal_constraints_.size() - 1; ++i) { if (!system_.normal_constraints_[i].isSatisfied(box)) { gradients.push_back(system_.normal_constraints_[i].gradient(box)); } } for (int i = 0; i < system_.sic_constraints_.size(); ++i) { if (!system_.sic_constraints_[i].isSatisfied(box, node_data->sic_constraints_caches[i])) { gradients.push_back(system_.sic_constraints_[i].gradient(box, node_data->sic_constraints_caches[i])); } } // Without the goal variable IntervalMatrix matrix(nb_var - 1, gradients.size() + 1); matrix.set_col(0, system_.goal_function_->gradient(box.subvector(0, nb_var - 2))); for (int i = 0; i < gradients.size(); ++i) { matrix.set_col(i + 1, gradients[i].subvector(0, nb_var - 2)); } bool testfailed = true; if (matrix.nb_cols() == 1) { if (matrix.col(0).contains(Vector::zeros(nb_var - 2))) { testfailed = false; } } else { int* pr = new int[matrix.nb_rows()]; int* pc = new int[matrix.nb_cols()]; IntervalMatrix LU(matrix.nb_rows(), matrix.nb_cols()); testfailed = true; try { interval_LU(matrix, LU, pr, pc); } catch(SingularMatrixException&) { testfailed = false; } delete[] pr; delete[] pc; } if(testfailed) { box.set_empty(); } }
ifstream* CovOptimData::read(const char* filename, CovOptimData& cov, std::stack<unsigned int>& format_id, std::stack<unsigned int>& format_version) { ifstream* f = CovList::read(filename, cov, format_id, format_version); if (format_id.empty() || format_id.top()!=subformat_number || format_version.top()!=FORMAT_VERSION) { cov.data->_optim_optimizer_status = (unsigned int) Optimizer::SUCCESS; cov.data->_optim_is_extended_space = false; cov.data->_optim_uplo = NEG_INFINITY; cov.data->_optim_loup = POS_INFINITY; cov.data->_optim_loup_point.resize((int) cov.n); cov.data->_optim_loup_point = IntervalVector::empty(cov.n); cov.data->_optim_time = -1; cov.data->_optim_nb_cells = 0; } else { format_id.pop(); format_version.pop(); read_vars(*f, cov.n, cov.data->_optim_var_names); unsigned int status = read_pos_int(*f); switch (status) { case 0: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::SUCCESS; break; case 1: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::INFEASIBLE; break; case 2: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::NO_FEASIBLE_FOUND; break; case 3: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::UNBOUNDED_OBJ; break; case 4: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::TIME_OUT; break; case 5: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::UNREACHED_PREC; break; default: ibex_error("[CovOptimData]: invalid optimizer status."); } cov.data->_optim_is_extended_space = (bool) read_pos_int(*f); cov.data->_optim_uplo = read_double(*f); cov.data->_optim_uplo_of_epsboxes = read_double(*f); cov.data->_optim_loup = read_double(*f); unsigned int loup_found = read_pos_int(*f); unsigned int nb_var = cov.is_extended_space() ? cov.n-1 : cov.n; cov.data->_optim_loup_point.resize((int) nb_var); // TODO: we assume here that the goal var is n-1 cov.data->_optim_loup_point = loup_found==1? cov[0].subvector(0,nb_var-1) : IntervalVector::empty(nb_var); cov.data->_optim_time = read_double(*f); cov.data->_optim_nb_cells = read_pos_int(*f); } return f; }
void CtcBisectActiveParameters::contract(IntervalVector& box, ContractContext& context) { lp_solver_.clean_ctrs(); lp_solver_.set_bounds(box); lp_solver_.set_obj_var(sys_.ext_nb_var - 1, 1.0); lp_solver_.set_sense(LPSolver::MINIMIZE); if(linearizer_.linearize(box, lp_solver_, context.prop) < 0) { return; } //lp_solver_.write_file(); auto return_code = lp_solver_.solve(); if (return_code != LPSolver::Status_Sol::OPTIMAL) { return; } //Vector sol(box.mid()); Vector sol = lp_solver_.get_primal_sol(); Vector sol_without_goal = sol.subvector(0, sys_.nb_var - 1); //Vector dual(lp_solver_.get_nb_rows()); Vector dual = lp_solver_.get_dual_sol(); //IntervalVector rhs(dual.size()); IntervalVector rhs = lp_solver_.get_lhs_rhs(); //Matrix A(lp_solver_.get_nb_rows(), system_.ext_nb_var); Matrix A = lp_solver_.get_rows(); BxpNodeData* node_data = (BxpNodeData*) context.prop[BxpNodeData::id]; if(node_data == nullptr) { ibex_error("CtcBisectActiveParameters: BxpNodeData must be set"); } blankenship(sol, sys_, node_data); // After variables, linearized goal and normal constraints /*int current_row = sys_.ext_nb_var+sys_.normal_constraints_.size(); for(int constraint_index = 0; constraint_index < sys_.sic_constraints_.size(); ++constraint_index) { auto& constraint = sys_.sic_constraints_[constraint_index]; //auto& cache = constraint.cache_->parameter_caches_; auto& cache = node_data->sic_constraints_caches[constraint_index]; int caches_size = cache.parameter_caches_.size(); for(int i = 0; i < caches_size; ++i) { auto parameter_box = cache.parameter_caches_[i].parameter_box; //if(Interval(dual[current_row]).inflate(1e-10).contains(0)) { if(constraint.evaluate(sol, parameter_box).ub() > 0) { auto bisectList = bisectAllDim(parameter_box); cache.parameter_caches_[i] = _createNewCache(constraint, box, bisectList[0]); for (int j = 1; j < bisectList.size(); ++j) cache.parameter_caches_.emplace_back(_createNewCache(constraint, box, bisectList[j])); } current_row++; } }*/ }
void Manifold::write_txt(const char* filename, bool MMA) const { ofstream file; file.open(filename, ios::out); if (file.fail()) ibex_error("[manifold]: cannot create output file.\n"); // character to separate elements in a list char s=MMA? ',' : ' '; // character that ends a list //char e=MMA? ' ' : '}'; if (MMA) file << "{{"; file << n << s << m << s << nb_ineq; if (MMA) file << "},"; else file << '\n'; file << status; if (MMA) file << ",{"; else file << '\n'; file << inner.size() << s << boundary.size() << s << unknown.size() << s << pending.size(); if (MMA) file << "},{"; else file << '\n'; file << time << s << nb_cells; if (MMA) file << "}"; else file << '\n'; if (MMA) file << ",{"; bool first_sol=true; for (vector<SolverOutputBox>::const_iterator it=inner.begin(); it!=inner.end(); it++) { if (!first_sol && MMA) file << ','; else first_sol=false; write_txt(file,*it,MMA); } for (vector<SolverOutputBox>::const_iterator it=boundary.begin(); it!=boundary.end(); it++) { if (!first_sol && MMA) file << ','; else first_sol=false; write_txt(file,*it,MMA); } for (vector<SolverOutputBox>::const_iterator it=unknown.begin(); it!=unknown.end(); it++) { if (!first_sol && MMA) file << ','; else first_sol=false; write_txt(file,*it,MMA); } for (vector<SolverOutputBox>::const_iterator it=pending.begin(); it!=pending.end(); it++) { if (!first_sol && MMA) file << ','; else first_sol=false; write_txt(file,*it,MMA); } if (MMA) file << '}'; if (MMA) file << "}\n"; file.close(); }
FncKhunTucker::FncKhunTucker(const NormalizedSystem& sys, Function& _df, Function** _dg, const IntervalVector& current_box, const BitSet& active) : Fnc(1,1), nb_mult(0), // **tmp** n(sys.nb_var), sys(sys), df(_df), dg(active.size()), active(active), eq(BitSet::empty(sys.f_ctrs.image_dim())), ineq(BitSet::empty(sys.f_ctrs.image_dim())), bound_left(BitSet::empty(sys.nb_var)), bound_right(BitSet::empty(sys.nb_var)) { int l=1; // lambda0 if (_dg==NULL && !active.empty()) { ibex_error("[FncKhunTucker] an unconstrained system cannot have active constraints"); } unsigned int i=0; // index of a constraint in the active set for (BitSet::const_iterator c=active.begin(); c!=active.end(); ++c, ++i) { dg.set_ref(i,*_dg[c]); if (sys.ops[c]==EQ) eq.add(i); else ineq.add(i); //cout << " constraint n°" << c << " active\n"; } l+=active.size(); for (int j=0; j<sys.box.size(); j++) { if (current_box[j].lb() <= sys.box[j].lb()) { bound_left.add(j); //cout << " left bound n°" << j << " active\n"; l++; } if (current_box[j].ub() >= sys.box[j].ub()) { bound_right.add(j); //cout << " right bound n°" << j << " active\n"; l++; } } (int&) nb_mult = l; (int&) _nb_var = n + l; assert(_nb_var == sys.nb_var + eq.size() + ineq.size() + bound_left.size() + bound_right.size() + 1); (Dim&) _image_dim = Dim(_nb_var, 1); }
/* * Build the bisector */ Bsc& StrategyParam::get_bsc() { Bsc* bsc; System& ext_sys = get_ext_sys(); // <=> original system in case of a solver if (bisection=="roundrobin") bsc = &rec(new RoundRobin (prec)); else if (bisection== "largestfirst") bsc= &rec(new LargestFirst(prec)); else if (bisection=="smearsum") bsc = &rec(new SmearSum(ext_sys,prec)); else if (bisection=="smearmax") bsc = &rec(new SmearMax(ext_sys,prec)); else if (bisection=="smearsumrel") bsc = &rec(new SmearSumRelative(ext_sys,prec)); else if (bisection=="smearmaxrel") bsc = &rec(new SmearMaxRelative(ext_sys,prec)); else ibex_error("StrategyParam: unknown bisection mode"); return *bsc; }
void BD_Factory::add_gaol(double f_RES) { Array<const ExprNode> new_args(sip.n_arg+sip.p_arg); int I=0; int J=0; for (int K=0; K<sip.n_arg+sip.p_arg; K++) { if (!sip.is_param[K]) new_args.set_ref(K,new_vars[I++]); else // necessary for applying goal function but ignored at the end // (there is no parameter in the goal function): new_args.set_ref(K,ExprConstant::new_(sip.p_domain[J++],true)); } const ExprNode* goal_node=&((*sip.sys.goal)(new_args)); if (problem==ORA) { const ExprConstant& f_RES_node=ExprConstant::new_scalar(f_RES); goal_node = &((*goal_node) - f_RES); add_ctr(ExprCtr(*goal_node,LEQ)); const ExprNode& minus_eta=-new_vars[sip.n_arg]; add_goal(minus_eta); delete &minus_eta; } else { add_goal(*goal_node); } // cleanup for (int K=0; K<sip.n_arg+sip.p_arg; K++) { if (sip.is_param[K]) { if (!new_args[K].fathers.is_empty()) ibex_error("parameters in the objective"); delete &new_args[K]; } } cleanup(*goal_node,false); f_ctrs_copy.clone.clean(); }
void Gradient::gradient(const IntervalVector& box, IntervalVector& gbox) { if (!f.expr().dim.is_scalar()) { ibex_error("Cannot called \"gradient\" on a vector-valued function"); } if (_eval.eval(box).is_empty()) { // outside definition domain -> empty gradient gbox.set_empty(); return; } gbox.clear(); g.write_arg_domains(gbox); f.forward<Gradient>(*this); g.top->i()=1.0; f.backward<Gradient>(*this); g.read_arg_domains(gbox); }
void Optimizer::update_uplo() { double new_uplo=POS_INFINITY; if (! buffer.empty()) { new_uplo= buffer.minimum(); if (new_uplo > loup) { cout << " loup = " << loup << " new_uplo=" << new_uplo << endl; ibex_error("optimizer: new_uplo>loup (please report bug)"); } if (new_uplo < uplo_of_epsboxes) uplo = new_uplo; else uplo= uplo_of_epsboxes; } else if (buffer.empty() && loup != POS_INFINITY) { // empty buffer : new uplo is set to ymax (loup - precision) if a loup has been found new_uplo=compute_ymax(); // not new_uplo=loup, because constraint y <= ymax was enforced // cout << " new uplo buffer empty " << new_uplo << " uplo " << uplo << endl; double m = minimum(new_uplo, uplo_of_epsboxes); if (uplo < m) uplo = m; // warning: hides the field "m" of the class // note: we always have uplo <= uplo_of_epsboxes but we may have uplo > new_uplo, because // ymax is strictly lower than the loup. } }
Bsc::Bsc(const Vector& prec) : _prec(prec) { for (int i=0; i<prec.size(); i++) if (prec[i]<=0) ibex_error("precision must be a nonnegative number"); }
double Manifold::read_double(ifstream& f) { double x; f.read((char*) &x, sizeof(x)); //f >> x; if (f.eof()) ibex_error("[manifold]: unexpected end of file."); return x; }
/* * Build the contractors */ Ctc& StrategyParam::get_ctc() { Ctc* ctc; System& ext_sys = get_ext_sys(); // <=> original system in case of a solver // the first contractor called Ctc& hc4=rec(new CtcHC4(ext_sys,ratio_propag,hc4_incremental)); // Build contractor #2: // -------------------------- // An interval Newton iteration // for solving f()=0 where f is // a vector-valued function representing // the system. Ctc* ctcnewton= NULL; if (filtering == "acidhc4n" || filtering=="hc4n" || filtering=="3bcidhc4n") ctcnewton= &rec(new CtcNewton(get_sys().f, NEWTON_CEIL, prec, GAUSS_SEIDEL_RATIO)); if (filtering=="hc4" || filtering=="hc4n") { ctc = (!ctcnewton)? &hc4 : &rec(new CtcCompo(hc4,ctcnewton)); } else { // hc4 inside acid and 3bcid : incremental propagation beginning with the shaved variable Ctc& hc44cid=rec(new CtcHC4(ext_sys.ctrs,0.1,true)); if (filtering=="acidhc4" || filtering=="acidhc4n") { // The ACID contractor (component of the contractor when filtering == "acidhc4") Ctc& acidhc4=rec(new CtcAcid(ext_sys,hc44cid,optim)); // hc4 followed by acidhc4 : the actual contractor used when filtering == "acidhc4" ctc=(!ctcnewton)? &rec(new CtcCompo(hc4, acidhc4)) : &rec(new CtcCompo(hc4, acidhc4, *ctcnewton)); } else if (filtering =="3bcidhc4" || filtering =="3bcidhc4n") { // The 3BCID contractor on all variables (component of the contractor when filtering == "3bcidhc4") Ctc& c3bcidhc4=rec(new Ctc3BCid(hc44cid)); // hc4 followed by 3bcidhc4 : the actual contractor used when filtering == "3bcidhc4" ctc=(!ctcnewton)? &rec(new CtcCompo(hc4, c3bcidhc4)) : &rec(new CtcCompo(hc4, c3bcidhc4, *ctcnewton)); } else { ibex_error("StrategyParam: unknown contractor mode"); } } // The CtcXNewton contractor // corner selection for linearizations : two corners are selected, a random one and its opposite vector<LinearRelaxXTaylor::corner_point> cpoints; cpoints.push_back(LinearRelaxXTaylor::RANDOM); cpoints.push_back(LinearRelaxXTaylor::RANDOM_INV); LinearRelax* lr; if (lin_relax=="art") lr = &rec(new LinearRelaxCombo(ext_sys,LinearRelaxCombo::ART)); else if (lin_relax=="compo") lr = &rec(new LinearRelaxCombo(ext_sys,LinearRelaxCombo::COMPO)); else if (lin_relax=="xn") lr = &rec(new LinearRelaxXTaylor(ext_sys,cpoints)); else ibex_error("StrategyParam: unknown liner relaxation mode"); // fixpoint linear relaxation , hc4 with default fix point ratio 0.2 if (lin_relax=="compo" || lin_relax=="art"|| lin_relax=="xn") { //cxn = new CtcLinearRelaxation (*lr, hc44xn); Ctc& cxn_poly = rec(new CtcPolytopeHull(*lr, CtcPolytopeHull::ALL_BOX)); // hc4 inside xnewton loop Ctc& hc44xn = rec(new CtcHC4(ext_sys.ctrs,ratio_propag,false)); Ctc& cxn_compo = rec(new CtcCompo(cxn_poly, hc44xn)); Ctc& cxn = rec(new CtcFixPoint (cxn_compo, fixpoint_ratio)); // the actual contractor ctc + linear relaxation return rec(new CtcCompo (*ctc, cxn)); } else return *ctc; }
Bsc::Bsc(double prec) : _prec(1,prec) { if (prec<0) ibex_error("precision must be a nonnegative number"); // note: prec==0 allowed with, e.g., LargestFirst }
int LinearizerDuality::linearize(const IntervalVector& box, LPSolver& lp_solver, BoxProperties& prop) { // ========= get active constraints =========== /* Using system cache seems not interesting. */ //BxpSystemCache* cache=(BxpSystemCache*) prop[BxpSystemCache::get_id(sys)]; BxpSystemCache* cache=NULL; //-------------------------------------------------------------------------- BitSet* active; if (cache!=NULL) { active = &cache->active_ctrs(); } else { active = new BitSet(sys.active_ctrs(box)); } // ============================================ size_t n = sys.nb_var; size_t m = sys.f_ctrs.image_dim(); size_t n_total = n + m*n; int nb_ctr=0; // number of inequalities added in the LP solver // BxpLinearRelaxArgMin* argmin=(BxpLinearRelaxArgMin*) prop[BxpLinearRelaxArgMin::get_id(sys)]; // // if (argmin && argmin->argmin()) { // pt=*argmin->argmin(); // } else pt=box.mid(); if (!active->empty()) { //IntervalMatrix J=cache? cache->active_ctrs_jacobian() : sys.f_ctrs.jacobian(box,active); //IntervalMatrix J=sys.f_ctrs.jacobian(box,*active); IntervalMatrix J(active->size(),n); // derivatives over the box sys.f_ctrs.hansen_matrix(box,pt,J,*active); if (J.is_empty()) { if (cache==NULL) delete active; return -1; } // the evaluation of the constraints in the point IntervalVector gx(sys.f_ctrs.eval_vector(pt,*active)); if (gx.is_empty()) { if (cache==NULL) delete active; return 0; } int i=0; // counter of active constraints for (BitSet::iterator c=active->begin(); c!=active->end(); ++c, i++) { if (!sys.f_ctrs.deriv_calculator().is_linear[c]) { for (size_t j=0; j<n; j++) { Vector row(n_total,0.0); row[j]=1; row[n + c*n +j]=1; double rhs = pt[j] - lp_solver.get_epsilon(); lp_solver.add_constraint(row, LEQ, rhs); nb_ctr++; } } Vector row(n_total,0.0); row.put(0,J[i].lb()); IntervalVector gl(J[i].lb()); Vector diam_correctly_rounded = (IntervalVector(J[i].ub())-gl).lb(); for (size_t j=0; j<n; j++) { if (diam_correctly_rounded[j]<0) ibex_error("negative diameter"); } row.put(n + c*n,-diam_correctly_rounded); double rhs = (-gx[i] + (gl*pt)).lb()- lp_solver.get_epsilon(); lp_solver.add_constraint(row, LEQ, rhs); nb_ctr++; } } if (cache==NULL) delete active; return nb_ctr; }
void SystemFactory::add_var(const ExprSymbol& v) { if (goal || !exprs.empty()) ibex_error("cannot add a variable to a system after a constraint (or the goal function)"); vars.push_back(&v); }