clc;
clear all;
Max=10;
for(i=1:1:Max)
n(i,:)=randint(1,2,[2 100])
end
%n(2,:)=randint(1,2,[2 100])
%n(3,:)=randint(1,2,[2 100])
%n(4,:)=randint(1,2,[2 100])
%n(5,:)=randint(1,2,[2 100])
for i=1:1:Max
%stem( n(i,1),n(i,2))
plot( n(i,1), n(i,2),'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10,...
'Tag','hi')
hold on;
end
grid on;
hold on;
% generate RREQ
RREQ.Src=1
RREQ.Dst=5
%%%%%%%% all the nodes generate a hello packet put the start time
%% when received by the destination the time is calculated and thus
%% distance is obtained.
xs=0
ys=0
for i=1:1:Max
for j=1:1:Max
if(i==j)
d(i,j)=0
else
xs=(n(i,1)-n(j,1))*(n(i,1)-n(j,1))
ys=(n(i,2)-n(j,2))*(n(i,2)-n(j,2))
d(i,j)=sqrt(xs+ys)
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
path=RREQ.Src;
current=RREQ.Src;
INF=999999999999999
small=INF
tmp=0;
while current~=RREQ.Dst
for i=1:1:Max
if current~=i
if( d(current,i)<small)
k=ismember(path,i);
k=find(k);
if(k)
disp 'hi'
else
small=d(current,i)
tmp=i;
end
end
end
end
current=tmp;
path=[path current]
small=INF
end
disp 'loop ends'
path
sz=size(path)
sz=sz(:,2)
x1=n(path(1),1)
rows=x1
x2=n(path(1),2)
col=x2
for i=2:1:sz
x1=n(path(i),1)
rows=[rows ;x1]
x2=n(path(i),2)
col=[col;x2]
end
x=[rows col]
plot(x(:,1),x(:,2))
r=randperm(100);
for j=1:1:4
node(j).es=r(j);
end
A=[20,60,100,120,160,200,250,300]
for i=1:1:8
thrput(1,i)=performance(A(1,i),node,d,Max);
end
figure()
plot(A, thrput)
评论0