0% found this document useful (0 votes)
3 views

Unit 2 - Heuristics Searching

The document discusses informed search algorithms, particularly heuristic search methods such as Greedy best-first search, A* search, and various local search algorithms. It emphasizes the significance of heuristics in optimizing search strategies, using the 8-puzzle as a primary example to illustrate different heuristic approaches. The document also covers the properties of these algorithms, including their completeness, time complexity, and optimality, particularly focusing on the A* search algorithm and the concept of admissible heuristics.

Uploaded by

Pratik Nirgun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit 2 - Heuristics Searching

The document discusses informed search algorithms, particularly heuristic search methods such as Greedy best-first search, A* search, and various local search algorithms. It emphasizes the significance of heuristics in optimizing search strategies, using the 8-puzzle as a primary example to illustrate different heuristic approaches. The document also covers the properties of these algorithms, including their completeness, time complexity, and optimality, particularly focusing on the A* search algorithm and the concept of admissible heuristics.

Uploaded by

Pratik Nirgun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Informed search algorithms

(Heuristic search)
Sub Topics
• Greedy best-first search
• A* search
• AO* search algorithm
• Local search algorithms
• Hill-climbing search
• Simulated annealing search
• Local beam search
• Genetic algorithms
Recall tree search…

This “strategy” is what


differentiates different
search algorithms
Significance of Heuristics
Example: 8 Puzzle

1 2 3 1 2 3
7 8 4 8 4
6 5 7 6 5
4
1 2 3 GOAL 1 2 3
8 4 7 8 4
7 6 5 6 5

right

1 2 3 1 2 3 1 2 3
7 8 4 7 8 4 7 4
6 5 6 5 6 8 5

Which move is best?


5
8 Puzzle Heuristics
• Blind search techniques used an arbitrary
ordering (priority) of operations.
• Heuristic search techniques make use of
domain specific information - a heuristic.
• What heurisitic(s) can we use to decide
which 8-puzzle move is “best” (worth
considering first).

6
8 Puzzle Heuristics
• For now - we just want to establish some
ordering to the possible moves (the values
of our heuristic does not matter as long as
it ranks the moves).
• Later - we will worry about the actual
values returned by the heuristic function.

7
A Simple 8-puzzle heuristic
• Number of tiles in the correct position.
– The higher the number is the better.
– Easy to compute (fast and takes little
memory).
– Probably the simplest possible heuristic.

8
Another approach
• Number of tiles in the incorrect position.
– This can also be considered a lower bound on
the number of moves from a solution!
– The “best” move is the one with the lowest
number returned by the heuristic.
– Is this heuristic more than a heuristic (is it
always correct?).
• Given any 2 states, does it always order them
properly with respect to the minimum number of
moves away from a solution?
9
1 2 3 GOAL 1 2 3
8 4 7 8 4
7 6 5 6 5

right

1 2 3 1 2 3 1 2 3
7 8 4 7 8 4 7 4
6 5 6 5 6 8 5
h=2 h=4 h=3

10
Another 8-puzzle heuristic
• Count how far away (how many tile
movements) each tile is from it’s correct
position.
• Sum up this count over all the tiles.
• This is another estimate on the number of
moves away from a solution.

11
1 2 3 GOAL 1 2 3
8 4 7 8 4
7 6 5 6 5

right

1 2 3 1 2 3 1 2 3
7 8 4 7 8 4 7 4
6 5 6 5 6 8 5
h=2 h=4 h=4

12
Techniques
• There are a variety of search techniques
that rely on the estimate provided by a
heuristic function.
• In all cases - the quality (accuracy) of the
heuristic is important in real-life application
of the technique!

13
Romania with step costs in km
Best-first search
• Idea: use an evaluation function f(n) for each node
– estimate of "desirability"
→ Expand most desirable unexpanded node

• Implementation:
Order the nodes in fringe in decreasing order of
desirability

• Special cases:
– greedy best-first search
– A* search
Greedy best-first search
• Evaluation function f(n) = h(n) (heuristic)
= estimate of cost from n to goal

e.g., hSLD(n) = straight-line distance from n


to Bucharest

• Greedy best-first search expands the node


that appears to be closest to goal
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Algorithm (GBFS)
• Open : it is a priority queue maintain to
store the node with most promising value
of the heuristic function
• Close : node that have already been
examined.
Contd…..
1. Start with OPEN contain just the initial state
2. Until a goal is found or there are no node left
on OPEN do:
1. Pick them best node on OPEN
2. Generate its successor
3. For each successor do
1. If it has not been generated before, evaluate it. Add it to
OPEN, record its parent
2. If it has been generated before, change the parent if new
path is better than the previous one.
Properties of GBFS
• Complete? Not unless it keeps track of all
states visited (otherwise can get stuck in
loops)
• e.g., Iasi → Neamt → Iasi → Neamt →

• Time? O(bm), but a good heuristic can give
dramatic improvement
• Space? O(bm) -- keeps all nodes in
memory
• Optimal? No
A* search
• 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 from n to goal
• f(n) = estimated total cost of path through
n to goal
A* search example
A* search example
A* search example
A* search example
A* search example
A* search example
Admissible heuristics
• A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach
the goal state from n.
• An admissible heuristic never overestimates the
cost to reach the goal, i.e., it is optimistic
• Example: hSLD(n) (never overestimates the
actual road distance)
• Theorem: If h(n) is admissible, A* using TREE-
SEARCH is optimal
Optimality of A* (proof)
• Suppose some suboptimal goal G2 has been generated and is in the
fringe. Let n be an unexpanded node in the fringe such that n is on a
shortest path to an optimal goal G.

• f(G2) = g(G2) since h(G2) = 0


• g(G2) > g(G) since G2 is suboptimal
• f(G) = g(G) since h(G) = 0
• f(G2) > f(G) from above

g(n) = cost so far to reach n h(n) = estimated cost from n to goal


• f(n) = estimated total cost of path through n to goal
Optimality of A* (proof)
• Suppose some suboptimal goal G2 has been generated and is in the
fringe. Let n be an unexpanded node in the fringe such that n is on a
shortest path to an optimal goal G.

• f(G2) > f(G) from above


• h(n) ≤ h*(n) since h is admissible
• g(n) + h(n) ≤ g(n) + h*(n)
• f(n) ≤ f(G)

Hence f(G2) > f(n), and A* will never select G2 for expansion
Admissible heuristics
E.g., for the 8-puzzle:

• h1(n) = number of misplaced tiles


• h2(n) = total Manhattan distance
(i.e., no. of squares from desired location of each tile)

• h1(S) = ?
• h2(S) = ?
Admissible heuristics
E.g., for the 8-puzzle:

• h1(n) = number of misplaced tiles


• h2(n) = total Manhattan distance
(i.e., no. of squares from desired location of each tile)

• h1(S) = ? 8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
Heuristic functions
• 8-puzzle
– Avg. solution cost is about 22 steps
– branching factor ~ 3
– Exhaustive search to depth 22:
• 3.1 x 1010 states.
– A good heuristic function can reduce the search process.

• Two commonly used heuristics


– h1 = the number of misplaced tiles
• h1(s)=8
– h2 = the sum of the distances of the tiles from their goal
positions (manhattan distance).
• h2(s)=3+1+2+2+2+3+3+2=18
Notion of dominance
• If h2(n) ≥ h1(n) for all n (both admissible)
• then h2 dominates h1
• h2 is better for search

• Typical search costs (average number of


nodes expanded) for 8-puzzle problem
Dominance

d=12 IDS = 3,644,035 nodes


A*(h1) = 227 nodes
A*(h2) = 73 nodes

d=24 IDS = too many nodes


A*(h1) = 39,135 nodes
A*(h2) = 1,641 nodes

You might also like