当前位置: 首页 > news >正文

基于粒子群优化算法的最佳方式优化无线传感器节点的位置(Matlab代码实现)

    目录

💥1 概述

📚2 运行结果

🎉3 参考文献

👨‍💻4 Matlab代码

💥1 概述

此代码优化了由于电池耗尽而产生覆盖空洞后 WSN 节点的位置。如果活动通信中的任何节点死亡,则通过PSO优化再次定位其余节点,将覆盖区域最大化作为目标函数。​

📚2 运行结果

主函数部分代码:

close all
clear
clc
addpath(genpath(cd))
warning('off')
%%
N=10;                       % number of nodes
area=[10,10];              % nodes deployment area in meter
Trange=2;                   % transmission range of sensor node in meter
nodes.pos=area(1).*rand(N,2);% nodes geographical locations
lambda=0.125;                % signal wavelength in meter
nodes.major = Trange;        % major axis for ellpitical range in meter
nodes.minor = lambda*Trange;  % minro axis for ellipitical range in meter
% redundantNo=9;               % number of healing nodes   
redundantNo=round(10*N/100);
%% plot the nodes deployment
cnt=1;
for ii=1:N      for jj=1:Nif ii~=jjnodes.distance(ii,jj)=pdist([nodes.pos(ii,:);nodes.pos(jj,:)]);if nodes.distance(ii,jj)<Trange || nodes.distance(ii,jj)==Trangenodes.inrange(ii,jj)=1;elsenodes.inrange(ii,jj)=0;endendend
end
​
figure
F5=plot(nodes.pos(:,1),nodes.pos(:,2),'.','color','r');
hold on
for ii=1:N                   % plot the circular transmission range[nodes.circle.x(ii,:),nodes.circle.y(ii,:)]=circle(nodes.pos(ii,1),nodes.pos(ii,2),Trange);F6=fill(nodes.circle.x(ii,:),nodes.circle.y(ii,:),[0.25,0.25,0.25]);alpha 0.3hold on
end
axis on
xlabel('x(m)')
ylabel('y(m)')
title('Initial Placement of Nodes with circular transmission range')
%% plot delauny triangle
TRI = delaunay(nodes.pos(:,1),nodes.pos(:,2));
figure(2)
F5 = plot(nodes.pos(:,1),nodes.pos(:,2),'.','color','r');
hold on
for ii=1:N                   % plot the circular transmission range[nodes.circle.x(ii,:),nodes.circle.y(ii,:)]=circle(nodes.pos(ii,1),nodes.pos(ii,2),Trange);F6=fill(nodes.circle.x(ii,:),nodes.circle.y(ii,:),[0.25,0.25,0.25]);alpha 0.3hold on
end
axis on
xlabel('x(m)')
ylabel('y(m)')
title('Coverage hole in initila position of Nodes')
hold on
triplot(TRI,nodes.pos(:,1),nodes.pos(:,2))
%% Hole detection
[holeDetected.circle,Circmcenter.circle,circumradius.circle]=holeDetection(TRI,nodes,F5,F6,Trange,area,2,1);
display(['--> No of detected Holes for Circular = ',num2str(numel(find(holeDetected.circle)))])
%% PSO optimize position of rest wsn nodes to cover the hole
nvars = 2*(N);
fun=@(x)objf(x,Trange,area);
lb=zeros(nvars,1);
ub=area(1).*ones(nvars,1);
options = optimoptions(@particleswarm,'Display','iter','MaxIterations',100,'PlotFcn','pswplotbestf');
[x,fval] = particleswarm(fun,nvars,lb,ub,options);
finalPos = reshape(x,[numel(x)/2,2]);
% plot the final tuned Node' pos
figure
plot(finalPos(:,1),finalPos(:,2),'
o
','
color
','
r
');
hold on
for ii=1:N                 % plot the circular transmission range[finalcircle.x(ii,:),finalcircle.y(ii,:)]=circle(finalPos(ii,1),finalPos(ii,2),Trange);fill(finalcircle.x(ii,:),finalcircle.y(ii,:),[0.25,0.25,0.25]);alpha 0.3hold on
end

🎉3 参考文献

[1]史朝亚. 基于PSO算法无线传感器网络覆盖优化的研究[D]. 南京理工大学.

部分理论引用网络文献,若有侵权联系博主删除。

http://www.lryc.cn/news/67550.html

相关文章:

  • 第一章 Andorid系统移植与驱动开发概述 - 读书笔记
  • vi编辑器的三种模式及其对应模式下常用指令
  • webpack: 5 报错,错误
  • MyBatis的缓存
  • c语言-位段
  • Servlet3.0 新特性全解
  • PAT A1045 Favorite Color Stripe
  • 真实业务场景使用-门面模式(外观)设计模式
  • 基于多动作深度强化学习的柔性车间调度研究(Matlab代码实现)
  • 出口亚马逊平衡车CE/UKCA认证注意事项
  • 云原生环境下的安全实践:保护应用程序和数据的关键策略
  • vue 改变数据后,数据变化页面不刷新
  • 【Qt编程之Widgets模块】-006:QSortFilterProxyModel代理的使用方法
  • 上林赋 汉 司马相如
  • 7.对象模型
  • 机器学习——基本概念
  • Qt---感觉挺重要的部分
  • springboot+vue家乡特色推荐系统(源码+文档)
  • 在Shell脚本中通过ssh从脚本运行函数
  • 简单学习一下 MyBatis 动态SQL使用及原理
  • WhatsApp如何让客户参与变得更简单?
  • 记一次 MySQL 主从同步异常的排查记录,百转千回
  • Cpython的多线程技术之痛
  • NDK OpenGL离屏渲染与工程代码整合
  • Python基础入门编程代码练习(二)
  • C# | 对象池
  • CSS小技巧之圆形虚线边框
  • QString与QByteArray互相转换的方法
  • Springboot +Flowable,设置流程变量的方式(一)
  • 机器学习13(正则化)