基于matlab的最小支配集CDS仿真

简介: 基于matlab的最小支配集CDS仿真

1.算法描述

   支配集的定义如下:给定无向图G =(V , E),其中V是点集, E是边集, 称V的一个子集S称为支配集当且仅当对于V-S中任何一个点v, 都有S中的某个点u, 使得(u, v) ∈E。对于图G = (V, E) 来说,最小支配集指的是从 V 中取尽量少的点组成一个集合, 使得 V 中剩余的点都与取出来的点有边相连.也就是说,设 V' 是图的一个支配集,则对于图中的任意一个顶点 u ,要么属于集合 V', 要么与 V' 中的顶点相邻. 在 V' 中除去任何元素后 V' 不再是支配集, 则支配集 V' 是极小支配集.称G 的所有支配集中顶点个数最少的支配集为最小支配集,最小支配集中的顶点个数称为支配数.

   最小支配集(minimal dominating set):对于图G=(V,E)来说,设V'是图G的一个支配集,则对于图中的任意一个顶点u,要么属于集合V',要么与V'中的顶点相连。在V'中除去任何元素后V'不再是支配集,则支配集V'是极小支配集。称G中所有支配集中顶点个数最少的支配集为最小支配集,最小支配集中的顶点个数称为支配数。

最小支配集的性质:

1)求最小支配集问题被证明属于NP完全问题,即对于给定问题域的输入规模,目前尚无足够的手段证明该问题能够被判定在多项式时间内求解。

2)在含n个点的任意图中,若任意点的度大于等于3,则该图的最小支配集小于等于3n/8。

3)对于特殊图,如树,可使用贪心或dp的方法解决问题。

贪心策略

   首先选择一点为树根,再按照深度优先遍历得到遍历序列,按照所得序列的反向序列的顺序进行贪心,对于一个即不属于支配集也不与支配集中的点相连的点来说,如果他的父节点不属于支配集,将其父节点加入到支配集

具体实现
1.设整型数组dfn,fa,布尔数组vis,st。dfn[i]表示dfs中出现的第i个节点,fa[i]表示dfs中节点i的父节点,vis[i]-false表示节点i不属于支配集也不与支配集中的点相连,st[i]-true表示节点i在MDS中。

2.建图(邻接表)。

3.dfs一遍树,确定dfn,fa。

4.dfn逆序查找,确定vis,st,同时得出MDS。

2.仿真效果预览
matlab2013B仿真结果如下:

1.png

3.MATLAB部分代码预览

temp_self=Neighbor_hop2(:,:,1)*0;%2 hop's information
 
for i=1:Node_Num
 
    if Color_N(i,1)==4||Color_N(i,1)==2
        temp_self=temp_self*0;%2 hop's information
        
        %node i formulation the 2_hop connected graph
        for n=1:d1(i,1)
            temp2=d1(d1(i,n+1),1);
            temp_count=1;
            state=1;
            for m=2:temp2+1
                temp_self(n,1)=d1(i,n+1);
                temp=Neighbor_hop2(n,m,i);
                state=1;
                for p=1:d1(i,1)
                    if temp==i
                        state=0;
                        break;
                    elseif 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
        
        
        
        
%%        
        %chose some node in two_hops of node i to connect the2_hop's dominating nodes
        Already_handle=zeros(Max_Degree*Max_Degree,1);
        Already_handle_result=Already_handle;
        handle_count=0;
        for n=1:d1(i,1)
            if temp_self(n,1)==0;
                break;                
            end
            for m=2:Max_Degree+1
                if temp_self(n,m)==0
                    break;
                end
                if Color_N(temp_self(n,m),1)==4||Color_N(temp_self(n,m),1)==2
                    state=0;
                    for p=1:handle_count
                        if Already_handle(p,1)==temp_self(n,m)
                            state=1;
                            if Already_handle_result(p,1)==0
                                break;
                            else
                                if Color_N(temp_self(n,1))==2||Color_N(temp_self(n,1))==4
                                    Already_handle_result(p,1)=0;
                                    break;
                                elseif  d1(temp_self(n,1),1)>d1(Already_handle_result(p,1),1)
                                    Already_handle_result(p,1)=temp_self(n,1);
                                elseif d1(temp_self(n,1),1)==d1(Already_handle_result(p,1),1)
                                    if temp_self(n:1)<Already_handle_result(p,1)
                                        Already_handle_result(p,1)=temp_self(n,1);
                                    end
                                end
                            end
                        end
                    end
                    if state==0;
                        if Color_N(temp_self(n,1))==2||Color_N(temp_self(n,1))==4
                            Already_handle(handle_count+1,1)=temp_self(n,m);
                            Already_handle_result(handle_count+1,1)=0;
                            handle_count=handle_count+1;
                        else
                            Already_handle(handle_count+1,1)=temp_self(n,m);
                            Already_handle_result(handle_count+1,1)=temp_self(n,1);
                            handle_count=handle_count+1;
                        end
                    end
                end
            end
        end
        
        for n=1:handle_count
           if  Already_handle_result(n,1)==0
              
           else
               Color_N(Already_handle_result(n,1))=6;
               
               temp1=Already_handle_result(n,1);
               temp2=Already_handle(n,1);
               plot([Posxy(i,1),Posxy(temp1,1)],[Posxy(i,2),Posxy(temp1,2)],'o-.c')
               plot([Posxy(temp2,1),Posxy(temp1,1)],[Posxy(temp2,2),Posxy(temp1,2)],'o-.c')
               
           end
        end
        
%%        
        %node i formulation the 3_hop connected graph
       Already_handle2=zeros(Max_Degree*Max_Degree*Max_Degree,1);
       handle_count2=0;
       Already_handle2_reult=zeros(Max_Degree*Max_Degree*Max_Degree,2);
       
       for n=1:d1(i,1)
           if temp_self(n,1)==0;
                break;                
           end
           for m=2:Max_Degree+1
                if temp_self(n,m)==0
                    break;
                end
                for p=1:d1(temp_self(n,m),1)
                    
                    temp_node=d1(temp_self(n,m),p+1);
                    
                    if Color_N(temp_node)==2||Color_N(temp_node)==4
                        
                        state_in=0;
                        
                        % it is one of 2hops neighboor of nod i if state_in==1;
                        for n2=1:d1(i,1)
                            if temp_self(n2,1)==0
                                break;
                            end
                            if temp_self(n2,1)==temp_node
                                state_in=1;
                                break;
                            end
                            for m2=2:Max_Degree+1
                                if temp_self(n2,m2)==0
                                    break;
                                end
                                if temp_self(n2,m2)==temp_node
                                    state_in=1;
                                    break;
                                end
                            end
                            if state_in==1
                                break;
                            end
                        end
                        
                        % it is one of 2hops neighboor of nod i if
                        % state_in==0, then we get the rout from there.
                        if state_in==0
                            
                            state_in2=0;
                            
                            for q=1:handle_count2
                                
                                if temp_node==Already_handle2(q,1)
                                    
                                    state_in2=1;
                                    
                                    temp1=Already_handle2_reult(q,1);
                                    temp2=Already_handle2_reult(q,2);
                                    temp3=temp_self(n,1);
                                    temp4=temp_self(n,m);
                                    
                                    if temp1==0
                                        break;
                                        %do nothing
                                    else
                                        if Color_N(temp3,1)==2||Color_N(temp3,1)==4||Color_N(temp4,1)==2||Color_N(temp4,1)==4
                                            Already_handle2_reult(q,1)=0;
                                            Already_handle2_reult(q,2)=0;
                                        else
                                            a=d1(temp3,1)+d1(temp4,1);
                                            b=d1(temp1,1)+d1(temp2,1);
                                            if a>b
                                                Already_handle2_reult(q,1)=temp3;
                                                Already_handle2_reult(q,2)=temp4;
                                            elseif a==b
                                                if temp3+temp4<temp1+temp2
                                                    Already_handle2_reult(q,1)=temp3;
                                                    Already_handle2_reult(q,2)=temp4;
                                                else
                                                    %do nothing
                                                end
                                            end
                                        end
                                    end
                                    
                                end
                                
                                if state_in2==1
                                   break; 
                                end
                                
                            end
                            
                            if state_in2==0;
                                handle_count2=handle_count2+1;
                                Already_handle2(handle_count2,1)=temp_node;
                                temp1=temp_self(n,1);
                                temp2=temp_self(n,m);
                                if  Color_N(temp1,1)==2||Color_N(temp1,1)==4||Color_N(temp2,1)==2||Color_N(temp2,1)==4
                                    Already_handle2_reult(handle_count2,1)=0;
                                    Already_handle2_reult(handle_count2,2)=0;
                                else
                                    Already_handle2_reult(handle_count2,1)=temp_self(n,1);
                                    Already_handle2_reult(handle_count2,2)=temp_self(n,m);
                                end
                            end
                            
                        end
                        
                    end
                    
                end
                
           end
       end
       
       for n=1:handle_count2
           if  Already_handle2_reult(n,1)==0
 
           else
               Color_N(Already_handle2_reult(n,1),1)=7;
               Color_N(Already_handle2_reult(n,2),1)=7;
               
               temp1=Already_handle2_reult(n,1);
               temp2=Already_handle2_reult(n,2);
               temp3=Already_handle2(n,1);
               plot([Posxy(i,1),Posxy(temp1,1)],[Posxy(i,2),Posxy(temp1,2)],'o-.b')
               plot([Posxy(temp2,1),Posxy(temp1,1)],[Posxy(temp2,2),Posxy(temp1,2)],'o-.b')
               plot([Posxy(temp2,1),Posxy(temp3,1)],[Posxy(temp2,2),Posxy(temp3,2)],'o-.b')
 
           end
       end
       
    end
end
A_037
相关文章
|
数据可视化
基于MATLAB的OFDM调制发射与接收仿真
基于MATLAB的OFDM调制发射与接收仿真
|
监控 算法
基于SEIR传染病模型的社会舆情传播matlab模拟与仿真
本项目基于SEIR传染病模型构建社会舆情传播分析系统,利用MATLAB 2022A进行仿真测试。通过数值求解微分方程组,模拟舆情从产生、扩散到平息的全过程,揭示其内在传播规律。模型将人群分为易感者、暴露者、感染者和康复者四类,结合真实推文数据绘制传播曲线,验证模型有效性,为舆情监控与干预提供科学依据。
|
传感器 机器学习/深度学习 数据采集
四旋翼飞行器及电机动力学研究(Matlab代码、Simulink仿真实现)
四旋翼飞行器及电机动力学研究(Matlab代码、Simulink仿真实现)
452 2
|
算法 测试技术 Python
【IEEE复现】配电网可靠性评估用于分配优化模型:一种非仿真的线性规划方法(Matlab代码实现)
【IEEE复现】配电网可靠性评估用于分配优化模型:一种非仿真的线性规划方法(Matlab代码实现)
227 1
基于IEEE 802.11a标准的物理层MATLAB仿真
基于IEEE 802.11a标准的物理层MATLAB仿真
670 0
|
算法 机器人
基于SOA海鸥优化算法的PID控制器最优控制参数计算matlab仿真
本课题研究基于海鸥优化算法(SOA)优化PID控制器参数的方法,通过MATLAB仿真对比传统PID控制效果。利用SOA算法优化PID的kp、ki、kd参数,以积分绝对误差(IAE)为适应度函数,提升系统响应速度与稳定性。仿真结果表明,SOA优化的PID控制器在阶跃响应和误差控制方面均优于传统方法,具有更快的收敛速度和更强的全局寻优能力,适用于复杂系统的参数整定。
基于MATLAB/Simulink平台搭建同步电机、异步电机和双馈风机仿真模型
基于MATLAB/Simulink平台搭建同步电机、异步电机和双馈风机仿真模型
1351 30
|
传感器 算法 数据挖掘
基于协方差交叉(CI)的多传感器融合算法matlab仿真,对比单传感器和SCC融合
基于协方差交叉(CI)的多传感器融合算法,通过MATLAB仿真对比单传感器、SCC与CI融合在位置/速度估计误差(RMSE)及等概率椭圆上的性能。采用MATLAB2022A实现,结果表明CI融合在未知相关性下仍具鲁棒性,有效降低估计误差。
561 15
|
机器学习/深度学习 算法 数据可视化
基于MVO多元宇宙优化的DBSCAN聚类算法matlab仿真
本程序基于MATLAB实现MVO优化的DBSCAN聚类算法,通过多元宇宙优化自动搜索最优参数Eps与MinPts,提升聚类精度。对比传统DBSCAN,MVO-DBSCAN有效克服参数依赖问题,适应复杂数据分布,增强鲁棒性,适用于非均匀密度数据集的高效聚类分析。
|
开发框架 算法 .NET
基于ADMM无穷范数检测算法的MIMO通信系统信号检测MATLAB仿真,对比ML,MMSE,ZF以及LAMA
简介:本文介绍基于ADMM的MIMO信号检测算法,结合无穷范数优化与交替方向乘子法,降低计算复杂度并提升检测性能。涵盖MATLAB 2024b实现效果图、核心代码及详细注释,并对比ML、MMSE、ZF、OCD_MMSE与LAMA等算法。重点分析LAMA基于消息传递的低复杂度优势,适用于大规模MIMO系统,为通信系统检测提供理论支持与实践方案。(238字)

热门文章

最新文章