mirror of
https://github.com/Z3Prover/z3
synced 2025-08-01 00:43:18 +00:00
Gamble finder.
This commit is contained in:
parent
0caa2f27a1
commit
34a3f8db6e
2 changed files with 63 additions and 0 deletions
|
@ -66,6 +66,7 @@ namespace sat {
|
||||||
find_maj(clauses);
|
find_maj(clauses);
|
||||||
find_orand(clauses);
|
find_orand(clauses);
|
||||||
find_andxor(clauses);
|
find_andxor(clauses);
|
||||||
|
find_gamble(clauses);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool npn3_finder::implies(literal a, literal b) const {
|
bool npn3_finder::implies(literal a, literal b) const {
|
||||||
|
@ -299,6 +300,65 @@ namespace sat {
|
||||||
find_npn3(clauses, m_on_orand, try_orand);
|
find_npn3(clauses, m_on_orand, try_orand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void npn3_finder::find_gamble(clause_vector& clauses) {
|
||||||
|
if (!m_on_gamble) return;
|
||||||
|
|
||||||
|
binary_hash_table_t binaries;
|
||||||
|
ternary_hash_table_t ternaries;
|
||||||
|
quaternary_hash_table_t quaternaries;
|
||||||
|
process_more_clauses(clauses, binaries, ternaries, quaternaries);
|
||||||
|
|
||||||
|
const auto try_gamble = [&](literal w, literal x, literal y, literal z, clause &c) {
|
||||||
|
clause *c1, *c2, *c3, *c4;
|
||||||
|
if (!has_quaternary(quaternaries, ternaries, ~x, ~y, ~z, w, c1)) return false;
|
||||||
|
if (!has_ternary(ternaries, ~x, y, ~w, c2)) return false;
|
||||||
|
if (!has_ternary(ternaries, ~y, z, ~w, c3)) return false;
|
||||||
|
if (!has_ternary(ternaries, x, ~z, ~w, c4)) return false;
|
||||||
|
|
||||||
|
c.mark_used();
|
||||||
|
if (c1) c1->mark_used();
|
||||||
|
if (c2) c2->mark_used();
|
||||||
|
if (c3) c3->mark_used();
|
||||||
|
if (c4) c4->mark_used();
|
||||||
|
m_on_gamble(w, x, y, z);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (clause* cp : clauses) {
|
||||||
|
clause& c = *cp;
|
||||||
|
if (c.size() != 4 || c.was_used()) continue;
|
||||||
|
literal w = c[0], x = c[1], y = c[2], z = c[3];
|
||||||
|
|
||||||
|
if (try_gamble(w, x, y, z, c)) continue;
|
||||||
|
if (try_gamble(w, x, z, y, c)) continue;
|
||||||
|
if (try_gamble(w, y, x, z, c)) continue;
|
||||||
|
if (try_gamble(w, y, z, x, c)) continue;
|
||||||
|
if (try_gamble(w, z, x, y, c)) continue;
|
||||||
|
if (try_gamble(w, z, y, x, c)) continue;
|
||||||
|
if (try_gamble(x, w, y, z, c)) continue;
|
||||||
|
if (try_gamble(x, w, z, y, c)) continue;
|
||||||
|
if (try_gamble(x, y, w, z, c)) continue;
|
||||||
|
if (try_gamble(x, y, z, w, c)) continue;
|
||||||
|
if (try_gamble(x, z, w, y, c)) continue;
|
||||||
|
if (try_gamble(x, z, y, w, c)) continue;
|
||||||
|
if (try_gamble(y, w, x, z, c)) continue;
|
||||||
|
if (try_gamble(y, w, z, x, c)) continue;
|
||||||
|
if (try_gamble(y, x, w, z, c)) continue;
|
||||||
|
if (try_gamble(y, x, z, w, c)) continue;
|
||||||
|
if (try_gamble(y, z, w, x, c)) continue;
|
||||||
|
if (try_gamble(y, z, x, w, c)) continue;
|
||||||
|
if (try_gamble(z, w, x, y, c)) continue;
|
||||||
|
if (try_gamble(z, w, y, x, c)) continue;
|
||||||
|
if (try_gamble(z, x, w, y, c)) continue;
|
||||||
|
if (try_gamble(z, x, y, w, c)) continue;
|
||||||
|
if (try_gamble(z, y, w, x, c)) continue;
|
||||||
|
if (try_gamble(z, y, x, w, c)) continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::function<bool(clause*)> not_used = [](clause* cp) { return !cp->was_used(); };
|
||||||
|
clauses.filter_update(not_used);
|
||||||
|
}
|
||||||
|
|
||||||
void npn3_finder::find_andxor(clause_vector& clauses) {
|
void npn3_finder::find_andxor(clause_vector& clauses) {
|
||||||
if (!m_on_andxor) return;
|
if (!m_on_andxor) return;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace sat {
|
||||||
on_function_t m_on_maj;
|
on_function_t m_on_maj;
|
||||||
on_function_t m_on_orand;
|
on_function_t m_on_orand;
|
||||||
on_function_t m_on_andxor;
|
on_function_t m_on_andxor;
|
||||||
|
on_function_t m_on_gamble;
|
||||||
|
|
||||||
typedef svector<std::pair<literal, clause*>> use_list_t;
|
typedef svector<std::pair<literal, clause*>> use_list_t;
|
||||||
scoped_ptr_vector<use_list_t> m_use_lists;
|
scoped_ptr_vector<use_list_t> m_use_lists;
|
||||||
|
@ -99,6 +100,7 @@ namespace sat {
|
||||||
void find_maj(clause_vector& clauses);
|
void find_maj(clause_vector& clauses);
|
||||||
void find_orand(clause_vector& clauses);
|
void find_orand(clause_vector& clauses);
|
||||||
void find_andxor(clause_vector& clauses);
|
void find_andxor(clause_vector& clauses);
|
||||||
|
void find_gamble(clause_vector& clauses);
|
||||||
void validate_clause(literal x, literal y, literal z, vector<literal_vector> const& clauses);
|
void validate_clause(literal x, literal y, literal z, vector<literal_vector> const& clauses);
|
||||||
void validate_clause(literal_vector const& clause, vector<literal_vector> const& clauses);
|
void validate_clause(literal_vector const& clause, vector<literal_vector> const& clauses);
|
||||||
|
|
||||||
|
@ -110,6 +112,7 @@ namespace sat {
|
||||||
void set_on_maj(std::function<void(literal head, literal a, literal b, literal c)> const& f) { m_on_maj = f; }
|
void set_on_maj(std::function<void(literal head, literal a, literal b, literal c)> const& f) { m_on_maj = f; }
|
||||||
void set_on_orand(std::function<void(literal head, literal a, literal b, literal c)> const& f) { m_on_orand = f; }
|
void set_on_orand(std::function<void(literal head, literal a, literal b, literal c)> const& f) { m_on_orand = f; }
|
||||||
void set_on_andxor(std::function<void(literal head, literal a, literal b, literal c)> const& f) { m_on_andxor = f; }
|
void set_on_andxor(std::function<void(literal head, literal a, literal b, literal c)> const& f) { m_on_andxor = f; }
|
||||||
|
void set_on_gamble(std::function<void(literal head, literal a, literal b, literal c)> const& f) { m_on_gamble = f; }
|
||||||
void operator()(clause_vector& clauses);
|
void operator()(clause_vector& clauses);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue