320 likes | 345 Views
Artificial Intelligence. CS 165A Thursday, October 11, 2007. Blind search (Ch. 3) Informed (heuristic) search methods (Ch 4). Today. 1. Notes. 8-puzzle problem There are two disjoint sets of states! Homework assignment #1 posted Due Tuesday October 23 rd May work in groups of two
E N D
Artificial Intelligence CS 165A Thursday, October 11, 2007 • Blind search (Ch. 3) • Informed (heuristic) search methods (Ch 4) Today 1
Notes • 8-puzzle problem • There are two disjoint sets of states! • Homework assignment #1 posted • Due Tuesday October 23rd • May work in groups of two • Get going on it right away! • Midterm schedule scheduled: November 13th • “Mid-to-late-term exam”
Review Search Criteria • Primary criteria to evaluate search strategies • Completeness • Is it guaranteed to find a solution (if one exists)? • Optimality • Does it find the “best” solution (if there are more than one)? • Time complexity • Number of nodes generated/expanded • (How long does it take to find a solution?) • Space complexity • How much memory does it require? • Some performance measures • Best case • Worst case • Average case • Real-world case
Review General Search Algorithm (Version 2) • Uses a queue (a list) and a queuing function to implement a search strategy • Queuing-Fn(queue, elements) inserts a set of elements into the queue and determines the order of node expansion functionGENERAL-SEARCH(problem, QUEUING-FN) returns a solution or failure nodes MAKE-QUEUE(MAKE-NODE(INITIAL-STATE[problem])) loop do if nodes is empty then return failure node REMOVE-FRONT(nodes) if GOAL-TEST[problem] applied to STATE(node) succeeds then return node nodes QUEUING-FN(nodes, EXPAND(node, OPERATORS[problem])) end
Depth-First Search • Always expands one of the nodes at the deepest level of the tree • Low memory requirements • Problem: depth could be infinite • Uses LIFO queue functionDEPTH-FIRST-SEARCH(problem) returns a solution or failure return GENERAL-SEARCH(problem, ENQUEUE-AT-FRONT)
Thursday Quiz • Given the initial node s, a goal node g, and the current node n .... What is a heuristic functionh(n) of the current node? • What does it mean for a search routine to be complete? Is breadth-first search complete?
A B C B C D E D B D E F D F Example State space graph Search tree Queue (A) (B C) (D C) (C) (B D E) (D D E) (D E) (E) (F) A
1 2 MIU MII 2 MIUIU 2 2 MIUIUIUIUIUIUIUIU MIUIUIUIU Example: MU-Puzzle • State space description • Start state: MI • Goal state: MU • Operators: • x I x IU • M x M x x • I I I U • U U (null) Search tree Queue (MI) (MIU MII) (MIUIU MII) (MIUIUIUIU MII) (MIUIUIUIUIUIUIUIU MII) … MI
Is depth-first this? Or this? Note on depth-first search That is, when a node is expanded, is it expanded fully? • For our purposes, YES • Open all children of each node
Complete? Optimal? Time complexity? Space complexity? No No Exponential: O( bm ) Polynomial: O( bm) Depth-First Search • b = Maximum branching factor of the search tree • d = Depth of an optimal solution (may be more than one) • m = maximum depth of the search tree (may be infinite)
bm • Why is the space complexity (memory usage) of depth-first search O( bm )? • Remove expanded node when all descendents evaluated • At each of the m levels, you have to keep b nodes in memory • Example: • b = 3 • m = 6 • Nodes in memory: bm+1 = 19 Actually, (b-1)m + 1 = 13 nodes, the way we have been keeping our node list
Uniform Cost Search • Similar to breadth-first search, but always expands the lowest-cost node, as measured by the path cost function, g(n) • g(n) is (actual) cost of getting to node n • Breadth-first search is actually a special case of uniform cost search, where g(n) = DEPTH(n) • If the path cost is monotonically increasing, uniform cost search will find the optimal solution functionUNIFORM-COST-SEARCH(problem) returns a solution or failure return GENERAL-SEARCH(problem, ENQUEUE-IN-COST-ORDER)
Example A 2 6 8 B C E 2 12 8 4 D 1 F Try breadth-first and uniform cost
Complete? Optimal? Time complexity? Space complexity? Yes Yes Exponential: O( bd ) Exponential: O( bd ) Uniform-Cost Search Same as breadth-first
functionDEPTH-LIMITED-SEARCH(problem, depth-limit) returns a solution or failure return GENERAL-SEARCH(problem, ENQUEUE-AT-FRONT-IF-UNDER-DEPTH-LIMIT) Must explicitly represent node depth Depth-Limited Search • Like depth-first search, but uses a depth cutoff to avoid long (possibly infinite), unfruitful paths • Do depth-first search up to depth limit l • Depth-first is special case with l=inf • Problem: How to choose the depth limit l? • Some problem statements make it obvious (e.g., TSP), but others don’t (e.g., MU-puzzle)
Complete? Optimal? Time complexity? Space complexity? No, unless d l No Exponential: O( bl ) Exponential: O( bl ) Depth-Limited Search • b = Maximum branching factor of the search tree • d = Depth of an optimal solution (may be more than one) • m = maximum depth of the search tree (may be infinite) • l = depth limit
Iterative-Deepening Search • Since the depth limit is difficult to choose in depth-limited search, use depth limits of l = 0, 1, 2, 3, … • Do depth-limited search at each level functionITERATIVE-DEEPENING-SEARCH(problem) returns a solution or failure fordepth 0 to do ifDEPTH-LIMITED-SEARCH(problem, depth) succeeds then return result end return failure
Iterative-Deepening Search • IDS has advantages of • Breadth-first search – Optimal and complete • Depth-first search – Modest memory requirements • This is the preferred blind search method when the search space is large and the solution depth is unknown • Many states are expanded multiple times • Is this terribly inefficient? • No… and it’s great for memory (compared with breadth-first) • Why is it not particularly inefficient?
IDS efficiency • When d = 2, the penalty for IDS is almost 100% • When d = 3, the penalty for IDS is about 50% • When d = 10, the penalty for IDS is about 11% • When d = 35, the penalty for IDS is about 3% This assumes the solution is in the “right bottom corner”
Complete? Optimal? Time complexity? Space complexity? Yes Yes Exponential: O( bd ) Polynomial: O( bd) Iterative-Deepening Search • b = Maximum branching factor of the search tree • d = Depth of an optimal solution (may be more than one) • m = maximum depth of the search tree (may be infinite)
bd • Why is the space complexity (memory usage) of iterative-deepening search O( bd )? • At each of the d levels, you have to keep b nodes in memory • Example: • b = 3 • d = 6 • Nodes in memory: bd+1 = 19 Actually, (b-1)d + 1 = 13 nodes, the way we have been keeping our node list
… … Bidirectional Search Forward search only:
Bidirectional Search Simultaneously search forward from the initial state and backward from the goal state Much more efficient!
Bidirectional Search • O(bd/2) rather than O(bd) – hopefully • Both actions and predecessors (inverse actions) must be defined • Must test for intersection between the two searches • Constant time for test? • Really a search strategy, not a specific search method • Often not practical…. Example: 410≈ 1,000,000 2*45 ≈ 2,000
Complete? Optimal? Time complexity? Space complexity? Yes Yes Exponential: O( bd/2 ) Exponential: O( bd/2 ) Bidirectional Search * Assuming breadth-first search used, and no misses!
Summary of Search Criteria b – max branching factor of the search tree d – depth of the least-cost solution m – max depth of the state-space (may be infinity) l – depth cutoff (Slightly different from the textbook)
When to Use Which Method? • What kinds of problems are most appropriate (or inappropriate) for each type of search method? • Hmm, that would be a good test question….
Why might you want to know this? Practical note about search algorithms • The computer can’t “see” the search graph like we can • No “bird’s eye view” – make relevant information explicit! • What information should you keep for a node in the search tree? • State • (1 2 0) • Parent node (or perhaps complete ancestry) • Node #3 (or, nodes 0, 2, 5, 11, 14) • Depth of the node • d = 4 • Path cost up to (and including) the node • g(node) = 12 • Operator that produced this node • Operator #1
Avoiding repeated states • It may be beneficial to explicitly avoid repeated states, especially where there are loops in the state graph and/or reversible operators • Search space can be very significantly pruned • How to deal with repeated states: • Do not return to state we just came from(parent node) • Do not create paths with cycles (ancestor nodes) • Do not generate any state that was ever generated before(complete tree) • But there is a cost • Have to keep track (in memory) of every state generated
Avoiding repeated states: Example • For my M&C implementation in Lisp : • With no checking • 11,851 nodes expanded, 760 MB • Checking parent • 55 nodes expanded, 17 kB • Checking ancestors • 26 nodes expanded, 7 kB • Checking all expanded nodes • 14 nodes, 4 kB memory
Search as problem-solving • We have defined the problem • Data • States, initial state(s), goal test/state(s), path cost function • Operations • State transitions • Control – Search to find paths from initial states to goal states • Build up a search tree whose nodes and arcs correspond to nodes and arcs in the state space graph • Solution: “Best” path through the state space
Next: • Informed (heuristic) search methods (Ch 4)