Logic Programming Lecture 7: Search Strategies:

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

Review: Search problem formulation
Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
PROBLEM SOLVING AND SEARCH
Logic Programming Lecture 3: Recursion, lists, and data structures.
And-Or Graphs CSCE 580 Spr03 Instructor: Marco Valtorta Hrishikesh J. Goradia Seang-Chan Ryu.
Part2 AI as Representation and Search
Tree Searching. Tree searches A tree search starts at the root and explores nodes from there, looking for a goal node (a node that satisfies certain conditions,
Problem Solving Agents A problem solving agent is one which decides what actions and states to consider in completing a goal Examples: Finding the shortest.
1 Lecture 3 Uninformed Search. 2 Uninformed search strategies Uninformed: While searching you have no clue whether one non-goal state is better than any.
Solving Problems by Searching Currently at Chapter 3 in the book Will finish today/Monday, Chapter 4 next.
CS 480 Lec 3 Sept 11, 09 Goals: Chapter 3 (uninformed search) project # 1 and # 2 Chapter 4 (heuristic search)
CMSC 471 Spring 2014 Class #4 Thu 2/6/14 Uninformed Search Professor Marie desJardins,
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
1 Lecture 3: 18/4/1435 Uninformed search strategies Lecturer/ Kawther Abas 363CS – Artificial Intelligence.
Implementation and Evaluation of Search Methods. Use a stack data structure. 1. Push root node of tree on the stack. 2. Pop the top node off the stack.
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
Artificial Intelligence Lecture No. 7 Dr. Asad Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Tyler Robison Summer
Review: Search problem formulation
17-Jun-15 Searching in BeeperHunt (Mostly minor variations on old slides)
1 Solving Problems by Searching. 2 Terminology State State Space Initial State Goal Test Action Step Cost Path Cost State Change Function State-Space.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
Using Search in Problem Solving
CS 188: Artificial Intelligence Spring 2006 Lecture 2: Queue-Based Search 8/31/2006 Dan Klein – UC Berkeley Many slides over the course adapted from either.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Heuristic Search Notes for Ch.12 of Bratko and Ch.2 of Shoham For CSCE 580.
1 Lecture 3 Uninformed Search
State-Space Searches. 2 State spaces A state space consists of –A (possibly infinite) set of states The start state represents the initial problem Each.
For Friday Finish chapter 3 Homework: –Chapter 3, exercise 6 –May be done in groups. –Clarification on part d: an “action” must be running the program.
Solving Problems by Searching
State-Space Searches.
Artificial Intelligence Course outline Introduction Problem solving Generic algorithms Knowledge Representation and Reasoning Expert Systems Uncertainty.
CMU Snake Robot
Review: Search problem formulation Initial state Actions Transition model Goal state (or goal test) Path cost What is the optimal solution? What is the.
Logic Programming Lecture 7: Search Strategies: Problem representations Depth-first, breadth-first, and AND/OR search.
CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #3 Instructor: Eyal Amir Grad TAs: Wen Pu, Yonatan Bisk Undergrad TAs: Sam.
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning.
AND/OR Graphs Ivan Bratko Faculty of Information and Computer Sc. University of Ljubljana Useful for solving problems by problem decomposition Searching.
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l all learning algorithms,
CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.
State-Space Searches. 2 State spaces A state space consists of A (possibly infinite) set of states The start state represents the initial problem Each.
CS.462 Artificial Intelligence SOMCHAI THANGSATHITYANGKUL Lecture 02 : Search.
Search Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Dan Klein, Stuart Russell, Andrew Moore, Svetlana Lazebnik,
Artificial Intelligence
Lecture 7: Uninformed Search Dr John Levine Algorithms and Complexity February 13th 2006.
Artificial Intelligence LECTURE 4 ARTIFICIAL INTELLIGENCE LECTURES BY ENGR. QAZI ZIA.
For Friday Finish reading chapter 4 Homework: –Lisp handout 4.
For Monday Read chapter 4, section 1 No homework..
Lecture 3: Uninformed Search
1 Solving problems by searching 171, Class 2 Chapter 3.
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Advanced Artificial Intelligence Lecture 2: Search.
Computer Science CPSC 322 Lecture 6 Iterative Deepening and Search with Costs (Ch: 3.7.3, 3.5.3)
For Friday Read chapter 4, sections 1 and 2 Homework –Chapter 3, exercise 7 –May be done in groups.
CSCI 4310 Lecture 2: Search. Search Techniques Search is Fundamental to Many AI Techniques.
Problem Solving as Search. Problem Types Deterministic, fully observable  single-state problem Non-observable  conformant problem Nondeterministic and/or.
1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search.
Breadth First Search and Depth First Search. Greatest problem in Computer Science Has lead to a lot of new ideas and data structures Search engines before.
Logic Programming Lecture 8: Term manipulation & Meta-programming.
Graph Search II GAM 376 Robin Burke. Outline Homework #3 Graph search review DFS, BFS A* search Iterative beam search IA* search Search in turn-based.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
Source: David Lee Matuszek
Logic Programming Lecture 8: Term manipulation & Meta-programming.
Search CSC 358/ Outline Homework #6 Game search States and operators Issues Search techniques DFS, BFS Beam search A* search Alpha-beta.
Brian Williams, Fall 041 Analysis of Uninformed Search Methods Brian C. Williams Sep 21 st, 2004 Slides adapted from: Tomas Lozano Perez,
Logic Programming Lecture 2: Unification and proof search.
Artificial Intelligence Solving problems by searching.
Lecture 3: Uninformed Search
Lecture 7: Search Strategies
Artificial Intelligence
Presentation transcript:

Logic Programming Lecture 7: Search Strategies: Problem representations Depth-first, breadth-first, and AND/OR search

Outline for today Problem representation Depth-First Search Iterative Deepening Breadth-First Search AND/OR (alternating/game tree) search

Search problems Many classical (AI/CS) problems can be formulated as search problems Examples: Graph searching Blocks world Missionaries and cannibals Planning (e.g. robotics)

Search spaces Set of states s1,s2,... Goal predicate goal(X) Step predicate s(X,Y) that says we can go from state X to state Y A solution is a path leading from some start state S to a goal state G satisfying goal(G).

Example: Blocks world C B A [[c,b,a],[],[]]

Example: Blocks world B A C [[b,a],[],[c]]

Example: Blocks world A B C [[a],[b],[c]]

Example: Blocks world A B C [[],[a,b],[c]]

Representation in Prolog 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]]). ... goal([[],[],[a,b,c]]).

An abstract problem space s(a,b).s(b,c).s(c,a). s(c,f(d)).s(f(N),f(g(N))).s(f(g(X)),X). goal(d). a b c f(d) f(g(d)) d f(g(g(d))) ... g(d)

Depth-first search dfs(Node,Path) dfs(S,[S]) :- goal(S). Path is a path to a goal starting from Node dfs(S,[S]) :- goal(S). dfs(S,[S|P]) :- s(S,T), dfs(T,P). This should look familiar

Problem 1: Cycles C B A

Solution 1: Remember where you've been Avoid cycles by avoiding previously visited states 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).

Problem 2: Infinite state space DFS 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 ...

Solution 2: Depth bounding 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).

Problem 3: What is a good bound? Don't know this in advance, in general Too low? Might miss solutions Too high? Might spend a long time searching pointlessly

Solution 3: Iterative deepening dfs_id(N,Node,Path) :- dfs_bound(N,Node,Path) ; M is N+1, dfs_id(M,Node,Path).

Breadth-first search Keep track of all possible solutions, try shortest ones first Maintain 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).

Extending paths 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,[]).

Problem: Speed Concatenating new paths to end of list is slow Avoid this using difference lists? Will revisit next week

AND/OR search 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

AND/OR search Search space has 2 kinds of states: OR: "we get to choose next state" AND: "opponent gets to choose" we need to be able to handle any opponent move

Example: Tic tac toe ... x x x x ... ... ... ...

Representation or(S,Nodes) and(S,Nodes) goal(S) 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

Example: A simple game and(a,[b,c]).or(b,[d,a]).or(c,[d,e]).goal(e). a

Basic idea andor(Node) :- goal(Node). andor(Node) :- or(Node,Nodes), member(Node1,Nodes), andor(Node1). and(Node,Nodes), solveall(Nodes).

Solutions 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 - min/max

Further reading: Next time: Bratko, Prolog Programming for Artificial Intelligence ch. 8 (difference lists), ch. 11 (DFS/BFS) also Ch. 12 (BestFS), 13 (AND/OR) Next time: Higher-order logic programming