LAL: Linear Arrangement Library 21.07.01
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 - 2021
7 *
8 * This file is part of Linear Arrangement Library. To see the full code
9 * visit the webpage:
10 * https://github.com/lluisalemanypuig/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// 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
110 all_lab_rooted_trees(uint32_t n) noexcept
113 {
114 reset();
115 }
121#ifndef SWIG
127#endif
130
131 /* GETTERS */
132
134 inline bool end() const noexcept { return m_reached_end; }
135
136 /* MODIFIERS */
137
145 inline void next() noexcept {
146 if (not has_next() or m_reached_end) {
147 m_reached_end = true;
148 return;
149 }
150
151 // m_n > 1
152 if (m_cur_root < m_n - 1) {
153 ++m_cur_root;
154 }
155 else {
156 m_cur_root = 0;
159 }
160 }
161
163 inline void reset() noexcept {
165 __reset();
166 next();
167 }
168
170 inline bool has_next() const noexcept {
171 return m_cur_root + 1 < m_n or not m_gen_lab_free_tree.end();
172 }
173
174 inline graphs::rooted_tree yield_tree() noexcept {
175 const auto t = get_tree();
176 next();
177 return t;
178 }
179
180protected:
187 inline graphs::rooted_tree __get_tree() noexcept {
188#if defined DEBUG
189 assert(m_cur_root < m_n);
190#endif
192 }
193
195 inline void __reset() noexcept {
196 m_reached_end = false;
197 // so that in the next call the root is set to 0
198 m_cur_root = m_n - 1;
199 // the labeled free tree generator now points to the first tree
201 // deactivate all postprocessing of the free tree
203 }
204
205private:
213 bool m_reached_end = false;
214};
215
216} // -- namespace generate
217} // -- namespace lal
Base class for tree generators.
Definition tree_generator.hpp:87
tree_type_t get_tree() noexcept
Retrieve the generated tree.
Definition tree_generator.hpp:146
void deactivate_all_postprocessing_actions() noexcept
Deactivates all postprocessing actions.
Definition tree_generator.hpp:204
void activate_all_postprocessing_actions() noexcept
Definition tree_generator.hpp:192
const uint32_t m_n
Definition tree_generator.hpp:245
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:126
void reset() noexcept
Sets the generator to its initial state.
Definition all_lab_free_trees.hpp:140
void next() noexcept
Generates next tree.
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:174
void next() noexcept
Generates next tree.
Definition all_lab_rooted_trees.hpp:145
all_lab_free_trees m_gen_lab_free_tree
Labelled free tree generator.
Definition all_lab_rooted_trees.hpp:207
bool m_reached_end
Has the end of the generation been reached?
Definition all_lab_rooted_trees.hpp:213
void reset() noexcept
Sets the generator to its initial state.
Definition all_lab_rooted_trees.hpp:163
node m_cur_root
Current root.
Definition all_lab_rooted_trees.hpp:211
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition all_lab_rooted_trees.hpp:134
graphs::rooted_tree __get_tree() noexcept
Constructs the current tree.
Definition all_lab_rooted_trees.hpp:187
bool has_next() const noexcept
Returns whether there are more trees to generate.
Definition all_lab_rooted_trees.hpp:170
~all_lab_rooted_trees()=default
Default destructor.
all_lab_rooted_trees(uint32_t n) noexcept
Constructor with number of nodes.
Definition all_lab_rooted_trees.hpp:110
all_lab_rooted_trees(const all_lab_rooted_trees &Gen)=default
Copy constructor.
graphs::free_tree m_cur_ftree
Current labelled free tree.
Definition all_lab_rooted_trees.hpp:209
all_lab_rooted_trees(all_lab_rooted_trees &&Gen)=default
Move constructor.
void __reset() noexcept
Sets the iterator to its initial state.
Definition all_lab_rooted_trees.hpp:195
Free tree graph class.
Definition free_tree.hpp:59
Rooted tree graph class.
Definition rooted_tree.hpp:107
Main namespace of the library.
Definition definitions.hpp:48
uint32_t node
Node type.
Definition definitions.hpp:51