CSCI360 Introduc/ontoAr/ficialIntelligence Week2:ProblemSolvingandOp/miza/on Instructor:Wei-MinShen StatusCheckandReview • Statuscheck – HaveyouregisteredinPiazza? – HaveyouruntheProject-1? – HaveyousubmiMedyourpre-readingreports? • Herearesomegoodonesforyourreference • Reviewoflastlecture – Agent?Typesofagents? – Environment?Typesofenvironment? • Today’slecture=? ClassOutline Wk2Ch3:SolvingProblems • Howtorepresentaproblem? – states,ac/ons,ini/als,goals,(e.g.,/c-tac-toe) • Howtosolveaproblem? – Search:fromheretothere,ini/alstogoals – Depth-first,breadth-first • Howgoodisyoursolu/on?(fig6.1,ALFE) – Howgoodisyourstate?Howcostlyisanac/on? – Best-first,DynamicProgramming,A*,etc. – Canyouguaranteeanything?(op/malvsheuris/c) • Howmuchdoyouwanttopayforyoursolu/on? – Howdeep/widecanyougo? • Predeterminedvsdynamic(e.g.,itera/vedeepening) – Onewayormanyways(bi-direc/onal)? • Howbigisaproblem?Canyouputthewholeworldinyourhead? – TowerofHanoi,chess,robot-and-world, • HM:statespaceforTOH,assignvaluesforstateandac/ons ClassOutline Wk2Ch4:Op/miza/on • Howtofindtheextremesoff(x)? • Whyisitsoimportant? • Whyisitsohard?(noonehasofferedageneralsolu/on!) – – – – – – – – Whichwaytogo? Howmuchcanyousee?(localvsglobal) Howmanypointscanyouremember? Howbigisyourstep?(skipTHEpoint?) Howwellcanyouguess? Howmuchdoyouknowaboutthefunc/on? Howdoyouknowyouaredone? Willthefunc/onchangebyitself? • HW:yourownanswersfortheaboveques/ons ThisWeek’sLecture • ProblemSolvingandSearchTechniques • Op/miza/onTechniques • HomeWork1assignments SolvingProblemsbySearch • Howtorepresentareal-worldproblem? – Examples,statespace,states,ac/ons,ini/als,goals. • Howtosolveaproblem? – Search:fromheretothere,ini/alstogoals – Depth-first,breadth-first • Howgoodisyoursolu/on?(fig6.1,ALFE) – Howgoodisyourstate?Howcostlyisanac/on? – Best-first,DynamicProgramming,A*,etc. – Canyouguaranteeanything?(op/malvsheuris/c) • Howmuchdoyouwanttopayforyoursolu/on? – Howdeep/widecanyougo? • Predeterminedvsdynamic(e.g.,itera/vedeepening) – Onewayormanyways(bi-direc/onal)? • Howbigisaproblem?Canyouputthewholeworldinyourhead? – TowerofHanoi,chess,robot-and-world, Whatisa“Problem”? • Anyideas? • Hint:ThinkitasrelatedtoAgent Whatisa“Problem”? • Anyideas? • Hint:ThinkitasrelatedtoAgent – Percepts,ac/ons,environment,goals,u/li/es • Problem: – States,ini/alstate,goalstates, – Solu/on:asequenceofac/onsleadstothegoal ProblemExamples:8Puzzle,PAC-Man Ini/alState GoalState(s) TowerofHanoi,ACleaningRobot Can“dirt”beagoal? 10 TravelExampleandProject-1 StateSpace Howtorepresentareal-worldproblem • GraphSearch – – – – – – Graph Ver/ces Edges Startver/ces Goalver/ces Solu/onisa (minimumcost) pathfromthe starttothegoal SearchProblem Statespace States Ac/ons=operators Ini/alstate Goalstatesorgoaltest Solu/onisa(minimum cost)ac/onsequence fromthestarttothe goalstate(orastate thatsa/sfiesthegoal test) ABIGQues/on: Howdothe“sensors” and“percepts”enter thepicture? VacuumRobotandItsWorld TravelingfromAradToBucharest Whatisa“state”here? StateGraphsvs.SearchTrees EachNODEinthesearchtreeisan en/rePATHinthestategraph(note howmanynodesinthegraphappear mul/ple/mesinthesearchtree) G a b c f d s s e p h r q Wealmostalways constructbothondemand –andweconstructasliBle aspossible d b c a a e e h h p q p q c a r p f q G r q q f c a G StateSpaceandSearchTree ASearchTree Statespace withac/ons, costs/rewards (Fig6.1,ALFE) • Anodeinthesearchtreeis adatastructurecontaining thestateplusotherdata 17 SearchTreeNodes SolvingProblemsbySearch • Howtorepresentaproblem? – Examples(e.g.,8puzzle,TOH,Roomba,Travel),,states,ac/ons,ini/als,goals. • Howtosolveaproblem? • Howgoodisyoursolu/on?(fig6.1,ALFE) – Search:fromheretothere,fromtheini/alstothegoals – Depth-first,breadth-first – Howgoodisyourstate?Howcostlyisanac/on? – Best-first,DynamicProgramming,A*,etc. – Canyouguaranteeanything?(op/malvsheuris/c) • Howmuchdoyouwanttopayforyoursolu/on? – Howdeep/widecanyougo? • Predeterminedvsdynamic(e.g.,itera/vedeepening) – Onewayormanyways(bi-direc/onal)? • Howbigisaproblem?Canyouputthewholeworldinyourhead? – TowerofHanoi,chess,robot-and-world, • HM:statespaceforTOH,assignvaluesforstateandac/ons. ProblemSolvingMethods(Overview) • Breadth-firstsearch • Depth-firstsearch • Best-firstsearch – Goodness=(past+future) – Uniformcost(es/matepastandfuture) – A*searchalgorithm(es/matethefuture) – DynamicProgramming(backfromthefuture) Treesearchalgorithms Basic idea: offline, systematic exploration of simulated state-space by generating successors of explored states func(onTREE-SEARCH(problem,strategy) returnsasolu/on,orfailure ini/alizethesearchtreeusingtheini/alstateproblem loopdo iftherearenocandidatesforexpansion,thenreturnfailure choosealeafnodeforexpansionaccordingtostrategy ifthenodecontainsagoalstatethen returnthecorrespondingsolu/on elseexpandthenodeandaddresul/ngnodestothesearchtree end Breath-firststrategy:theleastdepthnode Depth-firststrategy:thedeepestdepthnode Implementa/on(TreeSearch) func(onTREE-SEARCH(problem)returnasolu/onorfailure fron/er←MAKE-QUEUE(MAKE-NODE(problem.INITIAL-STATE)) loopdo ifEMPTY?(fron/er)thenreturnfailure node←CHOOSE-NODE-By-Strategy(fron/er) ifproblem.GOAL-TESTappliedtonode.STATEsucceeds thenreturnSOLUTION(node) fron/er←INSERT-ALL(EXPAND(node,problem),fron/er) • Thefron/eristhesetofnodes thathavebeengeneratedbut notyetexpanded Strategy:Breadth-FirstSearch • Expandshallowestnodesfirst – Leotorightatanydepth 22 Breath-firstSearchexample StateGraph Depth-FirstSearch • Expanddeepestnodesfirst – Leotorightatanydepth 24 Depth-FirstSearch • Expanddeepestnodesfirst – Leotorightatanydepth – Backtrackwhenhit“terminal” Depth-firstSearchexample StateGraph Ques/on: Willthedepthgrowforever? Whereisthe“terminal”? LoopProblems GraphSearch(Preven/ngLoop) func(onGRAPH-SEARCH(problem)returnasolu/onorfailure fron/er←MAKE-QUEUE(MAKE-NODE(problem.INITIAL-STATE)) explored_set←empty loopdo ifEMPTY?(fron/er)thenreturnfailure node←CHOOSE-NODE-By-Strategy(fron/er) ifproblem.GOAL-TESTappliedtonode.STATEsucceeds thenreturnSOLUTION(node) explored_set←INSERT(node,explored_set) foreachnew_nodeinEXPAND(node,problem)do ifNOT(MEMBER?(new_node,fron/er))and NOT(MEMBER?(new_node,explored_set)) thenfron/er←INSERT(new_node,fron/er) SolvingProblemsbySearch • Howtorepresentaproblem? – Examples(e.g.,8puzzle,TOH,Roomba,Travel),,states,ac/ons,ini/als,goals. • Howtosolveaproblem? • Howgoodisyoursolu/on?(fig6.1,ALFE) – Search:fromheretothere,fromtheini/alstothegoals – Depth-first,breadth-first – Howgoodisyourstate?Howcostlyisanac/on? – Best-first,DynamicProgramming,A*,etc. – Canyouguaranteeanything?(op/malvsheuris/c) • Howmuchdoyouwanttopayforyoursolu/on? – Howdeep/widecanyougo? • Predeterminedvsdynamic(e.g.,itera/vedeepening) – Onewayormanyways(bi-direc/onal)? • Howbigisaproblem?Canyouputthewholeworldinyourhead? – TowerofHanoi,chess,robot-and-world, • HM:statespaceforTOH,assignvaluesforstateandac/ons. Best-Firstsearchalgorithms func(onTREE-SEARCH(problem,strategy) returnsasolu/on,orfailure ini/alizethesearchtreeusingtheini/alstateproblem loopdo iftherearenocandidatesforexpansion,thenreturnfailure choosealeafnodeforexpansionaccordingtostrategy ifthenodecontainsagoalstatethen returnthecorrespondingsolu/on elseexpandthenodeandaddresul/ngnodestothesearchtree end Best-firststrategy:choosethe“best”node:goodness=(pastcost+futurecost) Whendoweusethisstrategy? TravelingfromAradToBucharest Wehavetheknowledgeabouttheactualdrivingdistances Best-firstSearchexample Choosethebestnodetoexpand:(pastcost)+(thebestfuturecost) Sibiu:(140)+(80+97+101)=? Timisoanra:(118)+(111+70+75+120+138)=? Zerind:(75)+(71+151+80+97+101)=? TwoBigQues/onsabout“Best”? • Whatifthebestfuturecostisunknowntous? • Whatifthebestfuturecostistooexpensivetocompute? Whatifwedon’tknowthefuture? • Goodness=pastcost+thebestfuturecost – Whatifthebestfuturecostisunknowntous? • Es/mateGoodness:uniformcost(naïve) • Es/mateGoodness=pastcost+es/matedfuturecost – Evalua/onfunc/onf(n)=g(n)+h(n) • g(n)thecost(sofar)toreachthecurrentnoden • h(n)es/matedcosttogetfromthecurrentnodentothegoal • f(n)es/matedtotalcostofpaththroughntothegoal TravelingfromAradToBucharest Supposethefuturedrivingdistancestothegoalisunknowntous Butweknowthestraight-linedistancestothegoal Sensor:? Sensor:? Usingthees/matedfuturecost Choosethebestnodetoexpand:(pastcost+es/matedfuturecost) Sibiu:140+253 Timisoanra:118+329 Zerind:75+374 Whatifoures/ma/oniswrong? Examplesareplenty “Myfathertoldmeso” “Ididdrivethatroadbefore” “IhaveaniPhone” “Googlemap” …… How“wrong”canwetolerate? Over-es/mate? Under-es/mate? Byhowmuch? Es/mateby“AdmissibleHeuris/cs” • Aheuris/cisadmissibleifitneveroveres/matesthe futurecosttoreachthegoal • Admissibleheuris/csare“op/mis/c” Formally: 1.h(n)≤h*(n)whereh*(n)isthetruecostfromntothegoal 2.h(n)≥0,withh(G)=0foranygoalG e.g.hSLD(n)(GPS)isadmissiblebecauseitneveroveres/matestheactual roaddistancetothegoal 38 A*searchalgorithm func(onTREE-SEARCH(problem,strategy) returnsasolu/on,orfailure ini/alizethesearchtreeusingtheini/alstateproblem loopdo iftherearenocandidatesforexpansion,thenreturnfailure choosealeafnodeforexpansionaccordingtostrategy ifthenodecontainsagoalstatethen returnthecorrespondingsolu/on elseexpandthenodeandaddresul/ngnodestothesearchtree end Best-firststrategy:choosethebestnode:goodness=(pastcost+futurecost) A*strategy:choosethe“admissiblyes/matedbest”node: goodness=(pastcost+admissiblyes/matedfuturecost) Whatif“futureistoohardtocompute”? • Computethebestfuturecostforanode mustconsiderallpossiblepathsfromthe nodetothegoal – Thisistooexpensivebecausetherearesomany suchpaths • Solu/on – UseDynamicProgramming • Notcomputepathbypath • Butcomputestagebystage(breath-first) DynamicProgramming(ALFE6.1.1) Backwardrecursion:computethefuturecostbybackfromthegoal*stagebystage Backwardrecursionequa/on: Best-FirstbyDynamicProgramming func(onTREE-SEARCH(problem,strategy) returnsasolu/on,orfailure ini/alizethesearchtreeusingtheini/alstateproblem loopdo iftherearenocandidatesforexpansion,thenreturnfailure choosealeafnodeforexpansionaccordingtostrategy ifthenodecontainsagoalstatethen returnthecorrespondingsolu/on elseexpandthenodeandaddresul/ngnodestothesearchtree end Best-firststrategy:choosethebestnode:goodness=(pastcost+futurecost) A*strategy:choosethebestnode:goodness=(pastcost+admissiblyes/matedfuturecost) Dynamicprogramming:choosethebestnode:goodness=(pastcost+V(s)) Evalua/onofsearchstrategies • Asearchstrategyisdefinedbypickingtheorderofnodeexpansion. • Searchalgorithmsarecommonlyevaluatedaccordingtothefollowingfourcriteria: – – – – • Completeness:doesitalwaysfindasolu/onifoneexists? Timecomplexity:howlongdoesittakeasfunc/onofnumberofnodes? Spacecomplexity:howmuchmemorydoesitrequire? Op(mality:doesitguaranteetheleast-costsolu/on? Timeandspacecomplexityaremeasuredintermsof: – b–maxbranchingfactorofthesearchtree – d–depthoftheleast-costsolu/on – m–maxdepthofthesearchtree(maybeinfinity) SolvingProblemsbySearch • Howtorepresentaproblem? – Examples(e.g.,8puzzle,TOH,Roomba,Travel),,states,ac/ons,ini/als,goals. • Howtosolveaproblem? • Howgoodisyoursolu/on?(fig6.1,ALFE) – Search:fromheretothere,fromtheini/alstothegoals – Depth-first,breadth-first – Howgoodisyourstate?Howcostlyisanac/on? – Best-first,DynamicProgramming,A*,etc. – Canyouguaranteeanything?(op/malvsheuris/c) • Howmuchdoyouwanttopayforyoursolu/on? – Howdeep/widecanyougo? • Predeterminedvsdynamic(e.g.,itera/vedeepening) – Onewayormanyways(bi-direc/onal)? • Howbigisaproblem?Canyouputthewholeworldinyourhead? – TowerofHanoi,chess,robot-and-world, • HM:statespaceforTOH,assignvaluesforstateandac/ons. OtherSearch-relatedTechniques • Itera/vedeepening – Limitthesearchdepth,incrementallyincreaseit • Bi-direc/onalsearch – Searchfromtheini/altothegoal,aswellas fromthegoaltotheini/al SolvingProblemsbySearch • Howtorepresentaproblem? – Examples(e.g.,8puzzle,TOH,Roomba,Travel),,states,ac/ons,ini/als,goals. • Howtosolveaproblem? • Howgoodisyoursolu/on?(fig6.1,ALFE) – Search:fromheretothere,fromtheini/alstothegoals – Depth-first,breadth-first – Howgoodisyourstate?Howcostlyisanac/on? – Best-first,DynamicProgramming,A*,etc. – Canyouguaranteeanything?(op/malvsheuris/c) • Howmuchdoyouwanttopayforyoursolu/on? – Howdeep/widecanyougo? • Predeterminedvsdynamic(e.g.,itera/vedeepening,fixeddepth) – Onewayormanyways(bi-direc/onal)? • Howbigisaproblem?Canyouputthewholeworldinyourhead? – TowerofHanoi,chess,robot-and-world, • HM:statespaceforTOH,assignvaluesforstateandac/ons. Complexity:Howbigisaproblem? WhenyousolveN=64, itwouldbetheendoftheworld! Timecomplexityofdepth-first • In the worst case: • the (only) goal node may be on the right-most branch, b0 b1 d b G bd-1 bd • Time complexity = bd + bd-1 + … + 1 = bd+1 -1 b-1 • Thus: O(bd) CS561-Lectures3-4-Macskassy-Spring 2011 48 Spacecomplexityofdepth-first • Largest number of nodes in QUEUE is reached in bottom leftmost node. • Example: m = 3, b = 3 : G ... • QUEUE contains all nodes. Thus: 7. • In General: ((b-1) * m) + b • Order: O(m*b) 49 Comparinguninformedsearchstrategies Criterion Time Space Op/mal? Complete? – – – – Breadth- Uniform Depth- Depth- Itera/ve Bidirec/onal first cost first limited deepening(ifapplicable) b^d b^d b^m b^l b^d b^(d/2) b^d b^d bm bl bd b^(d/2) Yes Yes No No Yes Yes Yes Yes No Yes, ifl≥d Yes Yes b–maxbranchingfactorofthesearchtree d–depthoftheleast-costsolu/on m–maxdepthofthestate-space(maybeinfinity) l–depthcutoff 50 Summary • Problemformula/onusuallyrequiresabstrac/ngaway real-worlddetailstodefineastatespacethatcanbe exploredusingcomputeralgorithms. • Onceproblemisformulatedinabstractform,complexity analysishelpsuspickingoutbestalgorithmtosolve problem. • Varietyofuninformedsearchstrategies;differenceliesin methodusedtopicknodethatwillbefurtherexpanded. • Itera/vedeepeningsearchonlyuseslinearspaceandnot muchmore/methanotheruniformedsearchstrategies. CS561,Lectures3-5 51 SolvingProblemsbySearch • Howtorepresentaproblem? – Examples(e.g.,8puzzle,TOH,Roomba,Travel),,states,ac/ons,ini/als,goals. • Howtosolveaproblem? • Howgoodisyoursolu/on?(fig6.1,ALFE) – Search:fromheretothere,fromtheini/alstothegoals – Depth-first,breadth-first – Howgoodisyourstate?Howcostlyisanac/on? – Best-first,DynamicProgramming,A*,etc. – Canyouguaranteeanything?(op/malvsheuris/c) • Howmuchdoyouwanttopayforyoursolu/on? – Howdeep/widecanyougo? • Predeterminedvsdynamic(e.g.,itera/vedeepening) – Onewayormanyways(bi-direc/onal)? • Howbigisaproblem?Canyouputthewholeworldinyourhead? – TowerofHanoi,chess,robot-and-world, • HM:statespaceforTOH,assignvaluesforstateandac/ons. HomeWork • TowerofHanio(n=3) – 1.Writethestatespace,states,ac/ons – 2.Assumethecostofanac/ontomoveadiskis theweightofthedisk,computethe“bestfuture cost”V(s0)forthestartstateusingdynamic programming Startstates0 goal Theweightofthedisk:disk1=1,disk2=2,disk3=3
© Copyright 2026 Paperzz