150 likes | 165 Views
Explore search algorithms such as A*, Uniform Cost Search, and Breadth-First Search for solving problems efficiently. Understand how agents transition states to find solutions.
E N D
Ch. 3 – Search Supplemental slides for CSE 327 Prof. Jeff Heflin
8-Puzzle Transition Model state s actions a blank-right blank-left blank-up blank-down RESULT(s,a)
8-puzzle Search Tree initial state
Tree Search Algorithm function TREE-SEARCH(problem) returns a solution, or failure initialize the frontier using the initial state of problemloopdoif the frontier is empty then return failure choose a leaf node and remove it from the frontierif 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
function SIMPLE-PROBLEM-SOLVING-AGENT(percept)returns an action persistent: seq, an action sequence, initially emptystate, some description of the current world stategoal, a goal, initially nullproblem, a problem formulation state UPDATE-STATE(state,percept)ifseq is empty thengoal FORMULATE-GOAL(state)problem FORMULATE-PROBLEM(state,goal)seq SEARCH(problem) ifseq = failurethen return a null actionaction FIRST(seq)seq REST(seq)returnaction From Figure 3.1, p. 67 Problem Solving Agent Algorithm
state: <J12, J8, J3> initial state: <0, 0, 0> goal test: <1, x, y> x and y can be any value path cost: 1 per solution step? 1 per gallon of water moved? actions/successor function let C12=12, C8=8, C3=3 fill-jug-i if Ji < Ci then Ji=Ci empty-jug-i-into-jug-j if Ji <= Cj – Jj thenJj’ = Jj + Ji, Ji’=0 fill-jug-i-from-jug-j if Jj >= Ci – Ji thenJj’ = Jj – (Ci – Ji), Ji’=Ci Water Jug Problem
Depth-first Search 1 A not generated on frontier 2 7 B C in memory deleted 3 8 6 9 D E F G 4 5 H I
Breadth-first Search 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
Uniform Cost Search State space Search tree 1 10 I G g(n)=0 I 4 B 5 2 3 C g(n)=4 B G g(n)=10 not generated 4 3 on frontier G C g(n)=9 g(n)=7 in memory deleted
Repeated States State space Search tree A B A C G B C initial state goal test A C A B G B C A B G
A* Example • Use A* to solve the 8-puzzle: goal state: initial state: 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
A* on 8-puzzle 1 f=0+3=3 Heuristic = H1 2 f=1+3=4 3 f=1+3=4 4 f=2+2=4 f=2+3=5 f=2+4=6 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. f=3+3=6 f=3+3=6 5 f=3+1=4 f=4+2=6 6 f=4+0=4
A* on 8-puzzle 1 f=0+4=4 Heuristic = H2 2 f=1+3=4 f=1+5=6 3 f=2+2=4 f=2+4=6 f=3+3=6 f=3+3=6 4 f=3+1=4 f=4+2=6 5 f=4+0=4
Summary of Search Algorithms • a – optimal if step costs are identical • b – optimal and complete if step costs > 0 • c – optimal if heuristic is admissible and consistent