Logic Programming Prolog 6
اسلاید 1: Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued1The “Russian Farmer” ProblemContinued
اسلاید 2: Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued2(F,W,G,C)(l, l, l, l)(r, r, l, l) (r, l, l, l) (r, l, r, l)(r, l, l, r)(l, l, l, l) (l, l, r, l) (r, r, r, l) (r, l, r, l)(r, l, r, r)(l, r, r, l) (l, r, l, l) (l, l, r, l) (l, l, r, r) (l, l, l, r) (l, l, r, l)(r, r, r, l) (r, r, l, r) (r, r, l, l) (r, l, l, r) (r, r, l, r) (r, l, r, r)(l, l, l, r) (l, r, l, l) (l, r, l, r) (l, l, l, r) (l, r, l, r) (l, r, l, l)(r, r, l, r) (r, r, r, r) (r, r, r, r) (r, r, l, r)XXXXXXXXXXXXXXXXXXX
اسلاید 3: Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued3(F,W,G,C)(l, l, l, l)(r, l, r, l)(l, l, r, l) (r, r, r, l) (r, l, r, r)(l, r, l, l) (l, l, l, r) (r, r, l, r) (r, r, l, r) (l, r, l, r) (l, r, l, r) (r, r, r, r)
اسلاید 4: Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued4?- 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 rightThe farmer crosses the river from right to leftThe farmer takes the Wolf from left of the river to rightThe farmer takes the Goat from right of the river to leftThe farmer takes the cabbage from left of the river to rightThe farmer crosses the river from right to leftThe farmer takes the Goat from left of the river to rightA solution is: The farmer takes the Goat from left of the river to rightThe farmer crosses the river from right to leftThe farmer takes the cabbage from left of the river to rightThe farmer takes the Goat from right of the river to leftThe farmer takes the Wolf from left of the river to rightThe farmer crosses the river from right to leftThe farmer takes the Goat from left of the river to rightNo
اسلاید 5: Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued5path(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),!.path(Target, Target,Path,Path). % Reached the goalgo(Start,Target):- path(Start, Target,[Start],Path), write(‘A solution is:’),nl, write_path(Path).
اسلاید 6: Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued6move(state(X,X,G,C),state(Y,Y,G,C)):-opposite(X,Y). % FARMER & WOLFunsafe( state(F,X,X,_) ):- opposite(F,X),!. % The wolf eats the goatOther unsafe clausesopposite(left,right).opposite(right,left).move(state(X,W,X,C),state(Y,W,Y,C)):-opposite(X,Y). % FARMER &GOATmove(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
اسلاید 7: Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued7write_path( [] ).write_path( [H1,H2|T] ) :- write_move(H1,H2), write_path([H2|T]).write_move( state(X,X,G,C), state(Y,Y,G,C) ) :-!,write(‘The farmer takes the Wolf from the ‘), write(X),write(‘side of the river to ‘),write(Y),nl.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.
اسلاید 8: Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued8?-go(X,Y).?-go(state(left,left,left,left),Y).
نقد و بررسی ها
هیچ نظری برای این پاورپوینت نوشته نشده است.