LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
tree_generator.hpp
1/*********************************************************************
2 *
3 * Linear Arrangement Library - A library that implements a collection
4 * algorithms for linear arrangments of graphs.
5 *
6 * Copyright (C) 2019 - 2024
7 *
8 * This file is part of Linear Arrangement Library. The full code is available
9 * at:
10 * https://github.com/LAL-project/linear-arrangement-library.git
11 *
12 * Linear Arrangement Library is free software: you can redistribute it
13 * and/or modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * Linear Arrangement Library is distributed in the hope that it will be
18 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public License
23 * along with Linear Arrangement Library. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * Contact:
26 *
27 * LluĂ­s Alemany Puig (lluis.alemany.puig@upc.edu)
28 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
29 * CQL (Complexity and Quantitative Linguistics Lab)
30 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
31 * Webpage: https://cqllab.upc.edu/people/lalemany/
32 *
33 * Ramon Ferrer i Cancho (rferrericancho@cs.upc.edu)
34 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office 220, Omega building
37 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
38 * Webpage: https://cqllab.upc.edu/people/rferrericancho/
39 *
40 ********************************************************************/
41
42#pragma once
43
44// lal includes
45#include <lal/graphs/free_tree.hpp>
46#include <lal/graphs/rooted_tree.hpp>
47
48namespace lal {
49namespace generate {
50
119template <
120 class tree_t,
121 std::enable_if_t< std::is_base_of_v<graphs::tree, tree_t>, bool > = true
122>
124private:
126 static constexpr bool is_free = std::is_base_of_v<graphs::free_tree, tree_t>;
127
128public:
129 using generated_tree_t = tree_t;
130
131public:
132 /* CONSTRUCTORS */
133
135 _tree_generator() noexcept = default;
136
141 _tree_generator(const uint64_t n) noexcept : m_n(n) { }
146 _tree_generator(const _tree_generator& Gen) noexcept = default;
147
152 _tree_generator(_tree_generator&& Gen) noexcept = default;
153
155 virtual ~_tree_generator() noexcept = default;
156
157 /* INITIALIZE */
158
160 void init(const uint64_t n) noexcept {
161 m_n = n;
163 }
164
166 void clear() noexcept { }
167
168 /* OPERATORS */
169
180
181 /* GETTERS */
182
196 [[nodiscard]] tree_t get_tree() noexcept
197 {
198 tree_t t = __get_tree();
199
200 // free and rooted trees
201 if (m_normalize_tree) {
202 t.normalize();
203 }
205 t.calculate_tree_type();
206 }
207
208 // only free trees
209 if constexpr (is_free) {
210
211 }
212
213 // only rooted trees
214 if constexpr (not is_free) {
216 t.calculate_size_subtrees();
217 }
218 }
219 return t;
220 }
221
222 /* MODIFIERS */
223
235 [[nodiscard]] virtual tree_t yield_tree() noexcept = 0;
236
248
260
261 /* SETTERS */
262
267 void set_normalize_tree(const bool v) noexcept {
269 }
270
275 void set_calculate_size_subtrees(const bool v) noexcept {
277 }
278
285 void set_calculate_tree_type(const bool v) noexcept {
287 }
288
289protected:
296 [[nodiscard]] virtual tree_t __get_tree() noexcept = 0;
297
298protected:
300 uint64_t m_n = 0;
301
303 bool m_normalize_tree = true;
308};
309
310} // -- namespace generate
311} // -- namespace lal
Base class for tree generators.
Definition tree_generator.hpp:123
bool m_normalize_tree
Normalize the generated tree.
Definition tree_generator.hpp:303
void set_normalize_tree(const bool v) noexcept
Should trees be normalized?
Definition tree_generator.hpp:267
uint64_t m_n
Number of vertices.
Definition tree_generator.hpp:300
virtual tree_t yield_tree() noexcept=0
Yields a tree, advancing the generator if necessary.
void clear() noexcept
Clears the memory used by the generator.
Definition tree_generator.hpp:166
_tree_generator() noexcept=default
Default constructor.
void deactivate_all_postprocessing_actions() noexcept
Deactivates all postprocessing actions.
Definition tree_generator.hpp:255
static constexpr bool is_free
Helpful Boolean value to compact 'if constexpr' expressions.
Definition tree_generator.hpp:126
void set_calculate_size_subtrees(const bool v) noexcept
Should the size of the subtrees be calculated?
Definition tree_generator.hpp:275
void init(const uint64_t n) noexcept
Initializes the tree generator.
Definition tree_generator.hpp:160
_tree_generator(_tree_generator &&Gen) noexcept=default
Default move constructor.
_tree_generator & operator=(const _tree_generator &Gen)=default
Default copy assignment operator.
void activate_all_postprocessing_actions() noexcept
Activates all postprocessing actions.
Definition tree_generator.hpp:243
_tree_generator(const _tree_generator &Gen) noexcept=default
Default copy constructor.
virtual ~_tree_generator() noexcept=default
Default destructor.
void set_calculate_tree_type(const bool v) noexcept
Should the tree be classified into types?
Definition tree_generator.hpp:285
bool m_calculate_size_subtrees
Calculate the size of the subtrees of the generated rooted tree.
Definition tree_generator.hpp:305
virtual tree_t __get_tree() noexcept=0
Retrieve the generated tree.
tree_t get_tree() noexcept
Retrieve the generated tree.
Definition tree_generator.hpp:196
bool m_calculate_tree_type
Calculate the type of tree of the generated tree.
Definition tree_generator.hpp:307
Main namespace of the library.
Definition basic_types.hpp:48