Professional Documents
Culture Documents
2024 Slide3 InformedSearch Eng
2024 Slide3 InformedSearch Eng
Informed Uninformed
Content
• Heuristic function
• Inform Search
– Greedy Best-first search
– Beam Search
– Hill-climbing Search (Depth First Search)
– A* search
10
5
11.2
Heuristic function
4 3 1 1 2 3
6 5 8 4
8 2 7 7 6 5
4 3 1 1 2 3
6 5 8 4
8 2 7 7 6 5
B (30)
P. B. Sơn & N. V. Vinh 3/23/2024 19
Greedy (Ex 2)
• Using Greedy Search, find path from S to t
4 4
A B C
3
S 5 5
G
4 3
D E F
2 4
23
Beam search (1):
Depth 1) S • Assume a pre-fixed
WIDTH (example :
3 4 2)
A D
• Perform breadth-
Depth 2) first, BUT:
S
S
• Only keep the
A D WIDTH best new
nodes
7 B 8 6 depending on
D A 9 E heuristic
X X at each new level.
Bỏ Bỏ 24
Beam search (2):
Depth 3) S
A D • Optimi-
zation:
B D A E ignore
11 C 12 11 B F 10
_ E X X leafs that
X are not
end ignore goal
nodes
Depth 4) S
A D
B D A E
_C E X X B F
X
1525 A 0.0
_C G
Beam search algorithm:
• Homework
Properties:
Completeness:
Beam search: NO
Speed/Memory:
Beam search:
QUEUE always has length WIDTH, so memory usage is
constant = WIDTH, time is of the order of WIDTH*m*b or
WIDTH*d*b if no solution is found
26
Hill-climbing Search
A 10.4 B 6.7 C 4
S 11
8.9 G
D E 6.9 F 3
• Perform depth-
A 10.4 D 8.9 first, BUT:
• instead of left-to-
A 10.4 E 6.9 right selection,
• FIRST select the
6.7 B F 3.0
child with the best
G heuristic value
29
Hill-climbing Algorithm
1. Initialize queue L containing only start state;
2. Loop do
2.1. if (L == Empty) then
failed search message; end};
2.2. Remove u state from beginning of the L;
2.3. if (u == Goal state) then
{successful search message; end};
2.4. for (each state v expanding from u) do put v into L1;
2.5. Sort L1 in ascending order of the evaluation function so that the best state is at the
top of the L1
2.6. Move L1 to the beginning of L so that the beginning of L1 becomes the beginning
of L
P. B. Sơn & N. V. Vinh 3/23/2024 30
Properties of Hill-climbing search
• Completeness:
– Hill climbing: YES (backtracking)
• Speed/Memory:
– same as Depth-first (in worst case)
• Optimal
– No
UCS Greedy
A*
A* Search
• A* Search uses evaluation function f(n) = g(n) + h(n)
– g(n): cost from initial node to node n
– h(n): estimated cost of cheapest path from n to goal.
– f(n): estimated total cost of cheapest solution through n.
• Best first (Greedy) Search minimises h(n)
– Effective but not optimal
• Uniform-cost Search minimizes g(n)
– Optimal but not effective
Source: Wikipedia
Uniform cost search vs. A* search
Source: Wikipedia
Greedy vs. UCS vs. A*
• Example:
15
• h1(S) = ?
• h2(S) = ?
•
P. B. Sơn & N. V. Vinh 3/23/2024 53
Designing heuristic functions
Heuristics for 8-puzzle problem :
• h1(n) = Number of misplaced tiles
• h2(n) = Total Manhattan distance (number of squares from desired location of each tile)
• h1(S) = ? 8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
• Depth d=12
IDS = 3,644,035 nodes
A*(h1) = 227 nodes
A*(h2) = 73 nodes
• Depth d=24
IDS = too many nodes ~ 54 * 109 nodes
A*(h1) = 39,135 nodes
A*(h2) = 1,641 nodes
• Reduce constraints
• A problem with less constraints than in actions is called relaxed problem
• The value of the optimal solution for the relaxed problem is the
admissible function of the original problem
• If the rule of the 8-puzzle problem is relaxed so that the pieces can move
freely (anywhere), then h1(n) gives the shortest solution.
• If the rule of the 8-puzzle problem is relaxed so that the pieces can move
any adjacent squares, then h2(n) gives the shortest solution.
366
15
Composite Heuristic Functions
• Let h1, h2,.., hm be admissible heuristics for a given
task.
• Define the composite heuristic:
– h(n) = max (h1(n), h2(n), …, hm(n)).
• h is admissible heuristic
• h dominate h1, h2, …, hm
Image: maps.google.com
A*: Summary
A* uses both backward costs and (estimates of) forward costs
BFS Yes If all step costs are equal O(b^d) O(b^d) Queue
IDS Yes If all step costs are equal O(b^d) O(bd) Stack