Download presentation
Presentation is loading. Please wait.
Published byΛαυρέντιος Ζάρκος Modified over 5 years ago
1
Supplemental slides for CSE 327 Prof. Jeff Heflin
Ch. 3 – Search Supplemental slides for CSE 327 Prof. Jeff Heflin
2
8-Puzzle Transition Model
7 2 4 5 6 8 3 1 state s actions a blank-right blank-left blank-up blank-down 7 2 4 5 6 8 3 1 7 2 4 5 6 8 3 1 7 4 5 2 6 8 3 1 7 2 4 5 3 6 8 1 RESULT(s,a)
3
8-puzzle Search Tree initial state 7 2 4 5 8 6 3 1 7 2 4 8 6 5 3 1 7 2
4
Tree Search Algorithm function Tree-Search(problem) returns a solution, or failure initialize the frontier using the initial state of problem loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution expand the chosen node, adding the resulting nodes to the frontier From Figure 3.7, p. 77
5
Repeated States A B C A C A B G B C A B G initial state goal state
State space Search tree A B A C G B C initial state goal state A C A B G B C A B G
6
Graph Search Algorithm
function Graph-Search(problem) returns a solution, or failure initialize the frontier using the initial state of problem initialize the explored set to be empty loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution add the node to the explored set expand the chosen node, adding the resulting nodes to the frontier, but only if not in the frontier or explored set From Figure 3.7, p. 77
7
Depth-first Search A not generated on frontier B C in memory deleted D
1 A not generated on frontier 2 7 B C in memory deleted 3 6 8 9 D E F G blue = in memory, green = on frontier, red = out of memory, clear = not generated 4 5 H I
8
Breadth-first Search A not generated on frontier B C in memory deleted
1 A not generated on frontier 2 3 B C in memory deleted 4 5 6 7 D E F G 8 9 H I
9
Uniform Cost Search I B G not generated on frontier C G in memory
State space Search tree 1 10 I G I g(n)=0 4 B 5 2 3 C B g(n)=4 G g(n)=10 not generated 4 on frontier 3 C G g(n)=7 g(n)=9 in memory deleted
10
Uninformed Search Summary
depth-first breadth-first uniform cost queuing add to front (LIFO) add to back (FIFO) by path cost complete? no yes yes, if all step costs are greater than 0 optimal? yes, if identical step costs time expensive space modest
11
A* Example n’s state h(n) A g B 5 C 7 D 8 E 1 F G D 9 3 B 4 2 5 G A E
D 9 3 B 4 2 5 G A E 5 6 2 F C Have already expanded the same state. No need to calculate f(n) 1 A g(n)=0, h(n)=6, f(n)=0+6=6 3 B 4 D E Lower cost node is on frontier 2 f=2+5=7 f=3+8=11 f= 5 +1=6 E 5* G B C f=12+0=12 f= 9+5=14 f=10+7=17
12
Heuristics in A* Use A* to solve the 8-puzzle:
initial state: goal state: 1 2 3 4 6 8 7 5 1 2 3 4 5 6 7 8 path cost is the total number of moves made Consider these heuristics H1: The number of tiles out of place H2: Sum of distances of tiles from goal positions Ignore moves that return you to the previous state
13
A* on 8-puzzle Heuristic = H1 1 f=0+3=3 2 f=1+3=4 3 f=1+3=4 f=2+3=5
6 8 7 5 Heuristic = H1 2 1 2 3 4 6 8 7 5 f=1+3=4 3 1 2 3 4 6 7 5 8 f=1+3=4 1 2 3 4 8 7 6 5 f=2+3=5 1 2 3 4 6 8 7 5 f=2+4=6 4 1 2 3 4 6 7 5 8 f=2+2=4 1 2 4 6 3 7 5 8 f=2+4=6 Whether or not this node is expanded depends on how you break ties. It could be expanded at any time or not at all. 1 3 4 2 6 7 5 8 f=3+3=6 1 2 3 4 6 7 5 8 f=3+3=6 5 1 2 3 4 5 6 7 8 f=3+1=4 The notation f=x+y=z is used to show the f(n) calculation for each node, where f=f(n)=z, x=g(n), y=h(n). 1 2 3 4 5 6 7 8 f=4+2=6 6 1 2 3 4 5 6 7 8 f=4+0=4
14
A* on 8-puzzle Heuristic = H2 1 f=0+4=4 f=1+5=6 2 f=1+3=4 3 f=2+2=4
7 5 Heuristic = H2 1 2 3 4 6 8 7 5 f=1+5=6 2 1 2 3 4 6 7 5 8 f=1+3=4 3 1 2 3 4 6 7 5 8 f=2+2=4 1 2 4 6 3 7 5 8 f=2+4=6 1 3 4 2 6 7 5 8 f=3+3=6 1 2 3 4 6 7 5 8 f=3+3=6 4 1 2 3 4 5 6 7 8 f=3+1=4 1 2 3 4 5 6 7 8 f=4+2=6 5 1 2 3 4 5 6 7 8 f=4+0=4
15
Summary of Search Algorithms
type ordering optimal? complete? efficient? depth-first uninformed LIFO no if lucky breadth-first FIFO yesa yes uniform cost g(n) yesb greedy informed h(n) usually A* g(n)+h(n) yesc a – if step costs are identical b – if step costs > 0 c – if heuristic is admissible and consistent
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.