Você está na página 1de 37

Simple Hill Climbing

First state that is better than the current state is selected.

Simple Hill Climbing


Algorithm 1. Evaluate the initial state. 2. Loop until a solution is found or there are no new operators left to be applied:
- Select and apply a new operator - Evaluate the new state: goal quit better than current state new current state

Steepest-Ascent Hill Climbing (Gradient Search)


Considers all the moves from the current
state.

Selects the best one as the next state.

Difference between Hill climbing and Best first search: In Hill Climbing-one move is selected and all others are rejected, never to be reconsidered.
In Best first search-one move is selected but others are kept around so that they can be revisited later if the selected path becomes less promising.

Hill Climbing: Disadvantages


Local maximum A state that is better than all of its neighbours, but not better than some other states far away.

Hill Climbing: Disadvantages


Plateau A flat area of the search space in which all neighbouring states have the same value.

Hill Climbing: Disadvantages


Ridge The orientation of the high region, compared to the set of available moves, makes it impossible to climb up. However, two moves executed serially may increase the height.
7

Hill Climbing: Disadvantages


Ways Out

Backtrack to some earlier node and try going


in a different direction.

Make a big jump to try to get in a new section. Moving in several directions at once.

Hill Climbing: Disadvantages


Hill climbing is a local method:
Decides what to do next by looking only at the immediate consequences of its choices.

Global information might be encoded in


heuristic functions.

Hill Climbing: Disadvantages


Start
A D C B Blocks World

Goal

D C B A

10

Hill Climbing: Disadvantages


Start
0 A D C B Blocks World

Goal
4

D C B A

Local heuristic: +1 for each block that is resting on the thing it is supposed to be resting on. -1 for each block that is resting on a wrong thing.
11

Hill Climbing: Disadvantages


0
A D C B

2
D C B A

12

Hill Climbing: Disadvantages


D
C B A D 0 0 A

C
B

C
B

D
A

C
B

0 A D

13

Hill Climbing: Disadvantages


Start
-6 A D C B Blocks World

Goal
6

D C B A

Global heuristic: For each block that has the correct support structure: +1 to every block in the support structure. For each block that has a wrong support structure: -1 to every block in the support structure.
14

Hill Climbing: Disadvantages


D
C B A D -6 -2 A

-3

C
B

C
B

D
A

C
B

-1 A D

15

Hill Climbing: Conclusion


Can be very inefficient in a large, rough
problem space.

Global heuristic may have to pay for


computational complexity.

Often useful when combined with other


methods, getting it started right in the right general neighbourhood.
16

A* Method
A* (Aystar) (Hart, 1972) method is a combination of branch & bound and best search, combined with the dynamic programming principle. The heuristic function (or Evaluation function) for a node N is defined as f(N) = g(N) + h(N) The function g is a measure of the cost of getting from the Start node (initial state) to the current node.
It is sum of costs of applying the rules that were applied along the best path to the current node.

The function h is an estimate of additional cost of getting from the current node to the Goal node (final state).
Here knowledge about the problem domain is exploited.

A* algorithm is called OR graph / tree search algorithm.

Behavior of A* Algorithm
Underestimation If we can guarantee that h never over estimates actual value from current to goal, then A* algorithm is guaranteed to find an optimal path to a goal, if one exists.

Example Underestimation f=g+h


Here h is underestimated

Underestimated

(1+3)B (2+3) E

(1+4)C

(1+5)D

3 moves away from goal

3 moves away from goal

(3+3) F

Explanation -Example of Underestimation


Assume the cost of all arcs to be 1. A is expanded to B, C and D. f values for each node is computed. B is chosen to be expanded to E. We notice that f(E) = f(C) = 5 Suppose we resolve in favor of E, the path currently we are expanding. E is expanded to F. Clearly expansion of a node F is stopped as f(F)=6 and so we will now expand C. Thus we see that by underestimating h(B), we have wasted some effort but eventually discovered that B was farther away than we thought. Then we go back and try another path, and will find optimal path.

Example Overestimation
Here h is overestimated

A Overestimated (1+3) B (2+2) E (3+1)F (4+0) G (1+4) C (1+5) D

Explanation Example of Overestimation


A is expanded to B, C and D. Now B is expanded to E, E to F and F to G for a solution path of length 4. Consider a scenario when there a direct path from D to G with a solution giving a path of length 2. We will never find it because of overestimating h(D). Thus, we may find some other worse solution without ever expanding D. So by overestimating h, we can not be guaranteed to find the cheaper path solution.

Admissibility of A*
A search algorithm is admissible, if
for any graph, it always terminates in an optimal path from initial state to goal state, if path exists.

If heuristic function h is underestimate of actual value from current state to goal state, then the it is called admissible function. Alternatively we can say that A* always terminates with the optimal path in case
h(x) is an admissible heuristic function.

Example: Solve Eight puzzle problem using A* algorithm


Start state 3 5 4 7 1 6 2 8 Goal state 5 7 4 1 3 6 2 8

Evaluation function f (X) = g (X) + h(X) h (X) = the number of tiles not in their goal position in a given state X g(X) = depth of node X in the search tree Initial node has f(initial_node) = 4 Apply A* algorithm to solve it. The choice of evaluation function critically determines search results.

Example: Eight puzzle problem (EPP)


Start state 3 5 4 7 1 6 2 8 Goal state 5 7 4 1 3 6 2 8

Evaluation function - f for EPP


The choice of evaluation function critically determines search results. Consider Evaluation function f (X) = g (X) + h(X)
h (X) g(X) = = the number of tiles not in their goal position in a given state X depth of node X in the search tree

For Initial node


f(initial_node) = 4

Apply A* algorithm to solve it.

Search Tree

Start State f = 0+4 3 7 6 5 1 2 4 8 up (1+3) 3 7 6 5 2 4 1 8 left (1+5) 3 7 6 5 1 2 4 8 right (2+4) 3 7 6 5 2 4 1 8 right (1+5) 3 7 6 5 1 2 4 8

up (2+3) 3 6 5 7 2 4 1 8 left (3+2) 3 6 5 7 2 4 1 8 down (4+1) 5 3 6 7 2 4 1 8

left (2+3) 3 7 6 5 2 4 1 8 right (3+4) 3 6 5 7 2 4 1 8

right

5 3 6 7 2 4 1 8

Goal State

Harder Problem
Harder problems (8 puzzle) cant be solved by heuristic function defined earlier.
Initial State 2 4 7 1 5 6 8 3 1 8 7 Goal State 2 6 3 4 5

A better estimate function is to be thought. h (X) = the sum of the distances of the tiles from their goal position in a given state X Initial node has h(initial_node) = 1+1+2+2+1+3+0+2=12

Problem Reduction
Goal: Acquire TV set

Goal: Steal TV set

Goal: Earn some money AND-OR Graphs

Goal: Buy TV set

Algorithm AO* (Martelli & Montanari 1973, Nilsson 1980)

29

Problem Reduction: AO*


A 5 A 6 B 3 9 C 4 A 11 D 10 B 6 12 C 4 D 10 D 5

A 9 B 3 9 C 4

E 4

F 4

G 5

H 7

E 4

F 4

30

Problem Reduction: AO*


A 11
B 13 C 10

A 14
B 13 C 15

D 5

E 6
G 5

F 3

D 5

E 6
G 10 H 9

F 3

Necessary backward propagation

31

Constraint Satisfaction
Many AI problems can be viewed as problems
of constraint satisfaction.
Cryptarithmetic puzzle:

SEND MORE MONEY

32

Constraint Satisfaction
As compared with a straightforard search
procedure, viewing a problem as one of constraint satisfaction can reduce substantially the amount of search.

33

Constraint Satisfaction
Operates in a space of constraint sets. Initial state contains the original constraints
given in the problem.

A goal state is any state that has been


constrained enough.

34

Constraint Satisfaction
Two-step process: 1. Constraints are discovered and propagated as far as possible. 2. If there is still not a solution, then search begins, adding new constraints.

35

Initial state:
No two letters have the same value.
The sum of the digits must be as shown.
M=1 S = 8 or 9 O=0 N=E+1 C2 = 1 N+R>8 E9

SEND MORE MONEY

E=2
N=3 R = 8 or 9 2 + D = Y or 2 + D = 10 + Y

C1 = 0
2+D=Y N + R = 10 + E R=9 S =8

C1 = 1
2 + D = 10 + Y D=8+Y D = 8 or 9

D=8
Y=0

D=9
Y=1
36

Constraint Satisfaction
Two kinds of rules: 1. Rules that define valid constraint propagation. 2. Rules that suggest guesses when necessary.

37

Você também pode gostar