0% found this document useful (0 votes)
14 views49 pages

Ai Unit Ii

The document outlines the first unit of a syllabus on Artificial Intelligence, focusing on problem-solving agents and search algorithms. It describes the components of well-defined problems, including initial states, actions, transition models, goal tests, and path costs, while providing examples of toy and real-world problems. The document also discusses various search strategies and the structure of search algorithms used to navigate state spaces.

Uploaded by

saifurrahman8671
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)
14 views49 pages

Ai Unit Ii

The document outlines the first unit of a syllabus on Artificial Intelligence, focusing on problem-solving agents and search algorithms. It describes the components of well-defined problems, including initial states, actions, transition models, goal tests, and path costs, while providing examples of toy and real-world problems. The document also discusses various search strategies and the structure of search algorithms used to navigate state spaces.

Uploaded by

saifurrahman8671
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/ 49
AL UNIT-IL ARTIFICIAL INTELLIGENCE (19A05502T) Syllabus: UNIT-I Solving Problems by searching: Problem Solving Agents, Example problems, searching for Solutions, Uninformed Search Strategies, Informed search strategies, Heuristic Functions, Beyond Classical~Search: Local Search Algorithms and Optimization Problems, Local Search in Continues. Spaces, Searching with Nondeterministi¢ Action$ nd Searching) with-partial dbservations, online search agents and unknown environments. anne SEARCH ALGORITHMS IN ARTIFICIAL INTELLIGENCE PROBLEM SOLVING AGENTS © Goal-based agent called'a. problem-solving agent. Problem-solving agents use atomic representations * Goal-based agents that use more advanced factored or stmctured representations are usually called planning agents © Intelligent ageats are supposed to maximize their performance measure. * Achieving this is sometimes simplified if the agent can adopt a goal and aim at satisfying it ® Imagine an agent in the city of Arad, Romania, enjoying 4 touring holiday. The agent’s performance measure contains many factors: it wants to improve its suntan, improve its Romanian, take in the sights, enjoy the nightlife (such as it is) and avoid hangovers, and so on. The decision problem is a complex one involving many tradeofis and careful reading of guidebooks. * Now, suppose the agent has a nonrefundable ticket to fly out of Bucharest the following day. In that case, it makes sense for the agent to adopt the goal of getting to Bucharest. SREC,NANDYAL. Page 1 AL UNIT-IT Courses of action that don’t reach Bucharest on time ean be rejected without further consideration and the agent’s decision problem is greatly simplified, Goals help organize behavior by limiting the objectives tat the agent is trying (o achieve and hence the actions it needs to consider. Goal formulation, based on the current situation and the agent's performance measure, is the first step in problem solving. © We will consider a goal to be a set of world states—exactly those states in which the goal is satisfied. The agent’s task is to find out how to act, now and in the future, so that it reaches a goal state. Before it can do this, it needs to decide (or we need to decide on its behalf) what sorts of actions and states it should cousider, + Problem formulation is the process of deciding what aetious and states to consider, given a goal. * The process of looking for a sequence of actions that reaches the goal is called search, © A search algorithm takes a problem as imput and retums a solution in the form of an action sequence. # Once a sointion is found, the actions it recommends can he carried ont. This is called the execution phase, Well-defined problems and solutions A problem can be defined formally by five components: Initial state v vn Actions Transition model: description of what each action does (stecessor) Goal test vvy Path cost 1, INITIAL STATE: The initial state that the agent starts in. For example, the initial state for our agent in Romania might be described as In (Arad) 2. ACTIONS: A description of the possible actions available to the agent. Given a patticular states, ACTIONS returns the set of actions that can be executed in s. We say that cach of these actions is applicable in s. For example, from the state In (Arad), the applicable actions are {Go(Sibiu), Go(Timisoara), Go(Zerind)} SREC,NANDYAL. Page 2 UNIT-IL 3. SUCCESSOR: A description of what each action does; the formal name for this is the transition model, specified by a function RESULT(s, a) that returns the state that results fiom doing action a in slate s. We also use the term SUCCESSOR to refer to any state reachable from a given state by a single action 4. GOAL TEST: The goal test, which determines whether a given state is a goal state. Sometimes there is an explicit set of possible goal states, and the test simply checks whether the given state is one of them. The agent's goal in Romania is the singleton set {InBucharest)} 1 PATH COST: A path cost function that assigns a numeri¢ cost to each path. The problem-solving agent chooses a cost fimetion that reflects its own performance measure. For the agent trying to get to Bucharest, time is of the essence, so the cost of'a path might be its Jength in kilometers. The process of removing detail from a representation ABSTRACTION js called abstraction function SIMPLE-PROBLEM-SOLVING-AGENT(pereept) returns an action persistent: seq, an action sequence, initially empty state,some description of the current world state SREC,NANDYAL. Page 3 AL UNIT-IT goal, a goal, initially null problem, a problem formulation state — UPDATE-STATE (slate, percept) if seq is empty then goal FORMULATE-GOAL(6tate) problem — FORMULATE-PROBLEMGstate, goal) seq — SEARCH(problem) if seq = failure then return @ null action action — FIRST(seq) seq REST(seq) retum action EXAMPLE PROBLEMS > The problem-solving approach has been applied to a vast array of task environments. We list some of the best known here, distinguishing between toy and real-world problems, > A toy problem is intended to illustrate or exercise various problem-solving methods. Tt can be given a concise, exact description aud hence is usable by different researchers to compare the performance of algorithms > A real-world problem is one whose solutions people actually care about. Such problems tend not to have a single agreed-tipon description, but we can give the general flavor of their formulations. ‘oy problem: SREC,NANDYAL. Page 4 AL UNIT-IL ‘The first example we examine is the vacuum world This ean be formulated as a problem as follows + States: The state is determined by both the agent location and the dirt locations. The agent is in one of two locations, each of which might or might not contain dirt, Thus, there are 2 « 22 = 8 possible world states. A larger eavitonment with n locations has a 2n states. + Initial state: Any state can be designated as the initial state + Actions: In this simple environment, each state has just three actions: Leff, Right, and Suck. Larger environments might also include Up and Down. ransition model: The actions have their expected effects, except that moving Left in the leftmost square, moving Right in the rightmost square, and Sucking in a clean square have no effect. The complete state space is shown in Figure * Goal test: This checks whether all the squares are clean, + Path cost: Each step casts 1, so the path cost is the number of steps in the path. 8-puzzle The &-puzzle, an instance of which ig shown in Figure 3.4, consists of a 3x3 board with eight numbered tiles and a blank space. A tile adjacent to the blank space can slide into the space. The object is to reach a specified goal state, such as the one shown on the right of the figure. The standard formulation is as follow Figure 3.4 “States: A state description specifies the location of each of the eight tiles and the blank in one of thenine squares. SREC,NANDYAL. Page 5 AL UNIT-IT + Initial state: Any state can be designated as the initial state. Note that any given goal can be reached from exactly half of the possible initial states (Exercise 3.4). + Actions: The simplest formulation defines the actions as movements of the blank space Left, Right, up, or down. Different subsets of these are possible depending on where the blank is. + Transition model: Given a state and action, this retums the resulting state; for example, if we apply Left to the start state in Figure 3.4, the resulting state has the 5 and the blank switched + Goal test: This checks whether the state matches the goal configuration shown in Figure 3.4. (Other goal configurations are possible.) + Path cost: Each step costs 1, so the path cost is the mmber of steps in the path The 8-puzzle belongs to the family of sliding-block puzzles, which are often used as SLIDING- BLOCK PUZZLES test problems for new search algorithms in AL ‘The goal of the $-queens problem is to place eight queens on a chessboard such that no queen attacks any other. (A queen attacks any pice in the same row, column or diagonal.) Figure 3.5 shows an attempted solution that fails: the queen in the rightmost colimn is attacked by the queen at the top left queens The goal of the 8-queens problem is to place eight queens on a chessboard such that no queen attacks any other. (A queen attacks any piece in the saine row, column ot diagonal.) Figure 3.5 shows an attempted solution that fails: the queen in the rightmost column is attacked by the queen at the top left. SREC,NANDYAL. Page 6 AL UNIT-IT > Although efficient special-purpose algorithns exist for this problem and for the whole n- queens family, it remains a usefil test problem for search algorithms. There are two main kinds of formulation. An incremental formulation involves operators that augment the state description, starting with an empty state; for the 8-qneens problem, this means that each action adds a queen to the state, > A couplete-state fonmnlation starts with all 8 queens on the board aud moves them around. In either case, the path cost is of no interest because only the final state counts. The first incremental formulation one might try is the following: + States: Any arrangement of 0 to 8 queens on the board is a state. + Initial state: No queens on the board. * Actions: Add a queen to any empty square. = Transition model: Returns the board with a queen added to the specified square. + Goal test: 8 queens are on the board, none attacked, Final Toy Problem ‘Our final toy problem was devised by Donald Kanth (1964) and illustrates how infinite state spaces can arise. Knuth conjectured that, starting with the umber 4, a sequence of factorial, ‘square root, and floor operations will reach any desited positive integer. For example, we can reach 5 fiom 4 as follows. The problem definition is very simple: + States: Positive numbers. + Initial state: 4. + Actions: Apply factorial, square root, or floor operation (factorial for integers only), + Transition model: As given by the mathematical definitions of the operations. + Goal test: State is the desired positive integer. SREC,NANDYAL. Page 7 AL UNIT-IL Real-world problems © Real-world problems we have already seen how the route-finding problem is defined in terms of specified locations and transitions along links between them. © Route-finding algorithms are used in a variety of applications, ‘© Some, such as Web sites and in-car systems that provide driving directions, are relatively straightforward extensions of the Romania example. © Others, such as routing video streams in computer networks, military operations planning, and airline travel-planning systems, involve much more complex specifications. Consider the aitline travel problems that must be solved by a travel-planning Web site: “States: Each state obviously includes a location (e.g, an aitport) and the current time Furthermore, because the cost of an action (a flight segment) may depend on previous segments, their fare bases, and their status as domestic or intemationsl, the state must record extra information about these “historical” aspects. + Initial state: This is specified by the user's query. + Actions: Take any flight fiom the current location, in any seat class, leaving afier the current time, leaving enough time for within-airport trarisfer if needed. + Transition model: The state resulting from taking 4 flight will have the flight’s destination as the current location and the flight’s arrival time as the current time. + Goal test: Are we at the final destination specified by the user? + Path cost: This depends on monetary cost, Waiting time, flight time, customs and immigration procedures, seat quality, time of day, type of airplane, frequent-flyer mileage awards, and so on Touring problems are closely related to route-finding problems, but with an important difference. Consider, for example, the problem “Visit every city in Figure 3.2 at least ouce, starting and ending in Bucharest.” As with route finding, the actions correspond to trips between adjacent cities. The state space, however, is quite different. Fach state mnst inchide not just the current Jocation but also the set of cities the agent has visited. So the initial state would be In(Bucharest), Visited({Bucharest}), a typical intermediate state would te In(Vashui), SREC,NANDYAL. Page & AL UNIT-IL Visited({Bucharest, Urziceni, Vasiui}), and the goal test would check whether the agent is in Bucharest and all 20 cities have been visited. v The TRAVELING SALESPERSON PROBLEM (ISP) is a touring problem in which cach city nmst be visited exactly once: The aim is to find the shortest tour. The problem. is known to be NP-hard, but an enormous amount of effort has been expended to improve the capabilities of TSP algorithms. In addition to planning trips for traveling salespersons, these algoritlms have been used for tasks such as planning movements of automatic cireuit-board drills and of stocking machines on shop floors. VA VLST layout problem requires positioning millions of components and connections on a chip to minimize area, minimize eireuit delays, minimize stray capacitances, and maximize manufacturing yield. The layout problem comes after the logical design phase and is usually split into two parts: cell layout and channel routing © In cell layout, the primitive components of the circuit are grouped into cells, each of which performs some recognized function. Each cell has a fixed footprint (size and shape) and requires a certain number of comnections to each of the other cells. The aim is to place the cells on the chip so that they do not overlap and so that there is room for the comnecting wires to be placed between the cells. © Channel routing finds a specific route for each wire through the gaps between the ells ‘These search problems are extremely complex, but definitely worth solving. Later in this chapter, we present some algorithms capable of solving them. SREC,NANDYAL. Page 0 AL UNIT-IL ¥ ROBOT NAVIGATION is a generalization of the route-findin problem described earlier. Rather than following a discrete set of routes, a robot can move im a continuous space with (in principle) an infinite set of possible actions and states. For a circular robot moving on a flat surface, the space is essentially two-dimensional. When the robot has arms aud legs or wheels that must also be controlled, the search space becomes many- dimensional. Advanced techniques are required just to make the search space finite, In addition to the complexity of the problem, real robots aust also deal with errors in their sensor readings and motor controls. SEARCHING FOR SOLUTIONS. Search tree: generated by initial state and possible actions Basic idea: = offline, simulated exploration of state space by generating successors of already- explored states. (expanding states) a the choice of which state to expand is determined by search strategy (4) Then state (0) Aner expaning Arad aa oe Se, () After expanding Sibi igure 86 Parl seach woes hare. Nodes that een expanded are shade: no Yet expanded ae SREC,NANDYAL. Page 10 UNIT-IL TFigure39._Thescpantion propery of GRAPH -SEAKCH, vere ona estangular {black nodes) ros the wexplred pion (gray nds) f(a). the esas been finden (one lea nove hen ex In, he remsiing acest fhe ok Fane bce panded in clock wie oe. Infrastructure for search algorithms Search algorithms require a data’ structure to keep tiack of the search tree that is being constructed, For each node n of the tree, we have a structure that contains four components: + n.STATE: the state in the state space to which the node comespouds, *n.PARENT: the node in the search tree that generated this node; +n. ACTION; the action that was applied to the parent to generate the node: + nPATH-COST: the cost, traditionally denoted by g(a), of the path from the initial state to the node, as indicated by the parent pointers function CHILD-NODE(problem, parent, action) retums a node retum anode with STATE = problem. RESULT (parent STATE, action), PARENT = parent, ACTION =action, PATH-COST = parent. PATH-COST + problem STEP-COST(parent. STATE, action) SREC,NANDYAL. Page 11 AL UNIT-IL PaRenr PATuCost = 6 Figure 3.10 Nodesare the data stracture from which the search re is constructed. Each thas a parent, sate, and various bookkeeping fel. Arrows point fom child vo parent. Measuring problem-solving performance Before we get into the design of specific search algorifhitns, we need to cousider the criteria that might be used to choose among them. ‘We can evaluate an algorithm’s performance in four ways: + Completeness: Is the algorithm guaranteed to find a Solution when there is one? + Optimality: Does the strategy find the optimal solution, as defined. + Time complexity: How long does it take to find a solution? + Space complexity: How naich memory is needed to perform the search? SEARCH ALGORTHIMS In Artificial Intelligence, Search techniques are universal problem-solving methods. Rational agents or Problem-solving agents in AI mostly used these search strategies or algorithms to solve a specific problem and provide the best result. Problein-solving agents are the goal-based agents and use atomic representation. Types of search algorithms: Based on the search problems we can chssify the search algorithms into uninformed (Blind search) search and informed search (Heuristic search) algorithms. SREC,NANDYAL. Page 12 UNIT-IL Search Algorithm ‘broaatn nret eearcn {Best First Search ‘Uniform cost search Depth frst search ‘Dept limited search UNINFORMED SEARCH ALGORITHMS Uninformed search is a class of general-purpose search algorithms which operates in brute force-way. Uninformed search algorithms do not haye additional information about state or search space other than how to traverse the tree, so it is also called blind search, Following are the various types of uninformed search algorithms: LBreadth-first Searc! Breadth-first Search Depth-first Search Depth-limited Search Iterative deepening depth-first search Uniform cost search Bidirectional Search Breadth-first search is the most common search strategy for traversing a tree or graph. This algorithm searches breadth wise in a tree or graph, so it is called breadth-first search. BFS algorithm starts searching from the root node of the tree and expands all successor nodes at the current level before moving to nodes of next level. The breadth-first search algorithm is an example of a general-graph search algorithm. Breadth-first search implemented using FIFO queue data structure, SREC,NANDYAL. Page 13 AL UNIT-IL Advantages + BES will provide a solution if any solution exists. + If there is more than one solation for a given problem, then BFS will provide the minimal solution which requites the least number of steps Disadvantages: + It requires lots of memory since each level of the tree must be saved into memory to expand the next level. + BFS needs lots of time if the solution is far away trom the root node Example: In the below tree structure, we liave shown the traversing of the tree using BFS algorithm fiom the root node S to goal node K. BES search algorithm traverse in layers, so it will follow the path which is shown by the dotted arrow, and the traversed path will be Se AnD BCD 2G- HOES OF Kk, Breadth First Search — | tat er | Laver — maa + | evel ‘Time Complexity: Time Complexity of BFS algorithm can be obtained by the mumber of nodes traversed in BFS until the shallowest Node. Where the d= depth of shallowest solution and b is a node at every state T () = 14074"... D*= O (b) ‘SRECNANDYAL Page 14 AL UNIT-IT Space Complexity: Space complexity of BFS algoritlum is given by the Memory size of frontier which is O(b*) Completeness: BFS is complete, which means if the shallowest goal node is at some finite depth, then BFS will find a sohution, Optimality: BFS is optimal if path cost is a non-decreasing function of the depth of the node 2. Depth-first Seare! + Dept-first seareh is a recursive algorithm for traversing a tree or graph data structure. + It is called the depth-first search because it starts from the root node and follows each. path to its greatest depth node before moving to the next path. + DFS uses a stack data structure for its implementation. + The process of the DFS algorithm is similar to the BFS algorithm. Advantage: + DES requires very less memory as it only needs to store-a stack of the nodes on the path. from root node to the current node. «It takes less time to reach to the goal node than BFS algorithm (if it traverses in the right path). Disadvantages, + There is the possibility that many states keep re-occurring, and there is no guarantee of finding the solution. + DFS algorithm goes for deep down searching and sometime it may go to the infinite loop. Depth et Search —_ ON ® © —omm a> aero Levelt Completeness: DFS search algorithm is complete within finite state space as it will expand every node within a limited search tree. SREC,NANDYAL. Page 15 Al UNIT ‘Time Complexity: Time complexity of DFS will be equivalent to the node traversed by the algorithm. Itis given by: ‘T(n)= 1+ 1+ n° ‘Where, m= maximum depth of any node and this can be much larger than d (Shallowest + n"=O(n") solution depth) Space Complexity: DFS algorithm needs to store ouly single path fiom the root node, heace space complexity of DFS is equivalent to the size of the fiinge set, which is O(bm) ‘Optimal: DFS search algorithm is uon-optimal, as it may generate a large number of steps or high cost to reach to the goal node. 3. Depth-Limited Search Algor um: A depth-limited search algorithm is similar to depth-first search with, a predetermined limit. Depth-limited search can solve the drawback of the infinite path in the Depth-first search, In this algorithm, the node at the depth limit will treat as it has ‘to successor nodes further. Depth-limited search can be terminated with two Conditions of failure: + Standard failure value: Tt indicates that problem does not have any solution. + Cutoff failure vaiue; It defines no solution for the problem within a given depth limit. © Depth-limited search is Memory efficient. Disadvantages: + Deptivlimited search also has a disadvantage of incompleteness. + Itmay not be optimal if the problem has more than one sohution, Example; Depth Limited Search ‘SRECNANDYAL Page 16 AL UNIT-IT ‘Completeness: DLS search algorithm is complete if the solution is above the depth-Hmit. Time Complexity: Time complexity of DLS algorithm is O(9. ‘Space Complexity: Space complexity of DLS algorithm is O(bxt). Optimal: Depth-limited search can be viewed as a special case of DFS, and it is also not optimal even if (>d. Uniform-Cost Search Algorithi © Unifoxm-cost search is a searching algorithm used for traversing a weighted tree or graph. This algorithm comes into play when a different cost is available for each edge. The primary goal of the uziform-cost.search is to find apath tothe goal node which has the lowest cumulative cost ‘© Uniform-cost search exparids nodes according to their path costs fiom the root node. It can be used to solve any grapl/tree where the optiinal cost is in demand. A uniform-cost search algorithm is implemented by the priority queue-It gives maximum priority to the lowest cumulative cost. Uniform cost search is equivalent to BFS algorithm if the path cost of all edges is the same, Advantages: © Uniform cost search is optimal because at every state the path with the least cost is chosen isadvantages: © It does not care about the number of steps involve in searching and only concerned about path cost. Due to which this algorithm may be stuck in an infinite loop. ‘Uniform Cost Search (Completeness: Uniloru-cost search is complete, such as if there is a solution, UCS will fund it ‘SRECNANDYAL Page 17 AL UNIT-IL ‘Time Complexity: Let C* is Cost of the optimal solution, and ¢ is each step to get closer to the goal nocie, Then the number of steps is = C¥e+1. Here we have taken +1, as we start from state 0 and end to Cs, Hence, the worst-case time complexity of Uniform-cost search is O(b!*!¢“#y, ‘Space Complexity: The same logic is for space complexity so, the worst-case space complexity of Uniform-cost search is O(b!"*), Optimal: Uniform-cost search is always optimal as it only selects a path with the lowest path cost. Iterative Deepening Depth-First Searel ‘© The iterative deepening algorithm is-a combination of DFS and BFS algorithms. This search algorithm finds out the best depth limit and does it by gradually increasing the limit until a goal is fond. ‘* This algorithm, performs depth-first search up to a certain “depth limit", and it keeps increasing the depth limit after each iteration until the goal node is found. © This Search algorithm combines the benefits of Breadth-first search's fast search and depth-first search's memory efficiency. ‘+ The iterative search algorithm is useful uninformed search when search space is large, and depth of goal node is unknown. Advantage: + It combines the benefits of BFS and DFS search algorithm in terms of fast search and memory efficiency. Disadvantages + ‘The main drawback of IDES is that it repeats all the work of the previous phase Example: Following tree Stmeture is showing the iterative deepening depth-first seach. IDDFS algorithm performs various iterations until it does not find the goal node. The iteration performed by the algoritim is given as ‘SRECNANDYAL Page 18 AL UNIT-IL Iterative deepening depth First search A AAR A odo me @ @ ® —uas V'stlteration--->A, In the fourth iteration, the algorithm will find the goal node ‘Completeness: This algorithm is complete is if the branching factor is finite. ‘Time Complexity: Let's suppose b is the branching factor and depth is d then the worst-case time complexity is O(b'. ‘Space Complexity: The space Complexity of IDDFS will be O@A). Optimal: IDDFS algorithm is optimal if path cost is a non- decreasing function of the depth of the node. Search Algorithm: Bidirectional search algorithm runs two simultaneous searches, one form initial state called as forward-search and other from goal node called as backward-search, 10 find the goal node. Bidirectional search replaces one single search graph with two small stib-graphs in which ire one starts the search from an initial-vertex atid other starts from goal vertex. The search stops when these two graphs intersect each other Bidirectional search can use search techniques such as BFS, DFS, DLS, ete. Advantages: + Bidirectional search is fast. «Bidirectional search requires less memory sadv: i: «Implementation of the bidirectional search tree is difficult. + Inbidirectional search, one should know the goal state in advanee. ‘SRECNANDYAL Page 19 AL UNIT-IT Example: In the below search tree, bidirectional search algorithm is applied. This algorithm divides one graph/tree into (wo sub-graphs. It starts traversing from node 1 in the forward direction and starts from goal node 16 in the backward direction. The algorithm terminates at node 9 where two searches meet. ‘Completeness: Bidirectional Search is complete if we use BES in both searches ‘Time Complexity: Time complexity of bidirectional seareh using BFS is O(b') Space Complexity: Space complexity of bidirectional search is O(b'. Optimal: Bidirectional search is Optimal. INFORMED SEARCH ALGORITHMS So far we have talked about the uninformed Search algorithms which looked through search space for all possible sokutions of the. problem without having any additional knowledge about search space, But informed search algorithm contains an array of knowledge such as how far we are from the goal, path cost, how to reach to goal node, etc. This knowledge helps agents to explore less to the search space and find more efficiently the goal node The informed search algorithm is more nsefill for large search space. Informed search algorithm uses the idea of heuristic. so it is also called Heuristic search. ‘Heuristics function: Heuristic is a fiction which is used in Informed Search, and it finds the most promising path. It takes the current state of the agent as its input and produces the estimation of how close agent is from the goal. The heuristic method, however, might not always give the best solution, but it guaranteed to find a good solution in reasonable time. Heuristic function estimates how close a state is to the goal. It is represented by h(n), and it calculates the cost of an optimal path between the pair of states. The value of the heuristic fimetion is always positive, SREC,NANDYAL. Page 20 AL UNIT-IT Admissibility of the heuristic fimetion is given as: h(a) < en) Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost should be less than or equal to the estimated cost. Searcl Pure Hew Pure heuristic search is the simplest form of heuristic search algorithms It expands nodes based on their heuristic value h(a). It maintains two lists, OPEN and CLOSED list. In the CLOSED list, it places those nodes which have already expanded and in the OPEN list, it places nodes which have yet not been expanded. On each iteration, each node /n with the lowest heuristic value is expanded and generates all its successors and n is placed to the closed list. The algorithm continues unita goal state is found. In the informed search we will discuss two main algorithms Which are given below. © Best First Search Algorithm(Greedy search) © A* Search Algorithm: Best-first Search Algorithm (Greedy Search): Greedy best-iirst seatch algorithm always selects the path which appears best at that moment. It is the combination of depth-first search and breadthi-first search algorithms. It uses the heuristic function and search. Best-first search allows us to take the advantages of both algorithms. With the help of best-first search, at each step, we can choose the most promising, node. In the be&t first search algorithm, we expand the node which is closest to the goal node and the closest cost is estimated by heuristic function, Le La) 2a). ‘Were, h(n)= estimated cost from node n to the goal. ‘The greedy best first algorithm is implemented by the priority queue. Best first search algorithm: + Step 1: Place the starting node into the OPEN list. + Step 2: Ifthe OPEN list is empty, Stop and return failure, + Step 3: Remove the node n, from the OPEN list which has the lowest valve of h(a), and places it in the CLOSED list. ‘SRECNANDYAL Page 21 AL UNIT-IT + Step 4: Expand the node n, and generate the successors of node 1 + Step &: Check each successor of node n, and find whether any node is a goal node or not. If any successor node is goal node, then retun success and (erminate the search, else proceed to Step 6. + Step 6: For each successor node, algorithm checks for evaluation function f(n), and then check if the node has been in either OPEN or CLOSED list. Ifthe node has not been in both list, then add it to the OPEN list. «Step 7: Retum to Step 2. Advantage + Best first search can switch between BES and DFS by gaining the advantages of both the algorithms. + This algorithm is more efficient than BFS and DFS algorithms. Disadvantages: + Itcan behave as an unguided depth-first search in the worst ease scenatio + Itcan get stuck in a loop as DFS. + This algorithm is not optimal. Example: Consider the below search problem, and we will averse it using greedy best-first search. At cach iteration, each node is expanded using evaluation function f(n)=h(n) , which is given in the below table. ® mode |) tay x al eZ |e]: J fN |h | @oelil: In this search example, we are using two lists which are OPEN and CLOSED Lists. Following are the iteration for traversing the above example. SREC,NANDYAL. Page 22 AL UNIT-IL 12) Expand the nodes of 8 and put in the CLOSED list Initialization: Open [A, B], Closed [S} Iteration 1; Open [A], Closed [5, B] Iteration2: Open{E,F,A],Closed|S,B] Open [E, A], Closed [S, B,F] Tteration3: Open[I,G,E,A],Closed|S,B,F} Open [I, E, A], Closed [S, B, F, G] Hence the final solution path will be: S—> B-—>F-—> G Time Complexity: ‘The worst case time complexity of Greedy best first search is O(b"». Space Complexit ‘Where, m is the maximum depth of the search space. fhe worst case space complexity’ of Greedy best first search is O(b") ‘Complete: Greedy best-first search is also incomplete, even if the given state space is finite, Optimal: Greedy best first search algorithm is not optimal. Search Algorithm: A* search is the most commonly known form of best-first search. Tt uses heuristic function h(n), and cost to reach the node 1 from the start state-g(n). It has combined features of UCS and greedy best-first search, by which it solve the problem efficiently. A* search algorithm, finds the shortest path through the seatch space using the heuristic function, This search algorithm expands less search tree and provides optimal result faster. A* algorithm is similar to UCS except that it uses g(a) h(n) instead of g(u). ‘SRECNANDYAL Page 23 AL UNIT-IL In A* search algorithm, we use search heuristic as well as the cost to reach the node. Hence we can combine both costs as following, and this sum is called asa fitness umber. Alo) = elm) + lo) N Algorithm of A* search: * Step!: Place the starting node in the OPEN list. + Step 2: Check if the OPEN list is empty or not, ifthe list is empty then Tetum failure and stops. + Step 3: Select the node from the OPEN list which has the stuallest value of evaluation finction (qth), iftnode n i goal node then return success and!sfop, otherwise + Step 4: Expand node u and generate all ofits successors, and put n inte the closed lst, For exch successor m’, check Whether 1! is already in the OPEN or CLOSED list, if not then compute evaluation fimetion for n' and place into Open list. * Step 5: Else if node n’ is already in OPEN and CLOSED, then it should be attached to the back pointer which reflects the lowest g(t) value «Step 6: Return to Step 2. Advantages: + A* search algorithm is the best algorithm than other search algorithins. « A* search algorithm is optimal and complete. + This algorithm can solve very complex problems. Disadvantages: ‘+ It does not always produce the shortest path as it mostly based on heuristics and approximation. + A* search algorithm has some complexity issues. ‘+The main drawback of A* is memory requirement as it keeps all generated nodes in the memory, so it is not practical for various large-scale problems. Example: ‘SRECNANDYAL Page 24

You might also like