02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH(...

59
Uninformed Search CS171, Fall 2016 Introduc;on to Ar;ficial Intelligence Prof. Alexander Ihler Reading: R&N 3.1-3.4

Transcript of 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH(...

Page 1: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

UninformedSearch

CS171,Fall2016Introduc;ontoAr;ficialIntelligence

Prof.AlexanderIhler Reading: R&N 3.1-3.4

Page 2: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Uninformedsearchstrategies•  Uninformed(blind):

–  Youhavenocluewhetheronenon-goalstateisbeKerthananyother.Yoursearchisblind.Youdon’tknowifyourcurrentexplora;onislikelytobefruiPul.

•  Variousblindstrategies:–  Breadth-firstsearch–  Uniform-costsearch–  Depth-firstsearch–  Itera;vedeepeningsearch(generallypreferred)–  Bidirec;onalsearch(preferredifapplicable)

Page 3: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Searchstrategyevalua;on•  Asearchstrategyisdefinedbytheorderofnodeexpansion

•  Strategiesareevaluatedalongthefollowingdimensions:–  completeness:doesitalwaysfindasolu;onifoneexists?–  ;mecomplexity:numberofnodesgenerated–  spacecomplexity:maximumnumberofnodesinmemory–  op;mality:doesitalwaysfindaleast-costsolu;on?

•  Timeandspacecomplexityaremeasuredintermsof–  b:maximumbranchingfactorofthesearchtree–  d:depthoftheleast-costsolu;on–  m:maximumdepthofthestatespace(maybe∞)–  (forUCS:C*:truecosttoop;malgoal;ε>0:minimumstepcost)

Page 4: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Uninformedsearchdesignchoices•  QueueforFron;er:

–  FIFO?LIFO?Priority?

•  Goal-Test:–  Dogoal-testwhennodeinsertedintoFron*er?–  Dogoal-testwhennoderemoved?

•  TreeSearch,orGraphSearch:–  ForgetExpanded(orExplored,Fig.3.7)nodes?–  Rememberthem?

Page 5: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

QueueforFron;er•  FIFO(FirstIn,FirstOut)

–  ResultsinBreadth-FirstSearch

•  LIFO(LastIn,FirstOut)–  ResultsinDepth-FirstSearch

•  PriorityQueuesortedbypathcostsofar–  ResultsinUniformCostSearch

•  Itera;veDeepeningSearchusesDepth-First

•  Bidirec;onalSearchcanuseeitherBreadth-FirstorUniformCostSearch

Page 6: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Whentodogoaltest?•  DoGoal-TestwhennodeispoppedfromqueueIFyoucareaboutfindingtheop;malpathANDyoursearchspacemayhavebothshortexpensiveandlongcheappathstoagoal.–  Guardagainstashortexpensivegoal.–  E.g.,UniformCostsearchwithvariablestepcosts.

•  Otherwise,doGoal-Testwhenisnodeinserted.–  E.g.,Breadth-firstSearch,Depth-firstSearch,orUniformCostsearchwhen

costisanon-decreasingfunc;onofdepthonly(whichisequivalenttoBreadth-firstSearch).

•  REASONABOUTyoursearchspace&problem.–  HowcouldIpossiblyfindanon-op;malgoal?

Page 7: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Goal test after pop

Generaltreesearch

Page 8: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Generalgraphsearch

Goal test after pop

Page 9: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Breadth-firstgraphsearchfunction BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure

node ← a node with STAT E = problem .INIT IAL-STAT E, PAT H-COST = 0 if problem .GOAL -TEST(node .STAT E) then return SOL UT ION(node ) frontier ← a FIFO queue with node as the only element explored ← an empty set loop do

if EMPTY?( frontier ) then return failure node ← POP( frontier ) /* chooses the shallowest node in frontier */ add node .STAT E to explored for each action in problem .ACT IONS(node .STAT E) do

child ← CHILD-NODE( problem , node , action ) if child .STAT E is not in explored or frontier then

if problem .GOAL -TEST(child .STAT E) then return SOL UT ION(child ) frontier ← INSE RT(child , frontier )

Figure 3.11 Breadth-first search on a graph.

Goal test before push

Page 10: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Uniformcostsearch

function UNIFORM-COST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT IAL-STAT E, PAT H-COST = 0 frontier ← a priority queue ordered by PAT H-COST, with node as the only element explored ← an empty set loop do

if EMPTY?( frontier ) then return failure node ← POP( frontier ) /* chooses the lowest-cost node in frontier */ if problem .GOAL -TEST(node .STAT E) then return SOL UT ION(node ) add node .STAT E to explored for each action in problem .ACT IONS(node .STAT E) do

child ← CHILD-NODE( problem , node , action ) if child .STAT E is not in explored or frontier then

frontier ← INSE RT(child , frontier ) else if child .STAT E is in frontier with higher PAT H-COST then

replace that frontier node with child

Figure 3.14 Uniform-cost search on a graph. The algorithm is identical to the general graph search algorithm in Figure 3.7, except for the use of a priority queue and the addition of an extra check in case a shorter path to a frontier state is discovered. The data structure for frontier needs to support efficient membership testing, so it should combine the capabilities of a priority queue and a hash table.

Goal test after pop

UCS: sort by g GBFS: identical, use h A*: identical, but use f = g+h

Page 11: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-limitedsearch&IDS

Goal test before push

Page 12: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

•  ForDFS,BFS,DLS,andIDS,thegoaltestisdonewhenthechildnodeisgenerated.–  Thesearenotop;malsearchesinthegeneralcase.–  BFSandIDSareop;malifcostisafunc;onofdepthonly;then,op;mal

goalsarealsoshallowestgoalsandsowillbefoundfirst

•  ForGBFSthebehavioristhesamewhetherthegoaltestisdonewhenthenodeisgeneratedorwhenitisremoved–  h(goal)=0soanygoalwillbeatthefrontofthequeueanyway.

•  ForUCSandA*thegoaltestisdonewhenthenodeisremovedfromthequeue.–  Thisprecau;onavoidsfindingashortexpensivepathbeforealongcheap

path.

WhentodoGoal-Test?Summary

Page 13: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Breadth-firstsearch•  Expandshallowestunexpandednode•  Fron;er:nodeswai;nginaqueuetobeexplored

–  alsocalledFringe,orOPEN•  Implementa;on:

–  Fron*erisafirst-in-first-out(FIFO)queue(newsuccessorsgoatend)–  Goaltestwheninserted

Initial state = A Is A a goal state? Put A at end of queue: Frontier = [A]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 14: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Breadth-firstsearch•  Expandshallowestunexpandednode•  Fron;er:nodeswai;nginaqueuetobeexplored

–  alsocalledFringe,orOPEN•  Implementa;on:

–  Fron*erisafirst-in-first-out(FIFO)queue(newsuccessorsgoatend)–  Goaltestwheninserted

Expand A to B,C Is B or C a goal state? Put B,C at end of queue: Frontier = [B,C]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 15: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Breadth-firstsearch•  Expandshallowestunexpandednode•  Fron;er:nodeswai;nginaqueuetobeexplored

–  alsocalledFringe,orOPEN•  Implementa;on:

–  Fron*erisafirst-in-first-out(FIFO)queue(newsuccessorsgoatend)–  Goaltestwheninserted

Expand B to D,E Is D or E a goal state? Put D,E at end of queue: Frontier = [C,D,E]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 16: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Breadth-firstsearch•  Expandshallowestunexpandednode•  Fron;er:nodeswai;nginaqueuetobeexplored

–  alsocalledFringe,orOPEN•  Implementa;on:

–  Fron*erisafirst-in-first-out(FIFO)queue(newsuccessorsgoatend)–  Goaltestwheninserted

Expand C to F, G Is F or G a goal state? Put F,G at end of queue: Frontier = [D,E,F,G]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 17: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Breadth-firstsearch•  Expandshallowestunexpandednode•  Fron;er:nodeswai;nginaqueuetobeexplored

–  alsocalledFringe,orOPEN•  Implementa;on:

–  Fron*erisafirst-in-first-out(FIFO)queue(newsuccessorsgoatend)–  Goaltestwheninserted

Expand D; no children Forget D Frontier = [E,F,G]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 18: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Breadth-firstsearch•  Expandshallowestunexpandednode•  Fron;er:nodeswai;nginaqueuetobeexplored

–  alsocalledFringe,orOPEN•  Implementa;on:

–  Fron*erisafirst-in-first-out(FIFO)queue(newsuccessorsgoatend)–  Goaltestwheninserted

Expand E; no children Forget E; B Frontier = [F,G]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 19: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Example BFS for 8-puzzle

Page 20: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Proper;esofbreadth-firstsearch•  Complete?Yes,italwaysreachesagoal(ifbisfinite)•  Time?1+b+b2+b3+…+bd=O(bd)(thisisthenumberofnodeswegenerate)•  Space?O(bd)

(keepseverynodeinmemory,eitherinfron;eroronapathtofron;er).•  Op;mal? No,forgeneralcostfunc;ons. Yes,ifcostisanon-decreasingfunc;ononlyofdepth.

–  Withf(d)≥f(d-1),e.g.,step-cost=constant:•  Allop;malgoalnodesoccuronthesamelevel•  Op;malgoalsarealwaysshallowerthannon-op;malgoals•  Anop;malgoalwillbefoundbeforeanynon-op;malgoal

•  UsuallySpaceisthebiggerproblem(morethan;me)

Page 21: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth of Nodes Solution Expanded Time Memory 0 1 5 microseconds 100 bytes 2 111 0.5 milliseconds 11 kbytes 4 11,111 0.05 seconds 1 megabyte 8 108 9.25 minutes 11 gigabytes 12 1012 64 days 111 terabytes

Assuming b=10; 200k nodes/sec; 100 bytes/node

BFS:Time&MemoryCosts

Page 22: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Breadth-firstisonlyop;malifpathcostisanon-decreasingfunc;onofdepth,i.e.,f(d)≥f(d-1);e.g.,constantstepcost,asinthe8-puzzle.

Canweguaranteeop;malityforvariableposi;vestepcosts≥ε?(Why≥ε?Toavoidinfinitepathsw/stepcosts1,½,¼,…)

Uniform-costSearch:Expandnodewithsmallestpathcostg(n).

•  Fron*erisapriorityqueue,i.e.,newsuccessorsaremergedintothequeuesortedbyg(n).–  Canremovesuccessorsalreadyonqueuew/higherg(n).

•  Savesmemory,costs;me;anotherspace-;metrade-off.

•  Goal-Testwhennodeispoppedoffqueue.

Uniform-costsearch

Page 23: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Implementation: Frontier = queue ordered by path cost. Equivalent to breadth-first if all step costs all equal. •  Complete?Yes,ifbisfiniteandstepcost≥ε>0. (otherwiseitcangetstuckininfiniteloops)

•  Time?#ofnodeswithpathcost≤costofop;malsolu;on. O(b⎣1+C*/ε⎦)≈O(bd+1)

•  Space?#ofnodeswithpathcost≤costofop;malsolu;on. O(b⎣1+C*/ε⎦)≈O(bd+1).

•  Op;mal? Yes,foranystepcost≥ε>0.

Uniform-costsearch

Page 24: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

ProofofCompleteness:Assume(1)finitemaxbranchingfactor=b;(2)minstepcost≥ε>0;(3)costtoop;malgoal=C*.Thenanodeatdepth⎣1+C*/ε⎦musthaveapathcost>C*.ThereareO(b^( ⎣ 1+C*/ε ⎦ ) such nodes,soagoalwillbefound.

ProofofOp;mality(givencompleteness):SupposethatUCSisnotop;mal.Then there must be an (optimal) goal state with path cost smaller than the found (suboptimal) goal state (invoking completeness). However, this is impossible because UCS would have expanded that node first, by definition. Contradiction.

Uniform-costsearch

Page 25: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5Routefindingproblem.Stepslabeledw/cost.

Orderofnodeexpansion: Pathfound: Costofpathfound:

Sg=0

Ex:Uniform-costsearch (Search tree version)

Page 26: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5Routefindingproblem.Stepslabeledw/cost.

Orderofnodeexpansion:S Pathfound: Costofpathfound:

Sg=0

Bg=5

Cg=15

Ag=1

Ex:Uniform-costsearch (Search tree version)

Page 27: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5Routefindingproblem.Stepslabeledw/cost.

Orderofnodeexpansion:SA Pathfound: Costofpathfound:

Sg=0

Bg=5

Cg=15

Ag=1

Gg=11

This early expensive goal node will go back onto the queue until after the later cheaper goal is found.

Ex:Uniform-costsearch (Search tree version)

Page 28: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5

Orderofnodeexpansion:SAB Pathfound: Costofpathfound:

Sg=0

Bg=5

Cg=15

Ag=1

Gg=11

Gg=10

Ifweweredoinggraphsearchwewouldremovethehigher-costofiden;calnodesandsavememory.However,UCSisop;malevenwithtreesearch,sincelower-costnodessorttothefront.

Routefindingproblem.Stepslabeledw/cost.

Ex:Uniform-costsearch (Search tree version)

Page 29: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5

Orderofnodeexpansion:SABG Pathfound:SBG Costofpathfound:10

Sg=0

Bg=5

Cg=15

Ag=1

Gg=11

Gg=10

Technically, the goal node is not really expanded, because we do not generate the children of a goal node. It is listed in “Order of node expansion” only for your convenience, to see explicitly where it was found.

Routefindingproblem.Stepslabeledw/cost.

Ex:Uniform-costsearch (Search tree version)

Page 30: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5

Orderofnodeexpansion: Pathfound: Costofpathfound:

Expanded:Next:Children:Queue:S/g=0

Routefindingproblem.Stepslabeledw/cost.

Ex:Uniform-costsearch (Virtual queue version)

Page 31: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5

Orderofnodeexpansion: S Pathfound: Costofpathfound:

Expanded:S/g=0Next:S/g=0Children:A/g=1,B/g=5,C/g=15Queue:S/g=0,A/g=1, B/g=5, C/g=15

Routefindingproblem.Stepslabeledw/cost.

Ex:Uniform-costsearch (Virtual queue version)

Page 32: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5

Orderofnodeexpansion: SA Pathfound: Costofpathfound:

Expanded:S/g=0, A/g=1Next:A/g=1Children:G/g=11Queue:S/g=0,A/g=1, B/g=5, C/g=15, G/g=11

Notethatinaproperpriorityqueueinacomputersystem,thisqueuewouldbesortedbyg(n).Forhand-simulatedsearchitismoreconvenienttowritechildrenastheyoccur,andthenscanthecurrentqueuetopickthehighest-prioritynodeonthequeue.

Routefindingproblem.Stepslabeledw/cost.

Ex:Uniform-costsearch (Virtual queue version)

Page 33: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

10

S

A

B

C

G15

15

5

5

Orderofnodeexpansion: SAB Pathfound: Costofpathfound:

Expanded:S/g=0, A/g=1, B/g=5Next:B/g=5Children:G/g=10Queue:S/g=0,A/g=1, B/g=5, C/g=15, G/g=11, G/g=10

Routefindingproblem.Stepslabeledw/cost.

Ex:Uniform-costsearch (Virtual queue version)

Page 34: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Expanded:S/g=0, A/g=1, B/g=5, G/g=10Next:G/g=10Children:noneQueue:S/g=0,A/g=1, B/g=5, C/g=15, G/g=11, G/g=10

10

S

A

B

C

G15

15

5

5

Orderofnodeexpansion: SABG Pathfound:SBG Costofpathfound:10

Technically, the goal node is not really expanded, because we do not generate the children of a goal node. It is listed in “Order of node expansion” only for your convenience, to see explicitly where it was found.

The same “Order of node expansion”, “Path found”, and “Cost of path found” is obtained by both methods. They are formally equivalent to each other in all ways.

Routefindingproblem.Stepslabeledw/cost.

Ex:Uniform-costsearch (Virtual queue version)

Page 35: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

S B

A D

E

C

F

G

1 20

2

3

4 8

6 1 1

The graph above shows the step-costs for different paths going from the start (S) to the goal (G). Use uniform cost search to find the optimal path to the goal.

Exercise for home

Page 36: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

•  Whyrequirestepcost¸²>0?– Otherwise,aninfiniteregressispossible.– Recall:

S

G

G is the only goal node in the search space.

S is the start node.

cost(S,G) = 1

g(G) = 1

A

B

D

C

cost(S,A) = 1/2 g(A) = 1/2

cost(A,B) = 1/4 g(B) = 3/4

cost(B,C) = 1/8 g(C) = 7/8

cost(C,D) = 1/16 g(C) = 15/16

No return from this branch. G will never be popped.

...

Uniformcostsearch

Page 37: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode•  Fron*er=LastInFirstOut(LIFO)queue,i.e.,newsuccessorsgoat

thefrontofthequeue.•  Goal-Testwheninserted.

Initial state = A Is A a goal state? Put A at front of queue. frontier = [A]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 38: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand A to B, C. Is B or C a goal state? Put B, C at front of queue. frontier = [B,C]

Note: Can save a space factor of b by generating successors one at a time. See backtracking search in your book, p. 87 and Chapter 6.

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 39: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand B to D, E. Is D or E a goal state? Put D, E at front of queue. frontier = [D,E,C]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 40: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand D to H, I. Is H or I a goal state? Put H, I at front of queue. frontier = [H,I,E,C]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 41: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand H to no children. Forget H. frontier = [I,E,C]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 42: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand I to no children. Forget D, I. frontier = [E,C]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 43: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand E to J, K. Is J or K a goal state? Put J, K at front of queue. frontier = [J,K,C]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 44: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand J to no children. Forget J. frontier = [K,C]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 45: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand K to no children. Forget B, E, K. frontier = [C]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 46: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Depth-firstsearch•  Expanddeepestunexpandednode

–  Fron*er=LIFOqueue,i.e.,putsuccessorsatfront

Expand C to F, G. Is F or G a goal state? Put F, G at front of queue. frontier = [F,G]

Future= green dotted circles Frontier=white nodes Expanded/active=gray nodes Forgotten/reclaimed= black nodes

Page 47: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Proper;esofdepth-firstsearch•  Complete?No:failsinloops/infinite-depthspaces

–  Canmodifytoavoidloops/repeatedstatesalongpath•  checkifcurrentnodesoccurredbeforeonpathtoroot

–  Canusegraphsearch(rememberallnodeseverseen)•  problemwithgraphsearch:spaceisexponen;al,notlinear

–  S;llfailsininfinite-depthspaces(maymissgoalen;rely)

•  Time?O(bm)withm=maximumdepthofspace–  Terribleifmismuchlargerthand–  Ifsolu;onsaredense,maybemuchfasterthanBFS

•  Space?O(bm),i.e.,linearspace!–  Rememberasinglepath+expandedunexplorednodes

•  Op;mal?No:Itmayfindanon-op;malgoalfirst

A

B C

Page 48: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Itera;veDeepeningSearch•  ToavoidtheinfinitedepthproblemofDFS:

–  Onlysearchun;ldepthL–  i.e,don’texpandnodesbeyonddepthL–  Depth-LimitedSearch

•  Whatifsolu;onisdeeperthanL?–  Increasedepthitera;vely–  Itera;veDeepeningSearch

•  IDS–  Inheritsthememoryadvantageofdepth-firstsearch–  Hasthecompletenesspropertyofbreadth-firstsearch

Page 49: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Itera;veDeepeningSearch,L=0

Page 50: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Itera;veDeepeningSearch,L=1

Page 51: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Itera;veDeepeningSearch,L=2

Page 52: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Itera;veDeepeningSearch,L=3

Page 53: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

•  Numberofnodesgeneratedinadepth-limitedsearchtodepthdwithbranchingfactorb:

NDLS=b0+b1+b2+…+bd-2+bd-1+bd

•  Numberofnodesgeneratedinanitera;vedeepeningsearchtodepthdwithbranchingfactorb:

NIDS=(d+1)b0+db1+(d-1)b2+…+3bd-2+2bd-1+1bd=O(bd)

•  Forb=10,d=5,–  NDLS=1+10+100+1,000+10,000+100,000=111,111–  NIDS=6+50+400+3,000+20,000+100,000=123,450

[ Ratio: b/(b-1) ]

Itera;veDeepeningSearch

Page 54: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Proper;esofitera;vedeepeningsearch•  Complete? Yes

•  Time?O(bd)

•  Space?O(bd)

•  Op;mal?No,forgeneralcostfunc;ons. Yes,ifcostisanon-decreasingfunc;ononlyofdepth.

Generallythepreferreduninformedsearchstrategy.

Page 55: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Bidirec;onalSearch•  Idea

–  simultaneouslysearchforwardfromSandbackwardsfromG–  stopwhenboth“meetinthemiddle”–  needtokeeptrackoftheintersec;onof2opensetsofnodes

•  WhatdoessearchingbackwardsfromGmean–  needawaytospecifythepredecessorsofG

•  thiscanbedifficult,•  e.g.,predecessorsofcheckmateinchess?

–  whatiftherearemul;plegoalstates?–  whatifthereisonlyagoaltest,noexplicitlist?

•  Complexity

–  ;mecomplexityisbest:O(2b(d/2))=O(b(d/2))–  memorycomplexityisthesame

Page 56: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Bi-Direc;onalSearch

Page 57: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Summaryofalgorithms

Generally the preferred uninformed search strategy

Criterion Breadth-First

Uniform-Cost

Depth-First

Depth-Limited

Itera;veDeepeningDLS

Bidirec;onal(ifapplicable)

Complete? Yes[a] Yes[a,b] No No Yes[a] Yes[a,d]

Time O(bd) O(b⎣1+C*/ε⎦) O(bm) O(bl) O(bd) O(bd/2)

Space O(bd) O(b⎣1+C*/ε⎦) O(bm) O(bl) O(bd) O(bd/2)

Op;mal? Yes[c] Yes No No Yes[c] Yes[c,d]

There are a number of footnotes, caveats, and assumptions. See Fig. 3.21, p. 91. [a] complete if b is finite [b] complete if step costs ≥ ε > 0 [c] optimal if step costs are all identical (also if path cost non-decreasing function of depth only) [d] if both directions use breadth-first search (also if both directions use uniform-cost search with step costs ≥ ε > 0) Note that d ≤ ⎣1+C*/ε⎦

Page 58: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Youshouldknow…•  Overviewofuninformedsearchmethods

•  Searchstrategyevalua;on–  Complete?Time?Space?Op;mal?–  Maxbranching(b),Solu;ondepth(d),Maxdepth(m)–  (forUCS:C*:truecosttoop;malgoal;ε>0:minimumstepcost)

•  SearchStrategyComponentsandConsidera;ons–  Queue?GoalTestwhen?Treesearchvs.Graphsearch?

•  Variousblindstrategies:–  Breadth-firstsearch–  Uniform-costsearch–  Depth-firstsearch–  Itera;vedeepeningsearch(generallypreferred)–  Bidirec;onalsearch(preferredifapplicable)

Page 59: 02 Uninf Search · 2017. 6. 16. · Breadth-first graph search function BRE ADT H-FIRST-SEARCH( problem ) returns a solution, or failure node ← a node with STAT E = problem .INIT

Summary•  Problemformula;onusuallyrequiresabstrac;ngawayreal-world

detailstodefineastatespacethatcanfeasiblybeexplored

•  Varietyofuninformedsearchstrategies

•  Itera;vedeepeningsearchusesonlylinearspaceandnotmuchmore;methanotheruninformedalgorithms

http://www.cs.rmit.edu.au/AI-Search/Product/ http://aima.cs.berkeley.edu/demos.html (for more demos)