3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-05-06 23:35:46 +00:00

Polysat: refactor constraints (#5372)

* Refactor: remove sign and dep from constraint

* fix some bugs

* improve log messages

* Add missing premises to lemma

* Rename getter in an attempt to fix linux build
This commit is contained in:
Jakob Rath 2021-06-25 20:04:25 +02:00 committed by GitHub
parent a0b0c1f428
commit 3436b52c4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 435 additions and 325 deletions

View file

@ -0,0 +1,68 @@
/*++
Copyright (c) 2021 Microsoft Corporation
Module Name:
polysat clause builder
Author:
Nikolaj Bjorner (nbjorner) 2021-03-19
Jakob Rath 2021-04-6
--*/
#include "math/polysat/clause_builder.h"
#include "math/polysat/solver.h"
#include "math/polysat/log.h"
namespace polysat {
clause_builder::clause_builder(solver& s):
m_solver(s), m_dep(nullptr, s.m_dm)
{}
void clause_builder::reset() {
m_literals.reset();
m_new_constraints.reset();
m_level = 0;
m_dep = nullptr;
SASSERT(empty());
}
clause_ref clause_builder::build() {
// TODO: here we could set all the levels of the new constraints. so we do not have to compute the max at every use site.
clause_ref cl = clause::from_literals(m_level, std::move(m_dep), std::move(m_literals), std::move(m_new_constraints));
m_level = 0;
SASSERT(empty());
return cl;
}
void clause_builder::add_dependency(p_dependency* d) {
m_dep = m_solver.m_dm.mk_join(m_dep, d);
}
void clause_builder::push_literal(sat::literal lit) {
constraint* c = m_solver.m_constraints.lookup(lit.var());
SASSERT(c);
if (c->unit_clause()) {
add_dependency(c->unit_clause()->dep());
return;
}
m_level = std::max(m_level, c->level());
m_literals.push_back(lit);
}
void clause_builder::push_new_constraint(constraint_literal c) {
// TODO: assert that constraint is new (not 'inserted' into manager yet)
SASSERT(c);
SASSERT(c->is_undef());
tmp_assign _t(c.get(), c.literal());
if (c->is_always_false())
return;
m_level = std::max(m_level, c->level());
m_literals.push_back(c.literal());
m_new_constraints.push_back(c.detach());
}
}