mirror of
https://github.com/Z3Prover/z3
synced 2025-04-15 13:28:47 +00:00
maxres revised to handle weighted constraints
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
bf35a62da7
commit
5e9bf2ef53
|
@ -12,62 +12,79 @@
|
||||||
using namespace opt;
|
using namespace opt;
|
||||||
|
|
||||||
struct maxres::imp {
|
struct maxres::imp {
|
||||||
ast_manager& m;
|
struct info {
|
||||||
solver& s;
|
app* m_cls;
|
||||||
expr_ref_vector m_B;
|
rational m_weight;
|
||||||
expr_ref_vector m_D;
|
info(app* cls, rational const& w):
|
||||||
expr_ref_vector m_asms;
|
m_cls(cls), m_weight(w) {}
|
||||||
app_ref_vector m_clss;
|
info(): m_cls(0) {}
|
||||||
model_ref m_model;
|
};
|
||||||
expr_ref_vector m_soft_constraints;
|
ast_manager& m;
|
||||||
volatile bool m_cancel;
|
solver& s;
|
||||||
rational m_lower;
|
expr_ref_vector m_B;
|
||||||
rational m_upper;
|
expr_ref_vector m_D;
|
||||||
obj_map<expr, app*> m_asm2cls;
|
expr_ref_vector m_asms;
|
||||||
|
model_ref m_model;
|
||||||
|
expr_ref_vector m_soft_constraints;
|
||||||
|
volatile bool m_cancel;
|
||||||
|
rational m_lower;
|
||||||
|
rational m_upper;
|
||||||
|
obj_map<expr, info> m_asm2info;
|
||||||
|
ptr_vector<expr> m_new_core;
|
||||||
|
mus m_mus;
|
||||||
|
expr_ref_vector m_trail;
|
||||||
|
|
||||||
imp(ast_manager& m, solver& s, expr_ref_vector& soft_constraints):
|
imp(ast_manager& m, solver& s, expr_ref_vector& soft_constraints, vector<rational> const& weights):
|
||||||
m(m), s(s), m_B(m), m_D(m), m_asms(m), m_clss(m), m_soft_constraints(soft_constraints),
|
m(m), s(s), m_B(m), m_D(m), m_asms(m), m_soft_constraints(m),
|
||||||
m_cancel(false)
|
m_cancel(false),
|
||||||
|
m_mus(s, m),
|
||||||
|
m_trail(m)
|
||||||
{
|
{
|
||||||
|
// TBD: this introduces an assertion to solver.
|
||||||
|
init_soft(weights, soft_constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_literal(expr* l) {
|
bool is_literal(expr* l) {
|
||||||
return
|
return
|
||||||
is_uninterp_const(l) ||
|
is_uninterp_const(l) ||
|
||||||
m.is_not(l, l) && is_uninterp_const(l);
|
(m.is_not(l, l) && is_uninterp_const(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_soft(expr* e) {
|
void add_soft(expr* e, rational const& w) {
|
||||||
TRACE("opt", tout << mk_pp(e, m) << "\n";);
|
TRACE("opt", tout << mk_pp(e, m) << "\n";);
|
||||||
expr_ref asum(m), fml(m);
|
expr_ref asum(m), fml(m);
|
||||||
app_ref cls(m);
|
app_ref cls(m);
|
||||||
cls = mk_cls(e);
|
cls = mk_cls(e);
|
||||||
m_clss.push_back(cls);
|
m_trail.push_back(cls);
|
||||||
if (is_literal(e)) {
|
if (is_literal(e)) {
|
||||||
m_asms.push_back(e);
|
asum = e;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
asum = m.mk_fresh_const("soft", m.mk_bool_sort());
|
asum = m.mk_fresh_const("soft", m.mk_bool_sort());
|
||||||
fml = m.mk_iff(asum, e);
|
fml = m.mk_iff(asum, e);
|
||||||
s.assert_expr(fml);
|
s.assert_expr(fml);
|
||||||
m_asms.push_back(asum);
|
|
||||||
}
|
}
|
||||||
m_asm2cls.insert(m_asms.back(), cls.get());
|
new_assumption(asum, cls, w);
|
||||||
|
m_upper += w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void new_assumption(expr* e, app* cls, rational const& w) {
|
||||||
|
info inf(cls, w);
|
||||||
|
m_asm2info.insert(e, inf);
|
||||||
|
m_asms.push_back(e);
|
||||||
|
m_trail.push_back(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
lbool operator()() {
|
lbool operator()() {
|
||||||
expr_ref fml(m);
|
expr_ref fml(m);
|
||||||
ptr_vector<expr> core, new_core;
|
ptr_vector<expr> core;
|
||||||
solver::scoped_push _sc(s);
|
solver::scoped_push _sc(s);
|
||||||
for (unsigned i = 0; i < m_soft_constraints.size(); ++i) {
|
|
||||||
add_soft(m_soft_constraints[i].get());
|
|
||||||
}
|
|
||||||
m_upper = rational(m_soft_constraints.size());
|
|
||||||
while (true) {
|
while (true) {
|
||||||
TRACE("opt",
|
TRACE("opt",
|
||||||
display_vec(tout, m_asms.size(), m_asms.c_ptr());
|
display_vec(tout, m_asms.size(), m_asms.c_ptr());
|
||||||
s.display(tout);
|
s.display(tout);
|
||||||
tout << "\n";
|
tout << "\n";
|
||||||
|
display(tout);
|
||||||
);
|
);
|
||||||
lbool is_sat = s.check_sat(m_asms.size(), m_asms.c_ptr());
|
lbool is_sat = s.check_sat(m_asms.size(), m_asms.c_ptr());
|
||||||
if (m_cancel) {
|
if (m_cancel) {
|
||||||
|
@ -85,37 +102,21 @@ struct maxres::imp {
|
||||||
s.get_unsat_core(core);
|
s.get_unsat_core(core);
|
||||||
TRACE("opt", display_vec(tout << "core: ", core.size(), core.c_ptr()););
|
TRACE("opt", display_vec(tout << "core: ", core.size(), core.c_ptr()););
|
||||||
SASSERT(!core.empty());
|
SASSERT(!core.empty());
|
||||||
|
is_sat = minimize_core(core);
|
||||||
|
SASSERT(!core.empty());
|
||||||
if (core.empty()) {
|
if (core.empty()) {
|
||||||
return l_false;
|
return l_false;
|
||||||
}
|
}
|
||||||
#if 1
|
|
||||||
// minimize core:
|
|
||||||
mus ms(s, m);
|
|
||||||
for (unsigned i = 0; i < core.size(); ++i) {
|
|
||||||
app* cls = 0;
|
|
||||||
VERIFY(m_asm2cls.find(core[i], cls));
|
|
||||||
SASSERT(cls);
|
|
||||||
SASSERT(m.is_or(cls));
|
|
||||||
ms.add_soft(core[i], cls->get_num_args(), cls->get_args());
|
|
||||||
}
|
|
||||||
unsigned_vector mus_idx;
|
|
||||||
is_sat = ms.get_mus(mus_idx);
|
|
||||||
if (is_sat != l_true) {
|
if (is_sat != l_true) {
|
||||||
return is_sat;
|
return is_sat;
|
||||||
}
|
}
|
||||||
new_core.reset();
|
remove_core(core);
|
||||||
for (unsigned i = 0; i < mus_idx.size(); ++i) {
|
rational w = split_core(core);
|
||||||
new_core.push_back(core[mus_idx[i]]);
|
|
||||||
}
|
|
||||||
core.reset();
|
|
||||||
core.append(new_core);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
TRACE("opt", display_vec(tout << "minimized core: ", core.size(), core.c_ptr()););
|
TRACE("opt", display_vec(tout << "minimized core: ", core.size(), core.c_ptr()););
|
||||||
max_resolve(core);
|
max_resolve(core, w);
|
||||||
fml = m.mk_not(m.mk_and(m_B.size(), m_B.c_ptr()));
|
fml = m.mk_not(m.mk_and(m_B.size(), m_B.c_ptr()));
|
||||||
s.assert_expr(fml);
|
s.assert_expr(fml);
|
||||||
m_lower += rational::one();
|
m_lower += w;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
IF_VERBOSE(1, verbose_stream() << "(opt.max_res lower: " << m_lower << ")\n";);
|
IF_VERBOSE(1, verbose_stream() << "(opt.max_res lower: " << m_lower << ")\n";);
|
||||||
|
@ -123,6 +124,57 @@ struct maxres::imp {
|
||||||
return l_true;
|
return l_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lbool minimize_core(ptr_vector<expr>& core) {
|
||||||
|
m_mus.reset();
|
||||||
|
for (unsigned i = 0; i < core.size(); ++i) {
|
||||||
|
app* cls = get_clause(core[i]);
|
||||||
|
SASSERT(cls);
|
||||||
|
SASSERT(m.is_or(cls));
|
||||||
|
m_mus.add_soft(core[i], cls->get_num_args(), cls->get_args());
|
||||||
|
}
|
||||||
|
unsigned_vector mus_idx;
|
||||||
|
lbool is_sat = m_mus.get_mus(mus_idx);
|
||||||
|
if (is_sat != l_true) {
|
||||||
|
return is_sat;
|
||||||
|
}
|
||||||
|
m_new_core.reset();
|
||||||
|
for (unsigned i = 0; i < mus_idx.size(); ++i) {
|
||||||
|
m_new_core.push_back(core[mus_idx[i]]);
|
||||||
|
}
|
||||||
|
core.reset();
|
||||||
|
core.append(m_new_core);
|
||||||
|
return l_true;
|
||||||
|
}
|
||||||
|
|
||||||
|
rational get_weight(expr* e) {
|
||||||
|
return m_asm2info.find(e).m_weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
app* get_clause(expr* e) {
|
||||||
|
return m_asm2info.find(e).m_cls;
|
||||||
|
}
|
||||||
|
|
||||||
|
rational split_core(ptr_vector<expr> const& core) {
|
||||||
|
|
||||||
|
// find the minimal weight:
|
||||||
|
SASSERT(!core.empty());
|
||||||
|
rational w = get_weight(core[0]);
|
||||||
|
for (unsigned i = 1; i < core.size(); ++i) {
|
||||||
|
rational w2 = get_weight(core[i]);
|
||||||
|
if (w2 < w) {
|
||||||
|
w = w2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// add fresh soft clauses for weights that are above w.
|
||||||
|
for (unsigned i = 0; i < core.size(); ++i) {
|
||||||
|
rational w2 = get_weight(core[i]);
|
||||||
|
if (w2 > w) {
|
||||||
|
new_assumption(core[i], get_clause(core[i]), w2 - w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
void display_vec(std::ostream& out, unsigned sz, expr* const* args) {
|
void display_vec(std::ostream& out, unsigned sz, expr* const* args) {
|
||||||
for (unsigned i = 0; i < sz; ++i) {
|
for (unsigned i = 0; i < sz; ++i) {
|
||||||
out << mk_pp(args[i], m) << " ";
|
out << mk_pp(args[i], m) << " ";
|
||||||
|
@ -130,7 +182,14 @@ struct maxres::imp {
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void max_resolve(ptr_vector<expr>& core) {
|
void display(std::ostream& out) {
|
||||||
|
for (unsigned i = 0; i < m_asms.size(); ++i) {
|
||||||
|
expr* a = m_asms[i].get();
|
||||||
|
out << mk_pp(a, m) << " : " << get_weight(a) << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void max_resolve(ptr_vector<expr>& core, rational const& w) {
|
||||||
SASSERT(!core.empty());
|
SASSERT(!core.empty());
|
||||||
expr_ref fml(m), asum(m);
|
expr_ref fml(m), asum(m);
|
||||||
app_ref cls(m);
|
app_ref cls(m);
|
||||||
|
@ -144,7 +203,6 @@ struct maxres::imp {
|
||||||
// d_i := (!core_{i+1} or d_{i+1}) for i = 0...sz-2
|
// d_i := (!core_{i+1} or d_{i+1}) for i = 0...sz-2
|
||||||
// soft (!d_i or core_i)
|
// soft (!d_i or core_i)
|
||||||
//
|
//
|
||||||
remove_core(core);
|
|
||||||
for (unsigned i = core.size()-1; i > 0; ) {
|
for (unsigned i = core.size()-1; i > 0; ) {
|
||||||
--i;
|
--i;
|
||||||
expr* d_i1 = m_D[i+1].get();
|
expr* d_i1 = m_D[i+1].get();
|
||||||
|
@ -155,11 +213,10 @@ struct maxres::imp {
|
||||||
asum = m.mk_fresh_const("a", m.mk_bool_sort());
|
asum = m.mk_fresh_const("a", m.mk_bool_sort());
|
||||||
cls = m.mk_implies(d_i, b_i);
|
cls = m.mk_implies(d_i, b_i);
|
||||||
fml = m.mk_iff(asum, cls);
|
fml = m.mk_iff(asum, cls);
|
||||||
s.assert_expr(fml);
|
|
||||||
m_asms.push_back(asum);
|
|
||||||
cls = mk_cls(cls);
|
cls = mk_cls(cls);
|
||||||
m_clss.push_back(cls);
|
m_trail.push_back(cls);
|
||||||
m_asm2cls.insert(asum, cls);
|
new_assumption(asum, cls, w);
|
||||||
|
s.assert_expr(fml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,9 +256,7 @@ struct maxres::imp {
|
||||||
for (unsigned i = 0; i < m_asms.size(); ++i) {
|
for (unsigned i = 0; i < m_asms.size(); ++i) {
|
||||||
if (core.contains(m_asms[i].get())) {
|
if (core.contains(m_asms[i].get())) {
|
||||||
m_asms[i] = m_asms.back();
|
m_asms[i] = m_asms.back();
|
||||||
m_clss[i] = m_clss.back();
|
|
||||||
m_asms.pop_back();
|
m_asms.pop_back();
|
||||||
m_clss.pop_back();
|
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,11 +272,12 @@ struct maxres::imp {
|
||||||
|
|
||||||
bool get_assignment(unsigned index) const {
|
bool get_assignment(unsigned index) const {
|
||||||
expr_ref tmp(m);
|
expr_ref tmp(m);
|
||||||
m_model->eval(m_soft_constraints[index], tmp);
|
VERIFY(m_model->eval(m_soft_constraints[index], tmp));
|
||||||
return m.is_true(tmp);
|
return m.is_true(tmp);
|
||||||
}
|
}
|
||||||
void set_cancel(bool f) {
|
void set_cancel(bool f) {
|
||||||
m_cancel = f;
|
m_cancel = f;
|
||||||
|
m_mus.set_cancel(f);
|
||||||
}
|
}
|
||||||
void collect_statistics(statistics& st) const {
|
void collect_statistics(statistics& st) const {
|
||||||
}
|
}
|
||||||
|
@ -232,10 +288,22 @@ struct maxres::imp {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_soft(vector<rational> const& weights, expr_ref_vector const& soft) {
|
||||||
|
m_soft_constraints.reset();
|
||||||
|
m_upper.reset();
|
||||||
|
m_lower.reset();
|
||||||
|
m_asm2info.reset();
|
||||||
|
m_trail.reset();
|
||||||
|
m_soft_constraints.append(soft);
|
||||||
|
for (unsigned i = 0; i < m_soft_constraints.size(); ++i) {
|
||||||
|
add_soft(m_soft_constraints[i].get(), weights[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
maxres::maxres(ast_manager& m, solver& s, expr_ref_vector& soft_constraints) {
|
maxres::maxres(ast_manager& m, solver& s, expr_ref_vector& soft_constraints, vector<rational> const& weights) {
|
||||||
m_imp = alloc(imp, m, s, soft_constraints);
|
m_imp = alloc(imp, m, s, soft_constraints, weights);
|
||||||
}
|
}
|
||||||
|
|
||||||
maxres::~maxres() {
|
maxres::~maxres() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace opt {
|
||||||
struct imp;
|
struct imp;
|
||||||
imp* m_imp;
|
imp* m_imp;
|
||||||
public:
|
public:
|
||||||
maxres(ast_manager& m, solver& s, expr_ref_vector& soft_constraints);
|
maxres(ast_manager& m, solver& s, expr_ref_vector& soft_constraints, vector<rational>const& weights);
|
||||||
~maxres();
|
~maxres();
|
||||||
virtual lbool operator()();
|
virtual lbool operator()();
|
||||||
virtual rational get_lower() const;
|
virtual rational get_lower() const;
|
||||||
|
|
|
@ -39,16 +39,16 @@ namespace opt {
|
||||||
m_msolver = 0;
|
m_msolver = 0;
|
||||||
is_sat = m_s->check_sat(0, 0);
|
is_sat = m_s->check_sat(0, 0);
|
||||||
}
|
}
|
||||||
|
else if (m_maxsat_engine == symbol("maxres")) {
|
||||||
|
m_msolver = alloc(maxres, m, *m_s, m_soft_constraints, m_weights);
|
||||||
|
}
|
||||||
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, *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, m_s.get(), m_soft_constraints, m_weights);
|
m_msolver = alloc(wmaxsmt, m, m_s.get(), m_soft_constraints, m_weights);
|
||||||
}
|
}
|
||||||
else if (m_maxsat_engine == symbol("maxres")) {
|
|
||||||
m_msolver = alloc(maxres, m, *m_s, m_soft_constraints);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
m_msolver = alloc(fu_malik, m, *m_s, m_soft_constraints);
|
m_msolver = alloc(fu_malik, m, *m_s, m_soft_constraints);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,21 @@ struct mus::imp {
|
||||||
vector<smt::literal_vector> m_cls2lits;
|
vector<smt::literal_vector> m_cls2lits;
|
||||||
expr_ref_vector m_vars;
|
expr_ref_vector m_vars;
|
||||||
obj_map<expr, unsigned> m_var2idx;
|
obj_map<expr, unsigned> m_var2idx;
|
||||||
|
volatile bool m_cancel;
|
||||||
|
|
||||||
public:
|
imp(solver& s, ast_manager& m): s(s), m(m), m_cls2expr(m), m_vars(m), m_cancel(false) {}
|
||||||
imp(solver& s, ast_manager& m): s(s), m(m), m_cls2expr(m), m_vars(m) {}
|
|
||||||
|
void reset() {
|
||||||
|
m_cls2expr.reset();
|
||||||
|
m_expr2cls.reset();
|
||||||
|
m_cls2lits.reset();
|
||||||
|
m_vars.reset();
|
||||||
|
m_var2idx.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_cancel(bool f) {
|
||||||
|
m_cancel = f;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned add_var(expr* v) {
|
unsigned add_var(expr* v) {
|
||||||
unsigned idx = m_vars.size();
|
unsigned idx = m_vars.size();
|
||||||
|
@ -47,10 +59,16 @@ public:
|
||||||
m_cls2lits.push_back(lits);
|
m_cls2lits.push_back(lits);
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expr* mk_not(expr* e) {
|
||||||
|
if (m.is_not(e, e)) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
return m.mk_not(e);
|
||||||
|
}
|
||||||
|
|
||||||
lbool get_mus(unsigned_vector& mus) {
|
lbool get_mus(unsigned_vector& mus) {
|
||||||
TRACE("opt", tout << "\n";);
|
TRACE("opt", tout << "\n";);
|
||||||
solver::scoped_push _sc(s);
|
|
||||||
unsigned_vector core;
|
unsigned_vector core;
|
||||||
for (unsigned i = 0; i < m_cls2expr.size(); ++i) {
|
for (unsigned i = 0; i < m_cls2expr.size(); ++i) {
|
||||||
core.push_back(i);
|
core.push_back(i);
|
||||||
|
@ -61,12 +79,17 @@ public:
|
||||||
ptr_vector<expr> core_exprs;
|
ptr_vector<expr> core_exprs;
|
||||||
model.resize(m_vars.size());
|
model.resize(m_vars.size());
|
||||||
while (!core.empty()) {
|
while (!core.empty()) {
|
||||||
IF_VERBOSE(0, display_vec(tout << "core: ", core););
|
TRACE("opt",
|
||||||
|
display_vec(tout << "core: ", core);
|
||||||
|
display_vec(tout << "mus: ", mus);
|
||||||
|
display_vec(tout << "model: ", model);
|
||||||
|
);
|
||||||
|
IF_VERBOSE(1, verbose_stream() << "(opt.mus reducing core: " << core.size() << " new core: " << mus.size() << ")\n";);
|
||||||
unsigned cls_id = core.back();
|
unsigned cls_id = core.back();
|
||||||
core.pop_back();
|
core.pop_back();
|
||||||
expr* cls = m_cls2expr[cls_id].get();
|
expr* cls = m_cls2expr[cls_id].get();
|
||||||
expr_ref not_cls(m);
|
expr_ref not_cls(m);
|
||||||
not_cls = m.mk_not(cls);
|
not_cls = mk_not(cls);
|
||||||
unsigned sz = assumptions.size();
|
unsigned sz = assumptions.size();
|
||||||
assumptions.push_back(not_cls);
|
assumptions.push_back(not_cls);
|
||||||
add_core(core, assumptions);
|
add_core(core, assumptions);
|
||||||
|
@ -113,7 +136,7 @@ public:
|
||||||
template<class T>
|
template<class T>
|
||||||
void display_vec(std::ostream& out, T const& v) const {
|
void display_vec(std::ostream& out, T const& v) const {
|
||||||
for (unsigned i = 0; i < v.size(); ++i) {
|
for (unsigned i = 0; i < v.size(); ++i) {
|
||||||
out << mk_pp(v[i], m) << " ";
|
out << v[i] << " ";
|
||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
@ -133,19 +156,18 @@ public:
|
||||||
*/
|
*/
|
||||||
void rmr(unsigned_vector& M, unsigned_vector& mus, svector<bool>& model) {
|
void rmr(unsigned_vector& M, unsigned_vector& mus, svector<bool>& model) {
|
||||||
TRACE("opt",
|
TRACE("opt",
|
||||||
display_vec(tout << "M:", M);
|
display_vec(tout << "core: ", M);
|
||||||
display_vec(tout << "mus:", mus);
|
display_vec(tout << "mus: ", mus);
|
||||||
display_vec(tout << "model:", model););
|
display_vec(tout << "model: ", model););
|
||||||
|
|
||||||
unsigned cls_id = mus.back();
|
unsigned cls_id = mus.back();
|
||||||
smt::literal_vector const& cls = m_cls2lits[cls_id];
|
smt::literal_vector const& cls = m_cls2lits[cls_id];
|
||||||
unsigned cls_id_new;
|
|
||||||
for (unsigned i = 0; i < cls.size(); ++i) {
|
for (unsigned i = 0; i < cls.size(); ++i) {
|
||||||
smt::literal lit = cls[i];
|
smt::literal lit = cls[i];
|
||||||
SASSERT(model[lit.var()] == lit.sign()); // literal evaluates to false.
|
SASSERT(model[lit.var()] == lit.sign()); // literal evaluates to false.
|
||||||
model[lit.var()] = !model[lit.var()]; // swap assignment
|
model[lit.var()] = !model[lit.var()]; // swap assignment
|
||||||
if (has_single_unsat(model, cls_id_new)) {
|
if (!mus.contains(cls_id) && has_single_unsat(model, cls_id)) {
|
||||||
mus.push_back(cls_id_new);
|
mus.push_back(cls_id);
|
||||||
rmr(M, mus, model);
|
rmr(M, mus, model);
|
||||||
}
|
}
|
||||||
model[lit.var()] = !model[lit.var()]; // swap assignment back
|
model[lit.var()] = !model[lit.var()]; // swap assignment back
|
||||||
|
@ -176,13 +198,6 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void display_vec(std::ostream& out, T const& v) {
|
|
||||||
for (unsigned i = 0; i < v.size(); ++i) {
|
|
||||||
out << v[i] << " ";
|
|
||||||
}
|
|
||||||
out << "\n";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mus::mus(solver& s, ast_manager& m) {
|
mus::mus(solver& s, ast_manager& m) {
|
||||||
|
@ -201,3 +216,10 @@ lbool mus::get_mus(unsigned_vector& mus) {
|
||||||
return m_imp->get_mus(mus);
|
return m_imp->get_mus(mus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mus::set_cancel(bool f) {
|
||||||
|
m_imp->set_cancel(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mus::reset() {
|
||||||
|
m_imp->reset();
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,10 @@ namespace opt {
|
||||||
unsigned add_soft(expr* cls, unsigned sz, expr* const* args);
|
unsigned add_soft(expr* cls, unsigned sz, expr* const* args);
|
||||||
|
|
||||||
lbool get_mus(unsigned_vector& mus);
|
lbool get_mus(unsigned_vector& mus);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void set_cancel(bool f);
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue