AI 0ML Assignment-2
AI 0ML Assignment-2
1. What is Production System? Explain water Jug problem as a state space search.
Production Systems : The entire procedure for getting a solution for AI problem can be viewed as
“Production System”. It provides the desired goal. It is a basic building block which describes the AI
problem and also describes the method of searching the goal.
Problem is “You are given two jugs, a 4-litre one and a 3-litre one. One neither has any measuring markers
on it. There is a pump that can be used to fill the jugs with water. How can you get exactly 2 litres of
water into 4-litre jug?”
Solution:
The state space for the problem can be described as a set of states, where each state represents the number
of gallons in each state. The game start with the initial state described as a set of ordered pairs of integers:
• State: (x, y)
– x = number of lts in 4 lts jug
– y = number of lts in 3 lts jug
x = 0, 1, 2, 3, or 4 y = 0, 1, 2, 3
• Start state: (0, 0) i.e., 4-litre and 3-litre jugs is empty initially.
• Goal state: (2, n) for any n that is 4-litre jug has 2 litres of water and 3-litre jug has any value from 0-3
since it is not specified.
• Attempting to end up in a goal state.
Production Rules: These rules are used as operators to solve the problem. They are represented as rules
whose left sides are used to describe new state that result from approaching the rule.
A monotonic production system is a production system in which the applications of a rule never
prevents the later application of another rule that could also have been applied at the time the first rule
was selected.
A partially commutative production system is a production system with the property that if the
application of a particular sequence of rules transforms state X into state Y, then any permutation of
those rules that is allowable also transforms state X into state Y.
A commutative production system is a production system that is both monotonic and partially
commutative.
In a formal sense, there is no relationship between kinds of problems and kinds of production of
systems, since all problems can be solved by all kinds of systems. But in practical sense, there
definitely is such a relationship between kinds of problems and the kinds of systems that led
themselves naturally to describing those problems.
f’=g+h’
Where
g : The actual cost path from the start state to the current state.
h’ : The actual cost path from the current state to goal state.
f’ : The actual cost path from the start state to the goal state.
For the implementation of A* algorithm we will use two arrays namely OPEN and CLOSE.
OPEN: An array which contains the nodes that has been generated but has not been yet
examined.
CLOSE: An array which contains the nodes that have been examined.
Algorithm:
Step 1: Place the starting node into OPEN and find its f (n) value.
Step 2: Remove the node from OPEN, having smallest f (n) value. If it is a goal node then stop
and return success.
Step 3: Else remove the node from OPEN, find all its successors.
Step 4: Find the f (n) value of all successors; place them into OPEN and place the removed node
into CLOSE.
Step 5: Go to Step-2.
Step 6: Exit.
Implementation:
The implementation of A* algorithm is 8-puzzle game.
Example
Step 1: In the above graph, the solvable nodes are A, B, C, D, E, F and the unsolvable nodes are G, H. Take A as the
starting node. So place A into OPEN.
Step 2: The children of A are B and C which are solvable. So place them into OPEN and place A into the CLOSE.
Step 3: Now process the nodes B and C. The children of B and C are to be placed into OPEN. Also remove B and
C from OPEN and place them into CLOSE
Step 5:
Now we have been reached at our goal state. So place F into CLOSE.
i.e. CLOSE =
6. Explain Breadth-first search and depth-first search. List down the advantages and
disadvantages of both?
Breadth First Search
To solve the water jug problem systemically construct a tree with limited states as its root. Generate all the
offspring and their successors from the root according to the rules until some rule produces a goal state. This
process is called Breadth- First Search.
Algorithm:
1) Create a variable called NODE_LIST and set it to the initial state.
2) Until a goal state is found or NODE_LIST is empty do:
a. Remove the first element from NODE_LIST and call it E. If NODE_LIST was empty quit.
b. For each way that each rule can match the state described in E do:
i.Apply the rule to generate a new state.
ii.If the new state is a goal state, quit and return this state.
iii.Otherwise, add the new state to the end of NODE_LIST.iii. Otherwise add the new state to the
end of NODE_LIST
The name hill climbing is derived from simulating the situation of a person climbing the hill. The
person will try to move forward in the direction of at the top of the hill. His movement stops when it
reaches at the peak of hill and no peak has higher value of heuristic function than this. Hill climbing
uses knowledge about the local terrain, providing a very useful and effective heuristic for eliminating
much of the unproductive search space. It is a branch by a local evaluation function. The hill climbing
is a variant of generate and test in which direction the search should proceed. At each point in the
search path, a successor node that appears to reach for exploration.
Disadvantages:
The question that remains on hill climbing search is whether this hill is the highest hill possible. Unfortunately without
further extensive exploration, this question cannot be answered. This technique works but as it uses local information
that’s why it can be fooled. The algorithm doesn’t maintain a search tree, so the current node data structure need only
record the state and its objective function value. It assumes that local improvement will lead to global improvement.
This set is often represented implicitly by a program that detects terminal states.