Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence Winter 2016 1
Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl component to mny AI systems - Automted resoning, theorem proving, root nvigtion, scheduling, gme plying,... 2
Serch Prolems A serch prolem consists of stte spce successor function (ctions, cost) (N, 1.0) (E, 1.0) strt stte nd gol test A solution is sequence of ctions (pln) from the strt stte to gol stte 3
Exmple: Trveling in Romni Strt Sttes: Initil Stte: Successor Function: Gol test: Solution: End 4
Exmples of Serch Prolems Sttes: Initil Stte: Successor Function: Gol test: Solution: Sttes: Initil Stte: Successor Function: Gol test: Solution: 5
Exmples of Serch Prolems 6
Our Definition Excludes... Chnce Continuous sttes Adversries Prtil Oservility All of the ove 7
Wht is is stte spce? The world stte includes every lst detil of the environment A serch stte keeps only the detils needed for plnning (strction) Prolem: Pthing Sttes: (x,y) loction Actions: NSEW Successor: updte loction only Gol test: is (x,y)=end Prolem: Et-All-Dots Sttes: {(x,y), dot oolens} Actions: NSEW Successor: updte loction nd possily dot oolen Gol test: dots ll flse Adpted from UC Berkeley s CS188 Course 8
Representing Serch Stte spce grph - - - Vertices correspond to sttes (one vertex for ech stte) Edges correspond to successors Gol test is set of gol nodes S p d q c h e r f G We serch for solution y uilding serch tree nd trversing it to find gol stte 9
Serch Tree A serch tree: Strt stte is the root of the tree Children re successors A pln is pth in the tree. A solution is pth from the root to gol node. For most prolems we do not ctully generte the entire tree S A A S B G B B G G 10 G
Quiz Given this stte grph, how lrge is the serch tree? A S G B 11
Expnding Nodes Expnding node - Applying ll legl opertors to the stte contined in the node - Generting nodes for ll corresponding successor sttes 12
Exmple: Trveling in Romni Strt End 13
Expnding Nodes 14
Generic Serch Algorithm Initilize with initil stte of the prolem Repet - If no cndidte nodes cn e expnded return filure - Choose lef node for expnsion, ccording to serch strtegy - - If node contins gol stte, return solution Otherwise, expnd the node. Add resulting nodes to the tree 15
Implementtion Detils Need to keep trck of nodes to e expnded (fringe) Implement using queue: - Insert node for initil stte - Repet - If queue is empty, return filure - Dequeue node - If node contins gol stte, return solution - Expnd node Serch lgorithms differ in their queuing function! 16
Serch Strtegies G c d e f S h p q r 17 Adpted from UC Berkeley s CS188 Course
Serch Strtegies S d e p c e h r q h r p q f p q f q c G q c G 18
Depth-First Serch S G d p q c e h f r S d p c e p h f r q q c G q e p h f r q q c G Strtegy: Expnd deepest node first Implementtion: LIFO stck 19
Key Properties Completeness: Is the lg. gurnteed to find solution if the solution exists? Optimlity: Does the lg. find the optiml solution? Time complexity Spce complexity (size of the fringe) m tiers : rnching fctor m: mximum depth d: depth of shllowest gol node 1 node nodes 2 nodes m nodes Numer of nodes in tree? 1++ 2 + + m =O( m ) 20
DFS Properties Complete? No! m could e infinite (why?) Optiml? No! It finds leftmost solution first, regrdless of cost or depth Time complexity It could process the entire tree! Therefore O( m ) m tiers 1 node nodes 2 nodes Spce complexity Only hs silings on pth to root! Therefore O(m)! m nodes 21
Bredth-First Serch S G d p q c e h f r S d p c e p h f r q q c G q e p h f r q q c G Strtegy: Expnd shllowest node first Implementtion: FIFO queue 22
BFS Properties Complete? Yes! d must e finite is solution exists Optiml? Mye! If costs re ll 1 Time complexity It could process the tree until it finds the shllowest gol! Therefore O( d ) m tiers 1 node nodes 2 nodes m nodes Spce complexity O(d ) 23
Quiz: DFS vs BFS 24
Itertive Deepening Serch Cn we comine serch methods to tke dvntge of DFS spce complexity nd BFS completeness/ shllow solution dvntge? 25
IDS Properties Complete? Yes! d must e finite is solution exists (like BFS) Optiml? Mye! If costs re ll 1 Time complexity It could process the tree until it finds the shllowest gol! Therefore O( d ) Spce complexity O(d) m tiers 1 node nodes 2 nodes m nodes Wsteful? Most nodes found in lowest level of serch so not too d 26
Cost-Sensitive Serch 2 2 GOAL 1 8 c 3 2 3 d 2 e 9 8 2 f START 1 4 h 2 p 15 q 4 r Recll tht BFS ws only optiml under some conditions (i.e. we only cred out numer of ctions tken). Wht cn we do if ctions hve different costs? 27
Uniform Cost Serch Strtegy: Expnd chepest node first Implementtion: Priority queue 2 2 GOAL 3 1 d c 3 8 2 e 9 8 2 f 2 START 1 p 4 15 q 4 h r 2 28
UCS Properties Complete? Yes! (ssuming min cost is positive nd est solution hs finite cost) Optiml? Yes! Time complexity Processes ll nodes with cost less thn chepest solution If chepest solution cost C* nd edges cost t lest ε then depth is pproximtely C*/ε. Thus time O( C*/ ε ) Spce complexity C*/ε tiers O(C*/ ε ) 29
Summry These lgorithms re siclly the sme except for the order in which they expnd nodes Bsiclly ll priority queues with different wys to determining priorities How successful the serch is depends hevily on your model! 30
Questions? Next clss: Informed serch 31