Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Informed Search and Exploration. Outline Best-First Search Greedy Best-First Search A * Search Heuristics Variances of A* Search.

Similar presentations


Presentation on theme: "Chapter 4 Informed Search and Exploration. Outline Best-First Search Greedy Best-First Search A * Search Heuristics Variances of A* Search."— Presentation transcript:

1 Chapter 4 Informed Search and Exploration

2 Outline Best-First Search Greedy Best-First Search A * Search Heuristics Variances of A* Search

3 Tree Search (Reviewed, Fig. 3.9) A search strategy is defined by picking the order of node expansion function T REE -S EARCH ( problem, strategy ) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree

4 Search Strategies Uninformed Search Strategies by systematically generating new states and testing against the goal Informed Search Strategies by using problem-specific knowledge beyond the definition of the problem to find solutions more efficiently

5 Best-First Search An instance of general Tree-Search or Graph- Search A node is selected for expansion based on an evaluation function, f(n), with the lowest evaluation an estimate of desirability expand most desirable unexpanded node Implementation a priority queue that maintains the fringe in ascending order of f-values Best-first search is venerable but inaccurate

6 Best-First Search (cont.-1) Heuristic search uses problem-specific knowledge: evaluation function Choose the seemingly-best node based on the cost of the corresponding solution Need estimate of the cost to a goal e.g.,depth of the current node sum of distances so far Euclidean distance to goal, etc. Heuristics: rules of thumb Goal: to find solutions more efficiently

7 Best-First Search (cont.-2) Heuristic Function h(n) =estimated cost of the cheapest path from node n to a goal (h(n) = 0, for a goal node) Special cases Greedy Best-First Search (or Greedy Search) minimizing estimated cost from the node to reach a goal A * Search minimizing the total estimated solution cost

8 Heuristic Heuristic is derived from heuriskein in Greek, meaning to find or to discover The term heuristic is often used to describe rules of thumb or advices that are generally effective, but not guaranteed to work in every case In the context of search, a heuristic is a function that takes a state as an argument and returns a number that is an estimate of the merit of the state with respect to the goal

9 Heuristic (cont.) A heuristic algorithm improves the average-case performance, but does not necessarily improve the worst-case performance Not all heuristic functions are beneficial The time spent evaluating the heuristic function in order to select a node for expansion must be recovered by a corresponding reduction in the size of search space explored Useful heuristics should be computationally inexpensive!

10 Romania with Step Costs in km Straight-line distances to Bucharest Arad366 Bucharest0 Craiova160 Drobeta242 Eforie161 Fagaras176 Giurgiu77 Hirsova151 Iasi226 Lugoj244 Mehadia241 Neamt234 Oradea380 Pitesti100 Rimnicu Vilcea193 Sibiu253 Timisoara329 Urziceni80 Vaslui199 Zerind374

11 Greedy Best-First Search Greedy best-first search expands the nodes that appears to be closest to the goal Evaluation function = Heuristic function f(n) = h(n) = estimated best cost to goal from n h(n) = 0 if n is a goal e.g., h SLD (n) = straight-line distance for route-finding function G REEDY -S EARCH ( problem ) returns a solution, or failure return B EST -F IRST -S EARCH ( problem, h )

12 Greedy Best-First Search Example

13 Analysis of Greedy Search Complete? Yes (in finite space with repeated-state checking) No (start down an infinite path and never return to try other possibilities) (e.g., from Iasi to Fagaras) Susceptible to false starts Isai Neamt (dead end) No repeated states checking Isai Neamt Isai Neamt (oscillation)

14 Analysis of Greedy Search (cont.) Optimal? No (e.g., from Arad to Bucharest) Arad Sibiu Fagaras Bucharest (450 = , is not shortest) Arad Sibiu Rim Pitesti Bucharest (418 = ) Time? best: O(d), worst: O(b m ) m: the maximum depth like depth-first search a good heuristic can give dramatic improvement Space? O(b m ): keep all nodes in memory

15 A * Search Avoid expanding paths that are already expansive To minimizing the total estimated solution cost Evaluation function f(n) = g(n) + h(n) f(n) = estimated cost of the cheapest solution through n g(n) = path cost so far to reach n h(n) = estimated cost of the cheapest path from n to goal function A * -S EARCH ( problem ) returns a solution, or failure return BEST-FIRST-SEARCH ( problem, g+h )

16 Romania with Step Costs in km (remind) Straight-line distances to Bucharest Arad366 Bucharest0 Craiova160 Drobeta242 Eforie161 Fagaras176 Giurgiu77 Hirsova151 Iasi226 Lugoj244 Mehadia241 Neamt234 Oradea380 Pitesti100 Rimnicu Vilcea193 Sibiu253 Timisoara329 Urziceni80 Vaslui199 Zerind374

17 A * Search Example

18 Romania with Step Costs in km (remind) Straight-line distances to Bucharest Arad366 Bucharest0 Craiova160 Drobeta242 Eforie161 Fagaras176 Giurgiu77 Hirsova151 Iasi226 Lugoj244 Mehadia241 Neamt234 Oradea380 Pitesti100 Rimnicu Vilcea193 Sibiu253 Timisoara329 Urziceni80 Vaslui199 Zerind

19 Admissible Heuristic A * search uses an admissible heuristic h(n) h(n) never overestimates the cost to the goal from n n, h(n) h * (n), where h * (n) is the true cost to reach the goal from n (also, h(n) 0, so h(G) = 0 for any goal G) e.g., h(n) is not admissible g(X) + h(X) = 102 g(Y) + h(Y) = 74 Optimal path is not found! e.g., straight-line distance h SLD (n) never overestimates the actual road distance

20 Admissible Heuristic (cont.) e.g., 8-puzzle h 1 (n) = number of misplaced tiles h 2 (n) = total Manhattan distance i.e., no. of squares from desired location of each tile h 1 (S) = h 2 (S) = A * is complete and optimal if h(n) is admissible = 18

21 Optimality of A * (proof) Suppose some suboptimal goal G 2 has been generated and is in the queue Let n be an unexpanded node on a shortest path to an optimal goal G

22 Optimality of A * (cont.-1) C*: cost of the optimal solution path A* may expand some nodes before selecting a goal node Assume: G is an optimal and G 2 is a suboptimal goal f(G 2 ) = g(G 2 ) + h(G 2 ) = g(G 2 ) > C * (1) For some n on an optimal path to G, if h is admissible, then f(n) = g(n) + h(n) C * (2) From (1) and (2), we have f(n) C * < f(G 2 ) So, A * will never select G 2 for expansion

23 Monotonicity (Consistency) of Heuristic A heuristic is consistent if h(n) c(n, a, n) + h(n) the estimated cost of reaching the goal from n is no greater than the step cost of getting to successor n plus the estimated cost of reaching the goal from n If h is consistent, we have f(n)= g(n) + h(n) = g(n) + c(n, a, n) + h(n) g(n) + h(n) = f(n) f(n) f(n) i.e., f(n) is non-decreasing along any path Theorem: If h(n) is consistent, A * is optimal n n G h(n) c(n,a,n )

24 Optimality of A * (cont.-2) A * expands nodes in order of increasing f value Gradually adds f-contours of nodes Contour i has all nodes with f=f i, where f i < f i+1

25 Why Use Estimate of Goal Distance? Order in which uniform-cost looks at nodes. A and B are same distance from start, so will be looked at before any longer paths. No bias toward goal. Assume states are points the Euclidean plane Order of examination using dist. From start + estimates of dist. to goal. Notes bias toward the goal; points away from goal look worse. ABgoal start

26 Analysis of A * Search Complete? Yes unless there are infinitely many nodes with f f(G) Optimal? Yes, if the heuristic is admissible Time? Exponential in [relative error in h * length of solution] Space? O(b d ), keep all nodes in memory Optimally Efficient? Yes i.e., no other optimal algorithms is guaranteed to expand fewer nodes than A* A* is not practical for many large-scale problems since A * usually runs out of space long before it runs out of time

27 Heuristic Functions Example for 8-puzzle branching factor 3 depth = 22 # of states = ! / 2 = 181,400 (reachable distinct states) for 15-puzzle # of states Two commonly used candidates h 1 (n)= number of misplaced tiles = 8 h 2 (n)= total Manhattan distance (i.e., no. of squares from desired location to each tile) = = 18 Start State Goal State

28 Effect of Heuristic Accuracy on Performance h 2 dominates (is more informed than) h 1

29 Effect of Heuristic Accuracy on Performance (cont.) Effective Branching Factor b * is defined by N + 1 = 1 + b * + (b * ) 2 + +(b * ) d N: total number of nodes generated by A * d: solution depth b * : branching factor that a uniform tree of depth d would have to have in order to contain N+1 nodes e.g., A * finds a solutions at depth 5 using 52 nodes, then b * = 1.92 A well designed heuristic would have a value of b * close to 1, allowing fairly large problems to be solved A heuristic function h 2 is said to be more informed than h 1 (or h 2 dominates h 1 ) if both are admissible and n, h 2 (n) h 1 (n) A * using h 2 will never expand more nodes than A * using h 1

30 Inventing Admissible Heuristic Functions Relaxed problems problems with fewer restrictions on the actions The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem e.g., 8-puzzle A tile can move from square A to square B if A is horizontally or vertically adjacent to B and B is blank. (P if R and S) 3 relaxed problems A tile can move from square A to square B if A is horizontally or vertically adjacent to B. (P if R) --- derive h 2 A tile can move from square A to square B if B is blank. (P if S) A tile can move from square A to square B. (P) --- derive h 1

31 Inventing Admissible Heuristic Functions (cont.-1) Composite heuristics Given h 1, h 2, …, h m ; none dominates any others h(n) = max { h 1 (n), h 2 (n), …, h m (n) } Subproblem The cost of the optimal solution of the subproblem is a lower bound on the cost of the complete problem To get tiles 1, 2, 3 and 4 into their correct positions, without worrying about what happens to other tiles. Start State Goal State

32 Inventing Admissible Heuristic Functions (cont.-2) Weighted evaluation functions f w (n) = (1-w)g(n) + wh(n) Learn the coefficients for features of a state h(n) = w 1 f 1 (n),, w k f k (n) Search cost Good heuristics should be efficiently computable

33 Memory-Bounded Heuristic Search Overcome the space problem of A *, without sacrificing optimality or completeness IDA * (iterative deepening A * ) a logic extension of iterative deepening search to use heuristic information the cutoff used is the f-cost (g+h) rather than depth RBFS(recursive best-first search) MA * (memory-bounded A * ) SMA * (simplified MA * ) is similar to A *, but restricts the queue size to fit into the available memory

34 Iterative Deepening A * Iterative deepening is useful for reducing memory requirement At each iteration, perform DFS with an f-cost limit IDA * is complete and optimal (with the same caveats as A * search) Space complexity: O (bf * / ) O(bd) f * : the optimal solution cost : the smallest operator cost Time complexity: O( b d ) : the number of different f values In the worst case, if A * expands N nodes, IDA * will expand 1+2+…+N = O(N 2 ) nodes IDA * uses too little memory

35 Iterative Deepening A * (cont.-1) first, each iteration expands all nodes inside the contour for the current f-cost peeping over to find out the next contour lines once the search inside a given contour has been complete a new iteration is started using a new f-cost for the next contour

36 Iterative Deepening A * (cont.-2) function IDA * ( problem ) returns a solution sequence inputs: problem, a problem local variables: f-limit, the current f -C OST limit root, a node root M AKE -N ODE ( I NITIAL -S TATE [ problem ]) f-limit f -C OST ( root ) loop do solution, f-limit DFS-C ONTOUR ( root, f-limit ) if solution is non-null then return solution if f-limit = then return failure end

37 Iterative Deepening A * (cont.-3) function DFS-C ONTOUR ( node, f-limit ) returns a solution sequence and a new f -C OST limit inputs: node, a node f-limit, the current f -C OST limit local variables: next-f, the f -C OST limit for the next contour, initially if f -C OST [ node ] > f-limit then return null, f -C OST [ node ] if G OAL -T EST [ problem ]( S TATE [ node ]) then return node, f-limit for each node s in S UCCESSORS ( node ) do solution, new-f DFS-C ONTOUR ( s, f-limit ) if solution is non-null then return solution, f-limit next-f M IN ( next-f, new-f ) end return null, next-f

38 Recursive Best-First Search (RBFS) Keeps track of the f-value of the best-alternative path available if current f-values exceeds this alternative f-value, then backtrack to alternative path upon backtracking change f-value to the best f-value of its children re-expansion of this result is thus still possible

39 Recursive Best-First Search (cont.-1) Arad 366 Timisoara 447 Zerind 449 Sibiu 393 Arad 646 Fagaras 415 Oradea Craiova Sibiu 553 Rim Vil Pitesti 415 Arad 366 Timisoara 447 Zerind 449 Sibiu 393 Arad 646 Fagaras 415 Oradea Sibiu 591 Bucharest 450 Fagaras 417 Rim Vil Arad 366 Timisoara 447 Zerind 449 Sibiu 393 Arad 646 Fagaras 415 Oradea Bucharest 418 Craiova 615 Rim Vil 607 Pitesti Craiova Sibiu 553 Rim Vil 447

40 Recursive Best-First Search (cont.-2) function R ECURSIVE -B EST -F IRST -S EARCH ( problem ) returns a solution, or failure RBFS( problem, M AKE -N ODE ( I NITIAL -S TATE [ problem ] ), ) function RBFS ( problem, node, f_limit ) returns a solution, or failure and a new f -C OST limit if G OAL -T EST [ problem ]( S TATE [ node ]) then return node successors E XPAND ( node, problem ) if successors is empty then return failure, for each node s in successors do f [ s ] max( g ( s ) + h ( s ), f [ node ]) repeat best the lowest f -value node in successors if f [ best ] f_limit then return failure, f [ best ] alternative the second lowest f -value among successors result, f [ best ] RBFS( problem, best, M IN ( f_limit, alternative )) if result failure then return result

41 Analysis of RBFS RBFS is a bit more efficient than IDA* still excessive node generation (mind changes) Complete? Yes Optimal? Yes, if the heuristic is admissible Time? Exponential difficult to characterize, depend on accuracy of h(n) and how often best path changes Space? O(bd) IDA* and RBFS suffer from too little memory

42 Simplified Memory Bounded A * (SMA * ) SMA * expands the (newest) best leaf and deletes the (oldest) worst leaf Aim: find the lowest-cost goal node with enough memory Max Nodes = 3 A – root node D,F,I,J – goal nodes Label: current f-Cost

43 Simplified Memory Bounded A * (cont.-1) 3. memory is full update (A) f-Cost for the min chlid expand G, drop the higher f-Cost leaf (B) 5. drop H and add I G memorize H update (G) f-Cost for the min child update (A) f-Cost 6. I is goal node, but may not be the best solution the path through G is not so great, so B is generated for the second time 7. drop G and add C A memorize G C is non-goal node C mark to infinite 8. drop C and add D B memorize C D is a goal node, and it is lowest f-Cost node then terminate How about J has a cost of 19 instead of 24 ?

44 Simplified Memory Bounded A * (cont.-2) A 0+12=12 F 30+0=30 E 30+5=35 D 20+0=20 C 20+5=25 G 8+5=13 B 10+5=15 K 24+5=29 J 24+0=24 I H 16+2=18 Aim: find the lowest-cost goal node with enough memory Max Nodes = 3 A – root node D,F,I,J – goal nodes Label: current f-Cost

45 Simplified Memory Bounded A * (cont.-3) A 12 A B 15 A 13 G B 15 memory is full update (A) f-cost for the min child expand G, drop the higher f-cost leaf (B) A 13 (15) G 13 H 18 infinite memory is full A 15 (15) G 24 (infinite) I 24 drop H and add I G memorize H update (G) f-cost for the min child update (A) f-cost A 15 G 24 B 15 I is goal node, but may not be the best solution the path through G is not so great so B is generate for the second time A 15 (24) C 25 infinite B 15 drop G and add C A memorize G C is non-goal node C mark to infinite A 20 (24) D 20 B 20 (infinite) drop C and add D B memorize C D is a goal node and it is lowest f-cost node then terminate How about J has a cost of 19 instead of 24 ??

46 Simplified Memory Bounded A * (cont.-4) function SMA * ( problem ) returns a solution sequence inputs: problem, a problem local variables: Queue, a queue of nodes ordered by f -C OST Queue M AKE -Q UEUE ({ M AKE -N ODE ( I NITIAL -S TATE [ problem ])}) loop do if Queue is empty then return failure n deepest least f -C OST node in Queue if G OAL -T EST ( n ) then return success s N EXT -S UCCESSOR ( n ) if s is not a goal and is at maximum depth then f( s ) else f( s ) M AX ( f( n ), g ( s ) + h ( s )) if all of n s successors have been generated then update n s f -C OST and those of its ancestors if necessary if S UCCESSORS ( n ) all in memory then remove n from Queue if memory is full then delete shallowest, highest f -C OST node in Queue remove it from its parents successor list insert its parent on Queue if necessary insert s on Queue end

47 SMA * Algorithm SMA * makes use of all available memory M to carry out the search It avoids repeated states as far as memory allows Forgotten nodes: shallow nodes with high f-cost will be dropped from the fringe A forgotten node will only be regenerated if all other child nodes from its ancestor node have been shown to look worse Memory limitations can make a problem intractable

48 Analysis of SMA * Complete? Yes, if M d i.e.,if there is any reachable solution i.e.,the depth of the shallowest goal node is less than the memory size Optimal? Yes, if M d * i.e.,if any optimal solution is reachable; otherwise, it returns the best reachable solution Optimally efficiently? Yes, if M b m Time? It is often that SMA * is forced to switch back and forth continually between a set of candidate solution paths Thus, the extra time required for repeated generation of the same node Memory limitations can make a problem intractable from the point of view of computation time Space? Limited

49 HW2, 4/11 deadline Write an A* programs to solve the path finding problem.


Download ppt "Chapter 4 Informed Search and Exploration. Outline Best-First Search Greedy Best-First Search A * Search Heuristics Variances of A* Search."

Similar presentations


Ads by Google