0% found this document useful (0 votes)
37 views21 pages

Ai - Unit-1

Uploaded by

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

Ai - Unit-1

Uploaded by

poojithdev131149
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

III Year CSE II Sem Artificial Intelligence Unit II

UNIT –2 :Problem Solving: State-Space Search and Control Strategies:


Introduction, General Problem Solving, Characteristics of Problem, Exhaustive
searches, heuristic search techniques, iterative deepening a*, Constraint
Satisfaction

Problem Reduction and Game Playing: Introduction, problem reduction,


game playing, alpha-beta pruning, two-player perfect information games

2. Problem Solving – Basic Search

methods Problem Characteristics

 Heuristic search is a very general method applicable to a large class of


problem.

 In order to choose the most appropriate method (or combination of


methods) for a particular problem it is necessary to analyze the problem
along several key dimensions.

 Is the problem decomposable into a set of independent smaller sub


problems?

 Decomposable problems can be solved by the divide-and-


conquer technique.

 Use of decomposing problems:

 Each sub-problem is simpler to solve.

 Each sub-problem can be handed over to a different processor.


Thus can be solved in parallel processing environment.

 There are non decomposable problems.

 For example, Block world problem is non decomposable.

2.1. Problem Solving

 AI programs have a clean separation of

 computational components of data,

 operations & control.

 Search forms the core of many intelligent processes.

Page 1
III Year CSE II Sem Artificial Intelligence Unit II

 It is useful to structure AI programs in a way that facilitates describing


the search process.

Production System – PS

 PS is a formation for structuring AI programs which facilitates describing


search process.

 It consists of

 Initial or start state of the problem

 Final or goal state of the problem

 It consists of one or more databases containing information


appropriate for the particular task.

 The information in databases may be structured

 using knowledge representation schemes.

Production Rules

 PS contains set of production rules,

 each consisting of a left side that determines the applicability of


the rule and

 a right side that describes the action to be performed if the rule is


applied.

 These rules operate on the databases.

 Application of rules change the database.

 A control strategy that specifies the order in which the rules will be
applied when several rules match at once.

 One of the examples of Production Systems is an Expert System.

Advantages of PS

 In addition to its usefulness as a way to describe search, the production


model has other advantages as a formalism in AI.

 It is a good way to model the strong state driven nature of


intelligent action.

Page 2
III Year CSE II Sem Artificial Intelligence Unit II

 As new inputs enter the database, the behavior of the system


changes.

 New rules can easily be added to account for new situations


without disturbing the rest of the system, which is quite important
in real-time environment.

Example : Water Jug Problem

 Problem statement:

 Given two jugs, a 4-gallon and 3-gallon having no measuring


markers on them. There is a pump that can be used to fill the jugs
with water. How can you get exactly 2 gallons of water into 4-
gallon jug.

 Solution:

 State for this problem can be described as the set of ordered pairs
of integers (X, Y) such that

 X represents the number of gallons of water in 4-gallon jug


and

 Y for 3-gallon jug.

 Start state is (0,0)

 Goal state is (2, N) for any value of N.

Production Rules

 Following are the production rules for this problem.

Page 3
III Year CSE II Sem Artificial Intelligence Unit II

R6: (X, Y | X+Y >= 3  X > 0)  (X – (3 – Y), 3)

{Pour water from 4-gallon jug into 3-


gallon jug until 3-gallon jug is full}

R7: (X, Y | X+Y <= 4  Y > 0)  (X+Y, 0)

{Pour all water from 3-gallon jug into


4-gallon jug }

R8: (X, Y | X+Y <= 3  X > 0)  (0, X+Y)

{Pour all water from 4-gallon jug into


3-gallon jug }

Superficial Rules: {May not be used in this problem}

R9: (X, Y | X > 0)  (X – D, Y)

{Pour some water D out from 4-gallon jug}

R10: (X, Y | Y > 0)  (X, Y - D)

{Pour some water D out from 3- gallon jug}

Page 4
III Year CSE II Sem Artificial Intelligence Unit II

Trace of steps involved in solving the water jug problem - First solution

Trace of steps involved in solving the water jug problem - Second


solution

 Note that there may be more than one solutions.

 For each problem

 there is an initial description of the problem.

Page 5
III Year CSE II Sem Artificial Intelligence Unit II

 final description of the problem.

 more than one ways of solving the problem.

 a path between various solution paths based on some criteria of


goodness or on some heuristic function is chosen.

 there are set of rules that describe the actions called production
rules.

 Left side of the rules is current state and right side describes
new state that results from applying the rule.

 Summary: In order to provide a formal description of a problem, it is


necessary to do the following things:

 Define a state space that contains all the possible configurations of


the relevant objects.

 Specify one or more states within that space that describe possible
situations from which the problem solving process may start.
These states are called initial states.

 Specify one or more states that would be acceptable as solutions to


the problem called goal states.

 Specify a set of rules that describe the actions. Order of application


of the rules is called control strategy.

 Control strategy should cause motion towards a solution.

2.2 Control Strategies

 Control Strategy decides which rule to apply next during the process of
searching for a solution to a problem.

 Requirements for a good Control Strategy

 It should cause motion

In water jug problem, if we apply a simple control strategy of starting


each time from the top of rule list and choose the first applicable one, then we
will never move towards solution.

Page 6
III Year CSE II Sem Artificial Intelligence Unit II

 It should explore the solution space in a systematic manner

If we choose another control strategy, say, choose a rule randomly from


the applicable rules then definitely it causes motion and eventually will lead to
a solution. But one may arrive to same state several times. This is
because control strategy is not systematic.

Page 7
III Year CSE II Sem Artificial Intelligence Unit II

Page 8
III Year CSE II Sem Artificial Intelligence Unit II

Traveling Salesman Problem

 Consider 5 cities.

 A salesman is supposed to visit each of 5 cities.

 All cities are pair wise connected by roads.

 There is one start city.

 The problem is to find the shortest route for the salesman who has
to

 visit each city only once and

 returns to back to start city.

 A simple motion causing and systematic control structure could, in


principle solve this problem.

 Explore the search tree of all possible paths and return the shortest
path.

 This will require 4! paths to be examined.

Page 9
III Year CSE II Sem Artificial Intelligence Unit II

 If number of cities grow, say 25 cities, then the time required to wait a
salesman to get the information about the shortest path is of 0(24!)
which is not a practical situation.

 This phenomenon is called combinatorial explosion.

 We can improve the above strategy as follows:

 Begin generating complete paths, keeping track of the shortest


path found so far.

 Give up exploring any path as soon as its partial length becomes


greater than the shortest path found so far.

 This algorithm is efficient than the first one, still requires


exponential time  some number raised to N (number of cities).

a. Missionaries and Cannibals

 Problem Statement: Three missionaries and three cannibals want to cross


a river. There is a boat on their side of the river that can be used by
either one or two persons.

 How should they use this boat to cross the river in such a way that
cannibals never outnumber missionaries on either side of the
river? If the cannibals ever outnumber the missionaries (on either
bank) then the missionaries will be eaten. How can they all cross
over without anyone being eaten?

 PS for this problem can be described as the set of ordered pairs of left
and right bank of the river as (L, R) where each bank is represented as a
list [nM, mC, B]

 n is the number of missionaries M, m is the number of cannibals


C, and B represents boat.

 Start state: ( [3M, 3C, 1B], [0M, 0C, 0B] ),

 1B means that boat is present and 0B means it is not there on the


bank of river.

 Goal state: ( [0M, 0C, 0B], [3M, 3C, 1B] )

Page 10
III Year CSE II Sem Artificial Intelligence Unit II

 Any state: ([n1M, m1C, 1B], [n2 M, m2 C, 0B]) , with


constraints/conditions as n1 (0) ≥ m1; n2 (0) ≥ m2; n1 + n2 = 3, m1 +
m2 = 3

 By no means, this representation is unique.

 In fact one may have number of different representations for the


same problem.

 The table on the next slide consists of production rules based on


the chosen representation.

Page 11
III Year CSE II Sem Artificial Intelligence Unit II

2.3 State Space Search for Solving problems

 State space is another method of problem representation that facilitates


easy search similar to PS.

 In this method also problem is viewed as finding a path from start state
to goal state.

 A solution path is a path through the graph from a node in a set S to a


node in set G.

 Set S contains start states of the problem.

 A set G contains goal states of the problem.

 The aim of search algorithm is to determine a solution path in the graph.

 A state space consists of four components.

 Set of nodes (states) in the graph/tree. Each node represents the


state in problem solving process.

Page 12
III Year CSE II Sem Artificial Intelligence Unit II

 Set of arcs connecting nodes. Each arc corresponds to operator


that is a step in a problem solving process.

 Set S containing start states of the problem.

 Set G containing goal states of the problem.

2.3.1. The 8-Puzzle

Problem Statement:

 The eight puzzle problem consists of a 3 x 3 grid with 8 consecutively


numbered tiles arranged on it.

 Any tile adjacent to the space can be moved on it.

 Solving this problem involves arranging tiles in the goal state from
the start state.
Start state Goal state

3 7 6 5 3 6

5 1 2 7 2

4 8 4 1 8

Solution by State Space method

 The start state could be represented as: [ [3,7,2], [5,1, 2], [4,0,6] ]

 The goal state could be represented as: [ [5,3,6] [7,0,2], [4,1,8] ]

The operators can be thought of moving {up, down, left, right}, the direction in
which blank space effectively moves.

Page 13
III Year CSE II Sem Artificial Intelligence Unit II

Initial State

3 7 6
5 1 2
6 8

up left right
3 7 6 3 7 6 3 7 6
5 2 5 1 2 5 1 2
6 1 8 6 8 6 8

up left right
3 6 3 7 6 3 7 6
5 7 2 5 2 5 2
6 1 8 6 1 8 6 1 8

Searching for a Solution

 Problem can be solved by searching for a solution.

 Transform initial state of a problem into some final goal state.

 Problem can have more than one intermediate states between start and
goal states.

 All possible states of the problem taken together are said to form

 a state space or

 problem state and

 search is called state space search.

 Search is basically a procedure to discover a path through a problem


space from initial state to a goal state.

 There are two directions in which such a search could proceed.

 Data driven search, forward, from the start state

Goal driven search, backward, from the goal state

Page 14
III Year CSE II Sem Artificial Intelligence Unit II

2.3.2. Forward Reasoning (Chaining):

 It is a control strategy that starts with known facts and works towards a
conclusion.

 For example in 8 puzzle problem, we start from initial state to goal state.

 In this case we begin building a tree of move sequences with initial state
as the root of the tree.

 Generate the next level of the tree by finding all rules whose left
sides match with root and use their right side to create the new state.

 Continue until a configuration that matches the goal state is generated.

 Language OPS5 uses forward reasoning rules. Rules are expressed in the
form of “if-then rule”.

 Find out those sub-goals which could generate the given goal.

2.3.3. Backward Reasoning (Chaining)

 It is a goal directed control strategy that begins with the final goal.

 Continue to work backward, generating more sub goals that must also be
satisfied in order to satisfy main goal.

 Prolog (Programming in Logic) uses this strategy.

2.4. General Purpose Search Strategies:

 Breadth First Search (BFS)

 It expands all the states one step away from the initial state, then
expands all states two steps from initial state, then three steps
etc., until a goal state is reached.

 It expands all nodes at a given depth before expanding any nodes


at a greater depth.

 All nodes at the same level are searched before going to the next
level down.

 For implementation, two lists called OPEN and CLOSED are


maintained.

Page 15
III Year CSE II Sem Artificial Intelligence Unit II

 The OPEN list contains those states that are to be expanded


and CLOSED list keeps track of states already expanded.

 Here OPEN list is used as a queue.

Algorithm (BFS)

Input: Two states in the state space START and GOAL

Local Variables: OPEN, CLOSED, STATE-X, SUCCS

Output: Yes or No

Method:

• Initially OPEN list contains a START node and CLOSED list is empty;
Found = false;

 While (OPEN  empty and Found = false)

Do {

 Remove the first state from OPEN and call it STATE-X;

 Put STATE-X in the front of CLOSED list;

 If STATE-X = GOAL then Found = true else

{- perform EXPAND operation on STATE-X, producing a list of


SUCCESSORS;

- Remove from successors those states, if any, that are in the


CLOSED list;

- Append SUCCESSORS at the end of the OPEN list /*queue*/

} } /* end while */

If Found = true then return Yes else return No and Stop

Depth-First Search

 In depth-first search we go as far down as possible into the search tree /


graph before backing up and trying alternatives.

 It works by always generating a descendent of the most recently


expanded node until some depth cut off is reached

Page 16
III Year CSE II Sem Artificial Intelligence Unit II

 then backtracks to next most recently expanded node and


generates one of its descendants.

 So only path of nodes from the initial node to the current node is stored
in order to execute the algorithm.

 For implementation, two lists called OPEN and CLOSED with the same
conventions explained earlier are maintained.

 Here OPEN list is used as a stack.

 If we discover that first element of OPEN is the Goal state, then


search terminates successfully else move it to closed list and stack
its successor in open list.

Algorithms (DFS)

Input: Two states in the state space, START and GOAL

LOCAL Variables: OPEN, CLOSED, RECORD-X, SUCCESSORS

Output: A path sequence if one exists, otherwise return No

Method:

 Form a stack consisting of (START, nil) and call it OPEN list. Initially set
CLOSED list as empty; Found = false;

 While (OPEN  empty and Found = false) DO

• Remove the first state from OPEN and call it RECORD-X;

• Put RECORD-X in the front of CLOSED list;

• If the state variable of RECORD-X= GOAL,

then Found = true

Else

{ - Perform EXPAND operation on STATE-X, a state


variable of RECORD-X, producing a list of action records called
SUCCESSORS; create each action record by associating with each
state its parent.

Page 17
III Year CSE II Sem Artificial Intelligence Unit II

- Remove from SUCCESSORS any record whose state


variables are in the record already in the CLOSED list.

- Insert SUCCESSORS in the front of the OPEN list


/* Stack */

}/* end while */

 If Found = true then return the plan used /* find it by tracing through
the pointers on the CLOSED list */ else return No

 Stop

Comparisons

 DFS

 is effective when there are few sub trees in the search tree
that have only one connection point to the rest of the states.

 can be dangerous when the path closer to the START and farther
from the GOAL has been chosen.

 Is best when the GOAL exists in the lower left portion of the search
tree.

 Is effective when the search tree has a low branching factor.

 BFS

 can work even in trees that are infinitely deep.

 requires a lot of memory as number of nodes in level of the tree


increases exponentially.

 is superior when the GOAL exists in the upper right portion of a


search tree.

Depth First Iterative Deepening (DFID)

 DFID is an iterative method that expands all nodes at a given depth


before expanding any nodes at greater depth.

Page 18
III Year CSE II Sem Artificial Intelligence Unit II

 For a given depth d, DFID performs a DFS and never searches deeper
than depth d and d is increased by 1 in next iteration if solution is not
found.

 Advantages:

 It takes advantages of both the strategies (BFS & DFS) and suffers
neither the drawbacks of BFS nor of DFS on trees

 It is guaranteed to find a shortest - length (path) solution


from initial state to goal state (same as BFS).

 Since it is performing a DFS and never searches deeper than depth


d. the space it uses is O(d) (same as DFS).

 Disadvantages:

 DFID performs wasted computation prior to reaching the goal


depth but time complexity remains same as that of BFS and DFS

2.5. Various Heuristic Searches:

Heuristic Search

 Heuristics are criteria for deciding which among several alternatives be


the most effective in order to achieve some goal.

 Heuristic is a technique that

 improves the efficiency of a search process possibly by sacrificing


claims of systematicity and completeness.

 It no longer guarantees to find the best answer but almost always


finds a very good answer.

 Using good heuristics, we can hope to get good solution to hard


problems (such as travelling salesman) in less than exponential
time.

 There are general-purpose heuristics that are useful in a


wide variety of problem domains.

 We can also construct special purpose heuristics, which are


domain specific.

Page 19
III Year CSE II Sem Artificial Intelligence Unit II

2.5.1. General Purpose Heuristics

 A general-purpose heuristics for combinatorial problem is

 Nearest neighbor algorithms which works by selecting the locally


superior alternative.

 For such algorithms, it is often possible to prove an upper bound


on the error which provide reassurance that one is not paying
too high a price in accuracy for speed.

 In many AI problems,

 it is often hard to measure precisely the goodness of a particular


solution.

 But still it is important to keep performance question in mind


while designing algorithm.

 For real world problems,

 it is often useful to introduce heuristics based on relatively


unstructured knowledge.

 It is impossible to define this knowledge in such a way that


mathematical analysis can be performed.

 In AI approaches,

 behavior of algorithms are analyzed by running them on


computer as contrast to analyzing algorithm mathematically.

 There are at least two reasons for the adhoc approaches in AI.

 It is a lot more fun to see a program do something intelligent than


to prove it.

 AI problem domains are usually sufficiently complex, so generally


not possible to produce analytical proof that a procedure will work.

 It is even not possible to describe the range of problems well


enough to make statistical analysisof program behavior
meaningful.

 One of the most important analysis of the search process is


straightforward i.e.,

Page 20
III Year CSE II Sem Artificial Intelligence Unit II

 Number of nodes in a complete search tree of depth D and


branching factor F is F*D .

 This simple analysis motivates to

 look for improvements on the exhaustive search.

 find an upper bound on the search time which can be compared


with exhaustive search procedures.

Page 21

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy