Lecture 7: Search Strategies

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

Artificial Intelligence: Knowledge Representation
Review: Search problem formulation
Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
PROBLEM SOLVING AND SEARCH
And-Or Graphs CSCE 580 Spr03 Instructor: Marco Valtorta Hrishikesh J. Goradia Seang-Chan Ryu.
Part2 AI as Representation and Search
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.
Solving Problems by Searching Currently at Chapter 3 in the book Will finish today/Monday, Chapter 4 next.
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
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.
Logic Programming Lecture 7: Search Strategies: Problem representations Depth-first, breadth-first, and AND/OR search.
Lecture 3: Uninformed Search
CSCI 4310 Lecture 2: Search. Search Techniques Search is Fundamental to Many AI Techniques.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
Logic Programming Lecture 7: Search Strategies:
Artificial Intelligence Solving problems by searching.
Lecture 3 Problem Solving through search Uninformed Search
Lecture 3: Uninformed Search
Review: Tree search Initialize the frontier using the starting state
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
Last time: search strategies
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Breadth First and Depth First
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Heuristic Search A heuristic is a rule for choosing a branch in a state space search that will most likely lead to a problem solution Heuristics are used.
COMP 103 Tree Traversals Lindsay Groves 2016-T2 Lecture 22
Problem Solving by Searching
Uninformed Search Strategies
Games with Chance Other Search Algorithms
Games with Chance Other Search Algorithms
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Solving problems by searching
CS 188: Artificial Intelligence Fall 2008
Lecture 1B: Search.
Alpha-Beta Search.
CS Fall 2016 (Shavlik©), Lecture 9, Week 5
Searching for Solutions
Graphs.
Tree Searching.
Alpha-Beta Search.
Introduction to Artificial Intelligence Lecture 9: Two-Player Games I
Alpha-Beta Search.
CSE (c) S. Tanimoto, 2001 Search-Introduction
Artificial Intelligence
Pruned Search Strategies
Artificial Intelligence
Problem Spaces & Search
Artificial Intelligence
Iterative Deepening CPSC 322 – Search 6 Textbook § 3.7.3
Alpha-Beta Search.
CSE (c) S. Tanimoto, 2002 State-Space Search
Tree Searching.
Tree Searching.
Problem Spaces & Search
Graphs.
Graphs.
State-Space Searches.
Graphs.
State-Space Searches.
CSE (c) S. Tanimoto, 2004 State-Space Search
Games with Chance Other Search Algorithms
Graphs.
CMSC 471 Fall 2011 Class #4 Tue 9/13/11 Uninformed Search
Alpha-Beta Search.
State-Space Searches.
Search Strategies CMPT 420 / CMPG 720.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

Lecture 7: Search Strategies Logic Programming Lecture 7: Search Strategies

Outline for today Problem representation Depth-First Search Iterative Deepening Breadth-First Search Advanced techniques taster Best-first search AND/OR (alternating) search

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(a,d). goal(d). a d b c ...

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).

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(Node,Path)), dfs_noloop([Node|Path],Node1,Path1).

Problem 2: Infinite state space 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 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(N). 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?

A difference list implementation bfs_dl([[Node|Path]|_],_, [Node|Path]) :- goal(Node). bfs_dl([Path|Paths], Z, Solution) :- extend(Path,NewPaths), append(NewPaths,Z1,Z), Paths \== Z1, %% (Paths,Z1) is not empty DL bfs_dl(Paths,Z1,Solution). bfs_dl_start(N,P) :- bfs_dl([[N]|X],X,P). We'll come back to this next week

Best-first search Often want a minimum cost solution Idea: and maybe a heuristic cost measure Idea: Maintain "frontier" of solutions with similar cost Expand least-cost unexplored node

Example: Shortest paths Heuristic h(x) = map distance between points

Example: Shortest paths Heuristic h(x) = map distance between points

Example: Shortest paths Heuristic h(x) = map distance between points

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 "We 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). b c d e

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, heuristic measures of "good" positions

Next time Further reading: Next time: Bratko, ch. 8 (difference lists), ch. 11 (DFS/BFS) also Ch. 12 (BestFS), 13 (AND/OR) Next time: Advanced programming with terms (var/1, nonvar/1, =../2, ==/2, ...) Meta-programming