1 kuliah 4 : informed search. 2 outline best-first search greedy search a* search
TRANSCRIPT
1
Kuliah 4 : Informed Search
2
Outline
Best-First Search Greedy Search A* Search
3
Uninformed (Blind) Search
Uninformed (blind) Searches are normally very inefficient.
Adding domain knowledge can improve the search process.
4
A
3
2
1Start
Goal
Suppose we know that node A is very promising
Why not expand it right away?
5
Informed (Heuristic) Search
Explore the node that is most “likely” to be the nearest to a goal state.
Informed search algorithms choose the next node to expand using an evaluation function that estimates the merit of expanding the node. To focus search, the evaluation function must incorporate some heuristic that estimates the cost of the path from a state to the closest goal state.
6
Best-First Search
Idea: use an evaluation function f(n) for each node Estimate of desirability
Expand most desirable unexpanded node Implementation: fringe is queue sorted
by descreasing order of desirability Greedy search A* search
7
An Implementation of Best-First Search
function BEST-FIRST-SEARCH (problem, eval-fn)
returns a solution sequence, or failurequeuing-fn =
a function that sorts nodes by eval-fnreturn GENERAL-SEARCH
(problem,queuing-fn)
8
Greedy Search Estimation function :h(n) = estimate of cost from n to goal (heuristic)
For example :hSLD(n) = straight-line distance from n to Bucharest
Greedy search expands first the node that appears to be closest to the goal, according to h(n).
f(n) = h(n)
9
Romania with step costs in km
374
329
253
10
Greedy Best-First Search Example
Queue:((Arad 366))
11
Greedy Best-First Search Example
Queue:((Sibiu 253) (Timisoara 329) (Zerind 374))
Now expand Sibiu and add its successors to tree.
12
Greedy Best-First Search Example
Queue:((Fagaras 178) (Rimnicu 193) (Timisoara 329) (Arad 366) (Zerind 374) (Oradea 380))
Fagaras has the lowest h, so it is the next node to be expanded.
13
Greedy Best-First Search Example
Queue:((Bucharest 0) (Rimnicu 193) (Sibiu 253) (Timisoara 329) (Arad 366) (Zerind 374) (Oradea 380))
Goal generated!Path found isArad Sibiu Fagaras Bucharest
14
Example 1 : Road Map
Imagine the problem of finding a route on a road map and that the NET below is the road map:
DD EE
GGSS
AA BB CC
FF
44
4444
4433
3322
55 55
15
Example 1 : Road Map
Define h(T) = the straight-line distance from T to G
DD EE
GGSS
AA BB CC
FF
446.76.710.410.4
1111
8.48.46.96.9 33
The estimateThe estimatecan be wrong!can be wrong!
16
Example 2 : 8-puzzle
f1(T) = the number correctly placed tiles on the board:
11 33 22
44776655
88f1f1 = 4= 4
11 22 33
44556677
88
17
Example 2 : 8-puzzle
f2(T) = number or incorrectly placed tiles on board: gives (rough!) estimate of how far we are
from goal
f2f2 = 4= 4
11 33 22
44
776655
88
Most often, ‘distance to goal’ heuristics are more useful !Most often, ‘distance to goal’ heuristics are more useful !
11 22 33
44556677
88
18
Example 2 : 8-puzzle Manhattan Distance
f3(T) = the sum of ( the horizontal + vertical distance that each tile is away from its final destination): gives a better estimate of distance from the
goal node
f3f3 = = 11 + + 11 + + 22 + + 22 = 6 = 611 33 22
44776655
88
11 22 33
44556677
88
19
Properties of Greedy Search It is not complete.
Can get stuck in loops. Complete if search space is finite and there are checks for repeated states.
It is not optimal. Time complexity: O(bm), where b is the branching
factor and m is the max depth of the search space. Same worst-case time complexity as depth-first.
Space complexity: O(bm). Keeps all nodes in memory. Worse than O(bm) for depth-
first. Actual performance of greedy search is a function
of the accuracy of h.
20
What’s wrong with Greedy Search ?
Arad
Sibiuh = 253
Rimnicuh = 193
Pitestih = 98
Bucharesth = 0
h = 366140
8099
21197
101
Fagaras looks betterto greedy searchthan Rimnicu becauseit doesn’t take distance already covered into account!
Path through Fagaras has cost 450. Path throughRimnicu has cost 418! Yet, greedy search chose the former.
21
A* Search Idea: Avoid expanding paths that are
already expensive. Uses estimated total cost, f(n), of the
cheapest solution path through node n, as a measure of the merit of node n. Thus, f(n) is the evaluation function for A*.
f(n) = g(n) + h(n) where g(n) = path cost from start node to node n. h(n) = estimated cost of path from n to closest
goal node. This must NEVER overestimate the actual cost. [Note, if h(n) = 0 this is uniform-cost search.]
22
A* in actionh = 366g = 0f=366
Sibiuh = 253g = 140f = 393
Timisoarah = 329g = 118f = 447
Zerindh = 374g = 75f = 449
Arad
Queue:((Sibiu 393) (Timisoara 447) (Zerind 449))
Queue:((Arad 366))
Sibiu will be expanded next because it has the lowest f.
23
A* in actionh = 366g = 0f=366
Sibiuh = 253g = 140f =393
Timisoarah = 329g = 118f = 447
Zerindh = 374g = 75f = 449
Arad
Aradh=366g=380f=646
Fagarash = 178g = 239f = 417
Oradeah = 380g = 146f = 526
Rimnicuh = 193g = 220f = 413
Rimnicu willbe expanded next.Example to becontinued in class.
Queue:((Rimnicu 413) (Fagaras 417) (Timisoara 447) (Zerind 449) (Oradea 526) (Arad 646))
24
Properties of A* Search
Complete ? Yes, unless infinitely many nodes with f f(G)
Time ? Exponential in [(relative error in h) x (length of solution)]
Space ? Keeps all nodes in memory Optimal ? Yes – cannot expand fi+1 until
fi is finished
25
8-Puzzle8-Puzzle
1 2 3
4 5 6
7 8
12
3
4
5
67
8
N goal
• h1(N) = number of misplaced tiles = 6 is admissible
• h2(N) = sum of distances of each tile to goal = 13 is admissible
26
8-Puzzle8-Puzzle
4
5
5
3
3
4
3 4
4
2 1
2
0
3
4
3
f(N) = h(N) = number of misplaced tiles
Goal
27
8-Puzzle8-Puzzle
0+4
1+5
1+5
1+3
3+3
3+4
3+4
3+2 4+1
5+2
5+0
2+3
2+4
2+3
f(N) = g(N) + h(N) with h(N) = number of misplaced tiles
28
DD EE
GGSS
AA BB CC
FF
44
4444
4433
3322
55 55
Exercise
From S to G with :
• Uniform Cost Search
• Greedy Search
• A* Search
DD EE
GGSS
AA BB CC
FF
446.76.710.410.4
1111
8.98.96.96.9 33
Straight line distance
29
Answer : Search Tree
SSAA DD
BB DD EEAA
CC EE EE BB BB FF
DD FF BB FF CC EE AA CC GG
GG CC GG FF
GG
33
33 33
33
33
22
22
2244
44
4444
44
4444
44
44
44
44
44
5555
55 55
5555
30
Uniform Cost SearchSS
AA DD
BB DD AA EE
EE BB BB FF
BB FF CC EE AA CC GG
GG
GG FFCC
33 44
44 55
55
55 22
55 44
33
33 44
77 88 99 66
10101111CC EE
DD FF
GG
44 55
1111 1212 1313 1313
1313
44
At each step, select the node with the lowest accumulated cost.S-D-E-F-G
31
Greedy Search
A
A
D
E
S
B F
G
10.4 8.4
10.4 6.9
3.06.7
S-D-E-F-G
32
AA DD3 + 10.4 = 13.43 + 10.4 = 13.4 4 + 8.9 = 12.94 + 8.9 = 12.9
SS
SS
AA DD
AA EE
13.413.4
9 + 10.4 = 19.49 + 10.4 = 19.4 6 + 6.9 = 12.96 + 6.9 = 12.9XX
SSAA DD
AA EEBB FF
13.413.4
11 + 6.7 = 17.711 + 6.7 = 17.7 10 + 3.0 = 13.010 + 3.0 = 13.0XX
SSAA DD
AA EEBB FF
13.413.4
17.717.7
GG13 + 0.0 = 13.013 + 0.0 = 13.0
STOP!STOP!XX
A* example: road map
Rute : S-D-E-F-G = 13