Title: Greedy best-first search
1Greedy best-first search
- Use the heuristic function to rank the nodes
- Search strategy
- Expand node with lowest h-value
- Greedily trying to find the least-cost solution
2Greedy Best-First Search
Path search(start, operators, is_goal)
fringe makeList(start) while
(statefringe.popFirst()) if
(is_goal(state)) return
pathTo(state) S successors(state,
operators) fringe insert(S, fringe)
return NULL Order the nodes in
increasing values of h(N)
3- Procedure Best-First Search
- begin
- open ? Start
- closed ?
- while open ? do begin
- remove leftmost state from open and call it
X - if X is a goal then return the path from
Start to X - else begin
- generate children of X
- for each child of X do begin
- switch
- case the child is not on open or
closed ? - assign the child a heuristic
value and add the child to open - case the child is already on open
? - if the child was reached by a
shorter path then - give the state on open the
shorter path - case the child is already on
closed ? - if the child was reached by a
shorter path then - remove the state from closed
and add the child to open
4Example
A-5
- Open A5closed
- Evl A5 openB4,C4,D6closedA5
- Eval B4openC4,E5,F5,D6 closedB4,A5
- Eval C4 open H3,G4,E5,F5,D6
closedC4,B4,A5
B-4
D-6
C-4
H-3
E-5
G-4
F-5
5- A search algorithm is admissible if it is
guaranteed to find a minimal path to a solution
whenever such a path exist. - f(n) g(n) h(n)
- g(n) is the cost of the shortest path from the
start node to n. - h(n) is the actual cost of the shortest path n
to the goal. - Then f(n) is the actual cost of the optimal path
from a start node to a goal node that passes
through node n.
6- f does not exist.
- Algorithm A
- Use f(n) g(n) h(n) and best-first-search
algorithm - Algorithm A
- If h(n) ? h(n) in the algorithm A then it is
called Algorithm A - Theorem All A algorithms are admissible
7Implementing Heuristic Evaluations
- For 8-puzzle, two heuristics are
- Counts the tiles out of place in each state when
it is compared with the goal. - Sum all the distances by which the tiles are out
of place, one for each square a tile must be
moved to reach its position in the goal state.
2
8
3
1
4
6
7
5
left
2
8
3
2
8
3
2
8
3
1
4
6
1
4
1
4
6
7
5
7
5
6
7
5
8Example
h1(S)7 h2(S)4033102114
9Comparison of Heuristics applied to states in the
8-puzzle
h1 h2
2
8
3
5
6
1
4
6
7
5
2
8
3
3
1
4
4
7
5
6
2
8
3
5
6
1
4
6
7
5
Sum of distances out of place
Tile out of place
10Admissible Heuristic
11A Search
- Greedy best-first search is too greedy
- It does not take into account the cost of the
path so far! - Define
- f(n)g(n)h(n)
- g(n) is the cost of the path to node n
- h(n) is the heuristic estimate of the cost of
reaching the goal from node n - A search
- Expand node in fringe (queue) with lowest f value
122
8
3
1
1
4
6
7
5
left
2
2
8
3
2
8
3
2
8
3
1
4
6
1
4
1
4
6
6
4
6
7
5
7
5
6
7
5
3
4
2
8
3
2
8
3
2
3
5
1
4
5
1
4
8
1
4
6
7
5
6
7
5
6
7
5
6
5
8
3
2
8
3
2
3
5
2
1
4
1
4
7
8
1
4
7
5
6
5
6
7
5
6
13(No Transcript)
14A Another Example
15A
16A
17A
18A
19A
20A
21A Search
- Complete Yes
- Time Complexity Exponential
- - Depends on
h(n) - Space Complexity Exponential
- - Keeps all
nodes in memory - Optimal Yes. If h(n) is an admissible heuristic
- Optimally efficient
22How fast is A?
- A is the fastest search algorithm. That is, for
any given heuristic, no algorithm can expand
fewer nodes than A. - How fast is it? Depends of the quality of the
heuristic. - (relative error in h) x (length of solution)
- Exponential time complexity in worst case. A
good heuristic will help a lot here - O(bm) if the heuristic is perfect
- If the heuristic is useless (ie h(n) is hardcoded
to equal 0 ), the algorithm degenerates to
uniform cost. - If the heuristic is perfect, there is no real
search, we just march down the tree to the goal. - Generally we are somewhere in between the two
situations above. The time taken depends on the
quality of the heuristic.
23Dominance
- Given two admissible heuristics h1(n) and h2(n),
which is better? - If h2(n) ? h1(n) for all n, then
- h2 is said to dominate h1
- h2 is better for search
- For our 8-puzzle heuristic, does h2 dominate h1?
24As space complexity
Main problem space complexity A has worst case
O(bd) space complexity, but an iterative
deepening version is possible ( IDA )