You are on page 1of 48

EE4483/IM4483

Part I: Topic 3A
Heuristic Search

Experience + Efforts => find answer to Q or improve performance

1
Part I: Topic 3-A Heuristic Search
Outline
Key Terms
• What is it?
• Why Designing Heuristics?
• Heuristic Search Algorithms Search Strategies
 Hill-Climbing Complete/Optimal
 Best-First (greedy) Uninformed/ Informed search
 A* strategies
Heuristic Search
Designing Heuristics
Hill-Climbing Search
Best-First /Greedy Search
Admissible Heuristics
A* Search

2
Search Strategies
A strategy is defined by picking the order of node expansion

Strategies are evaluated along the following dimensions:


o completeness -- does it always find a solution if one exists?
o time complexity-- number of nodes generated/expanded
o space complexity-- maximum number of nodes in memory
o optimality- does it always find a least-cost solution?
Time and space complexity are measured in terms of
o b- maximum branching factor of the search tree
o d- depth of the least-cost solution
o m- maximum depth of the state space (may be ∞ )

Uninformed Search = blind search


Informed Search = heuristics-applied search

3
Uninformed vs Informed Search Strategies
Uninformed Strategies use only the Informed Strategies use problem-specific
information available in the problem knowledge to guide the search.
definition. - Use an evaluation function to estimate
- Systematic generate new states the ‘desirability’ of each node
- Inefficient - Usually more efficient
- Popular methods: - Popular methods:
o Breadth-first search o Hill-Climbing
o Depth-First search o Best-First (Greedy)
o Iterative Deepening search o A*

Summary of those Uninformed Search Algorithms


Search
BreadthFirst DepthFirst IterativeDeepening
Criteria

Completeness? Yes No Yes


Optimality? Yes No Yes
Time bd bm bd
Space bd bm bd
4
Introduction: Heuristic Search
• The word heuristic (adj) literally means:
o Based on learning by one's own personal discoveries and
experiences
o Helping one in the process of discovery (ally / adversary)
• The literal meaning of the word heuristics (n) is
o (The study of) the use of experience and practical efforts to
find answers to questions or to improve performance
• In state space search, heuristics are formalized as:
o Rules for choosing those branches in a state space that are most
likely to lead to an acceptable problem solution

5
Why Heuristics ?
We are forced to use heuristics because the computational cost of
finding the solution is often prohibitive excessively high
 In many problems, state space growth is combinatorially explosive, with
the number of possible states increasing exponentially or factorially with
the depth of the search
 In these cases, exhaustive, brute force search techniques may fail to
find a solution within any practical length of time
 Heuristics attack the above complexity by guiding the search along the
most "promising" path through the space
 By eliminating states and their descendants from consideration, a
heuristic algorithm is expected to defeat combinatorial explosion of
state space graphs and find an acceptable answer
 For example, chess, go, “large” TSP (n > 25)
Average branching factor=35, 250

6
Limitations of Heuristic Algorithm
• Like many rules of discovery and invention, heuristics
are fallible
• A heuristic is only an informed guess. Because heuristics use
limited information, such as the description of the states
currently under evaluation, they are seldom able to predict the
exact behavior of the state space farther along the search
• A heuristic can lead a search algorithm to a sub-optimal solution
or fail to find any solution at all. This inherent limitation of
heuristic search cannot be eliminated by "better" heuristics or
more efficient search algorithms

7
Two Key Components of Heuristic Search

Each Heuristic Search consists of two parts

• A heuristic measure

• An algorithm that uses the heuristic measure


to search the state space

8
Tic-Tac-Toe Example Total 9!

How to get h ?

9
Reduced State Space

“fitness”

10
Heuristic Search Algorithm- Hill Climbing
First h-search algorithm

Hill climbing: the simplest way


• Named after an eager, but short-sighted mountain climber
o Hill-climbing strategies expand the current node in the search and
evaluate its children
o The best child is selected for further expansion; neither its siblings nor
its parents are retained
o The search halts when it reaches a state that is better than any of its
children
o Also known as “greedy algorithm”, or “greedy search”

11
Hill-Climbing (cont.)

• Limitation of hill-climbing strategies


o An erroneous heuristic can lead along infinite paths that fail
o Hill-climbing strategies can also become stuck at local maxima
o If the local maximum is not a goal, the algorithm fails to find a solution
o In general, heuristic search requires a more informed algorithm; this is
provided by best-first search
• Convention
o If heuristics = fitness or goodness, the larger the better: “hill-climbing”,
“local maxima”. E.g., number of wins in Fig.4.2
o If heuristics = cost, the smaller the better: “gradient descent”, “local
minima”. E.g. the tour length in TSP
12
Example 1 on Heuristic Search h = cost here

Hill-climbing works?

Fig 4.4 Heuristic search of a hypothetical state space.

13
2nd h-search algorithm Best-First Search
The example below, the numbers are the heuristic cost of the states

14
The Best-First Algorithm

1. Start with OPEN containing only the initial state


2. Until a goal is found or there are no nodes left on OPEN, do:
(a) Pick the best node on OPEN
(b)Generate its successors
(c)For each successor, do:
i. If it has not been generated previously, evaluate it, add it to
OPEN, and record its parent
ii. If it has been generated previously, change the parent if this
new path is better than the previous one. Update the cost of
getting to this node from the starting state

17
1)

2)

//leave it.
3)

// sorting !

16
Example 1 on Heuristic Search h = cost here

Best-first work ?

Fig 4.4 Heuristic search of a hypothetical state space.

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

Open: children of those members in the Closed

Can we find P, using Hill-climbing ? Depth-first ? Breadth-first ? 20


Why Designing Heuristics ?
- Heuristic function h(n) :
- Estimated cost of the cheapest path from n to a goal state
- Depends only on the state at that node
- h(n) is not larger than the real cost (admissible)

- If we have h score, we can apply search algorithm


such as Best-First search

- If apply the same search algorithm, two different


heuristics may lead to different performances for
solving the problem.

21
Example: Designing Heuristics

Fig 4.6 The start state, first moves, and goal state for an example-8 puzzle. 22
Example: Designing Heuristics (cont.)

h1 h2 h3

Fig 4.8 Three heuristics applied to states in the 8-puzzle. 23


22
Devising Heuristics

Devising good heuristics is difficult


•Our goal is to use the limited information available to find a single
state descriptor, with which intelligent choices can be made
• Each of the heuristics proposed above for the 8-puzzle ignores some
critical bit of information and is subject to improvement
• The design of good heuristics is an empirical problem; judgement
and intuition help, but the final measure of a heuristic must be its
actual performance on problem instance
•Because heuristics are fallible, it is possible that a search algorithm can
be misled down some path that fails to lead to a goal. A depth count
can be used to detect fruitless paths in an attempt to minimise this
danger

23
Devising Heuristics (cont.)
• A depth count can be added to the heuristic evaluation of each state to
bias search in favour of states found shallower in the graph
• This makes the evaluation function (cost), f, the sum of two
components:
f(n) = g(n) + h(n)

• g(n) : path-cost function = cost from initial state to current state n.


Or it measures the actual length of the path from the start state
(depth count) to any state n [no information on the cost toward the
goal].

• h(n): heuristic function =Estimated cost of the cheapest path from


to a goal state. Problem-specific knowledge
• h(n) is not larger than the real cost ( admissible )

24
Best-First: greedy
f(n) = g(n) + h(n)
• g(n) : path-cost function = 0

• h(n): heuristic function =Estimated cost from to a goal state.

25
Best-First: A*

, When h(n) is admissible

h(n) is always under-estimated/same as the actual cost from n to a goal.

26
A* Algorithm -- optimal solution = admissibility
f(n) = g(n) + h(n)
o g(n) measures the actual length of the path from any state n to the start state (depth count)
o h(n) is an admissible heuristic estimate (cost) of state n

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


h(n) : tiles out of place
g(n) : cost from start state to n

Fig 4.10 State space generated in heuristic search of the 8-puzzle graph. 30
Example: Best-First Search for 8-puzzle

The successive stages for open and closed using the best-first-
search algorithm on Fig.4.10
open ………………… closed..........................
1. [a4] []
2. [c4, b6, d6] [a4]
3. [e5, f5, g6, b6, d6] [a4, c4]
4. [f5, h6, g6, b6, d6, I7] [a4, c4, e5]
5. [j5, h6, g6, b6, d6, k7, I7] [a4, c4, e5, f5]
6. [l5, h6, g6, b6, d6, k7, I7] [a4, c4, e5, f5, j5]
7. [m5, h6, g6, b6, d6, n7, k7, I7] [a4, c4, e5, f5, j5, l5]
8. success, m=goal !

31
Example: Best-First Search for 8-puzzle

The successive stages for open and closed using the best-
first-search algorithm on Fig.4.10
open …………… closed......................
1. [a4] []
2. [c4, b6, d6] [a4]
3. [e5, f5, g6, b6, d6] [a4, c4]
4. [f5, h6, g6, b6, d6, I7] [a4, c4, e5]
5. [j5, h6, g6, b6, d6, k7, I7] [a4, c4, e5, f5]
6. [l5, h6, g6, b6, d6, k7, I7] [a4, c4, e5, f5, j5]
7. [m5, h6, g6, b6, d6, n7, k7, I7] [a4, c4, e5, f5, j5, l5]
8. success, m=goal !

32
Fig 4.11 Open and closed as they appear after the 3rd iteration of heuristic search 33
Find better move ?

Fig 4.12 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. 34
Example : Breadth-First vs Depth-First Search

breadthѪfirst depthѪfirst

35
Example: Best-First (greedy) to Find a Path from Arad to Bucharest
h(n) : evaluation function =estimate of cost from n to the closest goal
hSLD(n) = straight-line distance from n to Bucharest
f(n) = hSLD(n)

176

100

Fig.3.2 A Simplified road map of part of Romania (SLD from a to b) 36


a) The initial State

b) After expandingArad

176

100

35
176

100

36
d) The total distance from A to B:
140+99+211 = 450

176

100

37
Example: A* to Find a Path from Arad to Bucharest
f(n) : estimated total cost of path through n to goal (Whole Life)
evaluation function f(n) = h(n) + g(n)
h(n) = straight-line distance from n to Bucharest
g(n) = straight-line distance from Arad to n

176

100

Fig.3.2 A Simplified road map of part of Romania (SLD from x to y ) 40


Arad

176

100

39
366+160

366+160

40
Example: A* to Find a Path from Arad to Bucharest
366

393

413
415

366+160 417

41
Properties of Best-First vs A*
Properties of Best-First (Greedy) – without g
Complete ?? No, can get stuck in loops
Optimal?? No
Time complexity ?? O(bm)
Space complexity ?? O(bm), keep all nodes in memory

Properties of Best-First A* - h(n) never overestimate cost


Complete ?? Yes
Optimal?? Yes - if h(n) is both admissible & consistent for graph
Time complexity ?? O(bm)
Space complexity ?? O(bm), keep all nodes in memory

Criteria Characteristics
completeness does it always find a solution if one exists?
optimality does it always find a least-cost solution?
time complexity number of nodes generated/expanded
space complexity maximum number of nodes in memory

42
Exercise Questions
1. “Hand run” the best-first algorithm starting from node A in the graph of Fig.ex1,
where the heuristic measure of the cost for each node is given as h. Write down the
nodes being visited in order until it finds the target node O.

Fig.ex1

Fig.ex3

2. Sometimes there is no good evaluation function for a problem, but there is a


good comparison method: a way to tell if one node is better than another,
without assigning them numerical values. Is this enough to do a best-first
greedy search?
3. Work out two heuristics h1(n), and h2(n) for a 8-puzzle problem at a state n,
and goal state G as shown in Fig.ex3, where h1(n)=number of misplaced tiles,
45
and h2(n) = total Manhattan distance, respectively.
Exercise 1_Discussion

Open Closed
A []
B(8), D(10), C(12), E(19) A
M(4),H(5),G(6),F(9), D(10), C(12), E(19) B, A
N(1), H(5),G(6),F(9), D(10), C(12), E(19) M,B,A

F(9), D(10), C(12), E(19) G,H,N,M,B,A Fig.ex1
L(3), D(10), C(12), E(19) F,G,H,N,M,B,A
D(10), C(12), E(19) L,F,G,H,N,M,B,A
C(12), J(13), I(14), E(19) D, L,F,G,H,N,M,B,A
J(13), I(14), E(19) C, D, L,F,G,H,N,M,B,A
O(2), I(14), E(19) J, C, D, L,F,G,H,N,M,B,A

The path: A->B->M->N->H->G->F->L->D->C->J->O

44
Sometimes there is no good evaluation function for
a problem, but there is a good comparison method:
Exercise 2 _Discussions a way to tell if one node is better than another,
without assigning them numerical values. Is this
enough to do a best-first greedy search?

Why can do Best-First (greedy) search without knowing the


exact h-measure?

• As long as we are able to select the best state from all the
states in the Open, the Best-First search can be performed
normally.

45
Exercise 3 Admissible Heuristics
p1 at (x1, y1) and p2 at (x2, y2),
Manhattan d(p1,p2) = |x1 - x2| + |y1 - y2|

46
Example : Dominates h – Better for search

h(n) <= h*(n)

47
Summary on Topic 3-A

48

You might also like