(*TASEP in contact with reservoirs ; entry,exit rates are α,β ; jump rate to the right is 1*)

(*definitions for graphical representations*)

color[n_]=(1-n) White+n Black;

plotconf[conf_]:=Graphics@Table[{color[conf[[i]]],Disk[{i,0},9/10/2]},{i,1,Length@conf}]

tabconf[conf_]:=Table[{color[conf[[i]]],Disk[{i,0},9/10/2]},{i,1,Length@conf}]

colorhist[n_]=(1-n) White+n Purple;

tabconfhist[hist_]:=Table[
confj=hist[[j]];Table[{colorhist[confj[[i]]],Disk[{i,-j},9/10/2]},{i,1,Length@confj}],
{j,1,Length@hist}]

(*evolution of configurations*)

L=30;ninit=Table[0,{L}];

evolve[m_,α_,β_]:=Module[{tabprob,tabevent,event,n=m},
tabprob={α (1-n[[1]])}~Join~Table[n[[i]](1-n[[i+1]]),{i,1,L-1}]~Join~{β n[[L]]};
(*event {{i},{j}} is creation in i, annihilation in j*)
tabevent={{{1},{}}}~Join~Table[{{i+1},{i}},{i,1,L-1}]~Join~{{{},{L}}};
event=RandomChoice[tabprob->tabevent];
Do[n[[i]]=1,{i,event[[1]]}];Do[n[[j]]=0,{j,event[[2]]}];
n
]

(*to stop the animation:suppress the result from this cell*)
Manipulate[
DynamicModule[{nn=ninit},
Framed[Show[Graphics[Pause[.01];Dynamic[tabconf[nn=evolve[nn,α,β];nn]]],
ImageSize->800
]]]
,
{{α,.2},.01,.99},{{β,.4},.01,.99}
]

(*evolution,including past configuration (without their times)*)

L=15;ninit=Table[1,{L}];

(*duration is the number of configurations that are remembered*)
IS=500;duration=15;
Manipulate[
DynamicModule[{nn=ninit,hist=Table[ninit,{duration}]},
Framed[Dynamic[Column[{
Graphics[tabconf[nn=evolve[nn,α,β];nn],ImageSize->IS],
Graphics[
hist=(Prepend[hist,nn])[[;;duration]];
tabconfhist[hist]
,ImageSize->IS]
}]
]]]
,
{{α,.2},.01,.99},{{β,.2},.01,.99}
]