Recall that the ordering of FRINGE defines the Heuristic (Informed) search strategy Search Algorithm #2 Search SEARCH#2 1. INSERT(initial-node,FRINGE) (Where we try to choose smartly) (Wh t t h tl ) 2. Repeat: a. If empty(FRINGE) then return failure b. N � REMOVE(FRINGE) R&N: Chap. 4, Sect. 4.1–3 c. s � STATE(N) d. If GOAL?(s) then return path or goal state e. For every state s’ in SUCCESSORS(s) i. Create a node N’ as a successor of N ii. INSERT(N’,FRINGE) 1 2 Best-First Search Best-First Search � It exploits state description to estimate � It exploits state description to estimate how “good” each search node is how “good” each search node is � An evaluation function f maps each node � An evaluation function f maps each node N of the search tree to a real number N of the search tree to a real number “Best” does not refer to the quality “B t” d t f t th lit f(N) ≥ 0 f(N) ≥ 0 of the generated path [Traditionally, f(N) is an estimated cost; so, the smaller [Traditionally, f(N) is an estimated cost; so, the smaller Best-first search does not generate f(N), the more promising N] f(N), the more promising N] optimal paths in general � Best-first search sorts the FRINGE in � Best-first search sorts the FRINGE in increasing f increasing f [Arbitrary order is assumed among nodes with equal f] [Arbitrary order is assumed among nodes with equal f] 3 4 How to construct f? How to construct f? � Typically, f(N) estimates: � Typically, f(N) estimates: • either the cost of a solution path through N • either the cost of a solution path through N Then f(N) = g(N) + h(N), where Then f(N) = g(N) + h(N), where – g(N) is the cost of the path from the initial node to N – g(N) is the cost of the path from the initial node to N – h(N) is an estimate of the cost of a path from N to a goal node – h(N) is an estimate of the cost of a path from N to a goal node • or the cost of a path from N to a goal node • or the cost of a path from N to a goal node Then f(N) = h(N) � Greedy best-search Then f(N) = h(N) Heuristic function � But there are no limitations on f. Any function � But there are no limitations on f. Any function of your choice is acceptable. of your choice is acceptable. But will it help the search algorithm? But will it help the search algorithm? 5 6 1
Heuristic Function Other Examples � The heuristic function h(N) ≥ 0 estimates the cost to go from STATE (N) to a goal state 5 8 1 2 3 4 2 1 4 5 6 Its value is independent of the current 7 3 6 7 8 search tree ; it depends only on STATE(N) STATE (N) Goal state and the goal test GOAL? � h 1 (N) = number of misplaced numbered tiles = 6 � Example: 5 8 1 2 3 � h 2 (N) = sum of the (Manhattan) distance of 4 2 1 4 5 6 every numbered tile to its goal position = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1 = 13 7 3 6 7 8 � h 3 (N) = sum of permutation inversions STATE (N) Goal state = n 5 + n 8 + n 4 + n 2 + n 1 + n 7 + n 3 + n 6 h 1 (N) = number of misplaced numbered tiles = 6 = 4 + 6 + 3 + 1 + 0 + 2 + 0 + 0 [Why is it an estimate of the distance to the goal?] = 16 7 8 8-Puzzle 8-Puzzle f(N) = h(N) = number of misplaced numbered tiles f(N) = g(N) + h(N) with h(N) = number of misplaced numbered tiles 3 3 4 3+3 5 3 1+5 2+3 4 4 3+4 3+4 2 5+2 4 0+4 2 1 3+2 4+1 3 3 1+3 2+3 0 5+0 4 3+4 5 1+5 4 2+4 The white tile is the empty tile 9 10 8-Puzzle Robot Navigation f(N) = h(N) = Σ distances of numbered tiles to their goals N y N 6 5 2 y g 5 2 1 4 3 0 4 x g x N h (N) = (x -x ) +(y -y ) 2 2 (L 2 or Euclidean distance) 6 5 1 N g N g h 2 (N) = |x N -x g | + |y N -y g | (L 1 or Manhattan distance) 11 12 2
Best-First → Efficiency Can we prove anything? � If the state space is infinite, in general the Local-minimum problem search is not complete � If the state space is finite and we do not discard nodes that revisit states, in general discard nodes that revisit states in general the search is not complete � If the state space is finite and we discard nodes that revisit states, the search is complete, but in general is not optimal f(N) = h(N) = straight distance to the goal 13 14 Admissible Heuristic Admissible Heuristic � Let h*(N) be the cost of the optimal path � Let h*(N) be the cost of the optimal path from N to a goal node from N to a goal node � The heuristic function h(N) is admissible � The heuristic function h(N) is admissible if: if: 0 ≤ h(N) ≤ h*(N) 0 ≤ h(N) ≤ h*(N) � An admissible heuristic function is always � An admissible heuristic function is always optimistic ! optimistic ! G is a goal node � h(G) = 0 15 16 8-Puzzle Heuristics 8-Puzzle Heuristics 5 8 1 2 3 5 8 1 2 3 4 2 1 4 5 6 4 2 1 4 5 6 7 3 6 7 8 7 3 6 7 8 STATE (N) Goal state STATE (N) Goal state � h (N) = number of misplaced tiles = 6 � h 1 (N) = number of misplaced tiles = 6 � h (N) = number of misplaced tiles = 6 � h 1 (N) = number of misplaced tiles = 6 is ??? is admissible � h 2 (N) = sum of the (Manhattan) distances of � h 2 (N) = sum of the (Manhattan) distances of every tile to its goal position every tile to its goal position = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1 = 13 = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1 = 13 is admissible is ??? � h 3 (N) = sum of permutation inversions � h 3 (N) = sum of permutation inversions = 4 + 6 + 3 + 1 + 0 + 2 + 0 + 0 = 16 = 4 + 6 + 3 + 1 + 0 + 2 + 0 + 0 = 16 is not admissible is not admissible 17 18 3
8-Puzzle Heuristics 8-Puzzle Heuristics 5 8 1 2 3 5 8 1 2 3 4 2 1 4 5 6 4 2 1 4 5 6 7 3 6 7 8 7 3 6 7 8 STATE (N) Goal state STATE (N) Goal state � h 1 (N) = number of misplaced tiles = 6 � h (N) = number of misplaced tiles = 6 � h 1 (N) = number of misplaced tiles = 6 � h (N) = number of misplaced tiles = 6 is admissible is admissible � h 2 (N) = sum of the (Manhattan) distances of � h 2 (N) = sum of the (Manhattan) distances of every tile to its goal position every tile to its goal position = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1 = 13 = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1 = 13 is admissible is admissible � h 3 (N) = sum of permutation inversions � h 3 (N) = sum of permutation inversions = 4 + 6 + 3 + 1 + 0 + 2 + 0 + 0 = 16 = 4 + 6 + 3 + 1 + 0 + 2 + 0 + 0 = 16 is ??? is not admissible 19 20 Robot Navigation Heuristics Robot Navigation Heuristics Cost of one horizontal/vertical step = 1 Cost of one horizontal/vertical step = 1 Cost of one diagonal step = 2 Cost of one diagonal step = 2 h 2 (N) = |x N -x g | + |y N -y g | is ??? h (N) = (x -x ) +(y -y ) 2 2 is admissible 1 N g N g 21 22 Robot Navigation Heuristics How to create an admissible h? � An admissible heuristic can usually be seen as the cost of an optimal solution to a relaxed problem (one obtained by removing constraints) � In robot navigation: g • The Manhattan distance corresponds to removing the obstacles Cost of one horizontal/vertical step = 1 • The Euclidean distance corresponds to removing both Cost of one diagonal step = 2 the obstacles and the constraint that the robot moves on a grid h 2 (N) = |x N -x g | + |y N -y g | is admissible if moving along diagonals is not allowed, and � More on this topic later not admissible otherwise h * (I) = 4 √ 2 h 2 (I) = 8 23 24 4
A* Search Result #1 (most popular algorithm in AI) A* is complete and optimal 1) f(N) = g(N) + h(N), where: • g(N) = cost of best path found so far to N [This result holds if nodes revisiting • h(N) = admissible heuristic function states are not discarded] states are not discarded] 2) for all arcs: c (N,N’) ≥ ε > 0 3) SEARCH#2 algorithm is used � Best-first search is then called A* search 25 26 Proof (1/2) Proof (1/2) 1) If a solution exists, A* terminates and 1) If a solution exists, A* terminates and returns a solution returns a solution - For each node N on the fringe, - For each node N on the fringe, f(N) = g(N)+h(N) ≥ g(N) ≥ d(N) ×ε , f(N) = g(N)+h(N) ≥ g(N) ≥ d(N) ×ε , where d(N) is the depth of N in the tree h d(N) h d h f N h where d(N) is the depth of N in the tree h d(N) h d h f N h K - As long as A* hasn’t terminated, a node K on the fringe lies on a solution path 27 28 Proof (1/2) Proof (2/2) 1) If a solution exists, A* terminates and 2) Whenever A* chooses to expand a goal returns a solution node, the path to this node is optimal - C*= cost of the optimal solution path - For each node N on the fringe, f(N) = g(N)+h(N) ≥ g(N) ≥ d(N) ×ε , - G’: non-optimal goal node in the fringe where d(N) is the depth of N in the tree h d(N) h d h f N h f(G’) = g(G’) + h(G’) = g(G’) > C* K K - As long as A* hasn’t terminated, a node K G’ - A node K in the fringe lies on an optimal on the fringe lies on a solution path path: f(K) = g(K) + h(K) ≤ C* - Since each node expansion increases the length of one path, K will eventually be - So, G’ will not be selected for expansion selected for expansion, unless a solution is found along another path 29 30 5
Recommend
More recommend