Professional Documents
Culture Documents
AI Lecture 5 - Heuristic Search
AI Lecture 5 - Heuristic Search
Dr Rob Wortham
Heuristic Search
• What is a heuristic?
• Searching with heuristics
• Greedy best-first
• A*
• Choosing heuristics – relaxed problems
• Reading
• Labs
• Heuristics
• Strategies derived from previous experiences with similar
problems.
• Depend on using readily accessible, though loosely applicable,
information to improve problem solving.
• Heuristics in Search
• h(n) = estimated cost of the cheapest path from the state at node
n to a goal state.
• h(n) = 0 if n is a goal state
LET’S
IGNORE
THIS PART
Sibiu Bucharest
Best-first
Optimal solution
solution
22/01/2024 Artificial Intelligence - Lecture 5 5
Greedy Best-First search – another problem
Initial state
Goal state
…
22/01/2024 Artificial Intelligence - Lecture 5 6
Greedy Best-First search – Key Facts
• Complete
• Only when performing graph search in finite state set.
• No, otherwise (it can get into loops).
• Optimal
• No.
g(n h(n
) )
I n G
Known cost from Estimated cost to goal
initial state state
Optimal …
solution
22/01/2024 Artificial Intelligence - Lecture 5 9
A* Search – Key facts
• Complete
• Yes.
• Optimal
• Yes. Tree search version is optimal with an admissible heuristic (see next slides).
• Graph search version is optimal with a consistent heuristic (see next slides).
• Example: Straight-line distance is admissible because the shortest path between any two
points is a straight line.
h(n)
h(nʹ)
• Consistency is required only for A* graph search.
• Every consistent heuristic is also admissible.
n nʹ
c
1955
1845 Babbage: The term
Discussed “Artificial
programming a intelligence”
computer to is coined
play chess.
22/01/2024 Artificial Intelligence - Lecture 5 13
Heuristic functions – The 8 Puzzle
7 2 4 7 2 4 7 2 4
5 8 6 5 8 5 6
1 3 1 3 6 1 3 8
A. ≅ 3 steps
Exhaustive tree search to depth 22 would examine roughly 322 ≅ 3.1 x 1022 states.
Graph search is much more efficient: 181,440 distinct states are reachable.
7
5
2
8
4
6
? 1
4
2
5
3
6
1 3 7 8
d = length
of optimal
solution
IDS =
Incremental
Deepening
Search
Is h2 always better than h1? Essentially, yes. Because h2 dominates h1: h2(n) >= h1(n), for any node n.
22/01/2024 Artificial Intelligence - Lecture 5 17
Heuristic functions – More Generally
• What about other problems?
• Is there a general way to generate good heuristic functions?
• Remember
• h1 = the number of misplaced tiles
• h2 = total distance of tiles from their goal positions
• Heuristic functions h1 and h2 are accurate path lengths for simplified versions of the problem.
• If we could move a tile anywhere, then h1 gives the shortest solution.
• If we could move a tile to any adjacent square, then h2 gives the shortest solution.
• The cost of an optimal solution to a relaxed problem is a lower bound on the cost of an optimal
solution to the real problem.
• Example: 8 Queens
• What is a heuristic?
• Searching with heuristics
• Greedy best-first
• A*
• Choosing heuristics – relaxed problems
• Reading
• Labs
Questions ?