62
HEURISTIC SEARCH

HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Embed Size (px)

Citation preview

Page 1: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

HEURISTIC SEARCH

Page 2: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Portion of the state space for tic-tac-toe.

Page 3: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Heuristically reduced state space for tic-tac-toe.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 4: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

First three levels of the tic-tac-toe state space reduced by symmetry

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 5: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

The “most wins” heuristic applied to the first children in tic-tac-toe.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 6: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Is it possible to completely cover with non-overlapping dominos an 8x8 grid having two diagonally opposite corners removed?

Page 7: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Is it possible to completely cover with non-overlapping dominos an 8x8 grid having two diagonally opposite corners removed?

Page 8: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Is it possible to completely cover with non-overlapping dominos an 8x8 grid having two diagonally opposite corners removed?

Issues:1) Representation

(organization)2) Algorithm

(process)

Page 9: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

The local maximum problem for hill-climbing with 3-level look ahead

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 10: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 11: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

priority queue

not necessary if states are added to open in sorted order

not necessary if using a monotone heuristic

Page 12: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Heuristic search of a hypothetical state space.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

(assume P3 is the goal state and lower scores are preferred)

Page 13: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

A trace of the execution of best_first_search for previous figure.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 14: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Heuristic search of a hypothetical state space with open and closed states highlighted.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 15: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Eight Puzzle…

Page 16: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Compare:best-first with depth factor: 26 moves to solution(7725 in CLOSED; 7498 left in OPEN)

best-first without depth factor: 48 moves to solution(272 in CLOSED; 332 in OPEN)

30 shuffle moves

Consider this screen shot of a brute-force breath-first search in process for the 15-puzzle where the optimal solution is known (by another method) to be located at depth 26.

How long will it take to find the solution?

Page 17: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

The start state, first moves, and goal state for an example-8 puzzle.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

1 2 34 5 67 8

or

Goal

Page 18: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Three heuristics applied to states in the 8-puzzle.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 19: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 20: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

The heuristic f applied to states in the 8-puzzle.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

(but should use a better heuristic…)

Page 21: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

State space generated in heuristic search of the 8-puzzle graph.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Notice that Luger is using the “Tiles out of place” heuristic.

Page 22: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

State space generated in heuristic search of the 8-puzzle graph.

The successive stages of open and closed that generate this graph are:

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 23: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Open and closed as they appear after the 3rd iteration of heuristic search

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 24: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Heuristic search with inclusion of a depth factor(heuristic here is # of tiles out of place) Nilsson

Page 25: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

i.e., as long as h(n) is not overestimated(i.e., because that could prevent search of the optimal path)

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 26: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

(i.e., locally admissible)

Note: If the graph search algorithm for best-first search is used with a monotonic heuristic, a new path cannot be shorter than one already found.

Page 27: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Note: the best h(n) can be is the actual cost of the optimal path from node n to the goal. If h1(n) < h2(n), then h1(n) is actually underestimating the cost more than h2(n) and is, therefore, less informed.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 28: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Comparison of state space searched using heuristic search with space searched by breadth-first search. The proportion of the graph searched heuristically is shaded. The optimal search selection is in bold. Heuristic used is f(n) = g(n) + h(n) where h(n) is tiles out of place.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 29: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Number of nodes generated as a function of branching factor, B, for various lengths, L, of solution paths. The relating equation is T = (BL+1 – 1)/(B – 1), adapted from Nilsson (1980)*.

*Note: equation in text is incorrect but the one shown here is correct for root node at depth 0

Bra

nchi

ng F

acto

r =

B

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 30: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Informal plot of cost of searching and cost of computing heuristic evaluation against informedness of heuristic, adapted from Nilsson (1980).

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

(i.e., cost to run the heuristic)

(i.e., cost to traverse the search graph)

Page 31: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Two-“Person” GamesTwo-“Person” Games

Page 32: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

State space for a variant of Nim. Each state partitions the seven matches into one or more piles of different sizes. First player who cannot make a legal move, wins.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 33: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Exhaustive minimax for the game of Nim. Bold lines indicate forced win for MIN. Each node is marked with its derived value (0 or 1) under minimax.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Note: Figure is slightly different from text...

Page 34: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Getting ready to apply minimax to a hypothetical state space. Leaf states show heuristic values.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 35: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Applying minimax to a hypothetical state space. Leaf states show heuristic values; internal states show backed-up values.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 36: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Heuristic measuring conflict applied to states of tic-tac-toe.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 37: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Two-ply minimax applied to the opening move of tic-tac-toe, from Nilsson (1971).

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 38: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Two ply minimax, and one of two possible MAX second moves, from Nilsson (1971).

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 39: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Two-ply minimax applied to X’s move near the end of the game, from Nilsson (1971).

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 40: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Let’s reconsider the application of minimax to the hypothetical state space shown a few slides back...

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Alpha-Beta Pruning

Page 41: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 42: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 43: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 44: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 45: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 46: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 47: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 48: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 49: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 50: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 51: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 52: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 53: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Alpha-beta pruning applied to the previous minimax state space search. States without numbers are not evaluated.

Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005

Page 54: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Alpha-Beta SearchAlpha-Beta SearchAs successors of a node are given backed-up values, the bounds As successors of a node are given backed-up values, the bounds on the backed-up values can change but:on the backed-up values can change but:– Alpha values of MAX nodes can never decreaseAlpha values of MAX nodes can never decrease– Beta values of MIN nodes can never increaseBeta values of MIN nodes can never increase

Rules for discontinuing search:Rules for discontinuing search:– Discontinue search below any MIN node having a beta value ≤ to Discontinue search below any MIN node having a beta value ≤ to

alpha value of any of its MAX node ancestors. Final backed-up value alpha value of any of its MAX node ancestors. Final backed-up value of this MIN node can be set to its beta value.of this MIN node can be set to its beta value.

– Discontinue search below any MAX node having an alpha value ≥ Discontinue search below any MAX node having an alpha value ≥ the beta value of any of its MIN node ancestors. Final backed-up the beta value of any of its MIN node ancestors. Final backed-up value of this MAX node can be set to its alpha value.value of this MAX node can be set to its alpha value.

Rules for computing alpha and beta values:Rules for computing alpha and beta values:– The alpha value of a MAX node is set equal to the current largest The alpha value of a MAX node is set equal to the current largest

final backed-up value of its successors.final backed-up value of its successors.– The beta value of a MIN node is set equal to the current smallest The beta value of a MIN node is set equal to the current smallest

final backed-up value of its successors.final backed-up value of its successors.

Page 55: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

102 8 4 5 8 3 2 7 6 2 5 1 0

Mini-Max

Page 56: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

102 8 4 5 8 3 2 7 6 2 5 1 0

10 8 8 3 7 5 1

138

8 Max’s move

Here are the backed-up values

Min’s move

Max takes this move

Mini-Max

Page 57: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

102 8 4 5 8 3 2 7 6 2 5 1 0

Mini-Max with Alpha-Beta Cutoffs

Page 58: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Mini-Max with Alpha-Beta Cutoffs

Page 59: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Node α-β valuesA (max) α = -, β = B (min) α = -, β = E (max) α = -, β = LE (max) α = 2, β = ME (max) α = 10, β = B (min) α = -, β = 10F (max) α = -, β = 10NF (max) α = 8, β = 10OF (max) α = 8, β = 10B (min) α = -, β = 8A (max) α = 8, β = C (min) α = 8, β = G (max) α = 8, β = PG (max) α = 8, β = QG (max) α = 8, β = C (min) α = 8, β = 8Search terminated below C because β @ C <= α @ A A (max) α = 8, β = D (min) α = 8, β = J (max) α = 8, β = VJ (max) α = 8, β = WJ (max) α = 8, β = D (min) α = 8, β = 5Search terminated below D because β @ D <= α @ A

Processing sequence for α-β assignment and visiting leaf nodes:

Page 60: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

32 8 5 7 6 0 1 5 2 8 4 10 2

E

Max

MinB

A

F MaxG H

C

J

D

KI

Another Example of Mini-Max with Alpha-Beta Cutoffs

Page 61: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

32 8 5 7 6 0 1 5 2 8 4 10 2

Eα=3

Max’s move

Here are the final alpha-beta (=backed-up) values(X denotes branches that do not need to be searched)

Min’s move

Max takes this move

Bβ=3

Aα=8

Fα=8

Max’s move

X

Gα=7

X

Hα=1

Cβ=1

X

Jα=8

Dβ=8

Kα=10

X

I

Another Example of Mini-Max with Alpha-Beta Cutoffs

There is no need to search below a MAX node whose value is greater than the parent node’s value (because the MIN node above wouldn’t accept anything > than its value), nor to search below a MIN node (e.g., node C) whose value is less than the parent’s value (because the MAX node above wouldn’t accept anything < than its value).

Page 62: HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe

Processing sequence:

Node α or β valueE α=3B β=3F α=8No search of F’s right subtree because α @ F > β @ BG α=7No search of G’s right subtree because α @ G > β @ BA α=3H α=1C β=1No search of C’s right subtree because β @ C < α @ AJ α=8D β=8K α=10No search of K’s right subtree because α @ K > β @ DA α=8

note: α or β values are also the backed-up values...

32 8 5 7 6 0 1 5 2 8 4 10 2

Eα=3

Max’s move

Here are the final alpha-beta (=backed-up) values(X denotes branches that do not need to be searched)

Min’s move

Max takes this move

Bβ=3

Aα=8

Fα=8

Max’s move

X

Gα=7

X

Hα=1

Cβ=1

X

Jα=8

Dβ=8

Kα=10

X

I

Processing Sequence for Previous Search