You are on page 1of 26

# Artificial Intelligence (AI

)
Problem Solving: State-Space Search and Control Strategies

Objectives
• Identify problem-solving methods for AI problems. • Solve given problems by using the appropriate general purpose and search methods.

2

Types of Problem Solving Methods • General purpose • Special purpose 3 .

General Problem Solving • Production system – Start (initial) state(s) – Goal (final) state(s) – Databases with knowledge representation schemes – Production rules – Control strategies 4 .

0) – Goal state: (4. – Start state: (0. where X is the gallons of water in the 5-g jug and Y is the gallons in the 3-gallon (3-g) jug.State-Space Problems: Water Jug • Problem: – Two jugs.N) for any value of N ≤ 3 5 . with no measuring marker – Unlimited water supply through a tap – Need 4 gallons of water in the 5-gallon (5-g) jug • Solution: – Describe state space as a set of ordered pairs of integers (X.Y). of 5 gallons and 3 gallons.

State-Space Problems: Water Jug • Discuss: – Possible operations that can be used in the water jug problem – Production rules corresponding to these operations – Possible solution paths for the problem 6 .

– If the cannibals outnumber the missionaries on the same side. 7 .State-Space Problems: Missionaries and Cannibals • Problem: – Three cannibals and three missionaries want to cross a river. – A boat for one or two persons exists on one side of the river. the missionaries will be eaten. – How should they use the boat to cross the river without anyone being eaten? The cannibals should not outnumber the missionaries.

1B].n1+n2 = 3. mC. 0B]. -]. m1C.[n2M.State-Space Problems: Missionaries and Cannibals • Solution: – State space can be described as a set of ordered pairs of the left and right banks (L. m is the number of cannibals C and B represents the boat. 3C.n2 (≠0) ≥ m2. m2C. 1B means that the boat is present and 0B means it is absent – Any state: ([n1M.R) of the river.[0M.0C.[3M. B]. – Start state: ([3M. 0B]). 3C. 1B]) 8 . where n is the number of missionaries M. with constraints/conditions at any state as n1 (≠0) ≥ m1. 0C. boat can be either side – Goal state: ([0M. m1+m2 = 3. – Each bank can be represented as a list [nM.-]).

9 .State-Space Problems: Missionaries and Cannibals • Discuss: – Possible production rules that can be used for the problem. – Possible solution paths.

10 . • Approach: Apply the appropriate operator to transfer one state of a problem to another state.State-Space Search • Components of state space – A set S containing the start states of the problem – A set G containing goal states of the problem – Set of nodes in a graph/tree representing the states in a problem-solving process – Set of arcs connecting the nodes • Solution path: Path through the graph from a node in S to a node in G.

respectively.State-Space Search • Determine the possible search space algorithm and tree of nodes in a graph for the missionaries and cannibals problem: – Assume that: • State (L : R). or (331:000) • Goal state: (0M0C0B : 3M3C1B). or (000:331) 11 . • Start state: (3M3C1B : 0M0C0B). where L = n1M m1C1B and R = n2Mm2C0B • B represents the boat with 1 or 0 indicating its presence or absence.

Exercise: Eight-Puzzle Problem • Problem: – A 3x3 grid has 8 randomly numbered (1 to 8) tiles with one empty cell. – At any point. an adjacent tiles can move to this cell and create a new empty cell. as per the following figure. 3 5 7 1 Start State 6 2 5 3 6 7 4 1 Goal State 2 8 4 8 12 . – Arrange the tiles to arrive at the goal state from the start state. by using the state-space search method.

Control Strategies • Systematic control strategies: – Depth-first – Breadth-first • Types of search strategies: – Forward chaining – Data-driven search from the start date – Backward chaining – Goal-driven search from the goal state 13 .

– Requirement for absolute or relative solution. – Consistency of the knowledge base to be used to solve the problem.Characteristics of Problems • Characteristics of problems to be considered to determine the search strategy and solution path for a given problem: – Type of problem – Ignorable. recoverable or irrecoverable. – Decomposability of problem. 14 . – Role of knowledge.

Exhaustive Searches • • • • Breadth-first search Depth-first search Depth-first iterative deepening Bidirectional search 15 .

– Time required to find a solution by using the algorithm.Choosing Effective Search Methods • Measure the effectiveness of a search strategy in terms of: – Completeness of search algorithm for a solution. – Space required by the algorithm to find a solution. 16 . – Optimality of the algorithm.

17 .Choosing Effective Search Methods (Cont’d) • Analyze the effectiveness of the exhaustive search methods discussed earlier.

– Prepare a graph to depict the problem and determine possible solution paths. Take hypothetical values for the number of cities and the distance between the cities. 18 .Exercise: Choosing Effective Search Methods • Solve the traveling salesman problem by using the appropriate search method: – Find the shortest route that a salesman should take to visit all cities once and return to the starting point.

Heuristic Search Techniques • General-purpose heuristics. • Best-first search. • Hill climbing. • Beam search. 19 . • A* algorithm. • Branch and bound search (uniform cost search).

Iterative-Deepening A* (IDA*) 5 1st iteration (Threshold = 5) 6 x 8 xx 5 2nd iteration (Threshold = 6) 6 4 4 8 xx 9 xx 7 x 3rd iteration (Threshold = 7) 5 9 xx 5 6 5 8 xx 4 7 x 4 4 8 9 4 Goal 4 8 xx xx 20 xx Sample Working of IDA* .

for each i. – A set of constraints between the values of the variables. x2. 1 ≤ i ≤ n. • Represent the problem as a unidirectional graph – the Constraint graph – in which the nodes are the variables and the edges are binary constraints. a value of xi € Di where all constraints are satisfied.Constraint Satisfaction • Constraint satisfaction (CS) problems are aimed at satisfying a given set of constraints. • You need to find. …. • Such problems have: – A set of variables {x1. 21 . xn} with each xi € Di with possible values.

Constraint Satisfaction Problems : Examples • Examples of constraint satisfaction problems: – Cryptography: A number puzzle where a group of arithmetic operations has some or all digits replaced by letters and the original digits must be found – for example: B + G B A A A M S L E E L S – N-Queen: Given the condition that no two queens on the same row/column/diagonal attack each other. red and black. 22 . colour three regions in blue. such that no two neighbouring regions have the same colour. – Map colouring: Given a map.

23 .Solved Example: Crypt-Arithmetic Puzzle • Solve the solution for the following crypt-arithmetic puzzle with your faculty: B + G B A A A M S L E E L S • Assign a unique number from 0-9 to each letter that satisfies the above addition.

Initial problem state: G = ?. several choices for rules may apply. A useful heuristics can help to select the best rule to apply first. At each cycle. which will in turn generate new constraints at the next cycle. A = >?. L = ? Apply constraint inference rules to generate new constraints. M = ?. choose another rule to generate another assignment. Apply the letter assignment rules to perform all assignments required by the current set of constraints. E = ?. Then. S = ?. • • 24 . B = ?.Solved Example: Crypt-Arithmetic Puzzle (Cont’d) • • • • Constraints: No two letters should have the same values.

25 .Summary • Discuss your key learning from this session.

based on your learning in this session. 26 .Exercises • Attempt the given exercises for Chapter 2 of the Artificial Intelligence book.