Download presentation
Presentation is loading. Please wait.
Published byGervais Oliver Modified over 9 years ago
1
State Space Search Algorithms CSE 472 Introduction to Artificial Intelligence Autumn 2003
2
Depth First Search a b de c f gh Maintain stack of nodes to visit Properties –Complete? –Time Complexity? –Space Complexity? Not for infinite spaces O(b^d) O(d)
3
Breadth First Search a b c def gh Maintain FIFO queue of nodes to visit Properties –Complete? –Time Complexity? –Space Complexity? Yes O(b^d)
4
Iterative Deepening Search DFS with limit; incrementally grow limit Properties –Complete? –Time Complexity? –Space Complexity? Yes O(b^d) O(d) b de c f gh a b c a
5
Dijkstra’s Shortest Path Algorithm Like breadth-first search, but uses a priority queue instead of a FIFO queue Generalizes BFS to case where arcs can have different lengths –Example: maze where roads between intersections are different lengths –Example: complete CSE major doing as little homework as possible, where each course has estimated number of hours of homework
6
Pseudocode for Dijkstra Initialize the cost of each vertex to cost[s] = 0; heap.insert(s); While (! heap.empty()) n = heap.deleteMin() if (n is a goal vertex) then return “Success!” For (each vertex a which is adjacent to n along edge e) if (cost[n] + edge_cost[e] < cost[a]) then cost [a] = cost[n] + edge_cost[e] previous_on_path_to[a] = n; if (a is in the heap) then heap.decreaseKey(a) else heap.insert(a)
7
Edsger Wybe Dijkstra (1930-2002) Invented concept of structured programming 1972 Turing Award “In their capacity as a tool, computers will be but a ripple on the surface of our culture. In their capacity as intellectual challenge, they are without precedent in the cultural history of mankind.”
8
Map of Manhattan How would you find a path from S to G? 52 nd St 51 st St 50 th St 10 th Ave 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave 3 rd Ave 2 nd Ave S G
9
Best-First Search The Manhattan distance ( x+ y) is an estimate of the distance to the goal –It is a heuristic function Best-First Search –Order nodes in priority queue to minimize estimated distance to the goal h(n) Compare: Dijkstra –Order nodes in priority queue to minimize distance from the start
10
Best First in Action How would you find a path from S to G? 52 nd St 51 st St 50 th St 10 th Ave 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave 3 rd Ave 2 nd Ave S G
11
Problem 1: Led Astray Eventually will expand vertex to get back on the right track 52 nd St 51 st St 50 th St 10 th Ave 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave 3 rd Ave 2 nd Ave S G
12
Problem 2: Optimality With Best-First Search, are you guaranteed a shortest path is found when –goal is first seen? –when goal is removed from priority queue (as with Dijkstra?)
13
Sub-Optimal Solution No! Goal is by definition at distance 0: will be removed from priority queue immediately, even if a shorter path exists! 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) h=2 h=1 h=4 h=5
14
Synergy? Dijkstra / Breadth First guaranteed to find optimal solution Best First often visits far fewer vertices, but may not provide optimal solution –Can we get the best of both?
15
A* (“A star”) Order vertices in priority queue to minimize (distance from start) + (estimated distance to goal) f(n) = g(n) + h(n) f(n) = priority of a node g(n) = true distance from start h(n) = heuristic distance to goal
16
Optimality Suppose the estimated distance (h) is always less than or equal to the true distance to the goal –heuristic is a lower bound on true distance –heuristic is admissible Then: when the goal is removed from the priority queue, we are guaranteed to have found a shortest path!
17
A* in Action 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) 50 th St vertexg(n)h(n)f(n) 52 nd & 9 th 055
18
A* in Action 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) 50 th St vertexg(n)h(n)f(n) 52 nd & 4 th 527 51 st & 9 th 145
19
A* in Action 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) 50 th St vertexg(n)h(n)f(n) 52 nd & 4 th 527 51 st & 8 th 235 50 th & 9 th 257
20
A* in Action 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) 50 th St vertexg(n)h(n)f(n) 52 nd & 4 th 527 51 st & 7 th 325 50 th & 9 th 257 50 th & 8 th 347
21
A* in Action 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) 50 th St vertexg(n)h(n)f(n) 52 nd & 4 th 527 51 st & 6 th 415 50 th & 9 th 257 50 th & 8 th 347 50 th & 7 th 437
22
A* in Action 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) 50 th St vertexg(n)h(n)f(n) 52 nd & 4 th 527 51 st & 5 th 505 50 th & 9 th 257 50 th & 8 th 347 50 th & 7 th 437
23
A* in Action 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) 50 th St vertexg(n)h(n)f(n) 52 nd & 4 th 527 50 th & 9 th 257 50 th & 8 th 347 50 th & 7 th 437 DONE!
24
What Would Dijkstra Have Done? 52 nd St 51 st St 9 th Ave 8 th Ave 7 th Ave6 th Ave5 th Ave4 th Ave S G (5 blocks) 50 th St 49 th St 48 th St 47 th St
25
Importance of Heuristics D IDS A*(h1)A*(h2) 2 10 6 6 4 11213 12 6 68020 18 8 638439 25 10 4712793 39 12 364404 227 73 143473941 539 113 18 3056 363 24 391351641 h1 = number of tiles in the wrong place h2 = sum of distances of tiles from correct location 7 2 3 8 5 4 1 6
26
Maze Runner Demo
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.