mirror of
https://github.com/Z3Prover/z3
synced 2025-10-26 01:14:36 +00:00
abstract solver API
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
9cf99e26a6
commit
d04e72819a
11 changed files with 237 additions and 110 deletions
|
|
@ -37,6 +37,7 @@ Revision History:
|
|||
#include "sat/sat_drat.h"
|
||||
#include "sat/sat_parallel.h"
|
||||
#include "sat/sat_local_search.h"
|
||||
#include "sat/sat_solver_core.h"
|
||||
#include "util/params.h"
|
||||
#include "util/statistics.h"
|
||||
#include "util/stopwatch.h"
|
||||
|
|
@ -75,11 +76,10 @@ namespace sat {
|
|||
void collect_statistics(statistics & st) const;
|
||||
};
|
||||
|
||||
class solver {
|
||||
class solver : public solver_core {
|
||||
public:
|
||||
struct abort_solver {};
|
||||
protected:
|
||||
reslimit& m_rlimit;
|
||||
bool m_checkpoint_enabled;
|
||||
config m_config;
|
||||
stats m_stats;
|
||||
|
|
@ -197,12 +197,12 @@ namespace sat {
|
|||
// Misc
|
||||
//
|
||||
// -----------------------
|
||||
void updt_params(params_ref const & p);
|
||||
void updt_params(params_ref const & p) override;
|
||||
static void collect_param_descrs(param_descrs & d);
|
||||
|
||||
void collect_statistics(statistics & st) const;
|
||||
void collect_statistics(statistics & st) const override;
|
||||
void reset_statistics();
|
||||
void display_status(std::ostream & out) const;
|
||||
void display_status(std::ostream & out) const override;
|
||||
|
||||
/**
|
||||
\brief Copy (non learned) clauses from src to this solver.
|
||||
|
|
@ -217,6 +217,9 @@ namespace sat {
|
|||
// Variable & Clause creation
|
||||
//
|
||||
// -----------------------
|
||||
void add_clause(unsigned num_lits, literal * lits, bool learned) override { mk_clause(num_lits, lits, learned); }
|
||||
bool_var add_var(bool ext) override { return mk_var(ext, true); }
|
||||
|
||||
bool_var mk_var(bool ext = false, bool dvar = true);
|
||||
void mk_clause(literal_vector const& lits, bool learned = false) { mk_clause(lits.size(), lits.c_ptr(), learned); }
|
||||
void mk_clause(unsigned num_lits, literal * lits, bool learned = false);
|
||||
|
|
@ -279,29 +282,28 @@ namespace sat {
|
|||
//
|
||||
// -----------------------
|
||||
public:
|
||||
bool inconsistent() const { return m_inconsistent; }
|
||||
unsigned num_vars() const { return m_level.size(); }
|
||||
unsigned num_clauses() const;
|
||||
bool inconsistent() const override { return m_inconsistent; }
|
||||
unsigned num_vars() const override { return m_level.size(); }
|
||||
unsigned num_clauses() const override;
|
||||
void num_binary(unsigned& given, unsigned& learned) const;
|
||||
unsigned num_restarts() const { return m_restarts; }
|
||||
bool is_external(bool_var v) const { return m_external[v] != 0; }
|
||||
bool is_external(literal l) const { return is_external(l.var()); }
|
||||
void set_external(bool_var v);
|
||||
void set_non_external(bool_var v);
|
||||
bool is_external(bool_var v) const override { return m_external[v] != 0; }
|
||||
void set_external(bool_var v) override;
|
||||
void set_non_external(bool_var v) override;
|
||||
bool was_eliminated(bool_var v) const { return m_eliminated[v] != 0; }
|
||||
void set_eliminated(bool_var v, bool f) { m_eliminated[v] = f; }
|
||||
void set_eliminated(bool_var v, bool f) override { m_eliminated[v] = f; }
|
||||
bool was_eliminated(literal l) const { return was_eliminated(l.var()); }
|
||||
unsigned scope_lvl() const { return m_scope_lvl; }
|
||||
unsigned search_lvl() const { return m_search_lvl; }
|
||||
bool at_search_lvl() const { return m_scope_lvl == m_search_lvl; }
|
||||
bool at_base_lvl() const { return m_scope_lvl == 0; }
|
||||
bool at_base_lvl() const override { return m_scope_lvl == 0; }
|
||||
lbool value(literal l) const { return static_cast<lbool>(m_assignment[l.index()]); }
|
||||
lbool value(bool_var v) const { return static_cast<lbool>(m_assignment[literal(v, false).index()]); }
|
||||
unsigned lvl(bool_var v) const { return m_level[v]; }
|
||||
unsigned lvl(literal l) const { return m_level[l.var()]; }
|
||||
unsigned init_trail_size() const { return at_base_lvl() ? m_trail.size() : m_scopes[0].m_trail_lim; }
|
||||
unsigned init_trail_size() const override { return at_base_lvl() ? m_trail.size() : m_scopes[0].m_trail_lim; }
|
||||
unsigned trail_size() const { return m_trail.size(); }
|
||||
literal trail_literal(unsigned i) const { return m_trail[i]; }
|
||||
literal trail_literal(unsigned i) const override { return m_trail[i]; }
|
||||
literal scope_literal(unsigned n) const { return m_trail[m_scopes[n].m_trail_lim]; }
|
||||
void assign(literal l, justification j) {
|
||||
TRACE("sat_assign", tout << l << " previous value: " << value(l) << "\n";);
|
||||
|
|
@ -333,8 +335,8 @@ namespace sat {
|
|||
config const& get_config() const { return m_config; }
|
||||
void set_incremental(bool b) { m_config.m_incremental = b; }
|
||||
bool is_incremental() const { return m_config.m_incremental; }
|
||||
extension* get_extension() const { return m_ext.get(); }
|
||||
void set_extension(extension* e);
|
||||
extension* get_extension() const override { return m_ext.get(); }
|
||||
void set_extension(extension* e) override;
|
||||
bool set_root(literal l, literal r);
|
||||
void flush_roots();
|
||||
typedef std::pair<literal, literal> bin_clause;
|
||||
|
|
@ -369,13 +371,13 @@ namespace sat {
|
|||
//
|
||||
// -----------------------
|
||||
public:
|
||||
lbool check(unsigned num_lits = 0, literal const* lits = nullptr);
|
||||
lbool check(unsigned num_lits = 0, literal const* lits = nullptr) override;
|
||||
|
||||
model const & get_model() const { return m_model; }
|
||||
model const & get_model() const override { return m_model; }
|
||||
bool model_is_current() const { return m_model_is_current; }
|
||||
literal_vector const& get_core() const { return m_core; }
|
||||
literal_vector const& get_core() const override { return m_core; }
|
||||
model_converter const & get_model_converter() const { return m_mc; }
|
||||
void flush(model_converter& mc) { mc.flush(m_mc); }
|
||||
void flush(model_converter& mc) override { mc.flush(m_mc); }
|
||||
void set_model(model const& mdl);
|
||||
char const* get_reason_unknown() const { return m_reason_unknown.c_str(); }
|
||||
bool check_clauses(model const& m) const;
|
||||
|
|
@ -545,10 +547,10 @@ namespace sat {
|
|||
bool_var max_var(bool learned, bool_var v);
|
||||
|
||||
public:
|
||||
void user_push();
|
||||
void user_pop(unsigned num_scopes);
|
||||
void pop_to_base_level();
|
||||
unsigned num_user_scopes() const { return m_user_scope_literals.size(); }
|
||||
void user_push() override;
|
||||
void user_pop(unsigned num_scopes) override;
|
||||
void pop_to_base_level() override;
|
||||
unsigned num_user_scopes() const override { return m_user_scope_literals.size(); }
|
||||
reslimit& rlimit() { return m_rlimit; }
|
||||
// -----------------------
|
||||
//
|
||||
|
|
@ -645,8 +647,9 @@ namespace sat {
|
|||
clause * const * begin_learned() const { return m_learned.begin(); }
|
||||
clause * const * end_learned() const { return m_learned.end(); }
|
||||
clause_vector const& learned() const { return m_learned; }
|
||||
clause_vector const& clauses() const { return m_clauses; }
|
||||
void collect_bin_clauses(svector<bin_clause> & r, bool learned, bool learned_only = false) const;
|
||||
clause_vector const& clauses() const override { return m_clauses; }
|
||||
void collect_bin_clauses(svector<bin_clause> & r, bool learned, bool learned_only) const override;
|
||||
|
||||
|
||||
// -----------------------
|
||||
//
|
||||
|
|
@ -654,11 +657,11 @@ namespace sat {
|
|||
//
|
||||
// -----------------------
|
||||
public:
|
||||
bool check_invariant() const;
|
||||
bool check_invariant() const override;
|
||||
void display(std::ostream & out) const;
|
||||
void display_watches(std::ostream & out) const;
|
||||
void display_watches(std::ostream & out, literal lit) const;
|
||||
void display_dimacs(std::ostream & out) const;
|
||||
void display_dimacs(std::ostream & out) const override;
|
||||
void display_wcnf(std::ostream & out, unsigned sz, literal const* lits, unsigned const* weights) const;
|
||||
void display_assignment(std::ostream & out) const;
|
||||
std::ostream& display_justification(std::ostream & out, justification const& j) const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue