本文整理汇总了Python中graphillion.GraphSet.trees方法的典型用法代码示例。如果您正苦于以下问题:Python GraphSet.trees方法的具体用法?Python GraphSet.trees怎么用?Python GraphSet.trees使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphillion.GraphSet
的用法示例。
在下文中一共展示了GraphSet.trees方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_forests
# 需要导入模块: from graphillion import GraphSet [as 别名]
# 或者: from graphillion.GraphSet import trees [as 别名]
def test_forests(self):
try:
#universe = tl.grid(8, 8, 0.37)
universe = [(1, 2), (1, 10), (2, 3), (2, 11), (3, 12), (4, 5), (5, 6), (5, 14), (6, 15), (7, 8), (8, 9), (8, 17), (9, 18), (10, 11), (11, 12), (11, 20), (13, 22), (14, 15), (14, 23), (16, 25), (17, 26), (18, 27), (19, 20), (19, 28), (20, 21), (21, 22), (21, 30), (22, 23), (22, 31), (23, 24), (24, 25), (25, 26), (26, 27), (26, 35), (27, 36), (28, 29), (28, 37), (29, 30), (29, 38), (30, 31), (31, 40), (32, 33), (32, 41), (33, 42), (34, 35), (37, 38), (37, 46), (38, 39), (40, 41), (41, 42), (41, 50), (42, 51), (43, 52), (44, 45), (45, 54), (46, 55), (47, 48), (47, 56), (48, 49), (49, 58), (50, 59), (51, 52), (51, 60), (52, 53), (53, 54), (53, 62), (55, 56), (56, 65), (57, 58), (57, 66), (59, 60), (59, 68), (61, 62), (61, 70), (62, 63), (64, 65), (64, 73), (65, 74), (66, 75), (67, 76), (68, 69), (69, 70), (69, 78), (70, 71), (70, 79), (71, 80), (72, 81), (74, 75), (75, 76), (76, 77), (80, 81)]
GraphSet.set_universe(universe)
generators = [1, 9, 73, 81]
forests = GraphSet.forests(roots=generators, is_spanning=True)
self.assertEqual(len(forests), 54060425088)
too_large_trees = GraphSet()
for substation in generators:
too_large_trees |= GraphSet.trees(root=substation).larger(23)
safe_forests = forests.excluding(too_large_trees)
self.assertEqual(len(safe_forests), 294859080)
closed_switches = (forests - safe_forests).choice()
scores = {}
for switch in universe:
scores[switch] = 1 if switch in closed_switches else -1
failures = safe_forests.blocking().minimal()
self.assertEqual(len(failures), 1936)
failure = failures.choice()
for line in failure:
safe_forests = safe_forests.excluding(line)
self.assertEqual(len(safe_forests), 0)
except ImportError:
pass
示例2: test_forests
# 需要导入模块: from graphillion import GraphSet [as 别名]
# 或者: from graphillion.GraphSet import trees [as 别名]
def test_forests(self):
try:
universe = tl.grid(8, 8, 0.37)
GraphSet.set_universe(universe)
generators = [1, 9, 73, 81]
forests = GraphSet.forests(roots=generators, is_spanning=True)
self.assertEqual(len(forests), 54060425088)
too_large_trees = GraphSet()
for substation in generators:
too_large_trees |= GraphSet.trees(root=substation).larger(23)
safe_forests = forests.excluding(too_large_trees)
self.assertEqual(len(safe_forests), 294859080)
closed_switches = (forests - safe_forests).choice()
scores = {}
for switch in universe:
scores[switch] = 1 if switch in closed_switches else -1
failures = safe_forests.blocking().minimal()
self.assertEqual(len(failures), 1936)
failure = failures.choice()
for line in failure:
safe_forests = safe_forests.excluding(line)
self.assertEqual(len(safe_forests), 0)
except ImportError:
pass
示例3: test_graphs
# 需要导入模块: from graphillion import GraphSet [as 别名]
# 或者: from graphillion.GraphSet import trees [as 别名]
def test_graphs(self):
GraphSet.set_universe([(1, 2), (1, 4), (2, 3), (2, 5), (3, 6), (4, 5),
(5, 6)])
# any subgraph
gs = GraphSet.graphs()
self.assertTrue(isinstance(gs, GraphSet))
self.assertEqual(len(gs), 2**7)
self.assertTrue([(1, 2)] in gs)
# subgraphs separating [1, 5] and [2]
gs = GraphSet.graphs(vertex_groups=[[1, 5], [2]])
self.assertEqual(len(gs), 6)
self.assertTrue([(1, 4), (4, 5)] in gs)
self.assertTrue([(1, 2), (1, 4), (4, 5)] not in gs)
# matching
dc = {}
for v in range(1, 7):
dc[v] = range(0, 2)
gs = GraphSet.graphs(degree_constraints=dc)
self.assertEqual(len(gs), 22)
self.assertTrue([(1, 2), (3, 6)] in gs)
self.assertTrue([(1, 2), (2, 3), (3, 6)] not in gs)
for g in gs:
self.assertTrue(len(g) < 4)
# subgraphs with 1 or 2 edges
gs = GraphSet.graphs(num_edges=range(1, 3))
self.assertEqual(len(gs), 28)
for g in gs:
self.assertTrue(1 <= len(g) and len(g) < 3)
# single connected component and vertex islands
gs = GraphSet.graphs(vertex_groups=[[]])
self.assertEqual(len(gs), 80)
self.assertTrue([(1, 2), (2, 3)] in gs)
self.assertTrue([(1, 2), (2, 3), (4, 5)] not in gs)
# any forest
gs = GraphSet.graphs(no_loop=True)
self.assertEqual(len(gs), 112)
self.assertTrue([(1, 2), (1, 4), (2, 5)] in gs)
self.assertTrue([(1, 2), (1, 4), (2, 5), (4, 5)] not in gs)
for g in gs:
self.assertTrue(len(g) < 6)
# constrained by GraphSet
gs = GraphSet.graphs(no_loop=True)
gs = gs.graphs(vertex_groups=[[]])
self.assertEqual(len(gs), 66)
self.assertTrue([(1, 2), (1, 4), (2, 5)] in gs)
self.assertTrue([(1, 2), (1, 4), (2, 5), (4, 5)] not in gs)
# single connected components across 1, 3, and 5
gs = GraphSet.connected_components([1, 3, 5])
self.assertEqual(len(gs), 35)
self.assertTrue([(1, 2), (2, 3), (2, 5)] in gs)
self.assertTrue([(1, 2), (2, 3), (5, 6)] not in gs)
GraphSet.set_universe([(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4),
(2, 5), (3, 4), (3, 5), (4, 5)])
# cliques with 4 vertices
gs = GraphSet.cliques(4)
self.assertEqual(len(gs), 5)
self.assertTrue([(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] in gs)
self.assertTrue([(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 5)] not in gs)
GraphSet.set_universe([(1, 2), (1, 4), (2, 3), (2, 5), (3, 6), (4, 5),
(5, 6)])
# trees rooted at 1
gs = GraphSet.trees(1)
self.assertEqual(len(gs), 45)
self.assertTrue([] in gs)
self.assertTrue([(1, 2), (1, 4), (2, 5), (4, 5)] not in gs)
# spanning trees
gs = GraphSet.trees(is_spanning=True)
self.assertEqual(len(gs), 15)
self.assertTrue([(1, 2), (1, 4), (2, 3), (2, 5), (3, 6)] in gs)
self.assertTrue([(1, 2), (1, 4), (2, 3), (2, 5), (4, 5)] not in gs)
for g in gs:
self.assertEqual(len(g), 5)
# forests rooted at 1 and 3
gs = GraphSet.forests([1, 3])
self.assertEqual(len(gs), 54)
self.assertTrue([] in gs)
self.assertTrue([(1, 2), (2, 3)] not in gs)
# spanning forests rooted at 1 and 3
gs = GraphSet.forests([1, 3], is_spanning=True)
self.assertEqual(len(gs), 20)
self.assertTrue([(1, 2), (1, 4), (2, 5), (3, 6)] in gs)
self.assertTrue([(1, 2), (1, 4), (2, 3), (2, 5)] not in gs)
for g in gs:
self.assertEqual(len(g), 4)
#.........这里部分代码省略.........