0% found this document useful (0 votes)
40 views70 pages

Lect03 Informed Search

Greedy best-first search is an informed search strategy that selects nodes for expansion based solely on the heuristic estimate of distance to the goal. It evaluates nodes using just the heuristic function f(n) = h(n), where h(n) is a problem-specific heuristic function. This can quickly find solutions but is not guaranteed to be optimal. The document illustrates greedy best-first search on a problem involving traveling between cities in Romania using a straight-line distance heuristic.
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)
40 views70 pages

Lect03 Informed Search

Greedy best-first search is an informed search strategy that selects nodes for expansion based solely on the heuristic estimate of distance to the goal. It evaluates nodes using just the heuristic function f(n) = h(n), where h(n) is a problem-specific heuristic function. This can quickly find solutions but is not guaranteed to be optimal. The document illustrates greedy best-first search on a problem involving traveling between cities in Romania using a straight-line distance heuristic.
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/ 70

Informed Search

Bùi Tiến Lên

2022
Contents

1. Best-first search

2. Greedy best-first search

3. A* search

4. Memory-bounded heuristic search

5. Heuristic functions
Informed search strategies
Best-first
search

Greedy
best-first search

A* search
Informed (heuristic) search strategies
Memory-
bounded • Use problem-specific knowledge beyond the definition of the problem itself
heuristic search

Heuristic • Can find solutions more efficiently than can an uninformed strategy
functions

What is heuristic
• Additional knowledge of the problem is imparted to the search algorithm.
• Heuristic estimates how close a state is to a goal.

3
Best-first search
Best-first search
Best-first
search

Greedy
best-first search

A* search
• An instance of the general tree/graph search algorithm
Memory-
bounded
heuristic search
• A node is selected for expansion based on an evaluation function, f (n),
Heuristic which is construed as a cost estimate.
functions
• The node with the lowest evaluation f (n) is expanded first
• The implementation of best-first graph search is identical to that for
uniform-cost search, except for the use of f instead of g to order the
priority queue
• The choice of f determines the search strategy

5
Best-first search (cont.)
Best-first
search

Greedy
best-first search

A* search
• Most best-first algorithms include as a component of f a heuristic function,
denoted h(n):
Memory-
bounded
heuristic search

Heuristic
h(n) estimated cost of the cheapest path from the state at node n to
functions a goal state
• h(n) depends only on the state at node n
• Assumption of h
• Arbitrary, nonnegative, problem-specific functions
• Constraint: if n is a goal node, then h(n) = 0

6
Greedy best-first search
Greedy best-first search
Best-first
search

Greedy
best-first search

A* search
• Try to expand the node that is closest to the goal, on the grounds that this
Memory-
bounded
heuristic search
is likely to lead to a solution quickly.
Heuristic • Thus, it evaluates nodes by using just the heuristic function
functions

f (n) = h(n)

8
Illustration: Romania
Best-first
search

Greedy
best-first search

A* search
• Use the straight-line distance heuristic, which we will call hSLD
Memory-
bounded
heuristic search Table 1: Values of hSLD – straight-line distances to Bucharest.
Heuristic
functions Arad 366 Mehadia 241
Bucharest 0 Neamt 234
Craiova 160 Oradea 380
Drobeta 242 Pitesti 100
Eforie 161 Rimnicu Vilcea 193
Fagaras 176 Sibiu 253
Giurgiu 77 Timisoara 329
Hirsova 151 Urziceni 80
Iasi 226 Vaslui 199
Lugoj 244 Zerind 374

9
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search
• The initial state
Memory- Straight−line distance
bounded
Oradea to Bucharest
71
Neamt Arad 366
heuristic search 75
Zerind 151
87 Bucharest
Craiova
0
160
Iasi Dobreta 242

Heuristic
Arad 140 Eforie 161
92 Fagaras 178
Sibiu

functions
99 Fagaras Giurgiu 77
118 Hirsova
Vaslui 151
80
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
142 Mehadia 241
111 211 Neamt 234
Lugoj 97 Pitesti
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad
366

10
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search
• After expanding Arad
Memory-
bounded
Straight−line distance
Oradea to Bucharest
71

heuristic search
Neamt Arad 366
87 Bucharest 0
Zerind 151 Craiova
75 160
Iasi Dobreta 242
Heuristic Arad 140
92
Eforie
Fagaras
161
178
functions
Sibiu 99 Fagaras Giurgiu 77
118 Hirsova
Vaslui 151
80
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
142 Mehadia 241
111 211 Neamt 234
Lugoj 97 Pitesti
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad

Sibiu Timisoara Zerind


253 329 374

11
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search
• After expanding Sibu
Memory-
bounded
Straight−line distance
Oradea to Bucharest
71

heuristic search
Neamt Arad 366
87 Bucharest 0
Zerind 151 Craiova
75 160
Iasi Dobreta 242
Heuristic Arad 140
92
Eforie
Fagaras
161
178
functions
Sibiu 99 Fagaras Giurgiu 77
118 Hirsova
Vaslui 151
80
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
142 Mehadia 241
111 211 Neamt 234
Lugoj 97 Pitesti
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad

Sibiu Timisoara Zerind


329 374

Arad Fagaras Oradea Rimnicu Vilcea


366 176 380 193

12
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search
• After expanding Fagaras
Memory-
bounded
Straight−line distance
Oradea to Bucharest
71

heuristic search
Neamt Arad 366
87 Bucharest 0
Zerind 151 Craiova
75 160
Iasi Dobreta 242
Heuristic Arad 140
92
Eforie
Fagaras
161
178
functions
Sibiu 99 Fagaras Giurgiu 77
118 Hirsova
Vaslui 151
80
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
142 Mehadia 241
111 211 Neamt 234
Lugoj 97 Pitesti
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad

Sibiu Timisoara Zerind


329 374

Arad Fagaras Oradea Rimnicu Vilcea


366 380 193

Sibiu Bucharest
253 0 13
Properties
Best-first
search

Greedy
best-first search

A* search
• Time: O(b m ), but a good heuristic can give dramatic improvement
Memory-
bounded • Space: O(b m ), keeps all nodes in memory
heuristic search

Heuristic
• Complete: No, can get stuck in loops, e.g., find a path from Iasi to Fagaras,
functions Iasi → Neamt → Iasi → Neamt → ...
• Yes in finite space with repeated-state checking
• Optimal: No
Oradea
71
Neamt

Zerind 87
75 151
Iasi
Arad
140
92
Sibiu Fagaras
99
118
Vaslui
80
Rimnicu Vilcea
Timisoara
142
111 Pitesti 211
Lugoj 97
70 98
85 Hirsova
Mehadia 146 101 Urziceni
75 138 86
Bucharest
Drobeta 120
90
Craiova Eforie
Giurgiu

14
A* search
A* search
Best-first
search

Greedy
best-first search

A* search
• A* search (pronounced A-star search) is the most widely known form of
Memory-
bounded
heuristic search
best-first search
Heuristic • Ideas
functions
• Use heuristic to guide search, but not only
• 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 of the cheapest path to goal from n
• f (n): estimated cost of the cheapest solution through n
• The algorithm is identical to Uniform-Cost-Search except that A* uses
g + h instead of g

16
Illustration: Romania
Best-first
search

Greedy
best-first search

A* search Oradea
Straight−line distance
to Bucharest
71
Neamt Arad 366
Memory- 75
Zerind 151
87 Bucharest
Craiova
0
160
bounded Arad 140
Iasi Dobreta
Eforie
242
161
heuristic search Sibiu 99 Fagaras
92 Fagaras
Giurgiu
178
77
118 Hirsova
Vaslui 151
80
Heuristic
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
functions 111
97 Pitesti
211
142 Mehadia
Neamt
241
234
Lugoj
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad
366=0+366

17
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search Oradea
Straight−line distance
to Bucharest
71
Neamt Arad 366
Memory- 75
Zerind 151
87 Bucharest
Craiova
0
160
bounded Arad 140
Iasi Dobreta
Eforie
242
161
heuristic search Sibiu 99 Fagaras
92 Fagaras
Giurgiu
178
77
118 Hirsova
Vaslui 151
80
Heuristic
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
functions 111
97 Pitesti
211
142 Mehadia
Neamt
241
234
Lugoj
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad

Sibiu Timisoara Zerind


393=140+253 447=118+329 449=75+374

18
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search Oradea
Straight−line distance
to Bucharest
71
Neamt Arad 366
Memory- 75
Zerind 151
87 Bucharest
Craiova
0
160
bounded Arad 140
Iasi Dobreta
Eforie
242
161
heuristic search Sibiu 99 Fagaras
92 Fagaras
Giurgiu
178
77
118 Hirsova
Vaslui 151
80
Heuristic
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
functions 111
97 Pitesti
211
142 Mehadia
Neamt
241
234
Lugoj
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad

Sibiu Timisoara Zerind


447=118+329 449=75+374

Arad Fagaras Oradea Rimnicu Vilcea


646=280+366 415=239+176 671=291+380 413=220+193

19
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search Oradea
Straight−line distance
to Bucharest
71
Neamt Arad 366
Memory- 75
Zerind 151
87 Bucharest
Craiova
0
160
bounded Arad 140
Iasi Dobreta
Eforie
242
161
heuristic search Sibiu 99 Fagaras
92 Fagaras
Giurgiu
178
77
118 Hirsova
Vaslui 151
80
Heuristic
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
functions 111
97 Pitesti
211
142 Mehadia
Neamt
241
234
Lugoj
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad

Sibiu Timisoara Zerind


447=118+329 449=75+374

Arad Fagaras Oradea Rimnicu Vilcea


646=280+366 415=239+176 671=291+380

Craiova Pitesti Sibiu


526=366+160 417=317+100 553=300+253

20
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search Oradea
Straight−line distance
to Bucharest
71
Neamt Arad 366
Memory- 75
Zerind 151
87 Bucharest
Craiova
0
160
bounded Arad 140
Iasi Dobreta
Eforie
242
161
heuristic search Sibiu 99 Fagaras
92 Fagaras
Giurgiu
178
77
118 Hirsova
Vaslui 151
80
Heuristic
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
functions 111
97 Pitesti
211
142 Mehadia
Neamt
241
234
Lugoj
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad

Sibiu Timisoara Zerind


447=118+329 449=75+374

Arad Fagaras Oradea Rimnicu Vilcea


646=280+366 671=291+380

Sibiu Bucharest Craiova Pitesti Sibiu


591=338+253 450=450+0 526=366+160 417=317+100 553=300+253

21
Illustration: Romania (cont.)
Best-first
search

Greedy
best-first search

A* search Oradea
Straight−line distance
to Bucharest
71
Neamt Arad 366
Memory- 75
Zerind 151
87 Bucharest
Craiova
0
160
bounded Arad 140
Iasi Dobreta
Eforie
242
161
heuristic search Sibiu 99 Fagaras
92 Fagaras
Giurgiu
178
77
118 Hirsova
Vaslui 151
80
Heuristic
Iasi 226
Rimnicu Vilcea Lugoj
Timisoara 244
functions 111
97 Pitesti
211
142 Mehadia
Neamt
241
234
Lugoj
Oradea 380
70 98 Pitesti 98
146 85 Hirsova
Mehadia 101 Urziceni Rimnicu Vilcea 193
75 138 86 Sibiu 253
Bucharest Timisoara 329
120
Dobreta
90 Urziceni 80
Craiova Eforie Vaslui 199
Giurgiu Zerind 374

Arad

Sibiu Timisoara Zerind


447=118+329 449=75+374

Arad Fagaras Oradea Rimnicu Vilcea


646=280+366 671=291+380

Sibiu Bucharest Craiova Pitesti Sibiu


591=338+253 450=450+0 526=366+160 553=300+253

Bucharest Craiova Rimnicu Vilcea


418=418+0 615=455+160 607=414+193
22
Properties
Best-first
search

Greedy
best-first search

A* search
• Time Exponential in [relative error in h × length of solution.]
Memory-
bounded
heuristic search
• Space Keeps all nodes in memory
Heuristic • Complete Yes, unless there are infinitely many nodes with f ≤ f (G)
functions
• Optimal Yes, cannot expand fi+1 until fi is finished
• A* expands all nodes with f (n) < C ∗
• A* expands some nodes with f (n) = C ∗
• A* expands no nodes with f (n) > C ∗

23
Admissibility and Consistency
Best-first
search

Greedy
best-first search

A* search

Memory- Concept 1
bounded
heuristic search h(n) is an admissible heuristic
Heuristic
functions
• if it never overestimates the cost to reach the goal
• or if for every node n, h(n) ≤ h∗ (n) (h∗ (n) is a the true optimal cost to reach
the goal state from n)

• An example of an admissible heuristic is the straight-line distance hSLD that


we used in getting to Bucharest

24
Admissibility and Consistency (cont.)
Best-first
search

Greedy
best-first search

A* search Concept 2
Memory-

h(n) is an consistent heuristic if for every node n and every


bounded
heuristic search
n
Heuristic successor n0 of n generated by any action a, the estimated cost of c(n,a,n’)
functions
reaching the goal from n is no greater than the step cost of h(n)
getting to n0 plus the estimated cost of reaching the goal from n0
n’
h(n’)
h(n) ≤ c(n, a, n0 ) + h(n0 ) G

• Consistent heuristic is also admissible

25
Optimal for A*
Best-first
search

Greedy
best-first search

A* search
• Using tree search algorithm to find a path from S to G
Memory-
bounded
heuristic search
S h=5
Heuristic
functions

a h=4

3
1

G h=0

26
Optimal for A* (cont.)
Best-first
search

Greedy
best-first search

A* search

Memory-
Theorem 1
bounded
heuristic search The tree-search version of A* is optimal if h(n) is admissible
Heuristic
functions Proof
Suppose some suboptimal goal G2 has been generated and is in the frontier.
Let n be an unexpanded node on a shortest path to an optimal goal G (graph
separation)

• f (G) = g(G) since h(G) = 0 Start

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


n
• g(G2 ) > g(G) since G2 is suboptimal
• f (G) > f (n) since h is admissible G G2

• Since f (G2 ) > f (n), A* will never select G2 for


expansion
27
Optimal for A* (cont.)
Best-first
search

Greedy
best-first search

A* search
• Using graph search algorithm to find a path from S to G
Memory-
bounded
heuristic search S h=2
Heuristic
functions
1 1

a h =4 b h=1

1 2

c h=1

G h=0
28
Optimal for A* (cont.)
Best-first
search

Greedy
best-first search

A* search

Memory-
Theorem 2
bounded
heuristic search The graph-search version of A* is optimal if h(n) is consistent
Heuristic
functions Proof
• if h(n) is consistent, then the values of f (n) along any path are
nondecreasing. Suppose n0 is a successor of n; then g(n0 ) = g(n) + c(n, a, n0 )
for some action a, and we have

f (n0 ) = g(n0 ) + h(n0 ) = g(n) + c(n, a, n) + h(n0 ) ≥ g(n) + h(n) = f (n)

• Whenever A* selects a node n for expansion, the optimal path to that node
has been found. Were this not the case, there would have to be another
frontier node n0 on the optimal path from the start node to n; f (n0 ) < f (n)
⇒ n0 would have been selected first.
29
Contours
Best-first
search

Greedy
best-first search

A* search
• Search algorithm expands nodes in order of increasing f value
Memory-
bounded • We can draw contours in the state space, just like the contours in a
topographic map
heuristic search

Heuristic
functions • Gradually adds “f -contours” of nodes, contour i has all nodes with
f < fi , where fi < fi+1
O

N
Z

I
A
380 S
F
V
400
T R

L P

H
M U
B
420
D
E
C
G
30
Contours (cont.)
Best-first
search

Greedy
best-first search

A* search
• The bands of uniform-cost search will be “circular” around the start state.
Memory-
bounded
heuristic search
• The bands of A* with more accurate heuristics will stretch toward the goal
Heuristic state and become more narrowly focused around the optimal path
functions

31
The 8-puzzle
Best-first
search

Greedy
best-first search

A* search
• The average solution cost for a randomly generated 8-puzzle instance is
Memory-
bounded about 22 steps
heuristic search
• The branching factor b is about 3
Heuristic
functions • 8-puzzle:
• 322 ≈ 3.1 × 1010 states (using an exhaustive tree search)
• 9!/2 = 181, 440 reachable states (using graph search)
• 15-puzzle: around 1013 states

7 2 4 1 2

5 6 3 4 5

8 3 1 6 7 8

Start State Goal State

Figure 1: A typical instance of the 8-puzzle. The optimal solution is 26 steps long.
32
Admissible heuristics for 8-puzzle
Best-first
search

Greedy
best-first search

A* search
• h1 = the number of misplaced tiles. h1 is an admissible heuristic because it is
Memory-
bounded clear that any tile that is out of place must be moved at least once
heuristic search
• h2 = the sum of the distances of the tiles from their goal positions. h2 is also
Heuristic
functions admissible because all any move can do is move one tile one step closer to
the goal

7 2 4 1 2

5 6 3 4 5

8 3 1 6 7 8

Start State Goal State

• h1 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 8 and
h2 = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18
33
Solve 8 puzzle
Best-first
search

Greedy
best-first search

A* search

Memory- • Using h2
bounded 2 3 1 2 3
heuristic search
Start 1 4 5 8 4 Goal
Heuristic
functions 8 7 6 7 6 5

6=0+6

2 3 1 2 3

1 4 5 4 5

8 7 6 8 7 6

8=1+7 6=1+5

1 2 3 2 3 1 2 3

4 5 1 4 5 8 4 5

8 7 6 8 7 6 7 6

8=2+6 8=2+6 6=2+4

34
Memory-bounded heuristic search
Memory-bound heuristic search
Best-first
search

Greedy
best-first search

A* search
• In practice, A* usually runs out of space long before it runs out of time
Memory-
bounded
heuristic search
• Idea: try something like DFS, but not forget everything about the branches
Heuristic we have partially explored
functions

36
Iterative-deepening A* (IDA*)
Best-first
search

Greedy
best-first search

A* search
• The main difference with IDS
Memory-
bounded
heuristic search
• Cut-off use the f -value (g + h) rather than the depth
Heuristic
• At each iteration, the cutoff value is the smallest f -value of any node
functions
that exceeded the cutoff on the previous iteration
• Avoid the substantial overhead associated with keeping a sorted queue of
nodes.
• Practical for many problems with unit step costs, yet difficult with real valued
costs

37
Algorithm
Best-first
search

Greedy
best-first search

A* search

Memory- function IDA*(problem) returns a solution, or failure


bounded
heuristic search
local variables:
Heuristic
f _limit: the current f-COST limit
functions root: a node
root ← Make-Node(problem.Initial-State)
f _limit ← root.f
loop do
solution, f _limit ← DFS-Contour(problem, root, f _limit)
if solution is non-null then return solution
if f _limit = ∞ then return failure

38
Algorithm (cont.)
Best-first
search

Greedy
best-first search

A* search

Memory- function DFS-Contour(problem,node,f _limit)


bounded
heuristic search
returns a solution, or failure and a new f-cost limit
Heuristic
if node.f > f _limit then return null, node.f
functions if problem.Goal-Test(node.State) then return Solution(node)
successors ← ∅
for each action in problem.Actions(node.State) do
add Child-Node(problem,node,action) into successors
f _next ← ∞
for each s in successors do
solution,f _new ← DFS-Contour(problem, s, f _limit)
if solution is non-null then return solution, f _limit
f _next ← Min(f _next, f _new)
return null, f _next

39
Illustration
Best-first
search

Greedy
best-first search

A* search
• IDA* search for the shortest route from v0 (start node) to v25 (goal node);
Memory-
bounded
heuristic search
each node has a f value.
Heuristic 1
functions

3 4

4 5 5 5

6 7 7 6 5 7 6 8

11 13 15 14 11 8 12 7 12 6 14 15 7 13 15 9

40
Recursive best-first search (RBFS)
Best-first
search

Greedy
best-first search

A* search
• Keep track of the f -value of the best alternative path available from any
Memory-
bounded
heuristic search
ancestor of the current node
Heuristic
• backtrack when the current node exceeds f _limit
functions
• As it backtracks, replace f -value of each along the path with the best value
f (n) of its children

41
Algorithm
Best-first
search

Greedy
best-first search

A* search

Memory-
function Recursive-Best-First-Search(problem)
bounded returns a solution, or failure
heuristic search return Rbfs(problem,Make-Node(problem.Initial-State),∞)
Heuristic function Rbfs(problem,node,f _limit)
functions returns a solution, or failure and a new f-cost limit
if problem.Goal-Test(node.State) then return Solution(node)
successors ← ∅
for each action in problem.Actions(node.State) do
add Child-Node(problem,node,action) into successors
if successors is empty then return failure,∞
for each s in successors do
# update f with value from previous search, if any
s.f ← Max(s.g + s.h, node.f )
loop do
best ← lowest f-value node in successors
if best.f > f _limit then return failure,best.f
alternative ← the second-lowest f -value among successors
result,best.f ← Rbfs(problem, best, Min(f _limit, alternative))
if result 6= failure then return result

42
Illustration
Best-first
search

Greedy
best-first search

A* search
• Stages in an RBFS search for the shortest route to Bucharest. The f -limit
Memory-
bounded value for each recursive call is shown on top of each current node, and every
heuristic search

Heuristic
node is labeled with its f -cost.
functions
Arad

366

Sibiu Timisoara Zerind

393 447 449

Arad Fagaras Oradea Rimnicu V.


646 415 671 413

Sibiu Bucharest Craiova Pitesti Sibiu

591 450 526 417 553

Bucharest Craiova Rimnicu V.

418 615 607

43
Illustration (cont.)
Best-first
search

Greedy
best-first search

A* search
(a) The path via Rimnicu Vilcea is followed until the current best leaf (Pitesti)
has a value that is worse than the best alternative path (Fagaras).
Memory-
bounded
heuristic search

Heuristic Arad

functions 366

Sibiu Timisoara Zerind

393 447 449

Arad Fagaras Oradea Rimnicu V.


646 415 671 413

Sibiu Bucharest Craiova Pitesti Sibiu

591 450 526 417 553

Bucharest Craiova Rimnicu V.

418 615 607

44
Illustration (cont.)
Best-first
search

Greedy
best-first search

A* search
(b) The recursion unwinds and the best leaf value of the forgotten subtree (417)
is backed up to Rimnicu Vilcea; then Fagaras is expanded, revealing a best
Memory-
bounded
heuristic search
leaf value of 450.
Heuristic
functions Arad

366

Sibiu Timisoara Zerind

393 447 449

Arad Fagaras Oradea Rimnicu V.


646 415 671 413

Sibiu Bucharest Craiova Pitesti Sibiu

591 450 526 417 553

Bucharest Craiova Rimnicu V.

418 615 607

45
Illustration (cont.)
Best-first
search

Greedy
best-first search

A* search
(c) The recursion unwinds and the best leaf value of the forgotten subtree (450) is
backed up to Fagaras; then Rimnicu Vilcea is expanded. This time, because the
Memory-
bounded
heuristic search
best alternative path (through Timisoara) costs at least 447, the expansion
Heuristic
functions continues to Bucharest.
Arad

366

Sibiu Timisoara Zerind

393 447 449

Arad Fagaras Oradea Rimnicu V.


646 415 671 413

Sibiu Bucharest Craiova Pitesti Sibiu

591 450 526 417 553

Bucharest Craiova Rimnicu V.

418 615 607

46
Properties
Best-first
search

Greedy
best-first search

A* search
• Optimality
Memory-
bounded
heuristic search
• Like A*, optimal if h(n) is admissible
Heuristic • Time complexity
functions
• Difficult to characterize
• Depends on accuracy of h(n) and how often best path changes
• Can end up “switching” back and forth
• Space complexity
• Linear time: O(bd)
• Other extreme to A* - uses too little memory even if more memory were
available

47
Simplified Memory-bound A* – SMA*
Best-first
search

Greedy
best-first search

A* search
• Similar to A*, but delete the worst node (largest f -value) when memory is
Memory-
bounded
heuristic search
full
Heuristic • SMA* expands the (newest) best leaf and deletes the (oldest) worst leaf
functions
• SMA* also backs up the value of the forgotten node to its parent.
• If there is a tie (equal f -values), delete the oldest nodes first
• Simplified-MA* finds the optimal reachable solution given the memory
constraint.
• The depth of the shallowest goal node, is less than the memory size
(expressed in nodes)
• Time can still be exponential.

48
Algorithm
Best-first
search

Greedy
best-first search

A* search
function SMA*(problem) returns a solution, or failure
Memory-
bounded frontier ← Make-Node(problem.Initial-State)
heuristic search loop do
Heuristic if frontier = ∅ then return failure
functions node ← Pop(frontier )
if problem.Goal-Test(node.State) then return Solution(node)
s ← Next-Successor(node)
if s is not a goal and is at maximum depth then
s.f ← ∞
else
s.f ← Max(s.g + s.h, node.f )
if all of node's successors have been generated then
update node's f-cost and those of its ancestors if necessary
if Successors(node) all in memory then
remove node from frontier
if memory is full then
delete shallowest, highest f-cost node in frontier
remove it from its parent's successor list
insert its parent on frontier if necessary
frontier ← Insert(s, frontier)
49
Illustration
Best-first
search

Greedy
best-first search

A* search
• Find the lowest-cost goalnode with enough memory
Memory-
bounded
heuristic search
• Max Nodes = 3
Heuristic
• A: start node and D, F, I, J: goal nodes
functions • Each edge/node is labelled with its step cost/heuristic value

A 12

10 8

B 5 G 5

10 10 8 16

C 5 D 0 H 2 I 0

10 10 8 8

E 5 F 0 J 0 K 5

50
Illustration (const.)
Best-first
search

Greedy
best-first search

A* search
• Consider only current f-cost
Memory-
bounded
heuristic search A 12
Heuristic
functions

B 15 G 13

C 25 D 20 H 18 I 24

E 35 F 30 J 24 K 29

51
Learning to search better
Best-first
search

Greedy
best-first search

A* search
• Could an agent learn how to search better? Yes
Memory-
bounded
heuristic search
• Metalevel state space: in which each state captures the internal
Heuristic (computational) state of a program that is searching in an object-level state
functions
space.
• A metalevel learning algorithm learn from these experiences to avoid
exploring unpromising subtrees
• For example, the map of Romania problem
• The internal state of the A* algorithm is the current search tree.
• Each action in the metalevel state space is a computation step that
alters the internal state; for example, each computation step in A*
expands a leaf node and adds its successors to the tree

52
Heuristic functions
The effect of heuristic accuracy on performance
Best-first
search

Greedy
best-first search

A* search
• Effective branching factor b ∗ characterize the quality of a heuristic.
Memory-
bounded
heuristic search
• If the total number of nodes generated by A* for a particular problem is N
Heuristic and the solution depth is d, then b ∗ is the branching factor that a uniform
functions
tree of depth d would have to have in order to contain N + 1 nodes

N + 1 = 1 + (b ∗ ) + (b ∗ )2 + ... + (b ∗ )d

• b ∗ varies across problem instances, but fairly constant for sufficiently hard
problems
• A well-designed heuristic would have a value of b ∗ close to 1 ⇒ fairly large
problems solved at reasonable cost

54
The effect of heuristic accuracy on performance (cont.)
Best-first
search

Greedy
best-first search

A* search
Search Cost (nodes generated) Effective Branching Factor
Memory-
bounded
d IDS A*(h1 ) A*(h2 ) IDS A*(h1 ) A*(h2 )
heuristic search 2 10 6 6 2.45 1.79 1.79
Heuristic 4 112 13 12 2.87 1.48 1.45
functions 6 680 20 18 2.73 1.34 1.30
8 6384 39 25 2.80 1.33 1.24
10 47127 93 39 2.79 1.38 1.22
12 3644035 227 73 2.78 1.42 1.24
14 – 539 113 – 1.44 1.23
16 – 1301 211 – 1.45 1.25
18 – 3056 363 – 1.46 1.26
20 – 7276 676 – 1.47 1.27
22 – 18094 1219 – 1.48 1.28
24 – 39135 1641 – 1.48 1.26

Table 2: Comparison of the search costs and effective branching factors for the IDS and
A* algorithms with h1 , h2 . Data are averaged over 100 instances of the 8-puzzle for each
of various solution lengths d.
55
Dominance and Composite
Best-first
search

Greedy
best-first search

A* search
• If h2 (n) ≥ h1 (n) for all n (both admissible) then h2 dominates h1 and is
Memory-
bounded
heuristic search
better for search
Heuristic
• A* using h2 will never expand more nodes than A* using h1
functions
• Hence, it is generally better to use a heuristic function with higher values,
provided it is consistent and that the computation time for the heuristic is
not too long.
• Given a collection of admissible heuristics {h1 , ..., hm } is available for a
problem and none of them dominates any of the others.
• The composite heuristic function is defined as

h(n) = max{h1 (n), . . . , hm (n)}

is consistent and dominates all component heuristics

56
Relaxed problems
Best-first
search

Greedy
best-first search

A* search

Memory- Concept 3
bounded
heuristic search A problem with fewer restrictions on the actions is called a relaxed problem.
Heuristic
functions
• Prove that the angle in a semicircle is a right angle.
A

O C

57
Generating admissible heuristics from relaxed problems
Best-first
search

Greedy
best-first search

A* search
• The state-space graph of the relaxed problem is a supergraph of the original
Memory-
bounded
heuristic search
state space because the removal of restrictions creates added edges in the
Heuristic
graph.
functions

b d b d

S G S G

a c a c

Figure 2: Original problem state-space Figure 3: Relaxed problem state-space

58
Generating admissible heuristics from relaxed problems
Best-first
search

Greedy
best-first search (cont.)
A* search

Memory-
bounded
heuristic search
• Hence, the cost of an optimal solution to a relaxed problem is an admissible
Heuristic
heuristic for the original problem.
functions
• Furthermore, because the derived heuristic is an exact cost for the relaxed
problem, it must obey the triangle inequality and is therefore consistent.

59
Generating admissible heuristics from relaxed problems
Best-first
search

Greedy
best-first search (cont.)
A* search

Memory-
bounded Original problem of 8 puzzle
heuristic search

Heuristic
• A tile can move from square A to square B if A is horizontally or vertically
functions
adjacent to B and B is blank

We can generate three relaxed problems by removing one or both of the conditions
Relaxed problems
1. A tile can move from square A to square B if A is adjacent to B → h2
2. A tile can move from square A to square B if B is blank → exercise
3. A tile can move from square A to square B → h1

60
Generating admissible heuristics from subproblems
Best-first
search

Greedy
best-first search

A* search
• Admissible heuristics can also be derived from the solution cost of a
Memory-
bounded subproblem of a given problem
heuristic search
• The cost of the optimal solution of this subproblem ≤ the cost of the
Heuristic
functions original problem (lower bound).
• More accurate than Manhattan distance in some cases

2 4 1 2

5 6 3 54 6

8 3 1 7 8

Start State Goal State

Figure 4: A subproblem of the 8-puzzle instance. The task is to get tiles 1, 2, 3, and 4
into their correct positions, without worrying about what happens to the other tiles.

61
Goal fixed?
Best-first
search

Greedy
best-first search

A* search
• Assume that the goal state G is fixed
Memory-
bounded
heuristic search
• Using Uniform-Cost-Search to find the shortest path from G to the
Heuristic other states
functions
• The final g values can be considered as optimal h∗ values

62
Goal fixed? (cont.)
Best-first
search

Greedy
best-first search

A* search f
21
h
Memory-
6
bounded 17
heuristic search 4 G
4

Heuristic e
3
functions 8
d 9

5 4
1

b
8
c

f g = 26 f h = 26
21 21
h g =6 h h=6
6 6
17 17
4 G g =0 4 G h=0
4 4
3 3
e g =9 e h=9
8 8
d g =3 9 d h=3 9

5 4 5 4
1 1

b g =7 b h=7
8 8
c g =4 c h=4

63
Pattern databases
Best-first
search

Greedy
best-first search

A* search
• Pattern databases (PDB) where store the exact solution costs for every
Memory-
bounded
heuristic search
possible subproblem instance
Heuristic
• E.g., every possible configuration of the four tiles and the blank
functions
• The database itself is constructed by searching back from the goal and
recording the cost of each new pattern encountered; the expense of this
search is amortized over many subsequent problem instances
• The complete heuristic is constructed using the patterns in the databases

64
Computing the Heuristic
Best-first
search

Greedy
best-first search

A* search

Memory-
bounded 5 10 14 7 1 2 3
heuristic search

Heuristic 8 3 6 1 4 5 6 7
functions

15 12 9 8 9 10 11

2 11 4 13 12 13 14 15

• 31 moves needed to solve red tiles


• 22 moves need to solve blue tiles
• Overall heuristic is maximum of 31 = max(31, 22) moves

65
Disjoint pattern databases
Best-first
search

Greedy
best-first search

A* search
• Limitation of traditional PDB: Take max → diminish returns on additional
Memory-
bounded
heuristic search
PDBs
Heuristic • Disjoint pattern databases: Count only moves of the pattern tiles, ignoring
functions
non-pattern moves.
• If no tile belongs to more than one pattern, add their heuristic values.

66
Computing the Heuristic
Best-first
search

Greedy
best-first search

A* search

Memory-
bounded 5 10 14 7 1 2 3
heuristic search

Heuristic 8 3 6 1 4 5 6 7
functions

15 12 9 8 9 10 11

2 11 4 13 12 13 14 15

• 20 moves needed to solve red tiles


• 25 moves needed to solve blue tiles
• Overall heuristic is sum, or 45 = 20 + 25 moves

67
Performance
Best-first
search

Greedy
best-first search

A* search
• 15 Puzzle
Memory-
bounded • 1000 × speedup vs. Manhattan distance
heuristic search
• IDA* with the two DBs (the 7-tile database contains 58 million entries
Heuristic
functions and the 8-tile database contains 519 million entries) solves 15-puzzles
optimally in 30 milliseconds
• 24 Puzzle
• 12 million × speedup vs. Manhattan distance
• IDA* can solve random instances in 2 days.
• Requires 4 DBs (each DB has 128 million entries)
• Without PDBs: 65,000 years

68
Learning heuristics from experience
Best-first
search

Greedy
best-first search

A* search
• Experience means solving a lot of instances of a problem.
Memory-
bounded
heuristic search
• E.g., solving lots of 8-puzzles
Heuristic • Each optimal solution to a problem instance provides examples from which
functions
h(n) can be learned
• Learning algorithms
• Neural nets
• Decision trees
• Inductive learning

69
References

Goodfellow, I., Bengio, Y., and Courville, A. (2016).


Deep learning.
MIT press.
Lê, B. and Tô, V. (2014).
Cở sở trí tuệ nhân tạo.
Nhà xuất bản Khoa học và Kỹ thuật.
Nguyen, T. (2018).
Artificial intelligence slides.
Technical report, HCMC University of Sciences.
Russell, S. and Norvig, P. (2016).
Artificial intelligence: a modern approach.
Pearson Education Limited.

You might also like