0% found this document useful (0 votes)
19 views

19-Lecture 19 - Hurestic Search - Algorithms

The document discusses heuristic search algorithms, including best-first search and hill-climbing search. It provides pseudocode for implementing best-first search and hill-climbing search. An example of best-first search is given with multiple iterations showing the open and closed states. Best-first search uses a heuristic function to guide the search by prioritizing states closer to the goal. Hill-climbing search is used for optimization problems to find the highest valued state.

Uploaded by

alnymyb12345
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

19-Lecture 19 - Hurestic Search - Algorithms

The document discusses heuristic search algorithms, including best-first search and hill-climbing search. It provides pseudocode for implementing best-first search and hill-climbing search. An example of best-first search is given with multiple iterations showing the open and closed states. Best-first search uses a heuristic function to guide the search by prioritizing states closer to the goal. Hill-climbing search is used for optimization problems to find the highest valued state.

Uploaded by

alnymyb12345
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Artificial Intelligence

Lecture 19
Heuristic Search Algorithms

Adil Al-Azzawi, Ph.D.


Assistant Professor, Computer Science Department
College of Science, University of Diyala
2023-2024 1
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:

Procedure Best-First-Search
Begin
1.Identify possible starting states and measure the distance

"Best-First" Search
(f) of their closeness with the goal; Put them in a list 𝐿;
2.While 𝐿 is not empty do
2.1 Begin
2.1 Identify the node n from L that has the minimum
f; If there exist more than one node with minimum f,
select any one of them (say, n) arbitrarily;
2.2 If 𝑛 is the goal then
return n along with the path from the starting node
and exit;
2.3 Else remove 𝑛 from 𝐿 and add all the children of 𝑛 to
the list 𝐿, with their labeled paths from the starting
node;
2.2 End
3. End While;
End.
2
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ If the first element on open is not a goal, the algorithm applies all
matching production rules or operators to generate its descendants.
▪ If a child state is already on open or closed the algorithm checks to
make sure that the state records the shorter of the two partial solution
paths.
▪ Duplicate states are not retained.
▪ By updating the ancestor history of nodes on open and closed when they
are rediscovered, the algorithm is more likely to find a shorter path to
a goal.
▪ Heuristic search of a hypothetical state space.

3
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ A trace of the execution of best First.

4
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Search on this graph appears below.
▪ Suppose P is the goal state in the graph of the following figure.

5
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ A trace of the execution of best First.
▪ Because P is the goal, states along the path to P tend to have low
heuristic values.

6
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ A trace of the execution of best First.
▪ The heuristic is fallible: the state 0 has a lower value than the goal itself
and is examined first.

7
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ A trace of the execution of best First.
▪ Unlike hill climbing, which does not maintain a priority queue for the
selection of "next" states, the algorithm recovers from this error and finds
the correct goal.

8
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iteration State Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]

9
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iteration State Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]

1 2

10
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iteration State Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]

1 2

11
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iteration State Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]

1 2

12
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iteration State Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]

1 2 3 4

13
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iteration State Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]
3 B4 [E5,F5,C4,D6] [A5,B4]

1 2

14
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iteration State Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]
3 B4 [E5,F5,C4,D6] [A5,B4]

1 2 3 5 4

15
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iter. St. Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]
3 B4 [E5,F5,C4,D6]
[A5,B4]
[C4,E5,F5,D6]
4 C4 [G4,H3,E5,F5,D6] [A5,B4,C4]

16
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iter. St. Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]
[E5,F5,C4,D6]
3 B4 [A5,B4]
[C4,E5,F5,D6]
[G4,H3,E5,F54,D6]
4 C4 [A5,B4,C4]
[H3,G4,E5,F5,D6]

17
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iter. St. Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]
[E5,F5,C4,D6]
3 B4 [A5,B4]
[C4,E5,F5,D6]
[G4,H3,E5,F54,D6]
4 C4 [A5,B4,C4]
[H3,G4,E5,F5,D6]
5 H3 [O2,P3,G4,E5,F5,D6] [A5,B4,C4,H3]

18
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

Iter. St. Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]
[E5,F5,C4,D6]
3 B4 [A5,B4]
[C4,E5,F5,D6]
[G4,H3,E5,F54,D6]
4 C4 [A5,B4,C4]
[H3,G4,E5,F5,D6]
5 H3 [O2,P3,G4,E5,F5,D6] [A5,B4,C4,H3]
6 O2 [P3,G4,E5,F5,D6] [A5,B4,C4,H3,O2]

19
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


▪ Example:

It. St. Open Close


1 - [A5] []
2 A5 [B4,C4,D6] [A5]
[E5,F5,C4,D6]
3 B4 [A5,B4]
[C4,E5,F5,D6]
[G4,H3,E5,F54,D6]
4 C4 [A5,B4,C4]
[H3,G4,E5,F5,D6]
5 H3 [O2,P3,G4,E5,F5,D6] [A5,B4,C4,H3]
6 O2 [P3,G4,E5,F5,D6] [A5,B4,C4,H3,O2]
7 P3 Is the Goal [A5,B4,C4,H3,O2,P3]

20
Heuristic Search Algorithms:

▪ Implementing "Best-First" Search:


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

21
Heuristic Search Algorithms:

▪ Hill-Climbing Search (Max):


▪ Beside looking for a path to a goal state, search can also be used to
solve optimization problems, where each state has an evaluation
value attached, and the problem is to find the state with the highest
value.
▪ In this situation, local (i.e., without memory) best-first search is also
called "hill climbing".
▪ Such a procedure stops at local maxima.

22
Heuristic Search Algorithms:

▪ Hill-Climbing Search (Max):


▪ Such a procedure stops at local maxima.

Procedure Hill-Climbing

"Hill-Climbing" Search
Begin
1.Identify possible starting states and measure the distance
(𝑓) of their closeness with the goal node; Push them in a
stack according to the ascending order of their 𝑓;
2. Repeat
2.1 Pop stack to get the stack-top element;
2.2 If the stack-top element is the goal, announce it and
exit
2.3 Else push its children into the stack in the ascending
order of their f values;
3.3 Until the stack is empty;
End.

23
Heuristic Search Algorithms:

▪ A algorithm and A* Search Implementation


▪ Which node S has the smallest 𝑓’.
▪ So, node S will be selected for expansion the next time.
▪ The process would thus continue until the goal node is reached.

24
Heuristic Search Algorithms:

▪ A algorithm and A* Search Implementation


▪ The process would thus continue until the goal node is reached.

25
Heuristic Search Algorithms:

▪ A algorithm and A* Search Implementation


▪ The process would thus continue until the goal node is reached.

26

You might also like