02-Matlab Subroutines Used in the Simulation
-
Upload
trivediurvi9087 -
Category
Documents
-
view
214 -
download
0
description
Transcript of 02-Matlab Subroutines Used in the Simulation
MATLAB SUBROUTINES USED IN THE SIMULATION
1. Channel allocation Based on Aggressive Algorithm Given the channel state, to allocate the
channel based on the aggressive Algorithm. Input (no,S,sto_state) & output cell array X with 4
columns(sto_state,ch_lock, norelock,chrelock)
function[X]=allo_agra7(no,S,sto_state);
ch_lock=0;
norelock=0;
chrelock=0;
nor_cost=call_cost7(no,S,sto_state);
if min(nor_cost)~=inf
chslock=find(nor_cost==min(nor_cost));
ch_lock=chslock(1,1);
sto_state(no,(ch_lock+2))=1;
sto_state(no,1)=(sto_state(no,1))+1;
else ceny=2*(sto_state(no,3:(S+2)));
nbd=unique([0,nbd_cells7(no)]);
len=length(nbd);
for k=1:(len-1),
y(k,:)=sto_state(nbd(1,(k+1)),3:(S+2));
end;
Y=(sum(y))+ceny;
singy=find(Y==1);
if (length(singy))~=0
for j=1:(length(singy)),
a=find(y(:,singy(1,j))==1)';
at_l=nbd(1,(a(1,1)+1));
agre_cost=call_cost7(at_l,S,sto_state);
if (min(agre_cost))~=inf
chsrelock=find(agre_cost==min(agre_cost));
chrelock=chsrelock(1,1);
sto_state(no,(singy(1,j)+2))=1;
sto_state(no,1)=sto_state(no,1)+1;
sto_state(at_l,(chrelock+2))=1;
sto_state(at_l,(singy(1,j)+2))=0;
ch_lock=singy(1,j);
norelock=at_l;
break;
elseif (j==length(singy))
sto_state(no,2)=sto_state(no,2)+1;
end;
end;
else
sto_state(no,2)=sto_state(no,2)+1;
end;
end;
X{1,1}=sto_state;
X{1,2}=ch_lock;
X{1,3}=norelock;
X{1,4}=chrelock;
2. To allocate/block a call based on the cost for that particular call in that particular cell returns cell
array with column 1 as sto_state & column 2 as ch_lock
function[A]=allo_dcam7(no,S,sto_state,fd);
X=call_cost17(no,S,sto_state,fd);
x=min(X);
ch_lock=0;
if x==inf
sto_state(no,2)=(sto_state(no,2))+1;
else
sto_state(no,1)=(sto_state(no,1))+1;
for i=1:S,
if X(1,i)==x
ch_lock=i;
sto_state(no,(ch_lock+2))=1;
break;
end;
end;
end;
A{1,1}=sto_state;
A{1,2}=ch_lock;
3. Routine to Identify a Cell in which call is under progress There is always a requirement
to find where is a given call in progress. Given any coordinate of the mobile handset, it will be able to
find the number of cell in which call is under progress.
function[no]=call_cell(x,y);
x_figure=x/((sqrt(3))*2/2);
a1=(ceil(x_figure))*(sqrt(3))*2/2;
a2=(floor(x_figure))*(sqrt(3))*2/2;
y_figure=y/(3*2/2);
b1=(ceil(y_figure))*3*2/2;
b2=(floor(y_figure))*3*2/2;
e1=coord_fn(a1,b1);
e2=coord_fn(a1,b2);
e3=coord_fn(a2,b1);
e4=coord_fn(a2,b2);
e=[e1,e2,e3,e4];
for j=1:4,
if isnan(e(j))~=1
e_c=no_coord(e(j));
e_x=e_c(1,1);
e_y=e_c(1,2);
d(j)=sqrt((e_x-x)^2+(e_y-y)^2);
else d(j)=inf;
end;
end;
for j=1:4,
if (min(d))>2
no=NaN;
elseif (min(d)<=2)&(d(j)==min(d))
no=e(j);
end;
end;
4. Co-channel Set When ever any cell is identified where call is under progress on any particular
channel, all the co-channel cells of the referred channel cane be located.
function[X]=coch_set(no);
%given a cell (no,s,N,M),to find the set of
%immediate cochannel cells
j=2;
c=no_coord(no);
a=c(1,1);
b=c(1,2);
d=(sqrt(7))*(sqrt(3))*2;
theta=(asin(sqrt(((j^2)*3/4)/(7))))*180/pi;
for q=1:6
alpha=theta+((q-1)*60);
ang=(alpha)*pi/180;
a1=a+d*cos(ang);
b1=b+d*sin(ang);
X(q)=coord_fn(a1,b1);
end;
X=[X(1),X(2),X(3),X(4),X(5),X(6)];
5. Identify central Cell Whenever approximate center coordinates are given, this will
return the cell number if it belongs to a cell.
function[c]=coord_fn(a,b);
x_element=round(a/((sqrt(3))*2/2));
y_element=round(b/(3*2/2));
if (((x_element-y_element)/2)<(7-0.5))&...
(((x_element-y_element)/2)>=0)&(y_element>=0)...
&(y_element<=(7-1))
c=floor((1+((x_element-y_element)/2)+...
7*(y_element)));
else c=NaN;
end;
6. Cost of Re-allocation After allocation of channel call is awaited completion. Once
completed, cost of re-allocation of channel is estimated. Minimum cost channel is released. Cost_re17
calculates cost as per the cost formula and cost_re27 calculates the cost as per the analytical model.
6.1 function[X]=cost_re17(no,S,sto_state,fd);
x=sto_state(no,3:(S+2));
tot_ch=sum(x);
eng_ch=find(x);
nbd=unique([0,nbd_cells7(no)]);
len=length(nbd);
for i=1:S,
for k=1:(len-1),
if ismember(i,eng_ch)
if ismember(i,fd{1,nbd(1,(k+1))})
q(k,i)=0;
else q(k,i)=1;
end;
if ismember(i,fd{1,no})==1
qx(1,i)=0;
else qx(1,i)=1;
end;
y(k,:)=avail_ch17(nbd(1,(k+1))...
,S,sto_state);
if y(k,i)==1
b(k,i)=0;
else b(k,i)=1;
end;
r(k,i)=b(k,i)+(2*q(k,i));
else qx(1,i)=-(inf);
r(k,i)=inf;
end;
end;
end;
R=sum(r);
for i=1:S,
X(1,i)=(1-qx(1,i))+R(1,i);
end;
6.2 Reallocation Cost Given the ch state,this function returns the cost of re_allocation based
on analytical model.Input as (no,S,sto_state)
function[X]=cost_re27(no,S,sto_state);
x=sto_state(no,3:(S+2));
eng_ch=find(x);
sto_state1=sto_state;
sto_state1(no,3:(S+2))=zeros(1,S);
nbd=unique([0,nbd_cells7(no)]);
len=length(nbd);
for j=1:(len-1),
y(j,:)=avail_ch7(nbd(1,(j+1)),S,sto_state1);
end;
Y=sum(y);
for i=1:S,
if ismember(i,eng_ch)==1
X(1,i)=Y(1,i);
else
X(1,i)=inf;
end;
end;
7. Aggressive DCA Algorithm Given average inter arrival time & average holding time, it will
estimate the probability of blocking in aggressive DCA using analytical model. Input (S,L,T,Y).
function[prob]=dca_agra7n(S,L,T,Y);
sto_state=zeros(49,(S+2));
seq=1:1:Y;
loc_com=(1+(floor([48*ones(1,Y)].*[rand(1,Y)])));
ex_durn=exprnd(T,1,Y);
ex_iarr=exprnd(L,1,Y);
ex_arri=zeros(1,Y);
for i=1:(Y-1),
ex_arri=(ex_arri)+((ex_iarr(1,i))*[zeros(1,i),ones(1,(Y-i))]);
end;
ex_inibal=(ex_iarr)-(ex_iarr(1,1))*(ones(1,Y));
ex_arr=[((ex_inibal)+(ex_arri));ones(1,Y);seq;...
loc_com;zeros(1,Y)];
ex_fini=[((ex_durn)+(ex_arr(1,:)));zeros(1,Y);seq;...
loc_com;zeros(1,Y)];
ex_comp=[ex_arr(:,1),ex_fini,ex_arr(:,(2:Y))];
tot_seq=sort([ex_arr(1,:),ex_fini(1,:)]);
temp_comp=zeros(5,1);
for i=1:(2*Y),
j=i:1:(2*Y);
a=find(ex_comp(1,j)==tot_seq(1,i));
k=a(1,1);
temp_comp=ex_comp(:,i);
ex_comp(:,i)=ex_comp(:,k+i-1);
ex_comp(:,k+i-1)=temp_comp;
end;
pre_arr=[0,ex_comp(1,1:(2*Y-1))];
ex_comp(1,:)=ex_comp(1,:)-pre_arr;
for i=1:2*Y,
tim_elap(ex_comp(1,i));
if (ex_comp(2,i)==1)
A=allo_agra7(ex_comp(4,i),S,sto_state);
sto_state=A{1,1};
if (A{1,3}~=0)
for r=1:i-1,
if ((ex_comp(4,r)==A{1,3})&...
(ex_comp(5,r)==A{1,2}))
ex_comp(5,r)=A{1,4};
break;
end;
end;
end;
ex_comp(5,i)=A{1,2};
else b=find(ex_comp(3,1:(i-1))==ex_comp(3,i));
if (ex_comp(5,b(1,1))~=0)
E=deallo_dca1a7n(ex_comp(4,i),S,...
sto_state,ex_comp,(i-1));
sto_state=E{1,1};
chpos=E{1,2};
ex_comp(5,chpos)=ex_comp(5,b(1,1));
ex_comp(5,b(1,1))=0;
% sto_state(ex_comp(4,b(1,1)),ex_comp(5,b(1,1))...
% +2)=0;
end;
end;
end;
bc=sum((sto_state(:,2))')
ac=sum((sto_state(:,1))')
prob=bc/(ac+bc);
8. DCA (P) Algorithm when handoff considered To estimate the probability of blocking in
DCA(P)with handoff. Speed of the mobile also added in the routine.
function[P]=dca_hand7(S,L,T,Y,V);
dd=0;
sto_state=zeros(49,(S+2));
A=pre_stofnn1(L,T,Y,V);
ex_comp=A{1,1};
len=A{1,2};
for i=1:len,
tim_elap(ex_comp(1,i));
if (ex_comp(2,i)==1)
if (ex_comp(6,i)==0)
A=allo_dca7(ex_comp(4,i),S,sto_state);
sto_state=A{1,1};
ex_comp(5,i)=A{1,2};
else B=allo_dca7(ex_comp(4,i),S,sto_state);
sto_state=B{1,1};
ex_comp(5,i)=B{1,2};
if (B{1,2}==0)
dd=dd+1;
end;
end;
else b=find(ex_comp(3,1:(i-1))==ex_comp(3,i));
if (ex_comp(5,b(1,1))~=0)
E=deallo_dca1a7n(ex_comp(4,i),S,...
sto_state,ex_comp,(i-1));
sto_state=E{1,1};
chpos=E{1,2};
ex_comp(5,chpos)=ex_comp(5,b(1,1));
ex_comp(5,b(1,1))=0;
end;
end;
end;
dc=dd;
nc=sum((sto_state(:,2))');
bc=nc-dc;
hc=(len/2)-Y;
ac=sum((sto_state(:,1))');
pb=bc/(Y);
pd=dc/(hc);
P=[pb,pd];
9. DCA (A) Algorithm when handoff considered Given average inter arrival time & average
holding time to estimate the probability of blocking in aggressive DCA using mathematical model.
function[P]=dca_handcen(S,L,T,Y,V,H);
sto_stateh=zeros (49, (H+2));
sto_state=zeros (49, (S+2));
A=pre_stofnn1 (L,T,Y,V);
ex_comp=A{1,1};
len=A {1,2};
for i=1:len,
tim_elap(ex_comp (1,i));
if (ex_comp(2,i)==1)
if (ex_comp(6,i)==0)
A=allo_dca 7(ex_comp(4, i),S,sto_state);
sto_state=A {1,1};
ex_comp(5,i)=A{1,2};
else sh=allo_dca7(ex_comp(4,i),H,sto_stateh);
sto_stateh=sh{1,1};
ex_comp(5,i)=sh{1,2};
end;
else b=find(ex_comp(3,1:(i-1))==ex_comp(3,i));
if (ex_comp(5,b(1,1))~=0)
if (ex_comp(6,i)==0)
E=deallo_dca1a7n(ex_comp(4,i),S,...
sto_state,ex_comp,(i-1));
sto_state=E{1,1};
chpos=E{1,2};
ex_comp(5,chpos)=ex_comp(5,b(1,1));
else
E=deallo_dca1a7n(ex_comp(4,i),H,...
sto_stateh,ex_comp,(i-1));
sto_stateh=E{1,1};
chpos=E{1,2};
ex_comp(5,chpos)=ex_comp(5,b(1,1));
end;
end;
end;
end;
bc=sum((sto_state(:,2))');
ac=sum((sto_state(:,1))');
pb=bc/(ac+bc);
hc=sum((sto_stateh(:,1))');
dc=sum((sto_stateh(:,2))');
pd=dc/(ac);
P=[pb,pd];
10. DCA (A) Algorithm with mathematical model Given average inter arrival time & average
holding time to estimate the probability of blocking in aggressive DCA using mathematical model.
function[P]= dca_handque (S,L,T,Y,V);
bc=0;
dc=0;
hc=0;
sto_state=zeros (49,(S+2));
A=pre_ stofnn 2(L,T,Y,V);
ex_comp= A {1,1};
len= A {1,2};
for i=1:len,
tim_elap(ex_comp(1,i));
if (ex_comp(2,i)==1)
if (ex_comp(6,i)==0)
B=allo_dca7 (ex_comp(4,i),S,sto_state);
sto_state=B{1,1};
ch_all=find(ex_comp(3,:)==ex_comp(3,i));
ex_comp(5,ch_all)=(B{1,2})*...
ones(1,length(ch_all));
if (B{1,2}==0)
bc=bc+1;
end;
elseif ((ex_comp(6,i)~=0)&(ex_comp(5,i)==0))
A=allo_dcahq7(ex_comp(4,i),S,sto_state,...
ex_comp(7,i),dc,hc);
sto_state=A{1,1};
dc=A{1,3};
hc=A{1,4};
ch_all=find(ex_comp(6,:)==ex_comp(6,i));
ex_comp(5,ch_all)=(A{1,2})*ones(1,length(ch_all));
end;
elseif (ex_comp(5,i)~=0)
E=deallo_dcahq1a7n(ex_comp(4,i),S,...
sto_state,ex_comp);
sto_state=E{1,1};
chpos=E{1,2};
ex_comp(5,chpos)=(ex_comp(5,i))*...
ones(1,length(chpos));
ch_all=find(ex_comp(6,:)==ex_comp(6,i));
ex_comp(5,ch_all)=zeros(1,length(ch_all));
end;
end;
hhh=hc
bbb=bc
ddd=dc
nc=sum((sto_state(:,2))')
ac=sum((sto_state(:,1))')
pb=bc/(ac+nc);
pd=dc/(Y);
P=[pb,pd];