slide1
Download
Skip this Video
Download Presentation
The “Russian Farmer” Problem Continued

Loading in 2 Seconds...

play fullscreen
1 / 7

Lecture - PowerPoint PPT Presentation


  • 265 Views
  • Uploaded on

The “Russian Farmer” Problem Continued. (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).

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lecture' - Melvin


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

The “Russian Farmer” Problem

Continued

Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued

slide2

(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)

Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued

slide3

?- 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, Cabbage and Wolf Problem Continued

slide4

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 issafe

not( member(NextNode,Visited) ),% Check for recurrence

path(NextNode, Target,[NextNode |Visited],Path),!.

path(Target, Target,Path,Path).% Reached the goal

Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued

slide5

move(state(X,X,G,C),state(Y,Y,G,C)):-opposite(X,Y). % FARMER & WOLF

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, Cabbage and Wolf Problem Continued

slide6

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.

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.

Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued

slide7

?-go(X,Y).

?-go(state(left,left,left,left),Y).

Lecture 24 Farmer, Goat, Cabbage and Wolf Problem Continued

ad