LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
bipartite_graph_coloring.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/basic_types.hpp>
46#include <lal/detail/array.hpp>
47
48namespace lal {
49namespace properties {
50
61public:
68 typedef uint64_t color_t;
70 static constexpr color_t invalid_color = 2;
72 static constexpr color_t red = 0;
74 static constexpr color_t blue = 1;
75
76public:
78 bipartite_graph_coloring() noexcept = default;
84 bipartite_graph_coloring& operator= (const bipartite_graph_coloring&) noexcept = default;
86 bipartite_graph_coloring& operator= (bipartite_graph_coloring&&) noexcept = default;
87
92 bipartite_graph_coloring(std::size_t n) noexcept {
93 init(n);
94 }
95
98
103 void init(std::size_t n) noexcept {
105 }
106
108 [[nodiscard]] bool is_color_valid(node u) const noexcept {
109 return get_color_of(u) != invalid_color;
110 }
111
113 [[nodiscard]] std::size_t size() const noexcept { return m_coloring.size(); }
114
116 [[nodiscard]] color_t get_color_of(node u) const noexcept { return m_coloring[u]; }
118 [[nodiscard]] color_t& get_color_of(node u) noexcept { return m_coloring[u]; }
119
121 [[nodiscard]] color_t operator[] (node u) const noexcept { return m_coloring[u]; }
123 [[nodiscard]] color_t& operator[] (node u) noexcept { return m_coloring[u]; }
124
126 [[nodiscard]] color_t operator[] (node_t u) const noexcept { return m_coloring[*u]; }
128 [[nodiscard]] color_t& operator[] (node_t u) noexcept { return m_coloring[*u]; }
129
130private:
137};
138
139} // -- namespace properties
140} // -- namespace lal
A class to represent a coloring of the vertices of a bipartite graph.
Definition bipartite_graph_coloring.hpp:60
std::size_t size() const noexcept
Returns the size of this m_coloring (the number of vertices)
Definition bipartite_graph_coloring.hpp:113
detail::array< color_t > m_coloring
The array that contains the m_coloring.
Definition bipartite_graph_coloring.hpp:136
bipartite_graph_coloring() noexcept=default
Default constructor.
color_t get_color_of(node u) const noexcept
Returns the color of node u.
Definition bipartite_graph_coloring.hpp:116
void init(std::size_t n) noexcept
Initializes this object with n vertices.
Definition bipartite_graph_coloring.hpp:103
static constexpr color_t invalid_color
An invalid color, used to initialize colors to an invalid value.
Definition bipartite_graph_coloring.hpp:70
uint64_t color_t
A useful type for colors.
Definition bipartite_graph_coloring.hpp:68
color_t operator[](node u) const noexcept
Returns the color of node u.
Definition bipartite_graph_coloring.hpp:121
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
bool is_color_valid(node u) const noexcept
Returns whether or not the color of vertex u is valid.
Definition bipartite_graph_coloring.hpp:108
color_t & get_color_of(node u) noexcept
Returns the color of node u.
Definition bipartite_graph_coloring.hpp:118
~bipartite_graph_coloring()=default
Default destrutor.
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
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59
std::size_t size() const noexcept
Size of the array.
Definition array.hpp:215
void resize(const std::size_t new_size) noexcept
Resize the array.
Definition array.hpp:187
Typesafe node type.
Definition basic_types.hpp:70