A Kahn Process Network was implemented with Pytho:
Ideas:
Use the Python list to simulate the queue.
One queue per channel
Use a list (Fglog) to record all push-to-FG channel values for the final display
The channel's queue is set to a global variable
Code implementation:
h1f=[];fg=[];gh1=[];gh0=[];h0f=[]fglog=[]h1firstrun=Trueh0firstrun=Trueflastchoose=0gLastChoose=0defH1 ():GlobalH1firstrunifH1firstrun:h1firstrun=FalseGlobalh1f H1f.append (1) Else: GlobalGH1ifLen (GH1)! =0:value=gh1.pop (0)Globalh1f h1f.append (value)defH0 ():GlobalH0firstrunifH0firstrun:h0firstrun=FalseGlobalh0f h0f.append (0)Else: GlobalGh0ifLen (gh0)! =0:value=gh0.pop (0)Globalh0f h0f.append (value)deff ():GlobalFlastchooseifFlastchoose = =0:Globalh1fifLen (h1f)! =0:value=h1f.pop (0)GlobalFGGlobalfglog fg.append (value) fglog.append (value) flastchoose= 1Else: Globalh0fifLen (h0f)! =0:value=h0f.pop (0)GlobalFGGlobalfglog fg.append (value) fglog.append (value) flastchoose=0defg ():GlobalFGifLen (FG)! =0:GlobalGlastchoose Value=fg.pop (0)ifGlastchoose = =0:Globalgh1 gh1.append (value) glastchoose= 1Else: Globalgh0 gh0.append (value) glastchoose=0if __name__=='__main__': Runorder='Order3' PrintRunorderifRunorder = ='Order1': forIinchRange (50): H1 (); H0 (); F (); G ()elifRunorder = ='Order2': forIinchRange (50): H1 (); H1 (); H1 (); G (); F (); H0 (); H0 (); elifRunorder = ='Order3': forIinchRange (50): f (); F (); G (); H1 (); H0 (); H1 (); H0 (); H0 (); G ()PrintFglog
Python implementations of Kahnprocessnetwork