3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-27 08:28:44 +00:00

pb theory

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2013-11-17 21:10:15 -08:00
parent 50cc852112
commit 9734bab205
3 changed files with 27 additions and 23 deletions

View file

@ -6,6 +6,7 @@ def_module_params('opt',
('maxsat_engine', SYMBOL, 'fu_malik', "select engine for non-weighted maxsat: 'fu_malik', 'core_maxsat'"), ('maxsat_engine', SYMBOL, 'fu_malik', "select engine for non-weighted maxsat: 'fu_malik', 'core_maxsat'"),
('pareto', BOOL, False, 'return a Pareto front (as opposed to a bounding box)'), ('pareto', BOOL, False, 'return a Pareto front (as opposed to a bounding box)'),
('dump_benchmarks', BOOL, False, 'dump benchmarks for profiling'), ('dump_benchmarks', BOOL, False, 'dump benchmarks for profiling'),
('debug_conflict', BOOL, False, 'debug conflict resolution'),
)) ))

View file

@ -26,6 +26,8 @@ Notes:
namespace smt { namespace smt {
bool theory_pb::s_debug_conflict = false; // true; //
void theory_pb::ineq::negate() { void theory_pb::ineq::negate() {
m_lit.neg(); m_lit.neg();
numeral sum = 0; numeral sum = 0;
@ -396,8 +398,6 @@ namespace smt {
ineqs->push_back(&c); ineqs->push_back(&c);
} }
void theory_pb::collect_statistics(::statistics& st) const { void theory_pb::collect_statistics(::statistics& st) const {
st.update("pb axioms", m_stats.m_num_axioms); st.update("pb axioms", m_stats.m_num_axioms);
st.update("pb propagations", m_stats.m_num_propagations); st.update("pb propagations", m_stats.m_num_propagations);
@ -920,7 +920,9 @@ namespace smt {
tout << "\n"; tout << "\n";
display(tout, c);); display(tout, c););
// DEBUG_CODE(resolve_conflict(conseq, c);); if (s_debug_conflict) {
resolve_conflict(conseq, c);
}
justification* js = 0; justification* js = 0;
ctx.mk_clause(lits.size(), lits.c_ptr(), js, CLS_AUX_LEMMA, 0); ctx.mk_clause(lits.size(), lits.c_ptr(), js, CLS_AUX_LEMMA, 0);
IF_VERBOSE(2, ctx.display_literals_verbose(verbose_stream(), IF_VERBOSE(2, ctx.display_literals_verbose(verbose_stream(),
@ -934,25 +936,27 @@ namespace smt {
context& ctx = get_context(); context& ctx = get_context();
bool_var v = l.var(); bool_var v = l.var();
unsigned lvl = ctx.get_assign_level(v); unsigned lvl = ctx.get_assign_level(v);
IF_VERBOSE(0, verbose_stream() << l << "*" << coeff << " marked: " << ctx.is_marked(v) << " lvl: " << lvl << "\n";);
if (!ctx.is_marked(v) && lvl > ctx.get_base_level()) { if (!ctx.is_marked(v) && lvl > ctx.get_base_level()) {
IF_VERBOSE(0, verbose_stream() << l << "*" << coeff << " marked. lvl: " << lvl << "\n";);
ctx.set_mark(v); ctx.set_mark(v);
m_unmark.push_back(v);
if (lvl == m_conflict_lvl) { if (lvl == m_conflict_lvl) {
++m_num_marks; ++m_num_marks;
} }
else { m_lemma.m_args.push_back(std::make_pair(l, coeff));
m_lemma.m_args.push_back(std::make_pair(l, coeff));
}
} }
} }
void theory_pb::process_ineq(ineq& c) { void theory_pb::process_ineq(ineq& c) {
// TBD: create CUT. // TBD: create CUT.
context& ctx = get_context(); // only process literals that were
// assigned below current index 'idx'.
context& ctx = get_context();
for (unsigned i = 0; i < c.size(); ++i) { for (unsigned i = 0; i < c.size(); ++i) {
process_antecedent(c.lit(i), c.coeff(i)); process_antecedent(c.lit(i), c.coeff(i));
} }
process_antecedent(~c.lit(), 1); process_antecedent(~c.lit(), 1);
m_lemma.m_k += c.k();
} }
// //
@ -984,7 +988,7 @@ namespace smt {
// point into stack of assigned literals // point into stack of assigned literals
literal_vector const& lits = ctx.assigned_literals(); literal_vector const& lits = ctx.assigned_literals();
SASSERT(!lits.empty()); SASSERT(!lits.empty());
unsigned idx = lits.size()-1; unsigned idx = lits.size()-1;
do { do {
// //
@ -997,6 +1001,7 @@ namespace smt {
for (unsigned i = 0; i < num_lits; ++i) { for (unsigned i = 0; i < num_lits; ++i) {
process_antecedent(cls->get_literal(i), 1); process_antecedent(cls->get_literal(i), 1);
} }
m_lemma.m_k += 1;
justification* cjs = cls->get_justification(); justification* cjs = cls->get_justification();
if (cjs) { if (cjs) {
// TBD // TBD
@ -1005,7 +1010,8 @@ namespace smt {
break; break;
} }
case b_justification::BIN_CLAUSE: case b_justification::BIN_CLAUSE:
SASSERT(conseq.var() != js.get_literal().var()); m_lemma.m_k += 1;
process_antecedent(~js.get_literal(), 0);
process_antecedent(~js.get_literal(), 1); process_antecedent(~js.get_literal(), 1);
break; break;
case b_justification::AXIOM: case b_justification::AXIOM:
@ -1025,8 +1031,8 @@ namespace smt {
// //
// find the next marked variable in the assignment stack // find the next marked variable in the assignment stack
// //
SASSERT(idx > 0); SASSERT(idx > 0);
SASSERT(m_num_marks > 0); SASSERT(m_num_marks > 0);
do { do {
conseq = lits[idx]; conseq = lits[idx];
v = conseq.var(); v = conseq.var();
@ -1036,19 +1042,15 @@ namespace smt {
js = ctx.get_justification(v); js = ctx.get_justification(v);
--m_num_marks; --m_num_marks;
ctx.unset_mark(v);
IF_VERBOSE(0, verbose_stream() << "unmark: " << v << "\n";);
} }
while (m_num_marks > 0); while (m_num_marks > 0);
// unset the marks on lemmas // unset the marks on lemmas
for (unsigned i = 0; i < m_lemma.size(); ++i) { while (!m_unmark.empty()) {
bool_var v = m_lemma.lit(i).var(); ctx.unset_mark(m_unmark.back());
if (ctx.is_marked(v)) { m_unmark.pop_back();
IF_VERBOSE(0, verbose_stream() << "unmark: " << v << "\n";); }
ctx.unset_mark(v);
}
}
TRACE("card", display(tout, m_lemma);); TRACE("card", display(tout, m_lemma););

View file

@ -140,6 +140,7 @@ namespace smt {
unsigned m_num_marks; unsigned m_num_marks;
unsigned m_conflict_lvl; unsigned m_conflict_lvl;
ineq m_lemma; ineq m_lemma;
svector<bool_var> m_unmark;
void resolve_conflict(literal conseq, ineq& c); void resolve_conflict(literal conseq, ineq& c);
void process_antecedent(literal l, numeral coeff); void process_antecedent(literal l, numeral coeff);
void process_ineq(ineq& c); void process_ineq(ineq& c);
@ -165,6 +166,6 @@ namespace smt {
virtual void restart_eh(); virtual void restart_eh();
virtual void collect_statistics(::statistics & st) const; virtual void collect_statistics(::statistics & st) const;
static bool s_debug_conflict;
}; };
}; };