LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
all_lab_rooted_trees.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// C++ includes
45#if defined DEBUG
46#include <cassert>
47#endif
48
49// lal includes
50#include <lal/graphs/rooted_tree.hpp>
51#include <lal/generate/all_lab_free_trees.hpp>
52#include <lal/generate/tree_generator.hpp>
53
54namespace lal {
55namespace generate {
56
102class all_lab_rooted_trees : public _tree_generator<graphs::rooted_tree> {
103public:
104 /* CONSTRUCTORS */
105
107 all_lab_rooted_trees() noexcept : _tree_generator<graphs::rooted_tree>() { }
108
113 all_lab_rooted_trees(uint64_t n) noexcept {
114 init(n);
115 }
120 all_lab_rooted_trees(const all_lab_rooted_trees& Gen) noexcept = default;
121
127
130
135
136 /* INITIALIZE */
137
142 void init(uint64_t n) noexcept {
145 reset();
146 }
147
152 void clear() noexcept {
156 }
157
158 /* GETTERS */
159
161 [[nodiscard]] bool end() const noexcept { return m_reached_end; }
162
164 [[nodiscard]] node get_current_root() const noexcept { return m_cur_root; }
165
166 /* MODIFIERS */
167
175 void next() noexcept {
176 if (not has_next() or m_reached_end) {
177 m_reached_end = true;
178 return;
179 }
180
181 // m_n > 1
182 if (m_cur_root < m_n - 1) {
183 ++m_cur_root;
184 }
185 else {
186 m_cur_root = 0;
189 }
190 }
191
193 void reset() noexcept {
195 __reset();
196 next();
197 }
198
200 [[nodiscard]] bool has_next() const noexcept {
201 return m_cur_root + 1 < m_n or not m_gen_lab_free_tree.end();
202 }
203
204 [[nodiscard]] graphs::rooted_tree yield_tree() noexcept {
205 const auto t = get_tree();
206 next();
207 return t;
208 }
209
210protected:
217 [[nodiscard]] graphs::rooted_tree __get_tree() noexcept {
218#if defined DEBUG
219 assert(m_cur_root < m_n);
220#endif
222 }
223
225 void __reset() noexcept {
226 m_reached_end = false;
227 // so that in the next call the root is set to 0
228 m_cur_root = m_n - 1;
229 // the labeled free tree generator now points to the first tree
231 // deactivate all postprocessing of the free tree
233 }
234
235private:
243 bool m_reached_end = false;
244};
245
246} // -- namespace generate
247} // -- namespace lal
Base class for tree generators.
Definition tree_generator.hpp:123
uint64_t m_n
Definition tree_generator.hpp:300
void clear() noexcept
Clears the memory used by the generator.
Definition tree_generator.hpp:166
void deactivate_all_postprocessing_actions() noexcept
Deactivates all postprocessing actions.
Definition tree_generator.hpp:255
void init(const uint64_t n) noexcept
Initializes the tree generator.
Definition tree_generator.hpp:160
void activate_all_postprocessing_actions() noexcept
Definition tree_generator.hpp:243
tree_t get_tree() noexcept
Retrieve the generated tree.
Definition tree_generator.hpp:196
Exhaustive enumeration of labelled free trees.
Definition all_lab_free_trees.hpp:99
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition all_lab_free_trees.hpp:160
void clear() noexcept
Clears the memory used.
Definition all_lab_free_trees.hpp:151
void reset() noexcept
Sets the generator to its initial state.
Definition all_lab_free_trees.hpp:203
void next() noexcept
Generates next tree.
Definition all_lab_free_trees.hpp:171
void init(const uint64_t n) noexcept
Initializes the generator with a given number of vertices.
Definition all_lab_free_trees.hpp:140
Exhaustive enumeration of labelled rooted trees.
Definition all_lab_rooted_trees.hpp:102
graphs::rooted_tree yield_tree() noexcept
Yields a tree, advancing the generator if necessary.
Definition all_lab_rooted_trees.hpp:204
all_lab_rooted_trees(const all_lab_rooted_trees &Gen) noexcept=default
Copy constructor.
void next() noexcept
Generates next tree.
Definition all_lab_rooted_trees.hpp:175
all_lab_rooted_trees & operator=(const all_lab_rooted_trees &g) noexcept=default
Copy assignment operator.
void clear() noexcept
Clears the memory used.
Definition all_lab_rooted_trees.hpp:152
all_lab_rooted_trees(all_lab_rooted_trees &&Gen) noexcept=default
Move constructor.
node get_current_root() const noexcept
Returns the current root.
Definition all_lab_rooted_trees.hpp:164
all_lab_free_trees m_gen_lab_free_tree
Labelled free tree generator.
Definition all_lab_rooted_trees.hpp:237
void init(uint64_t n) noexcept
Initializes the generator with a given number of vertices.
Definition all_lab_rooted_trees.hpp:142
bool m_reached_end
Has the end of the generation been reached?
Definition all_lab_rooted_trees.hpp:243
void reset() noexcept
Sets the generator to its initial state.
Definition all_lab_rooted_trees.hpp:193
node m_cur_root
Current root.
Definition all_lab_rooted_trees.hpp:241
all_lab_rooted_trees() noexcept
Empty constructor.
Definition all_lab_rooted_trees.hpp:107
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition all_lab_rooted_trees.hpp:161
graphs::rooted_tree __get_tree() noexcept
Constructs the current tree.
Definition all_lab_rooted_trees.hpp:217
bool has_next() const noexcept
Returns whether there are more trees to generate.
Definition all_lab_rooted_trees.hpp:200
~all_lab_rooted_trees()=default
Default destructor.
all_lab_rooted_trees(uint64_t n) noexcept
Constructor with number of nodes.
Definition all_lab_rooted_trees.hpp:113
graphs::free_tree m_cur_ftree
Current labelled free tree.
Definition all_lab_rooted_trees.hpp:239
void __reset() noexcept
Sets the iterator to its initial state.
Definition all_lab_rooted_trees.hpp:225
Free tree graph class.
Definition free_tree.hpp:60
virtual void clear() noexcept
Frees the memory occupied by this graph.
Rooted tree graph class.
Definition rooted_tree.hpp:109
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51