Presentation on theme: "1 Problem Solving Using Search Brute-force search Heuristic search Competitive search."— Presentation transcript:
1 Problem Solving Using Search Brute-force search Heuristic search Competitive search
Copyright P. Doerschuk Search2 Search cont. Many problems can only be solved by searching
Copyright P. Doerschuk Search3 Importance of efficient search algorithms zTic tac toe ystate space of 9!: x9 possible first moves, followed by 8 possible second moves, followed by 7 possible third moves, etc., or 9x8x7x…x1 moves or 9! yCan use exhaustive search zChess y possible paths ycan’t use exhaustive search
Copyright P. Doerschuk Search4 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 Search6 Tree-based search 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 Search7 Eights puzzle state tree
Copyright P. Doerschuk Search8 Graph search vs tree search zGeneral 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 Search9 Unguided (blind) 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 Search10 Unguided (blind) search cont. zBreadth 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 Search11 Breadth-first search zABCDEFGHIJKL QUEUE: A BC CDE DEFG EFGHI FGHIJK GHIJKLM HIJKLMNO IJKLMNO JKLMNO KLMNO LMNO
Copyright P. Doerschuk Search12 Unguided (blind) 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 Search13 Depth-first search zABDHIEJKCFL QUEUE: A BC DEC HIEC IEC EC JKC KC C FG LMG...
Copyright P. Doerschuk Search14 Breadth first vs depth first yBreadth 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 B n 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 Search15 Unguided (blind) search cont. zDepth-first search with iterative deepening yperform depth-first search up to a maxDepth 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(B n ) zNote: all unguided search techniques have worst case exponential time behavior
Copyright P. Doerschuk Search16 Using state space to represent reasoning with predicate calculus zUse and/or graphs to represent implications of the form p q r
Copyright P. Doerschuk Search17 zTwo 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 Search19 Guided (heuristic) search zuses additional information, often in the form of estimates, to guide the search
Copyright P. Doerschuk Search20 Guided (heuristic) 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 Search21 Ex: Traveling Salesperson zFig. 3.9
Copyright P. Doerschuk Search22 Guided (heuristic) search cont. zBest-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 Search23 Guided (heuristic) search cont zHeuristic 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 Search24 Guided (heuristic) search cont zfor the eight puzzle, yg(n) = the number of moves from start to the current state. yH1(n) = the number of tiles that are out of place; yH2(n) = the sum of the Manhattan distances (horizontal and vertical distances) for the tiles that are out of place
Copyright P. Doerschuk Search25 Guided (heuristic) search cont. zA* search use evaluation function f(n)=g(n)+h(n) where h(n) <=h*(n) //h*(n) is actual minimum cost from n to goal
Copyright P. Doerschuk Search26 Shortest path problem zFind 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 zA* also eliminates the more costly of redundant paths
Copyright P. Doerschuk Search27 Shortest path problem cont. zA* shortest path algorithm 1. create a queue and add the first node to it as a zero-length path. 2. Loop: xIf the queue is empty, quit and announce failure. xRemove 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. xReject all new paths with loops. xIf two or more paths reach a common node, delete all those paths except the one that reaches the common node with the minimum cost. xSort 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 Search30 Competitive (Game) Search zUsed 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 Search31 'minimax' 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) = (rX + cX + dX) - (ro + co + do)
Copyright P. Doerschuk Search32 'minimax' 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 zX tries to maximize alpha at each MAX level; O tries to minimize beta at each MIN level
Copyright P. Doerschuk Search33 Summary zSearch methods yunguided xdepth first, breadth first yguided xhill climbing xbest first xA* ycompetitive xminimax