mirror of
https://github.com/Z3Prover/z3
synced 2025-06-23 14:23:40 +00:00
working on card
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
d68cb5aee7
commit
904f87feac
3 changed files with 45 additions and 19 deletions
|
@ -3719,6 +3719,9 @@ namespace smt {
|
||||||
svector<bool> expr_signs;
|
svector<bool> expr_signs;
|
||||||
for (unsigned i = 0; i < num_lits; i++) {
|
for (unsigned i = 0; i < num_lits; i++) {
|
||||||
literal l = lits[i];
|
literal l = lits[i];
|
||||||
|
if (get_assignment(l) != l_false) {
|
||||||
|
std::cout << l << " " << get_assignment(l) << "\n";
|
||||||
|
}
|
||||||
SASSERT(get_assignment(l) == l_false);
|
SASSERT(get_assignment(l) == l_false);
|
||||||
expr_lits.push_back(bool_var2expr(l.var()));
|
expr_lits.push_back(bool_var2expr(l.var()));
|
||||||
expr_signs.push_back(l.sign());
|
expr_signs.push_back(l.sign());
|
||||||
|
|
|
@ -236,6 +236,7 @@ namespace smt {
|
||||||
m_args[i].neg();
|
m_args[i].neg();
|
||||||
}
|
}
|
||||||
m_bound = sz - m_bound + 1;
|
m_bound = sz - m_bound + 1;
|
||||||
|
SASSERT(m_bound > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
lbool theory_pb::card::assign(theory_pb& th, literal lit) {
|
lbool theory_pb::card::assign(theory_pb& th, literal lit) {
|
||||||
|
@ -259,6 +260,10 @@ namespace smt {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (index == m_bound + 1) {
|
||||||
|
// literal is no longer watched.
|
||||||
|
return l_undef;
|
||||||
|
}
|
||||||
SASSERT(index <= m_bound);
|
SASSERT(index <= m_bound);
|
||||||
SASSERT(m_args[index] == lit);
|
SASSERT(m_args[index] == lit);
|
||||||
|
|
||||||
|
@ -401,7 +406,9 @@ namespace smt {
|
||||||
}
|
}
|
||||||
else if (j == m_bound) {
|
else if (j == m_bound) {
|
||||||
literal_vector lits(size() - m_bound, m_args.c_ptr() + m_bound);
|
literal_vector lits(size() - m_bound, m_args.c_ptr() + m_bound);
|
||||||
for (i = 0; i < j; ++i) {
|
th.negate(lits);
|
||||||
|
lits.push_back(lit());
|
||||||
|
for (i = 0; i < m_bound; ++i) {
|
||||||
if (ctx.get_assignment(lit(i)) == l_undef) {
|
if (ctx.get_assignment(lit(i)) == l_undef) {
|
||||||
th.add_assign(*this, lits, lit(i));
|
th.add_assign(*this, lits, lit(i));
|
||||||
}
|
}
|
||||||
|
@ -473,9 +480,9 @@ namespace smt {
|
||||||
m_stats.m_num_predicates++;
|
m_stats.m_num_predicates++;
|
||||||
|
|
||||||
if (m_util.is_aux_bool(atom)) {
|
if (m_util.is_aux_bool(atom)) {
|
||||||
std::cout << "aux bool\n";
|
|
||||||
bool_var abv = ctx.mk_bool_var(atom);
|
bool_var abv = ctx.mk_bool_var(atom);
|
||||||
ctx.set_var_theory(abv, get_id());
|
ctx.set_var_theory(abv, get_id());
|
||||||
|
// std::cout << "aux bool " << ctx.get_scope_level() << " " << mk_pp(atom, get_manager()) << " " << literal(abv) << "\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -909,6 +916,7 @@ namespace smt {
|
||||||
m_stats.m_num_propagations++;
|
m_stats.m_num_propagations++;
|
||||||
context& ctx = get_context();
|
context& ctx = get_context();
|
||||||
TRACE("pb", tout << "#prop: " << c.num_propagations() << " - " << lits << " " << c.lit() << " => " << l << "\n";);
|
TRACE("pb", tout << "#prop: " << c.num_propagations() << " - " << lits << " " << c.lit() << " => " << l << "\n";);
|
||||||
|
SASSERT(validate_antecedents(lits));
|
||||||
ctx.assign(l, ctx.mk_justification(
|
ctx.assign(l, ctx.mk_justification(
|
||||||
card_justification(
|
card_justification(
|
||||||
c, get_id(), ctx.get_region(), lits.size(), lits.c_ptr(), l)));
|
c, get_id(), ctx.get_region(), lits.size(), lits.c_ptr(), l)));
|
||||||
|
@ -1528,9 +1536,6 @@ namespace smt {
|
||||||
}
|
}
|
||||||
|
|
||||||
m_card_lim.resize(new_lim);
|
m_card_lim.resize(new_lim);
|
||||||
|
|
||||||
add_cardinality_lemma();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void theory_pb::clear_watch(ineq& c) {
|
void theory_pb::clear_watch(ineq& c) {
|
||||||
|
@ -1619,6 +1624,7 @@ namespace smt {
|
||||||
tout << " => " << l << "\n";
|
tout << " => " << l << "\n";
|
||||||
display(tout, c, true););
|
display(tout, c, true););
|
||||||
|
|
||||||
|
SASSERT(validate_antecedents(lits));
|
||||||
ctx.assign(l, ctx.mk_justification(
|
ctx.assign(l, ctx.mk_justification(
|
||||||
pb_justification(
|
pb_justification(
|
||||||
c, get_id(), ctx.get_region(), lits.size(), lits.c_ptr(), l)));
|
c, get_id(), ctx.get_region(), lits.size(), lits.c_ptr(), l)));
|
||||||
|
@ -1672,7 +1678,7 @@ namespace smt {
|
||||||
|
|
||||||
void theory_pb::process_card(card& c, int offset) {
|
void theory_pb::process_card(card& c, int offset) {
|
||||||
context& ctx = get_context();
|
context& ctx = get_context();
|
||||||
process_antecedent(c.lit(0), offset);
|
inc_coeff(c.lit(0), offset);
|
||||||
for (unsigned i = c.k() + 1; i < c.size(); ++i) {
|
for (unsigned i = c.k() + 1; i < c.size(); ++i) {
|
||||||
process_antecedent(c.lit(i), offset);
|
process_antecedent(c.lit(i), offset);
|
||||||
}
|
}
|
||||||
|
@ -1893,7 +1899,10 @@ namespace smt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void theory_pb::add_cardinality_lemma() {
|
bool theory_pb::can_propagate() { return m_card_reinit; }
|
||||||
|
|
||||||
|
|
||||||
|
void theory_pb::propagate() {
|
||||||
context& ctx = get_context();
|
context& ctx = get_context();
|
||||||
ast_manager& m = get_manager();
|
ast_manager& m = get_manager();
|
||||||
if (ctx.inconsistent() || !m_card_reinit) {
|
if (ctx.inconsistent() || !m_card_reinit) {
|
||||||
|
@ -1901,11 +1910,15 @@ namespace smt {
|
||||||
}
|
}
|
||||||
m_card_reinit = false;
|
m_card_reinit = false;
|
||||||
|
|
||||||
|
if (!validate_antecedents(m_antecedents)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pb_util pb(m);
|
pb_util pb(m);
|
||||||
expr_ref pred(pb.mk_fresh_bool(), m);
|
expr_ref pred(pb.mk_fresh_bool(), m);
|
||||||
bool_var abv = ctx.mk_bool_var(pred);
|
bool_var abv = ctx.mk_bool_var(pred);
|
||||||
ctx.set_var_theory(abv, get_id());
|
ctx.set_var_theory(abv, get_id());
|
||||||
literal lit(abv);
|
literal lit(abv);
|
||||||
|
// std::cout << "fresh " << pred << " " << lit << "\n";
|
||||||
|
|
||||||
card* c = alloc(card, lit, m_bound);
|
card* c = alloc(card, lit, m_bound);
|
||||||
for (unsigned i = 0; i < m_active_coeffs.size(); ++i) {
|
for (unsigned i = 0; i < m_active_coeffs.size(); ++i) {
|
||||||
|
@ -1967,7 +1980,6 @@ namespace smt {
|
||||||
b_justification js;
|
b_justification js;
|
||||||
literal conseq = ~confl[2];
|
literal conseq = ~confl[2];
|
||||||
|
|
||||||
|
|
||||||
while (m_num_marks > 0) {
|
while (m_num_marks > 0) {
|
||||||
|
|
||||||
v = conseq.var();
|
v = conseq.var();
|
||||||
|
@ -2112,6 +2124,7 @@ namespace smt {
|
||||||
--slack;
|
--slack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SASSERT(validate_antecedents(m_antecedents));
|
||||||
ctx.assign(prop_lit, ctx.mk_justification(theory_propagation_justification(get_id(), ctx.get_region(), m_antecedents.size(), m_antecedents.c_ptr(), prop_lit, 0, 0)));
|
ctx.assign(prop_lit, ctx.mk_justification(theory_propagation_justification(get_id(), ctx.get_region(), m_antecedents.size(), m_antecedents.c_ptr(), prop_lit, 0, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2220,6 +2233,22 @@ namespace smt {
|
||||||
SASSERT(!c.is_eq() || (sum == c.k()) == (ctx.get_assignment(c.lit()) == l_true));
|
SASSERT(!c.is_eq() || (sum == c.k()) == (ctx.get_assignment(c.lit()) == l_true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool theory_pb::validate_antecedents(literal_vector const& lits) {
|
||||||
|
context& ctx = get_context();
|
||||||
|
for (unsigned i = 0; i < lits.size(); ++i) {
|
||||||
|
if (ctx.get_assignment(lits[i]) != l_true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void theory_pb::negate(literal_vector & lits) {
|
||||||
|
for (unsigned i = 0; i < lits.size(); ++i) {
|
||||||
|
lits[i].neg();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// display methods
|
// display methods
|
||||||
|
|
||||||
void theory_pb::display_resolved_lemma(std::ostream& out) const {
|
void theory_pb::display_resolved_lemma(std::ostream& out) const {
|
||||||
|
|
|
@ -201,6 +201,7 @@ namespace smt {
|
||||||
m_compilation_threshold(0),
|
m_compilation_threshold(0),
|
||||||
m_compiled(l_false)
|
m_compiled(l_false)
|
||||||
{
|
{
|
||||||
|
SASSERT(bound > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
literal lit() const { return m_lit; }
|
literal lit() const { return m_lit; }
|
||||||
|
@ -270,16 +271,6 @@ namespace smt {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct card_reinit {
|
|
||||||
literal_vector m_lits;
|
|
||||||
card* m_card;
|
|
||||||
|
|
||||||
card_reinit(literal_vector const& lits, card* c):
|
|
||||||
m_lits(lits),
|
|
||||||
m_card(c)
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
theory_pb_params m_params;
|
theory_pb_params m_params;
|
||||||
|
|
||||||
svector<var_info> m_var_infos;
|
svector<var_info> m_var_infos;
|
||||||
|
@ -393,7 +384,6 @@ namespace smt {
|
||||||
|
|
||||||
void reset_coeffs();
|
void reset_coeffs();
|
||||||
literal cardinality_reduction(literal propagation_lit);
|
literal cardinality_reduction(literal propagation_lit);
|
||||||
void add_cardinality_lemma();
|
|
||||||
|
|
||||||
bool resolve_conflict(card& c, literal_vector const& conflict_clause);
|
bool resolve_conflict(card& c, literal_vector const& conflict_clause);
|
||||||
void process_antecedent(literal l, int offset);
|
void process_antecedent(literal l, int offset);
|
||||||
|
@ -409,6 +399,8 @@ namespace smt {
|
||||||
void validate_final_check(ineq& c);
|
void validate_final_check(ineq& c);
|
||||||
void validate_assign(ineq const& c, literal_vector const& lits, literal l) const;
|
void validate_assign(ineq const& c, literal_vector const& lits, literal l) const;
|
||||||
void validate_watch(ineq const& c) const;
|
void validate_watch(ineq const& c) const;
|
||||||
|
bool validate_antecedents(literal_vector const& lits);
|
||||||
|
void negate(literal_vector & lits);
|
||||||
|
|
||||||
bool proofs_enabled() const { return get_manager().proofs_enabled(); }
|
bool proofs_enabled() const { return get_manager().proofs_enabled(); }
|
||||||
justification* justify(literal l1, literal l2);
|
justification* justify(literal l1, literal l2);
|
||||||
|
@ -437,6 +429,8 @@ namespace smt {
|
||||||
virtual model_value_proc * mk_value(enode * n, model_generator & mg);
|
virtual model_value_proc * mk_value(enode * n, model_generator & mg);
|
||||||
virtual void init_model(model_generator & m);
|
virtual void init_model(model_generator & m);
|
||||||
virtual bool include_func_interp(func_decl* f) { return false; }
|
virtual bool include_func_interp(func_decl* f) { return false; }
|
||||||
|
virtual bool can_propagate();
|
||||||
|
virtual void propagate();
|
||||||
|
|
||||||
static literal assert_ge(context& ctx, unsigned k, unsigned n, literal const* xs);
|
static literal assert_ge(context& ctx, unsigned k, unsigned n, literal const* xs);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue