LAL: Linear Arrangement Library 21.07.01
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
graph.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#include <vector>
46
47// lal includes
48#include <lal/definitions.hpp>
49
50namespace lal {
51namespace graphs {
52
69class graph {
70public:
71 /* CONSTRUCTORS */
72
74 graph() noexcept { }
79 graph(uint32_t n) noexcept {
80 _init(n);
81 }
86 graph(const graph& g) noexcept {
88 }
89#ifndef SWIG
94 graph(graph&& g) noexcept {
95 move_full_graph(std::move(g));
96 }
97#endif
99 virtual ~graph() noexcept { }
100
101 /* OPERATORS */
102
103#ifndef SWIG
108 graph& operator= (const graph& g) noexcept {
110 return *this;
111 }
116 graph& operator= (graph&& g) noexcept {
117 move_full_graph(std::move(g));
118 return *this;
119 }
120#endif
121
122 /* MODIFIERS */
123
130 virtual void init(uint32_t n) noexcept;
137 virtual void clear() noexcept;
138
149 virtual void normalise() noexcept;
150
158 virtual bool check_normalised() noexcept;
159
169 virtual void finish_bulk_add(bool norm = true, bool check = true) noexcept = 0;
170
171 /* SETTERS */
172
174 inline void set_normalised(bool v = true) noexcept { m_normalised = v; }
175
176 /* GETTERS */
177
185 virtual std::vector<edge_pair> get_Q() const noexcept = 0;
186
188 inline bool has_node(node u) const noexcept { return u < get_num_nodes(); }
189
191 virtual bool has_edge(node u, node v) const = 0;
192
194 inline uint32_t get_num_nodes() const noexcept
195 { return static_cast<uint32_t>(m_adjacency_list.size()); }
196
198 inline uint32_t get_num_edges() const noexcept { return m_num_edges; }
199
201 virtual std::vector<edge> get_edges() const noexcept = 0;
202
210 inline bool is_normalised() const noexcept { return m_normalised; }
211
213 virtual bool is_directed() const noexcept = 0;
215 virtual bool is_undirected() const noexcept = 0;
216
217protected:
221 uint32_t m_num_edges = 0;
234 bool m_normalised = true;
235
236protected:
238 virtual void _init(uint32_t n) noexcept;
240 virtual void _clear() noexcept;
241
243 void copy_full_graph(const graph& g) noexcept;
245 void move_full_graph(graph&& g) noexcept;
246
260 void __disjoint_union(const graph& g) noexcept;
261
263 virtual void extra_work_per_edge_add(node u, node v) noexcept;
265 virtual void extra_work_per_edge_remove(node u, node v) noexcept;
267 void normalise_after_add(bool norm, bool check) noexcept;
269 void normalise_after_remove(bool norm, bool check) noexcept;
270};
271
272} // -- namespace graphs
273} // -- namespace lal
Abstract class for graphs.
Definition graph.hpp:69
void copy_full_graph(const graph &g) noexcept
Copies all members of this class.
virtual void extra_work_per_edge_add(node u, node v) noexcept
Do some extra work after an edge has been added.
bool has_node(node u) const noexcept
Returns true if node u is in this graph.
Definition graph.hpp:188
bool is_normalised() const noexcept
Returns whether this graph is normalised or not.
Definition graph.hpp:210
virtual ~graph() noexcept
Destructor.
Definition graph.hpp:99
void __disjoint_union(const graph &g) noexcept
Disjoint union of graphs.
virtual void normalise() noexcept
Normalises the graph.
graph(const graph &g) noexcept
Copy constructor.
Definition graph.hpp:86
virtual bool has_edge(node u, node v) const =0
Returns true if the undirected edge (u, v) exists in the graph.
virtual bool is_directed() const noexcept=0
Returns whether this graph is directed or not.
graph & operator=(const graph &g) noexcept
Copy assignment operator.
Definition graph.hpp:108
virtual void _clear() noexcept
Clears memory for the graph class.
virtual void extra_work_per_edge_remove(node u, node v) noexcept
Do some extra work after an edge has been removed.
virtual bool is_undirected() const noexcept=0
Returns whether this graph is undirected or not.
virtual void finish_bulk_add(bool norm=true, bool check=true) noexcept=0
Completes the inner structure of the graph after adding a bulk of edges.
graph() noexcept
Empty constructor.
Definition graph.hpp:74
graph(graph &&g) noexcept
Move constructor.
Definition graph.hpp:94
virtual std::vector< edge_pair > get_Q() const noexcept=0
Returns all independent pairs of edges of this graph.
virtual void init(uint32_t n) noexcept
Allocates the necessary memory for this class.
uint32_t m_num_edges
Amount of edges of this graph.
Definition graph.hpp:221
uint32_t get_num_nodes() const noexcept
Returns the number of ndoes.
Definition graph.hpp:194
void normalise_after_remove(bool norm, bool check) noexcept
Normalise the graph after one (or more) edges have been removed.
void normalise_after_add(bool norm, bool check) noexcept
Normalise the graph after one (or more) edges have been added.
uint32_t get_num_edges() const noexcept
Returns the number of edges.
Definition graph.hpp:198
void move_full_graph(graph &&g) noexcept
Moves all members of this class.
std::vector< neighbourhood > m_adjacency_list
Data structure that implements the graph.
Definition graph.hpp:219
void set_normalised(bool v=true) noexcept
Sets whether this graph is normalised or not.
Definition graph.hpp:174
graph(uint32_t n) noexcept
Constructor with number of nodes.
Definition graph.hpp:79
virtual std::vector< edge > get_edges() const noexcept=0
Returns all edges of this graph.
virtual void _init(uint32_t n) noexcept
Initialises memory of graph class.
virtual void clear() noexcept
Frees the memory occupied by this graph.
virtual bool check_normalised() noexcept
Checks if the graph is normalised.
bool m_normalised
Is this graph normalised?
Definition graph.hpp:234
Main namespace of the library.
Definition definitions.hpp:48
uint32_t node
Node type.
Definition definitions.hpp:51
std::vector< node > neighbourhood
List of nodes.
Definition definitions.hpp:79