广度优先搜索是统一成本搜索的一个特例
在人工智能中,主要有两种搜索技术:
- 不知情/盲目的搜索技术
- 知情搜索技术
Uninformed 类别下的搜索算法是:
- 广度优先搜索
- 统一成本搜索
- 深度优先搜索
- 深度受限搜索
- 迭代深化深度优先搜索
- 双向搜索
Informed 类别下的搜索算法是:
- 最佳首次搜索
- A* 搜索
现在,我们将定义 BFS 和 UCS 搜索的步骤,然后我们将从 UCS 搜索算法中推导出 BFS。
广度优先搜索算法:
Open list is implemented using Queue for BFS.
- Add the initial node x0 to the open list.
- Take a node x from the front-end of open list. If the open list is empty then we can’t proceed further hence can’t find the target node.
(a) If open list is empty, stop with failure.
(b) On the other hand, if x is the target node, stop with success. - Expand x to obtain a set S of child nodes of x, and put x into the closed list.
- For each node x’ in set S, if it is not in the closed list, add it to the open list along with the edge (x, x’).
- Return to Step 2.
BFS 的属性:
- 从某种意义上说,它是一种完全搜索,它总能在有限搜索图中的有限步中找到解。
- 转移成本函数是 d(x, x') = 1 或任何常数。
广度优先搜索的优势:
- 它将找到起点和任何其他可到达点之间的最短路径。
- 它总能找到最佳解决方案。
- BFS 中没有什么像无用的路径,因为它是逐级搜索的。
- 在更短的时间内找到最近的目标。
统一成本搜索算法:
- Add the initial node x0 and its cost C(x0) to the open list.
- Get a node x from the top of the open list. (a) If the open list is empty then we can’t proceed further and hence can’t find the solution. So, if open list is empty then stop with failure. (b) If x is the target node then we can stop here. So, if x is target node then stop with success.
- Expand x to get a set S of the child nodes of x, and move x to the closed list.
- Pick each x’ from the set S which is not present in the closed list, find its accumulated cost: C(x’) = C(x) + d(x, x’).
- If x’ is not present in the open list: Add x’, C(x’) and (x, x’) to the open list. (a) If x’ in already present in the open list, update its cost C(x’) and link (x, x’) in the open list if the new cost is smaller than old cost.
- Sort the open list based on the node costs, and return to step-2.
UCS 的属性:
- 我们总能找到从初始节点到当前节点的最佳路径。
- C(x) 是节点 x 的累积成本,从初始节点开始。
- d(x, x') 是从节点 x 到节点 x' 的状态转换成本。
- 如果我们为所有边设置 d(x, x')=1,UCS 就等同于广度优先搜索。
从 UCS 导出 BFS:
The cost function in BFS: C(x’) = C(x) + 1 …(1)
The cost function in UCS: C(x’) = C(x) + d(x, x’) …(2)
C(x0) = 1 in BFS and UCS …(3)
If we make transition cost from node x to x’ = 1 then;
UCS: C(x’) = C(x) + 1 …(4)
Thus, from (1) and (4), we conclude that BFS is derived from UCS by making transition cost as 1.
Therefore, BFS is a special case of UCS.
统一成本搜索如何成为 A* 搜索的特例 - 人工智能
- Add the initial node x0 and its cost C(x0) to the open list.
- Get a node x from the top of the open list. (a) If the open list is empty then we can’t proceed further and hence can’t find the solution. So, if open list is empty then stop with failure. (b) If x is the target node then we can stop here. So, if x is target node then stop with success.
- Expand x to get a set S of the child nodes of x, and move x to the closed list.
- Pick each x’ from the set S which is not present in the closed list, find its accumulated cost: C(x’) = C(x) + d(x, x’).
- If x’ is not present in the open list: Add x’, C(x’) and (x, x’) to the open list. (a) If x’ in already present in the open list, update its cost C(x’) and link (x, x’) in the open list if the new cost is smaller than old cost.
- Sort the open list based on the node costs, and return to step-2.
UCS 的属性:
- 我们总能找到从初始节点到当前节点的最佳路径。
- C(x) 是节点 x 的累积成本,从初始节点开始。
- d(x, x') 是从节点 x 到节点 x' 的状态转换成本。
- 如果我们为所有边设置 d(x, x')=1,UCS 就等同于广度优先搜索。
A* 搜索算法:
- Put the initial node x0 and its cost F(x0)=H(x0) to the open list.
- Get a node x from the top of the open list.
-
- (a) If the open list is empty then we can’t proceed further and hence can’t find the solution. So, if open list is empty then stop with failure.
- (b) If x is the target node then we can stop here. So, if x is target node then stop with success.
- Expand x to get a set S of child nodes. Put x to the closed list.
- H(x) = Heuristic cost of reaching upto state x from initial state.
- d(x, x’) = cost of state transition from state x to state x’.
- For each x’ in S, find its cost: C(x’)=C(x)+d(x,x’)
-
- (a) If x’ is in the closed list but the new cost is smaller than the old one, move x’ to the open list and update the edge (x,x’) and the cost.
- (b) Else, if x’ is in the open list, but the new cost is smaller than the old one, update the edge (x,x’) and the cost.
- (c)Else (if x’ is not in the open list nor in the closed list), put x’ along with the edge (x,x’) and the cost F to the open list.
- (d) Sort the open list according to the costs of the nodes, and return to Step 2.
A* 算法承诺最好的最优解。
Deriving UCS from A* algorithm:
Cost function in UCS: C(x’) = C(x} + d(x, x’) …(1)
Cost function in A*: F(x’) = F(x) + d(x, x’) + [H(x’) – H(x)] …(2)
Put H(x) = 0, for all nodes x.
Substitute H(x) = 0, in equation (2).
We get: F(x’) = F(x) + d(x, x’) + [0 – 0]
where F(x) = cost of reach state x.
Hence, F(x) = C(x)
Thus, A* becomes UCS if heuristic cost of every node is 0. So, UCS is a special case of A* algorithm.