0% found this document useful (0 votes)
57 views

AI 0ML Assignment-2

The document describes the water jug problem as a state space search problem that can be solved using a production system. It provides the details of the problem, including the initial and goal states, represented as ordered pairs (x,y) where x is the amount of water in the 4L jug and y is the amount in the 3L jug. It also describes the production rules that define the possible state transitions. Breadth-first search and depth-first search are two common search algorithms that can be used to systematically generate and search the state space to find a goal state.

Uploaded by

Dileep Kn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

AI 0ML Assignment-2

The document describes the water jug problem as a state space search problem that can be solved using a production system. It provides the details of the problem, including the initial and goal states, represented as ordered pairs (x,y) where x is the amount of water in the 4L jug and y is the amount in the 3L jug. It also describes the production rules that define the possible state transitions. Breadth-first search and depth-first search are two common search algorithms that can be used to systematically generate and search the state space to find a goal state.

Uploaded by

Dileep Kn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Module-1

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.

Water Jug Problem

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.

The solution to the water-jug problem is:


2. Explain production system characteristics.
Production system is a good way to describe the operations that can be performed in a search for
solution of the problem.
Two questions we might reasonably ask at this point are:
▪ Can production systems, like problems, be described by a set of characteristics that shed some
light on how they can easily be implemented?
▪ If so, what relationships are there between problem types and the types of production systems
best suited to solving the problems?
The answer for the first question can be considered with the following definitions of classes of
production systems:

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 non-monotonic production system is one which this is not true.

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.

3. Explain A* algorithm with example.


A* algorithm is a best first graph search algorithm that finds a least cost path from a given initial node
to one goal node. The simplification of Best First Search is called A* algorithm.
For many applications, it is convenient to define function as the sum of two components that we call g
and h’.

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

4. What is Means-Ends Analysis? Explain with an example.


Most of the search strategies either reason forward of backward however, often a mixture o the two
directions is appropriate. Such mixed strategy would make it possible to solve the major parts of problem
first and solve the smaller problems the arise when combining them together. Such a technique is called
"Means - Ends Analysis".
The means -ends analysis process centers around finding the difference between current state and goal
state. The problem space of means - ends analysis has an initial state and one or more goal state, a set of
operate with a set of preconditions their application and difference functions that computes the difference
between two state a(i) and s(j). A problem is solved using means - ends analysis by
1. Computing the current state s1 to a goal state s2 and computing their difference D12.
2. Satisfy the preconditions for some recommended operator op is selected, then to reduce the
difference D12.
3. The operator OP is applied if possible. If not the current state is solved a goal is created and means-
ends analysis is applied recursively to reduce the sub goal.
4. If the sub goal is solved state is restored and work resumed on the original problem.
( the first AI program to use means - ends analysis was the GPS General problem solver)
means- ends analysis I useful for many human planning activities. Consider the example of planing for
an office worker. Suppose we have a different table of three rules:
1. If in out current state we are hungry , and in our goal state we are not hungry , then either the "visit
hotel" or "visit Canteen " operator is recommended.
2. If our current state we do not have money , and if in your goal state we have money, then the "Visit
our bank" operator or the "Visit secretary" operator is recommended.
3. If our current state we do not know where something is , need in our goal state we do know, then
either the "visit office enquiry" , "visit secretary" or "visit co worker " operator is recommended.
5. Write AO* algorithm and explain the steps in it.
Algorithm:
Step 1: Place the starting node into OPEN.
Step 2: Compute the most promising solution tree say T0.
Step 3: Select a node n that is both on OPEN and a member of T0. Remove it from OPEN and place it in
CLOSE
Step 4: If n is the terminal goal node then leveled n as solved and leveled all the ancestors of n as solved.
If the starting node is marked as solved then success and exit.
Step 5: If n is not a solvable node, then mark n as unsolvable. If starting node is marked as unsolvable,
then return failure and exit.
Step 6: Expand n. Find all its successors and find their h (n) value, push them into OPEN.
Step 7: Return to Step 2.
Step 8: Exit.
Implementation:
Let us take the following example to implement the AO* algorithm.

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

‘O’ indicated that the nodes G and H are unsolvable.


Step 4: As the nodes G and H are unsolvable, so place them into CLOSE directly and process the nodes D and E.

Step 5:
Now we have been reached at our goal state. So place F into CLOSE.
i.e. CLOSE =

Step 6: Success and Exit

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 data structure used in this algorithm is QUEUE. Explanation of Algorithm:


– Initially put (0,0) state in the queue
– Apply the production rules and generate new state
– If the new states are not the goal state, (not generated before and not expanded) then only add these states
to queue

Advantages of Breadth-First Search
– In this procedure at any way it will find the goal.
– It does not follow a single unfruitful path for a long time.
– It finds the minimal solution in case of multiple paths.

Depth First Search


There is another way of dealing the Water Jug Problem. One should construct a single branched tree utility yields
a solution or until a decision terminate when the path is reaching a dead end to the previous state. If the branch is
larger than the pre-specified unit then backtracking occurs to the previous state so as to create another path. This is
called Chronological Backtracking because the order in which steps are undone depends only on the temporal
sequence in which the steps were originally made. This procedure is called Depth-First Search.
Algorithm:
1) If the initial state is the goal state, quit return success.
2) Otherwise, do the following until success or failure is signaled
a. Generate a successor E of the initial state, if there are no more successors, 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.

The data structure used in this algorithm is STACK. Explanation of Algorithm:


– Initially put the (0,0) state in the stack.
– Apply production rules and generate the n
– If the new states are not a goal state, (not g then only add the state to top of the Stack.
– If already generated state is encountered then POP the top of stack elements and search in another
direction.

Advantages of Depth First Search


– DFS consumes very less memory space.
– It will reach at the goal node in a less time period than BFS if it traverses in a right path.
– It may find a solution without examining much of search because we may get the desired solution in the very
first go.

7. Explain Hill Climbing and give its disadvantages.


Hill climbing search algorithm is simply a loop that continuously moves in the direction of
increasing value. It stops when it reaches a “peak” where no neighbour has higher value. This
algorithm is considered to be one of the simplest procedures for implementing heuristic search. The
hill climbing comes from that idea if you are trying to find the top of the hill and you go up direction
from where ever you are. This heuristic combines the advantages of both depth first and breadth first
searches into a single method.

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.

8. Define Control Strategy and requirements for good search strategy.


A good control strategy should have the following requirement: The first requirement is that it causes motion. In a
game playing program the pieces move on the board and in the water jug problem water is used to fill jugs. The
second requirement is that it is systematic, this is a clear requirement for it would not be sensible to fill a jug and
empty it repeatedly nor in a game would it be advisable to move a piece round and round the board in a cyclic
way. We shall initially consider two systematic approaches to searching.

Control Strategy The question arises


"How to decide which rule to apply next during the process of searching for a solution to a problem?"
Requirements of a good search strategy:
1. It causes motion. It must reduce the difference between current state and goal state. Otherwise, it will
never lead to a solution.
2. It is systematic. Otherwise, it may use more steps than necessary.
3. It is efficient. Find a good, but not necessarily the best, answer.

9. Define State Space Search. Write algorithm for state space.


A state space search can be searched in two directions like from the inputs towards the goal or from the goals towards
the inputs. In data driven search, one starts with the given facts of a problem and uses a set of legal moves or rules to
change the states. This process is continued until it generates a path that satisfies the goal condition. In goal driven
search, first determine the rules or legal moves that can be used to generate the goal and identifies the condition that
can be applied to use these rules. These conditions form the new goals or sub goals for the search. One must continue
the search process by working backwards through successive sub goals until it returns of moves or rules leading from
the data to a goal, even if it performs this process backwards. Data driven search is suggested if one is provided with
almost all the data at the time of formulation of the problem statement.

State Space Search


A state space represents a problem in terms of states and operators that change states.
A state space consists of:
• A representation of the states the system can be in.
• For example, in a board game, the board represents the current state of the game.
• A set of operators that can change one state into another state. In a board game, the operators are
the legal moves from any given state. Often the operators are represented as programs that change a
state representation to represent the new state.
• An initial state.
• A set of final states; some of these may be desirable, others undesirable.

This set is often represented implicitly by a program that detects terminal states.

You might also like