3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 13:28:47 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2017-03-03 18:09:41 -08:00
parent b5ace71bb8
commit f16dcef7e2
2 changed files with 25 additions and 16 deletions

View file

@ -223,8 +223,9 @@ namespace sat {
m_vars.reserve(c[i].var() + 1); m_vars.reserve(c[i].var() + 1);
literal t(~c[i]); literal t(~c[i]);
m_vars[t.var()].m_watch[is_pos(t)].push_back(id); m_vars[t.var()].m_watch[is_pos(t)].push_back(id);
m_constraints.back().m_literals.push_back(t); m_constraints.back().push(t);
} }
m_constraints.back().seal();
if (sz == 1 && k == 0) { if (sz == 1 && k == 0) {
m_vars[c[0].var()].m_bias = c[0].sign() ? 0 : 100; m_vars[c[0].var()].m_bias = c[0].sign() ? 0 : 100;
} }
@ -447,50 +448,55 @@ namespace sat {
SASSERT(c.m_k < constraint_value(c)); SASSERT(c.m_k < constraint_value(c));
if (m_rand() % 100 < 98) { if (m_rand() % 100 < 98) {
// take this branch with 98% probability. // take this branch with 98% probability.
// display(std::cout, c);
unsigned best_bsb = 0; unsigned best_bsb = 0;
// find the first one, to fast break the rest // find the first one, to fast break the rest
unsigned i = 0; unsigned i = 0;
literal const* lits = c.m_literals.c_ptr();
literal l;
while (true) { while (true) {
v = c[i].var(); l = *lits;
if (is_true(c[i])) { if (is_true(l)) {
v = l.var();
bool tt = cur_solution(v); bool tt = cur_solution(v);
int_vector const& falsep = m_vars[v].m_watch[!tt]; int_vector const& falsep = m_vars[v].m_watch[!tt];
for (unsigned j = 0; j < falsep.size(); ++j) { unsigned sz = falsep.size();
for (unsigned j = 0; j < sz; ++j) {
unsigned ci = falsep[j]; unsigned ci = falsep[j];
if (constraint_slack(ci) < 0) if (constraint_slack(ci) < 0)
++best_bsb; ++best_bsb;
else if (constraint_slack(ci) == 0) else if (constraint_slack(ci) == 0)
// >= unsat_stack_fill_pointer is enough best_bsb += m_unsat_stack.size();
best_bsb += m_constraints.size();
} }
break; break;
} }
++i; ++lits;
} }
++lits;
m_good_vars.push_back(v); m_good_vars.push_back(v);
for (++i; i < c.size(); ++i) { for (; (l = *lits) != null_literal; ++lits) {
v = c[i].var(); if (is_true(l)) {
if (is_true(c[i])) { v = l.var();
bool found = false; bool found = false;
unsigned bsb = 0; unsigned bsb = 0;
bool tt = cur_solution(v); bool tt = cur_solution(v);
int_vector const& falsep = m_vars[v].m_watch[!tt]; int_vector const& falsep = m_vars[v].m_watch[!tt];
for (unsigned j = 0; j < falsep.size() && !found; ++j) { unsigned sz = falsep.size();
for (unsigned j = 0; j < sz; ++j) {
unsigned ci = falsep[j]; unsigned ci = falsep[j];
if (constraint_slack(ci) < 0) { if (constraint_slack(ci) < 0) {
if (bsb == best_bsb) { if (bsb == best_bsb) {
found = true; found = true;
break;
} }
else { else {
++bsb; ++bsb;
} }
} }
else if (constraint_slack(ci) == 0) { else if (constraint_slack(ci) == 0) {
// >= unsat_stack_fill_pointer is enough bsb += m_unsat_stack.size();
bsb += m_constraints.size();
if (bsb > best_bsb) { if (bsb > best_bsb) {
found = true; found = true;
break;
} }
} }
} }

View file

@ -94,9 +94,12 @@ namespace sat {
struct constraint { struct constraint {
unsigned m_k; unsigned m_k;
int m_slack; int m_slack;
unsigned m_size;
literal_vector m_literals; literal_vector m_literals;
constraint(unsigned k) : m_k(k), m_slack(0) {} constraint(unsigned k) : m_k(k), m_slack(0), m_size(0) {}
unsigned size() const { return m_literals.size(); } void push(literal l) { m_literals.push_back(l); ++m_size; }
void seal() { m_literals.push_back(null_literal); }
unsigned size() const { return m_size; }
literal const& operator[](unsigned idx) const { return m_literals[idx]; } literal const& operator[](unsigned idx) const { return m_literals[idx]; }
}; };