m Matlab simulation of two-dimensional indoor infrared sensor deployment strategy based on virtual force optimization algorithm

Table of contents

1. Algorithm simulation effect

2. Algorithms involve an overview of theoretical knowledge

3. MATLAB core program

4. Complete algorithm code file


1. Algorithm simulation effect

The matlab2022a simulation results are as follows:

 

 

2. Algorithms involve an overview of theoretical knowledge

        Infrared sensors have been widely used in indoor environment monitoring, security, intelligent control and other fields. When deploying an infrared sensor indoors, the choice of its location has a crucial impact on the performance and signal quality of the sensor. Therefore, how to determine the best deployment position of infrared sensors has become a hot research topic. This paper will introduce a 2D indoor infrared sensor deployment strategy based on virtual force optimization algorithm, and focus on the application of virtual force algorithm in this strategy.

1. Research Background

       Infrared sensor is a sensor widely used in indoor environment monitoring, security, intelligent control and other fields. In practical applications, the position selection of the infrared sensor has a crucial impact on the performance and signal quality of the sensor. Therefore, how to determine the best deployment position of infrared sensors has become a hot research topic.

       Traditional methods of infrared sensor deployment are largely based on experience and trial-and-error. There are many problems in this method, such as requiring a lot of time and labor costs, not being able to guarantee the optimality of deployment, not being able to take into account the influence of different environments and different sensors, etc. Therefore, how to use modern optimization algorithms to optimize the deployment position of infrared sensors is one of the current research hotspots.

2. Virtual force optimization algorithm

       The virtual force optimization algorithm is an optimization algorithm based on physical models. It optimizes the solution of the optimization problem by simulating the action of physical mechanics. The basic idea is to express the solution of the problem to be optimized as a set of point positions, and then introduce some virtual forces (such as repulsion, attraction, etc.) to optimize the point positions.

The virtual force optimization algorithm includes the following steps:

Location of initialization points: Randomly generate the location of a set of initial points.

Calculate virtual force: According to the characteristics of the problem, calculate the repulsion and attraction of each point.

Update the position of the point: According to the action of the virtual force, the position of each point is updated.

Termination condition: After the predetermined termination condition is reached, the optimal solution is output.

3. Two-dimensional indoor infrared sensor deployment strategy based on virtual force optimization

       To solve the optimization problem of infrared sensor deployment, a two-dimensional indoor infrared sensor deployment strategy based on virtual force optimization algorithm. The main flow of the strategy is as follows:

       Building a 2D indoor model: First, you need to build a 2D indoor model, including room size, layout, walls, furniture and other information. It can be modeled using 2D modeling software or scanned in real time using a laser scanner.

       Determine the number and type of sensors: Determine the number and type of infrared sensors to be deployed based on actual needs.

      The location of the initialization point: Divide the indoor space into several areas, and randomly generate a set of initial point locations, each point corresponding to the deployment location of a sensor.

Calculate virtual force: According to the characteristics of the problem, calculate the repulsion and attraction of each point. Specifically, the following virtual forces can be used:

(1) Repulsion: Used to avoid overlapping between sensors. The repulsive force is inversely proportional to the distance between sensors, the closer the distance, the greater the repulsive force.

(2) Gravity: Used to attract the sensor to the target area. The gravitational force is inversely proportional to the distance between the sensor and the target area, the closer the distance, the greater the gravitational force.

(3) Wall repulsion: used to avoid the sensor from colliding with the wall. The wall repulsion is inversely proportional to the distance between the sensor and the wall, the closer the distance, the greater the repulsion.

Update the position of the point: According to the action of the virtual force, the position of each point is updated. Specifically, the acceleration of each point is calculated according to the magnitude and direction of the virtual force received by each point, and then the velocity and position of each point are updated according to the acceleration.

Repeat steps 4 and 5 until a predetermined termination condition is reached.

Output optimal solution: When the termination condition is reached, output the optimal deployment position of the sensor.

f1 coverage

       The calculation of coverage adopts the plane scanning method. For two sensors, one is a circle and the other is a square. For the coordinates obtained each time, we scan the entire plane area to calculate whether each point is in one or more A sensor, if this condition is met, then this point is included in the coverage area, and then after scanning all the points, count how many points have been scanned in, that is, the coverage rate. The corresponding code is:

f2 installation difficulty

        The difficulty of installation, this part does not have a special paper introduction, we define here as the distance between the sensor and the frontal obstacle as the basis for judging the difficulty of installation.

f3, the number of sensors after optimization

        The number of sensors, that is, the number after each optimization, is at the maximum preset value, and the smaller the value, the better.

3. MATLAB core program

...........................................................................
 
%下面这个for是优化适应度值的初始化计算
for i=1:Num
    XYZ1=[x(i,1:(dim-2)/2);x(i,1+(dim-2)/2:(dim-2))];
    NUM1          = 10;
    NUM2          = 10;
    [p(i),X1,Y1,f1,f2] = func_obj1(XYZ1,NUM1,NUM2);
    y(i,:)= x(i,:);
end
%全局最优
pg = x(1,:);             
%下面这个for是优化适应度值的初始化计算 
for i=2:Num
    XYZ1=[x(i,1:(dim-2)/2);x(i,1+(dim-2)/2:dim-2)];
    NUM1          = 10;
    NUM2          = 10;
    [pa(i),X1,Y1,f1,f2] = func_obj1(XYZ1,NUM1,NUM2);
    [pb(i),X1,Y1,f1,f2] = func_obj1(XYZ1,NUM1,NUM2);
    if pa(i) < pb(i)
       pg=x(i,:);
    end
end

for t=1:MAXGEN%开始优化
    t
    for i=1:Num
        Fx(i,:) = w*Fx(i,:)+rand*(pg(1:(dim-2)/2)        -x(i,1:(dim-2)/2));%水平力
        Fy(i,:) = w*Fy(i,:)+rand*(pg(1+(dim-2)/2:(dim-2))-x(i,1+(dim-2)/2:(dim-2)));%垂直力
        Fxy     = sqrt(Fx(i,:).^2+Fy(i,:).^2);
        
        Fxn(i,:) = w*Fxn(i,:)+rand*(pg(dim-1)-x(i,dim-1));%水平力
        Fyn(i,:) = w*Fyn(i,:)+rand*(pg(dim)  -x(i,dim));%垂直力
        Fxyn    = sqrt(Fxn(i,:).^2+Fyn(i,:).^2);        
        %更新变量
        x(i,1:(dim-2)/2)         = x(i,1:(dim-2)/2)+Fx(i,:)./Fxy*max_sensor;
        x(i,1+(dim-2)/2:(dim-2)) = x(i,1+(dim-2)/2:(dim-2))+Fy(i,:)./Fxy*max_sensor;
        x(i,dim-1) = x(i,dim-1)+Fxn(i,:)./Fxyn*max_sensor;
        x(i,dim)   = x(i,dim)  +Fyn(i,:)./Fxyn*max_sensor;        
        
        
        XYZ1=[x(i,1:(dim-2)/2);x(i,1+(dim-2)/2:(dim-2))];
        NUM1        = floor(x(i,dim-1));
        NUM2        = floor(x(i,dim));
        if NUM1>=N1
           NUM1=N1;
        end
        if NUM2>=N2
           NUM2=N2;
        end
        
        %适应度值的计算 
        [pa(i),X1,Y1,f1,f2,NX1,NX2] = func_obj1(XYZ1,NUM1,NUM2);
        if pa(i)<p(i)
           p(i)  = pa(i);
           y(i,:)= x(i,:);
        end
 
        XYZ1=[pg(1:(dim-2)/2);pg(1+(dim-2)/2:(dim-2))];
        NUM1        = floor(x(i,dim-1));
        NUM2        = floor(x(i,dim));
        if NUM1>=N1
           NUM1=N1;
        end
        if NUM2>=N2
           NUM2=N2;
        end
        %适应度值的计算 
        [pb(i),X1,Y1,f1,f2,NX1,NX2] = func_obj1(XYZ1,NUM1,NUM2);
        if p(i)<pb(i)
           pg=y(i,:);
        end
    end
    XYZ1=[pg(1:(dim-2)/2);pg(1+(dim-2)/2:(dim-2))];
    NUM1        = floor(x(i,dim-1));
    NUM2        = floor(x(i,dim));
        if NUM1>=N1%变量的约束
           NUM1=N1;
        end
        if NUM2>=N2%变量的约束
           NUM2=N2;
        end
    [pc,X1,Y1,f1,f2,NX1,NX2] = func_obj1(XYZ1,NUM1,NUM2);%适应度值的计算 
    Pbest(t)  = pc;
end
 
 

figure;
plot(1:10:MAXGEN,1-Pbest(1:10:end),'-r>',...
    'LineWidth',1,...
    'MarkerSize',6,...
    'MarkerEdgeColor','k',...
    'MarkerFaceColor',[0.9,0.9,0.0]);
grid on
xlabel('迭代次数');
ylabel('虚拟力算法优化过程');
legend('Average fitness');

%覆盖率
disp('覆盖率');
f1
%安装难易度
disp('安装难易度');
f2



[X1,Y1,NUM1_new,NUM2_new]=func_delete([X1;Y1],NX1,NX2);
%最优传感器数量
disp('最优传感器数量');
Nopt1 = NUM1_new
Nopt2 = NUM2_new

figure;
%显示障碍物
for i = 1:Nr1
    plotcube([L(i) W(i) 0],[X3(i),Y3(i),0],1,[0.8 0.9 0]);
    hold on
end
for i = 1:Nr2
    [x,y]=circle(R4(i),X4(i),Y4(i));
    plot(x,y,'g','linewidth',2);
    hold on
end
for i = 1:length(X1)
    if i<=Nopt1
    [x,y]=circle(Rad1,X1(i),Y1(i));
    plot(x,y,'r','linewidth',1);
    else
    %第一、传感器不用球或者圆替代,进行和原来一样的显示    
    rectangle('Position', [X1(i)-Rad2,Y1(i)-Rad2,2*Rad2,2*Rad2], 'LineWidth', 1, 'EdgeColor', 'b', 'Clipping', 'off')
    end
    
    hold on
    plot(X1(i),Y1(i),'r.');
end

view([0,90]);
axis equal
axis([0,SCALE,0,SCALE]);
09_057_m

4. Complete algorithm code file

V

Guess you like

Origin blog.csdn.net/hlayumi1234567/article/details/131137552