本文整理汇总了Python中networkx.barbell_graph函数的典型用法代码示例。如果您正苦于以下问题:Python barbell_graph函数的具体用法?Python barbell_graph怎么用?Python barbell_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了barbell_graph函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_barbell
def test_barbell():
G = nx.barbell_graph(5, 0)
_check_augmentations(G)
G = nx.barbell_graph(5, 2)
_check_augmentations(G)
G = nx.barbell_graph(5, 3)
_check_augmentations(G)
G = nx.barbell_graph(5, 4)
_check_augmentations(G)
开发者ID:aparamon,项目名称:networkx,代码行数:12,代码来源:test_edge_augmentation.py
示例2: test_disconnected_graph_root_node
def test_disconnected_graph_root_node(self):
"""Test for a single component of a disconnected graph."""
G = nx.barbell_graph(3, 0)
H = nx.barbell_graph(3, 0)
mapping = dict(zip(range(6), 'abcdef'))
nx.relabel_nodes(H, mapping, copy=False)
G = nx.union(G, H)
chains = list(nx.chain_decomposition(G, root='a'))
expected = [
[('a', 'b'), ('b', 'c'), ('c', 'a')],
[('d', 'e'), ('e', 'f'), ('f', 'd')],
]
self.assertEqual(len(chains), len(expected))
for chain in chains:
self.assertContainsChain(chain, expected)
开发者ID:aparamon,项目名称:networkx,代码行数:15,代码来源:test_chains.py
示例3: test_clique_removal
def test_clique_removal():
graph = nx.complete_graph(10)
i, cs = apxa.clique_removal(graph)
idens = nx.density(graph.subgraph(i))
eq_(idens, 0.0, "i-set not found by clique_removal!")
for clique in cs:
cdens = nx.density(graph.subgraph(clique))
eq_(cdens, 1.0, "clique not found by clique_removal!")
graph = nx.trivial_graph(nx.Graph())
i, cs = apxa.clique_removal(graph)
idens = nx.density(graph.subgraph(i))
eq_(idens, 0.0, "i-set not found by ramsey!")
# we should only have 1-cliques. Just singleton nodes.
for clique in cs:
cdens = nx.density(graph.subgraph(clique))
eq_(cdens, 0.0, "clique not found by clique_removal!")
graph = nx.barbell_graph(10, 5, nx.Graph())
i, cs = apxa.clique_removal(graph)
idens = nx.density(graph.subgraph(i))
eq_(idens, 0.0, "i-set not found by ramsey!")
for clique in cs:
cdens = nx.density(graph.subgraph(clique))
eq_(cdens, 1.0, "clique not found by clique_removal!")
开发者ID:NikitaVAP,项目名称:pycdb,代码行数:25,代码来源:test_clique.py
示例4: test025_barbell_graph
def test025_barbell_graph(self):
""" Very small barbell graph. """
g = nx.barbell_graph(9, 2)
mate2 = nx.max_weight_matching( g, True )
td.showGraph(g, mate2, "test025_barbell_graph_edmonds")
mate1 = mv.max_cardinality_matching( g )
self.assertEqual( len(mate1), len(mate2) )
开发者ID:AlexanderSoloviev,项目名称:mv-matching,代码行数:7,代码来源:test_matching_compound.py
示例5: data
def data(ndata=100):
"""
On request, this returns a list of ``ndata`` randomly made data points.
:param ndata: (optional)
The number of data points to return.
:returns data:
A JSON string of ``ndata`` data points.
"""
# x = 10 * np.random.rand(ndata) - 5
# y = 0.5 * x + 0.5 * np.random.randn(ndata)
# A = 10. ** np.random.rand(ndata)
# c = np.random.rand(ndata)
# return json.dumps([{"_id": i, "x": x[i], "y": y[i], "area": A[i],
# "color": c[i]}
# for i in range(ndata)])
G = nx.barbell_graph(6, 3)
# this d3 example uses the name attribute for the mouse-hover value,
# so add a name to each node
for n in G:
G.node[n]['name'] = n
# write json formatted data
return json.dumps(json_graph.node_link_data(G)) # node-link format to serialize
开发者ID:erikted,项目名称:graphnetworkx-d3,代码行数:26,代码来源:views.py
示例6: test_good_partition
def test_good_partition(self):
"""Tests that a good partition has a high performance measure.
"""
G = barbell_graph(3, 0)
partition = [{0, 1, 2}, {3, 4, 5}]
assert_almost_equal(14 / 15, performance(G, partition))
开发者ID:iaciac,项目名称:networkx,代码行数:7,代码来源:test_quality.py
示例7: test_directed
def test_directed(self):
"""Tests that each directed edge is counted once in the cut."""
G = nx.barbell_graph(3, 0).to_directed()
S = {0, 1, 2}
T = {3, 4, 5}
assert_equal(nx.cut_size(G, S, T), 2)
assert_equal(nx.cut_size(G, T, S), 2)
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_cuts.py
示例8: force
def force(request):
G = nx.barbell_graph(6, 3)
# write json formatted data
d = json_graph.node_link_data(G) #node-link format to serialize
# write json to client
# json.dump(d, open('data/force.json', 'w'))
return HttpResponse(json.dumps(d), mimetype='application/json')
开发者ID:stephenLee,项目名称:virtual,代码行数:7,代码来源:views.py
示例9: test_graph
def test_graph(self):
G = nx.barbell_graph(5, 0)
S = set(range(5))
T = set(G) - S
expansion = nx.edge_expansion(G, S, T)
expected = 1 / 5
assert_equal(expected, expansion)
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_cuts.py
示例10: test_barbell
def test_barbell():
G = nx.barbell_graph(8, 4)
nx.add_path(G, [7, 20, 21, 22])
nx.add_cycle(G, [22, 23, 24, 25])
pts = set(nx.articulation_points(G))
assert_equal(pts, {7, 8, 9, 10, 11, 12, 20, 21, 22})
answer = [
{12, 13, 14, 15, 16, 17, 18, 19},
{0, 1, 2, 3, 4, 5, 6, 7},
{22, 23, 24, 25},
{11, 12},
{10, 11},
{9, 10},
{8, 9},
{7, 8},
{21, 22},
{20, 21},
{7, 20},
]
assert_components_equal(list(nx.biconnected_components(G)), answer)
G.add_edge(2,17)
pts = set(nx.articulation_points(G))
assert_equal(pts, {7, 20, 21, 22})
开发者ID:AmesianX,项目名称:networkx,代码行数:25,代码来源:test_biconnected.py
示例11: test_barbell
def test_barbell():
G=nx.barbell_graph(8,4)
G.add_path([7,20,21,22])
G.add_cycle([22,23,24,25])
pts=set(biconnected.articulation_points(G))
assert_equal(pts,set([7,8,9,10,11,12,20,21,22]))
answer = [set([12, 13, 14, 15, 16, 17, 18, 19]),
set([0, 1, 2, 3, 4, 5, 6, 7]),
set([22, 23, 24, 25]),
set([11, 12]),
set([10, 11]),
set([9, 10]),
set([8, 9]),
set([7, 8]),
set([21, 22]),
set([20, 21]),
set([7, 20])]
bcc=list(biconnected.biconnected_components(G))
bcc.sort(key=len, reverse=True)
assert_equal(bcc,answer)
G.add_edge(2,17)
pts=set(biconnected.articulation_points(G))
assert_equal(pts,set([7,20,21,22]))
开发者ID:NikitaVAP,项目名称:pycdb,代码行数:25,代码来源:test_biconnected.py
示例12: test_directed_symmetric
def test_directed_symmetric(self):
"""Tests that a cut in a directed graph is symmetric."""
G = nx.barbell_graph(3, 0).to_directed()
S = {0, 1, 4}
T = {2, 3, 5}
assert_equal(nx.cut_size(G, S, T), 8)
assert_equal(nx.cut_size(G, T, S), 8)
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_cuts.py
示例13: test_single_edge
def test_single_edge(self):
"""Tests for a cut of a single edge."""
G = nx.barbell_graph(3, 0)
S = {0, 1, 2}
T = {3, 4, 5}
assert_equal(nx.cut_size(G, S, T), 1)
assert_equal(nx.cut_size(G, T, S), 1)
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_cuts.py
示例14: test_symmetric
def test_symmetric(self):
"""Tests that the cut size is symmetric."""
G = nx.barbell_graph(3, 0)
S = {0, 1, 4}
T = {2, 3, 5}
assert_equal(nx.cut_size(G, S, T), 4)
assert_equal(nx.cut_size(G, T, S), 4)
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_cuts.py
示例15: test_disconnected_graph
def test_disconnected_graph(self):
"""Test for a graph with multiple connected components."""
G = nx.barbell_graph(3, 0)
H = nx.barbell_graph(3, 0)
mapping = dict(zip(range(6), 'abcdef'))
nx.relabel_nodes(H, mapping, copy=False)
G = nx.union(G, H)
chains = list(nx.chain_decomposition(G))
expected = [
[(0, 1), (1, 2), (2, 0)],
[(3, 4), (4, 5), (5, 3)],
[('a', 'b'), ('b', 'c'), ('c', 'a')],
[('d', 'e'), ('e', 'f'), ('f', 'd')],
]
self.assertEqual(len(chains), len(expected))
for chain in chains:
self.assertContainsChain(chain, expected)
开发者ID:aparamon,项目名称:networkx,代码行数:17,代码来源:test_chains.py
示例16: test_is_locally_k_edge_connected
def test_is_locally_k_edge_connected():
G = nx.barbell_graph(10, 0)
assert_true(is_locally_k_edge_connected(G, 5, 15, k=1))
assert_false(is_locally_k_edge_connected(G, 5, 15, k=2))
G = nx.Graph()
G.add_nodes_from([5, 15])
assert_false(is_locally_k_edge_connected(G, 5, 15, k=2))
开发者ID:aparamon,项目名称:networkx,代码行数:8,代码来源:test_edge_augmentation.py
示例17: test_lobster
def test_lobster(self):
import networkx as nx
import matplotlib.pyplot as plt
#g = nx.random_lobster(15, 0.8, 0.1)
g = nx.barbell_graph(7, 5)
#g = nx.erdos_renyi_graph(15, 0.2)
nx.draw_graphviz(g)
plt.savefig("/tmp/lobster.png")
print distancematrix.matrix_calls(g.edges(), 7)
开发者ID:axiak,项目名称:pydistancematrix,代码行数:9,代码来源:simpletest.py
示例18: test_barbell
def test_barbell(self):
G=networkx.barbell_graph(3,0)
partition=[[0,1,2],[3,4,5]]
M=networkx.blockmodel(G,partition)
assert_equal(sorted(M.nodes()),[0,1])
assert_equal(sorted(M.edges()),[(0,1)])
for n in M.nodes():
assert_equal(M.node[n]['nedges'],3)
assert_equal(M.node[n]['nnodes'],3)
assert_equal(M.node[n]['density'],1.0)
开发者ID:AhmedPho,项目名称:NetworkX_fork,代码行数:10,代码来源:test_block.py
示例19: test_barbell
def test_barbell(self):
G = nx.barbell_graph(3, 0)
partition = [{0, 1, 2}, {3, 4, 5}]
M = nx.quotient_graph(G, partition, relabel=True)
assert_equal(sorted(M), [0, 1])
assert_equal(sorted(M.edges()), [(0, 1)])
for n in M:
assert_equal(M.node[n]['nedges'], 3)
assert_equal(M.node[n]['nnodes'], 3)
assert_equal(M.node[n]['density'], 1)
开发者ID:argriffing,项目名称:networkx,代码行数:10,代码来源:test_minors.py
示例20: test_barbell_graph
def test_barbell_graph(self):
# The (3, 0) barbell graph has two triangles joined by a single edge.
G = nx.barbell_graph(3, 0)
chains = list(nx.chain_decomposition(G, root=0))
expected = [
[(0, 1), (1, 2), (2, 0)],
[(3, 4), (4, 5), (5, 3)],
]
self.assertEqual(len(chains), len(expected))
for chain in chains:
self.assertContainsChain(chain, expected)
开发者ID:aparamon,项目名称:networkx,代码行数:11,代码来源:test_chains.py
注:本文中的networkx.barbell_graph函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论