3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 09:35:32 +00:00

add mutex pass

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2016-10-04 14:45:23 -07:00
parent e3f0aff318
commit f452895f5f
3 changed files with 117 additions and 0 deletions

View file

@ -136,4 +136,73 @@ lbool solver::get_consequences_core(expr_ref_vector const& asms, expr_ref_vector
return l_true;
}
lbool solver::find_mutexes(expr_ref_vector const& vars, vector<expr_ref_vector>& mutexes) {
mutexes.reset();
ast_manager& m = vars.get_manager();
typedef obj_hashtable<expr> expr_set;
expr_set A, P;
for (unsigned i = 0; i < vars.size(); ++i) {
A.insert(vars[i]);
}
while (!A.empty()) {
P = A;
expr_ref_vector mutex(m);
while (!P.empty()) {
expr_ref_vector asms(m);
expr* p = *P.begin();
P.remove(p);
if (!is_literal(m, p)) {
break;
}
mutex.push_back(p);
asms.push_back(p);
expr_set Q;
expr_set::iterator it = P.begin(), end = P.end();
for (; it != end; ++it) {
expr* q = *it;
scoped_assumption_push _scoped_push(asms, q);
if (is_literal(m, q)) {
lbool is_sat = check_sat(asms);
switch (is_sat) {
case l_false:
Q.insert(q);
break;
case l_true:
break;
case l_undef:
return l_undef;
}
}
}
P = Q;
}
if (mutex.size() > 1) {
mutexes.push_back(mutex);
}
for (unsigned i = 0; i < mutex.size(); ++i) {
A.remove(mutex[i].get());
}
}
// While A != {}:
// R = {}
// P = ~A
// While P != {}:
// Pick p in ~P,
// R = R u { p }
// Let Q be consequences over P of p modulo F.
// Let P &= Q
// If |R| > 1: Yield R
// A \= R
return l_true;
}
bool solver::is_literal(ast_manager& m, expr* e) {
return is_uninterp_const(e) || (m.is_not(e, e) && is_uninterp_const(e));
}

View file

@ -158,6 +158,14 @@ public:
virtual lbool get_consequences(expr_ref_vector const& asms, expr_ref_vector const& vars, expr_ref_vector& consequences);
/**
\brief Find maximal subsets A' of A such that |A'| <= 1. These subsets look somewhat similar to cores: cores have the property
that |~A'| >= 1, where ~A' is the set of negated formulas from A'
*/
virtual lbool find_mutexes(expr_ref_vector const& vars, vector<expr_ref_vector>& mutexes);
/**
\brief Display the content of this solver.
*/
@ -176,6 +184,8 @@ protected:
virtual lbool get_consequences_core(expr_ref_vector const& asms, expr_ref_vector const& vars, expr_ref_vector& consequences);
bool is_literal(ast_manager& m, expr* e);
};
#endif