3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-18 11:58:31 +00:00

pb solver

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2013-11-18 05:10:30 -08:00
parent 9734bab205
commit c42f0d60e6
2 changed files with 35 additions and 21 deletions

View file

@ -399,7 +399,7 @@ namespace smt {
} }
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 conflicts", m_stats.m_num_conflicts);
st.update("pb propagations", m_stats.m_num_propagations); st.update("pb propagations", m_stats.m_num_propagations);
st.update("pb predicates", m_stats.m_num_predicates); st.update("pb predicates", m_stats.m_num_predicates);
st.update("pb compilations", m_stats.m_num_compiles); st.update("pb compilations", m_stats.m_num_compiles);
@ -911,7 +911,7 @@ namespace smt {
void theory_pb::add_clause(ineq& c, literal conseq, literal_vector const& lits) { void theory_pb::add_clause(ineq& c, literal conseq, literal_vector const& lits) {
inc_propagations(c); inc_propagations(c);
m_stats.m_num_axioms++; m_stats.m_num_conflicts++;
context& ctx = get_context(); context& ctx = get_context();
TRACE("card", tout << "#prop:" << c.m_num_propagations << " - "; TRACE("card", tout << "#prop:" << c.m_num_propagations << " - ";
for (unsigned i = 0; i < lits.size(); ++i) { for (unsigned i = 0; i < lits.size(); ++i) {
@ -920,9 +920,11 @@ namespace smt {
tout << "\n"; tout << "\n";
display(tout, c);); display(tout, c););
DEBUG_CODE(
IF_VERBOSE(0, verbose_stream() << s_debug_conflict << "\n";);
if (s_debug_conflict) { if (s_debug_conflict) {
resolve_conflict(conseq, c); 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(),
@ -936,15 +938,21 @@ 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 (!ctx.is_marked(v) && lvl > ctx.get_base_level()) { IF_VERBOSE(0, verbose_stream() << "ante: " << l << "*" << coeff << " " << lvl << "\n";);
IF_VERBOSE(0, verbose_stream() << l << "*" << coeff << " marked. lvl: " << lvl << "\n";); if (lvl > ctx.get_base_level()) {
if (!ctx.is_marked(v)) {
ctx.set_mark(v); ctx.set_mark(v);
m_unmark.push_back(v); m_unmark.push_back(v);
if (lvl == m_conflict_lvl) { if (lvl == m_conflict_lvl) {
IF_VERBOSE(0, verbose_stream() << "new mark\n";);
++m_num_marks; ++m_num_marks;
} }
}
m_lemma.m_args.push_back(std::make_pair(l, coeff)); m_lemma.m_args.push_back(std::make_pair(l, coeff));
} }
else if (ctx.get_assignment(l) == l_true) {
m_lemma.m_k += coeff;
}
} }
void theory_pb::process_ineq(ineq& c) { void theory_pb::process_ineq(ineq& c) {
@ -953,8 +961,10 @@ namespace smt {
// assigned below current index 'idx'. // assigned below current index 'idx'.
context& ctx = get_context(); context& ctx = get_context();
for (unsigned i = 0; i < c.size(); ++i) { for (unsigned i = 0; i < c.size(); ++i) {
if (ctx.get_assignment(c.lit(i)) != l_undef) {
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(); m_lemma.m_k += c.k();
} }
@ -964,13 +974,15 @@ namespace smt {
// //
void theory_pb::resolve_conflict(literal conseq, ineq& c) { void theory_pb::resolve_conflict(literal conseq, ineq& c) {
IF_VERBOSE(0, display(verbose_stream(), c););
bool_var v; bool_var v;
context& ctx = get_context(); context& ctx = get_context();
unsigned& lvl = m_conflict_lvl = ctx.get_assign_level(c.lit()); unsigned& lvl = m_conflict_lvl = ctx.get_assign_level(c.lit());
for (unsigned i = 0; i < c.size(); ++i) { for (unsigned i = 0; i < c.size(); ++i) {
IF_VERBOSE(0, verbose_stream() << "conflict level: " << m_conflict_lvl << "\n";);
v = c.lit(i).var(); v = c.lit(i).var();
if (ctx.get_assignment(v) != l_undef) { if (ctx.get_assignment(v) != l_undef) {
IF_VERBOSE(0, verbose_stream() << c.lit(i) << " " << ctx.get_assign_level(v) << "\n";);
lvl = std::max(lvl, ctx.get_assign_level(v)); lvl = std::max(lvl, ctx.get_assign_level(v));
} }
} }
@ -994,15 +1006,17 @@ namespace smt {
// //
// Resolve selected conseq with antecedents. // Resolve selected conseq with antecedents.
// //
IF_VERBOSE(0, verbose_stream() << conseq << " " << js.get_kind() << "\n";);
switch(js.get_kind()) { switch(js.get_kind()) {
case b_justification::CLAUSE: { case b_justification::CLAUSE: {
clause* cls = js.get_clause(); clause& cls = *js.get_clause();
unsigned num_lits = cls->get_num_literals(); unsigned num_lits = cls.get_num_literals();
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; m_lemma.m_k += 1;
justification* cjs = cls->get_justification(); justification* cjs = cls.get_justification();
if (cjs) { if (cjs) {
// TBD // TBD
NOT_IMPLEMENTED_YET(); NOT_IMPLEMENTED_YET();
@ -1011,7 +1025,7 @@ namespace smt {
} }
case b_justification::BIN_CLAUSE: case b_justification::BIN_CLAUSE:
m_lemma.m_k += 1; m_lemma.m_k += 1;
process_antecedent(~js.get_literal(), 0); process_antecedent(conseq, 1);
process_antecedent(~js.get_literal(), 1); process_antecedent(~js.get_literal(), 1);
break; break;
case b_justification::AXIOM: case b_justification::AXIOM:

View file

@ -33,7 +33,7 @@ namespace smt {
typedef svector<std::pair<literal, numeral> > arg_t; typedef svector<std::pair<literal, numeral> > arg_t;
struct stats { struct stats {
unsigned m_num_axioms; unsigned m_num_conflicts;
unsigned m_num_propagations; unsigned m_num_propagations;
unsigned m_num_predicates; unsigned m_num_predicates;
unsigned m_num_compiles; unsigned m_num_compiles;