LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
rand_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// C++ includes
45#include <random>
46
47// lal includes
48#include <lal/linear_arrangement.hpp>
49#include <lal/graphs/graph.hpp>
50#include <lal/properties/bipartite_graph_coloring.hpp>
51#include <lal/properties/bipartite_graph_colorability.hpp>
52
53namespace lal {
54namespace generate {
55
85public:
86
96 template <class graph_t>
97 rand_bipartite_arrangements(const graph_t& g, const uint64_t seed = 0) noexcept {
98 static_assert(std::is_base_of_v<graphs::graph, graph_t>);
100 init(seed);
101 }
102
113
120 (const properties::bipartite_graph_coloring& c, const uint64_t seed = 0)
121 noexcept
122 {
123 m_coloring = c;
124 init(seed);
125 }
132 (properties::bipartite_graph_coloring&& c, const uint64_t seed = 0)
133 noexcept
134 {
135 m_coloring = std::move(c);
136 init(seed);
137 }
138
140 [[nodiscard]] const linear_arrangement& get_arrangement() noexcept;
141
143 [[nodiscard]] const linear_arrangement& yield_arrangement() noexcept {
144 return get_arrangement();
145 }
146
147private:
155 void init(const uint64_t seed) noexcept;
156
164 void init_arrangement(const bool red_first) noexcept;
165
166private:
168 std::size_t m_n_blue;
170 std::size_t m_n_red;
171
173 std::mt19937 m_gen;
179 std::bernoulli_distribution m_red_or_blue;
180
187
190
193
194private:
201};
202
203} // -- namespace generate
204} // -- namespace lal
Random generation of arrangements of any bipartite graph.
Definition rand_bipartite_arrangements.hpp:84
rand_bipartite_arrangements(rand_bipartite_arrangements &&Gen) noexcept=default
Default move constructor.
const linear_arrangement & yield_arrangement() noexcept
Returns a linear arrangement constructed uniformly at random.
Definition rand_bipartite_arrangements.hpp:143
const linear_arrangement & get_arrangement() noexcept
Returns a linear arrangement constructed uniformly at random.
rand_bipartite_arrangements(properties::bipartite_graph_coloring &&c, const uint64_t seed=0) noexcept
Constructor with coloring.
Definition rand_bipartite_arrangements.hpp:132
void init_arrangement(const bool red_first) noexcept
Initializes this class.
std::bernoulli_distribution m_red_or_blue
Boolean values generator.
Definition rand_bipartite_arrangements.hpp:179
linear_arrangement m_arr
The arrangement generated by this class.
Definition rand_bipartite_arrangements.hpp:186
std::mt19937 m_gen
Random number generator.
Definition rand_bipartite_arrangements.hpp:173
void init(const uint64_t seed) noexcept
Initializes this class.
rand_bipartite_arrangements(const properties::bipartite_graph_coloring &c, const uint64_t seed=0) noexcept
Constructor with coloring.
Definition rand_bipartite_arrangements.hpp:120
std::size_t m_n_red
Number of red vertices.
Definition rand_bipartite_arrangements.hpp:170
properties::bipartite_graph_coloring m_coloring
Coloring of the bipartite graph.
Definition rand_bipartite_arrangements.hpp:189
rand_bipartite_arrangements(const graph_t &g, const uint64_t seed=0) noexcept
Constructor with graph.
Definition rand_bipartite_arrangements.hpp:97
std::size_t m_n_blue
Number of blue vertices.
Definition rand_bipartite_arrangements.hpp:168
properties::bipartite_graph_coloring::color_t m_what_in_left
What color do we find in the left half?
Definition rand_bipartite_arrangements.hpp:192
rand_bipartite_arrangements(const rand_bipartite_arrangements &Gen) noexcept=default
Default copy constructor.
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
uint64_t color_t
A useful type for colors.
Definition bipartite_graph_coloring.hpp:68
static constexpr color_t red
A color, called red, of value 0.
Definition bipartite_graph_coloring.hpp:72
static constexpr color_t blue
A color, called blue, of value 1.
Definition bipartite_graph_coloring.hpp:74
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