建立如下的目标函数:

【网络覆盖优化】基于matlab的网络覆盖遗传优化问题仿真_覆盖优化

【网络覆盖优化】基于matlab的网络覆盖遗传优化问题仿真_拟合_02

表示的是每一代中被选择在工作状态的节点数目。

C'为对应的这些节点的覆盖范围。A为每个节点对应的覆盖范围。

基于这个目标函数,我们进行仿真,获得如下的仿真结果:

【网络覆盖优化】基于matlab的网络覆盖遗传优化问题仿真_网络优化_03

clc;
clear;
close all;
warning off;
addpath 'func\GA_toolbox\'
addpath 'func\'
RandStream.setDefaultStream(RandStream('mt19937ar','seed',1));

%目标区域大小
W = 10;
H = 10;
%网格划分
G = 20;
%节点数目
NN = 200;
[X,Y,R] = func_initial(W,H,NN);
axis([0,W,0,H]);


%根据遗传算法进行参数的拟合
MAXGEN = 60;
NIND = 200;
Chrom = crtbp(NIND,NN*10);
%14个变量的区间
Areas = [zeros(1,NN);
ones(1,NN)];

FieldD = [rep([10],[1,NN]);Areas;rep([0;0;0;0],[1,NN])];


ON_OFF = zeros(NIND,NN);
ON_OFFs = zeros(MAXGEN,NN);
NUMS = zeros(MAXGEN,1);
fgl = zeros(MAXGEN,1);
gen = 0;
for a=1:1:NIND
%所有节点均打开,作为其初始状态
ON_OFF(a,:) = 1;
%计算对应的目标值
[f,C1] = func_obj(ON_OFF(a,:),X,Y,R,W,H,G);
J(a,1) = 1/f;
end

Objv = (J+eps);
gen = 0;

while gen < MAXGEN;
gen
FitnV=ranking(Objv);
Selch=select('sus',Chrom,FitnV);
Selch=recombin('xovsp', Selch,0.99);
Selch=mut(Selch,0.01);
phen1=bs2rv(Selch,FieldD);
for a=1:1:NIND
if gen == 1
ON_OFF(a,:) = 1;
else
ON_OFF(a,:) = (phen1(a,:)>=0.5);
end
%计算对应的目标值
[f,C1] = func_obj(ON_OFF(a,:),X,Y,R,W,H,G);
JJ(a,1) = 1/f;

end
Objvsel =(JJ+eps);
[Chrom,Objv] = reins(Chrom,Selch,1,1,Objv,Objvsel);
gen = gen+1;

%保存参数收敛过程和误差收敛过程以及函数值拟合结论
for ii = 1:NIND
[f,C1] = func_obj(ON_OFF(:,ii),X,Y,R,W,H,G);
flgs(ii) = C1;
end
flgs2 = sort(flgs);
for ii = 1:NN
ON_OFFs(gen,ii) = mean(ON_OFF(:,ii))>=0.2;
end

Error(gen) = mean(JJ);
NUMS(gen) = sum(ON_OFFs(gen,:));
fgl(gen) = mean(flgs2(3:end-2));
end

figure(1);
plot([2:5:60],NUMS(2:5:gen),'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
xlabel('进化次数');
ylabel('采用的传感器节点数目');
grid on;

figure(2);
plot([2:5:60],fgl(2:5:gen),'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
xlabel('进化次数');
ylabel('节点的有效覆盖率%');
grid on;

A12-16