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

你可能感兴趣的文章
python语音播放
查看>>
python语言:装饰器原理
查看>>
Python 交互式数据可视化详解
查看>>
python语言有哪些优点和缺点_Python有哪些优缺点,你了解吗?
查看>>
Python 从入门到精通:30天速成教程到底有多狠?你能坚持下来吗?
查看>>
Python 从数据库中存储和检索密码的最安全方法
查看>>
Python语言及其应用 - 知识点遍历
查看>>
Python 优化提速的 8 个小技巧
查看>>
Python 余弦相似度与皮尔逊相关系数 计算
查看>>
python 使用execjs 报编码错误解决办法,UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xac in position 145: il
查看>>
python 使用filetype校验文件
查看>>
Python 使用flush函数将缓冲区数据立即写磁盘
查看>>
python 使用in判断不准确,in不好使
查看>>
Python 使用pandas 进行查询和统计详解
查看>>
Redis 配置文件redis.conf详细解释
查看>>
python网络爬虫(2)——scrapy框架的基础使用
查看>>
python网络爬虫实例教程试读_Python网络爬虫实战教程(全套完整版) - 学途无忧网 - 做技术的王者 - Powered By EduSoho...
查看>>
Python 使用哈希函数用于加密
查看>>
Python 依赖管理的革新——Poetry 深度解析
查看>>
python 保留精度及增加去除数字的千位分隔符(金额化数字)
查看>>