Mercurial > hg > Applications > Tokio
view Examples/dining_phil/di @ 0:cfb7c6b24319
Initial revision
author | kono |
---|---|
date | Thu, 30 Aug 2007 14:57:44 +0900 |
parents | |
children |
line wrap: on
line source
philosopher(Lfork,Rfork,Sta,Id):- Sta=think_, @Sta=pick_l. philosopher(Lfork,Rfork,Sta,Id):-Sta=pick_l, (@Lfork=Id, @Sta=pick_r ; @Sta=pick_l). philosopher(Lfork,Rfork,Sta,Id):-Sta=pick_r, @Lfork=Lfork, (@Rfork=Id, @Sta=eating ; @Sta=pick_r). philosopher(Lfork,Rfork,Sta,Id):- Sta=eating, @Rfork=Rfork, @Sta=free_l. philosopher(Lfork,Rfork,Sta,Id):- Sta=free_l, @Sta=free_r. philosopher(Lfork,Rfork,Sta,Id):- Sta=free_r, @Sta=think_. dining_philosopher(F,S):- length(20), [Fa,Fb,Fc,Fd,Fe]=F, [Sta,Stb,Stc,Std,Ste]=S, #philosopher(Fa,Fb,Sta,a), #philosopher(Fb,Fc,Stb,b), #philosopher(Fc,Fd,Stc,c), #philosopher(Fd,Fe,Std,e), #philosopher(Fe,Fa,Ste,f), #write((Sta,Stb,Stc,Std,Ste,-(Fa,Fb,Fc,Fd,Fe))). d0:- dining_philosopher( [_,b,b,e,e], [think_,eating,think_,eating,think_]). d1:- dining_philosopher( [_,_,_,_,_], [think_,think_,think_,think_,think_]).