本文整理匯總了Python中networkx.weakly_connected_component_subgraphs方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.weakly_connected_component_subgraphs方法的具體用法?Python networkx.weakly_connected_component_subgraphs怎麽用?Python networkx.weakly_connected_component_subgraphs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.weakly_connected_component_subgraphs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: plan
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def plan(config, state_info):
"""Defines a startup plan for the MineMeld graph.
Args:
config (MineMeldConfig): config
state_info (dict): state_info for each node
Returns a dictionary where keys are node names and
values the satrtup command for the node.
"""
plan = {}
graph = _build_graph(config)
for subgraph in nx.weakly_connected_component_subgraphs(graph, copy=True):
plan.update(_plan_subgraph(subgraph, config, state_info))
return plan
示例2: setUp
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def setUp(self):
self.undirected = [
nx.connected_component_subgraphs,
nx.biconnected_component_subgraphs,
]
self.directed = [
nx.weakly_connected_component_subgraphs,
nx.strongly_connected_component_subgraphs,
nx.attracting_component_subgraphs,
]
self.subgraph_funcs = self.undirected + self.directed
self.D = nx.DiGraph()
self.D.add_edge(1, 2, eattr='red')
self.D.add_edge(2, 1, eattr='red')
self.D.node[1]['nattr'] = 'blue'
self.D.graph['gattr'] = 'green'
self.G = nx.Graph()
self.G.add_edge(1, 2, eattr='red')
self.G.node[1]['nattr'] = 'blue'
self.G.graph['gattr'] = 'green'
示例3: setUp
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def setUp(self):
self.undirected = [
nx.connected_component_subgraphs,
nx.biconnected_component_subgraphs,
]
self.directed = [
nx.weakly_connected_component_subgraphs,
nx.strongly_connected_component_subgraphs,
nx.attracting_component_subgraphs,
]
self.subgraph_funcs = self.undirected + self.directed
self.D = nx.DiGraph()
self.D.add_edge(1, 2, eattr='red')
self.D.add_edge(2, 1, eattr='red')
self.D.nodes[1]['nattr'] = 'blue'
self.D.graph['gattr'] = 'green'
self.G = nx.Graph()
self.G.add_edge(1, 2, eattr='red')
self.G.nodes[1]['nattr'] = 'blue'
self.G.graph['gattr'] = 'green'
示例4: setUp
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def setUp(self):
self.undirected = [
nx.connected_component_subgraphs,
nx.biconnected_component_subgraphs,
]
self.directed = [
nx.weakly_connected_component_subgraphs,
nx.strongly_connected_component_subgraphs,
nx.attracting_component_subgraphs,
]
self.subgraph_funcs = self.undirected + self.directed
self.D = nx.DiGraph()
self.D.add_edge(1, 2, eattr='red')
self.D.add_edge(2, 1, eattr='red')
self.D.nodes[1]['nattr'] = 'blue'
self.D.graph['gattr'] = 'green'
self.G = nx.Graph()
self.G.add_edge(1, 2, eattr='red')
self.G.nodes[1]['nattr'] = 'blue'
self.G.graph['gattr'] = 'green'
示例5: get_lcc
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def get_lcc(di_graph):
di_graph = di_graph.to_undirected().to_directed()
di_graph = max(nx.weakly_connected_component_subgraphs(di_graph), key=len)
tdl_nodes = di_graph.nodes()
nodeListMap = dict(zip(tdl_nodes, range(len(tdl_nodes))))
di_graph = nx.relabel_nodes(di_graph, nodeListMap, copy=True)
return di_graph, nodeListMap
示例6: ok_to_remove_node
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def ok_to_remove_node(g,n):
g0 = copy.deepcopy(g)
n0 = get_node_by_addr(g0,n.addr)
g0.remove_node(n0)
return len([x for x in networkx.weakly_connected_component_subgraphs(g0)]) <= 1
示例7: cluster_padding_nodes
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def cluster_padding_nodes(cfg,addrs):
nodes = [get_node_by_addr(cfg,x) for x in addrs]
sg = cfg.subgraph(nodes)
gs = [g for g in networkx.weakly_connected_component_subgraphs(sg)]
return sorted(gs,key=lambda x:len(x))
示例8: _handle_contained_in
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def _handle_contained_in(ctx):
# for each 'contained' tree, recursively build new trees based on
# scaling groups with generated ids
for contained_tree in nx.weakly_connected_component_subgraphs(
ctx.plan_contained_graph.reverse(copy=True)):
# extract tree root node id
node_id = nx.topological_sort(contained_tree)[0]
_build_multi_instance_node_tree_rec(
node_id=node_id,
contained_tree=contained_tree,
ctx=ctx)
ctx.deployment_contained_graph = ctx.deployment_node_graph.copy()
示例9: components
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def components(self) -> List['DAGCircuit']:
"""Split DAGCircuit into independent components"""
comps = nx.weakly_connected_component_subgraphs(self.graph)
return [DAGCircuit(comp) for comp in comps]
示例10: get_lcc
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def get_lcc(di_graph):
di_graph = max(nx.weakly_connected_component_subgraphs(di_graph), key=len)
tdl_nodes = list(di_graph.nodes())
nodeListMap = dict(zip(tdl_nodes, range(len(tdl_nodes))))
nx.relabel_nodes(di_graph, nodeListMap, copy=False)
return di_graph, nodeListMap
示例11: test_connected_component_subgraphs
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def test_connected_component_subgraphs(self):
wcc = nx.weakly_connected_component_subgraphs
cc = nx.connected_component_subgraphs
for G, C in self.gc:
U = G.to_undirected()
w = {frozenset(g) for g in wcc(G)}
c = {frozenset(g) for g in cc(U)}
assert_equal(w, c)
示例12: test_weakly_connected_component_subgraphs
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def test_weakly_connected_component_subgraphs(self):
wcc = nx.weakly_connected_component_subgraphs
cc = nx.connected_component_subgraphs
for G, C in self.gc:
U = G.to_undirected()
w = {frozenset(g) for g in wcc(G)}
c = {frozenset(g) for g in cc(U)}
assert_equal(w, c)
示例13: is_forest
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def is_forest(G):
"""
Returns True if `G` is a forest.
A forest is a graph with no undirected cycles.
For directed graphs, `G` is a forest if the underlying graph is a forest.
The underlying graph is obtained by treating each directed edge as a single
undirected edge in a multigraph.
Parameters
----------
G : graph
The graph to test.
Returns
-------
b : bool
A boolean that is True if `G` is a forest.
Notes
-----
In another convention, a directed forest is known as a *polyforest* and
then *forest* corresponds to a *branching*.
See Also
--------
is_branching
"""
if len(G) == 0:
raise nx.exception.NetworkXPointlessConcept('G has no nodes.')
if G.is_directed():
components = nx.weakly_connected_component_subgraphs
else:
components = nx.connected_component_subgraphs
return all(len(c) - 1 == c.number_of_edges() for c in components(G))
示例14: test_connected_raise
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
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)
示例15: prep_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import weakly_connected_component_subgraphs [as 別名]
def prep_graph(G, relabel=True, del_self_loops=True, maincc=True):
r"""
Preprocess a graphs according to the parameters provided.
By default the (digraphs) graphs are restricted to their main (weakly) connected component.
Trying to embed graphs with several CCs may cause some algorithms to put them infinitely far away.
Parameters
----------
G : graph
A NetworkX graph
relabel : bool, optional
Determines if the nodes are relabeled with consecutive integers 0..N
del_self_loops : bool, optional
Determines if self loops should be deleted from the graph. Default is True.
maincc : bool, optional
Determines if the graphs should be restricted to the main connected component or not. Default is True.
Returns
-------
G : graph
A preprocessed NetworkX graph
Ids : list of tuples
A list of (OldNodeID, NewNodeID). Returns None if relabel=False.
"""
# Remove self loops
if del_self_loops:
G.remove_edges_from(G.selfloop_edges())
# Restrict graph to its main connected component
if maincc:
if G.is_directed():
Gcc = max(nx.weakly_connected_component_subgraphs(G), key=len)
else:
Gcc = max(nx.connected_component_subgraphs(G), key=len)
else:
Gcc = G
# Relabel graph nodes in 0...N
if relabel:
Grl = nx.convert_node_labels_to_integers(Gcc, first_label=0, ordering='sorted')
# A list of (oldNodeID, newNodeID)
ids = list(zip(sorted(Gcc.nodes), sorted(Grl.nodes)))
return Grl, ids
else:
return Gcc, None