mirror of
https://github.com/Z3Prover/z3
synced 2025-08-03 01:40:22 +00:00
refactor sat/sls interface. Remove wpm2 and bvsls dependencies
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
a02cab2194
commit
ee1a1b1135
43 changed files with 609 additions and 891 deletions
|
@ -19,11 +19,16 @@ Notes:
|
|||
#ifndef _OPT_MAXSMT_H_
|
||||
#define _OPT_MAXSMT_H_
|
||||
|
||||
#include "opt_solver.h"
|
||||
#include "statistics.h"
|
||||
#include"ast.h"
|
||||
#include"params.h"
|
||||
#include"solver.h"
|
||||
#include"filter_model_converter.h"
|
||||
#include"statistics.h"
|
||||
|
||||
namespace opt {
|
||||
|
||||
class context;
|
||||
|
||||
class maxsmt_solver {
|
||||
public:
|
||||
virtual ~maxsmt_solver() {}
|
||||
|
@ -44,8 +49,9 @@ namespace opt {
|
|||
//
|
||||
class maxsmt_solver_base : public maxsmt_solver {
|
||||
protected:
|
||||
ref<solver> m_s;
|
||||
solver& m_s;
|
||||
ast_manager& m;
|
||||
context& m_c;
|
||||
volatile bool m_cancel;
|
||||
expr_ref_vector m_soft;
|
||||
expr_ref_vector m_assertions;
|
||||
|
@ -53,55 +59,30 @@ namespace opt {
|
|||
rational m_lower;
|
||||
rational m_upper;
|
||||
model_ref m_model;
|
||||
ref<filter_model_converter> m_mc; // model converter to remove fresh variables
|
||||
svector<bool> m_assignment; // truth assignment to soft constraints
|
||||
params_ref m_params; // config
|
||||
bool m_enable_sls; // config
|
||||
bool m_enable_sat; // config
|
||||
bool m_sls_enabled;
|
||||
bool m_sat_enabled;
|
||||
struct is_bv;
|
||||
|
||||
public:
|
||||
maxsmt_solver_base(opt_solver* s, ast_manager& m, params_ref& p,
|
||||
vector<rational> const& ws, expr_ref_vector const& soft):
|
||||
m_s(s), m(m), m_cancel(false), m_soft(m),
|
||||
m_assertions(m),
|
||||
m_enable_sls(false), m_enable_sat(false),
|
||||
m_sls_enabled(false), m_sat_enabled(false) {
|
||||
m_s->get_model(m_model);
|
||||
SASSERT(m_model);
|
||||
updt_params(p);
|
||||
set_converter(s->mc_ref().get());
|
||||
init_soft(ws, soft);
|
||||
}
|
||||
maxsmt_solver_base(context& c, vector<rational> const& ws, expr_ref_vector const& soft);
|
||||
|
||||
virtual ~maxsmt_solver_base() {}
|
||||
virtual rational get_lower() const { return m_lower; }
|
||||
virtual rational get_upper() const { return m_upper; }
|
||||
virtual bool get_assignment(unsigned index) const { return m_assignment[index]; }
|
||||
virtual void set_cancel(bool f) { m_cancel = f; m_s->set_cancel(f); }
|
||||
virtual void collect_statistics(statistics& st) const {
|
||||
if (m_sls_enabled || m_sat_enabled) {
|
||||
m_s->collect_statistics(st);
|
||||
}
|
||||
}
|
||||
virtual void set_cancel(bool f) { m_cancel = f; s().set_cancel(f); }
|
||||
virtual void collect_statistics(statistics& st) const { }
|
||||
virtual void get_model(model_ref& mdl) { mdl = m_model.get(); }
|
||||
void set_model() { s().get_model(m_model); }
|
||||
virtual void updt_params(params_ref& p);
|
||||
virtual void init_soft(vector<rational> const& weights, expr_ref_vector const& soft);
|
||||
void add_hard(expr* e){ s().assert_expr(e); }
|
||||
solver& s() { return *m_s; }
|
||||
void set_converter(filter_model_converter* mc) { m_mc = mc; }
|
||||
solver& s() { return m_s; }
|
||||
void init();
|
||||
expr* mk_not(expr* e);
|
||||
bool probe_bv();
|
||||
void set_mus(bool f);
|
||||
void enable_bvsat();
|
||||
void enable_sls();
|
||||
app* mk_fresh_bool(char const* name);
|
||||
private:
|
||||
void enable_inc_bvsat();
|
||||
protected:
|
||||
void enable_sls(expr_ref_vector const& soft);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -110,32 +91,27 @@ namespace opt {
|
|||
*/
|
||||
|
||||
class maxsmt {
|
||||
ast_manager& m;
|
||||
ref<opt_solver> m_s;
|
||||
ast_manager& m;
|
||||
solver& m_s;
|
||||
context& m_c;
|
||||
scoped_ptr<maxsmt_solver> m_msolver;
|
||||
volatile bool m_cancel;
|
||||
expr_ref_vector m_soft_constraints;
|
||||
expr_ref_vector m_answer;
|
||||
vector<rational> m_weights;
|
||||
rational m_lower;
|
||||
rational m_upper;
|
||||
scoped_ptr<maxsmt_solver> m_msolver;
|
||||
symbol m_maxsat_engine;
|
||||
model_ref m_model;
|
||||
params_ref m_params;
|
||||
public:
|
||||
maxsmt(ast_manager& m): m(m), m_s(0), m_cancel(false), m_soft_constraints(m), m_answer(m) {}
|
||||
|
||||
lbool operator()(opt_solver* s);
|
||||
|
||||
maxsmt(context& c);
|
||||
lbool operator()(solver* s);
|
||||
void set_cancel(bool f);
|
||||
|
||||
void updt_params(params_ref& p);
|
||||
|
||||
void add(expr* f, rational const& w);
|
||||
unsigned size() const { return m_soft_constraints.size(); }
|
||||
expr* operator[](unsigned idx) const { return m_soft_constraints[idx]; }
|
||||
rational weight(unsigned idx) const { return m_weights[idx]; }
|
||||
|
||||
void commit_assignment();
|
||||
rational get_value() const;
|
||||
rational get_lower() const;
|
||||
|
@ -146,13 +122,9 @@ namespace opt {
|
|||
bool get_assignment(unsigned index) const;
|
||||
void display_answer(std::ostream& out) const;
|
||||
void collect_statistics(statistics& st) const;
|
||||
|
||||
private:
|
||||
|
||||
bool is_maxsat_problem(vector<rational> const& ws) const;
|
||||
|
||||
void verify_assignment();
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue