Lecture-12 c0W
Lecture-12 c0W
CS 165A
1
Practical note about search algorithms
• The computer can’t “see” the search graph like we can
– No “bird’s eye view” – make relevant information explicit!
• What information should you keep for a node in the search tree?
– State
(1 2 0)
2
Avoiding repeated states
• It may be beneficial to explicitly avoid repeated states,
especially where there are loops in the state graph and/or
reversible operators
– Search space can be very significantly pruned
• How to deal with repeated states:
– Do not return to state we just came from (parent node)
– Do not create paths with cycles (ancestor nodes)
– Do not generate any state that was ever generated before (graph
search)
• But there is a cost
– Have to keep track (in memory) of every state generated
– The path might not be optimal
3
Graph Search vs Tree Search
• Tree Search
– We might repeat some states
– But we do not need to remember states
• Graph Search
- We remember all the states that have been explored
- But we do not repeat some states
4
Search as problem-solving
• We have defined the problem
– Data
States, initial state(s), goal test/state(s), path cost function
– Operations
State transitions
5
Best-First Search
function BEST-FIRST-SEARCH(problem, EVAL-FN) returns a solution or
failure
QUEUING-FN a function that orders nodes by EVAL-FN
return GENERAL-SEARCH(problem, QUEUING-FN)
6
Uniform Cost Search
• Similar to breadth-first search, but always expands the
lowest-cost node, as measured by the path cost function,
g(n)
– g(n) is (actual) cost of getting to node n
– Breadth-first search is actually a special case of uniform cost
search, where g(n) = DEPTH(n)
– If the path cost is monotonically increasing, uniform cost search
will find the optimal solution
7
Example
A
2 8 6
B C E
2
12 1
4
D
1
F
8
Uniform-Cost Search
C = optimal cost
• Complete? Yes if ε = minimum step cost > 0
9
Greedy Best-First Search
• Uses a heuristic function, h(n), as the EVAL-FN
• h(n) estimates the cost of the best path from state n to a goal state
– h(goal) = 0
• Greedy search – always expand the node that appears to be the closest
to the goal (i.e., with the smallest h)
– Instant gratification, hence “greedy”
11
“A” Search
• Uniform-cost search minimizes g(n) (“past” cost)
12
A* Search
• “A* Search” is A Search with an admissible h
– h is optimistic – it never overestimates the cost to the goal
h(n) true cost to reach the goal
13
A* Example
15
Optimality of A*
• A* expands nodes in order of increasing f value
• Gradually adds "f-contours" of nodes
• Contour i has all nodes with f=fi, where fi < fi+1
•
Optimality of A*
• Optimality of A*
• Let OPT be the optimal path cost.
– All non-goal nodes on this path have f ≤ OPT.
Positive costs on edges
17
A* Search
• Optimal? Yes
• Complete? Yes
18
A* Works for Multiple Goals
R
5 1
A B
1 1
C D
1 10
G1 G2
19
Efficiency of A*
20
The cost of being informed
• Typical performance of informed search methods is much
better than uninformed methods
– Assuming reasonable heuristics exist
21
Cost tradeoff
Overall cost
“Informedness”
22
Graph Search vs Tree Search
• Tree Search
– We might repeat some states
– But we do not need to remember states
• Graph Search
- We remember all the states that have been explored
- But we do not repeat some states
23
Avoiding Repeated States using A* Search
• Is GRAPH-SEARCH optimal with A*?
Try with TREE-SEARCH and
B
GRAPH-SEARCH
1 h=5 1
A C D
4 4
h=5 h=1 h=0
7
E
h=0
Graph Search
Step 1: Expand A; Among B, C, E, Choose C
Step 2: Expand C; Among B, E, D, Choose B
Step 3: Expand B (C has been explored, stop); Among D, E,
Choose E. (you are not going to select C again) 24
Avoiding Repeated States using A* Search
• Is GRAPH-SEARCH optimal with A*?
Try with TREE-SEARCH and
B
GRAPH-SEARCH
1 h=5 1
A C D
4 4
h=5 h=1 h=0
7
E
h=0
Z S T
O A F R
26
Consistency (Monotonicity) of heuristic h
• A heuristic is consistent (or monotonic) provided
– for any node n, for any successor n’ generated by action a with
cost c(n,a,n’)
c(n,a,n’)
h(n) ≤ c(n,a,n’) + h(n’) n n’
– akin to triangle inequality. h(n’)
– guarantees admissibility (proof?). h(n)
g
– values of f(n) along any path are non-decreasing (proof?).
Contours of constant f in the state space
27
Consistent heuristic is admissible
• Let h(x) be a consistent heuristic and c(x,y) be the
corresponding step cost.
• Consistent heuristic: h(x)≤c(x,y)+h(y)
• Proof…
28
Memory Bounded Search
• Memory, not computation, is usually the limiting factor in
search problems
– Certainly true for A* search
• Why? What takes up memory in A* search?
29
Iterative Deepening A* (IDA*)
• IDA* is an optimal, memory-bounded, heuristic search
algorithm
– Requires space proportional to the longest path that it explores
– Space estimate: O(bd)
• Similar to Iterative Deepening Search
– Uses f-cost limit rather than depth-limit
– In IDS, depth-limit is incremented after each round
– In IDA*, f-cost limit is updated after each round
Limit based on the smallest f-cost of a pruned node from the
previous iteration
30
Simplified Memory-Bounded A* (SMA*)
• IDA* only keeps around the current f-cost limit
– Can check the current path for repeated states, but future paths may
repeat states already expanded
– Inefficient for small ε step costs
• SMA* uses more memory to keep track of repeated states
– Up to the limit of allocated memory
– Nodes with high f-cost are dropped from the queue when memory
is filled (“forgotten nodes”)
• Optimality and completeness depends on how much
memory is available with respect to the optimal solution
– SMA* is complete and optimal if there is any reachable solution
given the current memory limit
31
Heuristics
• What’s a heuristic for
– Driving distance (or time) from city A to city B ?
– 8-puzzle problem ?
– M&C ?
– Robot navigation ?
– Reaching the summit ?
• Admissible heuristic
– Does not overestimate the cost to reach the goal
– “Optimistic”
• Are the above heuristics admissible? Consistent?
32
8-Puzzle
33
Comparing and combining heuristics
• Heuristics generated by considering relaxed versions of a problem.
• Heuristic h1 for 8-puzzle
– Number of out-of-order tiles
• Heuristic h2 for 8-puzzle
– Sum of Manhattan distances of each tile
• h2 dominates h1 provided h2(n) ≥ h1(n).
– h2 will likely prune more than h1.
• max(h1,h2 , .. ,hn) is
– admissible if each hi is
– consistent if each hi is
• Cost of sub-problems and pattern databases
– Cost for 4 specific tiles
– Can these be added for disjoint sets of tiles?
34
Effective Branching Factor
• Though informed search methods may have poor worst-
case performance, they often do quite well if the heuristic
is good
– Even if there is a huge branching factor
35
Example: 8-puzzle problem
Solution length
36