本文整理汇总了Python中networkx.edge_connectivity函数的典型用法代码示例。如果您正苦于以下问题:Python edge_connectivity函数的具体用法?Python edge_connectivity怎么用?Python edge_connectivity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了edge_connectivity函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_complete_graphs
def test_complete_graphs():
for n in range(5, 25, 5):
G = nx.complete_graph(n)
assert_equal(n-1, nx.node_connectivity(G))
assert_equal(n-1, nx.node_connectivity(G.to_directed()))
assert_equal(n-1, nx.edge_connectivity(G))
assert_equal(n-1, nx.edge_connectivity(G.to_directed()))
开发者ID:Bramas,项目名称:networkx,代码行数:7,代码来源:test_connectivity.py
示例2: test_directed_edge_connectivity
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
assert_equal(1, nx.edge_connectivity(G))
assert_equal(1, nx.local_edge_connectivity(G,1,4))
assert_equal(1, nx.edge_connectivity(G,1,4))
assert_equal(2, nx.edge_connectivity(D))
assert_equal(2, nx.local_edge_connectivity(D,1,4))
assert_equal(2, nx.edge_connectivity(D,1,4))
开发者ID:Bramas,项目名称:networkx,代码行数:9,代码来源:test_connectivity.py
示例3: test_brandes_erlebach
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)])
assert_equal(3,nx.local_edge_connectivity(G,1,11))
assert_equal(3,nx.edge_connectivity(G,1,11))
assert_equal(2,nx.local_node_connectivity(G,1,11))
assert_equal(2,nx.node_connectivity(G,1,11))
assert_equal(2,nx.edge_connectivity(G)) # node 5 has degree 2
assert_equal(2,nx.node_connectivity(G))
开发者ID:Bramas,项目名称:networkx,代码行数:13,代码来源:test_connectivity.py
示例4: test_complete_graphs
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__))
开发者ID:qinyushuang,项目名称:networkx,代码行数:14,代码来源:test_connectivity.py
示例5: test_tutte
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__))
开发者ID:qinyushuang,项目名称:networkx,代码行数:7,代码来源:test_connectivity.py
示例6: test_directed_edge_connectivity
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__))
开发者ID:qinyushuang,项目名称:networkx,代码行数:16,代码来源:test_connectivity.py
示例7: test_edge_cutset_random_graphs
def test_edge_cutset_random_graphs():
for i in range(5):
G = nx.fast_gnp_random_graph(50,0.2)
cutset = nx.minimum_edge_cut(G)
assert_equal(nx.edge_connectivity(G), len(cutset))
G.remove_edges_from(cutset)
assert_false(nx.is_connected(G))
开发者ID:Friedsoap,项目名称:networkx,代码行数:7,代码来源:test_cuts.py
示例8: test_graph_from_pr_2053
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__),
)
开发者ID:ProgVal,项目名称:networkx,代码行数:25,代码来源:test_disjoint_paths.py
示例9: draw_graph
def draw_graph(nodes, edges, graphs_dir, default_lang='all'):
lang_graph = nx.MultiDiGraph()
lang_graph.add_nodes_from(nodes)
for edge in edges:
if edges[edge] == 0:
lang_graph.add_edge(edge[0], edge[1])
else:
lang_graph.add_edge(edge[0], edge[1], weight=float(edges[edge]), label=str(edges[edge]))
# print graph info in stdout
# degree centrality
print('-----------------\n\n')
print(default_lang)
print(nx.info(lang_graph))
try:
# When ties are associated to some positive aspects such as friendship or collaboration,
# indegree is often interpreted as a form of popularity, and outdegree as gregariousness.
DC = nx.degree_centrality(lang_graph)
max_dc = max(DC.values())
max_dc_list = [item for item in DC.items() if item[1] == max_dc]
except ZeroDivisionError:
max_dc_list = []
# https://ru.wikipedia.org/wiki/%D0%9A%D0%BE%D0%BC%D0%BF%D0%BB%D0%B5%D0%BA%D1%81%D0%BD%D1%8B%D0%B5_%D1%81%D0%B5%D1%82%D0%B8
print('maxdc', str(max_dc_list), sep=': ')
# assortativity coef
AC = nx.degree_assortativity_coefficient(lang_graph)
print('AC', str(AC), sep=': ')
# connectivity
print("Слабо-связный граф: ", nx.is_weakly_connected(lang_graph))
print("количество слабосвязанных компонент: ", nx.number_weakly_connected_components(lang_graph))
print("Сильно-связный граф: ", nx.is_strongly_connected(lang_graph))
print("количество сильносвязанных компонент: ", nx.number_strongly_connected_components(lang_graph))
print("рекурсивные? компоненты: ", nx.number_attracting_components(lang_graph))
print("число вершинной связности: ", nx.node_connectivity(lang_graph))
print("число рёберной связности: ", nx.edge_connectivity(lang_graph))
# other info
print("average degree connectivity: ", nx.average_degree_connectivity(lang_graph))
print("average neighbor degree: ", sorted(nx.average_neighbor_degree(lang_graph).items(),
key=itemgetter(1), reverse=True))
# best for small graphs, and our graphs are pretty small
print("pagerank: ", sorted(nx.pagerank_numpy(lang_graph).items(), key=itemgetter(1), reverse=True))
plt.figure(figsize=(16.0, 9.0), dpi=80)
plt.axis('off')
pos = graphviz_layout(lang_graph)
nx.draw_networkx_edges(lang_graph, pos, alpha=0.5, arrows=True)
nx.draw_networkx(lang_graph, pos, node_size=1000, font_size=12, with_labels=True, node_color='green')
nx.draw_networkx_edge_labels(lang_graph, pos, edges)
# saving file to draw it with dot-graphviz
# changing overall graph view, default is top-bottom
lang_graph.graph['graph'] = {'rankdir': 'LR'}
# marking with blue nodes with maximum degree centrality
for max_dc_node in max_dc_list:
lang_graph.node[max_dc_node[0]]['fontcolor'] = 'blue'
write_dot(lang_graph, os.path.join(graphs_dir, default_lang + '_links.dot'))
# plt.show()
plt.savefig(os.path.join(graphs_dir, 'python_' + default_lang + '_graph.png'), dpi=100)
plt.close()
开发者ID:irinfox,项目名称:minor_langs_internet_analysis,代码行数:60,代码来源:get_links_info.py
示例10: test_icosahedral
def test_icosahedral():
G=nx.icosahedral_graph()
for flow_func in flow_funcs:
assert_equal(5, nx.node_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(5, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
开发者ID:qinyushuang,项目名称:networkx,代码行数:7,代码来源:test_connectivity.py
示例11: test_empty_graphs
def test_empty_graphs():
for k in range(5, 25, 5):
G = nx.empty_graph(k)
for flow_func in flow_funcs:
assert_equal(0, nx.node_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(0, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
开发者ID:qinyushuang,项目名称:networkx,代码行数:8,代码来源:test_connectivity.py
示例12: test_edge_connectivity_flow_vs_stoer_wagner
def test_edge_connectivity_flow_vs_stoer_wagner():
graph_funcs = [
nx.icosahedral_graph,
nx.octahedral_graph,
nx.dodecahedral_graph,
]
for graph_func in graph_funcs:
G = graph_func()
assert_equal(nx.stoer_wagner(G)[0], nx.edge_connectivity(G))
开发者ID:qinyushuang,项目名称:networkx,代码行数:9,代码来源:test_connectivity.py
示例13: test_white_harary_2
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()))
assert_equal(1, nx.node_connectivity(G))
assert_equal(1, nx.edge_connectivity(G))
开发者ID:Bramas,项目名称:networkx,代码行数:9,代码来源:test_connectivity.py
示例14: test_not_connected
def test_not_connected():
G = nx.Graph()
G.add_path([1, 2, 3])
G.add_path([4, 5])
for flow_func in flow_funcs:
assert_equal(nx.node_connectivity(G), 0,
msg=msg.format(flow_func.__name__))
assert_equal(nx.edge_connectivity(G), 0,
msg=msg.format(flow_func.__name__))
开发者ID:qinyushuang,项目名称:networkx,代码行数:9,代码来源:test_connectivity.py
示例15: _memo_connectivity
def _memo_connectivity(G, u, v, memo):
edge = (u, v)
if edge in memo:
return memo[edge]
if not G.is_directed():
redge = (v, u)
if redge in memo:
return memo[redge]
memo[edge] = nx.edge_connectivity(G, *edge)
return memo[edge]
开发者ID:jianantian,项目名称:networkx,代码行数:10,代码来源:test_edge_kcomponents.py
示例16: test_edge_cutset_random_graphs
def test_edge_cutset_random_graphs():
for i in range(5):
G = nx.fast_gnp_random_graph(50,0.2)
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)
assert_equal(nx.edge_connectivity(G), len(cutset))
G.remove_edges_from(cutset)
assert_false(nx.is_connected(G))
开发者ID:AlistairNWard,项目名称:configurationClass,代码行数:11,代码来源:test_cuts.py
示例17: _assert_subgraph_edge_connectivity
def _assert_subgraph_edge_connectivity(G, ccs_subgraph, k):
"""
tests properties of k-edge-connected subgraphs
the actual edge connectivity should be no less than k unless the cc is a
single node.
"""
for cc in ccs_subgraph:
C = G.subgraph(cc)
if len(cc) > 1:
connectivity = nx.edge_connectivity(C)
assert_greater_equal(connectivity, k)
开发者ID:jianantian,项目名称:networkx,代码行数:12,代码来源:test_edge_kcomponents.py
示例18: test_edge_cutset_random_graphs
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 = arbitrary_element(next(ccs))
G.add_edges_from((start, arbitrary_element(c)) 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__))
开发者ID:nishnik,项目名称:networkx,代码行数:12,代码来源:test_cuts.py
示例19: test_brandes_erlebach
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__))
开发者ID:qinyushuang,项目名称:networkx,代码行数:21,代码来源:test_connectivity.py
示例20: test_white_harary_1
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)
assert_equal(1, nx.node_connectivity(G))
assert_equal(3, nx.edge_connectivity(G))
开发者ID:Bramas,项目名称:networkx,代码行数:15,代码来源:test_connectivity.py
注:本文中的networkx.edge_connectivity函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论