0% found this document useful (0 votes)
54 views59 pages

Chapter03b Informed Search

The document discusses different search strategies including best-first search, greedy best-first search, and A* search. It provides examples of searching on maps and outlines properties of the different approaches. A* search combines elements of best-first search and Dijkstra's algorithm to find optimal solutions while expanding fewer nodes.

Uploaded by

Scribd Chou
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)
54 views59 pages

Chapter03b Informed Search

The document discusses different search strategies including best-first search, greedy best-first search, and A* search. It provides examples of searching on maps and outlines properties of the different approaches. A* search combines elements of best-first search and Dijkstra's algorithm to find optimal solutions while expanding fewer nodes.

Uploaded by

Scribd Chou
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/ 59

Chapter 3

Solving Problems by Searching


Jane Hsu
National Taiwan University

Acknowledgements: This presentation is created by Jane hsu based


on the lecture slides from The Artificial Intelligence: A Modern
Approach by Russell & Norvig, a PowerPoint version by Min-Yen Kan,
as well as various materials from the web.
Outline
Informed (Heuristic) Search Strategies

p Best-first search
n Greedy best-first search
n A* search

p Heuristic Functions
n Relaxed problems
n Pattern database

Heuristic Search Jane Hsu 2


Best-First Search
p Idea: use an evaluation function f(n) for each
node
n estimate of "desirability"
n Expand most desirable unexpanded node

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

p Special cases:
n greedy best-first search
n A* search

Heuristic Search Jane Hsu 3


Romania with Step Costs

Heuristic Search Jane Hsu 4


Greedy Best-First Search
p 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

p Greedy best-first search expands the node


that appears to be closest to goal

Heuristic Search Jane Hsu 5


Greedy Best-First Search Example

Heuristic Search Jane Hsu 6


Greedy Best-First Search Example

Heuristic Search Jane Hsu 7


Greedy Best-First Search Example

Heuristic Search Jane Hsu 8


Greedy Best-First Search Example

Heuristic Search Jane Hsu 9


Greedy Best-First Search Example

Heuristic Search Jane Hsu 10


Greedy Best-First Search Example

Heuristic Search Jane Hsu 11


Map of Manhattan
p How would you find a path from S to G?

52nd St
S

51st St G

50th St
10th Ave

9th Ave

8th Ave

2nd Ave
3rd Ave
7th Ave

6th Ave

5th Ave

4th Ave

Heuristic Search Jane Hsu 12


Best-First Search
p The Manhattan distance (D x+ D y) is an
estimate of the distance to the goal
n It is a heuristic function
p Best-First Search
n Order nodes in priority queue to minimize
estimated distance to the goal h(n)
p Compare w/ Dijkstra
n Order nodes in priority queue to minimize
actual distance from the start

Heuristic Search Jane Hsu 13


Best First in Action
p How would you find a path from S to G?

52nd St
S

51st St G

50th St
10th Ave

9th Ave

8th Ave

2nd Ave
3rd Ave
7th Ave

6th Ave

5th Ave

4th Ave

Heuristic Search Jane Hsu 14


Problem 1: Led Astray
p Eventually will expand vertex to get back
on the right track

52nd St
S G

51st St

50th St
10th Ave

9th Ave

8th Ave

2nd Ave
3rd Ave
7th Ave

6th Ave

5th Ave

4th Ave

Heuristic Search Jane Hsu 15


Problem 2: Optimality
p With Best-First Search, are you
guaranteed a shortest path is found when
n goal is first seen?
n when goal is removed from priority queue (as
with Dijkstra?)

Heuristic Search Jane Hsu 16


Sub-Optimal Solution
p No! Goal is by definition at distance 0:
will be removed from priority queue
immediately, even if a shorter path
exists! (5 blocks)

52nd St S h=2
h=5

51st St h=4 G h=1


9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave

Heuristic Search Jane Hsu 17


Properties of Greedy Best-First Search
p Complete? No – can get stuck in loops,
e.g., Iasi à Neamt à Iasi à Neamt à
p Time? O(bm), but a good heuristic can give
dramatic improvement
p Space? O(bm) -- keeps all nodes in
memory
p Optimal? No

Heuristic Search Jane Hsu 18


Synergy?
p Dijkstra / Breadth First guaranteed to find
optimal solution
p Best First often visits far fewer vertices,
but may not provide optimal solution

n Can we get the best of both?

Heuristic Search Jane Hsu 19


A* Search
p Idea: avoid expanding paths that are
already expensive
p
p Evaluation function f(n) = g(n) + h(n)
p
n g(n) = cost so far to reach n
n h(n) = estimated cost from n to goal
n f(n) = estimated total cost of path through n
to goal

Heuristic Search Jane Hsu 20


A* Search Example

Heuristic Search Jane Hsu 21


A* Search Example

Heuristic Search Jane Hsu 22


A* Search Example

Heuristic Search Jane Hsu 23


A* Search Example

Heuristic Search Jane Hsu 24


A* Search Example

Heuristic Search Jane Hsu 25


A* Search Example

Heuristic Search Jane Hsu 26


A* Search Example

Heuristic Search Jane Hsu 27


A* Search Example

Heuristic Search Jane Hsu 28


A* Search Example

Heuristic Search Jane Hsu 29


A* in Action

(5 blocks) vertex g(n) h(n) f(n)


52nd St S
52nd & 0 5 5
9th
51st St G

50th St
9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave

Heuristic Search Jane Hsu 30


A* in Action

(5 blocks) vertex g(n) h(n) f(n)


52nd St S
52nd & 5 2 7
4th
51st St G
51st & 9th 1 4 5

50th St
9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave

Heuristic Search Jane Hsu 31


A* in Action

(5 blocks) vertex g(n) h(n) f(n)


52nd St S
52nd & 5 2 7
4th
51st St G
51st & 8th 2 3 5

50th St 50th & 9th 2 5 7


9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave

Heuristic Search Jane Hsu 32


A* in Action

(5 blocks) vertex g(n) h(n) f(n)


52nd St S
52nd & 5 2 7
4th
51st St G
51st & 7th 3 2 5

50th St 50th & 9th 2 5 7

50th & 8th 3 4 7


9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave

Heuristic Search Jane Hsu 33


A* in Action

(5 blocks) vertex g(n) h(n) f(n)


52nd St S
52nd & 5 2 7
4th
51st St G
51st & 6th 4 1 5

50th St 50th & 9th 2 5 7

50th & 8th 3 4 7


9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave 50th & 7th 4 3 7

Heuristic Search Jane Hsu 34


A* in Action

(5 blocks) vertex g(n) h(n) f(n)


52nd St S
52nd & 5 2 7
4th
51st St G
51st & 5th 5 0 5

50th St 50th & 9th 2 5 7

50th & 8th 3 4 7


9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave 50th & 7th 4 3 7

Heuristic Search Jane Hsu 35


A* in Action

(5 blocks) vertex g(n) h(n) f(n)


52nd St S
52nd & 5 2 7
4th
51st St G
50th & 9th 2 5 7

50th St 50th & 8th 3 4 7

50th & 7th 4 3 7


9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave

DONE!
Heuristic Search Jane Hsu 36
What Would Dijkstra Have Done?
(5 blocks)
52nd St S

51st St G

50th St

49th St

48th St

47th St
9th Ave

8th Ave

7th Ave

6th Ave

5th Ave

4th Ave
Heuristic Search Jane Hsu 37
Admissible Heuristics
p 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.

p An admissible heuristic never overestimates the


cost to reach the goal, i.e., it is optimistic
p Example: hSLD(n) (never overestimates the actual
road distance)
p Theorem: If h(n) is admissible, A* using TREE-
SEARCH is optimal.

Heuristic Search Jane Hsu 38


Optimality of A* (proof)
p 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.
p

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


p g(G2) > g(G) since G2 is suboptimal
p f(G) = g(G) since h(G) = 0
p f(G2) > f(G) from above
Heuristic Search Jane Hsu 39
Optimality of A* (proof)
p 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.
p

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


p h(n) ≤ h* (n) since h is admissible
p g(n) + h(n) ≤ g(n) + h*(n)
p f(n) ≤ f(G)
Hence f(G2) > f(n), and A* will never select G2 for expansion
Heuristic Search Jane Hsu 40
Optimality of A*
p A* expands nodes in order of increasing f value
n Gradually adds "f-contours" of nodes
n Contour i has all nodes with f=fi, where fi < fi+1
n All nodes with f(n) > C* (optimal solution) are pruned.

Heuristic Search Jane Hsu 41


Properties of A*
p Complete? Yes (unless there are infinitely
many nodes with f ≤ f(G) )
p
p Time? Exponential
p
p Space? Keeps all nodes in memory
p
p Optimal? Yes

Heuristic Search Jane Hsu 42


Properties of A*
p Complete? Yes – assume finitely many nodes with f(n) ≤
f(G)
p Optimal? Yes
p Efficient?
n A* is optimally efficient for any given heuristic function. i.e. no
other optimal algorithm is guaranteed to expand fewer nodes
than A*.
p Time? Exponential
p Space? Exponential (all nodes in memory)

p Theorem: The search space of A* grows exponentially


unless the error in the heuristic function grows no faster
than the logarithm of the actual path cost. [p.101]

Heuristic Search Jane Hsu 43


Question?

Heuristic Search Jane Hsu 44


8-Puzzle
p Convert the initial configuration into the
goal configuration by moving the tiles.
p Legal moves:
n Move any tile to adjacent empty square

Heuristic Search Jane Hsu 45


Admissible Heuristics
E.g., for the 8-puzzle:

p h1(n) = number of misplaced tiles


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

p h1(S) = ?
p h2(S) = ?
p
Heuristic Search Jane Hsu 46
Admissible Heuristics
E.g., for the 8-puzzle:

p h1(n) = number of misplaced tiles


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

p h1(S) = ? 8
p h2(S) = ? 3+1+2+2+2+3+3+2 = 18
Heuristic Search Jane Hsu 47
Dominance
p If h2(n) ≥ h1(n) for all n (both admissible)
p then h2 dominates h1
p h2 is better for search
p

p Typical search costs (average number of nodes expanded):


p

p d=12 IDS = 3,644,035 nodes


A*(h1) = 227 nodes
A*(h2) = 73 nodes
p d=24 IDS = too many nodes
A*(h1) = 39,135 nodes
A*(h2) = 1,641 nodes
p

Heuristic Search Jane Hsu 48


7 2 3
4 1 6
Importance of Heuristics 8 5
p h1 = number of tiles in the wrong place
p h2 = sum of distances of tiles from correct location

D IDS A*(h1) A*(h2)


2 10 6 6
4 112 13 12
6 680 20 18
8 6384 39 25
10 47127 93 39
12 364404 227 73
14 3473941 539 113
18 3056 363
24
Heuristic Search Jane39135
Hsu 1641 49
Inventing Heuristic Functions
p Relaxed problems: the cost of an exact solution to a relaxed
problem is often a good heuristic for the original problem. e.g.
n A if B and C
n A if B
n A if C
n A
p Composite heuristics
n h(n) = max (h1(n),…,hm(n))
p Weighted evaluation function
n fw(n) = (1-w)g(n) + w h(n)
p Learn the coefficients for features of a state
n h(n) = c1x1(n) + … + ckxk(n)
p Statistical information
p Search cost
n Good heuristics should be efficiently computable.

Heuristic Search Jane Hsu 50


Relaxed Problems
p A problem with fewer restrictions on the actions is called a
relaxed problem
p
p The cost of an optimal solution to a relaxed problem is an
admissible heuristic for the original problem
p Original: move any tile to adjacent empty square
p Relaxed problems:
n Move from A to B, if A is adjacent to B.
p Manhattan distance
n Move from A to B, if B is empty.
p Gaschnig’s heuristic (1979)
n Move from A to B. e.g. a tile can be moved to anywhere
p Misplaced tiles

Heuristic Search Jane Hsu 51


Composite Heuristics
p Given a collection of admissible heuristics
h1… hn for a problem, and none of them
dominates any of the others, which should
we choose?

Heuristic Search Jane Hsu 52


Finding Optimal Solutions
p Input: A random solvable initial state
p Output: A shortest sequence of moves
that maps the initial state to the goal state

p Generalized sliding-tile puzzle is NP


Complete (Ratner and Warmuth, 1986)
n People can’t find optimal solutions.
n Progress measured by size of problems that
can be solved optimally.

Heuristic Search Jane Hsu 53


Fifteen Puzzle
p Invented by Sam Loyd in 1870s
p “...engaged the attention of nine
1 2 3
out of ten persons of both 4 5 6 7
sexes and of all ages and
conditions of the community.” 8 9 10 11
p $1000 prize to swap positions of 12131415
two tiles

Ø Adapted from “Recent Progress in the


Design and Analysis of Admissible
Heuristic Functions” by R. Korf.

Heuristic Search Jane Hsu 54


Linear Conflict Heuristic
3 1 1 3

p Hansson, Mayer, and Yung, 1991


p Given two tiles in their goal row, but reversed in
position, additional vertical moves can be added
to Manhattan distance.
p Still not accurate enough to solve 24-Puzzle
p We can generalize this idea further.
Heuristic Search Jane Hsu 55
Sub-Problems
p Admissible heuristics can also be derived
from the solution cost of a sub-problem of
a given problem.

Heuristic Search Jane Hsu 56


Pattern Database Heuristics
p A pattern database is a complete set of
such positions, with associated number of
moves.
n e.g. a 8-tile pattern database for the Fifteen
Puzzle contains 519 million entries.
p On 15 puzzle, IDA* with pattern database
heuristics is about 10 times faster than
with Manhattan distance
n Culberson and Schaeffer, 1996
p Pattern databases can also be applied to
Rubik’s Cube.
Heuristic Search Jane Hsu 57
Additive Databases
5 10 14 7 1 2 3
8 3 6 1 4 5 6 7
15 12 9 8 9 10 11
2 11 4 13 12 13 14 15
p The 7-tile database contains 58 million entries.
n 20 moves needed to solve red tiles
p The 8-tile database contains 519 million entries.
n 25 moves needed to solve blue tiles
p Overall heuristic is 20+25=45 moves
Heuristic Search Jane Hsu 58
Rubik’s Cube
p Invented in 1974 by
Erno Rubik of Hungary
p Over 100 million sold
worldwide
p Most famous
combinatorial puzzle
ever

Heuristic Search Jane Hsu 59

You might also like