51#include <lal/graphs/tree_type.hpp>
52#include <lal/graphs/rooted_tree.hpp>
53#include <lal/graphs/free_tree.hpp>
54#include <lal/detail/data_array.hpp>
68 std::enable_if_t< std::is_base_of_v<graphs::tree, tree_t>,
bool> =
true
70void classify_tree(
const tree_t& t, std::array<bool, graphs::__tree_type_size>& array)
83 array[
static_cast<std::size_t
>(tt)] =
true;
88 const auto get_only_neighbour =
90 if constexpr (std::is_base_of_v<lal::graphs::free_tree, tree_t>) {
91 return t.get_neighbours(u)[0];
94 return (t.get_out_degree(u) == 0 ?
95 t.get_in_neighbours(u)[0] :
96 t.get_out_neighbours(u)[0]
104 const uint64_t n = t.get_num_nodes();
135 bool is_linear =
false;
136 bool is_star =
false;
137 bool is_quasistar =
false;
138 bool is_bistar =
false;
139 bool is_caterpillar =
false;
140 bool is_spider =
false;
141 bool is_two_linear =
false;
144 uint64_t n_deg_eq_1 = 0;
145 uint64_t n_deg_eq_2 = 0;
146 uint64_t n_deg_ge_2 = 0;
147 uint64_t n_deg_ge_3 = 0;
155 const int64_t du =
static_cast<int64_t
>(t.get_degree(u));
156 deg_internal[u] += (du > 1)*du;
158 n_deg_eq_1 += du == 1;
159 n_deg_eq_2 += du == 2;
160 n_deg_ge_2 += du > 1;
161 n_deg_ge_3 += du > 2;
166 deg_internal[ get_only_neighbour(u) ] -= 1;
171 if (n_deg_eq_1 == 2) {
175 assert(n_deg_ge_2 == n - 2);
178 is_caterpillar =
true;
182 if (n_deg_ge_2 == 2 and n - n_deg_ge_2 == n_deg_eq_1) {
184 is_caterpillar =
true;
188 if (n - n_deg_ge_2 == n_deg_eq_1 and
190 (n_deg_eq_2 == 2 and n_deg_ge_3 == 0) or
191 (n_deg_ge_3 == 1 and n_deg_eq_2 == 1)
196 is_caterpillar =
true;
200 if (n_deg_ge_2 == 1 and n_deg_eq_1 == n - 1) {
202 is_caterpillar =
true;
206 if (n_deg_ge_3 == 1 and n_deg_eq_1 + n_deg_eq_2 == n - 1) {
211 if (n_deg_ge_3 == 2 and n_deg_eq_1 + n_deg_eq_2 == n - 2) {
212 is_two_linear =
true;
215 if (not is_caterpillar) {
224 n1 += deg_internal[u] == 1;
227 is_caterpillar = n1 == 2 or n1 == 0;
void classify_tree(const tree_t &t, std::array< bool, graphs::__tree_type_size > &array) noexcept
Classify a tree into one of the types lal::graphs::tree_type.
Definition: tree_classification.hpp:70
tree_type
Enumeration of several types of trees.
Definition: tree_type.hpp:57
@ caterpillar
Caterpillar trees.
@ singleton
Singleton tree.
@ two_linear
2-linear trees.
@ quasistar
Quasi star trees.
@ unknown
The tree could not be classified.
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53
Wrapper of a C array for autmatic deallocation of memory.
Definition: data_array.hpp:59