You are on page 1of 9

Design Problem I

Artificial Intelligence
Submitted To

Mr. Jaswinder Singh

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.

6. In this move, farmer gets back alone to the left 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

How many journeys will it take to cross the river?

The solution to the problem is as follows

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.

6. In this move, farmer gets back alone to the left 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.

Total number of moves 7


Expectation III
State space search
Symbols used
F=Farmer

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.

Backward chaining (goal-driven processing) A strategy for controlling inference procedures, or


goal selection, during problem solving. In the case of a rule-based system, a rule whose
consequent part matches the desired goal can be used to generate sub goals from the rule's
antecedent part. The sub goals then become target goals and the process is repeated recursively
until all sub goals have been satisfied.
Forward chaining (data-driven processing) A control procedure used in problem solving and
rule-based systems. When a data item matches the antecedent part of a rule, then the
conditions for that rule have been satisfied and the consequent part of the rule is executed. The
process then repeats, usually through some form of conflict-resolution mechanism to prevent
the same rules firing continuously.
Whether you use forward or backwards reasoning to solve a problem depends on the properties
of your rule set and initial facts. Sometimes, if you have some particular goal (to test some
hypothesis), then backward chaining will be much more efficient, as you avoid drawing
conclusions from irrelevant facts. However, sometimes backward chaining can be very wasteful
- there may be many possible ways of trying to prove something, and you may have to try
almost all of them before you find one that works. Forward chaining may be better if you have
lots of things you want to prove (or if you just want to find out in general what new facts are
true); when you have a small set of initial facts; and when there tend to be lots of different rules
which allow you to draw the same conclusion. Backward chaining may be better if you are trying
to prove a single fact, given a large set of initial facts, and where, if you used forward chaining,
lots of rules would be eligible to fire in any cycle.
Expectation V
Puzzle in Prolog Programming

initial(X) :- sort([farmer,fox,goose,grain],X).

% exclude invalid combinations

check_invalid([goose, fox]) :- !, fail.

check_invalid([goose, grain]) :- !, fail.

check_invalid([goose, fox, grain]) :- !,fail.

check_invalid(_) :- true.

% check if we have reached the goal

find_solution(Goal,Goal,_, Moves,Plan) :-

reverse(Moves,Plan).

% try to make a move, check whether the result is valid

% and check the history to see if we are repeating a move

find_solution(Initial,Goal,History, Moves, Plan) :-

cross(Initial,[Near,Far],Move),

sort(Near,SNear),

sort(Far,SFar),

check_invalid(SNear),

check_invalid(SFar),
\\+(member([SNear,SFar],History)),

find_solution([SNear,SFar], Goal, [[SNear,SFar] | History], [ Move | Moves], Plan).

% cross from Near to Far side

cross([Near,Far],Result,Move) :-

member(farmer, Near),

cross1([Near,Far],Result, Move, forward).

% cross from Far to Near side

cross([Near,Far],[NN,NF],Move) :-

member(farmer, Far),

cross1([Far,Near],[NF,NN], Move, backward).

% let the farmer cross alone

cross1([Near,Far],[NN,NF],Move,Direction) :-

select(farmer,Near,NN),

append([farmer],Far, NF),

Move = [Direction, farmer, []].

% let the farmer cross with one Animal/grain

cross1([Near,Far],[NN,NF],Move,Direction) :-

select(farmer,Near,RemainingNear),

member(Animal,RemainingNear),

select(Animal,RemainingNear,NN),

append([farmer,Animal],Far, NF),

Move = [Direction, farmer, [Animal]].


run(Plan) :-

initial(I),

find_solution([I,[]],[[],I],[],[],Plan).

You might also like