0% found this document useful (0 votes)
121 views73 pages

Ai Unit 02

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
121 views73 pages

Ai Unit 02

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 73
problem Solving by 2 Searching Syttabus Yi enema. by Searching : Poti sot Sop, SSeS searching for solutions, sninformed search, informed search strategies, inal * cisssleal Search : local search algorithms, searching win on-d ng with partial observations, online search agents and searching visible part of intelligence. An intelligent agent is the one who can priate action in the given situation, st approp among the available set of ac any game like chess, cards, tic-tac-loe, etc.; we know that we have ve, but the intelligent one who searches for the correct move will d { travelling salesman problem, medical diagnosis system or any do is to carry out search which will produce the optimal h min cost and efforts. Hence, this chapter focuses on the ed in Al applications. Those are known as un-informed and inforn c. In case hey required 21 Problem Solving Agents Now let ws see how searching play a vital role in solving Al problems. Given & we can generate all the possible states it can have in real time, including start end state. To generate solution for the same is nothing but teaching a path from , to end state _ Problem solving agent 1s the one who finds the goal state from start state in following the shortest path, thereby saving the memory and time. It’s supposed to ximize its performance by fulfilling all the performance measures. brching techniques can be used in game playing like Tic-Tac-Toe or navigation blems like Travelling Salesman Problem. t, we will understand the representation of given problem so that appropriate ‘ching techniques can be applied to solve the problem. Examples on Problems Searching for Solution ly work in the field of AI focused on formal tasks, like game playing, proving prems, etc. es like chess, checkers received good deal of attention, because in case of machine ponents, system was using the experience gained in previous games to improve the ves in next game. lysis, etc. it was difficult because it involved analog sy compared to digital signals. 2 lowing are some of the famous search problems WH Amica! intotigence (MU B.Sc. T-SemV)_23 ; Problem > 1. 3*3*3 Rubik's cube problem Do I need to explain the problem ? be, we have a cube with six color faces. The goal is to In Rubik's cul cuboids in such a way that each face of cube will show distinct color as Fig. 2.1.1 Fig. 2.1.1 : Rubik’s cube Problem 2. 8-Puzzle T\-|41 |-]42 5|2)6 3)4/5 8)3/1] |6}7/8 Initial State Goal State Fig. 2.1.2 condition is only the blank tile can be moved to immediate up down, right or and the goal state is to be attained in minimum number of moves. Fig. 2.1.3 : N-Queen Problem in n-queen, the queens need to be placed on the n*n board, in such a way that no queen an dash the other queen, horizontally, vertically or diagonally. Missionaries and cannibals problem In this problem, there are three missionaries and three cannibals on the same side of a river. We need to get all of them to the other side of river through a canoe which can hold maximum two people at a time. The condition is no time during the process of shifting, number of cannibals on any a the side should be greater than the number of missionaries on the same side, = r ol, me sd farmer haw olf will eat the duck and the duck will eat the = The problem is that, the w an the farmer safely transport the wolf, the are at the same side. How ci ” opposite shore? ‘corn to the opp ie fl ae Farmer, Wolf, Duck and Com Fig. 2.1.5 : The river problem From the above examples, it must be clear that AI problems are the one there are few conditions specified and the aim is to not only generate the so also to improve performance of the system; because that is where the intelli the system gets challenged. - The term intelligence includes many cognitive skills, like the ability problems, learn, interpret and understand language. - Artificial intelligence does address all of these, but more progress has the area of problem solving concepts and methods. - These techniques enable to build programs that not only find solutions able to reason about problems. ~ Problem areas of artificial intelligence are flourishing as the need for to perform day to day operations is increasing, which earlier expertise. ~ It can be observed from above sub-section that artificial intelligence very large scope. Also those artificial intelligence problems are vivid solve. 7 in > Over the decades few techniques have been developed to make the prob simple and easy to tackle. ~ Research showed that intelligence requires knowledge and knowledge less desirable properties like : © Itis enormous, © Wtis tough to characterize precisely. © Itis dynamic, i ° {Cis structured in a way that matches to the ways it will using five components as follows : Problem ean be defined formally 3, Successor function Fig. C2.2 : Components of Problems Formulation > 1. Initial state : ‘The initial state is the one in which the agent starts in, > 2. Actions: I is the set of actions that can be executed or applicable in all po description of what each action does; the formal name for this is the > 3. Successor function : Avis a function that returns a state on executing an action on the cur > 4. Goal test: explicitly but needs to be generated b implicit goal test, For example ; 'y carrying out some computations, it bination dec} chess g; In Tic-Tac-Toe game making diagonal or | Ares the winning state which can be compare ‘ame, the goal state cannot be predefined ate”, which has to be evaluated implicitly. Path cost : It is simply the cost associated with each step to be taken to reach to the goal state. To determine the cost to reach to each state, there is a cost function, which is chosen by the problem solving agent. ‘oblem solution A well-defined problem with specification of initial state, goal test, successor function, and path cost. It can be represented as a data structure and used to implement a program which can search for the goal state. A solution to a problem is a sequence of actions chosen by the problem solving agent that leads from the initial state to a goal state. Solution quality is measured by the path cost function. itimal solution An optimal solution is the solution with least path cost among all solutions. A general sequence followed by a simple problem solving agent is, first it formulates the problem with the goal to be achieved, then it searches for a sequence of actions that would solve the problem, and then executes the actions one at a time. Example of 8-Puzzle Problem Formulate &-puzzle problem Sage ae 2. 2.2.1 depicts a typical scenario of 8-puzzle problem. It has a 3 x 3 board with tiles ving | through 8 numbers on it. cre is a blank tile which can be moved forward, backward, to left and to right. The aim to arrange all the tiles in the goal state form by moving the blank tile minimum times. ‘tag > diet ¥ Artificial intelligence MU B.S0 IT -SemV) 29. Frenne L roitin tate (11,2314 8 011% 65H 2. Actions : The blank space can move in Left, Right, Up and D specifying the actions. 3. Successor function * Fig, 2.2.1, the resulting Stat 5, 6),(7, 8, 0}) ps to reach (0 the final state, if we apply “Down” operator to the ¢ has the 5 and the blank switching their po 4 Goal test : {(1, 2. 3}(4 5. Path cost : Number of ste > Solution 1.23) 14,8,01,17,6,5)) 9 123) Biot, 17,6,0)} > (11,2, 3), 14.51.7.0.61).~? Lh 3h (40 2h Rea a (7.8,6)) [11,2 3h {45.5} {7-809} Path cost = 5 steps 2.2.3 Example of Missionaries and Cannibals Problem The problem statement as discussed in the previous section. Let's formu Jate th first. States : In this problem, number of missionaries, cannibals, and canoes on thi t is (3, 3, 1), as alll missionaries, cannibals and canoes are : state can be data structure having triplet (i, ik) e left bank of the river 1, Initial state + bank of the river. g Actions : Take x number of missionaries and y number of cannibals + 3, Successor function : If we take one missionary, one cannibal the o river will have two missionaries and two cannibals left. or Goal test : Reached state (0, 0, 0) 5, Path cost : Number of crossings to attain the goal state. Solution e sequence of actions within the path : 3.1) > (2,2,0) +(3,2,1) — (3,0,0) > Gels) > (1,0) (2.21) 4 (0,1,0) > (0,2,1) + (0,0,0) Cost = 11 crossings asia Artificial Intelligence (MU B.Sc. IT -Sem-V) 2-10 Vacuum-Cleaner Problem States In vacuum cleaner problem, state can be represented as [, clean] or [, yy]. The agent can be in one of the two blocks which can be either clean or dirty. Hence re are total 8 states in the vacuum cleaner world. Initial State : Any state can be considered as initial state. For example, [A, dirty] Actions : The possible actions for the vacuum cleaner machine are left, right, absorb, idle. Successor function : Fig. 2.2.2 indicating all possible states with actions and the next state. Fig. 2.2.2 : The state space for vacuum world Goal Test : The aim of the vacuum cleaner is eee Ee if [A, Clean] and [B, Clean]. Path Cost : Assuming that each action/ step costs 1 unit cost. The ath actions/ steps taken. 5 Example of Real Time Problems There are varieties of real time problems that cant) , Robot Navigation, Rout Finding Problem, design problem, Automatic Assembly S (tificial Inte gE mn + as finding algorithms. Web sites, of applications for route i ber There are num! ag systems that prov military operations planning, nvolve detailed ant roblem to be solved by a travel planning web site; ide driving directions, ing video streams in comp and airline travel-planning systems are few to ; tems i d complex specifications. these systems For now, let us consider a pt travel problem. State : State is represented by airport location and ci also record more information about previous s urrent date and time. calculate the path cost state may flights, their fare bases and their status as domestic or international. 1. Initial state ; This is specified by the user's query, stating initial location, d time. 2. Actions : Take any flight from the current location, select seat and class, after the current time, leaving enough time for within airport transfer if 3. Successor function : After taking the action i.e. selecting fight, location, what is the next location date and time reached is denoted by the successor The location reached is considered as the current location and the flight's as the current time. 4. Goal test : Is the current location the destination location? Path cost : In this case path cost is a function of monetary cost, waiting ti time, customs and immigration procedures, seat quality, time of day, type of frequent-flyer mileage awards and so on. Measuring Performance of Problem Solving Algorithm / ‘here are variety of problem solving methods and algorithms available i ‘ing any of these algorithms in detail, let’s consider the criteria to judge the algorithms. The performance of all these algorithms can be evaluated on the lowing factors. 1. Compl 2 i i k ipleteness : If the algorithm is able to produce the solution if one Satisfies completeness criteria. ‘Time complexity : It depends on the time taken to generate the solution, It is the number of nodes generated during the search. Space complexity : Memory required to store the generated nodes while performing the search. ‘Complexity of algorithms is expressed in terms of three quantities as follows : b: Called as branching factor representing maximum number of successors node can have in the search tree. d : Stands for depth of the shallowest goal node. m : Itis the maximum depth of any path in the search tree. Node Representation in Search Tree order to carry out search, first we need to build the search tree. The nodes are the jous possible states in the state space. connectors are the indicators of which all states are directly reachable from current ite, based on the successor function. wus the parent child relation is build and the search tree can be generated. Fig. 24.1 ws the representation of a tree node as a data structure in 8-puzzle problem. cach node of the tree, we can have following structure components i State / Value : The state in the state space to which the en assigned to the node. ; Parent node : The node in the search tree that Fig. P. 2.6.1 Breadth First Search (BFS) As the name suggests, in breadth-first search tec The root node is expanded first, then all the readth First Search (BFS) Fig. 2.7.1 : Working of BFS on binary tree 2.7.3 Implementation of Breadth First Search (BFS) — In BFS we use a FIFO queue for the fringe. Because of which the newly inse the fringe will automatically be placed after their parents. — Thus, the children nodes, which are deeper than their parents, £0 to the back of and old nodes, which are shallower, get expanded first. Following is the alg same. 2.7.4 Algorithm Put the root node on a queue _ while (queue is not empty) (a) remove a node from the queue (i) if (node is a goal node) return success; — (ii) put all children of node onto the queue; 2.7.5 Performance Evaluation ~ Completeness : It is complete, provided the shallowest goal node is at some fini ~ Optimality ; It is optimal, as it always finds the shallowest solution, Time complexity : O(b*), number of nodes in the fringe. Space complexity : O(b’), total number of nodes explored. Uniform Cost Search (UCS) 28.1 Concept of Uniform Cost Search (UCcs) Uniform cost search is a breadth first search with all paths having same co work in real time conditions we can have a simple extension to the basic of BFS. This results in an algorithm that is optimal with any path cost. in BFS as we always expand the shallowest node first; but in uniform cost search, instead expanding the shallowest node, the node with the lowest path cost will be expanded rst. The implementation details are as follow. Implementation of Uniform Cost Search (UCS) niform cost search can be achieved by implementing the fringe as a priority queue dered by path cost. The algorithm shown below is almost same as BFS; except for the se of a priority queue and the addition of an extra check in case a shorter path to any ic is discovered. ¢ algorithm takes care of nodes which are inserted in the fringe for exploration, by ing a data structure having priority queue and hash table. 1¢ priority queue used here contains total cost from root to the node. Uniform cost fh gives the minimum path cost the maximum priority. The algorithm using this iority queue is the following. Algorithm sert the root node into the queue, nile the queue is not empty : ) Dequeue the maximum priority node from the queue. (If priorities are same, alphabetically smaller node is chosen) ii) If the node is the goal node, print the path and exit. Else ert all the children of the dequeued node, with their total costs as priority. s the priority queue is maintained on the basis of the total path cost of node, the gorithm never expands a node which has a cost greater than the cost of the shortest 7. the tree. ame “Uniform Cost Search”. Performance Evaluation ‘ompleteness : Completeness is guaranteed provides ome small positive constant. Optimality : It produces optimal solution as nodes are expanded in order ¢ Opt t “ cost. : me complexity Uniform-cost search considers path costs rather than. ° complexity is does not merely depends on b a d. Hence we consider C* b the optimal solution, and assume that every Se costs at least €. Then the worst-case time and space complexity is O(b ), which can be (b°"), indicating number of node in memory at execution 19: — Space complexity oO 29 Depth Limited Search (DLS) a Flow tho drawbacks of OFS are overcome DLS and a. ompare and contrast DFS, DLS and IDDF: — 2.9.1 Concept of Depth Limited Search In order to avoid the infinite loop condition arising in DFS, in depth limited technique, depth-first search is carried out with a predetermined depth limit. ‘The nodes with the specified depth limit are treated as if they don’t have any s The depth limit solves the infinite-path problem. ¥ But as the search is carried out only till certain depth in the search tre problem of incompleteness. ae — Depth-first search can be viewed as a special case of depth-limited search with de equal to the depth of the tree. The process of DLS is depicted in Fig. 2.9.1. 2.9.2 Process : If depth limit is fixed to 2, DLS carries out depth first search till second level in the iki (A) (A) A) Bo +6 d 6o ®€ & @ (0) (E) os [<2 pm PN Fig. 2.9.1 : DIS working with depth limit 2.9.3 Implementation of Depth Limited Search Asin case of DFS in DLS we can use the same fringe implemented as

You might also like