template<AlephGraph GT, ArcFilter<
GT > SA = Dft_Show_Arc<GT>>
class Aleph::Unconnected_Components< GT, SA >
Compute the connected components of a graph.
This class takes a graph g (possibly disconnected) and computes all its connected components, storing them as a list of mapped subgraphs or as lists of node pointers.
A connected component is a maximal subgraph in which any two vertices are connected to each other by paths.
Algorithm:
- Iterate through all nodes of the graph
- For each unvisited node, perform DFS to find all reachable nodes
- Store each component as a separate subgraph or node list
Complexity:
- Time: O(V + E) where V is vertices and E is edges
- Space: O(V + E) for the output components
Usage example:
Inconnected_Components<decltype(g)> cc;
cc(g, components);
std::cout << "Graph has " << components.size() << " components\n";
Doubly-linked list (defined in tpl_dynList.H).
Graph implemented with double-linked adjacency lists.
Arc of graph implemented with double-linked adjacency lists.
- Note
- The name "Inconnected" is maintained for backward compatibility. It refers to finding components in a potentially disconnected graph.
-
Uses the
Build_Subtree control bit on nodes and arcs.
-
For graphs that are not directed: on a digraph the operations throw
std::domain_error. Following the arcs that leave each node does not give the components of a digraph, and an arc toward a component built before would point to a node of its subgraph; its strongly connected components are those of Tarjan_Connected_Components.
- Template Parameters
-
| GT | Graph type (must satisfy Aleph graph concept). |
| SA | Arc filter type (default: Dft_Show_Arc<GT>). |
- See also
- Build_Subgraph For building a single component
-
copy_graph() For copying an entire connected graph
Definition at line 467 of file tpl_components.H.
template<AlephGraph GT, ArcFilter<
GT > SA = Dft_Show_Arc<GT>>
template<template< class > class List>
Compute connected components as mapped subgraphs.
- Template Parameters
-
- Parameters
-
| [in] | g | Source graph. |
| [out] | list | Output list of subgraphs, one per component. |
- Exceptions
-
| std::domain_error | If g is a digraph. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 491 of file tpl_components.H.
References ah_domain_error_if, Aleph::and, Aleph::Dlink::append(), Aleph::Build_Subtree, Aleph::count(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::is_digraph(), IS_NODE_VISITED, GraphCommon< GT, Node, Arc >::reset_arcs(), GraphCommon< GT, Node, Arc >::reset_nodes(), and Aleph::Unconnected_Components< GT, SA >::sa.
template<AlephGraph GT, ArcFilter<
GT > SA = Dft_Show_Arc<GT>>
template<template< class > class List>
Compute connected components as lists of node pointers.
- Template Parameters
-
- Parameters
-
| [in] | g | Source graph. |
| [out] | list | Output list of node lists, one per component. |
- Exceptions
-
| std::domain_error | If g is a digraph. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 526 of file tpl_components.H.
References ah_domain_error_if, Aleph::and, Aleph::DynList< T >::append(), Aleph::Build_Subtree, Aleph::count(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::is_digraph(), IS_NODE_VISITED, l, GraphCommon< GT, Node, Arc >::reset_arcs(), GraphCommon< GT, Node, Arc >::reset_nodes(), Aleph::Unconnected_Components< GT, SA >::sa, and Aleph::DynList< T >::size().
template<AlephGraph GT, ArcFilter<
GT > SA = Dft_Show_Arc<GT>>
Check if a graph is connected.
- Parameters
-
- Returns
true if the graph has exactly one connected component (or is empty), false otherwise.
- Exceptions
-
| std::domain_error | If g is a digraph. |
Definition at line 610 of file tpl_components.H.
References ah_domain_error_if, Aleph::Unconnected_Components< GT, SA >::count_components(), GraphCommon< GT, Node, Arc >::get_num_nodes(), and GraphCommon< GT, Node, Arc >::is_digraph().
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().