Professional Documents
Culture Documents
Artificial Intelligence
Submitted To
Sr. Lect.
Submitted By
Rahul Soni
A3803A04
MCA Hons.
10811115
Expectation I
1. Farmer will cross the river with goose leaving grain and fox on the
left hand side of the river.
2. Farmer leaves the goose on the right bank and come bank alone to
the left bank.
3. Farmer picks the fox, move to the right bank, leave the fox on the
right bank and get the goose back on to the ship.
4. On the 4th move, farmer the goose back on to the left bank, left the
goose there and pick the grain.
5. This time, farmer moves the grain along with hin to the right bank.
Farmer drops the grain on the right bank.
7. In this move, farmer pick the goose and unboard the ship to get all its
posessions and himself on the other side of the river.
Expectation II
1. Farmer will cross the river with goose leaving grain and fox on
the left hand side of the river.
2. Farmer leaves the goose on the right bank and come bank alone
to the left bank.
3. Farmer picks the fox, move to the right bank, leave the fox on the
right bank and get the goose back on to the ship.
4. On the 4th move, farmer the goose back on to the left bank, left
the goose there and pick the grain.
5. This time, farmer moves the grain along with hin to the right
bank. Farmer drops the grain on the right bank.
7. In this move, farmer pick the goose and unboard the ship to get
all its posessions and himself on the other side of the river.
W=Wolf
G=Goose
C=Corn
~=River
Expectation IV
Forward reasoning or backward reasoning?
To come up with the solution for the problem, a combination of both the forward and
backward chaining are required.
Forward reasoning is preferred for this problem as this problem is solved using the GPS
i.e. the general problem solution. This solution uses the forward reasoning to arrive at the
solution of a problem.
Simultaneously, backward reasoning is also necessary as sometimes we need to backtrack
when the certain fact goes wrong.
initial(X) :- sort([farmer,fox,goose,grain],X).
check_invalid(_) :- true.
find_solution(Goal,Goal,_, Moves,Plan) :-
reverse(Moves,Plan).
cross(Initial,[Near,Far],Move),
sort(Near,SNear),
sort(Far,SFar),
check_invalid(SNear),
check_invalid(SFar),
\\+(member([SNear,SFar],History)),
cross([Near,Far],Result,Move) :-
member(farmer, Near),
cross([Near,Far],[NN,NF],Move) :-
member(farmer, Far),
cross1([Near,Far],[NN,NF],Move,Direction) :-
select(farmer,Near,NN),
append([farmer],Far, NF),
cross1([Near,Far],[NN,NF],Move,Direction) :-
select(farmer,Near,RemainingNear),
member(Animal,RemainingNear),
select(Animal,RemainingNear,NN),
append([farmer,Animal],Far, NF),
initial(I),
find_solution([I,[]],[[],I],[],[],Plan).