Search - University of Texas at Austinpstone/Courses/343Hfall17/... · Idea: get DFS’s space...

Post on 12-Oct-2020

0 views 0 download

Transcript of Search - University of Texas at Austinpstone/Courses/343Hfall17/... · Idea: get DFS’s space...

CS343H:HonorsArtificialIntelligenceSearch

Prof.PeterStone

UniversityofTexasatAustin[TheseslideswerecreatedbyDanKleinandPieterAbbeelforCS188IntrotoAIatUCBerkeley.AllCS188materialsareavailableathttp://ai.berkeley.edu.]

Today

▪ AgentsthatPlanAhead

▪ SearchProblems

▪ UninformedSearchMethods

▪ Depth-FirstSearch▪ Breadth-FirstSearch▪ Uniform-CostSearch

AgentsthatPlan

ReflexAgents

▪ Reflexagents:▪ Chooseactionbasedoncurrentpercept(and

maybememory)▪ Mayhavememoryoramodeloftheworld’s

currentstate▪ Donotconsiderthefutureconsequencesof

theiractions▪ ConsiderhowtheworldIS

▪ Canareflexagentberational?

VideoofDemoReflex—Success

VideoofDemoReflex—Stuck

PlanningAgents

▪ Planningagents:▪ Ask“whatif”▪ Decisionsbasedon(hypothesized)consequences

ofactions▪ Musthaveamodelofhowtheworldevolvesin

responsetoactions▪ Mustformulateagoal(test)▪ ConsiderhowtheworldWOULDBE

▪ Optimalvs.completeplanning

▪ Planningvs.replanning

VideoofDemo—Suboptimallocalreplanning

VideoofDemo—Globallyoptimalplanning

SearchProblems

SearchProblems

▪ Asearchproblemconsistsof:

▪ Astatespace

▪ Asuccessorfunction (withactions,costs)

▪ Astartstateandagoaltest

▪ Asolutionisasequenceofactions(aplan)whichtransformsthestartstatetoagoalstate

“N”,1.0

“E”,1.0

SearchProblemsAreModels

Example:TravelinginRomania

▪ Statespace:▪ Cities

▪ Successorfunction:▪ Roads:Gotoadjacentcitywith

cost=distance▪ Startstate:

▪ Arad▪ Goaltest:

▪ Isstate==Bucharest?

▪ Solution?

What’sinaStateSpace?

▪ Problem:Pathing▪ States:(x,y)location▪ Actions:NSEW▪ Successor:updatelocation

only▪ Goaltest:is(x,y)=END

▪ Problem:Eat-All-Dots▪ States:{(x,y),dotbooleans}▪ Actions:NSEW▪ Successor:updatelocation

andpossiblyadotboolean▪ Goaltest:dotsallfalse

Theworldstateincludeseverylastdetailoftheenvironment

Asearchstatekeepsonlythedetailsneededforplanning(abstraction)

StateSpaceSizes?

▪ Worldstate:▪ Agentpositions:120▪ Foodcount:30▪ Ghostpositions:12▪ Agentfacing:NSEW

▪ Howmany▪ Worldstates? 120x(230)x(122)x4(>74trillion!)▪ Statesforpathing? 120▪ Statesforeat-all-dots? 120x(230)(>128billion)

Quiz:SafePassage

▪ Problem:eatalldotswhilekeepingtheghostsperma-scared▪ Whatdoesthestatespacehavetospecify?▪ (agentposition,dotbooleans,powerpelletbooleans,remainingscaredtime)

StateSpaceGraphsandSearchTrees

StateSpaceGraphs

▪ Statespacegraph:Amathematicalrepresentationofasearchproblem▪ Nodesare(abstracted)worldconfigurations▪ Arcsrepresentsuccessors(actionresults)▪ Thegoaltestisasetofgoalnodes(maybeonlyone)

▪ Inastatespacegraph,eachstateoccursonlyonce!

▪ Wecanrarelybuildthisfullgraphinmemory(it’stoobig),butit’sausefulidea

StateSpaceGraphs

S

G

d

b

p q

c

e

h

a

f

r

Tinysearchgraphforatinysearchproblem

▪ Statespacegraph:Amathematicalrepresentationofasearchproblem▪ Nodesare(abstracted)worldconfigurations▪ Arcsrepresentsuccessors(actionresults)▪ Thegoaltestisasetofgoalnodes(maybeonlyone)

▪ Inastatespacegraph,eachstateoccursonlyonce!

▪ Wecanrarelybuildthisfullgraphinmemory(it’stoobig),butit’sausefulidea

SearchTrees

▪ Asearchtree:▪ A“whatif”treeofplansandtheiroutcomes▪ Thestartstateistherootnode▪ Childrencorrespondtosuccessors▪ Nodesshowstates,butcorrespondtoPLANSthatachievethosestates▪ Formostproblems,wecanneveractuallybuildthewholetree

“E”,1.0“N”,1.0

Thisisnow/start

Possiblefutures

StateSpaceGraphsvs.SearchTrees

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c Ga

S

G

d

b

p q

c

e

h

a

f

r

Weconstructbothondemand–andweconstructaslittleas

possible.

EachNODEinthesearchtreeisanentirePATHinthestatespacegraph.

SearchTreeStateSpaceGraph

Quiz:StateSpaceGraphsvs.SearchTrees

S G

b

a

Considerthis4-stategraph:

Important:Lotsofrepeatedstructureinthesearchtree!

Howbigisitssearchtree(fromS)?

Sowhywouldweeveruseasearchtree?

1)Cannotstore“closedlist”(previouslyvisitednodes)2)Graphhappenstobeatree,sonoreasontostoreclosedlist

TreeSearch

SearchExample:Romania

SearchingwithaSearchTree

▪ Search:▪ Expandoutpotentialplans(treenodes)▪ Maintainafringeofpartialplansunderconsideration▪ Trytoexpandasfewtreenodesaspossible

GeneralTreeSearch

▪ Importantideas:▪ Fringe▪ Expansion▪ Explorationstrategy

▪ Mainquestion:whichfringenodestoexplore?

Depth-FirstSearch

Depth-FirstSearch

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c G

a

S

G

d

b

p q

c

e

h

a

f

rqph

fd

ba

c

e

r

Strategy:expandadeepestnodefirst

Implementation:FringeisaLIFOstack

SearchAlgorithmProperties

SearchAlgorithmProperties

▪ Complete:Guaranteedtofindasolutionifoneexists?▪ Optimal:Guaranteedtofindtheleastcostpath?▪ Timecomplexity?▪ Spacecomplexity?

▪ Cartoonofsearchtree:▪ bisthebranchingfactor▪ misthemaximumdepth▪ solutionsatvariousdepths

▪ Numberofnodesinentiretree?▪ 1+b+b2+….bm=O(bm)

…b

1 nodeb nodes

b2 nodes

bm nodes

m tiers

Depth-FirstSearch(DFS)Properties

…b

1 nodeb nodes

b2 nodes

bm nodes

m tiers

▪ WhatnodesDFSexpand?▪ Someleftprefixofthetree.▪ Couldprocessthewholetree!▪ Ifmisfinite,takestimeO(bm)

▪ Howmuchspacedoesthefringetake?▪ Onlyhassiblingsonpathtoroot,soO(bm)

▪ Isitcomplete?▪ mcouldbeinfinite,soonlyifwepreventcycles

(morelater)

▪ Isitoptimal?▪ No,itfindsthe“leftmost”solution,regardlessof

depthorcost

Breadth-FirstSearch

Breadth-FirstSearch

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c G

a

S

G

d

b

p q

ce

h

a

f

r

Search

Tiers

Strategy:expandashallowestnodefirst

Implementation:FringeisaFIFOqueue

Breadth-FirstSearch(BFS)Properties

▪ WhatnodesdoesBFSexpand?▪ Processesallnodesaboveshallowestsolution▪ Letdepthofshallowestsolutionbes▪ SearchtakestimeO(bs)

▪ Howmuchspacedoesthefringetake?▪ Hasroughlythelasttier,soO(bs)

▪ Isitcomplete?▪ smustbefiniteifasolutionexists,soyes!

▪ Isitoptimal?▪ Onlyifcostsareall1(moreoncostslater)

…b

1 nodeb nodes

b2 nodes

bm nodes

s tiers

bs nodes

Quiz:DFSvsBFS

Quiz:DFSvsBFS

▪ WhenwillBFSoutperformDFS?

▪ WhenwillDFSoutperformBFS?

▪ Whatistheworstcaseforeach?

VideoofDemoMazeWaterDFS/BFS(part1)

VideoofDemoMazeWaterDFS/BFS(part2)

IterativeDeepening

…b

▪ Idea:getDFS’sspaceadvantagewithBFS’stime/shallow-solutionadvantages▪ RunaDFSwithdepthlimit1.Ifnosolution…▪ RunaDFSwithdepthlimit2.Ifnosolution…▪ RunaDFSwithdepthlimit3.…..

▪ Isn’tthatwastefullyredundant?▪ Generallymostworkhappensinthelowestlevelsearched,sonotsobad!

Cost-SensitiveSearch

BFSfindstheshortestpathintermsofnumberofactions.Itdoesnotfindtheleast-costpath.Wewillnowcoverasimilaralgorithmwhichdoesfindtheleast-costpath.

START

GOAL

d

b

pq

c

e

h

a

f

r

2

9 2

81

8

2

3

2

4

4

15

1

32

2

UniformCostSearch

UniformCostSearch

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c G

a

Strategy: expand a cheapest node first:

Fringe is a priority queue (priority: cumulative cost) S

G

d

b

p q

c

e

h

a

f

r

3 9 1

16411

5

713

8

1011

17 11

0

6

39

1

1

2

8

8 2

15

1

2

Cost contours

2

UniformCostSearch(UCS)Properties

▪ WhatnodesdoesUCSexpand?▪ Processesallnodeswithcostlessthancheapestsolution!▪ IfthatsolutioncostsC* andarcscostatleastε , thenthe“effective

depth”isroughlyC*/ε▪ TakestimeO(bC*/ε)(exponentialineffectivedepth)

▪ Howmuchspacedoesthefringetake?▪ Hasroughlythelasttier,soO(bC*/ε)

▪ Isitcomplete?▪ Assumingbestsolutionhasafinitecostandminimumarccostispositive,

yes!

▪ Isitoptimal?▪ Yes!(ProofnextlectureviaA*)

b

C*/ε “tiers”c ≤ 3

c ≤ 2

c ≤ 1

UniformCostIssues

▪ Remember:UCSexploresincreasingcostcontours

▪ Thegood:UCSiscompleteandoptimal!

▪ Thebad:▪ Exploresoptionsinevery“direction”▪ Noinformationaboutgoallocation

▪ We’llfixthatsoon!Start Goal

c ≤ 3c ≤ 2

c ≤ 1

VideoofDemoEmptyUCS

VideoofDemoMazewithDeep/ShallowWater---DFS,BFS,orUCS?(part1)

VideoofDemoMazewithDeep/ShallowWater---DFS,BFS,orUCS?(part2)

VideoofDemoMazewithDeep/ShallowWater---DFS,BFS,orUCS?(part3)

TheOneQueue

▪ Allthesesearchalgorithmsarethesameexceptforfringestrategies▪ Conceptually,allfringesarepriorityqueues(i.e.collectionsofnodeswithattachedpriorities)

▪ Practically,forDFSandBFS,youcanavoidthelog(n)overheadfromanactualpriorityqueue,byusingstacksandqueues

▪ Canevencodeoneimplementationthattakesavariablequeuingobject

SearchandModels

▪ Searchoperatesovermodelsoftheworld▪ Theagentdoesn’tactuallytryalltheplansoutintherealworld!

▪ Planningisall“insimulation”

▪ Yoursearchisonlyasgoodasyourmodels…