Lecture 4 Wht re common serch strtegies tht operte given only serch problem? How do they compre? 1
Agend A quick refresher DFS, BFS, ID-DFS, UCS Unifiction! 2
Serch Problem Formlism Defined vi the following components: The initil stte the gent strts in A successor/trnsition function S(x) = {ction+cost->stte} A gol test, which determines whether given stte is gol stte A pth cost tht ssigns numeric cost to ech pth A solution is sequence of ctions leding from initil stte to gol stte (optiml = lowest pth cost) Together the initil stte nd successor function implicitly define the stte spce, the set of ll rechble sttes 3
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 node(s) In serch grph, ech stte occurs only once! We cn rrely build this full grph in memory (i.e. it s too big), but it s useful ide S b p d q c h e r f G 4
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 N, 1.0 E, 1.0 5
Serching for Solutions Bsic ide: incrementlly build serch tree until gol stte is found Root = initil stte Expnd vi trnsition function to crete new nodes Nodes tht hven t been expnded re lef nodes nd form the frontier (open list) Different serch strtegies choose next node to expnd (s few s possible!) Use closed list to prevent expnding the sme stte more thn once 6
Generl Algorithm Queue (FIFO) Stck (LIFO) Priority Queue 7
Evluting Serch Strtegy Solution Completeness: does it lwys find solution if one exists? Efficiency Time Complexity: number of nodes generted/expnded Optimlity: does it lwys find lest-cost solution? Spce Complexity: mximum number of nodes in memory 8
Depth-First Serch (DFS) 9
DFS Exmple 10 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
Let s Evlute! 11
Serch Tree Properties Brnching fctor Mximum depth m tiers b 1 node b nodes b 2 nodes Solutions t vrious depths b m nodes Number of nodes in the tree? 1 + b + b 2 +. b m = O(?) b m 12
DFS Evlution Time Expnds left Could be whole tree! Assuming finite depth, O(b m ) m tiers b 1 node b nodes b 2 nodes Spce Only siblings on pth, O(bm) Complete Only if finite b m nodes Optiml No, left-most w/o regrd to cost/depth 13
Bredth-First Serch (BFS) 14
BFS Exmple 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 15
BFS Evlution Time Processes ll nodes bove shllowest solution, O(b s ) s tiers b 1 node b nodes b 2 nodes Spce Hs roughly the lst tier, so O(b s ) Complete Yes! b s nodes b m nodes Optiml Only if ll costs equl (more lter) 16
DFS vs. BFS Empty-DFS Empty-BFS Mze-DFS Mze-BFS 17
Grounding the Brnching Fctor Depth Nodes Time Memory 2 110 0.11 msecs 107 KB 4 11,110 11 msecs 10.6 MB 6 10 6 1.1 secs 1 GB 8 10 8 2 mins 103 GB 10 10 10 3 hours 10 TB 12 10 12 13 dys 1 PB 14 10 14 3.5 yers 99 PB 16 10 16 350 yers 10 EB Assumptions b = 10 1 million nodes/second 1000 bytes/node Memory often becomes the limiting fctor 18
Itertive Deepening DFS (ID-DFS) Bsic ide: DFS memory with BFS time/shllow solution DFS up to 1 DFS up to 2. Generlly most work hppens in the lowest level serched, so not too wsteful b 19
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, but it does not find the lest-cost pth. We will now cover similr lgorithm which does! 20
Uniform-Cost Serch (UCS) 21
UCS Exmple Strtegy: expnd chepest node first Fringe is priority queue (priority: cumultive cost) S 1 b 3 S 2 p 1 0 d 15 8 9 q 2 c h e 8 2 r G 2 f 1 Cost contours b 4 6 d c 3 e 9 e 5 h 17 r 11 11 h 13 r 7 p q f p q f 8 q c G p q 1 16 q 11 c G 10 22
UCS Evlution Time O(b C*/ε ) Spce O(b C*/ε ) C*/e tiers (effective depth) b c 1 c 2 c 3 Complete Yes! Optiml Yes! Assume optiml solution costs C* nd rcs cost t lest ε 23
UCS vs. DFS vs. BFS UCS is good nd optiml However, it still moves in every direction it s not informed bout gol direction Empty-UCS Mze-UCS MzeCost-DFS c 1 c 2 c 3 Strt Gol MzeCost-BFS MzeCost-UCS 24
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) Prcticlly, for DFS nd BFS, you cn void the log(n) overhed from n ctul priority queue, by using stcks nd queues Unifiction 25
Serch given only the problem definition DFS BFS UCS Fringe LIFO (stck) FIFO (queue) PQ (pth cost) Complete X X Optiml X Time O(b % ) O(b ' ) O(b ( /+ ) Spce O(bm) O(b ' ) O(b ( /+ ) Assumptions: potentilly infinite depth, rbitrry positive ction costs 26
Serch opertes over models of the world The gent doesn t ctully try ll the plns out in the rel world! Plnning is ll in simultion Your serch is only s good s your models A Reminder 27
Serch Gone Wrong 28
Summry We evluted severl uninformed strtegies to solve serch problem DFS, BFS, ID-DFS, UCS DFS, BFS, nd UCS cn ll be implemented vi generic grph-serch lgorithm over serch tree by simply chnging how the fringe is orgnized 29