34
CHAPTER - 2 Problem Spaces and Problem Solving by Searching Presented By : Radhika Srinivasan PG Roll No : 45

(Radhika) presentation on chapter 2 ai

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: (Radhika) presentation on chapter 2 ai

CHAPTER - 2

Problem Spaces and Problem Solving by

Searching

Presented By :Radhika Srinivasan PGRoll No : 45

Page 2: (Radhika) presentation on chapter 2 ai

What we will learn today …

What is Problem Spaces? How to Search to get solutions? Using Different searching algorithms i.e.

basically used in AI Some Toy problems and Real world problems

Page 3: (Radhika) presentation on chapter 2 ai

Introduction

Now, we’ll study about what are the kinds of problems where the AI is concerned and the technique that is used to solve those problems.

There are 4 things concerned to solve a particular problem.

Define the problem precisely. Analyze the problem. Isolate and represent the task knowledge i.e. required

to solve the problem. Finally, choose the best problem solving technique and

apply to the particular problem.

Page 4: (Radhika) presentation on chapter 2 ai

Areas

Problem Solving-Puzzles-Play games, e.g chess-Symbolic integration of mathematical formulas.-Some programs can improve their performance with

experience Logical reasoning– Prove assertions (theorems) by manipulating a database

of facts

Page 5: (Radhika) presentation on chapter 2 ai

Areas

Language– Understanding of natural language– Translation– E.g. Spelling checker Programming– Write computer programs based on a description Systems and languages– Time-sharing, list processing, and interactive debugging

were developed in the AI research

Page 6: (Radhika) presentation on chapter 2 ai

What is problem space ?

Problem space is a set of states and the connections between to represent the problem. Problem space graph is used to represent a problem space. In the graph, the states are represented by nodes of the graph, and the operators by edges between nodes.

For simplicity they are often represented as trees, where the initial state is the root of the tree. The cost of the simplification is that any state that can be reached by two different paths will be represented by duplicate nodes thereby increasing the tree size. The benefit of using tree is that the absence of cycles greatly simplifies many search algorithms.

Page 7: (Radhika) presentation on chapter 2 ai

Search

State Space and Problem Reduction– State space An operator produces exactly one new state– Problem reduction An operator produces a set of sub problems, each of

which have to be solved.- E.g. Tower of Hanoi

Page 8: (Radhika) presentation on chapter 2 ai

Search - problem representation

State space graph It is represented like nodes and edges where initial

state to the goal state. It can also represent as tree graph.

Page 9: (Radhika) presentation on chapter 2 ai

Search Strategy

A strategy is defined by picking the order of node expansion. Strategy is evaluated among the following dimensions.

Completeness- does it always find a solution if one exists?

Time complexity- no. of nodes generated. Space complexity- max no. of nodes in memory. Optimality- does it always find least cost solution? Time and space is measured in ‘b’ – max branching

factor of search tree. ‘d’- depth of least cost solution. ‘m’ – max depth of the state space may be (infinite)

Page 10: (Radhika) presentation on chapter 2 ai

Which are the Search Types ?

Blind search algorithms are as follows: In blind search the number of nodes can be extremely large, The order of expanding the nodes is

arbitrary - Breadth First Search - Depth First Search Heuristic search - Ordered Search - A* An optimal search Consider State space graph as general graph i.e. nodes and

points. Graphs can be directed undirected or mixed graph.

Page 11: (Radhika) presentation on chapter 2 ai

Breadth-First Search

Breadth First Search (BFS) searches breadth-wise in the problem space. Breadth-First search is like traversing a tree where each node is a state which may a be a potential candidate for solution.

Breadth first search expands nodes from the root of the tree and then generates one level of the tree at a time until a solution is found. It is very easily implemented by maintaining a queue of nodes.

Initially the queue contains just the root. In each iteration, node at the head of the queue is removed and then expanded. The generated child nodes are then added to the tail of the queue.

Page 12: (Radhika) presentation on chapter 2 ai

ALGORITHM: BREADTH-FIRST SEARCH

Create a variable called NODE-LIST and set it to the initial state.

Loop until the goal state is found or NODE-LIST is empty.

• Remove the first element, say E, from the NODE-LIST. If NODE-LIST was empty then quit.

• For each way that each rule can match the state described in E do:

- Apply the rule to generate a new state.- If the new state is the goal state, quit and return this state.- Otherwise add this state to the end of NODE-LIST

Page 13: (Radhika) presentation on chapter 2 ai

Advantages : BFS

Breadth first search will never get trapped exploring the useless path forever.

If there is a solution, BFS will definitely find it out. If there is more than one solution then BFS can find the

minimal one that requires less number of steps.

Page 14: (Radhika) presentation on chapter 2 ai

Disadvantages :BFS

The main drawback of Breadth first search is its memory requirement. Since each level of the tree must be saved in order to generate the next level, and the amount of memory is proportional to the number of nodes stored, the space complexity of BFS is O(bd).

As a result, BFS is severely space-bound in practice so will exhaust the memory available on typical computers in a matter of minutes.

If the solution is farther away from the root, breath first search will consume lot of time.

Page 15: (Radhika) presentation on chapter 2 ai

DEPTH FIRST SEARCH 

Depth First Search (DFS) searches deeper into the problem space.

BFS always generates successor of the deepest unexpanded node.

Depth First Search uses last-in first-out stack for keeping the unexpanded nodes.

More commonly, depth-first search is implemented recursively, with the recursion stack taking the place of an explicit node stack.

Page 16: (Radhika) presentation on chapter 2 ai

ALGORITHM: DEPTH FIRST SEARCH

If the initial state is a goal state, quit and return success.

Otherwise, loop until success or failure is signalled.a) Generate a state, say E, and let it be the successor of the initial state. If there is no successor, signal failure.b) Call Depth-First Search with E as the initial state.c) If success is returned, signal success. Otherwise continue in this loop.

Page 17: (Radhika) presentation on chapter 2 ai

ADVANTAGES 

The advantage of depth-first Search is that memory requirement is only linear with respect to the search graph.

The time complexity of a depth-first Search to depth d is O(b^d) since it generates the same set of nodes as BFS.

If depth-first search finds solution without exploring much in a path then the time and space it takes will be very less.

Page 18: (Radhika) presentation on chapter 2 ai

DISADVANTAGES 

There is a possibility that it may go down the left-most path forever. Even a finite graph can generate an infinite tree. 

Depth-First Search is not guaranteed to find the solution.

And there is no guarantee to find a minimal solution, if more than one solution exists.

Page 19: (Radhika) presentation on chapter 2 ai

Bidirectional Search

The algorithms so far use forward reasoning, i.e. moving from the start node towards a goal node. some cases we could use backward reasoning, i.e. moving

from the goal state to the start state. Forward and backward reasoning can be combined into

a technique called bidirectional search. - One starting from the initial state and searching

forward - One starting from the goal state and searching

backward The search terminates when the two graphs intersect

Page 20: (Radhika) presentation on chapter 2 ai

Problems in Real World

There are some toy searching that we’ll see this technique are used to solve some real world

problems like: Route finding.(computer networks, airline travel

planning system) Layout problems (VLSI layout, furniture layout,

packaging) Assembly sequencing.(Assembly of electrical motors) Task Scheduling.(Time tables, manufacturing)

Page 21: (Radhika) presentation on chapter 2 ai

Water Jug Problem

Consider the following problem: A Water Jug Problem: You are given two jugs, a 4-

gallon one and a 3-gallon one, a pump which has unlimited water which you can use to fill the jug, and the ground on which water may be poured. Neither jug has any measuring markings on it. How can you get exactly 2 gallons of water in the 4-gallon jug?

State Representation and Initial State – We will represent a state of the problem as a tuple

(x, y) where x represents the amount of water in the 4-gallon jug and y represents the amount of water in the 3-gallon jug. Goal state as (2,y).

Page 22: (Radhika) presentation on chapter 2 ai

Production Rules

(x,y)If x<4 -> (4,y) (x,y)If y<3 ->(x,3) (x,y)If x>0 ->(x-d,y) (x,y)If y>0 ->(x,y-d) (x,y)If x>0 ->(0,y) (x,y)If y>0 ->(x,0) (x,y)If(x+y>=4 and y>0) ->(4,y-(4-x)) (x,y)If (x+y>=3 and x>0) ->(x-(3-y),3) (x,y)If(x+y<=4 and y>0) ->(x+y,0) (x,y)If (x+y<=3 and x>0) ->(0,x+y) (0,2)->(2,0)

Page 23: (Radhika) presentation on chapter 2 ai

Solution

4 Gallon Jug 3 Gallon Jug

0 0

4 0

1 3

1 0

0 1

4 1

2 3

4 Gallon jug 3 Gallon jug

pump

Page 24: (Radhika) presentation on chapter 2 ai

Search Tree : Water Jug Problem

(0,0)

(4,0)

(4,3) (0,0) (1,3)

(0,3)

(4,3) (0,0) (3,0)

Page 25: (Radhika) presentation on chapter 2 ai

8 Puzzle Problem

1 3 5

2 7 4

6 8

1 2 3

4 5 6

7 8

Start State Goal State

Page 26: (Radhika) presentation on chapter 2 ai

8 Puzzle Problem

State space (S) Location of each of the 8 tiles(and the blank tile) Start State (s) Starting configuration Operators(O) Four Operators : Right, Left, Up, Down Goals(G) one of the goal configuration

Page 27: (Radhika) presentation on chapter 2 ai

8 Queen Problem

Problem: Place 8 queens on a chess board so that none of them attack each other

Formulation- I - A state is an arrangement of 0 to 8 queens on the board - Operators add a queen to any square. This formulation is not a systematic way to find the

solution, it takes a long time to get the solution.

Page 28: (Radhika) presentation on chapter 2 ai

8 Queen Problem

Formulation – II - A state is an arrangement of 0-8 queen with no one

attacked. - Operators place a queen in the left most empty column. - More systematic than formulation-I

Page 29: (Radhika) presentation on chapter 2 ai

8 Queen Problem

Formulation –III- A state is an arrangement of 8 queens on in each column.

-Operators move an attacked queen to another square in the same column.

-Keep on shuffling the queen until the goal is reached. - This formulation is more systematic hence , it is also

called as Iterative Formulation.

Page 30: (Radhika) presentation on chapter 2 ai

8 Queen Problem : Solution

Page 31: (Radhika) presentation on chapter 2 ai

Missionaries and Cannibals

Three missionaries and three cannibals find themselves on a side of river. They agreed to get to the other side of river. But missionaries are afraid of being eaten by cannibals so, the missionaries want to manage the trip in such a way that no. of missionaries on either side of the river is never less than the no. of cannibals on the same side. The boat is able to hold only 2 people at a time.

Page 32: (Radhika) presentation on chapter 2 ai

Missionaries and Cannibals

State(#m,#c,1/0) #m – number of missionaries on first bank #c – number of cannibals on first bank The last bit indicate whether the boat is in the first

bank. Operators

• Boat carries (1,0) or (0,1) or (1,1) or (2,0) or (0,2)

Page 33: (Radhika) presentation on chapter 2 ai
Page 34: (Radhika) presentation on chapter 2 ai