Saturday, 15 January 2011

z3 - getting new unsat cores -



z3 - getting new unsat cores -

there

i trying extract clause formulas , alter 1 clause's polarity every time, if solved sat, computing models , set clause in set. if solved unsat, find out new unsat cores. incrementally calling unsat core function, it's solved unsat, solver cannot give new unsat cores. codes below:

context c; expr x = c.int_const("x"); expr y = c.int_const("y"); solver s(c); expr f = x + y > 10 && x + y < 6 && y < 5 && x > 0; assert(f.is_app()); vector<expr> qs; if (f.decl().decl_kind() == z3_op_and) { std::cout << "f num. args (before simplify): " << f.num_args() << "\n"; f = f.simplify(); std::cout << "f num. args (after simplify): " << f.num_args() << "\n"; (unsigned = 0; < f.num_args(); i++) { std::cout << "creating reply literal q" << << " " << f.arg(i) << "\n"; std::stringstream qname; qname << "q" << i; expr qi = c.bool_const(qname.str().c_str()); // create new reply literal s.add(implies(qi, f.arg(i))); qs.push_back(qi); } } qs.clear(); vector<expr> f,c,m; size_t count = 0; for(unsigned i=0; i<f.num_args(); i++){ f.push_back(f.arg(i)); } while(!f.empty() && count != f.num_args()){ c.push_back(f[0]); f.erase(f.begin(),f.begin() +1); if(m.size()){ for(unsigned i=0; i<f.size();i++){ s.add(f[i]); } for(unsigned j=0; j<m.size(); j++){ s.add(m[j]); } expr notc= to_expr(c, z3_mk_not(c,c[count])); s.add(notc); }else{ expr notc = to_expr(c,z3_mk_not(c,c[count])); s.add(notc); for(unsigned =0; i<f.size(); i++){ s.add(f[i]); } } if(s.check() == sat){ cout<<"sat"<<"\n"; m.push_back(c[count]); }else if(s.check() == unsat){ size_t i; i=0; if(f.size()){ for(unsigned w=0; w<f.size(); w++){ std::stringstream qname; expr qi = c.bool_const(qname.str().c_str()); s.add(implies(qi,f[w])); qs.push_back(qi); i++; } } for(unsigned j=0; j<m.size(); j++){ stringstream qname; expr qi = c.bool_const(qname.str().c_str()); s.add(implies(qi,m[j])); qs.push_back(qi); i++; } std::stringstream qname; expr qi = c.bool_const(qname.str().c_str()); expr notc = to_expr(c,z3_mk_not(c,c[count])); s.add(implies(qi,notc)); if(s.check(qs.size(),&qs[0]) == unsat){ expr_vector core2 = s.unsat_core(); cout<<"new cores'size "<<core2.size()<<endl; cout<<"new cores "<<core2<<endl; } } qs.clear(); count++; }

it's unclear question is, i'm guessing extract multiple different unsat cores same formula. z3 not back upwards out of box, algorithms can implemented on top of it. see previous question , reference given there (algorithms computing minimal unsatisfiable subsets of constraints), explains basics behind core minimization.

z3

No comments:

Post a Comment