mirror of
https://github.com/Z3Prover/z3
synced 2025-06-23 14:23:40 +00:00
Fix cleanup/initialization of sat::simplifier. Relates to #570.
This commit is contained in:
parent
6204f67d38
commit
890142ef96
6 changed files with 119 additions and 89 deletions
|
@ -106,6 +106,10 @@ namespace sat {
|
||||||
literal get_literal1() const { return to_literal(m_val1); }
|
literal get_literal1() const { return to_literal(m_val1); }
|
||||||
literal get_literal2() const { return to_literal(m_val2 >> 1); }
|
literal get_literal2() const { return to_literal(m_val2 >> 1); }
|
||||||
bool is_learned() const { return (m_val2 & 1) == 1; }
|
bool is_learned() const { return (m_val2 & 1) == 1; }
|
||||||
|
bool operator==(const bin_clause & other) const {
|
||||||
|
return m_val1 == other.m_val1 && m_val2 == other.m_val2 ||
|
||||||
|
m_val1 == other.m_val2 && m_val2 == other.m_val1;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class tmp_clause {
|
class tmp_clause {
|
||||||
|
|
|
@ -256,7 +256,7 @@ namespace sat {
|
||||||
}
|
}
|
||||||
|
|
||||||
void probing::free_memory() {
|
void probing::free_memory() {
|
||||||
m_assigned.cleanup();
|
m_assigned.finalize();
|
||||||
m_to_assert.finalize();
|
m_to_assert.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ namespace sat {
|
||||||
}
|
}
|
||||||
|
|
||||||
simplifier::~simplifier() {
|
simplifier::~simplifier() {
|
||||||
|
free_memory();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline watch_list & simplifier::get_wlist(literal l) { return s.get_wlist(l); }
|
inline watch_list & simplifier::get_wlist(literal l) { return s.get_wlist(l); }
|
||||||
|
@ -96,7 +97,7 @@ namespace sat {
|
||||||
inline void simplifier::remove_clause_core(clause & c) {
|
inline void simplifier::remove_clause_core(clause & c) {
|
||||||
unsigned sz = c.size();
|
unsigned sz = c.size();
|
||||||
for (unsigned i = 0; i < sz; i++)
|
for (unsigned i = 0; i < sz; i++)
|
||||||
insert_todo(c[i].var());
|
insert_elim_todo(c[i].var());
|
||||||
m_sub_todo.erase(c);
|
m_sub_todo.erase(c);
|
||||||
c.set_removed(true);
|
c.set_removed(true);
|
||||||
TRACE("resolution_bug", tout << "del_clause: " << c << "\n";);
|
TRACE("resolution_bug", tout << "del_clause: " << c << "\n";);
|
||||||
|
@ -116,6 +117,7 @@ namespace sat {
|
||||||
inline void simplifier::remove_bin_clause_half(literal l1, literal l2, bool learned) {
|
inline void simplifier::remove_bin_clause_half(literal l1, literal l2, bool learned) {
|
||||||
SASSERT(s.get_wlist(~l1).contains(watched(l2, learned)));
|
SASSERT(s.get_wlist(~l1).contains(watched(l2, learned)));
|
||||||
s.get_wlist(~l1).erase(watched(l2, learned));
|
s.get_wlist(~l1).erase(watched(l2, learned));
|
||||||
|
m_sub_bin_todo.erase(bin_clause(l1, l2, learned));
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifier::init_visited() {
|
void simplifier::init_visited() {
|
||||||
|
@ -127,17 +129,33 @@ namespace sat {
|
||||||
m_use_list.finalize();
|
m_use_list.finalize();
|
||||||
m_sub_todo.finalize();
|
m_sub_todo.finalize();
|
||||||
m_sub_bin_todo.finalize();
|
m_sub_bin_todo.finalize();
|
||||||
|
m_elim_todo.finalize();
|
||||||
m_visited.finalize();
|
m_visited.finalize();
|
||||||
m_bs_cs.finalize();
|
m_bs_cs.finalize();
|
||||||
m_bs_ls.finalize();
|
m_bs_ls.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifier::initialize() {
|
||||||
|
m_need_cleanup = false;
|
||||||
|
s.m_cleaner(true);
|
||||||
|
m_last_sub_trail_sz = s.m_trail.size();
|
||||||
|
m_use_list.init(s.num_vars());
|
||||||
|
m_sub_todo.reset();
|
||||||
|
m_sub_bin_todo.reset();
|
||||||
|
m_elim_todo.reset();
|
||||||
|
init_visited();
|
||||||
|
TRACE("after_cleanup", s.display(tout););
|
||||||
|
CASSERT("sat_solver", s.check_invariant());
|
||||||
|
}
|
||||||
|
|
||||||
void simplifier::operator()(bool learned) {
|
void simplifier::operator()(bool learned) {
|
||||||
if (s.inconsistent())
|
if (s.inconsistent())
|
||||||
return;
|
return;
|
||||||
if (!m_subsumption && !m_elim_blocked_clauses && !m_resolution)
|
if (!m_subsumption && !m_elim_blocked_clauses && !m_resolution)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
|
||||||
CASSERT("sat_solver", s.check_invariant());
|
CASSERT("sat_solver", s.check_invariant());
|
||||||
TRACE("before_simplifier", s.display(tout););
|
TRACE("before_simplifier", s.display(tout););
|
||||||
|
|
||||||
|
@ -160,7 +178,6 @@ namespace sat {
|
||||||
if (!learned && (m_elim_blocked_clauses || m_elim_blocked_clauses_at == m_num_calls))
|
if (!learned && (m_elim_blocked_clauses || m_elim_blocked_clauses_at == m_num_calls))
|
||||||
elim_blocked_clauses();
|
elim_blocked_clauses();
|
||||||
|
|
||||||
|
|
||||||
if (!learned)
|
if (!learned)
|
||||||
m_num_calls++;
|
m_num_calls++;
|
||||||
|
|
||||||
|
@ -619,7 +636,7 @@ namespace sat {
|
||||||
TRACE("elim_lit", tout << "processing: " << c << "\n";);
|
TRACE("elim_lit", tout << "processing: " << c << "\n";);
|
||||||
m_need_cleanup = true;
|
m_need_cleanup = true;
|
||||||
m_num_elim_lits++;
|
m_num_elim_lits++;
|
||||||
insert_todo(l.var());
|
insert_elim_todo(l.var());
|
||||||
c.elim(l);
|
c.elim(l);
|
||||||
clause_use_list & occurs = m_use_list.get(l);
|
clause_use_list & occurs = m_use_list.get(l);
|
||||||
occurs.erase_not_removed(c);
|
occurs.erase_not_removed(c);
|
||||||
|
@ -1237,12 +1254,14 @@ namespace sat {
|
||||||
for (; it2 != end2; ++it2) {
|
for (; it2 != end2; ++it2) {
|
||||||
if (it2->is_binary_clause() && it2->get_literal() == l) {
|
if (it2->is_binary_clause() && it2->get_literal() == l) {
|
||||||
TRACE("bin_clause_bug", tout << "removing: " << l << " " << it2->get_literal() << "\n";);
|
TRACE("bin_clause_bug", tout << "removing: " << l << " " << it2->get_literal() << "\n";);
|
||||||
|
m_sub_bin_todo.erase(bin_clause(l2, l, it2->is_learned()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*itprev = *it2;
|
*itprev = *it2;
|
||||||
itprev++;
|
itprev++;
|
||||||
}
|
}
|
||||||
wlist2.set_end(itprev);
|
wlist2.set_end(itprev);
|
||||||
|
m_sub_bin_todo.erase(bin_clause(l, l2, it->is_learned()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TRACE("bin_clause_bug", tout << "collapsing watch_list of: " << l << "\n";);
|
TRACE("bin_clause_bug", tout << "collapsing watch_list of: " << l << "\n";);
|
||||||
|
|
|
@ -97,6 +97,8 @@ namespace sat {
|
||||||
|
|
||||||
void checkpoint();
|
void checkpoint();
|
||||||
|
|
||||||
|
void initialize();
|
||||||
|
|
||||||
void init_visited();
|
void init_visited();
|
||||||
void mark_visited(literal l) { m_visited[l.index()] = true; }
|
void mark_visited(literal l) { m_visited[l.index()] = true; }
|
||||||
void unmark_visited(literal l) { m_visited[l.index()] = false; }
|
void unmark_visited(literal l) { m_visited[l.index()] = false; }
|
||||||
|
@ -172,8 +174,13 @@ namespace sat {
|
||||||
simplifier(solver & s, params_ref const & p);
|
simplifier(solver & s, params_ref const & p);
|
||||||
~simplifier();
|
~simplifier();
|
||||||
|
|
||||||
void insert_todo(bool_var v) { m_elim_todo.insert(v); }
|
void insert_elim_todo(bool_var v) { m_elim_todo.insert(v); }
|
||||||
void reset_todo() { m_elim_todo.reset(); }
|
|
||||||
|
void reset_todos() {
|
||||||
|
m_elim_todo.reset();
|
||||||
|
m_sub_todo.reset();
|
||||||
|
m_sub_bin_todo.reset();
|
||||||
|
}
|
||||||
|
|
||||||
void operator()(bool learned);
|
void operator()(bool learned);
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@ namespace sat {
|
||||||
m_prev_phase.push_back(PHASE_NOT_AVAILABLE);
|
m_prev_phase.push_back(PHASE_NOT_AVAILABLE);
|
||||||
m_assigned_since_gc.push_back(false);
|
m_assigned_since_gc.push_back(false);
|
||||||
m_case_split_queue.mk_var_eh(v);
|
m_case_split_queue.mk_var_eh(v);
|
||||||
m_simplifier.insert_todo(v);
|
m_simplifier.insert_elim_todo(v);
|
||||||
SASSERT(!was_eliminated(v));
|
SASSERT(!was_eliminated(v));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -2674,7 +2674,7 @@ namespace sat {
|
||||||
m_phase.shrink(v);
|
m_phase.shrink(v);
|
||||||
m_prev_phase.shrink(v);
|
m_prev_phase.shrink(v);
|
||||||
m_assigned_since_gc.shrink(v);
|
m_assigned_since_gc.shrink(v);
|
||||||
m_simplifier.reset_todo();
|
m_simplifier.reset_todos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,7 +200,7 @@ namespace sat {
|
||||||
iterator begin() const { return m_set.begin(); }
|
iterator begin() const { return m_set.begin(); }
|
||||||
iterator end() const { return m_set.end(); }
|
iterator end() const { return m_set.end(); }
|
||||||
void reset() { m_set.reset(); m_in_set.reset(); }
|
void reset() { m_set.reset(); m_in_set.reset(); }
|
||||||
void cleanup() { m_set.finalize(); m_in_set.finalize(); }
|
void finalize() { m_set.finalize(); m_in_set.finalize(); }
|
||||||
uint_set& operator&=(uint_set const& other) {
|
uint_set& operator&=(uint_set const& other) {
|
||||||
unsigned j = 0;
|
unsigned j = 0;
|
||||||
for (unsigned i = 0; i < m_set.size(); ++i) {
|
for (unsigned i = 0; i < m_set.size(); ++i) {
|
||||||
|
@ -259,7 +259,7 @@ namespace sat {
|
||||||
bool empty() const { return m_set.empty(); }
|
bool empty() const { return m_set.empty(); }
|
||||||
unsigned size() const { return m_set.size(); }
|
unsigned size() const { return m_set.size(); }
|
||||||
void reset() { m_set.reset(); }
|
void reset() { m_set.reset(); }
|
||||||
void cleanup() { m_set.cleanup(); }
|
void finalize() { m_set.finalize(); }
|
||||||
class iterator {
|
class iterator {
|
||||||
uint_set::iterator m_it;
|
uint_set::iterator m_it;
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue