Download presentation
1
Problem Solving and Search in AI Heuristic Search
2
Heuristic Search Problem with uniform cost search Solution:
We are only considering the cost so far, not the expected cost of getting to the goal node But, we don’t know before hand the cost of getting to the goal from a previous state Solution: Need to estimate for each state the cost of getting from there to a goal state Use “heuristic” information to guess which nodes to expand next the heuristic is in the form of an evaluation function based on domain-specific information related to the problem. the evaluation function gives us a way to evaluate a node “locally” based on an estimate of the cost to get from the node to a goal node (the idea is to find the least cost path to a goal node).
3
Evaluation Functions h(n) is the heuristic function g(n): cost of the best path found so far between the initial node and n f(n) = h(n) greedy best-first search f(n) = g(n) + h(n) A* search
4
Best-First Search Basic Idea: always expand the node that minimizes (or maximizes) the evaluation function f(n) Greedy strategy: f(n) = h(n), where h(n) estimates the cost of getting from the node n to the goal if we keep nodes in memory (on the queue) for backtracking, then this is called (Greedy) Best-First search; if no queue and we stop as soon as f(n) is worse for the children than the parent, then this is called Hill-Climbing. What happens if always try at each step to move closer to the goal node? The BFS algorithm in this case will find the longer solution path, since it will begin by moving forward and then be committed to this choice. What about hill-climbing?
5
Best-First Search The evaluation function f maps each search node n to positive real number f(n) Traditionally, the smaller f(n), the more promising n Best-first search sorts the search queue at each step in increasing order of f random order is assumed among nodes with equal values of f
6
Best-First Search The evaluation function f maps each search node n to positive real number f(n) Traditionally, the smaller f(n), the more promising n Best-first search sorts the search queue at each step in increasing order of f random order is assumed among nodes with equal values of f “Best” only refers to the value of f, not to the quality of the actual path. Best-first search does not generate optimal paths in general
7
Best-First Search Example (Romania)
Suppose we don’t know the actual distances beforehand, but can figure out the straight line distances from a map
8
Best-First Search Example (Romania)
Suppose we don’t know the actual distances beforehand, but can figure out the straight line distances from a map Heuristic evaluation function: h(n) = straight-line distance between n and Bucharest h(n) is a heuristic because it is an estimate of the actual cost of getting from n to the goal Note that h(goal) = 0 always
9
Greedy Best-First Search
Arad h(n) = 366 <== Arad <==
10
Greedy Best-First Search
Arad h(n) = 366 h(n) = 253 Sibiu h(n) = 329 Timisoara h(n) = 374 Zerind <== Sibiu, Timisoara, Zerind <==
11
Greedy Best-First Search
Arad h(n) = 366 h(n) = 253 Sibiu h(n) = 329 Timisoara h(n) = 374 Zerind 366 178 193 380 Arad Fagaras Oradea Rimnicu <== Fagaras, Rimnicu, Timisoara, Zerind, Oradea <==
12
Greedy Best-First Search
Arad h(n) = 366 h(n) = 253 Sibiu h(n) = 329 Timisoara h(n) = 374 Zerind 178 193 380 Fagaras Oradea Rimnicu 253 h(n) = 0 Sibiu Bucharest <== Bucharest, Rimnicu, Timisoara, Zerind, Oradea <==
13
Greedy Best-First Search
Arad h(n) = 366 h(n) = 253 Sibiu h(n) = 329 Timisoara h(n) = 374 Zerind 178 193 380 Fagaras Oradea Rimnicu h(n) = 0 Actual cost of the solution: Arad => Sibiu => Fagaras => Bucharest is = 450 But, consider the path: Arad => Sibiu => Rimnicu => Pitesti => Bucharest with the cost 418 – So we got a suboptimal solution 253 Sibiu Bucharest
14
Heuristics for 8-Puzzle Problem
In total, there are a possible of 9! or 362,880 possible states. However, with a good heuristic function, it is possible to reduce this state to less than 50. Some possible heuristics for 8-Puzzle: h1(n) = no. of misplaced tiles may have many plateaus (indistinguishable states) doesn’t captures the number of moves to get to the right place h2(n) = sum of Manhattan distances (i.e., no. of squares from desired location of each tile) doesn’t capture the importance of sequencing tiles (putting them in the right order)
15
Heuristics for 8-Puzzle Problem
5 4 1 2 3 6 1 8 8 4 7 3 2 7 6 5 s = start state g = goal state h1(s) = 7 h2(s) = = 18
16
18 19 17 16 15 14 13 Part of the search tree generated by Best-First search using h2 = sum of Manhattan distances.
17
Heuristics Search in 8-Puzzle
18 19 17 16 15 14 13 12 11 Part of the search tree generated by Best-First search using h2 = sum of Manhattan distances. What will happen with hill-climbing? Initial Node Goal Node
18
A* Search (most popular algorithm in AI)
Basic Idea: avoid expanding paths that are already expensive Evaluation function: f(n) = g(n) + h(n) g(n) = cost so far to reach n h(n) = estimated cost to goal from n f(n) = estimated total cost of path through n to reach the goal Admissible heuristics i.e., h(n) £ h*(n), for all n, where h*(n) is the true cost from n Ex: straight-line distance never overestimates the actual road distance Ex: h1 and h2 is 8-puzzle never overestimate the actual no. of moves A* search is optimal (finds lowest cost solution) if h(n) is admissible however, the number of nodes expanded depends on how good the heuristic is best case: h(n) = h*(n) for all n A* will find the best solution with no search if h(n) > h*(n) for some n, then A* might still work, but might not find any solution at all
19
A* Search Arad f(n) = 366 140 75 118 h(n) = 253 f(n) = 393 h(n) = 329
Sibiu Timisoara Zerind 140 99 151 80 Arad Fagaras Oradea Rimnicu f(n) = 413 f(n) = 646 f(n) = 417 f(n) = 661 146 97 80 Craiova Pitesti Sibiu f(n) = 526 f(n) = 415 f(n) = 553
20
A* Search ... h(n) = 253 f(n) = 393 Sibiu 140 99 151 80 Arad Fagaras
Oradea Rimnicu f(n) = 413 f(n) = 646 f(n) = 417 f(n) = 661 146 97 80 Craiova f(n) = 415 Pitesti Sibiu f(n) = 526 f(n) = 553 138 97 101 Rimnicu Craiova Bucharest f(n) = 607 f(n) = 615 f(n) = 418
21
A* Search ... h(n) = 253 f(n) = 393 Sibiu 140 99 80 151 Arad
Fagaras Oradea Rimnicu f(n) = 413 f(n) = 646 f(n) = 526 99 211 146 97 80 Sibiu Bucharest Craiova f(n) = 415 Pitesti Sibiu f(n) = 591 f(n) = 450 f(n) = 526 f(n) = 553 138 97 101 Rimnicu Craiova Bucharest f(n) = 607 f(n) = 615 f(n) = 418
22
A* Search ... h(n) = 253 f(n) = 393 Sibiu 140 99 80 151 Arad
Fagaras Oradea Rimnicu f(n) = 413 f(n) = 646 f(n) = 526 99 211 146 97 80 Sibiu Bucharest Craiova f(n) = 415 Pitesti Sibiu f(n) = 591 f(n) = 450 f(n) = 526 f(n) = 553 138 97 101 Rimnicu Craiova Bucharest f(n) = 607 f(n) = 615 f(n) = 418
23
A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).
g(n) assumes each move has a cost of 1. Here we assume repeated state checking. f(n) = g(n) + h(n)
24
Order of expansion f(n) = g(n) + h(n)
A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles). g(n) assumes each move has a cost of 1. Here we assume repeated state checking. Order of expansion f(n) = g(n) + h(n)
25
A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).
g(n) assumes each move has a cost of 1. Here we assume repeated state checking. f(n) = g(n) + h(n)
26
A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).
g(n) assumes each move has a cost of 1. Here we assume repeated state checking. f(n) = g(n) + h(n)
27
A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).
g(n) assumes each move has a cost of 1. Here we assume repeated state checking. f(n) = g(n) + h(n)
28
A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).
g(n) assumes each move has a cost of 1. Here we assume repeated state checking. f(n) = g(n) + h(n)
29
A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).
g(n) assumes each move has a cost of 1. Here we assume repeated state checking. f(n) = g(n) + h(n)
30
A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).
g(n) assumes each move has a cost of 1. Here we assume repeated state checking. f(n) = g(n) + h(n) Note: at level 2 there are two nodes listed with f(n) = 5. Depending on which node is we put in front of the queue, the algorithm will either expand 6 or 7 nodes. Here we have assumed the worse case, and thus the tree shows that 6 nodes were expanded 7
31
Efficiency of A* Comparison of search costs and effective branching factors for the Iterative Deepening search and A* algorithms with h1 and h2 for 8-puzzle. d is the average depth of the search tree. Data are averaged over 100 instances of the problem, for various solution lengths.
32
When to Use Search Techniques?
The search space is small, and No other technique is available, or Developing a more efficient technique is not worth the effort The search space is large, and No other available technique is available, and There exist “good” heuristics
33
Heuristics in Tic-Tac-Toe? (you are X)
Which is a better move? Why? ? ? Is there a heuristic we can use to evaluate these configurations? ?
34
Heuristics in Tic-Tac-Toe? (you are X)
Which is a better move? Why? ? ?
35
Exercise Consider the problem of solving a cross-word puzzle
initial state is an empty board with some possible blocked cells a goal state is board configuration filled in with legal English words: How can this problem be viewed as a search problem? What are the operators? How can we measure path costs? Etc. Assuming we have dictionary of 100,000 words, what would be a good (uninformed) search strategy to use? Why? What might be some good heuristics to use for this problem? How effective might hill-climbing strategies work in solving this problem? How can we handle the local minima problem? Propose a solution and discuss its effectiveness.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.