Termination Criteria for Bidirectional Search

后端 未结 4 1054
执念已碎
执念已碎 2020-12-15 04:27

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,

4条回答
  •  不知归路
    2020-12-15 05:10

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

提交回复
热议问题