1
ARTIFICIAL
INTELLIGENCE
◤
CHAPTER 4
INFORMED
SEARCH
2
◤
OUTLINE
✔ Introduction
✔ Heuristic Search
✔ Greedy Search
✔ A* Search
✔ Memory Bounded Heuristic
Search
▪ Recursive Best First Search
▪ Simple Memory Bounded A*
✔ Dominance
✔ Relaxed Problems
3
◤
INTRODUCTION
Travel Salesperson Problem
Given a list of cities and their pair wise distances, the task is to find
a shortest possible tour that visits each city exactly once.
▪ Any idea how to improve this type of search?
▪ What type of information we may use to improve our search?
▪ Do you think this idea is useful: (At each stage visit the unvisited city
nearest to the current city)?
4
◤
HEURISTIC SEARCH ALGORITHM
5
◤
BEST-FIRST SEARCH
Idea: Use an evaluation function f(n) for each node
▪ family of search methods with various evaluation functions (estimate of "desirability“)
▪ usually gives an estimate of the distance to the goal
▪ often referred to as heuristics in this context
▪ Expand most desirable unexpanded node.
▪ A heuristic function ranks alternatives at each branching step based on the available
information (heuristically) in order to make a decision about which branch to follow during a
search.
Implementation:
▪ Order the nodes in fringe in decreasing order of desirability.
Special cases:
▪ greedy best-first search
▪ A* search
6
◤
BEST-FIRST SEARCH ALGORITHM
1. Initialize: Set OPEN= {Si}, CLOSED = { }, g(s) = 0, f(s) = h(s)
2. Fail: if OPEN = { } then return FAIL
3. Select: Select the minimum cost state (minimum evaluation function
f), n, from OPEN and insert in CLOSED
4. Terminate: if n belongs to G, terminate with Success, and return f(n)
5. Expand: Generate all direct successors of node n. For each
successor m, of n:
a) apply the evaluation function, f, to the node.
b) if the node has not been in either list, add it to OPEN.
else, if f(m) has decreased and m ∈ CLOSED, move m to OPEN
6. Loop: Go to Step 2
7
GREEDY BEST-FIRST SEARCH
◤
8
◤
ROMANIA WITH STEP COSTS IN KM
Suppose we can have this info (SLD)
▪ How can we use it to improve our search?
9
◤
GREEDY BEST-FIRST SEARCH
Greedy best-first search expands the node that appears to be
closest to goal.
▪ Estimate of cost from n to goal ,ex. hSLD(n)= straight-line
distance from n to Bucharest.
▪ Utilizes a heuristic function as evaluation function
▪ f(n) = h(n) = estimated cost from the current node to a
goal.
▪ Heuristic functions are problem-specific.
▪ Often straight-line distance for route-finding and similar problems.
10
◤
GREEDY BEST-FIRST SEARCH EXAMPLE
11
◤
GREEDY BEST-FIRST SEARCH EXAMPLE
12
◤
GREEDY BEST-FIRST SEARCH EXAMPLE
13
◤
GREEDY BEST-FIRST SEARCH EXAMPLE
14
◤
15
◤
GREEDY BEST-FIRST SEARCH
PROPERTIES
▪ Complete: No –can get stuck in loops (e.g., Iasi
□Neamt□Iasi □Neamt□….)
▪ Time: O(bm), but a good heuristic can give significant
improvement
▪ Space: O(bm) --keeps all nodes in memory
▪ Optimal: No
b: branching factor
m: maximum depth of the search tree
16
◤
DISCUSSION
▪ Do you think hSLD(n) is admissible?
▪ Did you find the Greedy idea useful?
▪ Ideas to improve it?
A*search
17
A* SEARCH
◤
18
◤
A* SEARCH
Idea: avoid expanding paths that are already expensive.
▪ Evaluation function = path cost + estimated cost to the goal
▪ 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 to goal through n
▪ Combines greedy and uniform-cost search to find the (estimated)
cheapest path through the current node
▪ Heuristics must be admissible
▪ Never overestimate the cost to reach the goal
▪ Very good search method, but with complexity problems
19
◤
A* SEARCH EXAMPLE
20
◤
A* SEARCH EXAMPLE
21
◤
A* SEARCH EXAMPLE
22
◤
A* SEARCH EXAMPLE
23
◤
A* SEARCH EXAMPLE
24
◤
A* SEARCH EXAMPLE
25
◤
A* SEARCH ALGORITHM
1. Initialize: Set OPEN= {Si}, CLOSED = { }, g(s) = 0, f(s) = h(s)
2. Fail: if OPEN = { } then return FAIL
3. Select: Select the minimum cost state, n, from OPEN and insert in
CLOSED
4. Terminate: if n belongs to G, terminate with Success, and return f(n)
5. Expand: Generate all direct successors of node n.
For each successor m, of n
if m ✂ [OPEN ∪ CLOSED], Set g(m) = g(n) + C(n,m)
Set f(m) = g(m) + h(m) and insert m in OPEN
if m ∈ [OPEN ∪ CLOSED], Set g(m) = min (g(m), g(n) + C(n,m)), Set
f(m) = g(m) + h(m)
if f(m) has decreased and m ∈ CLOSED, move m to OPEN
6. Loop: Go to Step 2
7. End
26
◤
A* SEARCH EXERCISE
NODE SL DISTANCE
A 8.0
B 7.3
C 7.6
D 6
E 5.4
F 4.1
G 4.1
H 2.8
I 2.0
J 2.2
27
◤
A* SEARCH EXERCISE
28
◤
GREEDY BEST-FIRST SEARCH
EXERCISE
NODE SL DISTANCE
A 8.0
B 7.3
C 7.6
D 6
E 5.4
F 4.1
G 4.1
H 2.8
I 2.0
J 2.2
29
◤
GREEDY BEST-FIRST SEARCH
EXERCISE
30
◤
EXERCISE
NOD SL DISTANCE
E
A 8.0
B 6.3
C 6.3
D 5.0
E 4.0
F 5.1
G 5.0
H 4.5
I 2.8
J 2.2
K 3.6
31
◤
ADMISSIBLE HEURISTICS
▪ 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-1: If h(n) is admissible, A* using tree-search is optimal.
32
◤
PROOF OF A* OPTIMALITY
▪ Recall that f(n) = g(n) + h(n)
▪ Now, suppose some suboptimal goal G2 has been generated and is in
the fringe. Let n be an unexpanded node in the fringe such that n is
on a shortest path to an optimal goal G.
▪ We want to prove:
f(n) < f(G2) i.e. A* will prefer n over G2
f(G2) = g(G2) since h(G2) = 0
g(G2) > g(G) since G2 is suboptimal f(G) = g(G) since h(G) = 0
f(G2) > f(G) from above
h(n) ≤ h*(n) since h is admissible g(n) + h(n) ≤ g(n) + h*(n)
f(n) ≤ f(G) Hence f(G2) > f(n), and n is expanded, thus, A* will never select G2 for
expansion
33
◤
PROOF OF A* OPTIMALITY (CONT’D)
In other words:
f(G2) = g(G2) + h(G2) = g(G2) > C*,
since G2 is a goal on a non-optimal path (C* is the
optimal cost)
f(n) = g(n) + h(n) <= C*, since h is admissible
f(n) <= C* < f(G2), so G2 will never be expanded
A* will not expand goals on sub-optimal paths
34
◤
CONSISTENT HEURISTICS
A heuristic is consistent if for every node n, every successor n’ of
n
generated by any action:
h(n) ≤ c(n,n') + h(n’)
If h is consistent, we have:
▪ f(n') = g(n') + h(n’)
= g(n) + c(n,n') + h(n') ≥ g(n) + h(n) = f(n)
▪ •i.e., f(n) is non-decreasing along any path.
▪ Theorem-2: If h(n)is consistent, A* using graph-search is
optimal.
▪ consistency is also called monotonicity
35
◤
OPTIMALITY OF A*
▪ A* expands nodes in order of increasing fvalue
▪ Gradually adds "f-contours" of nodes
▪ Contour i has all nodes with f = fi, where fi< fi+1
36
◤
COMPLEXITY OF A*
▪ The number of nodes within the goal contour search space
is still exponential
▪ with respect to the length of the solution
▪ better than other algorithms, but still problematic
▪ Frequently, space complexity is more important than time
complexity
▪ A* keeps all generated nodes in memory
37
◤
PROPERTIES OF A*
▪ Complete? Yes (unless there are infinitely many nodes with f ≤ f(G) )
▪ Time? Exponential
▪ Because all nodes such that f(n) <= C* are expanded!
▪ Space? Keeps all nodes in memory, (bd) Fringe is exponentially large
▪ Optimal? Yes (already proved to reach the optimal goal)
▪ A* prunes all nodes with f(n)>f((G)
Who can propose an idea to improve the time/space complexity?
38
◤
MEMORY BOUNDED HEURISTIC
SEARCH
▪ How can we solve the memory problem for A* search?
▪ Idea: Try something like iterative deeping search, but the cutoff
is f-cost (g+h) at each iteration, rather than depth first.
▪ Two types of memory bounded heuristic searches:
▪ Recursive BFS
▪ SMA*
39
◤
RECURSIVE BEST FIRST SEARCH (RBFS)
best alternative over
fringe nodes,
which are not children:
do I want to back up?
▪ RBFS changes its mind very
often in practice.
▪ This is because the f=g+h
become more accurate (less
optimistic) as we approach the
goal. Hence, higher level
nodes have smaller f-values
and will be explored first.
▪ Problem? If we have more
memory we cannot make use
of it.
▪ Any idea to improve this?
40
◤
PROPERTIES OF RECURSIVE BEST
FIRST SEARCH
▪ Complete? Yes, given enough
space
▪ Time? Hard to analyze
▪ Space? b*d
▪ Optimal? Yes, if admissible
41
◤
SIMPLE MEMORY BOUNDED A* (SMA*)
▪ This is like A*, but when memory is full we delete the
worst node (largest f-value).
▪ Like RBFS, we remember the best descendent in the
branch we delete.
▪ If there is a tie (equal f-values), we delete the oldest
nodes first.
▪ SMA* finds the optimal reachable solution given the
memory constraint.
▪ But time can still be exponential.
42
◤
SIMPLE MEMORY BOUNDED A* (SMA*)
▪ SMA* is a shortest path algorithm based on the A* algorithm.
▪ The advantage of SMA* is that it uses a bounded memory, while
the A* algorithm might need exponential memory.
▪ All other characteristics of SMA* are inherited from A*.
▪ How it works:
▪ Like A*, it expands the best leaf until memory is full.
▪ Drops the worst leaf node-the one with the highest f-value.
▪ Like RBFS, SMA* then backs up the value of the forgotten node to
its parent.
43
◤
SIMPLE MEMORY-BOUNDED A* (SMA*)
Example with 3-node memory
44
◤
SMA* ALGORITHM
45
◤
PROPERTIES OF SMA*
▪ It works with a heuristic, just as A*
▪ It is complete if the allowed memory is high enough to store the
shallowest solution.
▪ It is optimal if the allowed memory is high enough to store the shallowest
optimal solution, otherwise it will return the best solution that fits in the
allowed memory
▪ It avoids repeated states as long as the memory bound allows it
▪ It will use all memory available
▪ Enlarging the memory bound of the algorithm will only speed up the
calculation
▪ When enough memory is available to contain the entire search tree, then
calculation has an optimal speed
46
◤
ADMISSIBLE HEURISTICS
▪ Ex., for the 8-puzzle:
▪ h1(n) = number of misplaced tiles
▪ h2(n) = total Manhattan distance
▪ (i.e., no. of squares from desired location of each tile)
▪ h1(S) = 8
▪ h2(S) = 3+1+2+2+2+3+3+2 = 18
47
◤
DOMINANCE
▪ If h2(n) ≥ h1(n) for all n, and both are admissible.
▪ then h2 dominates h1 (h2 is more informed than h1)
▪ h2 is better for search: it is guaranteed to expand less
nodes.
▪ Typical search costs (average number of nodes expanded):
▪ d=1 IDS = 3,644,035 A*(h1) = 227 nodes A*(h2) = 73 nodes
2 nodes
▪ d=2 IDS = too many A*(h1) = 39,135 A*(h2) = 1,641
▪ What4to do If
nodes nodes
we have h1,…,hm; but none dominates the nodes
other?
▪ h(n) = max{h1(n), . . .hm(n)}
48
◤
RELAXED PROBLEMS
▪ 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 near
square, then h2(n) gives the shortest solution