LAL: Linear Arrangement Library 21.07.01
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
tree_generator.hpp
1#pragma once
2
3// lal includes
4#include <lal/graphs/free_tree.hpp>
5#include <lal/graphs/rooted_tree.hpp>
6
7namespace lal {
8namespace generate {
9
78template<
79 class tree_type,
80 bool is_free = std::is_base_of_v<graphs::free_tree, tree_type>,
81 std::enable_if_t<
82 std::is_base_of_v<graphs::free_tree, tree_type> ||
83 std::is_base_of_v<graphs::rooted_tree, tree_type>,
84 bool
85 > = true
86>
88public:
90 typedef std::conditional_t<is_free, graphs::free_tree, graphs::rooted_tree>
92
93public:
94 /* CONSTRUCTORS */
95
100 _tree_generator(uint32_t n) noexcept : m_n(n) { }
105 _tree_generator(const _tree_generator& Gen) = default;
106#ifndef SWIG
112#endif
114 virtual ~_tree_generator() = default;
115
116 /* OPERATORS */
117
118#ifndef SWIG
129#endif
130
131 /* GETTERS */
132
146 inline tree_type_t get_tree() noexcept
147 {
148 auto t = __get_tree();
149
150 // free and rooted trees
151 if (m_normalise_tree) {
152 t.normalise();
153 }
155 t.calculate_tree_type();
156 }
157
158 // only free trees
159 if constexpr (is_free) {
160
161 }
162
163 // only rooted trees
164 if constexpr (not is_free) {
166 t.calculate_size_subtrees();
167 }
168 }
169 return t;
170 }
171
172 /* MODIFIERS */
173
184 virtual tree_type_t yield_tree() noexcept = 0;
185
197
209
210 /* SETTERS */
211
216 inline void set_normalise_tree(bool v) noexcept
217 { m_normalise_tree = v; }
218
223 inline void set_calculate_size_subtrees(bool v) noexcept
225
232 inline void set_calculate_tree_type(bool v) noexcept
233 { m_calculate_tree_type = v; }
234
235protected:
242 virtual tree_type_t __get_tree() noexcept = 0;
243
245 const uint32_t m_n;
246
248 bool m_normalise_tree = true;
253};
254
255} // -- namespace generate
256} // -- namespace lal
Base class for tree generators.
Definition tree_generator.hpp:87
void set_calculate_tree_type(bool v) noexcept
Should the tree be classified into types?
Definition tree_generator.hpp:232
_tree_generator & operator=(const _tree_generator &Gen)=default
Default copy assignment operator.
std::conditional_t< is_free, graphs::free_tree, graphs::rooted_tree > tree_type_t
Shorthand for the type of tree this class returns.
Definition tree_generator.hpp:91
bool m_calculate_size_subtrees
Calculate the size of the subtrees of the generated rooted tree.
Definition tree_generator.hpp:250
_tree_generator(const _tree_generator &Gen)=default
Default copy constructor.
void set_normalise_tree(bool v) noexcept
Should trees be normalised?
Definition tree_generator.hpp:216
bool m_normalise_tree
Normalise the generated tree.
Definition tree_generator.hpp:248
void set_calculate_size_subtrees(bool v) noexcept
Should the size of the subtrees be calculated?
Definition tree_generator.hpp:223
_tree_generator(_tree_generator &&Gen)=default
Default move constructor.
tree_type_t get_tree() noexcept
Retrieve the generated tree.
Definition tree_generator.hpp:146
virtual tree_type_t yield_tree() noexcept=0
Yields a tree, advancing the generator if necessary.
bool m_calculate_tree_type
Calculate the type of tree of the generated tree.
Definition tree_generator.hpp:252
_tree_generator(uint32_t n) noexcept
Constructor with number of nodes.
Definition tree_generator.hpp:100
virtual ~_tree_generator()=default
Default destructor.
virtual tree_type_t __get_tree() noexcept=0
Retrieve the generated tree.
void deactivate_all_postprocessing_actions() noexcept
Deactivates all postprocessing actions.
Definition tree_generator.hpp:204
void activate_all_postprocessing_actions() noexcept
Activates all postprocessing actions.
Definition tree_generator.hpp:192
const uint32_t m_n
Number of vertices.
Definition tree_generator.hpp:245
tree_type
Enumeration of several types of trees.
Definition tree_type.hpp:55
Main namespace of the library.
Definition definitions.hpp:48