Skip to content

Commit

Permalink
virtual
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
  • Loading branch information
NikolajBjorner committed Aug 26, 2022
1 parent ca0a829 commit 1894c86
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
14 changes: 8 additions & 6 deletions src/sat/sat_drat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace sat {
if (s.get_config().m_drat_binary)
std::swap(m_out, m_bout);
}
// m_print_clause = nullptr;
}

drat::~drat() {
Expand Down Expand Up @@ -684,14 +683,15 @@ namespace sat {
verify(0, nullptr);
SASSERT(m_inconsistent);
}
if (m_print_clause) m_print_clause->on_clause(0, nullptr, status::redundant());
}
void drat::add(literal l, bool learned) {
++m_stats.m_num_add;
status st = get_status(learned);
if (m_out) dump(1, &l, st);
if (m_bout) bdump(1, &l, st);
if (m_check) append(l, st);
//if (m_print_clause) m_print_clause(1, &l, st);
if (m_print_clause) m_print_clause->on_clause(1, &l, st);
}
void drat::add(literal l1, literal l2, status st) {
if (st.is_deleted())
Expand All @@ -702,7 +702,7 @@ namespace sat {
if (m_out) dump(2, ls, st);
if (m_bout) bdump(2, ls, st);
if (m_check) append(l1, l2, st);
//if (m_print_clause) m_print_clause(2, ls, st);
if (m_print_clause) m_print_clause->on_clause(2, ls, st);
}
void drat::add(clause& c, status st) {
if (st.is_deleted())
Expand All @@ -712,7 +712,7 @@ namespace sat {
if (m_out) dump(c.size(), c.begin(), st);
if (m_bout) bdump(c.size(), c.begin(), st);
if (m_check) append(mk_clause(c), st);
//if (m_print_clause) m_print_clause(c.size(), c.begin(), st);
if (m_print_clause) m_print_clause->on_clause(c.size(), c.begin(), st);
}

void drat::add(literal_vector const& lits, status st) {
Expand All @@ -734,7 +734,8 @@ namespace sat {
if (m_out)
dump(sz, lits, st);

//if (m_print_clause) m_print_clause(sz, lits, st);
if (m_print_clause)
m_print_clause->on_clause(sz, lits, st);
}

void drat::add(literal_vector const& c) {
Expand All @@ -754,7 +755,8 @@ namespace sat {
}
}
}
// if (m_print_clause) m_print_clause(c.size(), c.data(), status::redundant());
if (m_print_clause)
m_print_clause->on_clause(c.size(), c.data(), status::redundant());
}

void drat::del(literal l) {
Expand Down
10 changes: 7 additions & 3 deletions src/sat/sat_drat.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ namespace sat {
class justification;
class clause;

struct print_clause {
virtual void on_clause(unsigned, literal const*, status) = 0;
};

class drat {
struct stats {
unsigned m_num_drup = 0;
Expand All @@ -73,7 +77,7 @@ namespace sat {
watched_clause(clause* c, literal l1, literal l2):
m_clause(c), m_l1(l1), m_l2(l2) {}
};
std::function<void(unsigned, literal const*, status)> m_print_clause;
print_clause* m_print_clause = nullptr;
svector<watched_clause> m_watched_clauses;
typedef svector<unsigned> watch;
solver& s;
Expand Down Expand Up @@ -140,8 +144,8 @@ namespace sat {
void add(literal_vector const& c); // add learned clause
void add(unsigned sz, literal const* lits, status st);

void set_print_clause(std::function<void(unsigned, literal const*, status)>& print_clause) {
// m_print_clause = print_clause;
void set_print_clause(print_clause& print_clause) {
m_print_clause = &print_clause;
}

// support for SMT - connect Boolean variables with AST nodes
Expand Down
35 changes: 24 additions & 11 deletions src/sat/smt/euf_proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ namespace euf {
m_drat_initialized = true;
}

void solver::def_add_arg(unsigned arg) {
get_drat().def_add_arg(arg);
}

void solver::def_end() {
get_drat().def_end();
}

void solver::def_begin(char id, unsigned n, std::string const& name) {
get_drat().def_begin(id, n, name);
}

void solver::drat_log_params(func_decl* f) {
for (unsigned i = f->get_num_parameters(); i-- > 0; ) {
auto const& p = f->get_parameter(i);
Expand All @@ -39,6 +51,7 @@ namespace euf {
drat_log_decl(to_func_decl(a));
}
}

void solver::drat_log_expr1(expr* e) {
if (is_app(e)) {
app* a = to_app(e);
Expand All @@ -48,14 +61,14 @@ namespace euf {
strm << mk_ismt2_func(a->get_decl(), m);
get_drat().def_begin('e', e->get_id(), strm.str());
for (expr* arg : *a)
get_drat().def_add_arg(arg->get_id());
get_drat().def_end();
def_add_arg(arg->get_id());
def_end();
}
else if (is_var(e)) {
var* v = to_var(e);
get_drat().def_begin('v', v->get_id(), "" + mk_pp(e->get_sort(), m));
get_drat().def_add_arg(v->get_idx());
get_drat().def_end();
def_add_arg(v->get_idx());
def_end();
}
else if (is_quantifier(e)) {
quantifier* q = to_quantifier(e);
Expand All @@ -65,8 +78,8 @@ namespace euf {
strm << " (" << q->get_decl_name(i) << " " << mk_pp(q->get_decl_sort(i), m) << ")";
strm << ")";
get_drat().def_begin('q', q->get_id(), strm.str());
get_drat().def_add_arg(q->get_expr()->get_id());
get_drat().def_end();
def_add_arg(q->get_expr()->get_id());
def_end();
}
else
UNREACHABLE();
Expand Down Expand Up @@ -118,7 +131,7 @@ namespace euf {
smt2_pp_environment_dbg env(m);
ast_smt2_pp(strm, f, env);
get_drat().def_begin('f', f->get_small_id(), strm.str());
get_drat().def_end();
def_end();
}

/**
Expand Down Expand Up @@ -188,13 +201,13 @@ namespace euf {
drat_log_expr(a);
drat_log_expr(b);
get_drat().def_begin('e', eq->get_id(), std::string("="));
get_drat().def_add_arg(a->get_id());
get_drat().def_add_arg(b->get_id());
get_drat().def_end();
def_add_arg(a->get_id());
def_add_arg(b->get_id());
def_end();
get_drat().bool_def(lit.var(), eq->get_id());
}

void solver::log_clause(unsigned n, literal const* lits, sat::status st) {
void solver::on_clause(unsigned n, literal const* lits, sat::status st) {
if (!get_config().m_lemmas2console)
return;
if (!st.is_redundant() && !st.is_asserted())
Expand Down
9 changes: 2 additions & 7 deletions src/sat/smt/euf_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,8 @@ namespace euf {
for (auto* s : m_solvers)
s->init_search();

if (get_config().m_lemmas2console) {
std::function<void(unsigned, sat::literal const*, sat::status)> on_clause =
[&](unsigned n, sat::literal const* lits, sat::status st) {
log_clause(n, lits, st);
};
get_drat().set_print_clause(on_clause);
}
if (get_config().m_lemmas2console)
get_drat().set_print_clause(*this);
}

bool solver::is_external(bool_var v) {
Expand Down
7 changes: 5 additions & 2 deletions src/sat/smt/euf_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace euf {
std::ostream& display(std::ostream& out) const;
};

class solver : public sat::extension, public th_internalizer, public th_decompile {
class solver : public sat::extension, public th_internalizer, public th_decompile, public sat::print_clause {
typedef top_sort<euf::enode> deps_t;
friend class ackerman;
class user_sort;
Expand Down Expand Up @@ -183,7 +183,10 @@ namespace euf {
bool m_drat_initialized{ false };
void init_drat();
ast_pp_util m_clause_visitor;
void log_clause(unsigned n, literal const* lits, sat::status st);
void on_clause(unsigned n, literal const* lits, sat::status st) override;
void def_add_arg(unsigned arg);
void def_end();
void def_begin(char id, unsigned n, std::string const& name);


// relevancy
Expand Down

0 comments on commit 1894c86

Please sign in to comment.