双向搜索的终止标准
根据我所做的大部分阅读,据说双向搜索算法在“向前”和“向后”边界首次相交时终止。然而,在人工智能:现代方法的第 3.4.6 节中,Russel 和 Norvig 指出:
双向搜索是通过将目标测试替换为检查来实现的 两个搜索的边界是否相交;如果他们这样做了,就已经找到了解决方案。 重要的是要认识到,找到的第一个解决方案可能不是最佳的,即使 两次搜索都是广度优先;需要进行一些额外的搜索以确保存在 不是跨越鸿沟的捷径。
我已经考虑这个说法很长一段时间了,但我找不到这种行为的例子。谁能提供一个示例图,其中双向 BFS 或 A* 搜索的前向边界和后向边界之间的第一个交点不是最短路径?
编辑:显然,BFS 不会在加权图中找到最短路径。听起来这段摘录是指无向图上的双向 BFS。或者,我有兴趣查看在加权图上使用双向 A* 的反例。
According to most of the reading I have done, a bidirectional search algorithm is said to terminate when the "forward" and "backward" frontiers first intersect. However, in Section 3.4.6 of Artificial Intelligence: A Modern Approach, Russel and Norvig state:
Bidirectional search is implemented by replacing the goal test with a check to see
whether the frontiers of the two searches intersect; if they do, a solution has been found.
It is important to realize that the first solution found may not be optimal, even if the
two searches are both breadth-first; some additional search is required to make sure there
isn't a shortcut across the gap.
I have considered this statement for quite some time, but am unable to find an example of this behavior. Can anyone provide an example graph where the first intersection between the forward and backward frontiers of a bidirectional BFS or A* search is not the shortest path?
Edit: Clearly BFS will not find the shortest path in a weighted graph. It sounds like this excerpt is referring to bidirectional BFS on a undirected graph. Alternatively, I would be interested in seeing a counterexample using bidirectional A* on a weighted graph.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这与双向搜索的实现方式有关。
BFS 的伪代码是这样的:
想象一下像这样实现双向搜索:
基本上,“向前”BFS 和“向后”BFS 的交替步骤。现在想象一个像这样的图:
BFS 的第一次向前和向后运行会给我们这样的状态:
现在算法选择下一个要从前向边界扩展的节点,并选择 B。
现在我们运行向后 BFS 并扩展节点D. D 的孩子 C 位于前沿,因此我们返回路径 A - B - C - D - E。
我认为这就是 Russel 和 Norvig 所指的内容。如果实现不考虑这种情况,它可能会为您提供不是最佳的解决方案。
在确定找到最佳解决方案之前,它应该完成扩展边界中具有相同“深度”的所有节点。或者可以按层而不是按节点交替进行前向和后向 BFS 搜索(向前扩展第 0 层中的所有节点,向后扩展第 0 层中的所有节点,向前扩展第 1 层中的所有节点等)
I think it has to do with how bidirectional search is implemented.
The pseudocode for BFS goes something like this:
Imagine implementing bidirectional search like this:
Basically, alternating steps of "forward" BFS and "backwards" BFS. Now imagine a graph like this:
The first forward and backward runs of BFS would give us a state like this:
Now the algorithm picks the next node to expand from the forward frontier and it picks B.
Now we run a backwards BFS and expand node D. D's child, C, is in the forward frontier, so we return the path A - B - C - D - E.
I think this is what Russel and Norvig where referring to. If the implementation doesn't consider this scenario it could give you a solution that's not optimal.
It should finish expanding all the nodes in the frontier that have the same "depth" before deciding it has found an optimal solution. Or maybe alternate the forward and backward BFS searches by layer and not by node (expand forward all nodes in layer 0, expand backward all nodes in layer 0, expand forward all nodes in layer 1, etc.)
我不知道这是否是拉塞尔和诺维格的初衷,但如果对图进行加权(即某些边比其他边长),那么最短路径可能比另一个路径有更多的步骤,这将导致在 BFS 中更快被发现。即使步数相同,也不一定先找到最好的;考虑一个具有六个节点的图:
(A->B) = (A->C) = 0
(B->D) = 2
(C->E) = 1
(D->F) = (E→F)=0
从A向前一步,从F向后一步后,向前前沿是{B,C},向后前沿是{D,E}。搜索者现在展开 B,嘿!路口! (A->B->D->F) = 2。但仍然应该进一步搜索才能发现 (A->C->E->F) 更好。
I don't know if this is what Russel and Norvig had in mind, but if the graph is weighted (i.e. some edges are longer than others), the shortest path might have more steps than another which would be found sooner in a BFS. Even if the number of steps is the same, the best might not be found first; consider a graph with six nodes:
(A->B) = (A->C) = 0
(B->D) = 2
(C->E) = 1
(D->F) = (E->F) = 0
After one step forward from A and one step backward from F, the forward frontier is {B,C} and the backward frontier is {D,E}. The searcher now expands B and hey! intersection! (A->B->D->F) = 2. But it should still search a little farther to discover that (A->C->E->F) is better.
在未加权(单位成本)图中,双向 BFS 在遇到交叉点时已找到最佳解决方案,如 Russell & Norvig 在 2003 年版《AIMA》第 80 页上写道:
(通过“扩展节点”,R&N意味着生成后继。强调。)
In an unweighted (unit cost) graph, bidirectional BFS has found the optimal solution when it hits the intersection, as Russell & Norvig themselves state on page 80 of the 2003 edition of ''AIMA'':
(By "expanding a node", R&N mean generating the successors. Emphasis added.)
一个简单的三角形就可以满足您的条件,边长为 6,6,10。最佳路径是长度为 10 的单段。在双向中,算法向前搜索较短的路径,长度为 6,然后反向也将采用较短的路径,长度同样为 6 - 它们会相遇,并且算法检测到找到一条完整的路径。
但很明显,2 个 6 的线段 (6+6=12) 比 1 个长度为 10 的线段长。
a simple triangle would satisfy your condition, with the sides being 6,6,10. The optimal path is the single segment of length 10. In Bi-directional, the algorithm searches the shorter path forward, which is length 6, then reverse would also take the shorter path, again length 6 - they would meet, and the algorithm detects a complete path is found.
but clearly 2 segments of 6 (6+6=12) is longer than one segment of length 10.