صفحه 1:
The “Russian Farmer”
Problem
Continued
Lecture 24 Farmer,
Cabba:
صفحه 2:
(F,W,G,C)
x 3 x
(tL) (LL) 6 1) اام
QLLy (Ayr, 1
|
@ 17,1) (Lr) (r
(rr) Gril) Gln) QLrr
(irate ie) 1, Lr, 1)
(rr, 7,1) رای راردا (Lr
ey Lyn) (aren aed
با یدیم ابا ب ( ۳ Q@LLn dir
۳ rL)
on (ony eee
با رد
Lecture 24 Farmer, Goat, 2
Cabbage and Wolf Problem
0
۳
صفحه 3:
(F,W,G,C)
121
G 1 ۲, 1(
Gin
0 كا ا 1-2
Ca 1 و 7
(Coes el else)
و 0 lr)
صفحه 4:
?- go( state(left,left,left,left), state(right,right,right,right) ).
A solution is:
The farmer takes the Goat from left of the river to right
The farmer crosses the river from right to left
The farmer takes the Wolf from left of the river to right
The farmer takes the Goat from right of the river to left
The farmer takes the cabbage from left of the river to right
The farmer crosses the river from right to left
The farmer takes the Goat from left of the river to right
A solution is:
The farmer takes the Goat from left of the river to right
The farmer crosses the river from right to left
The farmer takes the cabbage from left of the river to right
The farmer takes the Goat from right of the river to left
The farmer takes the Wolf from left of the river to right
The farmer crosses the river from right to left
The farmer takes the Goat from left of the river to right
No Lecture 24 Farmer, Goat, 4
Cabbage and Wolf Problem
7 رجي
صفحه 5:
go(Start,Target):-
path(Start, Target,[Start],Path),
write(‘A solution is:’),nl,
write_path(Path).
path(Start, Target, Visited, Path):-
move(Start, NextNode), %
Generate a move
not( unsafe(NextNode) ), % Check
that it is safe
not( member(NextNode, Visited) ), %
Check for recurrence
path(NextNode, Target,[NextNode |Visited],Path),!.
صفحه 6:
move(state(X,X,G,C),state(Y,Y,G,C)):-opposite(X,Y). %
move(state(X,W,X,C),state(Y,W,Y,C)):-opposite(X,Y). ۵
FARMER &GOAT
move(state(X,W,G,X),state(Y,W,G,Y)):-opposite(X,Y). »
FARMER & Cbg.
move(state(X,W,G,C),state(Y,W,G,C)):-opposite(X,Y). %
FARMER alone
unsafe( state(F,X,X,_) ):- opposite(F,X),!. % The wolf eats
the goat
Other unsafe clauses
opposite(left,right).
opposite(right, left).
Lecture 24 Farmer, Goat, 6
صفحه 7:
write_path( [] ).
write_path( [H1,H2|T] ) :- write_move(H1,H2),
write_path({H2|T]).
write_move( state(X,W,G,C), state(Y,W,G,C) ) :-!,
write(‘The farmer crosses the river
from ‘), write(X),write(‘ to
‘),write(Y),nl.
WILLE IMUVEL SLALELA,A,U, LU), SLALEL 1, 1,0,U) J 1,
write(‘The farmer takes the Wolf from
the ‘), write(X),write(‘side of the river
to ‘),write(Y),nl.
Lecture 24 Farmer, Goat,
صفحه 8:
?-go(X,Y).
?-go(state (left, left,left,left),Y).
Lecture 24 Farmer, Goat,
Cabbage and Problem