本文整理汇总了Python中Graph.Graph.dfs方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.dfs方法的具体用法?Python Graph.dfs怎么用?Python Graph.dfs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.dfs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: repaint
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import dfs [as 别名]
def repaint():
canvas.delete("point")
if len(circles) == 0: return # Nothing to paint
# Build the edges
edges = []
for i in range(len(circles)):
for j in range(i + 1, len(circles)):
if distance(circles[i], circles[j]) <= 2 * radius:
edges.append([i, j])
edges.append([j, i])
graph = Graph(circles, edges)
tree = graph.dfs(0)
isAllCirclesConnected = \
len(circles) == tree.getNumberOfVerticesFound()
for [x, y] in circles:
if isAllCirclesConnected: # All circles are connected
canvas.create_oval(x - radius, y - radius, x + radius,
y + radius, fill = "red", tags = "point")
else:
canvas.create_oval(x - radius, y - radius, x + radius,
y + radius, tags = "point")
示例2: dfs
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import dfs [as 别名]
def dfs(self):
self.lines = True
graph = Graph(self.point, self.edge)
dfs = graph.dfs(eval(self.v1.get()))
order = dfs.getSearchOrders()
for i in range(1, len(order)):
for j in range(len(self.edge)):
parent = dfs.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")
self.generate()
示例3: Graph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import dfs [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)
dfs = graph.dfs(graph.getIndex("Chicago"))
searchOrders = dfs.getSearchOrders()
print(str(dfs.getNumberOfVerticesFound()) +
" vertices are searched in this DFS order:")
for i in range(len(searchOrders)):
print(graph.getVertex(searchOrders[i]), end = " ")
print();
for i in range(len(searchOrders)):
if dfs.getParent(i) != -1:
print("parent of " + graph.getVertex(i) +
" is " + graph.getVertex(dfs.getParent(i)))
示例4: eval
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import dfs [as 别名]
l = eval(l[0])
v = []
for i in range(l):
v.append(fin.readline().split(" "))
for row in range(len(v)):
for column in range(len(v[row])):
v[row][column] = eval(v[row][column])
counter = 0
vertex = []
for i in range(len(v)):
vertex.append(str(v[i][0]))
edges = []
for i in range(l):
for j in range(1, len(v[i])):
edges.append([])
edges[counter].append(i)
edges[counter].append(v[i][j])
counter += 1
g = Graph(vertex, edges)
tree = g.dfs(0)
print("The number of vertricies is: " + str(l))
g.printEdges()
if tree.getNumberOfVerticesFound() == l:
print("They are connected")
else:
print("They are not connected")