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


Python Graph.bfs方法代码示例

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


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

示例1: bfs

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import bfs [as 别名]
 def bfs(self):
     self.lines = True
     graph = Graph(self.point, self.edge)
     bfs = graph.bfs(eval(self.v1.get()))
     order = bfs.getSearchOrders()
     for i in range( 1, len(order)):
         parent = bfs.getParent(i)
         self.canvas.create_line(self.node[parent][0], self.node[parent][1], self.node[order[i]][0], self.node[order[i]][1], arrow = LAST, fill = "red")
开发者ID:dmaslin,项目名称:Python-work,代码行数:10,代码来源:22.21.py

示例2: __init__

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import bfs [as 别名]
    def __init__(self):
        edges = getEdges()

        # Create a graph
        vertices = [x for x in range(NUMBER_OF_NODES)]
        graph = Graph(vertices, edges)

        # Obtain a BSF tree rooted at the target node
        self.tree = graph.bfs(511)
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:11,代码来源:NineTailModel.py

示例3: test_bfs

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import bfs [as 别名]
  def test_bfs(self):
    v = Vertex('v')
    w = Vertex('w')
    x = Vertex('x')
    y = Vertex('y')
    z = Vertex('z')
    a = Vertex('a')
    e1 = Edge(v,w)
    e2 = Edge(w,x)
    e3 = Edge(v,x)
    e4 = Edge(y,z)
    g = Graph([v,w,x,y,z,a], [e1,e2,e3,e4])

    # Start bfs from an isolated vertex
    self.verify_list_equal_unordered(list(g.bfs(a)), [a])

    # Start from one connected component
    self.verify_list_equal_unordered(list(g.bfs(y)), [y, z])

    # Start from second connected component
    self.verify_list_equal_unordered(list(g.bfs(v)), [v,w,x])
    self.verify_list_equal_unordered(list(g.bfs(v)), list(g.bfs(w)))
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:24,代码来源:Graph_test.py

示例4: Graph

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import bfs [as 别名]
# Create an edge list for graph in Figure 16.1
edges = [
    [0, 1], [0, 3], [0, 5],
    [1, 0], [1, 2], [1, 3],
    [2, 1], [2, 3], [2, 4], [2, 10],
    [3, 0], [3, 1], [3, 2], [3, 4], [3, 5],
    [4, 2], [4, 3], [4, 5], [4, 7], [4, 8], [4, 10],
    [5, 0], [5, 3], [5, 4], [5, 6], [5, 7],
    [6, 5], [6, 7],
    [7, 4], [7, 5], [7, 6], [7, 8],
    [8, 4], [8, 7], [8, 9], [8, 10], [8, 11],
    [9, 8], [9, 11],
    [10, 2], [10, 4], [10, 8], [10, 11],
    [11, 8], [11, 9], [11, 10]
  ]

graph = Graph(vertices, edges)
bfs = graph.bfs(graph.getIndex("Chicago")) 

searchOrders = bfs.getSearchOrders()
print(str(bfs.getNumberOfVerticesFound()) +
    " vertices are searched in this order:")
for i in range(len(searchOrders)):
    print(graph.getVertex(searchOrders[i]), end = " ")
print()

for i in range(len(searchOrders)):
    if bfs.getParent(i) != -1:
        print("parent of " + graph.getVertex(i) + 
          " is " + graph.getVertex(bfs.getParent(i)))
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:32,代码来源:TestBFS.py

示例5: spath

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import bfs [as 别名]
 def spath(self):
     graph = Graph(self.point, self.edge)
     bfs = graph.bfs(eval(self.v2.get()))
     path = bfs.getPath(eval(self.v3.get()))
     for i in range(1, len(path)):
         self.canvas.create_line(self.node[path[i - 1]][0], self.node[path[i - 1]][1], self.node[path[i]][0], self.node[path[i]][1], arrow = FIRST, fill = "red")
开发者ID:dmaslin,项目名称:Python-work,代码行数:8,代码来源:22.21.py


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