0% found this document useful (0 votes)
39 views65 pages

Heuristic Search: Unit 4

Uploaded by

Asma Al
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views65 pages

Heuristic Search: Unit 4

Uploaded by

Asma Al
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Taibah University_CS Dept.

CS 362_ Intelligent Systems

CS 362: Intelligent Systems


Slide 1

UNIT 4

HEURISTIC SEARCH
Taibah University_CS Dept. CS 362_ Intelligent Systems

Outline
Slide 2

4.0 Introduction

4.1 An Algorithm for Heuristic Search

4.2 Admissibility, Monotonicity, and Informedness

4.3 Using Heuristics I n Games

4.4 Complexity Issues


Taibah University_CS Dept. CS 362_ Intelligent Systems

Heuristic definition
Slide 3

George Polya (1945) defines heuristic as :


“the study of the methods and rules of discovery and invention”

 The verb eurisco, which means “I discover.”


 When Archimedes emerged from his famous bath clutching the
golden crown,
he shouted “Eureka!” meaning “I have found it!”.

 In state space search,


Heuristics are formalized as rules for choosing those branches in
a state space that are most likely to lead to an acceptable
problem solution.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Heuristic and AI problem solving


Slide 4

AI problem solvers employ heuristics in two basic situations:


1) A problem may not have an exact 2) A problem may have an exact solution,
solution because of inherent but the computational cost of
ambiguities in the problem finding it may be prohibitive
statement or available data.
The problem has an exact solution but is
• Medical diagnosis is an example of too complex to allow for a brute
this. A given set of symptoms may force solution.
have several possible causes; doctors
use heuristics to choose the most In many problems (such as chess),
likely diagnosis and formulate a plan
of treatment.
• Vision is example of an inexact
problem. Vision systems often use
heuristics to select the most likely of
several possible interpretations of as
scene.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Heuristic and AI problem solving


Slide 5

Heuristic or informed search:


 Exploits additional knowledge about the problem that helps
direct search to more promising paths.
 problem-solving strategies which in many cases find a solution
faster than uninformed search. However , this is not guaranteed.
 Could require a lot more time and can even result in the solution
not being found.
 Fallible because they rely on limited information, they may lead
to a suboptimal solution or to a dead end.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Heuristic and AI problem solving


Slide 6

Heuristic is:
 an AI search technique that employs heuristic for its moves.
 a rule of thumb that probably leads to a solution. Heuristics
play a major role in search strategies because of exponential
nature of the most problems.
 help to reduce the number of alternatives from an exponential
number to a polynomial number.

In Artificial Intelligence, heuristic search has a general meaning,


and a more specialized technical meaning. In a general sense, the
term heuristic is used for any advice that is often effective, but is
not guaranteed to work in every case. Within the heuristic search
architecture, however, the term heuristic usually refers to the
special case of a heuristic evaluation function.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Informed or Heuristic search Strategies


Slide 7

Types of informed search strategies:


• Best-First Search
- Greedy search
- A* search
- Best-First Search Analysis
- Heuristic Functions
• Memory Bounded Search
- Iterative Deepening A* Search
- Recursive best-first search
- Simplified Memory Bounded A*
• Iterative Improvement Algorithms
- Hill-Climbing Search
- Simulated Annealing
- Tabu Search
- and many more.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Heuristic Information
Slide 8

 In order to solve larger problems, domain-specific knowledge must be


added to improve search efficiency.

 Information about the problem include:


 the nature of states,
cost of transforming from one state to another,
and characteristics of the goals.

This information can often be expressed in the form of heuristic


evaluation function,
say f(n , g),
a function of the nodes n and/or the goals g.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Example (1): The game of tic-tac-toe


Slide 9

 Even if we use symmetry to


reduce the search space of
redundant moves,

 The number of possible paths


through the search space is
something like 12 x 7! =
60480. That is a measure of the
amount of work that would
have to be done by a brute-force
search.

Fig 4.1 First three levels of the tic-tac-


toe state space reduced by symmetry
Taibah University_CS Dept. CS 362_ Intelligent Systems

Heuristic Example (1)


Slide 10

Fig 4.2 The “most wins” heuristic


applied to the first children in tic-tac-
toe. Fig 4.3 Heuristically reduced state space for
tic-tac-toe.

 In reality, the number of states is smaller, as the board fills and


reduces options. This crude bound of 25 states is an
improvement of four orders of magnitude over 9!.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Example (2) The traveling salesman problem


Slide 11

 The traveling salesman problem is too


complex to be solved via exhaustive search
for large values of N.

 The nearest neighbor heuristic work well


most of the time, but with some
arrangements of cities it does not find the
shortest path. Consider the following two
graphs.
 In the first, nearest neighbor will find the
shortest path. In the second it does not:
Taibah University_CS Dept. CS 362_ Intelligent Systems

Hill Climbing
Slide 12

 The simplest way to implement heuristic search is through a procedure called hill-climbing
(Pearl 1984).
 Hill climbing (local search) is an iterative improvement algorithm that starts with an initial
state to a problem, then attempts to find the best node for the current node to follow. And
so on until goal node is found.

 Hill-climbing strategies expand the current state of the search and evaluate its children.

 The “best” child is selected for further expansion; neither its siblings nor its parent are
retained.

 In hill climbing the basic idea is to always head towards a state which is better than the
current one.

 So, if you are at town A and you can get to town B and town C (and your target is town D)
then you should make a move IF town B or C appear nearer to town D than town A does.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Hill Climbing
Slide 13

Note that:
 Backtracking is not permitted.
 At each step in the search, a single node is chosen to follow.
 The criterion for the node to follow is that it’s the best state for the current
state.
 Hill climbing do not care about path from initial state to goal
 In steepest ascent hill climbing you will always make your next state the best
successor of your current state, and will only make a move if that successor is
better than your current state. This can be described as follows:
1. Start with current-state = initial-state.

2. Until current-state = goal-state OR there is no change in current-state do:

A. Get the successors of the current state and use the evaluation function to assign a score to
each successor.
B. 2. If one of the successors has a better score than the current-state then set the new current-
state to be the successor with the best score.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Hill Climbing
Slide 14
Taibah University_CS Dept. CS 362_ Intelligent Systems

Hill Climbing
Slide 15
Taibah University_CS Dept. CS 362_ Intelligent Systems

Hill Climbing Example


Slide 16
Taibah University_CS Dept. CS 362_ Intelligent Systems

Hill Climbing
Slide 17

 Terminates when a peak is reached.


 Does not look ahead of the immediate neighbors of the current state.
 Chooses randomly among the set of best successors, if there is more than
one.
 Doesn’t backtrack, since it doesn’t remember where it’s been
 The problem with hill climbing is that the best node to enumerate locally may
not be the best node globally.
 For this reason, hill climbing can lead to local optimums, but not
necessarily the global optimum (the best solution available).
 Hill-climbing can get stuck without finding optimum
 Terminates when it reaches a peak (where no neighboring state has a
higher value)
 Does not look beyond immediate neighbors of current state
 Like climbing Everest in thick fog with amnesia
Taibah University_CS Dept. CS 362_ Intelligent Systems

Hill Climbing Example


Slide 18
Taibah University_CS Dept. CS 362_ Intelligent Systems

Problem of HILL-CLIMBING SEARCH


Slide 19
Taibah University_CS Dept. CS 362_ Intelligent Systems

The Best-First Search Algorithm (BEST-FS)


Slide 20

 Best First Search (or Greedy Best First Search ) is a combination of


depth first and breadth first searches.
• Depth first is good because a solution can be found without computing all
nodes and
• Breadth first is good because it does not get trapped in dead ends.
 The best first search allows us to switch between paths thus gaining
the benefit of both approaches.
 Best First Search described as follows:
• At each step the most promising node is chosen.
• If one of the nodes chosen generates nodes that are less promising it is
possible to choose another at the same level and in effect the search
changes from depth to breadth.
• If on analysis these are no better then this previously unexpanded node
and branch is not forgotten and the search method reverts to the
descendants of the first choice and proceeds, backtracking as it were.
Greedy best-first search
21
Greedy Best-first search
22
Greedy Best-first search
23
Taibah University_CS Dept. CS 362_ Intelligent Systems

The Best-First Search Algorithm(BEST-FS)


Slide 24

Best First Search Algorithm:


1- Start with OPEN holding the initial
state
2- Pick the best node on OPEN
3- Generate its successors
4- For each successor Do
If it has not been generated before
evaluate it add it to OPEN and record its
parent
If it has been generated before change the
parent if this new path is better and in
that case update the cost of getting to any
successor nodes
5- If a goal is found or no more nodes
left in OPEN, quit, else return to 2.
Taibah University_CS Dept. CS 362_ Intelligent Systems

The Best-First Search Algorithm(BEST-FS)


Slide 25

 The best first search algorithm will involve an OR graph which


avoids the problem of node duplication and assumes that each
node has a parent link to give the best node from which it came
and a link to all its successors.
 In this way if a better node is found this path can be propagated
down to the successors. This method of using an OR graph
requires 2 lists of nodes :
• OPEN is a priority queue of nodes that have been evaluated by the
heuristic function but which have not yet been expanded into
successors. The most promising nodes are at the front.
• CLOSED are nodes that have already been generated and these
nodes must be stored because a graph is being used in preference
to a tree.
Taibah University_CS Dept. CS 362_ Intelligent Systems

BEST-FS – Example 1
Slide 26

A trace of the execution of best_first_search


If the root is A and the goal is P for Figure 4.10
1.open = [A5]; closed = [ ]
2.evaluate A5; open = [B4,C4,D6]; closed = [A5]
3.evaluate B4; open = [C4,E5,F5,D6];
closed = [B4,A5]
4.evaluate C4; open = [H3,G4,E5,F5,D6];
closed = [C4,B4,A5]
5.evaluate H3; open = [O2,P3,G4,E5,F5,D6];
closed = [H3,C4,B4,A5]
6.evaluate O2; open = [P3,G4,E5,F5,D6];
closed = [O2,H3,C4,B4,A5]
7.evaluate P3; the solution is found!
Fig 4.10 Heuristic search of a
hypothetical state space.
Taibah University_CS Dept. CS 362_ Intelligent Systems

BEST-FS – Example 1
Slide 27

 open and closed states at level 3

Fig 4.11 Heuristic search of a hypothetical state


space with open and closed states highlighted.
Taibah University_CS Dept. CS 362_ Intelligent Systems

BEST-FS – Example 2
Slide 28

 The start state, first moves, and goal


state for an example-8 puzzle.
The simplest heuristic counts the tiles
out of place in each state when
compared with the goal.
 This heuristic does not use all of the
information available in a board
configuration, because it does not
take into account the distance the
tiles must be moved.
 A “better” heuristic would 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.
Taibah University_CS Dept. CS 362_ Intelligent Systems

BEST-FS – Example 2
Slide 29

 Three heuristics applied to states in the 8-puzzle.


tiles 2,8,1,6,7 Sum=1+2+1+1+1

tiles 2,8,1 Sum=1+2+1

tiles 2,8,1,6,5
Taibah University_CS Dept. CS 362_ Intelligent Systems

The A* Algorithm
Slide 30

 If two states have the same or nearly the same heuristic evaluations, it is
generally preferable to examine the state that is nearest to the root state of the
graph.
 This state will have a greater probability of being on the shortest path to the
goal.
 The distance from the starting state to its descendants can be measured by
maintaining a depth count for each state.
 This count is 0 for the beginning state and is incremented by 1 for each level of
the search.
 This makes our evaluation function, f , the sum of two components:
f (n) = g(n) + h(n)
Where
• g(n) measures the actual length of the path from any state n to the start
state and,
• h(n) is a heuristic estimate of the distance from state n to a goal.
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* Algorithm – Example
Slide 31

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

This is A* example
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* Algorithm – Example
Slide 32

 The full best-first search


of the 8-puzzle graph.

 Each state is labeled with


a letter and its heuristic
weight,
f(n) = g(n) + h(n)

 The successive stages of


open and closed that
generate this graph are:
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* Algorithm – Example
Slide 33

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


heuristic search
Taibah University_CS Dept. CS 362_ Intelligent Systems

The A* Search Algorithm Summarization


Slide 34

To summarize:
 Operations on states generate children of the state currently under
examination.
 Each new state is checked to see whether it has occurred before (is on
either open or closed), there by preventing loops.
 Each state n is given an f value equal to the sum of its depth in the
search space g(n) and a heuristic estimate of its distance to a goal
h(n). The h value guides search toward heuristically promising states
while the g value can prevent search from persisting indefinitely on a
fruitless path.
 States on open are sorted by their f values. By keeping all states on
open until they are examined or a goal is found, the algorithm
recovers from dead ends.
 As an implementation point, the algorithm’s efficiency can be
improved through maintenance of the open and closed lists, perhaps
as heaps or leftist trees.
Taibah University_CS Dept. CS 362_ Intelligent Systems

BEST-FS Properties
Slide 35

How does best-first search rate according to the four criteria


of performance?
 Complete:
 It is complete
 It always reaches goal.
 Optimal:
 It is not optimal
 A solution can be found in a longer path (higher g(n) with a lower h(n)
value)
 Time:
 It generates O(b m) nodes.
 Space:
 Space complexity is O(bm) [here b is maximum branching factor;
 Keeps every node in memory. m is maximum path length]
Taibah University_CS Dept. CS 362_ Intelligent Systems

Admissibility, Monotonicity , and Informedness


Slide 36

 We may evaluate the behavior of heuristics along a number of


dimensions.
 We may desire a solution and also require the algorithm to find
the shortest path to the goal.
 For instance, this could be important when an application might
have an excessive cost for extra solution steps, such as planning
a path for an autonomous robot through a dangerous
environment.
 Heuristics that find the shortest path to a goal whenever it
exists are said to be admissible.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Admissibility, Monotonicity , and


Informedness
Slide 37

 Conditions for optimality: Admissibility


 The heuristic is defined as admissible if it accurately estimates
the path cost to the goal, or underestimates it (remains
optimistic).

 This means that:


 g(n) (path cost from the initial node to the current node)
monotonically increases,

 While h(n) (path cost from the current node to the goal node)
monotonically decreases.
Taibah University_CS Dept. CS 362_ Intelligent Systems

Admissibility Measures
Slide 38

 A search algorithm is Admissible if it is guaranteed to find a


minimal path to a solution whenever such a path exists.

• Breadth-first search is an admissible search strategy. Because it


looks at every state at level n of the graph before considering
any state at the level n+1, any goal nodes are found along the
shortest possible path.

• Unfortunately, breadth-first search is often too inefficient for


practical use.
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm
Slide 39

 Best-First Search Algorithm A is called as A* algorithm


 Using the evaluation function f(n) = g(n) + h(n)
 If n is a node in the state space graph,
• g(n) measures the depth at which that state has been found in the graph,
and
• h(n) is the heuristic estimate of the distance from n to a goal.

 In this sense f(n) estimates the total cost of the path from the start
state through n to the goal state.
A* search
40

root
g(n): cost of path

h*(n): true minimum cost to goal


h(n): Heuristic
(expected) minimum
cost to goal. (estimation)
Goal
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm
Slide 41

 A* algorithm:
1- Start with OPEN holding the initial state
2- Pick the best node on OPEN
3- Generate its successors
4- For each successor Do
If it has not been generated before
evaluate it add it to OPEN and record
its parent
If it has been generated before change
the parent if this new path is better
and in that case update the cost of
getting to any successor nodes
5- If a goal is found or no more nodes left in
OPEN, quit, else return to 2.
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm
Slide 42

 We may characterize a class of Admissible Heuristic search


strategies. we define an evaluation function f*:
f*(n) = g*(n) + h*(n)
Where
• g*(n) is the cost of the shortest path from the start to node n and,
• h*(n) returns the actual cost of the shortest path from n to the
goal.
It follows that
f*(n) is the actual cost of the optimal path from a start node to
a goal node that passes through node n.
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm
Slide 43

 In algorithm A, g(n), the cost of the current path to state n , is a reasonable


estimate of g*, but they may not be equal: g(n)≥g*(n).
 These are equal only if the graph search has discovered the optimal path to
state n.
 Similarly, we replace h*(n) with h(n), a heuristic estimate of the minimal cost
to a goal state.
 Although we usually may not compute h*, it is often possible to determine
whether or not the heuristic estimate, h(n), is bounded from above by h*(n),
i.e., is always less than or equal to the actual cost of a minimal path.
 If algorithm A uses an evaluation function f in which h(n) ≤ h*(n), it is
called algorithm A*.
Taibah University_CS Dept. CS 362_ Intelligent Systems

ALGORITHM A, ADMISSIBILITY, ALGORITHM A*


Slide 44
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm - Romania Example


Slide 45

Find goal “Bucharest” starting at “Arad”.


Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm - Romania Example


Slide 46

 Find Bucharest starting at Arad


Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm - Romania Example


Slide 47

f(Arad) = c(??,Arad)+h(Arad)=0+366=366

Expand Arad and determine f(n) for each node


• f(Sibiu)=c(Arad,Sibiu)+h(Sibiu)=140+253=393
• f(Timisoara)=c(Arad,Timisoara)+h(Timisoara)=118+329=447
• f(Zerind)=c(Arad,Zerind)+h(Zerind)=75+374=449
Best choice is Sibiu
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm - Romania Example


Slide 48

Expand Sibiu and determine f(n) for each node


• f(Arad)=c(Sibiu,Arad)+h(Arad)=280+366=646
• f(Fagaras)=c(Sibiu,Fagaras)+h(Fagaras)=239+179=415
• f(Oradea)=c(Sibiu,Oradea)+h(Oradea)=291+380=671
• f(Rimnicu Vilcea)=c(Sibiu,Rimnicu Vilcea)+h(Rimnicu Vilcea)=220+193=413
Best choice is Rimnicu Vilcea
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm - Romania Example


Slide 49

Expand Rimnicu Vilcea and determine f(n) for each node


• f(Craiova)=c(Rimnicu Vilcea, Craiova)+h(Craiova)=366+160=526
• f(Pitesti)=c(Rimnicu Vilcea, Pitesti)+h(Pitesti)=317+100=417
• f(Sibiu)=c(Rimnicu Vilcea,Sibiu)+h(Sibiu)=300+253=553
Best choice is Fagaras
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm - Romania Example


Slide 50

Expand Fagaras and determine f(n) for each node


• f(Sibiu)=c(Fagaras, Sibiu)+h(Sibiu)=338+253=591
• f(Bucharest)=c(Fagaras,Bucharest)+h(Bucharest)=450+0=450
Best choice is Pitesti !!!
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm - Romania Example


Slide 51

Expand Pitesti and determine f(n) for each node


• f(Rimnicu Vilcea)=g(Pitesti, Rimnicu Vilcea)+h(Rimnicu
Vilcea)=414+193=607
• f(Craiova)=g(Pitesti, Craiova)+h(Craiova)=455+160=615
• f(Bucharest)=c(Pitesti,Bucharest)+h(Bucharest)=418+0=418
Best choice is Bucharest !!!
• Optimal solution (only if h(n) is admissable)
• Note values along optimal path !!
A* search example
52
A* search example
53
A* search example
54
A* search example
55
A* search example
56
A* search example
57
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm - Romania Example


Slide 58
Taibah University_CS Dept. CS 362_ Intelligent Systems

A* algorithm Properties
Slide 59

How does A* search rate according to the four criteria of


performance?
 Complete:
 It is complete
 As long as the memory supports the depth and branching factor of the tree.
 Optimal:
 It is optimal
 Depends on the use of an admissible heuristic
• No algorithm with the same heuristic is guaranteed to expand fewer
nodes
 Time:
 O(bd)
 Must keep track of the nodes evaluated so far
 Space:
 O(bd)
 Must keep track of the discovered nodes to be evaluated
SUMMARY of SEARCH TECHNIQUES

Search techniques

Blind Heuristic

Hill
Depth first Breadth first A*
climbing
Search Search search
Search
( DFS ) ( BFS )
Best-First Greedy
Search Search
Taibah University_CS Dept. CS 362_ Intelligent Systems

Comparison of different Search Algorithms


Slide 61
Taibah University_CS Dept. CS 362_ Intelligent Systems

MONOTONICITY
Slide 62

 In the study of path-finding problems in artificial intelligence, a heuristic function is said


to be consistent, or monotone, if its estimate is always less than or equal to the
estimated distance from any neighboring vertex to the goal, plus the step cost of
reaching that neighbor.
Inconsistent heuristics

 h decreases from parent


to child
 f(p)=5+5=10
 f(c1) = 6+2 = 8
 lower bound on the total
cost of reaching the goal
through c1

 information provided by
evaluating c1 is
“inconsistent”
Taibah University_CS Dept. CS 362_ Intelligent Systems

Monotonicity Example
Slide 64
Taibah University_CS Dept. CS 362_ Intelligent Systems

INFORMEDNESS
Slide 65

 When One Heuristic Is Better ? : More Informed Heuristics


 The more informed the search, the less the space that must be
searched to get the minimal path solution

You might also like