本文整理汇总了Python中networkx.maximum_spanning_tree函数的典型用法代码示例。如果您正苦于以下问题:Python maximum_spanning_tree函数的具体用法?Python maximum_spanning_tree怎么用?Python maximum_spanning_tree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了maximum_spanning_tree函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_prim_maximum_spanning_tree_edges_specify_weight
def test_prim_maximum_spanning_tree_edges_specify_weight(self):
G = nx.Graph()
G.add_edge(1, 2, weight=1, color="red", distance=7)
G.add_edge(1, 3, weight=30, color="blue", distance=1)
G.add_edge(2, 3, weight=1, color="green", distance=1)
G.add_node(13, color="purple")
G.graph["foo"] = "bar"
T = nx.maximum_spanning_tree(G, algorithm="prim")
assert_equal(sorted(T.nodes()), [1, 2, 3, 13])
assert_equal(sorted(T.edges()), [(1, 2), (1, 3)])
T = nx.maximum_spanning_tree(G, weight="distance", algorithm="prim")
assert_equal(sorted(T.edges()), [(1, 2), (1, 3)])
assert_equal(sorted(T.nodes()), [1, 2, 3, 13])
示例2: test_kruskal_maximum_spanning_tree_disconnected
def test_kruskal_maximum_spanning_tree_disconnected(self):
G = nx.Graph()
G.add_path([1, 2])
G.add_path([10, 20])
T = nx.maximum_spanning_tree(G, algorithm="kruskal")
assert_equal(sorted(map(sorted, T.edges())), [[1, 2], [10, 20]])
assert_equal(sorted(T.nodes()), [1, 2, 10, 20])
示例3: test_prim_maximum_spanning_tree_disconnected
def test_prim_maximum_spanning_tree_disconnected(self):
G = nx.Graph()
G.add_edge(1, 2)
G.add_edge(10, 20)
T = nx.maximum_spanning_tree(G, algorithm='prim')
assert_equal(sorted(map(sorted, T.edges())), [[1, 2], [10, 20]])
assert_equal(sorted(T.nodes()), [1, 2, 10, 20])
示例4: test_prim_maximum_spanning_tree_attributes
def test_prim_maximum_spanning_tree_attributes(self):
G = nx.Graph()
G.add_edge(1, 2, weight=1, color="red", distance=7)
G.add_edge(2, 3, weight=1, color="green", distance=2)
G.add_edge(1, 3, weight=10, color="blue", distance=1)
G.add_node(13, color="purple")
G.graph["foo"] = "bar"
T = nx.maximum_spanning_tree(G, algorithm="prim")
assert_equal(T.graph, G.graph)
assert_equal(T.node[13], G.node[13])
assert_equal(T.edge[1][2], G.edge[1][2])
示例5: test_weight_attribute
def test_weight_attribute(self):
G = nx.Graph()
G.add_edge(0, 1, weight=1, distance=7)
G.add_edge(0, 2, weight=30, distance=1)
G.add_edge(1, 2, weight=1, distance=1)
G.add_node(3)
T = nx.minimum_spanning_tree(G, algorithm=self.algo, weight='distance')
assert_nodes_equal(sorted(T), list(range(4)))
assert_edges_equal(sorted(T.edges()), [(0, 2), (1, 2)])
T = nx.maximum_spanning_tree(G, algorithm=self.algo, weight='distance')
assert_nodes_equal(sorted(T), list(range(4)))
assert_edges_equal(sorted(T.edges()), [(0, 1), (0, 2)])
示例6: test_kruskal_maximum_spanning_tree_isolate
def test_kruskal_maximum_spanning_tree_isolate(self):
G = nx.Graph()
G.add_nodes_from([1, 2])
T = nx.maximum_spanning_tree(G, algorithm="kruskal")
assert_equal(sorted(T.nodes()), [1, 2])
assert_equal(sorted(T.edges()), [])
示例7: test_maximum_spanning_tree
def test_maximum_spanning_tree(self):
T = nx.maximum_spanning_tree(self.G, algorithm="kruskal")
assert_equal(sorted(T.edges(data=True)), self.maximum_spanning_edgelist)
示例8: test_multigraph_keys_tree_max
def test_multigraph_keys_tree_max(self):
G = nx.MultiGraph()
G.add_edge(0, 1, key="a", weight=2)
G.add_edge(0, 1, key="b", weight=1)
T = nx.maximum_spanning_tree(G)
assert_equal([(0, 1, 2)], list(T.edges(data="weight")))
示例9: test_maximum_tree
def test_maximum_tree(self):
T = nx.maximum_spanning_tree(self.G, algorithm=self.algo)
actual = sorted(T.edges(data=True))
assert_edges_equal(actual, self.maximum_spanning_edgelist)
示例10: test_prim_maximum_spanning_tree
def test_prim_maximum_spanning_tree(self):
T = nx.maximum_spanning_tree(self.G, algorithm='prim')
assert_equal(T.edges(data=True), self.maximum_spanning_edgelist)