view Examples/dining_phil/ve @ 0:cfb7c6b24319

Initial revision
author kono
date Thu, 30 Aug 2007 14:57:44 +0900
parents
children
line wrap: on
line source

ph_think(L,R,I)         :- @free(L,R,I),less(4)
	&& ph_left(L,R,I).
ph_left(L,R,I)          :- @left(L,R,I),skip
	&& ph_eat(L,R,I).
ph_eat(L,R,I)           :- @both(L,R,I),length(2)
	&& ph_left_off(L,R,I).
ph_left_off(L,R,I)      :- @right(L,R,I),skip
	    && ph_think(L,R,I).

    less(N) :- M=N,less1(M).
    less1(N) :- N = 0, empty.
    less1(N) :- @N = N+1,next(less1(N)).

left(I,_,(I,left)).
both(I,I,(I,eat)).
right(_,I,(I,right)).
free(_,_,(_,free)).

ph_think(L,R,I)         :- empty.
ph_left(L,R,I)          :- empty.
ph_eat(L,R,I)           :- empty.
ph_left_off(L,R,I)      :- empty.

diningPh(Sa,Sb,Sc) :- 
	ph_think(A,B,(1,Sa)),
	ph_think(B,C,(2,Sb)),
	ph_think(C,A,(3,Sc)),
	#write((Sa,Sb,Sc)).

test :- length(10),diningPh(A,B,C).