LAL: Linear Arrangement Library 23.01.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 - 2023
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 (lalemany@cs.upc.edu)
28 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
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 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office S124, 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:
125 static constexpr bool is_free = std::is_base_of_v<graphs::free_tree, tree_t>;
126
127public:
128 using generated_tree_t = tree_t;
129
130public:
131 /* CONSTRUCTORS */
132
134 _tree_generator() noexcept = default;
135
140 _tree_generator(uint64_t n) noexcept : m_n(n) { }
145 _tree_generator(const _tree_generator& Gen) = default;
146
152
154 virtual ~_tree_generator() = default;
155
156 /* INITIALIZE */
157
159 void init(uint64_t n) noexcept {
160 m_n = n;
162 }
163
165 void clear() noexcept { }
166
167 /* OPERATORS */
168
179
180 /* GETTERS */
181
195 tree_t get_tree() noexcept
196 {
197 auto t = __get_tree();
198
199 // free and rooted trees
200 if (m_normalise_tree) {
201 t.normalise();
202 }
204 t.calculate_tree_type();
205 }
206
207 // only free trees
208 if constexpr (is_free) {
209
210 }
211
212 // only rooted trees
213 if constexpr (not is_free) {
215 t.calculate_size_subtrees();
216 }
217 }
218 return t;
219 }
220
221 /* MODIFIERS */
222
234 virtual tree_t yield_tree() noexcept = 0;
235
243 set_normalise_tree(true);
246 }
247
255 set_normalise_tree(false);
258 }
259
260 /* SETTERS */
261
266 void set_normalise_tree(bool v) noexcept
267 { m_normalise_tree = v; }
268
273 void set_calculate_size_subtrees(bool v) noexcept
275
282 void set_calculate_tree_type(bool v) noexcept
283 { m_calculate_tree_type = v; }
284
285protected:
292 virtual tree_t __get_tree() noexcept = 0;
293
294protected:
296 uint64_t m_n = 0;
297
299 bool m_normalise_tree = true;
304};
305
306} // -- namespace generate
307} // -- namespace lal
Base class for tree generators.
Definition: tree_generator.hpp:123
uint64_t m_n
Number of vertices.
Definition: tree_generator.hpp:296
virtual tree_t yield_tree() noexcept=0
Yields a tree, advancing the generator if necessary.
void init(uint64_t n) noexcept
Initializes the tree generator.
Definition: tree_generator.hpp:159
void set_calculate_tree_type(bool v) noexcept
Should the tree be classified into types?
Definition: tree_generator.hpp:282
void set_calculate_size_subtrees(bool v) noexcept
Should the size of the subtrees be calculated?
Definition: tree_generator.hpp:273
void clear() noexcept
Clears the memory used by the generator.
Definition: tree_generator.hpp:165
_tree_generator() noexcept=default
Default constructor.
void deactivate_all_postprocessing_actions() noexcept
Deactivates all postprocessing actions.
Definition: tree_generator.hpp:254
virtual ~_tree_generator()=default
Default destructor.
bool m_normalise_tree
Normalise the generated tree.
Definition: tree_generator.hpp:299
void set_normalise_tree(bool v) noexcept
Should trees be normalised?
Definition: tree_generator.hpp:266
_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:242
_tree_generator(_tree_generator &&Gen)=default
Default move constructor.
bool m_calculate_size_subtrees
Calculate the size of the subtrees of the generated rooted tree.
Definition: tree_generator.hpp:301
virtual tree_t __get_tree() noexcept=0
Retrieve the generated tree.
_tree_generator(const _tree_generator &Gen)=default
Default copy constructor.
tree_t get_tree() noexcept
Retrieve the generated tree.
Definition: tree_generator.hpp:195
bool m_calculate_tree_type
Calculate the type of tree of the generated tree.
Definition: tree_generator.hpp:303
Main namespace of the library.
Definition: basic_types.hpp:50