
什么是人工智能?
经典老派算法
关于BFS


算法如何工作
1BFS(G, s, goal)
2 Let Q be queue
3 Q.enqueue(s)
4 Mark s as visited
5 while (Q is not empty)
6 //Removing that vertex from queue
7 v = Q.dequeue()
8 If v is goal
9 return “found the goal”
10 //processing all the neighbours of v
11 for all neighbours w of v in Graph G
12 if w is not visited
13 //Stores w in Q to further visit its neighbour
14 Q.enqueue(w)
15 mark w as visited
寻找最短路径

1UniformCostSrearch(G, s)
2 s.costSoFar = 0;
3 for all nodes w in G except s
4 w.costSoFar = Int.maxInt
5 Let Q be a priority queue ordered by cost_so_far
6 Q.enqueue(s)
7 while (Q is not empty)
8 //Removing that vertex from queue
9 v = Q.dequeue()
10 If v is goal
11 return “found the goal”
12 //processing all the neighbours of v
13 for all neighbours w of v in Graph G
14 currentCost = dist[v,w]
15 newCost = v.costSoFar + currentCost;
16 If (newCost < w.costSoFar)
17 w.costSoFar = newCost ;
18 Q.enqueue(w)
1currentCost = dist[v,w]
2newCost = v.costSoFar + currentCost;
3If (newCost < w.costSoFar) {
4 w.costSoFar = newCost ;
5 Q.enqueue(w);
6}
图搜索和人工智能之间的关系

什么是问题的定义?
初始状态:在阿拉德; 当我们处于某个州时,它会返回一组可能的操作。例如:在阿拉德,我们可以去Zerind,Sibiu或Timisoara; 函数结果(s,a) - > s',在州,如果我们采取行动a,我们将去s'; 目标测试功能goaltest(s) - > t / f,它告诉我们是否达到了目标; step_cost(s,a,s') - >行动成本,它告诉我们使用动作a从s到s'的步骤成本; 成本(S1 - > S2 - > ...... - > Sn) - > n(路径成本),总路径成本;
探索的州的一部分(例如现在只是阿拉德) 有边疆。我们称之为已经探索过的最远的州(蒂米什瓦拉,泽林德和锡比乌) 未开发的州:所有其他城市
1TreeSearch(G, s)
2 s.costSoFar = 0;
3 for all nodes w in G except s
4 w.costSoFar = Int.maxInt
5 Let frontier be a priority queue ordered by the cost_so_far
6 frontier.enqueue(s)
7 while (frontier is not empty)
8 //Removing that vertex from frontier,whose neighbour will be visited now
9 v = frontier.dequeue()
10 If v is goal
11 return “found the goal”
12 //processing all the neighbours of v
13 for all neighbours w of v in Graph G
14 currentCost = dist[v,w]
15 newCost = v.costSoFar + currentCost;
16 If (newCost < w.costSoFar) {
17 w.costSoFar = newCost ;
18 frontier.enqueue(w)
总结
长按订阅更多精彩▼

如有收获,点个在看,诚挚感谢