Skip to content

Commit

Permalink
na
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
  • Loading branch information
NikolajBjorner committed Dec 22, 2021
1 parent 09ee60c commit 4b5ee91
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 24 deletions.
7 changes: 4 additions & 3 deletions src/sat/sat_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,10 @@ namespace sat {
void flush_roots();
typedef std::pair<literal, literal> bin_clause;
struct bin_clause_hash { unsigned operator()(bin_clause const& b) const { return b.first.hash() + 2*b.second.hash(); } };
protected:
watch_list & get_wlist(literal l) { return m_watches[l.index()]; }
watch_list const & get_wlist(literal l) const { return m_watches[l.index()]; }

watch_list const& get_wlist(literal l) const { return m_watches[l.index()]; }
watch_list& get_wlist(literal l) { return m_watches[l.index()]; }
protected:
watch_list & get_wlist(unsigned l_idx) { return m_watches[l_idx]; }
bool is_marked(bool_var v) const { return m_mark[v]; }
void mark(bool_var v) { SASSERT(!is_marked(v)); m_mark[v] = true; }
Expand Down
93 changes: 76 additions & 17 deletions src/sat/smt/euf_relevancy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,99 @@ namespace euf {
m_dual_solver->track_relevancy(v);
}

bool solver::init_relevancy() {
bool solver::init_relevancy1() {
m_relevant_expr_ids.reset();
if (!relevancy_enabled())
return true;
if (!m_dual_solver)
return true;
if (!(*m_dual_solver)(s()))
return false;
init_relevant_expr_ids();

for (auto lit : m_dual_solver->core())
push_relevant(lit.var());

relevant_subterms();

return true;
}

void solver::push_relevant(sat::bool_var v) {
expr* e = m_bool_var2expr.get(v, nullptr);
if (e)
m_relevant_todo.push_back(e);
}


bool solver::init_relevancy2() {
m_relevant_expr_ids.reset();
if (!relevancy_enabled())
return true;
init_relevant_expr_ids();
for (unsigned i = 0; i < s().trail_size(); ++i) {
sat::literal l = s().trail_literal(i);
auto v = l.var();
auto j = s().get_justification(v);
switch (j.get_kind()) {
case sat::justification::kind::BINARY:
case sat::justification::kind::TERNARY:
case sat::justification::kind::CLAUSE:
case sat::justification::kind::EXT_JUSTIFICATION:
push_relevant(l.var());
break;
case sat::justification::kind::NONE:
for (auto const& w : s().get_wlist(~l)) {
if (w.is_binary_non_learned_clause()) {
if (is_propagated(w.get_literal()))
continue;
}
else if (w.is_binary_clause())
continue;
else if (w.is_ternary_clause()) {
if (is_propagated(w.get_literal1()))
continue;
if (is_propagated(w.get_literal2()))
continue;
}
else if (w.is_clause()) {
if (is_propagated(w.get_blocked_literal()))
continue;
}
push_relevant(l.var());
break;
}
break;
}
}
relevant_subterms();
return true;
}

bool solver::is_propagated(sat::literal lit) {
return s().value(lit) == l_true && !s().get_justification(lit.var()).is_none();
}

void solver::init_relevant_expr_ids() {
unsigned max_id = 0;
for (enode* n : m_egraph.nodes())
max_id = std::max(max_id, n->get_expr_id());
m_relevant_expr_ids.resize(max_id + 1, false);
m_relevant_todo.reset();
m_relevant_todo.append(m_auto_relevant);
}

void solver::relevant_subterms() {
ptr_vector<expr>& todo = m_relevant_todo;
bool_vector& visited = m_relevant_visited;
auto const& core = m_dual_solver->core();
todo.reset();
for (auto lit : core) {
expr* e = m_bool_var2expr.get(lit.var(), nullptr);
if (e)
todo.push_back(e);
}
#if 0
std::cout << "init-relevant\n";
for (expr* e : m_auto_relevant)
std::cout << "auto-relevant " << e->get_id() << " " << mk_bounded_pp(e, m) << "\n";
#endif
todo.append(m_auto_relevant);
for (unsigned i = 0; i < todo.size(); ++i) {
expr* e = todo[i];
if (visited.get(e->get_id(), false))
continue;
visited.setx(e->get_id(), true, false);
if (!si.is_bool_op(e))
if (si.is_bool_op(e))
continue;
else
m_relevant_expr_ids.setx(e->get_id(), true, false);
if (!is_app(e))
continue;
Expand Down Expand Up @@ -152,8 +212,7 @@ namespace euf {

TRACE("euf",
for (enode* n : m_egraph.nodes())
if (is_relevant(n))
if (is_relevant(n))
tout << "relevant " << n->get_expr_id() << " [r" << n->get_root_id() << "]: " << mk_bounded_pp(n->get_expr(), m) << "\n";);
return true;
}
}
2 changes: 1 addition & 1 deletion src/sat/smt/euf_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ namespace euf {
if (unit_propagate())
return sat::check_result::CR_CONTINUE;

if (!init_relevancy())
if (!init_relevancy1())
give_up = true;

unsigned num_nodes = m_egraph.num_nodes();
Expand Down
10 changes: 7 additions & 3 deletions src/sat/smt/euf_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,17 @@ namespace euf {
bool_vector m_relevant_visited;
ptr_vector<expr> m_relevant_todo;
void ensure_dual_solver();
bool init_relevancy();


bool init_relevancy1();
bool init_relevancy2();
void relevant_subterms();
void init_relevant_expr_ids();
void push_relevant(sat::bool_var v);
bool is_propagated(sat::literal lit);
// invariant
void check_eqc_bool_assignment() const;
void check_missing_bool_enode_propagation() const;
void check_missing_eq_propagation() const;


// diagnosis
std::ostream& display_justification_ptr(std::ostream& out, size_t* j) const;
Expand Down

0 comments on commit 4b5ee91

Please sign in to comment.