DATA620006 魏忠钰 Serch I Mrch 7 th, 2018
Outline Serch Problems Uninformed Serch Depth-First Serch Bredth-First Serch Uniform-Cost Serch
Rel world tsk - Pc-mn
Serch problems A serch problem consists of: A stte spce A successor function (with ctions, costs) A strt stte A gol test
Serch Problems - Pc-mn A serch problem consists of: A stte spce A successor function (with ctions, costs) N, 1.0 A strt stte E, 1.0 A gol test Move to specific position
Rel world tsk : the 8-puzzle Strt Stte Gol Stte
Serch Problems: the 8-puzzle Stte spce Strt Stte integer loctions of 8 tiles. Successor function: Move blnk (up, down, right, left) Gol Stte
Rel Tsk: 8-Queens Puzzle Plce 8 queens on chessbord so tht no two queens ttck ech other. A queen ttcks ny piece in the sme row, column or digonl. 3 more queens missing
Serch Problem: 8-Queens Puzzle Stte spce: ny rrngement of 0 to 8 queens on bord Successor function: dd queen to ny squre Strt stte: blnk bord Gol test: 8 queens on bord, non ttcked
Rel world tsk : Trveling in Romni
Serch Problems: Trveling in Romni Stte spce Cities Successor function: Rods: Go to djcent city with cost = distnce Strt stte: Ard Gol test: Is stte == Buchrest?
Wht is in Stte Spce? The world stte includes every lst detil of the environment A serch stte keeps only the detils needed for plnning (bstrction) Problem: Pthing Sttes: (x,y) loction Actions: NSEW Successor: updte loction only Gol test: is (x,y)=end Problem: Et-All-Dots Sttes: {(x,y), dot boolens} Actions: NSEW Successor: updte loction nd possibly dot boolen Gol test: dots ll flse
Stte Spce Sizes? World stte: Bord blnks: 64 Queen number: 8 How mny World sttes? 64 8
Stte Spce Sizes? World stte: Agent positions: 120 Food count: 30 Ghost positions: 12 Agent fcing: NSEW How mny World sttes? 120x(2 30 )x(12 2 )x4 Sttes for pthing? 120 Sttes for et-ll-dots? 120x(2 30 )
Sfe Pssge Problem: et ll dots while keeping the ghosts perm-scred Wht does the stte spce hve to specify? (gent position, dot boolens, power dot boolens, remining scred time)
Stte Spce Grphs nd Serch Trees
Stte Spce Grph Stte spce grph: A mthemticl representtion of serch problem Nodes re (bstrcted) world configurtions Arcs represent successors (ction results) The gol test is set of gol nodes (mybe only one) In stte spce grph, ech stte occurs only once! We cn rrely build this full grph in memory (it s too big), but it s useful ide
Serch Trees This is now / strt N, 1.0 E, 1.0 Possible futures A serch tree: A wht if tree of plns nd their outcomes The strt stte is the root node Children correspond to successors Nodes show sttes, but correspond to PLANS tht chieve those sttes For most problems, we cn never ctully build the whole tree
Stte Spce Grphs vs. Serch Trees 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 Ech NODE in the serch tree is n entire PATH in the stte spce grph. Serch Tree Stte Spce Grph
Stte Spce Grphs vs. Serch Trees Consider this 4-stte grph: S G How big is its serch tree (from S)? b Importnt: Lots of repeted structure in the serch tree!
Tree Serch Uninformed Serch Depth-First Serch Bredth-First Serch Uniform-Cost Serch
Serch Exmple: Romni b c G S d h e f p q r
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
Serch Algorithm Properties Complete: Gurnteed to find solution if one exists? Optiml: Gurnteed to find the lest cost pth? Time complexity? Spce complexity? Crtoon of serch tree: b is the brnching fctor m is the mximum depth s is the solutions t vrious depths Number of nodes in entire tree? 1 + b + b 2 +. b m = O(b m ) m b 1 node b nodes b 2 nodes b m nodes
Depth-First Serch (DFS) Properties Wht nodes DFS expnd (Time Complexity)? Some left prefix of the tree. If m is finite, tkes time O(b m ) How much spce does the fringe tke (Spce Complexity)? Only hs siblings on pth to root, so O(bm) Is it complete? No, m cn be infinite m tiers b 1 node b nodes b 2 nodes Is it optiml? No, it finds the leftmost solution, regrdless of depth or cost b m nodes
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
Bredth-First Serch (BFS) Properties Wht nodes does BFS expnd (Time Complexity)? Processes ll nodes bove shllowest solution Let depth of shllowest solution be s Serch tkes time O(b s ) How much spce does the fringe tke? Hs roughly the lst tier, so O(b s ) Is it complete? yes Is it optiml? Yes (if the cost is equl per step) s tiers b 1 node b nodes b 2 nodes b s b m
DFS vs BFS When will BFS outperform DFS? The brnch fctor is reltively smll. The depth of the optiml solution is reltively shllow. When will DFS outperform BFS? The tree is deep nd the nswer is frequent.
Itertive Deepening Ide: get DFS s spce dvntge with BFS s time / shllow-solution dvntges Run DFS with depth limit 1. If no solution Run DFS with depth limit 2. If no solution Run DFS with depth limit 3... How mny nodes does BFS expnd? O(b d ) How much spce does the fringe tke? O(bd) Is it complete? yes! Is it optiml? Yes! (if the cost is equl per step) d b
Cost-Sensitive Serch 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 2 BFS finds the shortest pth in terms of number of ctions. It does not find the lest-cost pth. We will now cover similr lgorithm which does find the lest-cost pth.
Uniform Cost Serch Strtegy: expnd chepest node first: Fringe is priority queue (priority: cumultive cost) b 3 S 1 2 1 p d 15 8 9 q 2 c h e 8 2 r G 2 f 1 S 0 d 3 e 9 p 1 Cost contours Suppose C* = 10 nd e equls 3 b 4 6 c 11 e 5 h 13 r 7 p q f 8 q 11 c G 10 h 17 r 11 p q f q c G q 16
Uniform Cost Serch (UCS) Properties Wht nodes does UCS expnd? Processes ll nodes with cost less thn chepest solution! If tht solution costs C* nd rcs cost t lest e, then the effective depth is roughly C*/e Tkes time O(b C*/e ) (exponentil in effective depth) How much spce does the fringe tke? Hs roughly the lst tier, so O(b C*/e ) Is it complete? Assuming best solution hs finite cost nd minimum rc cost is positive, yes! C*/e tiers b c 1 c 2 c 3 Is it optiml? Yes!
Uniform Cost Issues Remember: UCS 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
Comprison Algorithm Complete? Optiml? Time? Spce? DFS N N O(b m ) O(bm) BFS Y Y O(b d ) O(b d ) IDS Y Y O(b d ) O(bd) UCS Y Y O(b C*/e ) O(b C*/e ) For BFS, Suppose the brnching fctor b is finite nd step costs re identicl;
How bd is BFS?
Dt structure LIFO stck FIFO queue Priority queue
Lst in First out Stck
FIFO queue
Priority queue
The One Queue All these serch lgorithms re the sme except for fringe strtegies Conceptully, ll fringes re priority queues (i.e. collections of nodes with ttched priorities) Cn even code one implementtion tht tkes vrible queuing object