Home      Affiliated Colleges      Course content      First Sem     Second Sem     Third Sem     Fourth Sem     Fifth Sem     Sixth Sem     Seventh Sem     Eighth Sem     Lab report 4th sem     Contact    

Thursday, January 27, 2011

Artificial Intelligence: Prolog Program for Solving Water Jug Problem:

action(X:Y,0:Y ):-
   X > 0.
action(X:Y,X:0):-
   Y > 0.
action(X:Y,4:Y):-
   X < 4.
action(X:Y,X:3):-
   Y < 3.
action(X:Y,4:Z):-
     X < 4,Z is Y - (4 - X),Z >= 0.
action(X:Y,Z:3):-
     Y < 3,Z is X - (3 - Y ),Z >= 0.
action(X:Y,Z:0):-
       Y > 0,Z is (X + Y),Z =< 4.
action(X:Y,0:Z):-
     X > 0,Z is (X + Y),Z =< 3.
path(X):-
 path(0:0,[0:0],X).
path(2:0,Visited,Visited).
path(State,Visited,Path):-
   action(State,NewState),
      not(member(NewState,Visited)),
   path(NewState,[NewState|Visited],Path).
member(X,[X|Y]).
member(X,[Y|Z]):- 
  member(X,Z).

No comments:

Post a Comment

^ Scroll to Top Related Posts with Thumbnails ^ Go to Top