logic programming search strategies
play

Logic Programming: Search Strategies Alan Smaill Nov 5, 2012 Alan - PowerPoint PPT Presentation

N I V E U R S E I H T T Y O H F G R E U D I B N Logic Programming: Search Strategies Alan Smaill Nov 5, 2012 Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 1/1 Today N I V E U R S E I H T T


  1. N I V E U R S E I H T T Y O H F G R E U D I B N Logic Programming: Search Strategies Alan Smaill Nov 5, 2012 Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 1/1

  2. Today N I V E U R S E I H T T Y O H F G R E U D I B N Problem representation Search Depth First Iterative Deepening Breadth First AND/OR (alternating/game tree) search Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 2/1

  3. Search Problems N I V E U R S E I H T T Y O H F G R E U D I B N Many classical AI/CS problems can be formulated as search problems. Examples: Graph searching Blocks world Missionaries and cannibals Planning (e.g. robotics) Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 3/1

  4. Search Spaces N I V E U R S E I H T T Y O H F G R E U D I B N Given by: Set of states s 1 , s 2 , . . . Goal predicate goal ( X ) Step predicate s ( X , Y ) that says we can go from state X to state Y A start state (or states) A solution is a path leading from the S to a goal state G satisfying goal ( G ). Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 4/1

  5. Example: Blocks world N I V E U R S E I H T T Y O H F G R E U D I B N Take configuration of blocks as a list of three towers, each tower being a list of blocks in a tower from top to bottom. C B A [[c,b,a],[],[c]) Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 5/1

  6. Example: Blocks world N I V E U R S E I H T T Y O H F G R E U D I B N Move a block from top of a tower to top of another tower: B A C [[b,a],[],[c]) Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 6/1

  7. Example: Blocks world N I V E U R S E I H T T Y O H F G R E U D I B N Next move: A B C [[a],[b],[c]) Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 7/1

  8. Example: Blocks world N I V E U R S E I H T T Y O H F G R E U D I B N Then — A B C [[],[a,b],[c]) Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 8/1

  9. Prolog representation N I V E U R S E I H T T Y O H F G R E U D I B N State is a list of stacks of blocks: [[a,b,c],[],[]] Transitions move a block from the top of one stack to the top of another: s([[A|As],Bs,Cs], [As,[A|Bs],Cs]). s([[A|As],Bs,Cs], [As,Bs,[A|Cs]]). ... Can specify particular goal position: goal([[],[],[1,b,c]]. Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 9/1

  10. An abstract problem space N I V E U R S E I H T T Y O H F G R E U D I B N Think of the graph generated by these declarations. s(a,b). s(b,c). In this case: s(c,a). the graph is infinite s(c,f(d)). s(f(N),f(g(N))). there is a loop near the top of the graph s(f(g(X)),X). goal(d). Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 10/1

  11. problem 1: cycles N I V E U R S E I H T T Y O H F G R E U D I B N We can already see in the blocks world example and in the abstract search space that it is easy to follow actions around in cycles, and not find the goal, even if there is a path to the goal. There are two main approaches to deal with this: remember where you’ve been work with depth bound Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 11/1

  12. Solution 1: remember where you’ve been N I V E U R S E I H T T Y O H F G R E U D I B N dfs_noloop(Path,Node,[Node|Path]) :- goal(Node). dfs_noloop(Path,Node,Path1) :- s(Node,Node1), \+(member(Node1,Path)), dfs_noloop([Node|Path],Node1,Path1). Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 12/1

  13. Problem 2: Infinite State Space N I V E U R S E I H T T Y O H F G R E U D I B N Compare the graph from the abstract search space. Depth First Search has similar problems to Prolog proof search: We may miss solutions because state space is infinite; Even if state space is finite, may wind up finding “easy” solution only after a long exploration of pointless part of search space Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 13/1

  14. Solution 2: depth bounding N I V E U R S E I H T T Y O H F G R E U D I B N Keep track of depth, stop if bound exceeded Note: does not avoid loops (can do this too) dfs_bound(_,Node,[Node]) :- goal(Node). dfs_bound(N,Node,[Node|Path]) :- N > 0, s(Node,Node1), M is N-1, dfs_bound(M,Node1,Path) Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 14/1

  15. Problem 3: what is a good bound? N I V E U R S E I H T T Y O H F G R E U D I B N In general, we just don’t know in advance: Too low? – Might miss solutions Too high? – Might spend a long time searching pointlessly Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 15/1

  16. Solution 3: iterative deepening N I V E U R S E I H T T Y O H F G R E U D I B N Use the following with some small start value for N dfs_id(N,Node,Path) :- dfs_bound(N,Node,Path) ; M is N+1, dfs_id(M,Node,Path). NB: if there is no solution, this will not terminate. Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 16/1

  17. Breadth first search N I V E U R S E I H T T Y O H F G R E U D I B N Keep track of all possible solutions, try shortest ones first; do this by maintaining a “queue” of solutions bfs([[Node|Path]|_], [Node|Path]) :- goal(Node). bfs([Path|Paths], S) :- extend(Path,NewPaths), append(Paths,NewPaths,Paths1), bfs(Paths1,S). bfs_start(N,P) :- bfs([[N]],P). Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 17/1

  18. extending paths N I V E U R S E I H T T Y O H F G R E U D I B N extend([Node|Path],NewPaths) :- bagof([NewNode,Node|Path], (s(Node,NewNode), \+ (member(NewNode,[Node|Path]))), NewPaths), !. %% if there are no next steps, %% bagof will fail and we’ll fall through. extend(_Path,[]). Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 18/1

  19. Problem: speed N I V E U R S E I H T T Y O H F G R E U D I B N Concatenating new paths to end of list is slow Avoid this using difference lists? Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 19/1

  20. AND/OR search N I V E U R S E I H T T Y O H F G R E U D I B N So far we’ve considered graph search problems Just want to find some path from start to end Other problems have more structure e.g. 2-player games AND/OR search is a useful abstraction Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 20/1

  21. Example: Noughts and Crosses N I V E U R S E I H T T Y O H F G R E U D I B N MAX ( X ) X X X MIN ( O ) X X X X X X X O X O X . . . MAX ( X ) O X O X X O X O . . . MIN ( O ) X X . . . . . . . . . . . . . . . X O X X O X X O X TERMINAL O X O O X X O X X O X O O Utility –1 0 +1 Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 21/1

  22. Representation N I V E U R S E I H T T Y O H F G R E U D I B N or(S,Nodes) S is an OR node with possible next states Nodes “Our move” and(S,Nodes) S is an AND node with possible next states Nodes “Opponent moves” goal(S) S is a “win” for us Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 22/1

  23. Example: A simple game N I V E U R S E I H T T Y O H F G R E U D I B N and(a,[b,c]). or(b,[d,a]). or(c,[d,e]). goal(e). What is the graph here? Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 23/1

  24. Basic Idea N I V E U R S E I H T T Y O H F G R E U D I B N andor(Node) :- goal(Node). andor(Node) :- or(Node,Nodes), member(Node1,Nodes), andor(Node1). andor(Node) :- and(Node,Nodes), solveall(Nodes). solveall(Nodes) :- ... Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 24/1

  25. Solutions N I V E U R S E I H T T Y O H F G R E U D I B N For each AND state, we need solutions for all possible next states For each OR state, we just need one choice A “solution” is thus a tree, or strategy Can adapt previous program to produce solution tree; Can also incorporate iterative deepening, loop avoidance, BFS. heuristic measures of “good” positions leads to algorithms like MiniMax. Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 25/1

  26. Further Reading N I V E U R S E I H T T Y O H F G R E U D I B N Bratko, Prolog Programming for Artificial Intelligence ch. 8 (difference lists), ch. 11 (DFS/BFS) also Ch. 12 (BestFS), 13 (AND/OR) Alan Smaill Logic Programming: Search Strategies Nov 5, 2012 26/1

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend