CS 188: Artificil Intelligence Spring 2007 Lecture 3: Queue-Bsed Serch 1/23/2007 Srini Nrynn UC Berkeley Mny slides over the course dpted from Dn Klein, Sturt Russell or Andrew Moore
Announcements Assignment 1 due 1/30 11:59 PM You cn do most of it fter tody Sections strt this week Sty tuned for Python Lb
Summry Agents interct with environments through ctutors nd sensors The gent function describes wht the gent does in ll circumstnces The gent progrm clcultes the gent function The performnce mesure evlutes the environment sequence A perfectly rtionl gent mximizes expected performnce PEAS descriptions define tsk environments Environments re ctegorized long severl dimensions: Observble? Deterministic? Episodic? Sttic? Discrete? Singlegent? Problem-solving gents mke pln, then execute it Stte spce encodings of problems
Problem-Solving Agents This is the hrd prt! This offline problem solving! Solution is executed eyes closed.
Tree Serch Bsic solution method for grph problems Offline simulted explortion of stte spce Serching model of the spce, not the rel world
A Serch Tree Serch: Expnd out possible plns Mintin fringe of unexpnded plns Try to expnd s few tree nodes s possible
Tree Serch
Generl Tree Serch Importnt ides: Fringe Expnsion Explortion strtegy Min question: which fringe nodes to explore?
Serch Nodes vs. Sttes 8 2 3 4 7 5 1 6 8 2 7 3 4 5 1 6 8 2 3 4 7 5 1 6 8 2 3 4 7 5 1 6 8 4 2 3 7 5 1 6 8 2 3 4 7 5 1 6
Serch Nodes vs. Sttes 8 2 3 4 7 5 1 6 8 2 7 3 4 5 1 6 If sttes re llowed to be revisited, the serch tree my be infinite even when the stte spce is finite 8 2 3 4 7 5 1 6 8 2 3 4 7 5 1 6 8 4 2 3 7 5 1 6 8 2 3 4 7 5 1 6
Sttes vs. Nodes Problem grphs hve problem sttes Hve successors Serch trees hve serch nodes Hve prents, children, depth, pth cost, etc. Expnd uses successor function to crete new serch tree nodes The sme problem stte my be in multiple serch tree nodes
Uninformed serch strtegies (.k.. blind serch) = use only informtion vilble in problem definition. When strtegies cn determine whether one nongol stte is better thn nother informed serch. Ctegories defined by expnsion lgorithm: Bredth-first serch Depth-first serch (Depth-limited serch) Itertive deepening serch Uniform-cost serch Bidirectionl serch
Stte Spce Grphs There s some big grph in which Ech stte is node Ech successor is n outgoing rc Importnt: For most problems we could never ctully build this grph S b p d q c h e r f G How mny sttes in 8- puzzle? Lughbly tiny serch grph for tiny serch problem
Exmple: Romni
Exmple: Tree Serch b c G S d h e f p q r
Stte Grphs vs Serch Trees S b d c h e f G Ech NODE in in the serch tree is n entire PATH in the problem grph. p q r S d e p We lmost lwys construct both on demnd nd we construct s little s possible. b c p h e q r f h r p q f q c G q q c G
Review: Depth First Serch S b d p c e p h f r q q c G q e p h f r q q c G S G d b p q c e h f r q p h f d b c e r Strtegy: expnd deepest node first Implementtion: Fringe is LIFO stck
Review: Bredth First Serch Strtegy: expnd shllowest node first Implementtion: Fringe is FIFO queue S b p d q c h e r f G S Serch Tiers b d c h e r p h q e r f p q p q f q c G q c G
Serch Algorithm Properties Complete? Gurnteed to find solution if one exists? Optiml? Gurnteed to find the lest cost pth? Time complexity? Spce complexity? Vribles: n b C* s m Number of sttes in the problem The verge brnching fctor B (the verge number of successors) Cost of lest cost solution Depth of the shllowest solution Mx depth of the serch tree
DFS Algorithm DFS Depth First Serch Complete Optiml Time Spce N O(B LMAX ) O(LMAX) N N N Infinite Infinite b START GOAL Infinite pths mke DFS incomplete How cn we fix this?
DFS With cycle checking, DFS is complete. m tiers b 1 node b nodes b 2 nodes b m nodes Algorithm DFS w/ Pth Checking Complete Optiml Time Spce Y N O(b m ) O(bm) When is DFS optiml?
BFS Algorithm DFS BFS w/ Pth Checking Complete Optiml Time Spce Y N O(b m ) O(bm) Y N* O(b s+1 ) O(b s+1 ) s tiers b 1 node b nodes b 2 nodes b s nodes b m nodes When is BFS optiml?
Comprisons When will BFS outperform DFS? When will DFS outperform BFS?
Costs on Actions b 2 3 1 d 2 c 3 8 2 e 9 8 2 GOAL 2 f START 1 p 4 15 q 4 h r 1 Notice tht BFS finds the shortest pth in terms of number of trnsitions. It does not find the lest-cost pth. We will quickly cover n lgorithm which does find the lest-cost pth.
Uniform Cost Serch Expnd chepest node first: Fringe is priority queue 2 b 1 3 S 1 p d 15 8 9 q 2 c h e 8 1 r G 2 f 1 S 0 d 3 e 9 p 1 Cost contours b 4 6 c 11 h p e 13 q 5 r f 7 8 h p 17 r 11 q f q c G q 16 q 11 c G 10
Priority Queue Refresher A priority queue is dt structure in which you cn insert nd retrieve (key, vlue) pirs with the following opertions: pq.push(key, vlue) pq.pop() inserts (key, vlue) into the queue. returns the key with the lowest vlue, nd removes it from the queue. You cn promote or demote keys by resetting their priorities Unlike regulr queue, insertions into priority queue re not constnt time, usully O(log n) We ll need priority queues for most cost-sensitive serch methods.
Uniform Cost Serch Wht will UCS do for this grph? 0 b START 1 0 1 GOAL Wht does this men for completeness?
Uniform Cost Serch Algorithm DFS BFS UCS w/ Pth Checking Complete Optiml Time Spce Y N O(b m ) O(bm) Y N O(b s+1 ) O(b s+1 ) Y* Y O(b C*/ε ) O(b C*/ε ) C*/ε tiers b We ll tlk more bout uniform cost serch s filure cses lter
Uniform Cost Problems Remember: explores incresing cost contours The good: UCS is complete nd optiml! c 1 c 2 c 3 The bd: Explores options in every direction No informtion bout gol loction Strt Gol
Depth-limited serch depth-first serch with depth limit l, i.e., nodes t depth l hve no successors Recursive implementtion:
Itertive deepening serch
Itertive deepening serch l =0
Itertive deepening serch l =1
Itertive deepening serch l =2
Itertive deepening serch l =3
Itertive deepening serch Number of nodes generted in depth-limited serch to depth d with brnching fctor b: N DLS = b 0 + b 1 + b 2 + + b d-2 + b d-1 + b d Number of nodes generted in n itertive deepening serch to depth d with brnching fctor b: N IDS = (d+1)b 0 + d b^1 + (d-1)b^2 + + 3b d-2 +2b d-1 + 1b d For b = 10, d = 5, N DLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111 N IDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456 Overhed = (123,456-111,111)/111,111 = 11%
Itertive Deepening Itertive deepening uses DFS s subroutine: 1. Do DFS which only serches for pths of length 1 or less. (DFS gives up on ny pth of length 2) 2. If 1 filed, do DFS which only serches pths of length 2 or less. 3. If 2 filed, do DFS which only serches pths of length 3 or less..nd so on. b Algorithm DFS BFS ID w/ Pth Checking Complete Optiml Time Spce Y N O(b m ) O(bm) Y N* O(b s+1 ) O(b s+1 ) Y N* O(b d ) O(bd)
Summry of lgorithms
Extr Work? Filure to detect repeted sttes cn cuse exponentilly more work. Why?
Grph Serch In BFS, for exmple, we shouldn t bother expnding the circled nodes (why?) S d e p b c e h r q h r p q f p q f q c G q c G
Grph Serch Very simple fix: never expnd node twice Cn this wreck correctness? Why or why not?
Serch Gone Wrong?