本文整理汇总了Python中networkx.barbell_graph函数的典型用法代码示例。如果您正苦于以下问题:Python barbell_graph函数的具体用法?Python barbell_graph怎么用?Python barbell_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了barbell_graph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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!")
示例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) )
示例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
示例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))
示例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)
示例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')
示例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)
示例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})
示例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]))
示例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)
示例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)
示例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)
示例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)