uninformed search - csc 411: ai spring 2013 -...
TRANSCRIPT
Uninformed SearchCSC 411: AISpring 2013
NC State University 1 / 29Uninformed Search
Formulating a problem
Any lessons we can learn?
• States are abstractions of real-world configurations.• Actions can be abstract but should be executable.• Solutions should be feasible.• Costs should be meaningful.
NC State University 2 / 29Uninformed Search
Searching for solutions
We formulate a problem in order to solve it.
How do we approach problem solving? Search (for now).
Search is about considering a set of possibilities, choosingone, and putting aside the rest for later, in case the chosenoption doesn’t work out.
NC State University 3 / 29Uninformed Search
Search algorithms
We traverse a state space by generating successors ofalready-explored states.
This generates a search tree or search graph.
(I’m going to be sloppy about distinguishing the two, sothat we don’t have to worry as much about bookkeeping.)
NC State University 4 / 29Uninformed Search
Search code
Roughly speaking. . .
SEARCH(problem)
initialize a frontier using initial state of problemwhile true
if no candidates for expansionreturn failure
choose a frontier elementif it corresponds to a goal state
return that goal stateelse expand it and add results to frontier
NC State University 5 / 29Uninformed Search
The functions we need to define
1 INITIAL-STATE(p) produces a state.2 ACTIONS(s) produces a list of actions.3 RESULT(s, a) produces a successor state.4 GOAL?(s) is Boolean test.5 STEP-COST(s1, a, s2) produces a quantity.
NC State University 6 / 29Uninformed Search
States versus nodes
A state is an abstract representation of a “physical”configuration.
A node is a data structure:
• n.State: A state.• n.Parent: A node.• n.Action: Action applied to n.Parent to generate n.• n.Cost, also g(n): The cost of the path from the
initial state to n.
NC State University 7 / 29Uninformed Search
Search code
EXPAND(p, node)successors = φfor action, result in SUCC(p, node.state)
sn = new successor nodesn.Parent = nodesn.Action = actionsn.State = resultsn.Cost = node.Cost + STEP-COST(node, action, sn)sn.depth = node.depth + 1successors = Insert(sn, successors)
return successors
NC State University 8 / 29Uninformed Search
More sloppiness
In pseudocode I’ll assume that nodes are generated suchthat they point to a problem: We can expand a nodewithout reference to a problem (EXPAND), and we can askwhether a node is a goal (GOAL?).
I’ll further assume that every search algorithm is passedeither
node = NODE(INITIAL-STATE(p))
or fringe, a frontier containing just that node.
NC State University 9 / 29Uninformed Search
Search code
SEARCH(fringe)while true
if Empty?(fringe)return failure
node = Pop(fringe)if GOAL?(node)
return nodeelse fringe = COMBINE(EXPAND(node), fringe)
NC State University 10 / 29Uninformed Search
Search code
Or if you like recursion and higher-order functions. . .
SEARCH(fringe, combiner-fn)if Empty?(fringe)
return failurenode = First(fringe)if GOAL?(node)
return nodeSEARCH(combiner-fn(EXPAND(node), Rest(fringe)))
NC State University 11 / 29Uninformed Search
Search strategies
A search strategy picks the order of node expansion.Strategies are evaluated along the following dimensions:
• Completeness: Does it find a solution if one exists?• Time complexity: Number of nodes generated.• Space complexity: Maximum nodes in memory.• Optimality: Does it find a least-cost solution?
Time and space complexity are measured in terms of
• b: maximum branching factor of the search tree.• d: depth of the least-cost solution.• m: maximum depth of the state space.
NC State University 12 / 29Uninformed Search
Uninformed search strategies
Uninformed search strategies use only the informationavailable in the problem definition.
• Breadth-first search• Uniform-cost search• Depth-first search• Depth-limited search• Iterative deepening search
NC State University 13 / 29Uninformed Search
Breadth-first search
Strategy: Expand the shallowest unexpanded node.
Typical implementation: Maintain fringe as a FIFOqueue, with new successors going at the end.
BFS(fringe). . .
fringe = BFS-COMBINE(EXPAND(node), fringe)
BFS-COMBINE(new-nodes, fringe)return Concatenate(fringe, new-nodes)
NC State University 14 / 29Uninformed Search
Properties of breadth-first search
Complete: Yes, if b is finite.
Time: 1 + b + b2 + . . .+ bd + b(bd − 1) = O(bd+1).
Space: O(bd+1). (Why?)
Optimal: Yes, if cost = 1 per step.
Space is a bigger problem than time.
NC State University 15 / 29Uninformed Search
Properties of breadth-first search
Complete: Yes, if b is finite.
Time: 1 + b + b2 + . . .+ bd + b(bd − 1) = O(bd+1).
Space: O(bd+1). (Why?)
Optimal: Yes, if cost = 1 per step.
Space is a bigger problem than time.
NC State University 16 / 29Uninformed Search
Uniform-cost search
Strategy: Expand the least-cost unexpanded node.
Typical implementation: Maintain fringe as a queueordered by path cost.
UCS(fringe). . .
fringe = UCS-COMBINE(EXPAND(node), fringe)
UCS-COMBINE(new-nodes, fringe)return Sort(Concatenate(new-nodes, fringe),
Lambda(n1, n2) n1.Cost ≤ n2.Cost)
NC State University 17 / 29Uninformed Search
Properties of uniform-cost search
Complete: Yes, if STEP-COST ≥ ε.
Time: Number of nodes with node.Cost ≤ C∗, the cost ofthe optimal solution: O
(bd
C∗ε e
).
Space: Number of nodes with node.Cost ≤ C∗,O(
bdC∗ε e
).
Optimal: Yes. Nodes are expanded in increasing order ofPATH-COST.
NC State University 18 / 29Uninformed Search
Depth-first search
Strategy: Expand the deepest unexpanded node.
Typical implementation: Maintain fringe as a stack, withsuccessors at the front.
DFS(fringe). . .
fringe = DFS-COMBINE(EXPAND(node), fringe)
DFS-COMBINE(new-nodes, fringe)return Concatenate(fringe, new-nodes)
NC State University 19 / 29Uninformed Search
Properties of depth-first search
Complete: No. It fails in infinite-depth spaces or spaceswith loops.
Time: O(bm). (Terrible if m is much larger than d, but ifsolutions are dense, DFS may be much faster than BFS.)
Space: O(bm).
Optimal: No.
NC State University 20 / 29Uninformed Search
Properties of depth-first search
Complete: No. It fails in infinite-depth spaces or spaceswith loops.
Time: O(bm). (Terrible if m is much larger than d, but ifsolutions are dense, DFS may be much faster than BFS.)
Space: O(bm).
Optimal: No.
NC State University 21 / 29Uninformed Search
Thought question
DFS takes only linear space, which is great.
How could we improve it to avoid the issue of not beingcomplete?
NC State University 22 / 29Uninformed Search
Depth-first search, revisited
DFS(node)if GOAL?(node)
return nodeelse for successor in EXPAND(node)
result = DFS(successor)if result 6= Failure return result
return Failure
NC State University 23 / 29Uninformed Search
Depth-limited searchDLS(node, limit)
if GOAL?(node) return nodeelse if limit is 0 return Cutoffelsecutoff ? = Falsefor successor in EXPAND(node)
result = DLS(successor, limit − 1)if result is Cutoff
cutoff ? = Trueelse if result is not Failure return result
if cutoff ?return Cutoff
else return Failure
NC State University 24 / 29Uninformed Search
Iterative deepening search
ITERATIVE-DEEPENING-SEARCH(node)for depth = 0 to∞
result = DLS(node, depth)if result 6= Cutoff return result
NC State University 25 / 29Uninformed Search
Iterative deepening search
Nodes generated in IDS:
NIDS = (d)b1 + (d − 1)b2 + . . .+ (1)bd
For b = 10, d = 5,
NIDS = 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 450
NBFS = 10 + 100 + 1, 000 + 10, 000 + 100, 000 = 111, 110
Time overhead: 11%
NC State University 26 / 29Uninformed Search
Properties of iterative deepening search
Complete: Yes.
Time: db + . . .+ bd = O(bd).
Space: O(bd).
Optimal. Yes, if STEP-COST is constant.
NC State University 27 / 29Uninformed Search
Properties of search algorithmsBFS UCS DFS DLS IDS
Complete yes yes no no yes
Time O(bd+1)∗ O(
bdC∗ε e
)O(bm) O(bl) O(bd)
Space O(bd+1)∗ O(
bdC∗ε e
)O(bm) O(bl) O(bd)
Optimal yes yes no no yes
NC State University 28 / 29Uninformed Search
Summary
• Problem formulation usually requires abstractingaway real-world details to define a state space thatcan feasibly be explored.
• We have many uninformed search strategies.• Subtle changes to search algorithms can produce
surprising improvements to performance.
NC State University 29 / 29Uninformed Search