mirror of
https://github.com/Z3Prover/z3
synced 2025-06-06 06:03:23 +00:00
debugging
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
94416bea52
commit
6f4c873b29
9 changed files with 139 additions and 102 deletions
|
@ -281,106 +281,109 @@ namespace sat {
|
||||||
for (unsigned i = 0; i < num_watch; ++i) {
|
for (unsigned i = 0; i < num_watch; ++i) {
|
||||||
watch_literal(p, p[i]);
|
watch_literal(p, p[i]);
|
||||||
}
|
}
|
||||||
p.set_slack(slack);
|
p.set_slack(slack);
|
||||||
p.set_num_watch(num_watch);
|
p.set_num_watch(num_watch);
|
||||||
}
|
}
|
||||||
TRACE("sat", display(tout << "init watch: ", p, true););
|
TRACE("sat", display(tout << "init watch: ", p, true););
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Chai Kuhlmann:
|
Chai Kuhlmann:
|
||||||
Lw - set of watched literals
|
Lw - set of watched literals
|
||||||
Lu - set of unwatched literals that are not false
|
Lu - set of unwatched literals that are not false
|
||||||
|
|
||||||
Lw = Lw \ { alit }
|
|
||||||
Sw -= value
|
|
||||||
a_max = max { a | l in Lw u Lu, l = undef }
|
|
||||||
while (Sw < k + a_max & Lu != 0) {
|
|
||||||
a_s = max { a | l in Lu }
|
|
||||||
Sw += a_s
|
|
||||||
Lw = Lw u {l_s}
|
|
||||||
Lu = Lu \ {l_s}
|
|
||||||
}
|
|
||||||
if (Sw < k) conflict
|
|
||||||
while (Sw < k + a_max) {
|
|
||||||
assign (l_max)
|
|
||||||
a_max = max { ai | li in Lw, li = undef }
|
|
||||||
}
|
|
||||||
ASSERT(Sw >= bound)
|
|
||||||
return no-conflict
|
|
||||||
|
|
||||||
a_max index: index of non-false literal with maximal weight.
|
Lw = Lw \ { alit }
|
||||||
|
Sw -= value
|
||||||
|
a_max = max { a | l in Lw u Lu, l = undef }
|
||||||
*/
|
while (Sw < k + a_max & Lu != 0) {
|
||||||
void card_extension::add_index(pb& p, unsigned index, literal lit) {
|
a_s = max { a | l in Lu }
|
||||||
if (value(lit) == l_undef) {
|
Sw += a_s
|
||||||
m_pb_undef.push_back(index);
|
Lw = Lw u {l_s}
|
||||||
if (p[index].first > m_a_max) {
|
Lu = Lu \ {l_s}
|
||||||
m_a_max = p[index].first;
|
}
|
||||||
}
|
if (Sw < k) conflict
|
||||||
}
|
while (Sw < k + a_max) {
|
||||||
}
|
assign (l_max)
|
||||||
|
a_max = max { ai | li in Lw, li = undef }
|
||||||
|
}
|
||||||
|
ASSERT(Sw >= bound)
|
||||||
|
return no-conflict
|
||||||
|
|
||||||
lbool card_extension::add_assign(pb& p, literal alit) {
|
a_max index: index of non-false literal with maximal weight.
|
||||||
|
|
||||||
TRACE("sat", display(tout << "assign: " << alit << "\n", p, true););
|
|
||||||
SASSERT(!inconsistent());
|
|
||||||
unsigned sz = p.size();
|
|
||||||
unsigned bound = p.k();
|
|
||||||
unsigned num_watch = p.num_watch();
|
|
||||||
unsigned slack = p.slack();
|
|
||||||
SASSERT(value(alit) == l_false);
|
|
||||||
SASSERT(p.lit() == null_literal || value(p.lit()) == l_true);
|
|
||||||
SASSERT(num_watch <= sz);
|
|
||||||
SASSERT(num_watch > 0);
|
|
||||||
unsigned index = 0;
|
|
||||||
m_a_max = 0;
|
|
||||||
m_pb_undef.reset();
|
|
||||||
for (; index < num_watch; ++index) {
|
|
||||||
literal lit = p[index].second;
|
|
||||||
if (lit == alit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
add_index(p, index, lit);
|
|
||||||
}
|
|
||||||
SASSERT(index < num_watch);
|
|
||||||
|
|
||||||
unsigned index1 = index + 1;
|
*/
|
||||||
for (; m_a_max == 0 && index1 < num_watch; ++index1) {
|
void card_extension::add_index(pb& p, unsigned index, literal lit) {
|
||||||
add_index(p, index1, p[index1].second);
|
if (value(lit) == l_undef) {
|
||||||
}
|
m_pb_undef.push_back(index);
|
||||||
|
if (p[index].first > m_a_max) {
|
||||||
|
m_a_max = p[index].first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned val = p[index].first;
|
lbool card_extension::add_assign(pb& p, literal alit) {
|
||||||
SASSERT(value(p[index].second) == l_false);
|
|
||||||
SASSERT(val <= slack);
|
|
||||||
slack -= val;
|
|
||||||
// find literals to swap with:
|
|
||||||
for (unsigned j = num_watch; j < sz && slack < bound + m_a_max; ++j) {
|
|
||||||
literal lit = p[j].second;
|
|
||||||
if (value(lit) != l_false) {
|
|
||||||
slack += p[j].first;
|
|
||||||
watch_literal(p, p[j]);
|
|
||||||
p.swap(num_watch, j);
|
|
||||||
add_index(p, num_watch, lit);
|
|
||||||
++num_watch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SASSERT(!inconsistent());
|
TRACE("sat", display(tout << "assign: " << alit << "\n", p, true););
|
||||||
DEBUG_CODE(for (auto idx : m_pb_undef) { SASSERT(value(p[idx].second) == l_undef); });
|
SASSERT(!inconsistent());
|
||||||
|
unsigned sz = p.size();
|
||||||
|
unsigned bound = p.k();
|
||||||
|
unsigned num_watch = p.num_watch();
|
||||||
|
unsigned slack = p.slack();
|
||||||
|
SASSERT(value(alit) == l_false);
|
||||||
|
SASSERT(p.lit() == null_literal || value(p.lit()) == l_true);
|
||||||
|
SASSERT(num_watch <= sz);
|
||||||
|
SASSERT(num_watch > 0);
|
||||||
|
unsigned index = 0;
|
||||||
|
m_a_max = 0;
|
||||||
|
m_pb_undef.reset();
|
||||||
|
for (; index < num_watch; ++index) {
|
||||||
|
literal lit = p[index].second;
|
||||||
|
if (lit == alit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
add_index(p, index, lit);
|
||||||
|
}
|
||||||
|
SASSERT(index < num_watch);
|
||||||
|
|
||||||
if (slack < bound) {
|
unsigned index1 = index + 1;
|
||||||
// maintain watching the literal
|
for (; m_a_max == 0 && index1 < num_watch; ++index1) {
|
||||||
slack += val;
|
add_index(p, index1, p[index1].second);
|
||||||
p.set_slack(slack);
|
}
|
||||||
p.set_num_watch(num_watch);
|
|
||||||
SASSERT(bound <= slack);
|
|
||||||
TRACE("sat", tout << "conflict " << alit << "\n";);
|
|
||||||
set_conflict(p, alit);
|
|
||||||
return l_false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
unsigned val = p[index].first;
|
||||||
|
SASSERT(value(p[index].second) == l_false);
|
||||||
|
SASSERT(val <= slack);
|
||||||
|
slack -= val;
|
||||||
|
// find literals to swap with:
|
||||||
|
for (unsigned j = num_watch; j < sz && slack < bound + m_a_max; ++j) {
|
||||||
|
literal lit = p[j].second;
|
||||||
|
if (value(lit) != l_false) {
|
||||||
|
slack += p[j].first;
|
||||||
|
watch_literal(p, p[j]);
|
||||||
|
p.swap(num_watch, j);
|
||||||
|
add_index(p, num_watch, lit);
|
||||||
|
++num_watch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SASSERT(!inconsistent());
|
||||||
|
DEBUG_CODE(for (auto idx : m_pb_undef) { SASSERT(value(p[idx].second) == l_undef); });
|
||||||
|
|
||||||
|
if (slack < bound) {
|
||||||
|
// maintain watching the literal
|
||||||
|
slack += val;
|
||||||
|
p.set_slack(slack);
|
||||||
|
p.set_num_watch(num_watch);
|
||||||
|
SASSERT(bound <= slack);
|
||||||
|
TRACE("sat", tout << "conflict " << alit << "\n";);
|
||||||
|
set_conflict(p, alit);
|
||||||
|
return l_false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index > p.size() || num_watch > p.size()) {
|
||||||
|
std::cout << "size: " << p.size() << "index: " << index << " num watch: " << num_watch << "\n";
|
||||||
|
}
|
||||||
// swap out the watched literal.
|
// swap out the watched literal.
|
||||||
--num_watch;
|
--num_watch;
|
||||||
SASSERT(num_watch > 0);
|
SASSERT(num_watch > 0);
|
||||||
|
@ -1711,6 +1714,7 @@ namespace sat {
|
||||||
}
|
}
|
||||||
|
|
||||||
void card_extension::simplify() {
|
void card_extension::simplify() {
|
||||||
|
return;
|
||||||
s().pop_to_base_level();
|
s().pop_to_base_level();
|
||||||
unsigned trail_sz;
|
unsigned trail_sz;
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -1734,11 +1734,14 @@ namespace sat {
|
||||||
}
|
}
|
||||||
IF_VERBOSE(1, verbose_stream() << "(sat-lookahead :units " << num_units << ")\n";);
|
IF_VERBOSE(1, verbose_stream() << "(sat-lookahead :units " << num_units << ")\n";);
|
||||||
|
|
||||||
if (num_units > 0 && !m_s.inconsistent()) {
|
if (m_s.inconsistent()) return;
|
||||||
|
|
||||||
|
if (num_units > 0) {
|
||||||
m_s.propagate_core(false);
|
m_s.propagate_core(false);
|
||||||
m_s.m_simplifier(false);
|
m_s.m_simplifier(false);
|
||||||
}
|
}
|
||||||
m_lookahead.reset();
|
m_lookahead.reset();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -162,7 +162,7 @@ namespace sat {
|
||||||
for (unsigned i = 0; i < sz; ++i)
|
for (unsigned i = 0; i < sz; ++i)
|
||||||
e.m_clauses.push_back(c[i]);
|
e.m_clauses.push_back(c[i]);
|
||||||
e.m_clauses.push_back(null_literal);
|
e.m_clauses.push_back(null_literal);
|
||||||
TRACE("sat_mc_bug", tout << "adding (wrapper): "; for (literal l : c) tout << l << " "; tout << "\n";);
|
// TRACE("sat_mc_bug", tout << "adding (wrapper): "; for (literal l : c) tout << l << " "; tout << "\n";);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool model_converter::check_invariant(unsigned num_vars) const {
|
bool model_converter::check_invariant(unsigned num_vars) const {
|
||||||
|
|
|
@ -1415,10 +1415,16 @@ namespace sat {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_config.m_lookahead_simplify) {
|
if (m_config.m_lookahead_simplify) {
|
||||||
lookahead lh(*this);
|
{
|
||||||
lh.simplify();
|
lookahead lh(*this);
|
||||||
lh.scc();
|
lh.simplify();
|
||||||
lh.collect_statistics(m_aux_stats);
|
lh.collect_statistics(m_aux_stats);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
lookahead lh(*this);
|
||||||
|
lh.scc();
|
||||||
|
lh.collect_statistics(m_aux_stats);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort_watch_lits();
|
sort_watch_lits();
|
||||||
|
@ -1450,7 +1456,7 @@ namespace sat {
|
||||||
m_next_simplify = m_conflicts_since_init + m_config.m_simplify_max;
|
m_next_simplify = m_conflicts_since_init + m_config.m_simplify_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
static unsigned file_no = 0;
|
static unsigned file_no = 0;
|
||||||
#pragma omp critical (print_sat)
|
#pragma omp critical (print_sat)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,19 @@ bound_manager::~bound_manager() {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bound_manager* bound_manager::translate(ast_manager& dst_m) {
|
||||||
|
bound_manager* result = alloc(bound_manager, dst_m);
|
||||||
|
ast_translation tr(m(), dst_m);
|
||||||
|
expr_dependency_translation edtr(tr);
|
||||||
|
for (auto& kv : m_lowers) result->m_lowers.insert(tr(kv.m_key), kv.m_value);
|
||||||
|
for (auto& kv : m_uppers) result->m_uppers.insert(tr(kv.m_key), kv.m_value);
|
||||||
|
for (auto& kv : m_lower_deps) result->m_lower_deps.insert(tr(kv.m_key), edtr(kv.m_value));
|
||||||
|
for (auto& kv : m_upper_deps) result->m_upper_deps.insert(tr(kv.m_key), edtr(kv.m_value));
|
||||||
|
for (expr* e : m_bounded_vars) result->m_bounded_vars.push_back(tr(e));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static decl_kind swap_decl(decl_kind k) {
|
static decl_kind swap_decl(decl_kind k) {
|
||||||
switch (k) {
|
switch (k) {
|
||||||
case OP_LE: return OP_GE;
|
case OP_LE: return OP_GE;
|
||||||
|
|
|
@ -47,6 +47,8 @@ public:
|
||||||
bound_manager(ast_manager & m);
|
bound_manager(ast_manager & m);
|
||||||
~bound_manager();
|
~bound_manager();
|
||||||
|
|
||||||
|
bound_manager* translate(ast_manager& dst_m);
|
||||||
|
|
||||||
ast_manager & m() const { return m_util.get_manager(); }
|
ast_manager & m() const { return m_util.get_manager(); }
|
||||||
|
|
||||||
void operator()(goal const & g);
|
void operator()(goal const & g);
|
||||||
|
|
|
@ -73,8 +73,17 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual solver* translate(ast_manager& m, params_ref const& p) {
|
virtual solver* translate(ast_manager& dst_m, params_ref const& p) {
|
||||||
return alloc(bounded_int2bv_solver, m, p, m_solver->translate(m, p));
|
flush_assertions();
|
||||||
|
bounded_int2bv_solver* result = alloc(bounded_int2bv_solver, dst_m, p, m_solver->translate(dst_m, p));
|
||||||
|
ast_translation tr(m, dst_m);
|
||||||
|
for (auto& kv : m_int2bv) result->m_int2bv.insert(tr(kv.m_key), tr(kv.m_value));
|
||||||
|
for (auto& kv : m_bv2int) result->m_bv2int.insert(tr(kv.m_key), tr(kv.m_value));
|
||||||
|
for (auto& kv : m_bv2offset) result->m_bv2offset.insert(tr(kv.m_key), kv.m_value);
|
||||||
|
for (func_decl* f : m_bv_fns) result->m_bv_fns.push_back(tr(f));
|
||||||
|
for (func_decl* f : m_int_fns) result->m_int_fns.push_back(tr(f));
|
||||||
|
for (bound_manager* b : m_bounds) result->m_bounds.push_back(b->translate(dst_m));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void assert_expr(expr * t) {
|
virtual void assert_expr(expr * t) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
virtual ~enum2bv_solver() {}
|
virtual ~enum2bv_solver() {}
|
||||||
|
|
||||||
virtual solver* translate(ast_manager& m, params_ref const& p) {
|
virtual solver* translate(ast_manager& m, params_ref const& p) {
|
||||||
return alloc(enum2bv_solver, m, p, m_solver->translate(m, p));
|
return alloc(enum2bv_solver, m, p, m_solver->translate(m, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
virtual ~pb2bv_solver() {}
|
virtual ~pb2bv_solver() {}
|
||||||
|
|
||||||
virtual solver* translate(ast_manager& m, params_ref const& p) {
|
virtual solver* translate(ast_manager& m, params_ref const& p) {
|
||||||
|
flush_assertions();
|
||||||
return alloc(pb2bv_solver, m, p, m_solver->translate(m, p));
|
return alloc(pb2bv_solver, m, p, m_solver->translate(m, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue