mirror of
https://github.com/Z3Prover/z3
synced 2025-06-21 05:13:39 +00:00
wip
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
0d9d4bb46e
commit
a50cecaefa
3 changed files with 31 additions and 16 deletions
|
@ -125,7 +125,6 @@ namespace polysat {
|
||||||
* should appear, otherwise the lemma would be a tautology
|
* should appear, otherwise the lemma would be a tautology
|
||||||
*/
|
*/
|
||||||
void conflict::insert(signed_constraint c) {
|
void conflict::insert(signed_constraint c) {
|
||||||
|
|
||||||
if (c.is_always_true())
|
if (c.is_always_true())
|
||||||
return;
|
return;
|
||||||
if (c->is_marked())
|
if (c->is_marked())
|
||||||
|
@ -321,7 +320,7 @@ namespace polysat {
|
||||||
bool conflict::try_eliminate(pvar v) {
|
bool conflict::try_eliminate(pvar v) {
|
||||||
bool has_v = false;
|
bool has_v = false;
|
||||||
for (auto c : *this)
|
for (auto c : *this)
|
||||||
has_v |= c->contains_var(v);
|
has_v |= c->is_var_dependent() && c->contains_var(v);
|
||||||
if (!has_v)
|
if (!has_v)
|
||||||
return true;
|
return true;
|
||||||
for (auto* engine : ve_engines)
|
for (auto* engine : ve_engines)
|
||||||
|
|
|
@ -79,10 +79,13 @@ namespace polysat {
|
||||||
if (!c.is_currently_false(s))
|
if (!c.is_currently_false(s))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
core.replace(crit1, c, new_constraints);
|
|
||||||
core.reset();
|
core.reset();
|
||||||
core.set(c);
|
for (auto d : new_constraints)
|
||||||
|
core.insert(d);
|
||||||
|
c->set_var_dependent();
|
||||||
|
core.insert(~c);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool inf_saturate::propagate(conflict& core, inequality const& crit1, inequality const& crit2, bool is_strict, pdd const& lhs, pdd const& rhs, vector<signed_constraint>& new_constraints) {
|
bool inf_saturate::propagate(conflict& core, inequality const& crit1, inequality const& crit2, bool is_strict, pdd const& lhs, pdd const& rhs, vector<signed_constraint>& new_constraints) {
|
||||||
|
|
|
@ -122,16 +122,13 @@ namespace polysat {
|
||||||
m_constraints.ensure_bvar(c.get());
|
m_constraints.ensure_bvar(c.get());
|
||||||
sat::literal lit = c.blit();
|
sat::literal lit = c.blit();
|
||||||
LOG("New constraint: " << c);
|
LOG("New constraint: " << c);
|
||||||
if (m_bvars.is_false(lit)) {
|
if (m_bvars.is_false(lit) || c.is_currently_false(*this)) {
|
||||||
set_conflict(c /*, dep */);
|
set_conflict(c /*, dep */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_bvars.assign(lit, m_level, nullptr, nullptr, dep);
|
m_bvars.assign(lit, m_level, nullptr, nullptr, dep);
|
||||||
m_trail.push_back(trail_instr_t::assign_bool_i);
|
m_trail.push_back(trail_instr_t::assign_bool_i);
|
||||||
m_search.push_boolean(lit);
|
m_search.push_boolean(lit);
|
||||||
if (c.is_currently_false(*this))
|
|
||||||
set_conflict(c /*, dep */);
|
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_LINEAR_SOLVER
|
#if ENABLE_LINEAR_SOLVER
|
||||||
m_linear_solver.new_constraint(*c.get());
|
m_linear_solver.new_constraint(*c.get());
|
||||||
|
@ -200,13 +197,13 @@ namespace polysat {
|
||||||
if (m_bvars.is_true(cl[idx]))
|
if (m_bvars.is_true(cl[idx]))
|
||||||
return false;
|
return false;
|
||||||
unsigned i = 2;
|
unsigned i = 2;
|
||||||
for (; i < cl.size() && (m_bvars.is_false(cl[i]) || lit2cnstr(cl[i]).is_currently_false(*this)); ++i);
|
for (; i < cl.size() && m_bvars.is_false(cl[i]); ++i);
|
||||||
if (i < cl.size()) {
|
if (i < cl.size()) {
|
||||||
m_bvars.watch(cl[i]).push_back(&cl);
|
m_bvars.watch(cl[i]).push_back(&cl);
|
||||||
std::swap(cl[1 - idx], cl[i]);
|
std::swap(cl[1 - idx], cl[i]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (m_bvars.is_false(cl[idx]) || lit2cnstr(cl[idx]).is_currently_false(*this))
|
if (m_bvars.is_false(cl[idx]))
|
||||||
set_conflict(cl);
|
set_conflict(cl);
|
||||||
else
|
else
|
||||||
assign_bool(level(cl), cl[idx], &cl, nullptr);
|
assign_bool(level(cl), cl[idx], &cl, nullptr);
|
||||||
|
@ -526,8 +523,6 @@ namespace polysat {
|
||||||
|
|
||||||
// Guess a literal from the given clause; returns the guessed constraint
|
// Guess a literal from the given clause; returns the guessed constraint
|
||||||
void solver::decide_bool(clause& lemma) {
|
void solver::decide_bool(clause& lemma) {
|
||||||
if (is_conflict())
|
|
||||||
return;
|
|
||||||
LOG_H3("Guessing literal in lemma: " << lemma);
|
LOG_H3("Guessing literal in lemma: " << lemma);
|
||||||
IF_LOGGING(m_viable.log());
|
IF_LOGGING(m_viable.log());
|
||||||
LOG("Boolean assignment: " << m_bvars);
|
LOG("Boolean assignment: " << m_bvars);
|
||||||
|
@ -626,7 +621,23 @@ namespace polysat {
|
||||||
// again L is in core, unless we core-reduced it away
|
// again L is in core, unless we core-reduced it away
|
||||||
|
|
||||||
clause_builder reason_builder = m_conflict.build_lemma();
|
clause_builder reason_builder = m_conflict.build_lemma();
|
||||||
SASSERT(std::find(reason_builder.begin(), reason_builder.end(), ~lit));
|
|
||||||
|
|
||||||
|
bool contains_lit = std::find(reason_builder.begin(), reason_builder.end(), ~lit);
|
||||||
|
if (!contains_lit) {
|
||||||
|
// At this point, we do not have ~lit in the reason.
|
||||||
|
// For now, we simply add it (thus weakening the reason)
|
||||||
|
//
|
||||||
|
// Alternative (to be considered later):
|
||||||
|
// - 'reason' itself (without ~L) would already be an explanation for ~L
|
||||||
|
// - however if it doesn't contain ~L, it breaks the boolean resolution invariant
|
||||||
|
// - would need to check what we can gain by relaxing that invariant
|
||||||
|
// - drawback: might have to bail out at boolean resolution
|
||||||
|
// Also: maybe we can skip ~L in some cases? but in that case it shouldn't be marked.
|
||||||
|
//
|
||||||
|
std::cout << "ADD extra " << ~lit << "\n";
|
||||||
|
reason_builder.push(~lit);
|
||||||
|
}
|
||||||
clause_ref reason = reason_builder.build();
|
clause_ref reason = reason_builder.build();
|
||||||
|
|
||||||
if (reason->empty()) {
|
if (reason->empty()) {
|
||||||
|
@ -856,6 +867,8 @@ namespace polysat {
|
||||||
signed_constraint sc(c, is_positive);
|
signed_constraint sc(c, is_positive);
|
||||||
for (auto const& wlist : m_pwatch) {
|
for (auto const& wlist : m_pwatch) {
|
||||||
auto n = std::count(wlist.begin(), wlist.end(), sc);
|
auto n = std::count(wlist.begin(), wlist.end(), sc);
|
||||||
|
if (n > 1)
|
||||||
|
std::cout << sc << "\n" << * this << "\n";
|
||||||
VERIFY(n <= 1); // no duplicates in the watchlist
|
VERIFY(n <= 1); // no duplicates in the watchlist
|
||||||
num_watches += n;
|
num_watches += n;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue