mirror of
https://github.com/Z3Prover/z3
synced 2025-05-07 07:45:46 +00:00
handle empty clauses created as lemmas as unsat state.
add unit tests
This commit is contained in:
parent
c69c316b27
commit
1e3ff3179e
10 changed files with 113 additions and 80 deletions
|
@ -51,6 +51,14 @@ namespace polysat {
|
|||
out << " \\/ ";
|
||||
out << lit;
|
||||
}
|
||||
if (m_dep) {
|
||||
ptr_vector<p_dependency> todo;
|
||||
todo.push_back(m_dep.get());
|
||||
vector<unsigned, false> vs;
|
||||
poly_dep_manager::linearize_todo(todo, vs);
|
||||
out << " deps ...";
|
||||
// out << "| " << vs;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ namespace polysat {
|
|||
s().assign_bool(s().level(*lemma), c.blit(), lemma.get(), nullptr);
|
||||
}
|
||||
|
||||
clause_builder conflict_core::build_core_lemma() {
|
||||
clause_builder conflict_core::build_lemma() {
|
||||
LOG_H3("Build lemma from core");
|
||||
LOG("core: " << *this);
|
||||
clause_builder lemma(s());
|
||||
|
@ -243,9 +243,6 @@ namespace polysat {
|
|||
return lemma;
|
||||
}
|
||||
|
||||
clause_builder conflict_core::build_lemma() {
|
||||
return build_core_lemma();
|
||||
}
|
||||
|
||||
bool conflict_core::resolve_value(pvar v, vector<signed_constraint> const& cjust_v) {
|
||||
// NOTE:
|
||||
|
|
|
@ -105,7 +105,6 @@ namespace polysat {
|
|||
|
||||
/** Convert the core into a lemma to be learned. */
|
||||
clause_builder build_lemma();
|
||||
clause_builder build_core_lemma();
|
||||
|
||||
bool try_eliminate(pvar v);
|
||||
bool try_saturate(pvar v);
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace polysat {
|
|||
(m_stats.m_num_decisions < m_max_decisions);
|
||||
}
|
||||
|
||||
lbool solver::check_sat() {
|
||||
lbool solver::check_sat() {
|
||||
LOG("Starting");
|
||||
while (inc()) {
|
||||
m_stats.m_num_iterations++;
|
||||
|
@ -520,7 +520,7 @@ namespace polysat {
|
|||
LOG_H3("resolve_bool: " << lit << " " << other);
|
||||
m_conflict.resolve(m_constraints, var, other);
|
||||
}
|
||||
|
||||
|
||||
void solver::report_unsat() {
|
||||
backjump(base_level());
|
||||
SASSERT(!m_conflict.empty());
|
||||
|
@ -565,9 +565,11 @@ namespace polysat {
|
|||
return;
|
||||
case l_false:
|
||||
continue;
|
||||
default:
|
||||
if (lit2cnstr(lit).is_currently_false(*this))
|
||||
default:
|
||||
if (lit2cnstr(lit).is_currently_false(*this)) {
|
||||
num_choices++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
num_choices++;
|
||||
|
@ -601,6 +603,10 @@ namespace polysat {
|
|||
SASSERT(m_justification[v].is_decision());
|
||||
|
||||
clause_ref lemma = m_conflict.build_lemma().build();
|
||||
if (lemma->empty()) {
|
||||
report_unsat();
|
||||
return;
|
||||
}
|
||||
m_conflict.reset();
|
||||
|
||||
backjump(get_level(v) - 1);
|
||||
|
@ -644,7 +650,7 @@ namespace polysat {
|
|||
// again L is in core, unless we core-reduced it away
|
||||
|
||||
clause_builder reason_builder = m_conflict.build_lemma();
|
||||
m_conflict.reset();
|
||||
|
||||
|
||||
bool contains_lit = std::find(reason_builder.begin(), reason_builder.end(), ~lit);
|
||||
if (!contains_lit) {
|
||||
|
@ -662,6 +668,12 @@ namespace polysat {
|
|||
}
|
||||
clause_ref reason = reason_builder.build();
|
||||
|
||||
if (reason->empty()) {
|
||||
report_unsat();
|
||||
return;
|
||||
}
|
||||
m_conflict.reset();
|
||||
|
||||
std::cout << "reason " << *reason << "\n";
|
||||
|
||||
// The lemma where 'lit' comes from.
|
||||
|
@ -751,6 +763,8 @@ namespace polysat {
|
|||
LOG(" Literal " << lit << " is: " << lit2cnstr(lit));
|
||||
SASSERT(m_bvars.value(lit) != l_true);
|
||||
}
|
||||
if (lemma.empty())
|
||||
std::cout << lemma << "\n";
|
||||
SASSERT(!lemma.empty());
|
||||
m_constraints.store(&lemma, *this);
|
||||
if (lemma.size() == 1) {
|
||||
|
|
|
@ -31,6 +31,20 @@ Notes:
|
|||
|
||||
namespace polysat {
|
||||
|
||||
ule_constraint::ule_constraint(constraint_manager& m, pdd const& l, pdd const& r) :
|
||||
constraint(m, ckind_t::ule_t), m_lhs(l), m_rhs(r) {
|
||||
m_vars.append(l.free_vars());
|
||||
for (auto v : r.free_vars())
|
||||
if (!m_vars.contains(v))
|
||||
m_vars.push_back(v);
|
||||
if (m_lhs.is_val() && m_rhs.is_val()) {
|
||||
if (m_lhs.val() <= m_rhs.val())
|
||||
m_lhs = m_rhs = 0;
|
||||
else
|
||||
m_lhs = 1, m_rhs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& ule_constraint::display(std::ostream& out, lbool status) const {
|
||||
out << m_lhs;
|
||||
if (is_eq() && status == l_true) out << " == ";
|
||||
|
|
|
@ -23,13 +23,7 @@ namespace polysat {
|
|||
pdd m_lhs;
|
||||
pdd m_rhs;
|
||||
|
||||
ule_constraint(constraint_manager& m, pdd const& l, pdd const& r):
|
||||
constraint(m, ckind_t::ule_t), m_lhs(l), m_rhs(r) {
|
||||
m_vars.append(l.free_vars());
|
||||
for (auto v : r.free_vars())
|
||||
if (!m_vars.contains(v))
|
||||
m_vars.push_back(v);
|
||||
}
|
||||
ule_constraint(constraint_manager& m, pdd const& l, pdd const& r);
|
||||
|
||||
public:
|
||||
~ule_constraint() override {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue