Declaration:
Student’s Sign:
Evaluator’s Comments:
___________________________________________________
Page 1
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
CAP451
Design Problem 1
DOS:15-March-2010 Marks: 20
i. If the fox is left alone with the goose, the goose will be eaten.
If the goose is left alone with the grain it will be eaten [3]
iii. Draw a state space search tree for this puzzle using left bank
and right bank to denote let and right banks respectively [4]
iv. For solving this problem, whether you will use Forward
reasoning or backward reasoning? Justify your answer [4]
Page 2
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
SOLUTION
EXPECTATION-I
If the fox is left alone with the goose, the goose will be eaten. If the
goose is left alone with the grain it will be eaten [3]
In first Journey Farmer takes Goose to other side. Above condition satisfied.
In second journey the Farmer drop the Goose and come alone.
In the third journey Farmer takes the grain to other side. Condition satisfied.
In fourth journey Farmer come back with goose with condition satisfied.
In fifth journey Farmer drops Goose on first side and takes the fox with him.
In the sixth journey Farmer drops Fox on other side and come back.
In the seventh journey the Farmer finally takes the Goose and reach
successfully by all the three things with no loss.
In the above seven steps of Farmer’s journey from one side to other side of
the river neither fox and grain, goose nor goose, fox stay or go together.
Therefore the above condition gets satisfied.
Page 3
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
EXPECTATION-II
How many journeys will be taken to cross river [3]
The following moves will be taken by the farmer for successful journey:
i. In First Move the farmer will take Goose and leave the Goose on the
other end because Fox will not eat grain and also the Farmer will
satisfy the condition of number of persons which can be handled by
the boat.
ii. In Second Move the Farmer will return alone.
iii. In the third Move the farmer will take the grain and leave the grain
there but he will pick the Goose with him, so that the Goose will not
eat grain.
iv. In fourth Move the farmer will take the Goose back with him.
v. In the fifth move the farmer will drop the Goose their and pick the
Fox.
vi. In the sixth move the farmer will drop the Fox on the other side and
come back alone and also by doing this the Fox will not eat the Grain.
vii. In the seventh move the farmer will finally take the Goose on the
other side and make a successful journey.
EXPECTATION-III
Draw a state space search tree for this puzzle using left bank and
right bank to denote left and right banks respectively [4]
Now for a farmer to cross the river with no any kind of loss of his animals and
grain he should have some state which describe his position during the
problem. The farmer will have three states:
Initial state
Intermediate state
Final or Goal state
Page 4
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
Now since we have two sides of the river so we should need some
notation symbols to describe them. So to resolve this problem either
takes some Boolean type values like true/false or take binary number
system digit to represent the two states i.e.
1 left bank of the river
0 right bank of the river
Intermediate states:
1. Move(Fm,Gs)
2. Drop(Gs)
3. Back(Fm)
4. Move(Fm,Gr)
5. Drop(Gr)
6. Back(Fm,Gs)
7. Move(Fm,Fx)
8. Drop(Fx)
9. Back(Fm) //Repeated
10. Move(Fm,Gs) //Repeated
11. Left(Fx,Gr)
12. Right(Gs)
13. Left(Fx)
14. Right(Gr)
15. Left(Gs)
16. Right(Fx,Gr)
Final state
Goal(Fm,Gs,Fs,Fx)
On the basis of the above data the following table will be drawn:
Sr. No. True/ Farmer Fox (Fx) Grain Goose
False (Fm) (Gr) (Gs)
1. Y 1 1 1 1
2. Y 1 1 1 0
3. Y 1 1 0 1
4. N 1 1 0 0
5. Y 1 0 1 1
6. Y 1 0 1 0
7. N 1 0 0 1
8. N 1 0 0 0
9. N 0 1 1 1
10. N 0 1 1 0
11. Y 0 1 0 1
12. 0
Y 0 1 0 0
13. 0
N 0 0 1 1
14. Y 0 0 1 0
15. Y 0 0 0 1
16. 0
Y 0 0 0 0
Page 5
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
Page 6
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
EXPECTATION-IV
For solving this problem, whether you will use Forward reasoning or
backward reasoning? Justify your answer [4]
Forward chaining:
Forward chaining is one of the two main methods of reasoning when using
inference rules (in artificial intelligence). The opposite of forward chaining is
backward chaining.
Forward chaining starts with the available data and uses inference rules to
extract more data (from an end user for example) until a goal is reached. An
inference engine using forward chaining searches the inference rules until it
finds one where the antecedent (If clause) is known to be true. When found it
can conclude, or infer, the consequent (Then clause), resulting in the addition
of new information to its data.
Inference engines will iterate through this process until a goal is reached.
For example, suppose that the goal is to conclude the color of a pet named
Fritz, given that he croaks and eats flies, and that the rule base contains the
following four rules:
1. If X croaks and eats flies - Then X is a frog
2. If X chirps and sings - Then X is a canary
3. If X is a frog - Then X is green
4. If X is a canary - Then X is yellow
Backward Chaining:
Backward chaining (or backward reasoning) is an inference method used in
automated theorem provers, proof assistants and other artificial intelligence
applications. It is one of the two most commonly used methods of reasoning
with inference rules and logical implications – the other is forward chaining.
Backward chaining is implemented in logic programming by SLD resolution.
Backward chaining starts with a list of goals (or a hypothesis) and works
backwards from the consequent to the antecedent to see if there is data
available that will support any of these consequents. An inference engine
using backward chaining would search the inference rules until it finds one
which has a consequent (Then clause) that matches a desired goal. If the
antecedent (If clause) of that rule is not known to be true, then it is added to
the list of goals (in order for one's goal to be confirmed one must also provide
data that confirms this new rule).
For example, suppose that the goal is to conclude the color of my pet Fritz,
given that he croaks and eats flies, and that the rule base contains the
following four rules:
1. If X croaks and eats flies – Then X is a frog
2. If X chirps and sings – Then X is a canary
3. If X is a frog – Then X is green
4. If X is a canary – Then X is yellow
Page 7
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
EXPECTATION-V
Represent This Puzzle in Prolog Programming [6]
puzzle(Start_State, Goal) :-
nl,
empty_stack(Empty_stack),
stack(Start_State, Empty_stack, Stack),
path(Start_State, Goal, Stack).
cross(Farmer, Crossing_Farmer),
not(unsafe(state(Crossing_Farmer, Fox, Goose, Crossing_Farmer))),
Page 8
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
empty_stack([]).
reverse_print_stack(Stack) :-
empty_stack(Stack).
reverse_print_stack(Stack) :-
stack(ElementA, ElementB, Stack),
reverse_print_stack(ElementB),
write(ElementA),
nl.
member_stack(State, Stack) :-
member(State, Stack).
Page 9
AI & Logic Programming RA3803A05 CAP-451/Design Problem-1
writelist([]) :- nl.
writelist([ElementA|ElementB]) :-
print(ElementA),
tab(1),
writelist(ElementB).
cross(s, n).
cross(n, s).
Another Solution:
change(e,w).
change(w,e).
move([X,X,Goose,Grain],Fox,[Y,Y,Goose,Grain]) :-
change(X,Y).
move([X,Fox,X,Grain],Goose,[Y,Fox,Y,Grain]) :-
change(X,Y).
move([X,Fox,Goose,X],Grain,[Y,Fox,Goose,Y]) :-
change(X,Y).
move([X,Fox,Goose,C],nothing,[Y,Fox,Goose,C]) :-
change(X,Y).
oneEq(X,X,_).
oneEq(X,_,X).
safe([Man,Fox,Goose,Grain]) :-
oneEq(Man,Goose,Fox),
oneEq(Man,Goose,Grain).
solution([e,e,e,e],[]).
solution(Config,[Move|Rest]) :-
move(Config,Move,NextConfig),
safe(NextConfig),
solution(NextConfig,Rest).
Page
10