当前位置: 首页>>代码示例>>Python>>正文


Python Graph.add_directed_link方法代码示例

本文整理汇总了Python中Graph.Graph.add_directed_link方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.add_directed_link方法的具体用法?Python Graph.add_directed_link怎么用?Python Graph.add_directed_link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph.Graph的用法示例。


在下文中一共展示了Graph.add_directed_link方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cycle_with_isolated_points

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_directed_link [as 别名]
 def test_cycle_with_isolated_points(self):
     graph = Graph()
     graph.add_directed_link(1, 2)
     graph.add_vertex(6)
     graph.add_vertex(7)
     graph.add_directed_link(2, 3)
     graph.add_vertex(1)
     graph.add_directed_link(6, 4)
     graph.add_directed_link(3, 1)
     graph.add_directed_link(3, 4)
     self.assertEqual(graph.topological_sort(), None)
开发者ID:vks4git,项目名称:a3200-2015-algs,代码行数:13,代码来源:tests.py

示例2: test_DAG_sort

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_directed_link [as 别名]
 def test_DAG_sort(self):
     graph = Graph()
     graph.add_directed_link(1, 2)
     graph.add_directed_link(1, 3)
     graph.add_directed_link(2, 4)
     graph.add_directed_link(3, 4)
     graph.add_directed_link(4, 5)
     graph.add_directed_link(2, 3)
     self.assertEqual(graph.topological_sort(), [1, 2, 3, 4, 5])
开发者ID:vks4git,项目名称:a3200-2015-algs,代码行数:11,代码来源:tests.py

示例3: test_two_connected_components

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_directed_link [as 别名]
 def test_two_connected_components(self):
     graph = Graph()
     graph.add_directed_link(1, 2)
     graph.add_directed_link(2, 3)
     graph.add_directed_link(3, 1)
     graph.add_directed_link(4, 5)
     graph.add_directed_link(5, 6)
     graph.add_directed_link(6, 4)
     self.assertEqual(graph.topological_sort(), None)
开发者ID:vks4git,项目名称:a3200-2015-algs,代码行数:11,代码来源:tests.py

示例4: test_not_connected_DAG_sort

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_directed_link [as 别名]
 def test_not_connected_DAG_sort(self):
     graph = Graph()
     graph.add_directed_link(1, 2)
     graph.add_directed_link(1, 3)
     graph.add_directed_link(2, 4)
     graph.add_directed_link(3, 4)
     graph.add_directed_link(4, 5)
     graph.add_directed_link(2, 3)
     graph.add_directed_link(6, 7)
     graph.add_directed_link(6, 8)
     graph.add_directed_link(7, 9)
     graph.add_directed_link(8, 9)
     graph.add_directed_link(9, 10)
     graph.add_directed_link(7, 8)
     ans1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     ans2 = [6, 7, 8, 9, 10, 1, 2, 3, 4, 5]
     arr = graph.topological_sort()
     match1 = True
     match2 = True
     for i in range(10):
         match1 = match1 or (arr[i] == ans1[i])
     for i in range(10):
         match2 = match2 or (arr[i] == ans2[i])
     self.assertTrue(match1 or match2)
开发者ID:vks4git,项目名称:a3200-2015-algs,代码行数:26,代码来源:tests.py

示例5: test_many_connected_components_with_cycle

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_directed_link [as 别名]
 def test_many_connected_components_with_cycle(self):
     graph = Graph()
     graph.add_directed_link(1, 2)
     graph.add_directed_link(1, 3)
     graph.add_directed_link(1, 4)
     graph.add_directed_link(2, 4)
     graph.add_directed_link(5, 6)
     graph.add_directed_link(7, 5)
     graph.add_directed_link(7, 9)
     graph.add_directed_link(11, 12)
     graph.add_directed_link(13, 12)
     graph.add_directed_link(11, 15)
     graph.add_directed_link(15, 16)
     graph.add_directed_link(15, 17)
     graph.add_directed_link(17, 10)
     graph.add_directed_link(10, 11)
     graph.add_directed_link(10, 17)
     self.assertEqual(graph.topological_sort(), None)
开发者ID:vks4git,项目名称:a3200-2015-algs,代码行数:20,代码来源:tests.py

示例6: test_cycle

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_directed_link [as 别名]
 def test_cycle(self):
     graph = Graph()
     graph.add_directed_link(1, 2)
     graph.add_directed_link(2, 3)
     graph.add_directed_link(3, 1)
     self.assertEqual(graph.topological_sort(), None)
开发者ID:vks4git,项目名称:a3200-2015-algs,代码行数:8,代码来源:tests.py


注:本文中的Graph.Graph.add_directed_link方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。