###========+=========+=========+=========+=========+=========+=========+=
## PROGRAM : discrete-TASEP.py
## PURPOSE : implement the Markov-chain algorithm for an asymmetric 
##           exclusion process on L sites
## LANGUAGE: Python 2.6, 2.7 
###========+=========+=========+=========+=========+=========+=========+=
import random, pylab,math
random.seed(2)
L=100
alpha=.2
beta=.2

Ntime=2000000
state=[0 for k in range(L+1)]
for iter in range(Ntime):
   k=random.randint(0,L)
   if k==0:
      if random.random() < alpha: state[1]=1
   elif k==L:
         if random.random() < beta: state[L]=0
   elif state[k]==1 and state[k+1]==0: 
      state[k+1]=1
      state[k]=0
   if iter%2000 == 0: 
      yaxis=[]
      for i in range(L):
          if state[i+1]==1: yaxis.append(i)
      xaxis=[iter for k in range(len(yaxis))]
      pylab.plot(xaxis,yaxis,'ro')
pylab.xlabel('Number of steps')
pylab.ylabel('System configuration')
pylab.show()
