3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

build issues, add equivalence finding to probing (disabled)

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-01-06 04:31:19 -08:00
parent d42a5410c9
commit 0278612328
6 changed files with 75 additions and 26 deletions

View file

@ -121,7 +121,7 @@ namespace sat {
}
}
std::function<void(aig_def)> force_var = [&, this] (aig_def a) {
std::function<void(aig_def)> force_var = [&] (aig_def a) {
for (unsigned i = 0; i < a.sz; ++i) {
unsigned v = literals[a.offset + i].var();
if (!ins[v]) {
@ -130,7 +130,7 @@ namespace sat {
}
}
};
std::function<void(unsigned)> add_var = [&, this] (unsigned v) {
std::function<void(unsigned)> add_var = [&] (unsigned v) {
if (!outs[v] && ins[v]) {
aigc.add_var(v);
outs[v] = true;
@ -229,7 +229,7 @@ namespace sat {
unsigned_vector sorted = top_sort();
vector<cut_set> cuts;
cuts.resize(m_aig.size());
max_cut_size = std::min(cut::max_cut_size, max_cut_size);
max_cut_size = std::min(cut().max_cut_size, max_cut_size);
cut_set cut_set2;
cut_set2.init(m_region, max_cutset_size + 1);
for (unsigned id : sorted) {

View file

@ -17,12 +17,12 @@
namespace sat {
struct cut {
static const unsigned max_cut_size = 6;
unsigned max_cut_size;
unsigned m_filter;
unsigned m_size;
unsigned m_elems[max_cut_size];
unsigned m_elems[6];
uint64_t m_table;
cut(): m_filter(0), m_size(0), m_table(0) {}
cut(): m_filter(0), m_size(0), m_table(0), max_cut_size(6) {}
cut(unsigned id): m_filter(1u << (id & 0x1F)), m_size(1), m_table(2) { m_elems[0] = id; }
@ -61,13 +61,13 @@ namespace sat {
uint64_t shift_table(cut const& other) const;
bool merge(cut const& a, cut const& b, unsigned max_cut_size) {
bool merge(cut const& a, cut const& b, unsigned max_sz) {
SASSERT(a.m_size > 0 && b.m_size > 0);
unsigned i = 0, j = 0;
unsigned x = a[i];
unsigned y = b[j];
while (x != UINT_MAX || y != UINT_MAX) {
if (!add(std::min(x, y), max_cut_size)) {
if (!add(std::min(x, y), max_sz)) {
return false;
}
if (x < y) {

View file

@ -19,11 +19,13 @@ Revision History:
--*/
#include "sat/sat_probing.h"
#include "sat/sat_solver.h"
#include "sat/sat_elim_eqs.h"
#include "sat/sat_simplifier_params.hpp"
namespace sat {
probing::probing(solver & _s, params_ref const & p):
s(_s) {
s(_s),
m_big(s.rand()) {
updt_params(p);
reset_statistics();
m_stopped_at = 0;
@ -137,9 +139,21 @@ namespace sat {
m_assigned.reset();
unsigned tr_sz = s.m_trail.size();
for (unsigned i = old_tr_sz; i < tr_sz; i++) {
m_assigned.insert(s.m_trail[i]);
literal lit = s.m_trail[i];
m_assigned.insert(lit);
#if 0
// learn equivalences during probing:
if (implies(lit, l)) {
if (nullptr == find_binary_watch(s.get_wlist(lit), l) ||
nullptr == find_binary_watch(s.get_wlist(~l), ~lit)) {
m_equivs.push_back(std::make_pair(lit, l));
}
}
#endif
}
cache_bins(l, old_tr_sz);
s.pop(1);
if (!try_lit(~l, true))
@ -177,23 +191,24 @@ namespace sat {
}
struct probing::report {
probing & m_probing;
probing & p;
stopwatch m_watch;
unsigned m_num_assigned;
report(probing & p):
m_probing(p),
p(p),
m_num_assigned(p.m_num_assigned) {
m_watch.start();
}
~report() {
m_watch.stop();
unsigned units = (m_probing.m_num_assigned - m_num_assigned);
unsigned units = (p.m_num_assigned - m_num_assigned);
IF_VERBOSE(2,
verbose_stream() << " (sat-probing";
if (units > 0) verbose_stream() << " :probing-assigned " << units;
verbose_stream() << " :cost " << m_probing.m_counter;
if (m_probing.m_stopped_at != 0) verbose_stream() << " :stopped-at " << m_probing.m_stopped_at;
if (!p.m_equivs.empty()) verbose_stream() << " :equivs " << p.m_equivs.size();
verbose_stream() << " :cost " << p.m_counter;
if (p.m_stopped_at != 0) verbose_stream() << " :stopped-at " << p.m_stopped_at;
verbose_stream() << mem_stat() << m_watch << ")\n";);
}
};
@ -215,6 +230,8 @@ namespace sat {
report rpt(*this);
bool r = true;
m_counter = 0;
m_equivs.reset();
m_big.init(s, true);
int limit = -static_cast<int>(m_probing_limit);
unsigned i;
unsigned num = s.num_vars();
@ -248,9 +265,26 @@ namespace sat {
}
CASSERT("probing", s.check_invariant());
finalize();
if (!m_equivs.empty()) {
union_find_default_ctx ctx;
union_find<> uf(ctx);
for (unsigned i = 2*s.num_vars(); i--> 0; ) uf.mk_var();
for (auto const& p : m_equivs) {
literal l1 = p.first, l2 = p.second;
uf.merge(l1.index(), l2.index());
uf.merge((~l1).index(), (~l2).index());
}
elim_eqs elim(s);
elim(uf);
}
return r;
}
bool probing::implies(literal a, literal b) {
return m_big.connected(a, b);
}
void probing::updt_params(params_ref const & _p) {
sat_simplifier_params p(_p);
m_probing = p.probing();

View file

@ -21,6 +21,7 @@ Revision History:
#define SAT_PROBING_H_
#include "sat/sat_types.h"
#include "sat/sat_big.h"
#include "util/params.h"
#include "util/statistics.h"
@ -43,7 +44,7 @@ namespace sat {
unsigned long long m_probing_cache_limit; // memory limit for enabling caching.
// stats
unsigned m_num_assigned;
unsigned m_num_assigned;
struct cache_entry {
bool m_available;
@ -60,6 +61,11 @@ namespace sat {
void process(bool_var v);
void process_core(bool_var v);
// learn equivalences from probing.
svector<std::pair<literal, literal>> m_equivs;
big m_big;
bool implies(literal a, literal b);
public:
probing(solver & s, params_ref const & p);