Sunteți pe pagina 1din 23

Best First Search:

How close is the goal now

Motivations

Breadth-first, depth-first, and greedy hill


climbing are uninformed (dumb in a sense) strategies. Even before the search starts, you have some idea what the goal states are like, e.g. tic-tac-toe wins, chess checkmates, TSP tours. You know what you are going for. The question is how to get there. If we have some guess of how close you are to a goal node, you can employ much more sophisticated (informed, smart) search techniques.

Objectives

1. Heuristic measures 2. Best-first search algorithm 3. Apply to 8-puzzle

Uninformed and informed searches


Breadth-first search Since we know what the goal state is like, is it possible get there faster?

Oracle path

Tic-tac-toe heuristic: most wining strikes

Maximize the heuristic measure: the higher the number, the more promising it is. We can also minimize the heuristic measure: the lower the number, the closer it is to a goal. Negate the above, we have -3, -4, and -2

Heuristic measures: Minimize and maximize

Given a state (node) Assign a number to this state based on a


heuristic. Maximize A number indicates how promising this node is to get to a goal state higher means better Minimize A number guessing how far it is to a goal: The lower the value, the more likely that it is on the direct path to the goal.

Breadth first

Depth first

Best first: Trace


state name - heuristic value

1. open=[A5]; closed=[ ] Ordered by heuristic values 2. Visit A5; open=[B4,C4,D6]; closed=[A5] 3. Visit B4; open=[C4,E5,F5,D6]; closed=[B4,A5] 4. visit C4; open=[H3,G4,E5,F5,D6]; closed=[C4,B4,A5] 5. visit H3; open=[O2,P3,G4,E5,F5,D6]; closed=[H3,C4,B4,A5]

The Best-First Search


A heuristic search use
heuristic (evaluation) function to select the best state to explore Can be implemented with a priority queue, best one lines up in the front of the queue Breadth-first implemented with a queue, first in first out Depth-first implemented with a stack, last in first out

Breadth-first

FIFO

Depth-first Best-first

LIFO _IBO

Best-First Search
Like the depth-first and breadth-first search, best-first search uses
two-lists.
open: to keep track of the frontier of the search. closed: to record states already visited.

Order the states on open according to some heuristic estimate of


their closeness to a goal.

At each iteration through the loop, consider the most promising state
on the open list next.

When visiting a child state, if it is already on open or closed, the


algorithm checks if the child is reached by a shorter path this time compared with the last time it arrived at this child.

Main program
Function best_first_search open := [Start] closed := [ ] while open [ ] remove leftmost state from open, call it X if X is a goal then return SUCCESS else visit(X) put X on closed sort open by heuristic merit (best leftmost) return FAIL End function

Process children of X
Subroutine visit(X) generate children of X for each child of X child has never been seen before case % 3 cases the child is not on open or closed: assign the child a heuristic value add the child to open
child is waiting

the child is already on open: if the child was reached by a shorter path then give the state on open the shorter path

the child is already on closed: child been visited if the child was reached by a shorter path then remove the child from closed add the child to open End Subroutine

8-puzzle heuristics

Number of tiles out of places


Compared with the goal state How many tiles are not in the right place? Sum of taxicab distances For each tile, how far is it from the goal position? How many squares away? What is its distance? The objective is to minimize this heuristic value as you search. As it approaches 0, you are closer to the goal.

2 heuristics and their calculations


n h1(n) h2(n)

Algorithm A

Given a heuristic measure, it is preferable to


examine the state that is nearest to the root. This means that it did not take long to get here. The distance from the starting state to its descendants can be measured by maintaining a depth count for each state. f(n) = g(n) + h(n) partial path cost, g(n) measures how far state n is from the start state. node cost, h(n) guesses how far state n is from a goal state. A strategy using best-first ordering and f(n) is called Algorithm A search.

Algorithm A with h1(n)

States that are closer to the start node are preferred because you can get there sooner.

4 =1+3
h1(n) h1(n)

Trace
1. open=[a4] closed=[ ] 2. open=[c4,b6,d6] closed=[a4] 3. open=[e5,f5,g6,b6,d6] closed=[a4, c4] 4. open=[f5,h6,g6,b6,d6,i7] closed=[a4,c4,e5]

5. open=[j5,h6,b6,d6,k7,i7] closed=[a4,c4,e5,f5]
6. open=[i5,h6,b6,d6,k7,i7] closed=[a4,c4,e5,f5,j5] 7. open=[m5,h6,b6,d6,k7,i7] closed=[a4,c4,e5,f5,j5,i5] success, m = goal

At the 3rd iteration

State f and h both have 3 tiles out of place but f is preferred because you can get to f sooner.

Heuristic search vs breadth-first search


f(n) = g(n) + h1(n) h1(n) = number of tiles out of place

heuristic search breadth-first

Space complexities: Oracle path traverses 6 nodes. Best-first with h1(n) touches 14 nodes. Breadth-first looks at 46 nodes.

A* algorithm

1. Uses Best-First Strategy 2. minimizes criterion f(n) = g(n) + h(n)


n is a node h(n) is a heuristic function g(n) is the smallest cost of the path from start to n

3. and h(n) h*(n) where h*(n) is an oracle that


returns the actual cost of the shortest path from n to the goal.
A* guarantees to find the optimal solution if it exists but it is rare to find such algorithm in practice. Still, this theorem affords us hope and stresses the potential of heuristics.

Financial adviser as a heuristic agent


savings_account (adequate) income(adequate) investment (stocks) This rule is in fact a heuristic. Factors such as the ages of the individual and his dependents are ignored. One way to address these issues is to attach a confidence measure between -1 and 1. savings_account (adequate) income(adequate) investment (stocks) with confidence = 0.8 savings_account (adequate) income(inadequate) investment (combination) with confidence = 0.5 savings_account (inadequate) investment(savings) with confidence = 0.1

Conclusion

Breadth-first, depth-first, and hill-climbing


strategies do not attempt to estimate how far along the search is toward a goal. We can use a heuristic to obtain this estimate. We then use this heuristic to guide the search direction. How good the search is depends on how good the heuristic is.

S-ar putea să vă placă și