LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
|
Undirected graph class. More...
#include <undirected_graph.hpp>
Public Member Functions | |
undirected_graph () noexcept | |
Empty constructor. | |
undirected_graph (const uint64_t n) noexcept | |
Constructor with number of nodes. | |
undirected_graph (const undirected_graph &g) noexcept | |
Copy constructor. | |
undirected_graph (undirected_graph &&g) noexcept | |
Move constructor. | |
virtual | ~undirected_graph () noexcept |
Destructor. | |
undirected_graph & | operator= (const undirected_graph &g) noexcept |
Copy assignment operator. | |
undirected_graph & | operator= (undirected_graph &&g) noexcept |
Move assignment operator. | |
void | reserve_degree (const node u, const uint64_t d) noexcept |
Predicts that the degree of node u is d. | |
virtual undirected_graph & | add_node () noexcept |
Adds a vertex to the graph. | |
virtual undirected_graph & | remove_node (const node u, const bool norm=true, const bool check_norm=true) noexcept |
Remove a node from this graph. | |
virtual undirected_graph & | add_edge (const node s, const node t, const bool norm=true, const bool check_norm=true) noexcept |
Adds an edge to the graph. | |
undirected_graph & | add_edge_bulk (const node s, const node t) noexcept |
Adds an edge to the graph. | |
void | finish_bulk_add (const bool norm=true, const bool check=true) noexcept |
Completes the inner structure of the graph after adding a bulk of edges. | |
virtual undirected_graph & | add_edges (const std::vector< edge > &edges, const bool norm=true, const bool check_norm=true) noexcept |
Adds a list of edges to the graph. | |
virtual undirected_graph & | set_edges (const std::vector< edge > &edges, const bool norm=true, const bool check_norm=true) noexcept |
Sets the edges to the graph. | |
virtual undirected_graph & | remove_edge (const node s, const node t, const bool norm=true, const bool check_norm=true) noexcept |
Remove an edge from this graph. | |
virtual undirected_graph & | remove_edge_bulk (const node s, const node t) noexcept |
Removes an edge from the graph. | |
void | finish_bulk_remove (const bool norm=true, const bool check=true) noexcept |
Completes the inner structure of the graph after removing edges in bulk. | |
virtual undirected_graph & | remove_edges (const std::vector< edge > &edges, const bool norm=true, const bool check_norm=true) noexcept |
Remove an edge from this graph. | |
virtual undirected_graph & | remove_edges_incident_to (const node u, const bool norm=true, const bool check_norm=true) noexcept |
Remove all edges incident to a given vertex. | |
undirected_graph & | disjoint_union (const undirected_graph &g) noexcept |
Disjoint union of graphs. | |
std::vector< edge_pair > | get_Q () const noexcept |
Returns all independent pairs of edges of this graph. | |
std::vector< edge > | get_edges () const noexcept |
Returns all edges of this graph. | |
const neighbourhood & | get_neighbors (const node u) const noexcept |
Returns the neighbourhood of node u. | |
uint64_t | get_degree (const node u) const noexcept |
Returns the number of neighbors of u. | |
bool | has_edge (const node u, const node v) const noexcept |
Returns true if the edge \(\{u,v\}\) exists in the graph. | |
bool | is_directed () const noexcept |
Returns whether this graph is directed or not. | |
bool | is_undirected () const noexcept |
Returns whether this graph is undirected or not. | |
std::vector< undirected_graph > | get_connected_components () const noexcept |
Returns all the connected components of this graph as individual graphs. | |
virtual void | init (const uint64_t n) noexcept |
Allocates the necessary memory for this class. | |
virtual void | clear () noexcept |
Frees the memory occupied by this graph. | |
virtual void | normalize () noexcept |
Normalizes the graph. | |
virtual bool | check_normalized () noexcept |
Checks if the graph is normalized. | |
void | set_normalized (const bool v=true) noexcept |
Sets whether this graph is normalized or not. | |
bool | has_node (const node u) const noexcept |
Returns true if node u is in this graph. | |
uint64_t | get_num_nodes () const noexcept |
Returns the number of ndoes. | |
uint64_t | get_num_edges () const noexcept |
Returns the number of edges. | |
bool | is_normalized () const noexcept |
Returns whether this graph is normalized or not. | |
Protected Member Functions | |
virtual void | _init (const uint64_t n) noexcept |
Initializes the memory in the graph hierarchy. | |
virtual void | _clear () noexcept |
Clears the memory of undirected_graph and graph classes. | |
virtual void | actions_after_add_edge (const node u, const node v) noexcept |
Do some extra work after the addition of an edge. | |
virtual void | actions_after_add_edges (const edge_list &e) noexcept |
Do some extra work after the addition of several edges. | |
virtual void | actions_after_add_edges_bulk () noexcept |
Do some extra work after the addition of several edges in bulk. | |
virtual void | actions_after_remove_edge (const node u, const node v) noexcept |
Do some extra work after the removal of an edge. | |
virtual void | actions_after_remove_edges (const edge_list &e) noexcept |
Do some extra work after the removal of several edges. | |
virtual void | actions_after_remove_edges_bulk () noexcept |
Do some extra work after the removal of several edges in bulk. | |
virtual void | actions_before_remove_edges_incident_to (const node u) noexcept |
Do some work before all edges incident to a node is removed. | |
virtual void | actions_after_remove_node (const node u) noexcept |
Do some work before the removal of a vertex. | |
void | copy_full_undirected_graph (const undirected_graph &u) noexcept |
Copies all members of this class and the parent class. | |
void | move_full_undirected_graph (undirected_graph &&u) noexcept |
Moves all members of this class and the parent class. | |
void | copy_full_graph (const graph &g) noexcept |
Copies all members of this class. | |
void | move_full_graph (graph &&g) noexcept |
Moves all members of this class. | |
void | __add_node () noexcept |
Adds a node to the graph. | |
void | __disjoint_union (const graph &g) noexcept |
Disjoint union of graphs. | |
void | normalize_after_edge_addition (const bool norm, const bool check) noexcept |
Normalize the graph after one (or more) edges have been added. | |
void | normalize_after_edge_removal (const bool norm, const bool check) noexcept |
Normalize the graph after one (or more) edges have been removed. | |
Protected Attributes | |
std::vector< neighbourhood > | m_adjacency_list |
Data structure that implements the graph. | |
uint64_t | m_num_edges = 0 |
Amount of edges of this graph. | |
bool | m_is_normalized = true |
Is this graph normalized? | |
Private Member Functions | |
void | remove_single_edge (const node u, const node v, neighbourhood &out_u, neighbourhood &in_v) noexcept |
Removes a single edge. | |
Undirected graph class.
Class implementing an undirected graph, using the adjacency list data structure.
An object of this class must be initialized either with its constructor or with the init method. Edges can then be added one by one (see add_edge) or all at the same time (see add_edges).
|
inlinenoexcept |
Constructor with number of nodes.
n | Number of nodes. |
|
inlinenoexcept |
Copy constructor.
g | Undirected graph. |
|
inlinenoexcept |
Move constructor.
g | Undirected graph. |
|
protectednoexceptinherited |
Disjoint union of graphs.
Given a graph, append it to the current graph.
All the nodes in g are relabelled starting at n, the number of nodes of the current graph.
g | Input graph. |
|
inlineprotectedvirtualnoexcept |
Initializes the memory in the graph hierarchy.
Initializes memory of lal::graphs::undirected_graph and lal::graphs::graph classes.
n | Number of nodes |
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
protectedvirtualnoexcept |
Do some extra work after the addition of an edge.
u | Node of the edge |
v | Node of the edge |
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
protectedvirtualnoexcept |
Do some extra work after the addition of several edges.
e | List of edges. |
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
protectedvirtualnoexcept |
Do some extra work after the addition of several edges in bulk.
This method should only be called after several calls to undirected_graph::add_edge_bulk or directed_graph::add_edge_bulk.
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
protectedvirtualnoexcept |
Do some extra work after the removal of an edge.
u | Node of the edge |
v | Node of the edge |
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
protectedvirtualnoexcept |
Do some extra work after the removal of several edges.
e | List of edges. |
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
protectedvirtualnoexcept |
Do some extra work after the removal of several edges in bulk.
This method should only be called after several calls to undirected_graph::remove_edge_bulk or directed_graph::remove_edge_bulk.
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
protectedvirtualnoexcept |
Do some work before the removal of a vertex.
u | Node to be removed. |
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
protectedvirtualnoexcept |
Do some work before all edges incident to a node is removed.
u | Node whose incident edges are to be removed. |
Reimplemented from lal::graphs::graph.
Reimplemented in lal::graphs::free_tree.
|
virtualnoexcept |
Adds an edge to the graph.
Method actions_after_add_edge is called after the edge has been added.
s | Valid node index: \(0 \le s < n\). |
t | Valid node index: \(0 \le t < n\). |
norm | Should the graph be normalized? |
check_norm | If norm is false then, should we check whether the result is normalized or not? This might be useful in case the resulting graph is normalized. If norm is true then check_norm is ignored. |
Reimplemented in lal::graphs::free_tree.
|
noexcept |
Adds an edge to the graph.
This method only adds an edge, and does no other work: normalisation is not checked, and no extra work per edge is done.
s | Valid node index: \(0 \le s < n\). |
t | Valid node index: \(0 \le t < n\). |
|
virtualnoexcept |
Adds a list of edges to the graph.
This operation is faster than calling add_edge since the edges are added in bulk.
edges | The edges to be added. |
norm | Normalize the graph after the insertions. |
check_norm | If norm is false then, should we check whether the result is normalized or not? This might be useful in case the resulting graph is normalized. If norm is true then check_norm is ignored. |
Reimplemented in lal::graphs::free_tree.
|
virtualnoexceptinherited |
Checks if the graph is normalized.
Checks, whether the graph's adjacency structure is normalized or not. In case it is, attribute m_is_normalized is set to true, so method is_normalized evaluates to true.
Reimplemented in lal::graphs::directed_graph.
|
virtualnoexceptinherited |
Frees the memory occupied by this graph.
See _clear for details.
|
noexcept |
Disjoint union of graphs.
Given a graph, append it to the current graph.
All the nodes in g are relabelled starting at n, the number of nodes of the current graph.
g | Input graph. |
|
virtualnoexcept |
Completes the inner structure of the graph after adding a bulk of edges.
This is meant to be used after several calls to undirected_graph::add_edge_bulk, directed_graph::add_edge_bulk.
norm | Normalize the graph. |
check | Check wether the graph is normalized or not. |
Implements lal::graphs::graph.
|
virtualnoexcept |
Completes the inner structure of the graph after removing edges in bulk.
This is meant to be used after several calls to undirected_graph::remove_edge_bulk, directed_graph::remove_edge_bulk.
norm | Normalize the graph. |
check | Check wether the graph is normalized or not. |
Implements lal::graphs::graph.
|
inlinenodiscardnoexcept |
Returns the number of neighbors of u.
u | Node to be queried. |
|
inlinenodiscardnoexcept |
Returns the neighbourhood of node u.
u | Node. |
|
nodiscardvirtualnoexcept |
Returns all independent pairs of edges of this graph.
The set \(Q(G)\) is defined as the pairs of edges of \(G\), \(E(G) \times E(G)\), that are independent, that is, that share no nodes.
Implements lal::graphs::graph.
|
virtualnoexceptinherited |
|
inlinenodiscardnoexceptinherited |
Returns whether this graph is normalized or not.
A graph is normalized if every node's adjacency list is sorted increasingly. For this, use method normalize().
|
virtualnoexceptinherited |
Normalizes the graph.
Sorts this graph's adjacency list structure in increasing order.
Besides expensive, this method may be unnecessary. Method check_normalized() checks whether the graph is normalized or not; in case it is, using this method is completely unnecessary.
Reimplemented in lal::graphs::directed_graph.
|
inlinenoexcept |
Copy assignment operator.
g | Undirected graph. |
|
inlinenoexcept |
Move assignment operator.
g | Undirected graph. |
|
virtualnoexcept |
Remove an edge from this graph.
Method actions_after_remove_edge is called after the edge has been removed.
s | Valid node index: \(0 \le s < n\). |
t | Valid node index: \(0 \le t < n\). |
norm | Normalize the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalized or not? This might be useful in case the resulting graph is normalized. If norm is true then check_norm is ignored. |
Reimplemented in lal::graphs::free_tree.
|
virtualnoexcept |
Removes an edge from the graph.
This method only removes an edge, and does no other work: normalisation is not checked, and no extra work per edge is done.
s | Valid node index: \(0 \le s < n\). |
t | Valid node index: \(0 \le t < n\). |
Reimplemented in lal::graphs::free_tree.
|
virtualnoexcept |
Remove an edge from this graph.
This operation is faster than removing edges one by one with remove_edge since the edges are removed in bulk.
edges | The edges to be added. |
norm | Normalize the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalized or not? This might be useful in case the resulting graph is normalized. If norm is true then check_norm is ignored. |
Reimplemented in lal::graphs::free_tree.
|
virtualnoexcept |
Remove all edges incident to a given vertex.
This operation is faster than removing edges one by one with remove_edge since the edges are removed in bulk.
Method actions_after_remove_edge is called after each edge has been removed.
u | The node whose incident vertices are to be removed. |
norm | Normalize the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalized or not? This might be useful in case the resulting graph is normalized. If norm is true then check_norm is ignored. |
Reimplemented in lal::graphs::free_tree.
|
virtualnoexcept |
Remove a node from this graph.
u | Valid node index: \(0 \le u < n\). |
norm | Normalize the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalized or not? This might be useful in case the resulting graph is normalized. If norm is true then check_norm is ignored. |
Reimplemented in lal::graphs::free_tree.
|
privatenoexcept |
Removes a single edge.
u | First node of edge. |
v | Second node of edge. |
out_u | Out-neighbourhood of node u. |
in_v | In-neighbourhood of node v. |
|
inlinenoexcept |
Predicts that the degree of node u is d.
Memory of size d is reserved so that adding edges is done more efficiently.
u | Node to reserve the degree for. |
d | The amount of memory to reserve. |
|
virtualnoexcept |
Sets the edges to the graph.
This list of edges is assumed to be all the edges that are going to be added to this graph. This means that the internal data structures are constructed more efficiently than when adding edges one by one (see add_edge) or in several chunks (see add_edges).
The current structure of the graph is cleared before setting the new edges.
edges | The edges to be added. |
norm | Normalize the graph after the insertions. |
check_norm | If norm is false then, should we check whether the result is normalized or not? This might be useful in case the resulting graph is normalized. If norm is true then check_norm is ignored. |
Reimplemented in lal::graphs::free_tree.
|
protectedinherited |
Is this graph normalized?
An undirected graph is normalized iff every node's adjacency list is sorted in increasing order.
In directed graphs, however, it is necessary that the adjacency lists of the out-neighbors and in-neighbors of nodes be sorted.
This attribute is set to 'true' in all graph's initialisation and destruction (when clear() method is called).