% This m-file sets up the one step state transition 
% P of a N Geo/D/1/B queue - which can be use to model 
%  an ATM switch - with a balanced loading pattern
% of Bernoulli arrivals on each of N input ports
% and a output port buffer size of K 
% From the notes we can determine the
% elements of P from the binomial density function 
% the user must spefcify NP - the number of ports,
%  K - the output buffer size, and p the probability of a cell
% arrival in a slot at a input port

%Compute binomial density of arrivals

jtemp = 0:NP;
NA = binopdf(jtemp,NP,p);

% initialize P to all zeros 
P = zeros(K+1, K+1);

% Set transition probabilities for normal states

upperlimit = K+1 - (NP-1);

P(1,1:(NP+1)) = NA;

for i=2: upperlimit
  P(i, i-1:i+NP-1) = NA;
end

% Set transition probabilities for state where a transition
%  to a full buffer is possible

for i=(upperlimit+1):(K+1)
 for j = (i-1):K
   P(i,j) = NA(j+1 - (i-1));
 end
 fsum = 0;
 for j=((K +1)-(i-1)):NP
   fsum = fsum + NA(j+1);
 end
 P(i,(K+1)) = fsum;
end

