资源简介
随机拓扑生成源码,用MATLAB软件仿真运行,只有源码,其他运行

代码片段和文件信息
function [SxyAMCostDelayDelayJitterPacketLoss]=NetCreate(BorderLengthNodeAmountAlphaBetaPlotIfFlagIf)
%%
%参数初始化
BorderLength=10;
NodeAmount=20;
Alpha=40;
Beta=3;
PlotIf=1;
FlagIf=1;
NN=10*NodeAmount;
SSxy=zeros(NN2);
%在正方形区域内随机均匀选取NN个节点
for i=1:NN
SSxy(i1)=BorderLength*rand;
SSxy(i2)=BorderLength*rand;
end
[IDXC]=kmeans(SSxyNodeAmount);
Sxy=[[1:NodeAmount]‘C]‘;
CountNeighborAmount=0;
%按横坐标由小到大的顺序重新为每一个节点编号
temp=Sxy;
Sxy2=Sxy(2:);
Sxy2_sort=(Sxy2);
for i=1:NodeAmount
pos=find(Sxy2==Sxy2_sort(i));
if length(pos)>1
error(‘仿真故障,请重试!‘);
end
temp(1i)=i;
temp(2i)=Sxy(2pos);
temp(3i)=Sxy(3pos);
end
Sxy=temp;
%在节点间随机产生边,并构造延时矩阵和费用矩阵
AM=zeros(NodeAmountNodeAmount);
NeighborAmount=zeros(2NodeAmount);
Cost=zeros(NodeAmountNodeAmount);
Delay=zeros(NodeAmountNodeAmount);
DelayJitter=zeros(NodeAmountNodeAmount);
PacketLoss=zeros(NodeAmountNodeAmount);
for i=1:(NodeAmount-1)
for j=(i+1):NodeAmount
Distance=((Sxy(2i)-Sxy(2j))^2+(Sxy(3i)-Sxy(3j))^2)^0.5;
P=Beta*exp(-Distance^5/(Alpha*BorderLength));
if P>rand
AM(ij)=1;
AM(ji)=1;
Delay(ij)=0.5*Distance/100000;
Delay(ji)=Delay(ij);
Cost(ij)=2+8*rand;
Cost(ji)=Cost(ij);
DelayJitter(ij)=0.000001*(1+2*rand);
DelayJitter(ji)=DelayJitter(ij);
PacketLoss(ij)=0.01*rand;
PacketLoss(ji)=PacketLoss(ij);
else
Delay(ij)=inf;
Delay(ji)=inf;
Cost(ij)=inf;
Cost(ji)=inf;
DelayJitter(ij)=inf;
DelayJitter(ji)=inf;
PacketLoss(ij)=inf;
PacketLoss(ji)=inf;
end
end
end
for i=1:NodeAmount
NeighborAmount(1i)=i;
for j=1:NodeAmount
NeighborAmount(2i)=NeighborAmount(2i)+AM(ij);
end
end
for i=1:NodeAmount
CountNeighborAmount=CountNeighborAmount+NeighborAmount(2i)
end
PJNA=CountNeighborAmount/NodeAmount;
PJNA
AM
Net_plot(BorderLengthNodeAmountSxyCostDelayDelayJitterPacketLossPlotIfFlagIf)
%用于绘制网络拓扑的函数
function Net_plot(BorderLengthNodeAmountSxyCostDelayDelayJitterPacketLossPlotIfFlagIf)
%画节点
if PlotIf==1
plot(Sxy(2:)Sxy(3:)‘r.‘)
%设置图形显示范围
xlim([0BorderLength]);
ylim([0BorderLength]);
hold on
%为节点标序号
for i=1:NodeAmount
Str=int2str(i);
text(Sxy(2i)+BorderLength/100Sxy(3i)+BorderLength/100Str‘FontSize‘12);
hold on
end
end
%画边,并给边标注费用和延时
if PlotIf==1
for i=1:(NodeAmount-1)
for j=(i+1):NodeAmount
if isinf(Cost(ij))==0
plot([Sxy(2i)Sxy(2j)][Sxy(3i)Sxy(3j)]);
if FlagIf==1
xx=0.5*(Sxy(2i)+Sxy(2j));
yy=0.5*(Sxy(3i)+Sxy(3j));
Str1=num2str(Cost(ij));
Str2=num2str(1000000*Delay(ij));
Str3=num2str(1000000*DelayJitter(ij));
Str4=num2str(100*PacketLoss(ij));
Str1=Str1(1:3);
Str2=Str2(1:3);
Str3=Str3(1:3);
Str4=Str4(1:3);
text(xxyy[‘(‘Str1‘‘Str2‘‘Str3‘‘Str4‘)‘]‘FontSize‘8);
end
hold on
end
end
end
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2926 2010-05-27 14:34 NetCreate.m
----------- --------- ---------- ----- ----
2926 1
- 上一篇:模糊k均值聚类算法matlab实现
- 下一篇:LBP算法的Matlab代码
相关资源
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
- k近邻算法matlab实现
- matlab识别系统
- 神经网络分类matlab程序
- matlab正弦信号发生器的设计
评论
共有 条评论