03 Informedsearch

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

Vietnam National University of HCMC

International University
School of Computer Science and Engineering

Introduction to Artificial Intelligence


(IT097IU)

Lecture 03: States and Searching -


Heuristic Search and More Sophisticated
Search

Instructor: Nguyen Trung Ky


Chapter 3:
Informed Search and Exploration

2
Informed Search
Definition:
Use problem-specific knowledge beyond the
definition of the problem itself
Can find solutions more efficiently
Best-first search
Greedy best-first search
A*
Heuristics

3
Best-First Search
Idea: use an evaluation function f(n) for each node
estimate of "desirability"
Expand most desirable unexpanded node
Implementation: use a data structure that maintains the frontier in
a decreasing order of desirability
Is it really the best?

Special cases: uniform-cost (Dijkstra’s algorithm), greedy search,


A* search

A key component is a heuristic function h(n):


h(n) = estimated cost of the cheapest path from node n to a goal node
h(n) = 0 if n is the goal
h(n) could be general or problem-specific

4
Best First Search Algorithm
1. initialize the Q with the starting state (node)
2. while Q is not empty, do
1) assign the first element of Q to N
2) if N is the goal, return SUCCESS
3) remove N from Q
4) add the children of N to Q
5) sort the entire Q by f (n)
3. return FAILURE

5
Recall Romania Map Example

What’s a proper heuristic that measures cheapest path from current node to goal node?

6
Romania Map with Costs

7
Greedy Best-First Search
Evaluation function: f(n) = h(n)
estimate the cost from n to goal
hSLD = straight line distance from n to
Bucharest

8
Example: Arad to Bucharest

9
Example: Arad to Bucharest

10
Example: Arad to Bucharest

11
Example: Arad to Bucharest

12
Analysis of Greedy Best-First
Complete?
From Iasi to Fagaras
No – can get stuck in loops, e.g., Iasi => Neamt => Iasi =>
Neamt => …
Time?
O(bm), but a good heuristic can give dramatic
improvement
Space?
O(bm) -- keeps all nodes in memory
Optimal?
No

13
A*: Minimizing Total Est. Cost
Idea: avoid expanding paths that are
already expensive

Evaluation function f (n) = g(n) + h(n)


g (n) = cost so far to reach n
h (n) = estimated cost from n to goal
f (n) = estimated total cost of path through n to
goal

14
A* Search Example

15
A* Search Example

16
A* Search Example

17
A* Search Example

18
A* Search Example

19
A* Search Example

20
Exercise
Use A* graph-search to generate a path
from Lugoj to Bucharest using the straight-
line distance heuristic.

21
Admissible Heuristic
A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach
the goal state from n

An admissible heuristic never overestimates the


cost to reach the goal, i.e., it is optimistic

Example: hSLD(n) (never overestimates the actual


road distance)

Theorem: If h(n) is admissible, A* using TREE-


SEARCH is optimal

22
Optimality of A* -- Proof
Suppose some suboptimal goal G2 has been generated
and is in the frontier. Let n be an unexpanded node in
the frontier such that n is on a shortest path to an
optimal goal G.

Assume the optimal cost is C*


f(n) = g(n) + h(G) <= C*
f*(n)= g*(n) + h*(G2) > C*
from the above, we have
f(n) <= C* < f*(n)
Thus, G2 will not be expanded

23
Consistency Heuristics
A heuristic is consistent if for every node n, every successor
n' of n generated by any action a, h(n) ≤ c(n,a,n') + h(n')
Triangle inequality

Every consistent heuristic is also admissible

Proof by induction on the number k of nodes


on the shortest path to any goal from n.
K = 1, let n’ be the goal node; then h(n) ≤ c(n, a, n’)
Assume n’ is on the shortest path k steps from the goal and that
h(n’) is admissible by hypothesis, then:
h(n) ≤ c(n,a,n’) + h(n’) ≤c(n,a,n’) + h*(n’) =h*(n)
So, h(n) at k+1 steps from the goal is also admissible.

24
A* With Graph Search
Theorem: If h(n) is consistent, A* using GRAPH-
SEARCH is optimal

If h is consistent, and n’ is a successor of n, we


have
f(n') = g(n') + h(n')
= g(n) + c(n,a,n') + h(n')
≥ g(n) + h(n)
= f(n)

i.e., f(n) is non-decreasing along any path


Whenever A* selects a node for expansion, the
optimal path to that node has been found

25
Optimality of A*
A* expands nodes in order of increasing f value
Assume C* is the optimal cost
A* expands all nodes with f(n) < C*
A* might then expand some of the nodes right on the “goal contour”
(f(n) = C*) before selecting a goal node
Uniform-cost search (h(n) = 0) => bands more circular

26
Analysis of A*
Important idea:
appropriate h(n) function
A* is optimal efficient (no other optimal alg. is guaranteed to
expand fewer nodes than A*)
pruning while still guaranteeing optimality
Complete?
Yes (unless there are infinitely many nodes with f ≤ f(G))
Optimal?
Yes, with finite b and positive path cost
However, A* is not the answer for all problems
Time?
Exponential in the length of the solution
Space?
Keeps all nodes in memory
A* usually runs out of space long before it runs out of time

27
Heuristic Functions

Two commonly used functions:


h1(n) = number of misplaced tiles
e.g., h1(n) = 8 in the above example
h2 (n) = sum of the distances of the tiles from their goal
positions, called Manhattan distance
e.g., h2 (n) = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18 in the
above example

28
Quality of Heuristic
Assume # of nodes generated by A* for a problem
is N and the solution depth is d, then b* is the
effective branching factor that a uniform tree of
depth d would have to have. Thus:
N + 1 = 1 + b* + (b*)2 + … + (b*)d

b* might vary across problem instances, but is


fairly constant for sufficiently hard problems

A well-designed heuristic would have a value of b*


close to 1

29
The Comparison

Each data point corresponds to 100 instances of the


8-puzzle problem in which the solution depth varies.
30
Heuristics Domination
If h2(n) ≥ h1(n) for all n (both
admissible)

then h2 dominates h1

h2 is better for search


A* using h2 will never expand more
nodes than A* using h1

31
Inventing Admissible Heuristic
A problem with fewer restrictions on the
actions is called a relaxed problem

The cost of an optimal solution to a relaxed


problem is an admissible heuristic for the
original problem
If the rules of the 8-puzzle are relaxed so that a
tile can move anywhere, then h1(n) gives the
shortest solution

If the rules are relaxed so that a tile can move


to any adjacent square, then h2 (n) gives the
shortest solution

32
Inventing Admissible Heuristic
If a collection of admissible heuristics h1 …
hm is available, and none of them
dominates any of the others, we can choose
h (n) = max{h1(n), …, hm(n)}

We can also get from sub-problem of a


given problem

33
Exercise
The heuristic path algorithm is a best-first
search in which the objective function is
f(n) = (2-w) x g(n) + w x h(n). For what
values of w is the algorithm guaranteed to
be optimal? (You may assume that h is
admissible.) What kind of search does this
perform when w = 0? When w = 1? When
w = 2?

34
Exercise
Prove each of the following statements:
Breadth-first search is a special case of uniform-
cost search.
Breadth-first search, depth-first search, and
uniform-cost search are special cases of best-
first search.
Uniform-cost search is a special case of A*
search.

35
Discussion
Lab Assignments

36

You might also like