2. Problem Solving
โข AI programs have a clean separation of
computational components of data,
operations & control.
โข It is represented in form of production
system or state-space formulation.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
3. Production System or
State-space Formulation
โข It is a formation for structuring AI
programs which facilitates describing
search process. It consists of
โ State-space
โ Initial or start state
โ Final or goal state
โ Set of production rules
โ A control strategy
โ Knowledge databases
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
4. State-space, Initial and Goal State
โข A state is a representation of elements at a
given moment for a given problem.
โ Ex: any configuration of tiles in 8-puzzle
problem i.e.
represent two different states of 8-puzzle problem
โข Among all possible states, there are two
special states called :
โ Initial state is the start point
โ Final state is the goal state
1 4 5
3 8
2 6 7
1 5
3 4 8
2 6 7
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
5. โข A State space is the set of all states reachable from the initial
state.
โข A state space forms a graph or tree in which the nodes are
states and the arcs between nodes are actions. Tree has only
one path to a given node i.e. it does not contain cycle whereas
a graph has several paths to a given node i.e. it contain cycles.
โข In state space, a path is a sequence of states connected by a
sequence of actions.
โข The solution of a problem is part of the map formed by the
state space.
โข The state space may be explicitly represented by a graph.
But more typically the state space can be implicitly
represented and generated when required. To generate
the state space implicitly, the agent needs to know
State-space, Initial and Goal State
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
6. production rules
โข It represents in form of a pair, each pair
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 states of the state-
space. Application of rules change the states.
โข These rules helps to move from one state to
another state which is called a successor state. A
state can have a number of successor states.Dr. Amit Kumar, Dept of CSE, JUET,
Guna
7. A control strategy
โข A control strategy is one that specifies the
order in which the rules will be applied. Ex
Generate and test, BFS,DFS etc
โข It helps to find the goal state or a path to the
goal state.
โข It is not necessary that a control strategy
always find an optimal path.
โข A good control strategy should causes the
motion in state-space and systematic .Dr. Amit Kumar, Dept of CSE, JUET,
Guna
8. Databases
โข One or more knowledge databases that
contains whatever information is appropriate
for the particular task.
โข Some part of the database is permanent while
other parts of it may pertain the information
that is applicable to the solution of the
current problem.
โข The information in the database must be
structured in appropriate way.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
9. Use of Production system
โข The production model not only helps to
formulate the problem but it has other
advantages as
โ It is a good way to model the strong state driven
nature of intelligent action. 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.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
10. 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 space or production system 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.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
11. Production system
Water jug
โข State-space: all possible combination of
(X,Y)
โข Initial state: both jugs are empty i.e. (0,0)
โข Goal State: 4-gallon jug contains 2-gallon
water, 2-gallon jug quantity unspecified
i.e.(2,n)
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
12. โข Production Rules:
โ R1: (X, Y | X < 4) ๏ (4, Y)
{Fill 4-gallon jug}
โ R2: (X, Y | Y < 3) ๏ (X, 3)
{Fill 3-gallon jug}
โ R3: (X, Y | X > 0) ๏ (0, Y)
{Empty 4-gallon jug}
โ R4: (X, Y | Y > 0) ๏ (X, 0)
{Empty 3-gallon jug}
โ R5:(X, Y | X+Y >= 4 ฮY > 0) ๏ (4, Y โ(4 โX))
{Pour water from 3-gallon jug into
4-gallon jug until 4-gallon jug is full}
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
13. โ 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 }
โ 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}
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
14. Solution-1
Number of
Steps
Rules applied 4-g
jug
3-g
jug
1 Initial State 0 0
2 R2 {Fill 3-g jug} 0 3
3 R7 {Pour all water from 3 to 4-g jug } 3 0
4 R2 {Fill 3-g jug} 3 3
5 R5 {Pour from 3 to 4-g jug until it is full} 4 2
6 R3 {Empty 4-gallon jug} 0 2
7 R7 {Pour all water from 3 to 4-g jug} 2 0
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
15. Solution-2
Number of
Steps
Rules applied 4-g
jug
3-g
jug
1 Initial State 0 0
2 R1 {Fill 4-g jug} 4 0
3 R6 {Pour all water from 4-G to 3-G jug } 1 3
4 R4 {Empty 3-g jug} 1 0
5 R8 {Pour water from 4 to 3-g jug until} 0 1
6 R1 {Fill 4-gallon jug} 4 1
7 R6 {Pour from 4 to 3-g jug until it is full} 2 3
8 R4 {Empty 3-g jug} 2 0
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
16. Points to be noted
โข There is an initial description of the problem.
โข Final description of the problem.
โข There are more than one ways of solving the
problem.
โข One would exercise a choice between various
solution paths based on some criteria of goodness
or on some heuristic function.
โข 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.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
17. 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.
โข Constraint: โฐAt any point in time, cannibals
should not be more than missionaries. โ
โ If the cannibals ever outnumber the missionaries
(on either bank) then the missionaries will be
eaten.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
18. โข 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] )
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
19. โข Any state: ([n1M, m1C, 1B], [n2 M, m2 C,
0B]) , with constraints/conditions as
โ n1 (โ 0) โฅ m1;
โ n2 (โ 0) โฅ m2;
โ n1 + n2 = 3 and 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.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
20. Set of Production Rules
Applied keeping constrains in mind
Rules for boat going from left bank to right bank of the river
Rule
No.
Left side of rule Right side of rule
L1 ([n1M, m1C, 1B],
[n2M, m2C,0B])
๏ ([(n1-2)M, m1C, 0B],
[(n2+2)M,m2C, 1B])
L2 ([n1M, m1C, 1B],
[n2M, m2C, 0B])
๏ ([(n1-1)M,(m1-1)C,0B],
[(n2+1)M,(m2+1)C, 1B])
L3 ([n1M, m1C, 1B],
[n2M, m2C, 0B])
๏ ([n1M, (m1-2)C, 0B],
[n2M, (m2+2)C, 1B])
L4 ([n1M, m1C, 1B],
[n2M, m2C, 0B])
๏ ([(n1-1)M, m1C,0B],
[(n2+1)M, m2C, 1B])
L5 ([n1M, m1C, 1B],
[n2M, m2C, 0B])
๏ ([n1M, (m1-1)C, 0B],
[n2M, (m2+1)C, 1B])
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
21. Set of Production Rules
Applied keeping constrains in mind
Rules for boat coming from right bank to left bank of the river
Rule
No.
Left side of rule Right side of rule
L1 ([n1M, m1C, 1B],
[n2M, m2C,0B])
๏ ([(n1+2)M, m1C, 0B],
[(n2-2)M,m2C, 1B])
L2 ([n1M, m1C, 1B],
[n2M, m2C, 0B])
๏ ([(n1+1)M,(m1+1)C,0B],
[(n2-1)M,(m2-1)C, 1B])
L3 ([n1M, m1C, 1B],
[n2M, m2C, 0B])
๏ ([n1M, (m1+2)C, 0B],
[n2M, (m2-2)C, 1B])
L4 ([n1M, m1C, 1B],
[n2M, m2C, 0B])
๏ ([(n1+1)M, m1C,0B],
[(n2-1)M, m2C, 1B])
L5 ([n1M, m1C, 1B],
[n2M, m2C, 0B])
๏ ([n1M, (m1+1)C, 0B],
[n2M, (m2-1)C, 1B])
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
23. 8-puzzle problem
โข Problem: the 8-puzzle is a square tray in
which 8 tiles are placed. The 9th square is
uncovered. A tile that is adjacent to the
blank space can be slide into that space.
the game consist of a starting position and
specified goal position . The goal is to
transform the starting position into goal
position by sliding the tile around.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
24. 8-puzzle problem
โข State space : configuration of 8 - tiles on the
board
โข Initial state : any configuration
โข Goal state : tiles in a specific order
โข Action : โblank movesโ
โข Transformation: blank moves L, R, U,D
โข ( blank tile position, {filled neighbors
positions}, action)
(1,{2,4},U) -๏ (4,{1,5,7},-)
โข Solution : optimal sequence of operators
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
27. Block world problem
โข Problem: given the following initial state,
aim is to reach the goal state, such that
smaller block can not be put on bigger
block and only one block can be moved at
a time
C
B
A
Goal State
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
28. Production system
โข State space : configuration of blocks on the
table
โข Initial state : any configuration
โข Goal state : blocks in a specific order
โข Action :
โ Clear (x) {block x has nothing on it}๏ On(x, Table){pick x and
put it on table}
โ Clear (x) and Clear (y) ๏ On(x, y){put x on y}
โข Solution : optimal sequence of operators
Dr. Amit Kumar, Dept of CSE, JUET,
Guna
29. Tutorial-1
โข Define the production system and one possible
solution for tower of Hanoi problem of 4 disk.
In this problem, there are three rods and a number of
disks of different sizes, which can slide onto any rod.
The puzzle starts with the disks in a neat stack in
ascending order of size on one rod, the smallest at the
top, thus making a conical shape. The objective of the
puzzle is to move the entire stack to another rod,
obeying the following simple rules:
โ Only one disk can be moved at a time.
โ Each move consists of taking the upper disk from one of
the stacks and placing it on top of another stack.
โ No disk may be placed on top of a smaller disk.
Dr. Amit Kumar, Dept of CSE, JUET,
Guna