770 likes | 1.16k Views
SOLVING PROBLEMS BY SEARCHING. by Gülce HANER. Outline. Problem- solving agents Example problems (Toy problems & Real world problems ) Searching for solutions Uninformed search strategies Avoiding repeated states Searching with partial information. 3.1 PROBLEM SOLVING AGENTS.
E N D
SOLVING PROBLEMS BY SEARCHING byGülce HANER
Outline • Problem-solvingagents • Exampleproblems (Toy problems & Real worldproblems) • Searchingforsolutions • Uninformedsearchstrategies • Avoidingrepeatedstates • Searchingwithpartialinformation
3.1 PROBLEM SOLVING AGENTS • Onekind of a goal-basedagent. (Goalbasedagent:considersfutureactionsandthedesirability of theiroutcomes.) • Decideswhatto do byfindingsequences of actionsthatleadtodesirablestates. • Intelligent agents are supposed to maximize their performance measures. • Achieving this is sometimes simplified if the agent can adopt a goal and aim at satisfying it. Why and how an agent might do this?
Example: • Suppose we have an agent in the City of Arad, Romania enjoying a touring holiday. • With performance measures containing many factors: -Improve suntan -Improve Romanian -Take the sights .... • The decision problem is a complex one with many tradeoffs.
Examplecont. • Now suppose the agent has a nonrefundable ticket to fly out of Bucharest the following day. • Than it makes sense for the agent to adopt the goal of getting to Bucharest. • By adopting this goal, - Theagentrejects the actions that don’t reach Bucharest on time. - Thus, theagent’s decision problem is greatly simplified.
Goalformulation • Goalshelp organize behaviorbylimitingtheobjectivesthattheagent is tryingtoachieve. • Theagent’stask is tofindoutwhichsequence of actionswillget it to a goalstate • Goalformulation, based on thecurrentsituationandtheagent’sperformancemeasure, is thefirst step in problem solving.
Problem formulation • Problem formulation: theprocess of decidingwhatactionsandstatestoconsider , given a goal. • in theexample -actions: drivingfromonemajortowntoanother -states: being in a particulartown
“Formulate,search,execute” • Theprocess of lookingfor a sequencethatleadsto a goalstate is calledsearch. • A searchalgorithmtakes a problem as inputandreturns a solution in the form of an actionsequence. • Once a solution is found, theactions it recommends can be carriedout. This is calledtheexecutionphase. • Thus, wehave a simple “formulate, search, execute” designfortheagent.
Assumptionsforenvironment • Assumptionsfortheenvironment of agentdesign in figure 3.1 are: • Static : withoutpayingattentiontoanychangesthatmight be occuring in theenvironment. • Observable • Discrete: “alternativecourses of action” can be enumerated • Deterministic: No unexpectedevents • Alltheseasumptionsmeanthatwearedealingwiththeeasiestkinds of environments.
Welldefinedproblemsandsolutions • Goal formulation is the first step in problem solving. • Then we need the problem formulation which is defined by four components: -Initialstate -Successor function (oroperator) -Goal test -Pathcost
Components of a problem formulation 1-Initialstate The state that the agent starts in. -ex: in(Arad) 2-Successorfunction -Given a particularstatex SUCCESSOR-FN(x)returns a set of <action,successor> orderedpairs -Ex: Fromstate in(Arad) successorfunctionreturns: {<Go(Sibiu),In(Sibiu)>,<Go(Zerind),In(Zerind)>, Go(Timisoara),In(Timisoara)>}
Components of a problem formulation 3-Goal test -Determineswhether a givenstatex is a goalstate. “x=in(Bucharest)” Goalstates can be either -explicit “in(Bucharest)” -abstractproperty “checkmate” in chess 4-Pathcost -A functionthatassigns a numericcosttoeachpath. -Sum of step costs c(x, a, y) > 0
Statespace, path • Together, theinitialstateandsuccessorfunctionimplicitly define thestatespace of the problem • -the set of allstatesreachablefromtheinitialstate. • Thestatespaceforms a graph in whichthenodesarestatesandthearcsbetweennodesareactions. • A path in thestatespace is a sequence of statesconnectedbysequences of actions.
Solutionquality, optimal solution • A solutionto a problem is a pathfromtheinitialstateto a goalstate. • Solutionqualityis measuredbythepathcostfunctionand an optimal solutionhas thelowestpathcostamongallsolutions.
Formulatingproblems • Wepreviouslyproposed a formulation of the problem gettingtoBucharest in terms of initialstate, successorfunction, goal test andpathcost. • Thisformulationseemsreasonable, yet it ommits a greatmanyaspects of therealworld. • A state of realworldincludesmoredetail, comparedtothesimplestatedescription “in(Bucharest)”. (detailslike, travelingcompanions, condition of theroad, what is on theradio, theweatheretc.)
Abstraction • Someconsiderationsareleftout of ourstatedescriptions, becausetheyareirrelevantto the problem of finding a routetoBucharest. • Theprocess of removingdetailfrom a representation is calledabstraction. Abstraction can be usedfor -statedescriptions -actions
Choice of a goodabstraction • Abstraction is validifwe can expandanyabstractsolutioninto a solution in themoredetailedworld. • Abstraction is usefulifcarryingouteach of theactions in thesolution is easierthantheoriginal problem. • For a goodabstraction: -remove as muchdetail as possible -retainingvalidity - ensureabstractactionsareeasytocarryout
Outline • Problem-solvingagents • Exampleproblems (Toy problems & Real worldproblems) • Searchingforsolutions • Uninformedsearchstrategies • Avoidingrepeatedstates • Searchingwithpartialinformation
3.2 EXAMPLE PROBLEMS • Toy problem -Intendedtoillustrateorexercisevarious problem-solvingmethods. -Concise, exactdescription -Can be usedtocompareperformance of algorithms • Real-world problem -Whosesolutionspeopleactuallycareabout -Theytend not tohave a singleagreedupondescription
Some toy problems Vacuumworld -States: location of theagent, containingdirtor not. possibleworldstates. -Initialstate: anystate -Successorfunction: legal statesthatresultfromthreeactions (Left,RightandSuck) -Goalstate: checkswhetherallthesquaresareclean. -Pathcost: # of steps in thepath (each step costs 1)
Some toy problems Statespaceforthevacuumworld
An instance 8-Puzzle • Consist of a 3x3 board with 8 numberedtilesand a blankspace. • Tileadjacenttotheblankspace can slideintothespace • Object: reach a specifiedgoalstate
Formulation of 8-puzzle • Statespace: location of each of theeighttilesandtheblank • Initialstate: Anystate • Successor function: states resulting from trying the four actions(blank moves left, right, up or down) • Pathcost: number of steps in thepath • 8-puzzlebelongstothefamily of slidingblockpuzzles • This general class is knownto be NP-complete • 9!/2=181,440 reachablestatesandeasilysolved
8-queens problem • Place 8-queens on a chessboardsuchthat no queenattacksanyother. • Twomainkinds of formulation 1- Complete-stateformulation Startswithall 8 queens on the board andmovesthemaround.
8-queens problem 2-Incrementalformulation: -States: Anyarrangement of 0 to 8 queens on the board -Initialstate: no queens on the board -Successorfunction: Add a queentoanyemptysquare -Goal test: 8 queensare on the board, noneattacked. ( possiblestatestoinvestigate.)
8-queens problem • Prohibitplacing a queen in anysquarethat is alreadyattacked(a betterformulation) -States: Arrangements of n queens(), onepercolumn in theleftmost n columns, with no queenattackinganother -Successorfunction: add a queentoanysquare in theleftmostemptycolumnsuchthat it is not attackedbyanyotherqueen (Reducesstatespacefromtojust 2,057 )
Real worldproblems • Some of the real world problems are, -Route finding problem -Touring problems -Travelling salesperson problem -VLSI layout problem -Robot navigation -Automatic assembly sequencing -Internet searching
Route finding problem • Used in a variety of applications -routing in computer networks, military operations planning, and airline travel planning systems etc. • Typically complex to specify
A simplified example of an airline travel problem: -States: Location (e.g., an airport) and the current time -Initial state: Specified by the problem -Successor function: States resulting from taking any scheduled flight (seat class and location), leaving later than the current time. -Goal test: Are we at the destination by some prespecified time? -Path cost: Depends on monetary cost , waiting time, flight time, seat quality and so on. -many additional complications to handle byzantine structure that airlines impose -Contingency plans should also be included
Touring problems • Closely related to route-finding problems • Ex: “Visit every city at least once, starting and ending at Bucharest” • Important differences , • States: “current location, set of cities the agent has visited” -Ex: in Vaslui; visited{Bucharest, Urziceni, Vaslui} • Initial state: “In Bucharest; visited(Bucharest)” • Goal test: -Is the agent in Bucharest? -Visited all cities?
Traveling salesperson problem (TSP) • A touring problem in which -Each city must be visited exactly once • Aim: Find the shortest tour • Knowns to be NP-hard
Outline • Problem-solvingagents • Exampleproblems (Toy problems & Real worldproblems) • Searchingforsolutions • Uninformedsearchstrategies • Avoidingrepeatedstates • Searchingwithpartialinformation
3.3 SEARCHING FOR SOLUTIONS • Havingformulatedsomeproblems, wenowneedtosolvethem. • This is done by a searchthroughthestatespace. • Thischapterdealswithsomesearchtechniquesthatuse an explicitsearchtree.
Problem: find a routefromAradtoBucharest. -Expanding : Applyingsuccessorfunctiontothecurrentstate, therebygenerating a new set of states. -Thechoice of whichstatetoexpand is determinedbythesearchstrategy. -When a goalstatefound, thesolutionis sequence of actionsfromgoalnodebacktotheroot. Partialsearchtrees -Frontier: a queuethat storesthe set of nodeswhicharegenerated but not yet expanded
Representation of nodes • A node is a data structurewithfivecomponents -State:thestate in thestatespacethatthenodecorresponds -Parent-node: thenode in thesearchtreethatgeneratedthisnode -Action: theactionthatwasappliedtotheparenttogeneratethenode -Path-cost: cost of thepathfrominitialstatetothenode -Depth: Thenumber of stepsalongthepathfromtheroot. • Node: bookkeeping data structuretorepresent a searchtree • -State: correspondstotheconfiguration of theworld
Measuring problem-solvingperformance Evaluation of an algorithm’sperformance • Completeness: Is the alg. guaranteedtofind a solutionwhenthere is one? • Optimality:Doesthestrategyfindsthe optimal solution • Time complexity: Howlongdoes it taketofind a solution? • Spacecomplexity:Howmuchmemory is neededtoperformthesearch?
Measuring problem-solving performance • Time and space complexity are always considered with respect to some measure of the problem difficulty. • In AI, complexity is expressed in terms of three quantities: - b, the branching factor, max number of successors at any node - d, the depth of the shallowest goal node - m, the maximum length of any path in the state space • Time is often measured in terms of number of nodes generated during search. • Space is meausured in terms of the maximum number of nodes stored in memory.
Assessingthe efectiveness of an alg. • Search cost • depends on the time complexity • can also include a term for memory usage • Total cost - combines the search cost and the path cost of the solution found
Outline • Problem-solvingagents • Exampleproblems (Toy problems & Real worldproblems) • Searchingforsolutions • Uninformedsearchstrategies • Avoidingrepeatedstates • Searchingwithpartialinformation
3.4 UNINFORMED SEARCH STRATEGIES • Also called blind search • No additional information about states beyond that provided in the problem definition • All they can do is generate successors and distinguish a goal state from a nongoal state. • Strategies that know whether a nongoal state is “more promising” than another are called informed search or heuristic search strategies.
UNINFORMED SEARCH STRATEGIES 1-Breadth-first search • The root node is expanded first, then all the successors of the root node are expanded next, then their successors, and so on. • Can be implemented by TREE-SEARCH with an empty frontier which is a first-in-first-out (FIFO) queue • FIFO queue puts all the newly generated successors at the end of the queue, which means that shallow nodes are expanded before deeper nodes.
Breadth-first search • Complete (provided the branching factor b is finite) • The shallowest goal node is not necessarily the optimal one. (optimal if all actions have the same cost) • Time complexity : -Suppose every state has b successors and the solution is at depth d -The total number of nodes generated in the worst case is : • Space complexity : - Every node that is generated must remain in memory. -the same as time complexity:
Breadth-first search • In general, exponential-complexity search problems cannot be solved by uninformed search methods for any but the smallest instances.
2-Uniform-cost search • Expands the node n with the lowest path cost. • Guided by path costs rather than depths • Let be the cost of optimal solution, and assume every action costs at least . • Time and space complexity in the worst case is which can be much larger than .
Uniformcostsearch • Guaranteescompletenessifevery ( : a smallpositiveconstant) -Otherwise (ifsome step cost=0) it can getstuck in an infiniteloop • condition is alsosufficienttoensureoptimality.
3-Depth-first search • Thesearchproceedsimmediatelytothedeepestlevel of the • searchtree, wherethenodeshave no successors • then “backesup” tothenextshallowestnodethatstill has • unexplorednodes. • Alwaysexpandsthe deepest node in the current frontier of the search tree. • Can be implementedbyTREE-SEARCH with an emptyfrontierwhich is a last-in-first-outqueue (stack)
Depth-firstsearch • Spacecomplexity: -Requiresstorage of onlybm+1nodes b:branchingfactor, m:maximum depth • Wouldrequire 118 kilobytesinstead of 10 petabytes at depth d=12 (a factor of 10 billiontimeslessspace) • Not alwaysoptimal (Ex. Goalnodes: J andC) • Not complete: wouldneverterminateiffirstlychoosensubtreewereunboundeddepth but contained no solution. • Time complexity: -m can be muchlargerthand