知情搜索(二)-找到最优解

普通分支界定算法

分支界定算法是努力寻找一条最优路径,为了确保找到一条到达目的地的路径,它找到路径后会继续生成部分路径,直到每条路径的代价大于或等于所找到的路径的代价。不具备启发值。

伪代码如下:

//Branch Bound Search
Branch_Bound(Root_Node, goal)
{
    Create Queue Q
    Insert Root Node into Q
    while(Q_Is_Not)
    {
        G = Remove from Q
        If(G=goal) Return the path from Root_Node to G;
        else
        Insert children of G into the Q
        Sort Q by path length
    }//and while
    Return failure
}

使用低估值的分支定界法

具有低估值的分支界定法是获得最佳解且具备启发性的方式。

 

采用动态规划的分支界定法

该算法给出如下建议:如果两条或者多条路径到达一个公共节点,只有到达这个公共节点具有最小代价的路径才被保存(其他路径删除)。

伪代码如下:

// Branch and Bound with Dynamic Programming
B_B_W_Dynamic_Programming (Root_Node, goal)
{
    Create Queue Q
    Insert Root_Node into Q
    while(Q_Is_Not_Empty)
    {
        G = Remove from Q
        Mark G visited
            If this mode has been visited previously, retain only the shortest path to G
        If(G = goal) Return the Path from Root_Node to G
        Insert the children of G which have not been previously visited into the Q 
    }
    return failure
}

 

A*搜索 

该方法采用具有剩余距离估计值和动态规划的分支定界法。

伪代码如下:

// A* Search
A* Search (Root_Node, Goal)
{
    Create Queue Q
    Insert Root_Node into Q
    while(Q_Is_Not_Empty)
    {
        G = Remove from Q
        Mark G visited
        If(G=goal) Return the path from Root_Node to G;
        Else
        Add each child node's estimated distance to current distance
        Insert the children of G which have not been previously visited into the Q 
        Sort Q by the path length;
    } 
    Return failure
}

 

你可能感兴趣的:(算法)