LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
all_bipartite_arrangements.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/linear_arrangement.hpp>
46#include <lal/graphs/graph.hpp>
47#include <lal/properties/bipartite_graph_coloring.hpp>
48#include <lal/properties/bipartite_graph_colorability.hpp>
49
50namespace lal {
51namespace generate {
52
120public:
121
130 template <class graph_t>
131 all_bipartite_arrangements(const graph_t& g) {
132 static_assert(std::is_base_of_v<graphs::graph, graph_t>);
134 init();
135 }
136
147
161 m_coloring = std::move(c);
162 init();
163 }
164
166 ~all_bipartite_arrangements() noexcept = default;
167
176 [[nodiscard]] const linear_arrangement& get_arrangement() const noexcept
177 { return m_arr; }
178
180 [[nodiscard]] bool end() const noexcept { return m_do_mirror and m_reached_end_red; }
181
188 void next() noexcept;
189
191 void reset() noexcept {
192 m_do_mirror = false;
193 m_reached_end_blue = false;
194 m_reached_end_red = false;
195 init_arrangement(true);
196 }
197
203 [[nodiscard]] linear_arrangement yield_arrangement() noexcept {
204 // yes, a copy...
206 next();
207 return arr;
208 }
209
210private:
217 void init() noexcept;
218
226 void init_arrangement(const bool red_first) noexcept;
227
228private:
235
237 std::size_t m_n_blue;
239 std::size_t m_n_red;
240
247
249 properties::bipartite_graph_coloring m_coloring;
250
251private:
253 static constexpr properties::bipartite_graph_coloring::color_t blue =
254 properties::bipartite_graph_coloring::blue;
256 static constexpr properties::bipartite_graph_coloring::color_t red =
257 properties::bipartite_graph_coloring::red;
258};
259
260} // -- namespace generate
261} // -- namespace lal
Exhaustive enumeration of all bipartite arrangements of any bipartite graph.
Definition all_bipartite_arrangements.hpp:119
all_bipartite_arrangements(all_bipartite_arrangements &&Gen) noexcept=default
Default move constructor.
all_bipartite_arrangements(const all_bipartite_arrangements &Gen) noexcept=default
Default copy constructor.
all_bipartite_arrangements(const graph_t &g)
Constructor with graph.
Definition all_bipartite_arrangements.hpp:131
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition all_bipartite_arrangements.hpp:180
void init() noexcept
Initializes this class.
const linear_arrangement & get_arrangement() const noexcept
Returns the current linear arrangemnt.
Definition all_bipartite_arrangements.hpp:176
all_bipartite_arrangements(properties::bipartite_graph_coloring &&c) noexcept
Constructor with coloring.
Definition all_bipartite_arrangements.hpp:160
~all_bipartite_arrangements() noexcept=default
Default destructor.
void next() noexcept
Generates the next arrangement.
linear_arrangement m_arr
The arrangement generated by this class.
Definition all_bipartite_arrangements.hpp:246
bool m_reached_end_blue
Has the end of the iteration been reached for blue vertices?
Definition all_bipartite_arrangements.hpp:232
all_bipartite_arrangements(const properties::bipartite_graph_coloring &c) noexcept
Constructor with coloring.
Definition all_bipartite_arrangements.hpp:152
bool m_reached_end_red
Has the end of the iteration been reached for red vertices?
Definition all_bipartite_arrangements.hpp:234
std::size_t m_n_red
Number of red vertices.
Definition all_bipartite_arrangements.hpp:239
linear_arrangement yield_arrangement() noexcept
Constructs the current arrangement.
Definition all_bipartite_arrangements.hpp:203
properties::bipartite_graph_coloring m_coloring
Coloring of the bipartite graph.
Definition all_bipartite_arrangements.hpp:249
void reset() noexcept
Sets the generator to its initial state.
Definition all_bipartite_arrangements.hpp:191
std::size_t m_n_blue
Number of blue vertices.
Definition all_bipartite_arrangements.hpp:237
void init_arrangement(const bool red_first) noexcept
Initializes this class.
bool m_do_mirror
Has the end of the iteration been reached for mirrored arrangements?
Definition all_bipartite_arrangements.hpp:230
Linear arrangement of vertices.
Definition linear_arrangement.hpp:103
A class to represent a coloring of the vertices of a bipartite graph.
Definition bipartite_graph_coloring.hpp:60
bipartite_graph_coloring bipartite_coloring(const graphs::undirected_graph &g) noexcept
Calculates the coloring of a bipartite graph.
Main namespace of the library.
Definition basic_types.hpp:48