基于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
相关文章
|
13天前
|
算法 5G 数据安全/隐私保护
大规模MIMO通信系统信道估计matlab性能仿真,对比LS,OMP,MOMP以及CoSaMP
本文介绍了大规模MIMO系统中的信道估计方法,包括最小二乘法(LS)、正交匹配追踪(OMP)、多正交匹配追踪(MOMP)和压缩感知算法CoSaMP。展示了MATLAB 2022a仿真的结果,验证了不同算法在信道估计中的表现。最小二乘法适用于非稀疏信道,而OMP、MOMP和CoSaMP更适合稀疏信道。MATLAB核心程序实现了这些算法并进行了性能对比。以下是部分
163 84
|
13天前
|
算法
基于GA遗传优化的TSP问题最优路线规划matlab仿真
本项目使用遗传算法(GA)解决旅行商问题(TSP),目标是在访问一系列城市后返回起点的最短路径。TSP属于NP-难问题,启发式方法尤其GA在此类问题上表现出色。项目在MATLAB 2022a中实现,通过编码、初始化种群、适应度评估、选择、交叉与变异等步骤,最终展示适应度收敛曲线及最优路径。
|
13天前
|
算法 BI Serverless
基于鱼群算法的散热片形状优化matlab仿真
本研究利用浴盆曲线模拟空隙外形,并通过鱼群算法(FSA)优化浴盆曲线参数,以获得最佳孔隙度值及对应的R值。FSA通过模拟鱼群的聚群、避障和觅食行为,实现高效全局搜索。具体步骤包括初始化鱼群、计算适应度值、更新位置及判断终止条件。最终确定散热片的最佳形状参数。仿真结果显示该方法能显著提高优化效率。相关代码使用MATLAB 2022a实现。
|
13天前
|
算法 数据可视化
基于SSA奇异谱分析算法的时间序列趋势线提取matlab仿真
奇异谱分析(SSA)是一种基于奇异值分解(SVD)和轨迹矩阵的非线性、非参数时间序列分析方法,适用于提取趋势、周期性和噪声成分。本项目使用MATLAB 2022a版本实现从强干扰序列中提取趋势线,并通过可视化展示了原时间序列与提取的趋势分量。代码实现了滑动窗口下的奇异值分解和分组重构,适用于非线性和非平稳时间序列分析。此方法在气候变化、金融市场和生物医学信号处理等领域有广泛应用。
|
13天前
|
监控 算法 数据安全/隐私保护
基于视觉工具箱和背景差法的行人检测,行走轨迹跟踪,人员行走习惯统计matlab仿真
该算法基于Matlab 2022a,利用视觉工具箱和背景差法实现行人检测与轨迹跟踪,通过构建背景模型(如GMM),对比当前帧与模型差异,识别运动物体并统计行走习惯,包括轨迹、速度及停留时间等特征。演示三维图中幅度越大代表更常走的路线。完整代码含中文注释及操作视频。
|
7天前
|
算法 5G 数据安全/隐私保护
3D-MIMO信道模型的MATLAB模拟与仿真
该研究利用MATLAB 2022a进行了3D-MIMO技术的仿真,结果显示了不同场景下的LOS概率曲线。3D-MIMO作为5G关键技术之一,通过三维天线阵列增强了系统容量和覆盖范围。其信道模型涵盖UMa、UMi、RMa等场景,并分析了LOS/NLOS传播条件下的路径损耗、多径效应及空间相关性。仿真代码展示了三种典型场景下的LOS概率分布。
21 1
|
14天前
|
算法
基于GA遗传优化的离散交通网络双层规划模型设计matlab仿真
该程序基于GA遗传优化设计了离散交通网络的双层规划模型,以路段收费情况的优化为核心,并通过一氧化碳排放量评估环境影响。在MATLAB2022a版本中进行了验证,显示了系统总出行时间和区域排放最小化的过程。上层模型采用多目标优化策略,下层则确保总阻抗最小,实现整体最优解。
|
14天前
|
资源调度 算法
基于迭代扩展卡尔曼滤波算法的倒立摆控制系统matlab仿真
本课题研究基于迭代扩展卡尔曼滤波算法的倒立摆控制系统,并对比UKF、EKF、迭代UKF和迭代EKF的控制效果。倒立摆作为典型的非线性系统,适用于评估不同滤波方法的性能。UKF采用无迹变换逼近非线性函数,避免了EKF中的截断误差;EKF则通过泰勒级数展开近似非线性函数;迭代EKF和迭代UKF通过多次迭代提高状态估计精度。系统使用MATLAB 2022a进行仿真和分析,结果显示UKF和迭代UKF在非线性强的系统中表现更佳,但计算复杂度较高;EKF和迭代EKF则更适合维数较高或计算受限的场景。
|
16天前
|
算法
基于SIR模型的疫情发展趋势预测算法matlab仿真
该程序基于SIR模型预测疫情发展趋势,通过MATLAB 2022a版实现病例增长拟合分析,比较疫情防控力度。使用SIR微分方程模型拟合疫情发展过程,优化参数并求解微分方程组以预测易感者(S)、感染者(I)和移除者(R)的数量变化。![]该模型将总人群分为S、I、R三部分,通过解析或数值求解微分方程组预测疫情趋势。
|
16天前
|
算法 安全
基于MATLAB的SEIR传染病模型建模与仿真
本项目基于SEIR模型,利用MATLAB 2022a对传染病传播过程进行建模与仿真。SEIR模型将人群分为易感者(S)、暴露者(E)、感染者(I)和康复者(R),通过四类人群间的转换描述传染病动态。通过设定初始条件与参数,并采用ODE求解器进行模拟,生成了不同状态人群随时间变化的曲线图,展示了感染趋势及防控效果。系统仿真结果显示了模型的有效性和预测能力。