Final Chapter 3 -3.1-3.2
Final Chapter 3 -3.1-3.2
Searching
CHAPTER 3 (3.1,3.2)
• Problem:
• It is the question which is to be solved
• For solving a problem it needs to be precisely defined
• Problem definition means, defining the start goal, goal state,
other valid states and transition rules
2
Problem Solving through AI
3
Solution of the problem
4
Method of solving problems through
AI techniques
• It involves the process of defining the search space,
deciding about start and goal state and then finding a
path from start state to goal state through search
space
• The search techniques are methods which are used to
find a way from start to goal state
5
Search Space & Search
6
Search Through State-Space
Goal state
Initial state
7
Production rules
8
Defining the problem as a state
space search
• Problem solving Searching for a goal state
• The state space representation forms the basis of most
of the AI problems
• Search is a very important process in the solution of
hard problems for which no more direct techniques are
available.
10
State Space Search
1. Define a state space that contains all the possible
configurations of the relevant objects.
2. Specify the initial states.
3. Specify the goal states.
4. Specify a set of rules:
What are unstated assumptions?
How general should the rules be?
How much knowledge for solutions should be in
the rules?
11
A problem solving agent is an agent which considers a
sequence of actions that forms a path to reach to the
goal state. Means it is an agent that facilitates to
obtain the final solution of the problem.
39
Famous Problems for Illustrating AI
Concepts
• Water Jug Problem
• Chess Problem
• 8-Puzzle Problem
• Tower of Hanoi Problem
• Traveling Salesperson Problem
40
State Space Search: Water Jug Problem
“You are given two jugs, a 4-gallon (litre) one and a 3-
gallon (litre) one. Neither has any measuring markers
on it. There is a pump (tap) that can be used to fill the
jugs with water. How can you get exactly 2 litres of
water into 4-litre jug.”
3 liters 4 liters
41
Water Jug Problem
42
State Space Search: Water Jug Problem
• x = 0, 1, 2, 3, or 4 y = 0, 1, 2, 3
• Start state: (0, 0).
• Goal state: (2, n) for any n.
• Attempting to end up in a goal state.
43
Water Jug Problem: A State
Space Search
Control structure needed that loops through a cycle in which a rule
whose left side matches the current state is chosen, an appropriate
change is made to the state as described in the right side of the
rule, and the resulting state is checked to see if it corresponds to a
goal state.
Production rules for Water Jug Problem
1. (x, y) (4, y)
if x 4
2. (x, y) (x, 3)
if y 3
3. (x, y) (x d, y)
if x 0
4. (x, y) (x, y d)
if y 0
45
Production rules for Water Jug Problem
5. (x, y) (0, y)
if x 0
6. (x, y) (x, 0)
if y 0
7. (x, y) (4, y (4 x))
if x y 4, y 0
8. (x, y) (x (3 y), 3)
if x y 3, x 0
46
Production rules for Water Jug Problem
9. (x, y) (x y, 0)
if x y 4, y 0
10. (x, y) (0, x y)
if x y 3, x 0
11. (0, 2) (2, 0)
47
Production rules for Water Jug
Problem
48
Production rules for Water Jug
Problem
49
State Space Search: Water Jug Problem
1. Current state = (0, 0)
2. Loop until reaching the goal state (2, 0)
Apply a rule whose left side matches
the current state
Set the new current state to be the
resulting state
(0, 0)
(0, 3)
(3, 0)
(3, 3)
(4, 2)
(0, 2)
(2, 0)
50
One Solution to the Water jug
Problem
51