博客
关于我
CDS最小支配集的MATLAB仿真
阅读量:247 次
发布时间:2019-03-01

本文共 3522 字,大约阅读时间需要 11 分钟。

% 初始化网络节点坐标Node_Num=200;Posxy=zeros(Node_Num,2);Radius=10;Scale=100;Area_Size_W=100;% 生成一层邻居信息d1=zeros(Node_Num,Node_Num+1);% 初始化网络节点坐标for i=1:Node_Num    Posxy(i,:)=Scale*rand(1,2);end% 计算每个节点的一层邻居信息for i=1:Node_Num    num1=0;    for j=1:Node_Num        if i~=j            dist=(Posxy(i,1)-Posxy(j,1))^2 + (Posxy(i,2)-Posxy(j,2))^2;            dist=sqrt(dist);            if dist
0 num1=num1+1; d1(i,num1+1)=j; end end end d1(i,1)=num1;end% 绘制网络图hold onfor i=1:Node_Num for j=1:d1(i,1) plot([Posxy(i,1),Posxy(d1(i,j+1),1)], [Posxy(i,2),Posxy(d1(i,j+1),2)], '-ok'); hold on; end endend% 计算每个节点的两层邻居信息Max_Degree=max(d1(:,1));Neighbor_hop2=zeros(Max_Degree,Max_Degree+1,Node_Num);for i=1:Node_Num for j=1:d1(i,1) Neighbor_hop2(j,1,i)=d1(i,j+1); for m=1:d1(d1(i,j+1),1) Neighbor_hop2(j,m+1,i)=d1(d1(i,j+1),m+1); end endend% 基于规则对节点进行颜色标记Color_N=zeros(Node_Num,1);% 0-white;1-gray;2-black;3-gray'for i=1:Node_Num if d1(i,1)<2 Color_N(i,1)=0; else for j=1:d1(i,1) color=0; for n=j+1:d1(i,1) state=0; for m=2:d1(Neighbor_hop2(j,1,i),1)+1 if Neighbor_hop2(n,1,i)==Neighbor_hop2(j,m,i) state=1; break; end end if state==0 color=1; break; end end if color==1 break; end end Color_N(i,1)=color; endend% 基于规则对节点进行颜色标记Color_N=zeros(Node_Num,1);% 0-white;1-gray;2-black;3-gray'for i=1:Node_Num if Color_N(i,1)==0 && d1(i,1)>0 temp_degree=0; temp_id=0; for j=1:d1(i,1) if Color_N(d1(i,j+1),1)~=0 && Color_N(d1(i,j+1),1)~=2 Color_N(d1(i,j+1),1)=3; end if d1(d1(i,j+1),1)>temp_degree temp_degree=d1(d1(i,j+1),1); temp_id=d1(i,j+1); end if d1(d1(i,j+1),1)==temp_degree if d1(i,j+1) > temp_id temp_degree=d1(d1(i,j+1),1); temp_id=d1(i,j+1); end end if temp_id~=0 Color_N(temp_id,1)=2; end end endend% 生成两层邻居信息tempall=1;temp_self=Neighbor_hop2(:,:,1)*0;for i=1:Node_Num if Color_N(i,1)==4 || Color_N(i,1)==2 temp_self=temp_self*0; for n=1:d1(i,1) temp2=d1(d1(i,n+1),1); temp_count=1; for m=2:Max_Degree+1 if temp2+1>m temp_self(n,m)=d1(i,n+1); temp=temp=Neighbor_hop2(n,m,i); state=1; for p=1:d1(i,1) if temp==i state=0; break; end if temp==d1(i,p+1) state=0; break; end end if state==1 temp_count=temp_count+1; temp_self(n, temp_count)=temp; end end end end endend% 已处理的节点信息Already_handle=zeros(Max_Degree*Max_Degree,1);Already_handle_result=Already_handle;handle_count=0;for n=1:handle_count if Already_handle_result(n,1)==0 Color_N(Already_handle_result(n,1))=6; endend

转载地址:http://ptwx.baihongyu.com/

你可能感兴趣的文章
OCP题库升级,新版的052考试题及答案整理-18
查看>>
OCR使用总结
查看>>
OfficeWeb365 SaveDraw 文件上传漏洞复现
查看>>
office中的所有content type
查看>>
office之Excel 你会用 Ctrl + E 吗?
查看>>
Office办公软件里的“开发工具”选项卡-ChatGPT4o作答
查看>>
OGG初始化之使用数据库实用程序加载数据
查看>>
ogg参数解析
查看>>
ognl详解
查看>>
Ogre 插件系统
查看>>
Oil Deposits
查看>>
oj2894(贝尔曼福特模板)
查看>>
OJ中处理超大数据的方法
查看>>
OJ中常见的一种presentation error解决方法
查看>>
OK335xS UART device registe hacking
查看>>
ok6410内存初始化
查看>>
OkDeepLink 使用教程
查看>>
OKHTTP
查看>>
Okhttp3添加拦截器后,报错,java.io.IOException: unexpected end of stream on okhttp3.Address
查看>>
OkHttp透明压缩,收获性能10倍,外加故障一枚
查看>>