Python networkx.number_weakly_connected_components() Examples
The following are 10
code examples of networkx.number_weakly_connected_components().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: split_train_test.py From EvalNE with MIT License | 6 votes |
def _sanity_check(G): r""" Helper function that checks if the input graphs contains a single connected component. Raises an error if not. Parameters ---------- G : graph A NetworkX graph Raises ------ ValueError If the graph has more than one (weakly) connected component. """ # Compute the number of connected components if G.is_directed(): num_ccs = nx.number_weakly_connected_components(G) else: num_ccs = nx.number_connected_components(G) # Rise an error if more than one CC exists if num_ccs != 1: raise ValueError("Input graph should contain one (weakly) connected component. " "This graph contains: " + str(num_ccs))
Example #2
Source File: graph.py From pybel with MIT License | 6 votes |
def list(self) -> List[Tuple[str, float]]: """Return a list of tuples that summarize the graph.""" number_nodes = self.graph.number_of_nodes() return [ ('Name', self.graph.name), ('Version', self.graph.version), ('Number of Nodes', number_nodes), ('Number of Namespaces', len(self.graph.count.namespaces())), ('Number of Edges', self.graph.number_of_edges()), ('Number of Annotations', len(self.graph.count.annotations())), ('Number of Citations', self.graph.number_of_citations()), ('Number of Authors', self.graph.number_of_authors()), ('Network Density', '{:.2E}'.format(nx.density(self.graph))), ('Number of Components', nx.number_weakly_connected_components(self.graph)), ('Number of Warnings', self.graph.number_of_warnings()), ]
Example #3
Source File: dagcircuit.py From quantumflow with Apache License 2.0 | 5 votes |
def component_nb(self) -> int: """Return the number of independent components that this DAGCircuit can be split into.""" return nx.number_weakly_connected_components(self.graph)
Example #4
Source File: test_weakly_connected.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def test_number_weakly_connected_components(self): for G, C in self.gc: U = G.to_undirected() w = nx.number_weakly_connected_components(G) c = nx.number_connected_components(U) assert_equal(w, c)
Example #5
Source File: test_weakly_connected.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def test_connected_raise(self): G=nx.Graph() assert_raises(NetworkXNotImplemented,nx.weakly_connected_components, G) assert_raises(NetworkXNotImplemented,nx.number_weakly_connected_components, G) assert_raises(NetworkXNotImplemented,nx.weakly_connected_component_subgraphs, G) assert_raises(NetworkXNotImplemented,nx.is_weakly_connected, G)
Example #6
Source File: test_weakly_connected.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_number_weakly_connected_components(self): for G, C in self.gc: U = G.to_undirected() w = nx.number_weakly_connected_components(G) c = nx.number_connected_components(U) assert_equal(w, c) # deprecated
Example #7
Source File: test_weakly_connected.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_null_graph(self): G = nx.DiGraph() assert_equal(list(nx.weakly_connected_components(G)), []) assert_equal(nx.number_weakly_connected_components(G), 0) assert_raises(nx.NetworkXPointlessConcept, nx.is_weakly_connected, G)
Example #8
Source File: test_weakly_connected.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_connected_raise(self): G = nx.Graph() assert_raises(NetworkXNotImplemented, nx.weakly_connected_components, G) assert_raises(NetworkXNotImplemented, nx.number_weakly_connected_components, G) assert_raises(NetworkXNotImplemented, nx.is_weakly_connected, G) # deprecated assert_raises(NetworkXNotImplemented, nx.weakly_connected_component_subgraphs, G)
Example #9
Source File: test_weakly_connected.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_number_weakly_connected_components(self): for G, C in self.gc: U = G.to_undirected() w = nx.number_weakly_connected_components(G) c = nx.number_connected_components(U) assert_equal(w, c)
Example #10
Source File: test_weakly_connected.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_connected_raise(self): G=nx.Graph() assert_raises(NetworkXNotImplemented,nx.weakly_connected_components, G) assert_raises(NetworkXNotImplemented,nx.number_weakly_connected_components, G) assert_raises(NetworkXNotImplemented,nx.weakly_connected_component_subgraphs, G) assert_raises(NetworkXNotImplemented,nx.is_weakly_connected, G)