本文整理汇总了Python中searcher.Searcher.depth_first_search方法的典型用法代码示例。如果您正苦于以下问题:Python Searcher.depth_first_search方法的具体用法?Python Searcher.depth_first_search怎么用?Python Searcher.depth_first_search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类searcher.Searcher
的用法示例。
在下文中一共展示了Searcher.depth_first_search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import depth_first_search [as 别名]
# Read from file
file = open(input_file, "r")
for line in file:
edge = line.split()
graph.add_vertex(edge[0])
graph.add_vertex(edge[1])
graph.add_edge(edge[0], edge[1], int(edge[2]))
file.close()
# Perform search
searcher = Searcher(graph)
try:
result = []
if search_type == "BFS":
result = searcher.breadth_first_search(start_node, end_node)
elif search_type == "DFS":
result = searcher.depth_first_search(start_node, end_node)
elif search_type == "UCS":
result = searcher.dijkstra_search(start_node, end_node)
# Write result to file
file = open(output_file, "w")
for node in result[0]:
file.write(node + "\n")
file.close()
except NoGraphPathException:
file = open(output_file, "w")
file.write("")
file.close()