LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
|
Rooted tree graph class. More...
#include <rooted_tree.hpp>
Public Member Functions | |
rooted_tree () noexcept | |
Empty constructor. | |
rooted_tree (uint64_t n) noexcept | |
Constructor with number of nodes and root node. More... | |
rooted_tree (const rooted_tree &r) noexcept | |
Copy constructor. More... | |
rooted_tree (rooted_tree &&r) noexcept | |
Move constructor. More... | |
rooted_tree (const free_tree &t, node r) noexcept | |
Constructor with tree and root node. | |
virtual | ~rooted_tree () noexcept |
Destructor. | |
rooted_tree & | operator= (const rooted_tree &r) noexcept |
Copy assignment operator. More... | |
rooted_tree & | operator= (rooted_tree &&r) noexcept |
Move assignment operator. More... | |
rooted_tree & | remove_node (node u, bool connect=false, bool norm=true, bool check_norm=true) noexcept |
Remove a node from this tree. More... | |
rooted_tree & | add_edge (node s, node t, bool norm=true, bool check_norm=true) noexcept |
Adds an edge to the tree. More... | |
rooted_tree & | add_edge_bulk (node s, node t) noexcept |
Adds an edge to the graph. More... | |
void | finish_bulk_add (bool norm=true, bool check=true) noexcept |
Finishes adding edges in bulk. More... | |
rooted_tree & | add_edges (const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept |
Adds a list of edges to the graph. More... | |
rooted_tree & | set_edges (const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept |
Sets the edges to the graph. More... | |
rooted_tree & | remove_edge (node s, node t, bool norm=false, bool check_norm=true) noexcept |
Remove an edge from this graph. More... | |
rooted_tree & | remove_edges (const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept |
Remove an edge from this graph. More... | |
virtual rooted_tree & | remove_edges_incident_to (node u, bool norm=true, bool check_norm=true) noexcept |
Remove all edges incident to a given vertex. More... | |
void | disjoint_union (const rooted_tree &t, bool connect_roots=true) noexcept |
Disjoint union of trees. More... | |
void | init_rooted (const free_tree &t, node r) noexcept |
Initialiser with tree and root node. More... | |
void | calculate_size_subtrees () noexcept |
Calculates the number of nodes at every rooted subtree. More... | |
void | calculate_tree_type () noexcept |
Calculates the type of tree. More... | |
void | set_root (node r) noexcept |
Set the root of this tree. More... | |
bool | is_root_valid (node r) const noexcept |
Is the root valid? More... | |
bool | can_add_edge (node s, node t) const noexcept |
Can this edge be added? More... | |
bool | can_add_edges (const std::vector< edge > &edges) const noexcept |
Can these edges be added? More... | |
bool | is_rooted () const noexcept |
Returns whether this tree is a rooted tree. | |
bool | is_rooted_tree () const noexcept |
Is this tree a valid rooted tree? More... | |
node | get_root () const noexcept |
Return the root of this tree. | |
bool | has_root () const noexcept |
uint64_t | get_num_nodes_subtree (node u) const noexcept |
Get the size of a subtree rooted at a given node. More... | |
bool | are_size_subtrees_valid () const noexcept |
Is a recalculation of the subtree's sizes needed? More... | |
std::vector< edge > | get_edges_subtree (node u, bool relab=false) const noexcept |
Retrieve the edges of the subtree rooted at u. More... | |
rooted_tree | get_subtree (node u) const noexcept |
Retrieve the subtree rooted at node u. More... | |
free_tree | to_free_tree (bool norm=true, bool check=true) const noexcept |
Converts this rooted tree into a free tree (see free_tree). More... | |
head_vector | get_head_vector (const linear_arrangement &arr={}) const noexcept |
Converts a rooted tree into a head vector. More... | |
bool | subtree_contains_node (node r, node u) const noexcept |
Does the subtree rooted at r contain node u? More... | |
void | normalise () noexcept |
Normalises the graph. More... | |
bool | check_normalised () noexcept |
Checks if the graph is normalised. More... | |
std::vector< edge_pair > | get_Q () const noexcept |
Returns all independent pairs of edges of this graph. More... | |
std::vector< edge > | get_edges () const noexcept |
Returns all edges of this graph. | |
bool | has_edge (node u, node v) const noexcept |
Returns true if the edge \((u,v)\) exists in the graph. | |
const neighbourhood & | get_out_neighbours (node u) const noexcept |
Returns the out-neighbours of node u. More... | |
const neighbourhood & | get_in_neighbours (node u) const noexcept |
Returns the in-neighbours of node u. More... | |
uint64_t | get_degree (node u) const noexcept |
Returns the in-degree plus the out-degree of this vertex. More... | |
uint64_t | get_out_degree (node u) const noexcept |
Returns the out-degree of a node. | |
uint64_t | get_in_degree (node u) const noexcept |
Returns the in-degree of a node. | |
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. | |
undirected_graph | to_undirected (bool norm=true, bool check=true) const noexcept |
Converts this directed graph into an undirected graph. More... | |
virtual void | init (uint64_t n) noexcept |
Allocates the necessary memory for this class. More... | |
virtual void | clear () noexcept |
Frees the memory occupied by this graph. More... | |
void | set_normalised (bool v=true) noexcept |
Sets whether this graph is normalised or not. | |
bool | has_node (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_normalised () const noexcept |
Returns whether this graph is normalised or not. More... | |
bool | is_tree () const noexcept |
Is this graph is an actual tree? More... | |
uint64_t | get_component_representative (node u) const noexcept |
Representative node of the connected component in which u belongs. More... | |
bool | are_nodes_in_same_component (node u, node v) const noexcept |
Checks if two nodes are in the same connected component. More... | |
uint64_t | get_num_nodes_component (node u) const noexcept |
Amount of nodes in a connected component of the tree. More... | |
bool | is_of_tree_type (const tree_type &tt) const noexcept |
Returns whether this tree is of type tt. More... | |
bool | is_tree_type_valid () const noexcept |
Is the type of this tree valid? More... | |
std::vector< std::string > | get_tree_type_list () const noexcept |
Returns the list of types as a list of strings. More... | |
Protected Member Functions | |
virtual void | _init (uint64_t n) noexcept |
virtual void | _clear () noexcept |
void | update_union_find_after_edge_add (node u, node v, uint64_t *const root_of, uint64_t *const root_size) noexcept |
Update the union find data structure after an edge addition. More... | |
void | update_union_find_after_edge_add (node u, node v, uint64_t *const root_of, uint64_t *const root_size) const noexcept |
Update the union find data structure after an edge addition. More... | |
void | update_union_find_after_edge_remove (node u, node v, uint64_t *const root_of, uint64_t *const root_size) noexcept |
Update the union find data structure after an edge removal. More... | |
void | update_union_find_after_edge_remove (node u, node v, uint64_t *const root_of, uint64_t *const root_size) const noexcept |
Update the union find data structure after an edge removal. More... | |
void | update_union_find_before_incident_edges_removed (node u, uint64_t *const root_of, uint64_t *const root_size) noexcept |
Update the union find data structure before the removal of all edges incident to a node. More... | |
void | update_union_find_before_incident_edges_removed (node u, uint64_t *const root_of, uint64_t *const root_size) const noexcept |
Update the union find data structure before the removal of all edges incident to a node. More... | |
void | copy_full_rooted_tree (const rooted_tree &r) noexcept |
Copies all members of this class and the parent class. | |
void | move_full_rooted_tree (rooted_tree &&r) noexcept |
Moves all members of this class and the parent class. | |
void | copy_full_directed_graph (const directed_graph &d) noexcept |
Copies all members of this class and the parent class. | |
void | move_full_directed_graph (directed_graph &&d) 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 | __disjoint_union (const graph &g) noexcept |
Disjoint union of graphs. More... | |
virtual void | actions_after_remove_node (node u) noexcept |
Do some work before an node is removed. More... | |
virtual void | actions_before_remove_edges_incident_to (node u) noexcept |
Do some work before all edges incident to a node is removed. More... | |
virtual void | actions_after_add_edge (node u, node v) noexcept |
Do some extra work after an edge has been added. More... | |
virtual void | actions_after_remove_edge (node u, node v) noexcept |
Do some extra work after an edge has been removed. More... | |
void | normalise_after_edge_addition (bool norm, bool check) noexcept |
Normalise the graph after one (or more) edges have been added. | |
void | normalise_after_edge_removal (bool norm, bool check) noexcept |
Normalise the graph after one (or more) edges have been removed. | |
void | tree_only_init (uint64_t n) noexcept |
Initialises only the memory of class tree. More... | |
void | tree_only_clear () noexcept |
Clears the memory used by only class tree. | |
void | tree_only_copy (const tree &t) noexcept |
Copies only members of class tree. | |
void | tree_only_move (tree &&t) noexcept |
Moves only members of class tree. | |
void | actions_after_remove_node (node u) noexcept |
Do some work before an node is removed. More... | |
void | actions_after_add_edge (node u, node v) noexcept |
Do some work after the addition of an edge. More... | |
void | actions_after_remove_edge (node u, node v) noexcept |
Do some work after the removal of an edge. More... | |
void | actions_before_remove_edges_incident_to (node u) noexcept |
Do some work before all edges incident to a node is removed. More... | |
void | tree_only_set_edges () noexcept |
Updates the data structures of a tree after the graph structure has had its set of edges set. More... | |
void | tree_only_remove_node (node u) noexcept |
Removes a vertex from the union-find data structure. More... | |
void | fill_union_find () noexcept |
Protected Attributes | |
node | m_root = 0 |
Root of the tree. | |
bool | m_has_root = false |
Has the root been set? | |
std::vector< uint64_t > | m_size_subtrees |
Number of nodes of the subtrees rooted at a certain node. More... | |
bool | m_are_size_subtrees_valid = false |
Are the contents of m_size_subtrees valid? | |
std::vector< neighbourhood > | m_in_adjacency_list |
In-neighbours for every node. | |
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_normalised = true |
Is this graph normalised? More... | |
std::vector< node > | m_root_of |
The root of every vertex in the union-find data structure. | |
std::vector< uint64_t > | m_root_size |
The size of the connected component that a root belongs to. More... | |
std::array< bool, __tree_type_size > | m_tree_type |
The type of this tree. | |
bool | m_is_tree_type_valid = false |
Is the type of this tree valid? More... | |
Private Member Functions | |
void | disjoint_union (const directed_graph &g) noexcept |
Disjoint union of graphs. More... | |
virtual directed_graph & | remove_node (node u, bool norm=true, bool check_norm=true) noexcept |
Remove a node from this graph. More... | |
void | remove_single_edge (node u, node v, neighbourhood &out_u, neighbourhood &in_v) noexcept |
Removes a single edge. More... | |
Rooted tree graph class.
This class provides its users with an abstraction of rooted trees. Rooted trees are free trees in which one vertex has been designated as the root. Furthermore, in the context of this library, these trees' edges are always oriented towards the leaves (away from the root); this is known as an arborescence. Many methods require objects of this class to be valid rooted trees: the object must be a tree (see is_tree), must have a root (see has_root), and be a valid rooted tree (see is_rooted_tree).
Rooted trees can be constructed in two different ways:
Adding edges one by one has a serious drawback. In case the edges do not have a consistent orientation (either always pointing away from the root or always pointing towards it), the resulting graph is not considered to be a valid rooted tree (see is_rooted_tree). Therefore, consider the use of methods can_add_edge or can_add_edges. Recall that removal of edges is allowed at every moment.
The root allows defining further properties on these graphs. For example, the user can query information regarding subtrees of a particular rooted tree (see methods get_num_nodes_subtree, calculate_size_subtrees, get_edges_subtree, and get_subtree). Not every vertex can be a root of the tree: in general, only those vertices with in-degree 0 can (see is_root_valid).
This class allows flexibility of use of rooted trees regarding the root's choice (within the valid possibilities). Method set_root allows changing the root of rooted trees multiple times and at any time. However, when the tree has all of its edges then only one vertex can be the root (that with in-degree 0). For this reason, in case a user wants to build "different rooted trees on different roots", it is strongly recommended that first a lal::graphs::free_tree is built, and then create a rooted tree using the constructor rooted_tree(const free_tree&, node), or the method init_rooted.
|
inlinenoexcept |
Constructor with number of nodes and root node.
n | Number of vertices. |
|
inlinenoexcept |
Copy constructor.
r | Rooted tree. |
|
inlinenoexcept |
Move constructor.
r | Rooted tree. |
|
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 |
Clears the memory of rooted_tree, undirected_graph and graph classes.
Reimplemented from lal::graphs::directed_graph.
|
inlineprotectedvirtualnoexcept |
Initialises memory of rooted_tree, undirected_graph and graph classes.
Reimplemented from lal::graphs::directed_graph.
|
protectedvirtualnoexceptinherited |
Do some extra work after an edge has been added.
u | Node of the edge |
v | Node of the edge |
Reimplemented in lal::graphs::tree.
Do some work after the addition of an edge.
u | First node of the edge. |
v | Second node of the edge. |
Reimplemented from lal::graphs::graph.
|
protectedvirtualnoexceptinherited |
Do some extra work after an edge has been removed.
u | Node of the edge |
v | Node of the edge |
Reimplemented in lal::graphs::tree.
|
protectedvirtualnoexceptinherited |
Do some work after the removal of an edge.
u | First node of the edge. |
v | Second node of the edge. |
Reimplemented from lal::graphs::graph.
|
protectedvirtualnoexceptinherited |
Do some work before an node is removed.
u | Node to be removed. |
Reimplemented in lal::graphs::tree.
|
protectedvirtualnoexceptinherited |
Do some work before an node is removed.
u | Node to be removed. |
Reimplemented from lal::graphs::graph.
|
protectedvirtualnoexceptinherited |
Do some work before all edges incident to a node is removed.
u | Node whose incident edges are to be removed. |
Reimplemented in lal::graphs::tree.
|
protectedvirtualnoexceptinherited |
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.
|
virtualnoexcept |
Adds an edge to the tree.
This operation checks that the edge added does not produce cycles only in a debug compilation of the library. For a more controlled addition of the edges, see can_add_edge.
For developers: method lal::graphs::graph::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 normalised? |
check_norm | If norm is false then, should we check whether the result is normalised or not? This might be useful in case the resulting graph is normalised. If norm is true then check_norm is ignored. |
Reimplemented from lal::graphs::directed_graph.
|
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 function checks that edges will not produce cycles only in a debug compilation of the library. Moreover, this operation is faster than calling add_edge since the edges are added in bulk. For a more controlled addition of the edges, see can_add_edges.
For developers: method lal::graphs::graph::actions_after_add_edge is called after each edge has been added.
edges | The edges to be added. |
norm | Normalise the graph after the insertions. |
check_norm | If norm is false then, should we check whether the result is normalised or not? This might be useful in case the resulting graph is normalised. If norm is true then check_norm is ignored. |
Reimplemented from lal::graphs::directed_graph.
|
inlinenoexceptinherited |
Checks if two nodes are in the same connected component.
u | First node. |
v | Second node. |
|
inlinenoexcept |
Is a recalculation of the subtree's sizes needed?
If the method returns false then the user should call calculate_size_subtrees so that the size of every rooted subtree is recalculated. This information must be calculated prior to calling many functions of this library.
|
noexcept |
Calculates the number of nodes at every rooted subtree.
|
virtualnoexcept |
Calculates the type of tree.
See tree_type for the list of different tree types.
Implements lal::graphs::tree.
Can this edge be added?
In a tree, an edge can only be added if it does not produce cycles, and it has not been added before.
In a rooted tree, an edge can only be added if the in-degree of vertex t (see lal::graphs::directed_graph::get_in_degree) is exactly 1 after adding the edge.
s | First node of the edge. |
t | Second node of the edge. |
Reimplemented from lal::graphs::tree.
|
virtualnoexcept |
Can these edges be added?
In a tree, a set of edges can only be added if their addition to the tree do not produce cycles and none of them have been added before.
In a rooted tree, edges \((s,t)\) can only be added if the in-degree of vertex t (see lal::graphs::directed_graph::get_in_degree) is exactly 1 after adding the edge.
edges | List of edges. |
Reimplemented from lal::graphs::tree.
|
virtualnoexceptinherited |
Checks if the graph is normalised.
Checks, whether the graph's adjacency structure is normalised or not. In case it is, attribute m_normalised is set to true, so method is_normalised evaluates to true.
Reimplemented from lal::graphs::graph.
|
virtualnoexceptinherited |
Frees the memory occupied by this graph.
See _clear for details.
|
privatenoexcept |
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. |
|
noexcept |
Disjoint union of trees.
Append a rooted tree to this tree. All the nodes in t are relabelled starting at n, the number of nodes of the current tree. If the current graph has no vertices, then the whole input tree (and its state) is simply copied into this tree.
t | Input tree. |
connect_roots | The root of the current tree and the root of t are joined by an edge. |
|
inlineprotectednoexceptinherited |
Fills the Union-Find data structure assuming that the graph structure has all of its edges.
|
virtualnoexcept |
Finishes adding edges in bulk.
norm | Normalise the tree. |
check | Check whether the tree is normalised or not. |
Reimplemented from lal::graphs::directed_graph.
|
inlinenoexceptinherited |
Representative node of the connected component in which u belongs.
If the current graph lacks some edges then it is clearly a forest, i.e., a series of disconnected components. This function returns a representative node of the connected component to which node u belongs.
Further, let \(cc(u)\) be the connected component of vertex u, and \(rep(cc(u))\) be the representative node of \(cc(u)\). For every other node \(v\in cc(u)\), this function will return the same representative node \(rep(cc(u))\). Therefore, \(rep(cc(u))=rep(cc(v))\) for every \(v\in cc(u)\).
u | Input node. |
|
inlinenoexceptinherited |
Returns the in-degree plus the out-degree of this vertex.
Returns the degree of this vertex in its underlying undirected structure. Same as get_in_degree + get_out_degree.
u | Vertex |
|
noexcept |
Retrieve the edges of the subtree rooted at u.
The list of edges returned contains labels that depend on the parameter relab. If relab is true then the nodes are relabelled to numbers in \([0, n_u)\), where \(n_u\) is the number of nodes of the subtree rooted at u, rather than keeping the original labelling of numbers in \([0,n)\), where n is the number of nodes of the tree.
For example, consider the following complete binary tree of 7 nodes, whose edges are
0 -> 1 -> 3 -> 4 -> 2 -> 5 -> 6
The edges of the subtree rooted at 1 are "1 -> 3" and "1 -> 4", or, for the mathematically inclined \((1,3), (1,4)\).
This method can be seen as a way of relabelling nodes when u is the root of the tree and relab is true.
u | Root node of the subtree. |
relab | Should the nodes be relabelled? |
|
noexcept |
Converts a rooted tree into a head vector.
See Head vector page for a definition of 'head vector'.
arr | Linear arrangement of the tree. |
|
inlinenoexceptinherited |
Returns the in-neighbours of node u.
u | Node |
|
inlinenoexceptinherited |
Amount of nodes in a connected component of the tree.
If the current graph lacks some edges then it is clearly a forest, i.e., a series of disconnected components. This function returns the size of the component node u belongs to.
In rooted trees one has to see this amount as the number of nodes of the component in the underlying undirected forest.
u | Input node. |
|
inlinenoexcept |
Get the size of a subtree rooted at a given node.
u | Vertex of the tree. |
|
inlinenoexceptinherited |
Returns the out-neighbours of node u.
u | Node |
|
virtualnoexceptinherited |
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.
|
noexcept |
Retrieve the subtree rooted at node u.
u | Root of the subtree. |
|
noexceptinherited |
Returns the list of types as a list of strings.
|
inlinenoexcept |
Returns whether this rooted tree's root has been set or not (see set_root).
|
virtualnoexceptinherited |
Initialiser with tree and root node.
Constructs a rooted tree from a free tree and one of its nodes as the root of the rooted tree.
Since the edges are oriented, method is_tree must be true on parameter t (otherwise, some edges might not be reachable from the root and hence completely undirectable).
t | Undirected tree. |
r | Root of the rooted tree. A node of g. |
|
inlinenoexceptinherited |
Returns whether this graph is normalised or not.
A graph is normalised if every node's adjacency list is sorted increasingly. For this, use method normalise().
|
inlinenoexceptinherited |
Returns whether this tree is of type tt.
See method calculate_tree_type to know how to calculate a tree's type.
tt | Type of tree (see lal::graphs::tree_type). |
|
inlinenoexcept |
Is the root valid?
A root is valid if it has in-degree 0. This is calculated as a function of the current state of the tree.
r | Given node. |
|
inlinenoexcept |
|
inlinenoexceptinherited |
Is this graph is an actual tree?
Returns true if the number of edges is one less than the number of nodes. Note that this would not really be true if the addition of edges was not constrained. Since it is constrained in a way that no cycles can be produced (for example, see free_tree::add_edge, or free_tree::add_edges), then we only need to check for the number of edges.
For further characterisations of a tree see [23] (chapter 4, pages 32-33).
|
inlinenoexceptinherited |
Is the type of this tree valid?
This function enables users determine when this tree's type should be calculated.
In case this function returns false, users should call function calculate_tree_type in order to obtain a valid tree type. Note, however, that prior to calling the function the type of this tree might be lal::graphs::tree_type::unknown and that the tree type may remain lal::graphs::tree_type::unknown even after the type has been calculated. Nevertheless, users should be suspicious of a tree being of lal::graphs::tree_type::unknown (in fact, of any) type if this method returns false, yet they should be sure of it if the type was calculated via method calculate_tree_type.
|
virtualnoexceptinherited |
Normalises the graph.
Sorts this graph's adjacency list structure in increasing order.
Besides expensive, this method may be unnecessary. Method check_normalised() checks whether the graph is normalised or not; in case it is, using this method is completely unnecessary.
Reimplemented from lal::graphs::graph.
|
inlinenoexcept |
Copy assignment operator.
r | Rooted tree. |
|
inlinenoexcept |
Move assignment operator.
r | Rooted tree. |
|
virtualnoexcept |
Remove an edge from this graph.
For developers: method lal::graphs::graph::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 | Normalise the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalised or not? This might be useful in case the resulting graph is normalised. If norm is true then check_norm is ignored. |
Reimplemented from lal::graphs::directed_graph.
|
virtualnoexcept |
Remove an edge from this graph.
This operation is faster than removing edges one by one with remove_edge(node,node,bool,bool) since the edges are removed in bulk.
For developers: method lal::graphs::graph::actions_after_remove_edge is called after each edge has been removed.
edges | The edges to be deleted. |
norm | Normalise the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalised or not? This might be useful in case the resulting graph is normalised. If norm is true then check_norm is ignored. |
Reimplemented from lal::graphs::directed_graph.
|
virtualnoexcept |
Remove all edges incident to a given vertex.
This operation is faster than removing edges one by one with remove_edge(node,node,bool,bool) since the edges are removed in bulk.
For developers: method lal::graphs::graph::actions_after_remove_edge is called after each edge has been removed.
u | The node whose incident vertices are to be removed. |
norm | Normalise the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalised or not? This might be useful in case the resulting graph is normalised. If norm is true then check_norm is ignored. |
Reimplemented from lal::graphs::directed_graph.
|
noexcept |
Remove a node from this tree.
u | Valid node index: \(0 \le u < n\). |
connect | If connect is true then the parent of u is connected to the children of u, if both parent and children exist. |
norm | Normalise the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalised or not? This might be useful in case the resulting graph is normalised. If norm is true then check_norm is ignored. |
|
privatevirtualnoexcept |
Remove a node from this graph.
u | Valid node index: \(0 \le u < n\). |
norm | Normalise the graph after the deletion. |
check_norm | If norm is false then, should we check whether the result is normalised or not? This might be useful in case the resulting graph is normalised. If norm is true then check_norm is ignored. |
Reimplemented from lal::graphs::directed_graph.
|
privatenoexceptinherited |
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. |
|
virtualnoexcept |
Sets the edges to the graph.
Sets the edges of this graph assuming that the nodes indexed in the list are, at most, the number of nodes of this 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). For a more controlled addition of the edges, see can_add_edges.
Moreover, the current structure of the graph is cleared before setting the new edges.
edges | The edges to be added. |
norm | Normalise the graph after the insertions. |
check_norm | If norm is false then, should we check whether the result is normalised or not? This might be useful in case the resulting graph is normalised. If norm is true then check_norm is ignored. |
Reimplemented from lal::graphs::directed_graph.
|
inlinenoexcept |
Set the root of this tree.
Changing the root of a rooted tree invalidates information dependant on the tree. See the postconditions for details.
r | Vertex that represents the root. |
Does the subtree rooted at r contain node u?
u | Node to query within the subtree. |
r | The root of the subtree. Notice that if r is the actual root of the subtree, the tree certainly contains u. |
|
noexcept |
Converts this rooted tree into a free tree (see free_tree).
norm | Normalise the tree. |
check | Chech whether the resulting graph is normalised or not. |
|
noexceptinherited |
Converts this directed graph into an undirected graph.
The undirected graph returned connects two vertices \(u,v\) if these two vertices are connected by a directed edge ( \((u,v)\) or \((v,u)\)) in this graph. In other words, if two vertices are connected by a single directed edge, the direction is dropped. If two edges are connected by two directed edges (of opposite directions) then the two are merged into a single undirected edge.
norm | Normalise the graph. |
check | Chech whether the resulting graph is normalised or not. |
|
inlineprotectednoexceptinherited |
Initialises only the memory of class tree.
n | Number of vertices. |
|
protectednoexceptinherited |
Removes a vertex from the union-find data structure.
u | Node that was removed. |
|
protectednoexceptinherited |
Updates the data structures of a tree after the graph structure has had its set of edges set.
|
protectedvirtualnoexcept |
Update the union find data structure after an edge addition.
This is a helper method to be able to call a template in the lal::detail namespace which updates the union find data structure under addition of an edge.
u | Node that is connected to v. |
v | Node that is connected to u. |
root_of | Array of n elements relating each vertex to its root in the union find data structure. |
root_size | Array of n elements relating each vertex to the size of the connected component it belongs to. |
Implements lal::graphs::tree.
|
protectedvirtualnoexcept |
Update the union find data structure after an edge addition.
This is a helper method to be able to call a template in the lal::detail namespace which updates the union find data structure under addition of an edge.
u | Node that is connected to v. |
v | Node that is connected to u. |
root_of | Array of n elements relating each vertex to its root in the union find data structure. |
root_size | Array of n elements relating each vertex to the size of the connected component it belongs to. |
Implements lal::graphs::tree.
|
protectedvirtualnoexcept |
Update the union find data structure after an edge removal.
This is a helper method to be able to call a template in the lal::detail namespace which updates the union find data structure under removal of an edge.
u | Node that is connected to v. |
v | Node that is connected to u. |
root_of | Array of n elements relating each vertex to its root in the union find data structure. |
root_size | Array of n elements relating each vertex to the size of the connected component it belongs to. |
Implements lal::graphs::tree.
|
protectedvirtualnoexcept |
Update the union find data structure after an edge removal.
This is a helper method to be able to call a template in the lal::detail namespace which updates the union find data structure under removal of an edge.
u | Node that is connected to v. |
v | Node that is connected to u. |
root_of | Array of n elements relating each vertex to its root in the union find data structure. |
root_size | Array of n elements relating each vertex to the size of the connected component it belongs to. |
Implements lal::graphs::tree.
|
protectedvirtualnoexcept |
Update the union find data structure before the removal of all edges incident to a node.
This is a helper method to be able to call a template in the lal::detail namespace which updates the union find data structure under removal of all incident edges to a node.
u | Node whose incident edges are to be removed. |
root_of | Array of n elements relating each vertex to its root in the union find data structure. |
root_size | Array of n elements relating each vertex to the size of the connected component it belongs to. |
Implements lal::graphs::tree.
|
protectedvirtualnoexcept |
Update the union find data structure before the removal of all edges incident to a node.
This is a helper method to be able to call a template in the lal::detail namespace which updates the union find data structure under removal of all incident edges to a node.
u | Node whose incident edges are to be removed. |
root_of | Array of n elements relating each vertex to its root in the union find data structure. |
root_size | Array of n elements relating each vertex to the size of the connected component it belongs to. |
Implements lal::graphs::tree.
|
protectedinherited |
Is the type of this tree valid?
This attribute keeps track of whether or not the function calculate_tree_type should be called before querying the type of this tree via function is_of_tree_type.
|
protectedinherited |
Is this graph normalised?
An undirected graph is normalised 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-neighbours and in-neighbours of nodes be sorted.
This attribute is set to 'true' in all graph's initialisation and destruction (when clear() method is called).
|
protectedinherited |
The size of the connected component that a root belongs to.
Formally, m_size_of[v] is the size of the connected component of a root vertex v. A vertex u is a root vertex if there exists a vertex w such that m_root_of[w] = u.
In this context, root is within the union-find data structure.
|
protected |
Number of nodes of the subtrees rooted at a certain node.
Given a node u, m_size_subtrees[u] gives the number of nodes of the subtree rooted at u.