mirror of
https://github.com/Z3Prover/z3
synced 2025-10-22 23:44:34 +00:00
apply formatting
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
e4cc27810f
commit
e95162b054
1 changed files with 206 additions and 186 deletions
|
@ -35,25 +35,32 @@ namespace search_tree {
|
||||||
|
|
||||||
enum class status { open, closed, active };
|
enum class status { open, closed, active };
|
||||||
|
|
||||||
template<typename Config>
|
template <typename Config> class node {
|
||||||
class node {
|
|
||||||
typedef typename Config::literal literal;
|
typedef typename Config::literal literal;
|
||||||
literal m_literal;
|
literal m_literal;
|
||||||
node *m_left = nullptr, *m_right = nullptr, *m_parent = nullptr;
|
node *m_left = nullptr, *m_right = nullptr, *m_parent = nullptr;
|
||||||
status m_status;
|
status m_status;
|
||||||
vector<literal> m_core;
|
vector<literal> m_core;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
node(literal const& l, node* parent) :
|
node(literal const &l, node *parent) : m_literal(l), m_parent(parent), m_status(status::open) {}
|
||||||
m_literal(l), m_parent(parent), m_status(status::open) {}
|
|
||||||
~node() {
|
~node() {
|
||||||
dealloc(m_left);
|
dealloc(m_left);
|
||||||
dealloc(m_right);
|
dealloc(m_right);
|
||||||
}
|
}
|
||||||
|
|
||||||
status get_status() const { return m_status; }
|
status get_status() const {
|
||||||
void set_status(status s) { m_status = s; }
|
return m_status;
|
||||||
literal const& get_literal() const { return m_literal; }
|
}
|
||||||
bool literal_is_null() const { return Config::is_null(m_literal); }
|
void set_status(status s) {
|
||||||
|
m_status = s;
|
||||||
|
}
|
||||||
|
literal const &get_literal() const {
|
||||||
|
return m_literal;
|
||||||
|
}
|
||||||
|
bool literal_is_null() const {
|
||||||
|
return Config::is_null(m_literal);
|
||||||
|
}
|
||||||
void split(literal const &a, literal const &b) {
|
void split(literal const &a, literal const &b) {
|
||||||
SASSERT(!Config::literal_is_null(a));
|
SASSERT(!Config::literal_is_null(a));
|
||||||
SASSERT(!Config::literal_is_null(b));
|
SASSERT(!Config::literal_is_null(b));
|
||||||
|
@ -66,9 +73,15 @@ namespace search_tree {
|
||||||
m_status = status::open;
|
m_status = status::open;
|
||||||
}
|
}
|
||||||
|
|
||||||
node* left() const { return m_left; }
|
node *left() const {
|
||||||
node* right() const { return m_right; }
|
return m_left;
|
||||||
node* parent() const { return m_parent; }
|
}
|
||||||
|
node *right() const {
|
||||||
|
return m_right;
|
||||||
|
}
|
||||||
|
node *parent() const {
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
node *find_active_node() {
|
node *find_active_node() {
|
||||||
if (m_status == status::active)
|
if (m_status == status::active)
|
||||||
|
@ -98,16 +111,21 @@ namespace search_tree {
|
||||||
m_right->display(out, indent + 2);
|
m_right->display(out, indent + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_core() const { return !m_core.empty(); }
|
bool has_core() const {
|
||||||
|
return !m_core.empty();
|
||||||
|
}
|
||||||
void set_core(vector<literal> const &core) {
|
void set_core(vector<literal> const &core) {
|
||||||
m_core = core;
|
m_core = core;
|
||||||
}
|
}
|
||||||
vector<literal> const & get_core() const { return m_core; }
|
vector<literal> const &get_core() const {
|
||||||
void clear_core() { m_core.clear(); }
|
return m_core;
|
||||||
|
}
|
||||||
|
void clear_core() {
|
||||||
|
m_core.clear();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Config>
|
template <typename Config> class tree {
|
||||||
class tree {
|
|
||||||
typedef typename Config::literal literal;
|
typedef typename Config::literal literal;
|
||||||
scoped_ptr<node<Config>> m_root = nullptr;
|
scoped_ptr<node<Config>> m_root = nullptr;
|
||||||
literal m_null_literal;
|
literal m_null_literal;
|
||||||
|
@ -148,13 +166,15 @@ namespace search_tree {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invariants:
|
// Invariants:
|
||||||
// Cores labeling nodes are subsets of the literals on the path to the node and the (external) assumption literals.
|
// Cores labeling nodes are subsets of the literals on the path to the node and the (external) assumption
|
||||||
// If a parent is open, then the one of the children is open.
|
// literals. If a parent is open, then the one of the children is open.
|
||||||
void close_with_core(node<Config> *n, vector<literal> const &C) {
|
void close_with_core(node<Config> *n, vector<literal> const &C) {
|
||||||
if (!n || n->get_status() == status::closed)
|
if (!n || n->get_status() == status::closed)
|
||||||
return;
|
return;
|
||||||
node<Config> *p = n->parent();
|
node<Config> *p = n->parent();
|
||||||
if (p && any_of(C, [](auto const& l) { return l == n->get_literal(); }})) {
|
if (p && any_of(C, [](auto const& l) {
|
||||||
|
return l == n->get_literal(); }
|
||||||
|
})) {
|
||||||
close_with_core(p, C);
|
close_with_core(p, C);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +188,8 @@ namespace search_tree {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given complementary sibling nodes for literals x and ¬x, sibling resolvent = (core_left ∪ core_right) \ {x, ¬x}
|
// Given complementary sibling nodes for literals x and ¬x, sibling resolvent = (core_left ∪ core_right) \ {x, ¬x}
|
||||||
vector<literal> compute_sibling_resolvent(node<Config>* left, node<Config>* right) {
|
vector<literal>
|
||||||
|
compute_sibling_resolvent(node<Config> *left, node<Config> *right) {
|
||||||
vector<literal> res;
|
vector<literal> res;
|
||||||
|
|
||||||
auto &core_l = left->get_core();
|
auto &core_l = left->get_core();
|
||||||
|
@ -233,8 +254,8 @@ namespace search_tree {
|
||||||
SASSERT(n != m_root.get());
|
SASSERT(n != m_root.get());
|
||||||
// all literals in conflict are on the path from root to n
|
// all literals in conflict are on the path from root to n
|
||||||
// remove assumptions from conflict to ensure this.
|
// remove assumptions from conflict to ensure this.
|
||||||
DEBUG_CODE(
|
DEBUG_CODE(auto on_path =
|
||||||
auto on_path = [&](literal const& a) {
|
[&](literal const &a) {
|
||||||
node<Config> *p = n;
|
node<Config> *p = n;
|
||||||
while (p) {
|
while (p) {
|
||||||
if (p->get_literal() == a)
|
if (p->get_literal() == a)
|
||||||
|
@ -243,8 +264,7 @@ namespace search_tree {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
SASSERT(all_of(conflict, [&](auto const& a) { return on_path(a); }));
|
SASSERT(all_of(conflict, [&](auto const &a) { return on_path(a); })););
|
||||||
);
|
|
||||||
|
|
||||||
while (n) {
|
while (n) {
|
||||||
if (any_of(conflict, [&](auto const &a) { return a == n->get_literal(); })) {
|
if (any_of(conflict, [&](auto const &a) { return a == n->get_literal(); })) {
|
||||||
|
@ -273,8 +293,8 @@ namespace search_tree {
|
||||||
|
|
||||||
auto p = n->parent();
|
auto p = n->parent();
|
||||||
while (p) {
|
while (p) {
|
||||||
if (p->left() && p->left()->get_status() == status::closed &&
|
if (p->left() && p->left()->get_status() == status::closed && p->right() &&
|
||||||
p->right() && p->right()->get_status() == status::closed) {
|
p->right()->get_status() == status::closed) {
|
||||||
p->set_status(status::closed);
|
p->set_status(status::closed);
|
||||||
n = p;
|
n = p;
|
||||||
p = n->parent();
|
p = n->parent();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue