3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 13:28:47 +00:00

refactor weighted maxsmt

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2014-04-14 16:24:23 -07:00
parent 1db7e0a149
commit 00f45579cc
5 changed files with 940 additions and 796 deletions

View file

@ -27,29 +27,29 @@ Notes:
namespace opt { namespace opt {
lbool maxsmt::operator()(opt_solver& s) { lbool maxsmt::operator()(opt_solver* s) {
lbool is_sat; lbool is_sat;
m_msolver = 0; m_msolver = 0;
m_s = &s; m_s = s;
IF_VERBOSE(1, verbose_stream() << "(maxsmt)\n";); IF_VERBOSE(1, verbose_stream() << "(maxsmt)\n";);
if (m_soft_constraints.empty()) { if (m_soft_constraints.empty()) {
TRACE("opt", tout << "no constraints\n";); TRACE("opt", tout << "no constraints\n";);
m_msolver = 0; m_msolver = 0;
is_sat = s.check_sat(0, 0); is_sat = m_s->check_sat(0, 0);
} }
else if (is_maxsat_problem(m_weights)) { else if (is_maxsat_problem(m_weights)) {
if (m_maxsat_engine == symbol("core_maxsat")) { if (m_maxsat_engine == symbol("core_maxsat")) {
m_msolver = alloc(core_maxsat, m, s, m_soft_constraints); m_msolver = alloc(core_maxsat, m, *m_s, m_soft_constraints);
} }
else if (m_maxsat_engine == symbol("weighted_maxsat")) { else if (m_maxsat_engine == symbol("weighted_maxsat")) {
m_msolver = alloc(wmaxsmt, m, opt_solver::to_opt(s), m_soft_constraints, m_weights); m_msolver = alloc(wmaxsmt, m, m_s.get(), m_soft_constraints, m_weights);
} }
else { else {
m_msolver = alloc(fu_malik, m, s, m_soft_constraints); m_msolver = alloc(fu_malik, m, *m_s, m_soft_constraints);
} }
} }
else { else {
m_msolver = alloc(wmaxsmt, m, opt_solver::to_opt(s), m_soft_constraints, m_weights); m_msolver = alloc(wmaxsmt, m, m_s.get(), m_soft_constraints, m_weights);
} }
if (m_msolver) { if (m_msolver) {

View file

@ -44,7 +44,7 @@ namespace opt {
class maxsmt { class maxsmt {
ast_manager& m; ast_manager& m;
opt_solver* m_s; ref<opt_solver> m_s;
volatile bool m_cancel; volatile bool m_cancel;
expr_ref_vector m_soft_constraints; expr_ref_vector m_soft_constraints;
expr_ref_vector m_answer; expr_ref_vector m_answer;
@ -58,7 +58,7 @@ namespace opt {
public: public:
maxsmt(ast_manager& m): m(m), m_s(0), m_cancel(false), m_soft_constraints(m), m_answer(m) {} maxsmt(ast_manager& m): m(m), m_s(0), m_cancel(false), m_soft_constraints(m), m_answer(m) {}
lbool operator()(opt_solver& s); lbool operator()(opt_solver* s);
void set_cancel(bool f); void set_cancel(bool f);

View file

@ -194,7 +194,7 @@ namespace opt {
lbool context::execute_maxsat(symbol const& id, bool committed) { lbool context::execute_maxsat(symbol const& id, bool committed) {
model_ref tmp; model_ref tmp;
maxsmt& ms = *m_maxsmts.find(id); maxsmt& ms = *m_maxsmts.find(id);
lbool result = ms(get_solver()); lbool result = ms(m_solver.get());
if (result == l_true && committed) ms.commit_assignment(); if (result == l_true && committed) ms.commit_assignment();
if (result != l_false && (ms.get_model(tmp), tmp.get())) ms.get_model(m_model); if (result != l_false && (ms.get_model(tmp), tmp.get())) ms.get_model(m_model);
return result; return result;
@ -381,7 +381,7 @@ namespace opt {
params_ref lia_p; params_ref lia_p;
lia_p.set_bool("compile_equality", optp.pb_compile_equality()); lia_p.set_bool("compile_equality", optp.pb_compile_equality());
tac3->updt_params(lia_p); tac3->updt_params(lia_p);
m_simplify = and_then(tac0.get(), tac2.get(), tac3.get(), mk_nnf_tactic(m)); m_simplify = and_then(tac0.get(), tac2.get(), tac3.get());
} }
else { else {
m_simplify = tac0.get(); m_simplify = tac0.get();

File diff suppressed because it is too large Load diff

View file

@ -31,7 +31,10 @@ namespace opt {
struct imp; struct imp;
imp* m_imp; imp* m_imp;
public: public:
wmaxsmt(ast_manager& m, opt_solver& s, expr_ref_vector& soft_constraints, vector<rational> const& weights); wmaxsmt(ast_manager& m,
opt_solver* s,
expr_ref_vector& soft_constraints,
vector<rational> const& weights);
~wmaxsmt(); ~wmaxsmt();
virtual lbool operator()(); virtual lbool operator()();
virtual rational get_lower() const; virtual rational get_lower() const;