本文整理汇总了Python中networkx.balanced_tree方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.balanced_tree方法的具体用法?Python networkx.balanced_tree怎么用?Python networkx.balanced_tree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.balanced_tree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def tree(start, height, r=2, role_start=0):
"""Builds a balanced r-tree of height h
INPUT:
-------------
start : starting index for the shape
height : int height of the tree
r : int number of branches per node
role_start : starting index for the roles
OUTPUT:
-------------
graph : a tree shape graph, with ids beginning at start
roles : list of the roles of the nodes (indexed starting at role_start)
"""
graph = nx.balanced_tree(r, height)
roles = [0] * graph.number_of_nodes()
return graph, roles
示例2: test_graphs
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_graphs(self):
H = nx.complete_graph(2)
H.add_edge(2, 3)
graphs = [nx.complete_graph(7),
dnx.chimera_graph(2, 1, 3),
nx.balanced_tree(5, 3),
nx.barbell_graph(8, 11),
nx.cycle_graph(5),
H]
for G in graphs:
tw, order = dnx.treewidth_branch_and_bound(G)
self.assertEqual(dnx.elimination_order_width(G, order), tw)
tw, order = dnx.min_width_heuristic(G)
self.assertEqual(dnx.elimination_order_width(G, order), tw)
tw, order = dnx.min_fill_heuristic(G)
self.assertEqual(dnx.elimination_order_width(G, order), tw)
tw, order = dnx.max_cardinality_heuristic(G)
self.assertEqual(dnx.elimination_order_width(G, order), tw)
示例3: setUp
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def setUp(self):
self.K = nx.krackhardt_kite_graph()
self.P3 = nx.path_graph(3)
self.P4 = nx.path_graph(4)
self.K5 = nx.complete_graph(5)
self.C4=nx.cycle_graph(4)
self.T=nx.balanced_tree(r=2, h=2)
self.Gb = nx.Graph()
self.Gb.add_edges_from([(0,1), (0,2), (1,3), (2,3),
(2,4), (4,5), (3,5)])
F = nx.florentine_families_graph()
self.F = F
示例4: setUp
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def setUp(self):
self.K = nx.krackhardt_kite_graph()
self.P3 = nx.path_graph(3)
self.P4 = nx.path_graph(4)
self.K5 = nx.complete_graph(5)
self.C4 = nx.cycle_graph(4)
self.T = nx.balanced_tree(r=2, h=2)
self.Gb = nx.Graph()
self.Gb.add_edges_from([(0, 1), (0, 2), (1, 3), (2, 3),
(2, 4), (4, 5), (3, 5)])
F = nx.florentine_families_graph()
self.F = F
self.LM = nx.les_miserables_graph()
示例5: test_real_degenerate
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_real_degenerate(self):
"""Verify that the Takagi decomposition returns a matrix that is unitary and results in a
correct decomposition when input a real but highly degenerate matrix. This test uses the
adjacency matrix of a balanced tree graph."""
g = nx.balanced_tree(2, 4)
a = nx.to_numpy_array(g)
rl, U = dec.takagi(a)
assert np.allclose(U @ U.conj().T, np.eye(len(a)))
assert np.allclose(U @ np.diag(rl) @ U.T, a)
示例6: make_complete_rary_tree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def make_complete_rary_tree(self, h=2, r=2):
self.add_edges_from(nx.balanced_tree(h=h, r=r,
create_using=nx.DiGraph()).edges)
self.linkage_dist = {n: d for n, (d, _) in
self.maxdist_from_roots().items()}
示例7: test_richclub2
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_richclub2():
T = nx.balanced_tree(2,10)
rc = nx.richclub.rich_club_coefficient(T,normalized=False)
assert_equal(rc,{0:4092/(2047*2046.0),
1:(2044.0/(1023*1022)),
2:(2040.0/(1022*1021))})
#def test_richclub2_normalized():
# T = nx.balanced_tree(2,10)
# rcNorm = nx.richclub.rich_club_coefficient(T,Q=2)
# assert_true(rcNorm[0] ==1.0 and rcNorm[1] < 0.9 and rcNorm[2] < 0.9)
示例8: setUp
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def setUp(self):
self.P3 = nx.path_graph(3)
self.P4 = nx.path_graph(4)
self.K5 = nx.complete_graph(5)
self.C4 = nx.cycle_graph(4)
self.C5 = nx.cycle_graph(5)
self.T = nx.balanced_tree(r=2, h=2)
self.Gb = nx.DiGraph()
self.Gb.add_edges_from([(0, 1), (0, 2), (0, 4), (2, 1),
(2, 3), (4, 3)])
示例9: test_balanced_tree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_balanced_tree(self):
"""Edge betweenness centrality: balanced tree"""
G=nx.balanced_tree(r=2,h=2)
b=nx.edge_betweenness_centrality(G, weight=None, normalized=False)
b_answer={(0, 1):12,(0, 2):12,
(1, 3):6,(1, 4):6,(2, 5):6,(2,6):6}
for n in sorted(G.edges()):
assert_almost_equal(b[n],b_answer[n])
示例10: test_already_arborescence
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_already_arborescence(self):
"""Tests that a directed acyclic graph that is already an
arborescence produces an isomorphic arborescence as output.
"""
A = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
B = nx.dag_to_branching(A)
assert_true(nx.is_isomorphic(A, B))
示例11: test_already_branching
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_already_branching(self):
"""Tests that a directed acyclic graph that is already a
branching produces an isomorphic branching as output.
"""
T1 = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
T2 = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
G = nx.disjoint_union(T1, T2)
B = nx.dag_to_branching(G)
assert_true(nx.is_isomorphic(G, B))
示例12: test_richclub2
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_richclub2():
T = nx.balanced_tree(2, 10)
rc = nx.richclub.rich_club_coefficient(T, normalized=False)
assert_equal(rc, {0: 4092 / (2047 * 2046.0),
1: (2044.0 / (1023 * 1022)),
2: (2040.0 / (1022 * 1021))})
示例13: test_rich_club_exception2
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_rich_club_exception2():
G = nx.MultiGraph()
nx.rich_club_coefficient(G)
# def test_richclub2_normalized():
# T = nx.balanced_tree(2,10)
# rcNorm = nx.richclub.rich_club_coefficient(T,Q=2)
# assert_true(rcNorm[0] ==1.0 and rcNorm[1] < 0.9 and rcNorm[2] < 0.9)
示例14: test_tree_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_tree_graph(self):
tg = nx.balanced_tree(3, 3)
assert_false(minimum_cycle_basis(tg))
示例15: test_balanced_tree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import balanced_tree [as 别名]
def test_balanced_tree(self):
"""Edge betweenness centrality: balanced tree"""
G = nx.balanced_tree(r=2, h=2)
b = nx.edge_betweenness_centrality(G, weight=None, normalized=False)
b_answer = {(0, 1): 12, (0, 2): 12,
(1, 3): 6, (1, 4): 6, (2, 5): 6, (2, 6): 6}
for n in sorted(G.edges()):
assert_almost_equal(b[n], b_answer[n])