本文整理匯總了Python中networkx.edge_connectivity方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.edge_connectivity方法的具體用法?Python networkx.edge_connectivity怎麽用?Python networkx.edge_connectivity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.edge_connectivity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_brandes_erlebach
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_brandes_erlebach():
# Figure 1 chapter 7: Connectivity
# http://www.informatik.uni-augsburg.de/thi/personen/kammer/Graph_Connectivity.pdf
G = nx.Graph()
G.add_edges_from([(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 6), (3, 4),
(3, 6), (4, 6), (4, 7), (5, 7), (6, 8), (6, 9), (7, 8),
(7, 10), (8, 11), (9, 10), (9, 11), (10, 11)])
for flow_func in flow_funcs:
kwargs = dict(flow_func=flow_func)
assert_equal(3, local_edge_connectivity(G, 1, 11, **kwargs),
msg=msg.format(flow_func.__name__))
assert_equal(3, nx.edge_connectivity(G, 1, 11, **kwargs),
msg=msg.format(flow_func.__name__))
assert_equal(2, local_node_connectivity(G, 1, 11, **kwargs),
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.node_connectivity(G, 1, 11, **kwargs),
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.edge_connectivity(G, **kwargs), # node 5 has degree 2
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.node_connectivity(G, **kwargs),
msg=msg.format(flow_func.__name__))
示例2: test_white_harary_1
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_white_harary_1():
# Figure 1b white and harary (2001)
# # http://eclectic.ss.uci.edu/~drwhite/sm-w23.PDF
# A graph with high adhesion (edge connectivity) and low cohesion
# (vertex connectivity)
G = nx.disjoint_union(nx.complete_graph(4), nx.complete_graph(4))
G.remove_node(7)
for i in range(4, 7):
G.add_edge(0, i)
G = nx.disjoint_union(G, nx.complete_graph(4))
G.remove_node(G.order() - 1)
for i in range(7, 10):
G.add_edge(0, i)
for flow_func in flow_funcs:
assert_equal(1, nx.node_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
示例3: test_directed_edge_connectivity
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_directed_edge_connectivity():
G = nx.cycle_graph(10, create_using=nx.DiGraph()) # only one direction
D = nx.cycle_graph(10).to_directed() # 2 reciprocal edges
for flow_func in flow_funcs:
assert_equal(1, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(1, local_edge_connectivity(G, 1, 4, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(1, nx.edge_connectivity(G, 1, 4, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.edge_connectivity(D, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(2, local_edge_connectivity(D, 1, 4, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.edge_connectivity(D, 1, 4, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
示例4: _assert_local_cc_edge_connectivity
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def _assert_local_cc_edge_connectivity(G, ccs_local, k, memo):
"""
tests properties of k-edge-connected components
the local edge connectivity between each pair of nodes in the the original
graph should be no less than k unless the cc is a single node.
"""
for cc in ccs_local:
if len(cc) > 1:
# Strategy for testing a bit faster: If the subgraph has high edge
# connectivity then it must have local connectivity
C = G.subgraph(cc)
connectivity = nx.edge_connectivity(C)
if connectivity < k:
# Otherwise do the brute force (with memoization) check
_all_pairs_connectivity(G, cc, k, memo)
# Helper function
示例5: test_graph_from_pr_2053
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_graph_from_pr_2053():
G = nx.Graph()
G.add_edges_from([
('A', 'B'), ('A', 'D'), ('A', 'F'), ('A', 'G'),
('B', 'C'), ('B', 'D'), ('B', 'G'), ('C', 'D'),
('C', 'E'), ('C', 'Z'), ('D', 'E'), ('D', 'F'),
('E', 'F'), ('E', 'Z'), ('F', 'Z'), ('G', 'Z')])
for flow_func in flow_funcs:
kwargs = dict(flow_func=flow_func)
# edge disjoint paths
edge_paths = list(nx.edge_disjoint_paths(G, 'A', 'Z', **kwargs))
assert_true(are_edge_disjoint_paths(G, edge_paths), msg=msg.format(flow_func.__name__))
assert_equal(
nx.edge_connectivity(G, 'A', 'Z'),
len(edge_paths),
msg=msg.format(flow_func.__name__),
)
# node disjoint paths
node_paths = list(nx.node_disjoint_paths(G, 'A', 'Z', **kwargs))
assert_true(are_node_disjoint_paths(G, node_paths), msg=msg.format(flow_func.__name__))
assert_equal(
nx.node_connectivity(G, 'A', 'Z'),
len(node_paths),
msg=msg.format(flow_func.__name__),
)
示例6: test_karate
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_karate():
G = nx.karate_club_graph()
for flow_func in flow_funcs:
kwargs = dict(flow_func=flow_func)
# edge disjoint paths
edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 33, **kwargs))
assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__))
assert_equal(
nx.edge_connectivity(G, 0, 33),
len(edge_dpaths),
msg=msg.format(flow_func.__name__),
)
# node disjoint paths
node_dpaths = list(nx.node_disjoint_paths(G, 0, 33, **kwargs))
assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__))
assert_equal(
nx.node_connectivity(G, 0, 33),
len(node_dpaths),
msg=msg.format(flow_func.__name__),
)
示例7: test_brandes_erlebach
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_brandes_erlebach():
# Figure 1 chapter 7: Connectivity
# http://www.informatik.uni-augsburg.de/thi/personen/kammer/Graph_Connectivity.pdf
G = nx.Graph()
G.add_edges_from([(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 6), (3, 4),
(3, 6), (4, 6), (4, 7), (5, 7), (6, 8), (6, 9), (7, 8),
(7, 10), (8, 11), (9, 10), (9, 11), (10, 11)])
for flow_func in flow_funcs:
kwargs = dict(flow_func=flow_func)
assert_equal(3, local_edge_connectivity(G, 1, 11, **kwargs),
msg=msg.format(flow_func.__name__))
assert_equal(3, nx.edge_connectivity(G, 1, 11, **kwargs),
msg=msg.format(flow_func.__name__))
assert_equal(2, local_node_connectivity(G, 1, 11, **kwargs),
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.node_connectivity(G, 1, 11, **kwargs),
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.edge_connectivity(G, **kwargs), # node 5 has degree 2
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.node_connectivity(G, **kwargs),
msg=msg.format(flow_func.__name__))
示例8: test_directed_edge_connectivity
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_directed_edge_connectivity():
G = nx.cycle_graph(10, create_using=nx.DiGraph()) # only one direction
D = nx.cycle_graph(10).to_directed() # 2 reciprocal edges
for flow_func in flow_funcs:
assert_equal(1, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(1, local_edge_connectivity(G, 1, 4, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(1, nx.edge_connectivity(G, 1, 4, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.edge_connectivity(D, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(2, local_edge_connectivity(D, 1, 4, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(2, nx.edge_connectivity(D, 1, 4, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
示例9: is_k_edge_connected
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def is_k_edge_connected(G, k):
"""
Tests to see if a graph is k-edge-connected
See Also
--------
is_locally_k_edge_connected
Example
-------
>>> G = nx.barbell_graph(10, 0)
>>> is_k_edge_connected(G, k=1)
True
>>> is_k_edge_connected(G, k=2)
False
"""
if k < 1:
raise ValueError('k must be positive, not {}'.format(k))
# First try to quickly determine if G is not k-edge-connected
if G.number_of_nodes() < k + 1:
return False
elif any(d < k for n, d in G.degree()):
return False
else:
# Otherwise perform the full check
if k == 1:
return nx.is_connected(G)
elif k == 2:
return not nx.has_bridges(G)
else:
# return nx.edge_connectivity(G, cutoff=k) >= k
return nx.edge_connectivity(G) >= k
示例10: random_k_edge_connected_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def random_k_edge_connected_graph(size, k, p=.1, rng=None):
"""
Super hacky way of getting a random k-connected graph
Example:
>>> # ENABLE_DOCTEST
>>> import plottool_ibeis as pt
>>> from ibeis.algo.graph.nx_utils import * # NOQA
>>> size, k, p = 25, 3, .1
>>> rng = ut.ensure_rng(0)
>>> gs = []
>>> for x in range(4):
>>> G = random_k_edge_connected_graph(size, k, p, rng)
>>> gs.append(G)
>>> ut.quit_if_noshow()
>>> pnum_ = pt.make_pnum_nextgen(nRows=2, nSubplots=len(gs))
>>> fnum = 1
>>> for g in gs:
>>> pt.show_nx(g, fnum=fnum, pnum=pnum_())
"""
import sys
for count in it.count(0):
seed = None if rng is None else rng.randint(sys.maxsize)
# Randomly generate a graph
g = nx.fast_gnp_random_graph(size, p, seed=seed)
conn = nx.edge_connectivity(g)
# If it has exactly the desired connectivity we are one
if conn == k:
break
# If it has more, then we regenerate the graph with fewer edges
elif conn > k:
p = p / 2
# If it has less then we add a small set of edges to get there
elif conn < k:
# p = 2 * p - p ** 2
# if count == 2:
aug_edges = list(k_edge_augmentation(g, k))
g.add_edges_from(aug_edges)
break
return g
示例11: test_edge_cutset_random_graphs
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_edge_cutset_random_graphs():
for flow_func in flow_funcs:
for i in range(3):
G = nx.fast_gnp_random_graph(50, 0.25)
if not nx.is_connected(G):
ccs = iter(nx.connected_components(G))
start = next(ccs)[0]
G.add_edges_from( (start,c[0]) for c in ccs )
cutset = nx.minimum_edge_cut(G, flow_func=flow_func)
assert_equal(nx.edge_connectivity(G), len(cutset),
msg=msg.format(flow_func.__name__))
G.remove_edges_from(cutset)
assert_false(nx.is_connected(G), msg=msg.format(flow_func.__name__))
示例12: test_white_harary_2
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_white_harary_2():
# Figure 8 white and harary (2001)
# # http://eclectic.ss.uci.edu/~drwhite/sm-w23.PDF
G = nx.disjoint_union(nx.complete_graph(4), nx.complete_graph(4))
G.add_edge(0, 4)
# kappa <= lambda <= delta
assert_equal(3, min(nx.core_number(G).values()))
for flow_func in flow_funcs:
assert_equal(1, nx.node_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(1, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
示例13: test_complete_graphs
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_complete_graphs():
for n in range(5, 20, 5):
for flow_func in flow_funcs:
G = nx.complete_graph(n)
assert_equal(n-1, nx.node_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(n-1, nx.node_connectivity(G.to_directed(),
flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(n-1, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(n-1, nx.edge_connectivity(G.to_directed(),
flow_func=flow_func),
msg=msg.format(flow_func.__name__))
示例14: test_petersen
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_petersen():
G = nx.petersen_graph()
for flow_func in flow_funcs:
assert_equal(3, nx.node_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
示例15: test_tutte
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import edge_connectivity [as 別名]
def test_tutte():
G = nx.tutte_graph()
for flow_func in flow_funcs:
assert_equal(3, nx.node_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))