mirror of
https://github.com/Z3Prover/z3
synced 2025-06-27 08:28:44 +00:00
include chronological backtracking, two-phase sat, xor inprocessing, probsat, ddfw
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
46d23ea8d7
commit
d17248821a
32 changed files with 3246 additions and 654 deletions
|
@ -102,7 +102,6 @@ namespace sat {
|
|||
literal l = lits.back();
|
||||
lits.pop_back();
|
||||
SASSERT(!m_binary[(~l).index()].empty());
|
||||
IF_VERBOSE(0, if (m_binary[(~l).index()].back() != ~to_literal(idx)) verbose_stream() << "pop bad literal: " << idx << " " << (~l).index() << "\n";);
|
||||
SASSERT(m_binary[(~l).index()].back() == ~to_literal(idx));
|
||||
m_binary[(~l).index()].pop_back();
|
||||
++m_stats.m_del_binary;
|
||||
|
@ -1655,6 +1654,77 @@ namespace sat {
|
|||
return result;
|
||||
}
|
||||
|
||||
void lookahead::get_clauses(literal_vector& clauses, unsigned max_clause_size) {
|
||||
// push binary clauses
|
||||
unsigned num_lits = m_s.num_vars() * 2;
|
||||
for (unsigned idx = 0; idx < num_lits; ++idx) {
|
||||
literal u = to_literal(idx);
|
||||
if (m_s.was_eliminated(u.var()) || is_false(u) || is_true(u)) continue;
|
||||
for (literal v : m_binary[idx]) {
|
||||
if (u.index() < v.index() && !m_s.was_eliminated(v.var()) && !is_false(v) && !is_true(v)) {
|
||||
clauses.push_back(~u);
|
||||
clauses.push_back(v);
|
||||
clauses.push_back(null_literal);
|
||||
}
|
||||
}
|
||||
}
|
||||
// push ternary clauses
|
||||
for (unsigned idx = 0; idx < num_lits; ++idx) {
|
||||
literal u = to_literal(idx);
|
||||
if (is_true(u) || is_false(u)) continue;
|
||||
unsigned sz = m_ternary_count[u.index()];
|
||||
for (binary const& b : m_ternary[u.index()]) {
|
||||
if (sz-- == 0) break;
|
||||
if (u.index() > b.m_v.index() || u.index() > b.m_u.index())
|
||||
continue;
|
||||
if (is_true(b.m_u) || is_true(b.m_v))
|
||||
continue;
|
||||
if (is_false(b.m_u) && is_false(b.m_v))
|
||||
continue;
|
||||
clauses.push_back(u);
|
||||
if (!is_false(b.m_u)) clauses.push_back(b.m_u);
|
||||
if (!is_false(b.m_v)) clauses.push_back(b.m_v);
|
||||
clauses.push_back(null_literal);
|
||||
}
|
||||
}
|
||||
|
||||
// push n-ary clauses
|
||||
for (unsigned idx = 0; idx < num_lits; ++idx) {
|
||||
literal u = to_literal(idx);
|
||||
unsigned sz = m_nary_count[u.index()];
|
||||
for (nary* n : m_nary[u.index()]) {
|
||||
if (sz-- == 0) break;
|
||||
unsigned sz0 = clauses.size();
|
||||
if (n->size() > max_clause_size) continue;
|
||||
for (literal lit : *n) {
|
||||
if (is_true(lit)) {
|
||||
clauses.shrink(sz0);
|
||||
break;
|
||||
}
|
||||
if (!is_false(lit)) {
|
||||
clauses.push_back(lit);
|
||||
}
|
||||
}
|
||||
if (clauses.size() > sz0) {
|
||||
clauses.push_back(null_literal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TRACE("sat",
|
||||
for (literal lit : clauses) {
|
||||
if (lit == null_literal) {
|
||||
tout << "\n";
|
||||
}
|
||||
else {
|
||||
tout << lit << " ";
|
||||
}
|
||||
}
|
||||
tout << "\n";
|
||||
m_s.display(tout);
|
||||
);
|
||||
}
|
||||
|
||||
void lookahead::propagate_binary(literal l) {
|
||||
literal_vector const& lits = m_binary[l.index()];
|
||||
TRACE("sat", tout << l << " => " << lits << "\n";);
|
||||
|
@ -1687,10 +1757,14 @@ namespace sat {
|
|||
unsigned base = 2;
|
||||
bool change = true;
|
||||
literal last_changed = null_literal;
|
||||
while (change && !inconsistent()) {
|
||||
unsigned ops = 0;
|
||||
m_max_ops = 100000;
|
||||
while (change && !inconsistent() && ops < m_max_ops) {
|
||||
change = false;
|
||||
for (unsigned i = 0; !inconsistent() && i < m_lookahead.size(); ++i) {
|
||||
IF_VERBOSE(10, verbose_stream() << "(sat.lookahead :compute-reward " << m_lookahead.size() << ")\n");
|
||||
for (unsigned i = 0; !inconsistent() && i < m_lookahead.size() && ops < m_max_ops; ++i) {
|
||||
checkpoint();
|
||||
++ops;
|
||||
literal lit = m_lookahead[i].m_lit;
|
||||
if (lit == last_changed) {
|
||||
SASSERT(!change);
|
||||
|
@ -1714,13 +1788,11 @@ namespace sat {
|
|||
num_units += do_double(lit, dl_lvl);
|
||||
if (dl_lvl > level) {
|
||||
base = dl_lvl;
|
||||
//SASSERT(get_level(m_trail.back()) == base + m_lookahead[i].m_offset);
|
||||
SASSERT(get_level(m_trail.back()) == base);
|
||||
}
|
||||
unsat = inconsistent();
|
||||
pop_lookahead1(lit, num_units);
|
||||
}
|
||||
// VERIFY(!missed_propagation());
|
||||
if (unsat) {
|
||||
TRACE("sat", tout << "backtracking and setting " << ~lit << "\n";);
|
||||
lookahead_backtrack();
|
||||
|
@ -2165,6 +2237,29 @@ namespace sat {
|
|||
return l_undef;
|
||||
}
|
||||
|
||||
|
||||
void lookahead::display_lookahead_scores(std::ostream& out) {
|
||||
scoped_ext _scoped_ext(*this);
|
||||
m_select_lookahead_vars.reset();
|
||||
init_search();
|
||||
scoped_level _sl(*this, c_fixed_truth);
|
||||
m_search_mode = lookahead_mode::searching;
|
||||
literal l = choose_base();
|
||||
if (l == null_literal) {
|
||||
out << "null\n";
|
||||
return;
|
||||
}
|
||||
for (auto const& l : m_lookahead) {
|
||||
literal lit = l.m_lit;
|
||||
if (!lit.sign() && is_undef(lit)) {
|
||||
double diff1 = get_lookahead_reward(lit);
|
||||
double diff2 = get_lookahead_reward(~lit);
|
||||
out << lit << " " << diff1 << " " << diff2 << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void lookahead::init_model() {
|
||||
m_model.reset();
|
||||
for (unsigned i = 0; i < m_num_vars; ++i) {
|
||||
|
@ -2255,7 +2350,13 @@ namespace sat {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
literal lookahead::choose() {
|
||||
return choose_base();
|
||||
}
|
||||
|
||||
literal lookahead::choose_base() {
|
||||
literal l = null_literal;
|
||||
while (l == null_literal && !inconsistent()) {
|
||||
pre_select();
|
||||
|
@ -2284,7 +2385,7 @@ namespace sat {
|
|||
init(learned);
|
||||
if (inconsistent()) return;
|
||||
inc_istamp();
|
||||
choose();
|
||||
choose_base();
|
||||
if (inconsistent()) return;
|
||||
SASSERT(m_trail_lim.empty());
|
||||
unsigned num_units = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue