slide 1
CS540 Uninformed Search
Yingyu Liang yliang@cs.wisc.edu Computer Sciences Department University of Wisconsin, Madison
CS540 Uninformed Search Yingyu Liang yliang@cs.wisc.edu Computer - - PowerPoint PPT Presentation
CS540 Uninformed Search Yingyu Liang yliang@cs.wisc.edu Computer Sciences Department University of Wisconsin, Madison slide 1 Main messages Many AI problems can be formulated as search. Iterative deepening is good when you don t
slide 1
Yingyu Liang yliang@cs.wisc.edu Computer Sciences Department University of Wisconsin, Madison
slide 2
much.
slide 3
slide 4
http://xkcd.com/1134/
slide 5
▪ Where’s the boat?
▪ succs((CSDF,)) = {(CD, SF)} ▪ succs((CDF,S)) = {(CD,FS), (D,CFS), (C, DFS)}
in I to a state in G. ▪ Optionally minimize the cost of the solution. C S D F
slide 6
slide 7
empty (to ground or other jug)
slide 8
slide 9
slide 10
expanded states at any given time
CSDF, CD,SF CDF, S D, CFS C, DSF DFS, C CSF, D S, CFD SF, CD , CSDF
C S D F start goal
slide 11
fringe (OPEN).
CSDF, CD,SF CDF, S D, CFS C, DSF DFS, C CSF, D S, CFD SF, CD , CSDF
slide 12
– The goal test – The succs() function
be informed search (next lecture).
▪ Won’t encounter repeated states. ▪ We will relax it later.
slide 13
Expand the shallowest node first
ripple
g
l
slide 14
Use a queue (First-in First-out)
s = de_queue()
if (s==goal) success!
en_queue(T)
slide 15
s = de_queue()
if (s==goal) success!
en_queue(T)
slide 16
s = de_queue()
if (s==goal) success!
en_queue(T)
slide 17
s = de_queue()
if (s==goal) success!
en_queue(T)
slide 18
queue (fringe , OPEN) [GFED] C If G is a goal, we've seen it, but we don't stop! Use a queue (First-in First-out)
s = de_queue()
if (s==goal) success!
en_queue(T)
slide 19
Use a queue (First-in First-out)
queue [] G ... until much later we pop G. We need back pointers to recover the solution path. Looking stupid?
slide 20
▪ the graph may be infinite. ▪ Goal(s) exists and is only finite steps away.
▪ # states generated ▪ Goal d edges away ▪ Branching factor b
▪ # states stored
g
l
slide 21
Four measures of search algorithms:
find a goal.
positive non-decreasing in depth), no otherwise.
▪ Back pointers for all generated nodes O(bd) ▪ The queue / fringe (smaller, but still O(bd))
slide 22
g
l
slide 23
O(bd) O(bd) Y, if 1 Y Breadth-first search space time
Complete
b: branching factor (assume finite) d: goal depth
slide 24
Four measures of search algorithms:
find a goal.
positive non-decreasing with depth), no otherwise.
▪ Back points for all generated nodes O(bd) ▪ The queue (smaller, but still O(bd)) Solution: Uniform-cost search
slide 25
costs along the path). Expand the least cost node first.
▪ Always take out the least cost item ▪ Remember heap? time O(log(#items in heap))
* Complications on graphs (instead of trees). Later.
slide 26
▪ Let C* be the cost of the least-cost goal ▪ O(bC*/ ), possibly C*/ >> d all edges except this one
g
l
C*
slide 27
O(bC*/) O(bC*/) Y Y Uniform-cost search2 O(bd) O(bd) Y, if 1 Y Breadth-first search space time
Complete 1. edge cost constant, or positive non-decreasing in depth
b: branching factor (assume finite) d: goal depth
slide 28
function general-search(problem, QUEUEING-FUNCTION) ;; problem describes the start state, operators, goal test, and ;; operator costs ;; queueing-function is a comparator function that ranks two states ;; general-search returns either a goal node or "failure" nodes = MAKE-QUEUE(MAKE-NODE(problem.INITIAL-STATE)) loop if EMPTY(nodes) then return "failure" node = REMOVE-FRONT(nodes) if problem.GOAL-TEST(node.STATE) succeeds then return node nodes = QUEUEING-FUNCTION(nodes, EXPAND(node, problem.OPERATORS)) ;; succ(s)=EXPAND(s, OPERATORS) ;; Note: The goal test is NOT done when nodes are generated ;; Note: This algorithm does not detect loops end
slide 29
Four measures of search algorithms:
find a goal.
positive non-decreasing with depth), no otherwise.
▪ Back points for all generated nodes O(bd) ▪ The queue (smaller, but still O(bd)) Solution: Depth-first search Solution: Uniform-cost search
slide 30
Expand the deepest node first
fan
g
l
slide 31
Use a stack (First-in Last-out)
s = pop()
if (s==goal) success!
push(T)
slide 32
(Space complexity)
g
l
c.f. BFS O(bd)
slide 33
complexity O(bm)
g
l
c.f. BFS O(bd)
g
l g
l
slide 34
O(bm) O(bm) N N Depth-first search O(bC*/) O(bC*/) Y Y Uniform-cost search2 O(bd) O(bd) Y, if 1 Y Breadth-first search space time
Complete 1. edge cost constant, or positive non-decreasing in depth
b: branching factor (assume finite) d: goal depth m: graph depth
slide 35
fan within ripple
g
l g
l g
l
slide 36
▪ Complete, optimal like BFS ▪ Small space complexity like DFS
▪ Each deepening repeats DFS from the beginning ▪ No! db+(d-1)b2+(d-2)b3+…+bd ~ O(bd) ▪ Time complexity like BFS
slide 37
O(bm) O(bm) N N Depth-first search O(bC*/) O(bC*/) Y Y Uniform-cost search2 O(bd) O(bd) Y, if 1 Y Breadth-first search O(bd) O(bd) Y, if 1 Y Iterative deepening space time
Complete 1. edge cost constant, or positive non-decreasing in depth
b: branching factor (assume finite) d: goal depth m: graph depth
slide 38
O(bm) O(bm) N N Depth-first search O(bC*/) O(bC*/) Y Y Uniform-cost search2 O(bd) O(bd) Y, if 1 Y Breadth-first search O(bd) O(bd) Y, if 1 Y Iterative deepening space time
Complete 1. edge cost constant, or positive non-decreasing in depth
b: branching factor (assume finite) d: goal depth m: graph depth
slide 39
s t a r t
g
l
slide 40
s t a r t g
l
▪ The fringes are O(bd/2) ▪ How do you start from the 8-queens goals?
slide 41
O(bm) O(bm) N N Depth-first search O(bC*/) O(bC*/) Y Y Uniform-cost search2 O(bd) O(bd) Y, if 1 Y Breadth-first search O(bd) O(bd) Y, if 1 Y Iterative deepening O(bd/2) O(bd/2) Y, if 1 Y Bidirectional search3 space time
Complete 1. edge cost constant, or positive non-decreasing in depth
b: branching factor (assume finite) d: goal depth m: graph depth
slide 42
CSDF, CD,SF CDF, S D, CFS C, DSF DFS, C CSF, D S, CFD SF, CD , CSDF
slide 43
(CLOSED).
slide 44
▪ Still O(bd) space complexity, not worse
▪ Known as Memorizing DFS (MEMDFS)
anywhere
▪ Alternative: Path Check DFS (PCDFS): remember
the current node)
slide 45
1.Maintain a “prefix” path from root to current node, initially empty. 2.Pop a state s. If s in prefix, skip to next pop 3.Goal-checking s. 4.s comes with a backpointer to its parent p. The prefix should contain p somewhere as in initial, ..., p, ... 5.Remove everything after p and put s there, so prefix is now initial, ..., p, s. 6.When you generate a successor t of s, check if t is in prefix or stack. If no, push t to the stack; if yes, do not push it.
slide 46
slide 47
Solution found: S A G
slide 48
slide 49
slide 50
slide 51
▪ Breadth-first search
▪ Depth-first search ▪ Iterative deepening ▪ Bidirectional search
same algorithm, with different priority functions?
▪ Completeness, optimality, time complexity, space complexity