Production Systems
A simple string rewriting production system example
Search Problem
Basic searching process
Algorithm’s performance and complexity
Computational complexity
‘Big - O’ notation
Tower of Hanoi
8 Puzzle
Water Jug Problem
Can Solution Steps be Ignored
Is Good Solution Absolute or Relative
Issues in the Design of Search Programs
2. Contents
• Production Systems
– A simple string rewriting production system example
• Search Problem
• Basic searching process
• Algorithm’s performance and complexity
– Computational complexity
– ‘Big - O’ notation
• Tower of Hanoi
• 8 Puzzle
• Water Jug Problem
• Can Solution Steps be Ignored
• Is Good Solution Absolute or Relative
• Issues in the Design of Search Programs
3. Production Systems
• A production system (or production rule system)
is a computer program typically used to provide
some form of artificial intelligence, which consists
primarily of a set of rules about behavior but it
also includes the mechanism necessary to follow
those rules as the system responds to states of
the world.
• Productions consist of two parts: a sensory
precondition (or "IF" statement) and an action (or
"THEN").
5. Search Problem
• Search is the process of allowing for several
possible sequences of operators to be applied
to the initial state and finding a sequence that
culminates in a goal state.
• Any search problem consists of the following:
S : full set of states
S0 : initial state
A : S → s is a set of operators
G : set of final states
7. Search Problem
• Involves finding a sequence of actions that
transforms the agent from the initial state to a
goal state.
• Represented by a 4 tuple {S,S0,A,G}.
• Sequence of actions is called a solution path.
• It is a path from initial state to a goal state S.
• Plan P is a sequence of actions.
P = {a0, a1, a2, ... aN}
• A sequence of states is called a path.
8. Basic searching process
• Check the current node.
• Execute an allowable action to find the
successor states.
• Pick one of the new states.
• Check if the new state is a solution state.
• If it is not, the new state becomes the current
state and the process is repeated.
14. Initial state
Goal states
S4
• The example illustrates how we can start from a
given state and follow the successor to find the
solution paths that lead to a goal state.
• The brown node defines the search tree.
• Typically, the search tree is extended one node
at a time.
• The search strategy is used to find the order of
the search tree.
15. For formal problem description
• Define a state space that contains all the possible
configurations of the relevant objects.
• Specify one or more (initial) states within that
space that describe possible situations from
which the problem solving process may start.
• Specify one or more (goal) states that would be
acceptable as solutions to the problem.
• 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.
16. Algorithm’s performance and
complexity
• Performance of an algorithm depends on internal
and external factors.
• Internal factors/External factors
– Time required to run
– Size of input to the algorithm
– Space (memory) required to run
– Speed of the computer
– Quality of the compiler
• Complexity is a measure of the performance of
an algorithm. Complexity measures the internal
factors, usually in time than space.
17. Computational complexity
• It is the measure of resources in terms of Time
and Space.
• If A is an algorithm that solves a decision problem
f, then run-time of A is the number of steps taken
on the input of length n.
• Time Complexity T(n) of a decision problem f is
the run-time of the ‘best’ algorithm A for f.
• Space Complexity S(n) of a decision problem f is
the amount of memory used by the ‘best’
algorithm A for f.
18. ‘Big - O’ notation
• The Big-O, theoretical measure of the execution
of an algorithm, usually indicates the time or the
memory needed, given the problem size n, which
is usually the number of items
• The Big-O notation is used to give an
approximation to the run-time-efficiency of an
algorithm
• The letter ‘O’ is for order of magnitude of
operations or space at run-time
19. ‘Big - O’ notation
• If an algorithm A requires time proportional to
f(n), then algorithm A is said to be of order
f(n), and it is denoted as O(f(n)).
• If algorithm A requires time proportional to
n2, then the order of the algorithm is said to
be O(n2).
• If algorithm A requires time proportional to n,
then the order of the algorithm is said to be
O(n).
20. ‘Big - O’ notation
• Determine the Big-O of an algorithm to
calculate the sum of the n elements in an
integer array a[0..n-1].
Line Instructions No. of
execution steps
line 1 sum 1
line 2 for(i=0; i<n; i++) n+1
line 3 sum += a[i] n
line 4 print sum 1
Total 2n + 3
21. ‘Big - O’ notation
Thus, the polynomial (2n + 3) is dominated by
the 1st term as n while the number of elements
in the array becomes very large.
• In determining the Big-O, ignore constants
such as 2 and 3. So the algorithm is of order n.
• So the Big-O of the algorithm is O(n).
• In other words the run-time of this algorithm
increases roughly as the size of the input data
n, e.g., an array of size n.
22. Tower of Hanoi
The objective of the puzzle is to move the entire
stack to the last rod, obeying the following rules:
1. Only one disk may be moved at a time.
2. Each move consists of taking the upper disk
from one of the stacks and placing it on top
of another stack or on an empty rod.
3. No disk may be placed on top of a disk that is
smaller than it.
23. Tower of Hanoi
• With 3 disks, the puzzle can be solved in 7
moves.
• The minimal number of moves required to
solve a Tower of Hanoi puzzle is 2n − 1,
where n is the number of disks.
24. Tower of Hanoi
• Operators: In the goal state, all the pegs are in
needle B, as shown in figure below.
A B C A B C
25. Tower of Hanoi
Step 1 : move A → B
Step 2 : move A → C
Step 3 : move B → C
Step 4 : move A → B
Step 5 : move C → A
Step 6 : move C → B
Step 7 : move A → B
27. • The Hamming distance between a board and the goal
board is the number of tiles in the wrong position.
• The Manhattan distance between a board and the
goal board is the sum of the Manhattan distances (sum
of the vertical and horizontal distance) from the tiles to
their goal positions.
8 Puzzle
30. 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
31. Water Jug Problem: Production Rules
R1: (X, Y | X < 4) (4, Y) Fill 4G
R2: (X, Y | Y < 3) (X, 3) Fill 3G
R3: (X, Y | X > 0) (0, Y) Empty 4G
R4: (X, Y | Y > 0) (X, 0) Empty 3G
R5: (X, Y | X+Y ≥ 4 ꓥ Y > 0) (4, Y – (4-X)) Pour water from 3G into
4G until 4G is full
R6: (X, Y | X+Y ≥ 3 ꓥ X > 0) (X – (3-Y), 3) Pour water from 4G jug
into 3G until 3G is full
R7: (X, Y | X+Y ≤ 4 ꓥ Y > 0) (X+Y, 0) Pour all water from 3G
into 4G
R8: (X, Y | X+Y ≤ 3 ꓥ X > 0) (0, X+Y) Pour all water from 4G
into 3G
32. Water Jug Problem: Solution 1
# Rules applied 4G 3G
1 Initial state 0 0
2 R2 {Fill 3G} 0 3
3 R7 {Pour all water from 3G to 4G} 3 0
4 R2 {Fill 3G} 3 3
5 R5 {Pour from 3G to 4G until it is full} 4 2
6 R3 {Empty 4G} 0 2
7 R7 {Pour all water from 3G to 4G} 2 0
33. Water Jug Problem: Solution 2
# Rules applied 4G 3G
1 Initial state 0 0
2 R1 {Fill 4G} 4 0
3 R6 {Pour from 4G to 3G until it is full} 1 3
4 R4 {Empty 3G} 1 0
5 R8 {Pour all water from 4G to 3G} 0 1
6 R1 {Fill 4G} 4 1
7 R6 {Pour from 4G to 3G until it is full} 2 3
8 R4 {Empty 3G} 2 0
34. Can Solution Steps be Ignored?
1. Ignorable, in which solution steps can be
ignored. Eg: Theorem Proving
2. Recoverable, in which solution steps can be
undone. Eg: 8-Puzzle
3. Irrecoverable, in which solution steps cannot
be undone. Eg: Chess
35. Is Good Solution Absolute or
Relative?
Consider the problem of answering
questions based on a database of simple
facts such as the following:
1. Jack Dawson was a man.
2. Jack Dawson was travelling in Titanic.
3. Jack Dawson was born in 1891.
4. All men are mortal.
5. All travelling in Titanic died as it sank in the
Atlantic on April 15, 1912.
6. No mortal lives longer than 100 years.
Suppose we ask a question: ‘Is Jack Dawson alive?’
36. Is Good Solution Absolute or
Relative?
Method I:
1. Jack Dawson was a man.
2. Jack Dawson was born in 1891.
3. All men are mortal.
4. Now it is 2022, so Jack Dawson’s age is 131 years.
5. No mortal lives longer than 100 years.
Method II:
1. Jack Dawson was travelling in Titanic.
2. All travelling in Titanic died as it sank in the Atlantic
on April 15, 1912.
ANSWER: So Jack Dawson is not alive.
37. Issues in the Design of Search
Programs
• Each search program can be considered to be
a tree traversal.
• The object of the search is to find a path from
the initial state to a goal state using a tree.
• The secret of a good search routine is to
generate only those nodes that are likely to
be useful, rather than having a precise tree.
38.
39. Issues in the Design of Search
Programs
1. The trees can be searched forward from the
initial node to the goal state or backwards
from the goal state to the initial state.
2. To select applicable rules, it is critical to have
an efficient procedure for matching rules
against states.
3. How to represent each node of the search
process?