双向搜索的终止标准

发布于 2024-10-04 02:16:28 字数 474 浏览 4 评论 0原文

根据我所做的大部分阅读,据说双向搜索算法在“向前”和“向后”边界首次相交时终止。然而,在人工智能:现代方法的第 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

笑脸一如从前 2024-10-11 02:16:28

我认为这与双向搜索的实现方式有关。

BFS 的伪代码是这样的:

until frontier.empty?
    node <- frontier.pop()
    add node to explored
    for each child not in expored or frontier:
        if child is goal then
            return path
        add child to frontier

想象一下像这样实现双向搜索:

until frontierForward.emtpy? or frontierBackward.empty?
    node <- frontierForward.pop()
    add node to exploredForward
    for each child not in exporedForward or frontierForward:
        if child in frontierBackward then
            return pathForward + pathBackward
        add child to frontierForward

    Do something similar but now searching backwards

基本上,“向前”BFS 和“向后”BFS 的交替步骤。现在想象一个像这样的图:

    B-C-D
  /       \
A           E
  \       /
    F - G

BFS 的第一次向前和向后运行会给我们这样的状态:

1) expandedForward = A ; frontierForward = B, F
2) expandedBackward = E ; frontierBackward = D, G

现在算法选择下一个要从前向边界扩展的节点,并选择 B。

3) expandedForward = A, B ; frontierForward = F, C

现在我们运行向后 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:

until frontier.empty?
    node <- frontier.pop()
    add node to explored
    for each child not in expored or frontier:
        if child is goal then
            return path
        add child to frontier

Imagine implementing bidirectional search like this:

until frontierForward.emtpy? or frontierBackward.empty?
    node <- frontierForward.pop()
    add node to exploredForward
    for each child not in exporedForward or frontierForward:
        if child in frontierBackward then
            return pathForward + pathBackward
        add child to frontierForward

    Do something similar but now searching backwards

Basically, alternating steps of "forward" BFS and "backwards" BFS. Now imagine a graph like this:

    B-C-D
  /       \
A           E
  \       /
    F - G

The first forward and backward runs of BFS would give us a state like this:

1) expandedForward = A ; frontierForward = B, F
2) expandedBackward = E ; frontierBackward = D, G

Now the algorithm picks the next node to expand from the forward frontier and it picks B.

3) expandedForward = A, B ; frontierForward = F, C

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.)

一页 2024-10-11 02:16:28

我不知道这是否是拉塞尔和诺维格的初衷,但如果对图进行加权(即某些边比其他边长),那么最短路径可能比另一个路径有更多的步骤,这将导致在 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.

流殇 2024-10-11 02:16:28

在未加权(单位成本)图中,双向 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'':

Bidirectional search is implemented by having one or both of the searches check each node before it is expanded to see if it is in the fringe of the other search tree [...] The algorithm is complete and optimal (for uniform step costs) if both searches are breadth-first[.]

(By "expanding a node", R&N mean generating the successors. Emphasis added.)

原谅过去的我 2024-10-11 02:16:28

一个简单的三角形就可以满足您的条件,边长为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文