Unverified Commit 4874e486 authored by Fedor Scholz's avatar Fedor Scholz
Browse files

remove construction of supertree

parent d941908d
......@@ -6,22 +6,6 @@
namespace terraces {
struct supertree_node {
std::vector<index> leaves;
struct supertree_node* left;
struct supertree_node* right;
};
/**
* Create a new node without any subnodes
*/
struct supertree_node* new_node(std::vector<index>);
/**
* Return a string representing the given supertree via preorder traversal
*/
std::string pretty_preorder(struct supertree_node*);
/**
* Map the given constraints according to the given vector of indices.
* If the vector of indices is {2, 5, 6} for example, we get the mapping 2->0, 5->1, 6->2.
......@@ -54,18 +38,6 @@ size_t count_supertree(index, const constraints&);
*/
size_t count_supertree(const std::vector<index>&, const constraints&);
/**
* Generate the supertree given a number and a vector of contraints. Entry point for tree
* enumeration.
*/
std::vector<struct supertree_node*> construct_supertree(index, const constraints&);
/**
* Generate the supertree given a vector of indices and a vector of contraints.
*/
std::vector<struct supertree_node*> construct_supertree(const std::vector<index>&,
const constraints&);
} // namespace terraces
#endif
......@@ -4,27 +4,6 @@
namespace terraces {
struct supertree_node* new_node(std::vector<index> leaves) {
struct supertree_node* temp = new supertree_node;
temp->leaves = leaves;
temp->left = NULL;
temp->right = NULL;
return temp;
}
std::string pretty_preorder(struct supertree_node* s) {
std::string res = "";
if (s != NULL) {
for (size_t i = 0; i < s->leaves.size(); i++) {
res += std::to_string(s->leaves.at(i));
}
res += " ";
res += pretty_preorder(s->left);
res += pretty_preorder(s->right);
}
return res;
}
constraints map_constraints(const std::vector<index>& leaves, constraints c) {
std::map<index, index> m;
for (size_t i = 0; i < leaves.size(); i++) {
......@@ -139,57 +118,4 @@ size_t count_supertree(const std::vector<index>& leaves, const constraints& c) {
return number - bip_count;
}
std::vector<struct supertree_node*> construct_supertree(index number, const constraints& c) {
std::vector<index> leaves(number);
for (size_t i = 0; i < number; i++) {
leaves.at(i) = i;
}
return construct_supertree(leaves, c);
}
std::vector<struct supertree_node*> construct_supertree(const std::vector<index>& leaves,
const constraints& c) {
std::vector<struct supertree_node*> list;
if (leaves.size() == 1) {
list.push_back(new_node(leaves));
return list;
}
constraints new_c = map_constraints(leaves, c);
std::vector<std::vector<index>> sets = apply_constraints(leaves.size(), new_c);
sets = map_sets(leaves, sets);
bipartition_iterator bip_it(sets);
for (size_t i = 0; i < (1 << (sets.size() - 1)) - 1; i++) {
std::vector<index> left_set = std::get<0>(bip_it.get_bipartition());
std::vector<index> right_set = std::get<1>(bip_it.get_bipartition());
constraints left_bips = filter_constraints(left_set, c);
constraints right_bips = filter_constraints(right_set, c);
std::vector<struct supertree_node*> left_supertree =
construct_supertree(left_set, left_bips);
std::vector<struct supertree_node*> right_supertree =
construct_supertree(right_set, right_bips);
for (size_t j = 0; j < left_supertree.size(); j++) {
struct supertree_node* left = left_supertree.at(j);
for (size_t k = 0; k < right_supertree.size(); k++) {
struct supertree_node* right = right_supertree.at(k);
struct supertree_node* node =
new_node(leaves); // making leaves as root
node->left = left; // connect left subtree
node->right = right; // connect right subtree
list.push_back(node); // add this tree to list
}
}
bip_it.increase();
}
return list;
}
} // namespace terraces
......@@ -74,29 +74,5 @@ TEST_CASE("count_supertree6", "[supertree]") {
CHECK(count_supertree(5, c) == 9);
}
TEST_CASE("enum_supertree1", "[supertree]") {
constraints c = {};
std::vector<struct supertree_node*> s = construct_supertree(7, c);
CHECK(s.size() == 10395);
}
TEST_CASE("enum_supertree2", "[supertree]") {
constraints c = {{0, 1, 2}};
std::vector<struct supertree_node*> s = construct_supertree(3, c);
CHECK(s.size() == 1);
}
TEST_CASE("enum_supertree3", "[supertree]") {
constraints c = {{0, 1, 2}, {2, 3, 4}};
std::vector<struct supertree_node*> s = construct_supertree(4, c);
CHECK(s.size() == 1);
}
TEST_CASE("enum_supertree4", "[supertree]") {
constraints c = {{1, 0, 2}, {3, 4, 1}};
std::vector<struct supertree_node*> s = construct_supertree(5, c);
CHECK(s.size() == 9);
}
} // namespace tests
} // namespace terraces
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment