博客
关于我
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/

你可能感兴趣的文章
python3.6.5+cuda9+cudnn7.1+win10+tensorflow-gpu1.9.0下载配置
查看>>
python3.6使用pickle序列化class
查看>>
python3.6入门到高阶(全栈) day027 网络通信协议 osi七层模型
查看>>
Python3.6属性错误:模块‘;异步没有属性‘;运行‘;
查看>>
python3.6版本中的python-weka-wrapper安装失败,错误代码为%1
查看>>
Python3.7安装cv2踩过的坑
查看>>
python写txt文件
查看>>
python关于sorted排序函数详细解析 附实战代码(全)
查看>>
python3.8调用m文件,调用matlab
查看>>
python3.9新特性_Python 3.9 新特性速览
查看>>
Python3.x:遍历select下拉框获取value值
查看>>
python360百科_11月编程排行榜:Python超过Java成第二
查看>>
Python关于Paginator分页函数详细解析 附实战代码
查看>>
python3、ipython3、setup-tools、pip等环境搭建详细总结
查看>>
python3下使用cv2.imwrite存储带有中文路径图片或者绝对路径图片
查看>>
python3与django中@property详解
查看>>
python3中如何表示无穷大
查看>>
Python3中提示:no module named 'wxpy'
查看>>
python3中选择文件对话框的格式打开和保存图片
查看>>
python3为什么print永远都是地址_Python3 print 函数用法总结
查看>>