Problem Solving Using Search Bruteforce search Heuristic search
Problem Solving Using Search Brute-force search Heuristic search Competitive search 1
Search cont. Many problems can only be solved by searching Copyright P. Doerschuk 2
Importance of efficient search algorithms Search z. Tic tac toe ystate space of 9!: x 9 possible first moves, followed by 8 possible second moves, followed by 7 possible third moves, etc. , or 9 x 8 x 7 x…x 1 moves or 9! y. Can use exhaustive search z. Chess y 10120 possible paths ycan’t use exhaustive search Copyright P. Doerschuk 3
State Space Search zuse a state space graph to represent the problem yeach node represents a partial solution state yeach arc represents transition between states xcan be directed or undirected ztree - a graph in which 2 nodes have at most one path between them (no loops or cycles) zstate space search - find a solution path from the start state to a goal state Copyright P. Doerschuk 4
traveling salesperson z. Fig 3. 7 z. O(N!) ; actually (N-1)! Copyright P. Doerschuk Search 5
Tree-based search Search 6 ztree representation is often used to search for a path from the initial state to the goal state (Ex: eights puzzle) znumber of possible states: 9! Copyright P. Doerschuk
Eights puzzle state tree Copyright P. Doerschuk Search 7
Search Graph search vs tree search z. General graph search algorithm must detect and eliminate loops; this is done by ensuring that a state is only examined once ztrees don’t need to do this because they don’t have loops Copyright P. Doerschuk 8
Unguided (blind) search Search zdoes not use heuristic information during the search process zdepth first search examines all descendants of a node before the nodes at the same level are examined zbreadth-first search examines all nodes at a given level before the nodes of the descendants Copyright P. Doerschuk 9
Unguided (blind) search Search 10 cont. z. Breadth first algorithm: 1. create a queue and add the first node to it 2. Loop: If the queue is empty, quit. Remove the first node from the queue. If the node contains the goal state, exit with the node as the solution. For each child of the current node: Add the new state (no duplicates) to the back of the queue. Copyright P. Doerschuk
Breadth-first search Search QUEUE: A BC CDE DEFG EFGHIJK z. ABCDEFGHIJKL Copyright P. Doerschuk GHIJKLMNO JKLMNO 11
Unguided (blind) search Search cont. zdepth first algorithm: 1. create a queue and add the first node to it 2. Loop: If the queue is empty, quit. Remove the first node from the queue. If the node contains the goal state, exit with the node as the solution. For each child of the current node: Add the new state (no duplicates) to the front of the queue. Copyright P. Doerschuk 12
Depth-first search Search QUEUE: A BC DEC HIEC EC z. ABDHIEJKCFL Copyright P. Doerschuk JKC KC C FG LMG 13
Breadth first vs depth first Search 14 y. Breadth first xguaranteed to find the shortest path xspace inefficient • all unexpanded nodes for each level are kept in the queue • if average branching factor is B, have Bn states on level n (root is level 0) • if solution path is long or B is large, memory requirements large ydepth first xnot guaranteed to find shortest path xspace efficient • at each level, keeps only the children of a single node in the queue (B*n) states at level n Copyright P. Doerschuk
Unguided (blind) search Search 15 cont. z. Depth-first search with iterative deepening yperform depth-first search up to a max. Depth ycontrol loop continually deepens depth-first search ymore efficient than breadth-first and depth-first on large search spaces Russell and Norvig 1995 ytime behavior is the same as depth-first and breadth-first search: O(Bn) z. Note: all unguided search techniques have worst case exponential time behavior Copyright P. Doerschuk
Using state space to represent reasoning with predicate calculus Search z. Use and/or graphs to represent implications of the form p q r Copyright P. Doerschuk 16
Search z. Two methods of searching graph: ydata-driven: find path from known true facts to goal ygoal directed: start with the proposition to be proved (the goal) and search backwards along arcs to find support for the goal among the true propositions Copyright P. Doerschuk 17
Search z. Examples: zp. 110, fig 3. 21 zp. 112, fig 3. 23 zfinancial advisor fig 3. 24 zsentence parser p. 116, fig 3. 25 Copyright P. Doerschuk 18
Guided (heuristic) search Search zuses additional information, often in the form of estimates, to guide the search Copyright P. Doerschuk 19
Guided (heuristic) search Search cont. zhill-climbing yeach node has an associated value or cost; move to the node with the highest value (or lowest cost) yuses no memory and backtracking ycan only find local maximum (minimum) Copyright P. Doerschuk 20
Ex: Traveling Salesperson Search z. Fig. 3. 9 Copyright P. Doerschuk 21
Guided (heuristic) search Search cont. z. Best-first algorithm: 1. create a queue and add the first node to it 2. Loop: If the queue is empty, quit. Remove the first node from the queue. If the node contains the goal state, exit with the node as the solution. For each child of the current node: if the child has not yet been visited or the child is reached by a path of lower cost than when visited previously, add the child node to the queue, in order of cost, eliminating any other higher cost paths to this child Copyright P. Doerschuk 22
Guided (heuristic) search Search cont z. Heuristic evaluation function may be the sum of two components: yf(n) = g(n) + h(n) xg(n) measures cost from the start state to state n xh(n) estimates cost from state n to goal state Copyright P. Doerschuk 23
Guided (heuristic) search Search cont zfor the eight puzzle, yg(n) = the number of moves from start to the current state. y. H 1(n) = the number of tiles that are out of place; y. H 2(n) = the sum of the Manhattan distances (horizontal and vertical distances) for the tiles that are out of place Copyright P. Doerschuk 24
Guided (heuristic) search Search cont. z. A* search use evaluation function f(n)=g(n)+h(n) where h(n) <=h*(n) Copyright P. Doerschuk //h*(n) is actual minimum cost from n to goal 25
Shortest path problem Search 26 z. Find the shortest path from a start node to a goal node zmust keep track of paths and costs of paths zreject paths with loops zfor the shortest path problem, g(n) is the total distance between the initial state and the state n, and h(n) is the estimated distance from state n to the goal state z. A* also eliminates the more costly of redundant paths Copyright P. Doerschuk
Shortest path problem Search 27 cont. z. A* shortest path algorithm 1. create a queue and add the first node to it as a zero-length path. 2. Loop: x. If the queue is empty, quit and announce failure. x. Remove the first path from the queue. If it ends at the goal state, exit with this path as the solution. Otherwise, create new paths by extending the first path to all the neighbors of the terminal node. x. Reject all new paths with loops. x. If two or more paths reach a common node, delete all those paths except the one that reaches the common node with the minimum cost. x. Sort the entire queue by the sum of the path length and a lower bound estimate of the cost remaining, with least-cost paths in front. Copyright P. Doerschuk
Example: TSP Copyright P. Doerschuk Search 28
Ex: robot path planning z. P. 94 -99, Winston 3 rd Edition Copyright P. Doerschuk Search 29
Competitive (Game) Search z. Used for competitive games zuses a move generator, a position evaluator and a look-ahead strategy zgame states are represented as a tree zinitial state is the root zthe player (computer) is the maximizer, and the opponent is the minimizer; 'minimax' search Copyright P. Doerschuk 30
'minimax' search Search cont. zexample: tic-tac-toe zevaluation function measures the number of rows/columns/diagonals open to the player versus the opponent: E(s) = H(s) = (r. X + c. X + d. X) - (ro + co + do) Copyright P. Doerschuk 31
'minimax' search Search cont. zalpha beta pruning prunes branches which are not needed zlower bound alpha is the largest current value of all the MAX ancestors of the node zupper bound beta is the smallest current value of all its MIN ancestors z. X tries to maximize alpha at each MAX level; O tries to minimize beta at each MIN level Copyright P. Doerschuk 32
Summary z. Search methods yunguided xdepth first, breadth first yguided xhill climbing xbest first x. A* ycompetitive xminimax Copyright P. Doerschuk Search 33
- Slides: 33