Chap 3 B Uninformed Search
Chap 3 B Uninformed Search
Chap 3 B Uninformed Search
• Question:
– what if a better path is found to a node already in frontier or on explored list?
Search strategy evaluation
• A search strategy is defined by the order of node expansion
• Goal-Test:
– Do goal-test when node inserted into Frontier?
– Do goal-test when node removed?
Frontier = [E,F,G]
Breadth-first search
• Expand shallowest unexpanded node
• Frontier: nodes waiting in a queue to be explored
– also called Fringe, or OPEN
• Implementation:
– Frontier is a first-in-first-out (FIFO) queue (new successors go at end)
– Goal test when inserted Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Expand E; no children Forgotten/reclaimed= black nodes
Forget E; B
Frontier = [F,G]
Example
BFS for
8-puzzle
Properties of breadth-first search
• Complete? Yes, it always reaches a goal (if b is finite)
• Time? 1 + b + b2 + b3 + … + bd = O(bd)
(this is the number of nodes we generate)
• Space? O(bd)
(keeps every node in memory, either in frontier or on a path to frontier).
• Optimal? No, for general cost functions.
Yes, if cost is a non-decreasing function only of depth.
– With f(d) ≥ f(d-1), e.g., step-cost = constant:
• All optimal goal nodes occur on the same level
• Optimal goals are always shallower than non-optimal goals
• An optimal goal will be found before any non-optimal goal
Uniform-cost Search:
Expand node with smallest path cost g(n).
• Frontier is a priority queue, i.e., new successors are merged into the
queue sorted by g(n).
– Can remove successors already on queue w/higher g(n).
• Saves memory, costs time; another space-time trade-off.
• Goal-Test when node is popped off queue.
Uniform cost search (R&N Fig. 3.14)
[A* is identical except queue sort = f(n)]
function U NIFORM -C OST-S EARCH ( problem ) returns a solution, or failure
node ← a node with S TAT E = problem .I NIT IAL -S TAT E, PAT H -C OST = 0
frontier ← a priority queue ordered by PAT H -C OST, with node as the only element
explored ← an empty set
loop do Goal test after pop
if E MPTY ?( frontier ) then return failure
node ← P OP( frontier ) /* chooses the lowest-cost node in frontier */ Avoid
if problem .G OAL -T EST(node .S TAT E) then return S OL UT ION (node )
add node .S TAT E to explored redundant
for each action in problem .A CT IONS(node .S TAT E) do frontier nodes
child ← C HILD -N ODE( problem , node , action )
if child .S TAT E is not in explored or frontier then
frontier ← I NSE RT(child , frontier ) Avoid
else if child .S TAT E is in frontier with higher PAT H -C OST then higher-cost
replace that frontier node with child frontier nodes
Figure 3.14 Uniform-cost search on a graph. The algorithm is identical to the general
graph search algorithm in Figure 3.7, except for the use of a priority queue and the addition of an
extra check in case a shorter path to a frontier state is discovered. The data structure for frontier
needs to support efficient membership testing, so it should combine the capabilities of a priority
queue and a hash table.
These three statements change tree search to graph search.
Uniform-cost search
Proof of Completeness:
Assume (1) finite max branching factor = b; (2) min step cost ≥
ε > 0; (3) cost to optimal goal = C*. Then a node at depth
1+C*/ε must have a path cost > C*. There are
O( b^( 1+C*/ε ) such nodes, so a goal will be found.
A B C
g=1 g=5 g=15
(Search tree version)
This early A B C
expensive goal g=1 g=5 g=15
node will go
back onto the G
queue until after g=11
the later
cheaper goal is
found.
(Search tree version)
A B C
g=1 g=5 g=15
G G
g=11 g=10
A B C
g=1 g=5 g=15
G G
g=11 g=10
Expanded:
Next:
Children:
Queue: S/g=0
(Virtual queue version)
Expanded: S/g=0
Next: S/g=0
Children: A/g=1, B/g=5, C/g=15
Queue: S/g=0, A/g=1, B/g=5, C/g=15
(Virtual queue version)
2 4 8
S B E G
1 20
C
The graph above shows the step-costs for different paths going from the start (S) to
the goal (G).
Use uniform cost search to find the optimal path to the goal.
D
...
G is the only goal node
in the search space. No return from this branch.
G will never be popped.
Iterative Deepening Search
• To avoid the infinite depth problem of DFS:
– Only search until depth L
– i.e, don’t expand nodes beyond depth L
– Depth-Limited Search
Goal test in
recursive call,
one-at-a-time
• For b = 10, d = 5,
– NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
– NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450
[ Ratio: b/(b-1) ]
Properties of iterative deepening search
• Complete? Yes
• Time? O(bd)
• Space? O(bd)
• Optimal? No, for general cost functions.
Yes, if cost is a non-decreasing function only of
depth.
B C
• Complete? No: fails in loops/infinite-depth spaces
– Can modify to avoid loops/repeated states along path
• check if current nodes occurred before on path to root
– Can use graph search (remember all nodes ever seen)
• problem with graph search: space is exponential, not linear
– Still fails in infinite-depth spaces (may miss goal entirely)
• Complexity
– time complexity is best: O(2 b(d/2)) = O(b (d/2))
– memory complexity is the same as time complexity
Bi-Directional Search
Bidirectional search termination
• R&N Sec. 3.4.6 discusses the BDS termination condition for BFS.
– To clarify it, and to handle UCS:
• For BFS, the search terminates when one fringe expands a node and discovers
that one of the new children is present in the other fringe. This is quick and
easy because the other fringe already maintains a hash table holding its fringe,
as discussed in the lecture slides about removing duplicate nodes from the
fringe, so you just look up the new child in the other fringe's hash table. If
present, then you join the path from the Start to that child to the reverse of
the path from the Goal to that child, and you have your path from Start to
Goal. The first such solution found may not be optimal; some additional search
is required to make sure there isn’t a short-cut across the gap.
• For UCS, the same applies, except that afterward you must continue searching
until the sum of the costs of the nodes at the head of each queue is greater
than or equal to the cost of the path you just found. This continuation
guarantees that there is not a longer cheaper path somewhere in the queues.
Of course, if you find a cheaper solution as the search winds down, it replaces
the previous solution.
Summary of algorithms
Criterion Breadth- Uniform- Depth- Depth- Iterative Bidirectional
First Cost First Limited Deepening (if applicable)
DLS
Complete? Yes[a] Yes[a,b] No No Yes[a] Yes[a,d]
Time O(bd) O(b1+C*/ε) O(bm) O(bl) O(bd) O(bd/2)
Space O(bd) O(b1+C*/ε) O(bm) O(bl) O(bd) O(bd/2)
Optimal? Yes[c] Yes No No Yes[c] Yes[c,d]
http://www.cs.rmit.edu.au/AI-Search/Product/
http://aima.cs.berkeley.edu/demos.html (for more demos)