您现在的位置:首页 >> 网络协议 >> 内容

m基于ABC人工蜂群优化的无线传感器网络路由优化算法matlab仿真,对比优化前后网络寿命,效率以及

时间:2023/3/21 21:35:55 点击:

  核心提示:12_034_m,包括程序操作录像+参考文献...

1.完整项目描述和程序获取

>面包多安全交易平台:https://mbd.pub/o/bread/ZJaamZlu

>如果链接失效,可以直接打开本站店铺搜索相关店铺:

点击店铺

>如果链接失效,程序调试报错或者项目合作可以加微信或者QQ联系。

2.部分仿真图预览



3.算法概述

        传感器节点通常布置在无人值守的运行环境中,节点能量由电池提供,但在使用过程中,电池的更换很不方便,因此无线传感器网络必须考虑如何解决能量有限的问题。因此,研究无线传感器网络优化算法以找到最大限度地减少能耗和提高无线传感器网络可靠性的最佳路径是非常重要的。

4.部分源码

....................................................................

%network topology 

dmatrix= zeros(Nnode,Nnode);

matrix = zeros(Nnode,Nnode);

Trust  = zeros(Nnode,Nnode);

for i = 1:Nnode 

    for j = 1:Nnode 

        Dist = sqrt((X(i) - X(j))^2 + (Y(i) - Y(j))^2); 

        %a link; 

        if Dist <= Radius 

           matrix(i,j)  = 1;   

           Trust(i,j)   = 1-((T(i)+T(j))/2);

           dmatrix(i,j) = Dist; 

        else 

           matrix(i,j)  = inf; 

           Trust(i,j)   = inf; 

           dmatrix(i,j) = inf; 

        end; 

    end; 

end; 

pathS  = 1;

pathE  = Nnode;

.......................................................................

%Get the best weight

w1s=cpop(1,1);

w2s=cpop(1,2);

w1 = w1s/(w1s + w2s);

w2 = w2s/(w1s + w2s);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

for ni = 1:length(Nnodes);

    ni

    %节点个数

    Nnode = Nnodes(ni);

    

    Delays2 = zeros(1,MTKL);%end-to-end delay

    consmp2 = zeros(1,MTKL);%Network topology control overhead  

    Srate2  = zeros(1,MTKL);%Packet delivery rate

    

    for jn = 1:MTKL

        X = rand(1,Nnode)*SCALE;  

        Y = rand(1,Nnode)*SCALE; 

        T = rand(1,Nnode); 

        Delays = zeros(Times,1);

        consmp = zeros(Times,1);  

        Srate  = zeros(Times,1);

        for t = 1:Times

            if t == 1

               X = X;

               Y = Y;

            else

               %Nodes send random moves

               X = X + Vmax*rand;

               Y = Y + Vmax*rand;

            end

            %network topology 

            dmatrix= zeros(Nnode,Nnode);

            matrix = zeros(Nnode,Nnode);

            Trust  = zeros(Nnode,Nnode);

            for i = 1:Nnode 

                for j = 1:Nnode 

                    Dist = sqrt((X(i) - X(j))^2 + (Y(i) - Y(j))^2); 

                    %a link; 

                    if Dist <= Radius 

                       matrix(i,j)  = 1;   

                       Trust(i,j)   = 1-((T(i)+T(j))/2);

                       dmatrix(i,j) = Dist; 

                    else 

                       matrix(i,j)  = inf; 

                       Trust(i,j)   = inf; 

                       dmatrix(i,j) = inf; 

                    end; 

                end; 

            end; 

            %Defines the communication start node and termination node

            tmp = randperm(Nnode);

            for i = 1:Nnode

                distA(i) = sqrt((X(i))^2 + (Y(i))^2);

                distB(i) = sqrt((X(i)-SCALE)^2 + (Y(i)-SCALE)^2);

            end

            [Va,Ia] = min(distA);

            [Vb,Ib] = min(distB);

            Sn  = Ia;

            En  = Ib;

            [paths,costs] = func_dijkstra_BF(Sn,En,dmatrix,Trust,w1,w2); 

            path_distance=min(Va,Vb); 

            for d=2:length(paths) 

                path_distance= path_distance + dmatrix(paths(d-1),paths(d)); 

            end 

            %end-to-end delay

            path_hops = min(length(paths)-1,1); 

            %The delay is calculated based on distance, packet length, and data packet rate

            Delays(t) = path_distance*(SLen/Smax)/1e3;

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            %Packet delivery rate 

            Ps       = rand/5;

            tmps     = 0;

            for ii = 1:path_hops

                tmps = tmps + path_distance*Ps^ii/1e3;

            end

            Srate(t) = 1-tmps;

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            %Network topology control overhead  

            consmp(t)= 1000*path_distance*(Eelec+Eelec+Efs);

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        end 

        Delays2(jn) = mean(Delays);

        Srate2(jn)  = mean(Srate);

        consmp2(jn) = mean(consmp);

    end

    ind1         = find(Delays2 > 1e5);

    ind2         = find(Delays2 < 0);

    ind          = unique([ind1,ind2]);

    Delays2(ind) = [];

    Delayn(ni)   = mean(Delays2);

    

    ind1         = find(Srate2 > 1);

    Srate2(ind1) = [];

    Sraten(ni)   = mean(Srate2);

    ind1         = find(consmp2 < 0);

    consmp2(ind1)= [];

    consmpn(ni)  = mean(consmp2);

end

 

 

figure;

for i = 1:Nnode 

    plot(X(i),Y(i), 'ro'); 

    text(X(i),Y(i), num2str(i)); 

    hold on

end

for i = 1:length(paths)-1 

    line([X(paths(i)) X(paths(i+1))], [Y(paths(i)) Y(paths(i+1))], 'LineStyle', '-'); 

    hold on

end

 

figure;

plot(Nnodes,Delayn,'b-o');

grid on

xlabel('number of noders');

ylabel('End-To-End delay');

axis([Nnodes(1),Nnodes(end),0,120]);

 

figure;

plot(Nnodes,Sraten,'b-o');

grid on

xlabel('number of noders');

ylabel('Packet delivery rate');

axis([Nnodes(1),Nnodes(end),0.8,1.05]);

 

figure;

plot(Nnodes,consmpn,'b-o');

grid on

xlabel('number of noders');

ylabel('Energy consumption');

axis([Nnodes(1),Nnodes(end),0,0.1]);

save R_new1.mat Nnodes Delayn Sraten consmpn

12_034_m

作者:我爱C编程 来源:我爱C编程
本站最新成功开发工程项目案例
相关评论
发表我的评论
  • 大名:
  • 内容:
本类固顶
  • 没有
  • FPGA/MATLAB商业/科研类项目合作(www.store718.com) © 2025 版权所有 All Rights Reserved.
  • Email:1480526168@qq.com 站长QQ: 1480526168