Problems Problem Spaces Problems, Problem Spaces, and Search Ahmed Rafea Ahmed Rafea
Problem Solving Steps Problem Solving Steps • Define the Problem precisely • Analyze the problem Analyze the problem • Isolate and represent the task knowledge • Choose the best problem solving technique
Defining the Problem as a State Space Search • Example ‐ Water Jug Problem E l W t J P bl • You are given two jugs, a 4 ‐ gallon one and a 3 ‐ gallon one gallon one. • Neither has any measuring markers on it. • There is a pump that can be used to fill the jugs Th i h b d fill h j with water. • How can you get exactly 2 gallons of water into H t tl 2 ll f t i t the 4 ‐ gallon jug? • initial state (0 0) • initial state (0,0) • goal state (2,n)
Operators Operators 1 1. if <4 > (4 ) if x<4 ‐ > (4,y) 2. if y<3 ‐ > (x,3) 3. if x>0 ‐ > (x ‐ d,y) 4. if y>0 ‐ > (x,y ‐ d) 5. if x>0 ‐ > (0,y) 6. 6 if y>0 > (x 0) if y>0 ‐ > (x,0) 7. if x+y>=4 and y>0 ‐ > (4,y ‐ (4 ‐ x)) 8. if x+y>=3 and x>0 ‐ > (x ‐ (3 ‐ y),3) 9. if x+y<=4 and y>0 ‐ > ((x+y),0) 10. if x+y<=3 and x>0 ‐ > (0,x+y) 11 11. (0,2) > (2,0) (0 2) ‐ > (2 0) 12. (2,y) ‐ > (y,2)
Algorithm : Breadth First Search Algorithm : Breadth ‐ First Search (0,0) ---------------------- | | (4.0) (0,3) ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ | | | | | | (4,3) (0,0) (3,1) (3,0) (4,3) (0,0)
Algorithm : Depth First Search Algorithm : Depth ‐ First Search (0,0) ---------------------- | | (4.0) (0,3) ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ | | | (4,3) (0,0) (3,1)
Advantage of Depth First Search Advantage of Depth ‐ First Search • Less Memory • By chance, it may find a solution without By chance, it may find a solution without examining much of the search space at all
Advantage of Breadth ‐ First Search • It will not get trapped exploring a blind alley • If there is a solution then BFS is guaranteed to If there is a solution then BFS is guaranteed to find it • If there are multiple solution, a minimal If h l i l l i i i l solution will be found
Recommend
More recommend