1. Scheduling algorithm based on clustering topology node hibernation

1. Overview of wireless sensor network operation

Wireless sensor network runs according to the number of rounds. The operation process of the network includes two parts: network establishment node and node stable operation stage, as shown in Figure 1.

FIG. 1 Schematic diagram of network running rounds

In the stage of establishing a network of the whole wireless sensor network clustering, was elected in accordance with a certain probability to become cluster head nodes, and then to its neighbor nodes send the invitation to join the cluster structure of the message, and the neighbor nodes judging by the strength of the signal, the nearest join cluster structure and according to the transfer of a TDMA time slice data to the cluster head. Then the nodes in the cluster enter the stable operation stage, and the cluster-head node and other common nodes work steadily. Each cluster-head node collects and fuses data on the coverage sense of the monitoring area, and finally forwards the data to the cluster-head node, while the redundant nodes are dormant and do not consume energy. Figure 2 is the node state diagram of a cluster structure in a wireless sensor network. The cluster head node, dormant node and common node in the figure are represented as CH CHCH node, white node and black node respectively.

Figure 2. Schematic diagram of WSN

2. NDSCT algorithm design

(1) Selection of cluster heads

In the selection of cluster head for the whole wireless sensor network, the node will randomly generate a random value between (0,1)(0,1) (0,1). If the preset threshold value is greater than the random value, it will be successfully selected as the cluster head node, and then the message of its successful selection as the cluster head is broadcast to other surrounding nodes. T(n)T(n) T(n) can be calculated as follows:

In Formula (1), p pp is the ratio of the cluster head node to the entire network node, E0 E_0E0 is the initial node energy, Er E s I dua L E_{residual}Eresidual is the residual node energy, n nn is the current rotation number, G GG is the set of nodes that failed to run for the head of cluster. According to Formula (1), the more residual energy a node has, the larger its threshold will be, so it will be easier to be selected as the cluster head node.

(2) Cluster formation

After the cluster head node broadcasts the message that has been elected as the cluster head to other nodes, other neighboring nodes will decide to join the cluster structure which is relatively close according to the signal strength of the broadcast message of the cluster head and confirm the message to the first cluster. When the cluster head node receives the request to join the message, TDMA method is used to transfer the time slice of data to each node in the cluster structure, and the cluster is established.

(3) Scheduling nodes in the cluster

After the formation of cluster structure in each round, all nodes in the activated cluster will conduct a judgment of coverage redundancy according to their id IDID size in turn. The conditions for determining the redundant coverage nodes are as follows:

(1) If the number of neighbor nodes in the perceptual coverage area of the node in the cluster is less than four, the node will continue to be active and work;

(2) if the quantity of nodes perception coverage area is greater than or equal to the number of neighbor nodes within four (4) and satisfy as shown in figure 3 cover conditions, namely the node’s perception of the coverage was completely covered by its neighbor nodes, then the node for redundant nodes, it perceived the data are perceived, neighbor node is the node in this round of dormancy, The next round starts over.

Figure 3 Node distribution in the coverage range of redundant node O

The flow chart of NDSCT algorithm is shown in Figure 4.

FIG. 4 Flow chart of NDSCT algorithm

2. Simulation analysis

1. Simulation environment

The clustering topology node dormancy scheduling algorithm was simulated by using MatlabMatlab as an experimental simulation platform, and the simulation results were compared with LEACH algorithm. All sensor nodes are randomly distributed within the target monitoring area of 100m×100m100m× 100m100m×100m. The sink node, namely the base station, is in the middle of the whole network. The total number of sensor nodes is 100. The communication radius of the sensor is twice the perception radius, that is, R C =2R S Rc=2RsRc=2Rs, R C RcRc is 30m, and R S RsRs is 15m. The parameter Settings of the experiment are the same as those in literature [1].

2. Number of dormant nodes

Figure 5 shows the number of dormant nodes in each round of NDSCT algorithm.

Figure 5 Number of dormant nodes in each round of NDSCT algorithm

3. Number of surviving nodes

The number of viable nodes in each round of NDSCT and LEACH algorithm is shown in Figure 6.

FIG. 6 Number of viable nodes

3. Total remaining energy of the network

The total remaining energy of the network in each round of NDSCT and LEACH algorithm is shown in Figure 7.

Figure 6 Total remaining energy of network

4. Nodes consume total energy

The total energy consumed by nodes in each round of NDSCT and LEACH algorithm is shown in Figure 8.

FIG. 8 Total energy consumed by nodes

5. Demo code

%% 清空环境变量
clear;
clc;

%% 初始化参数
xm = 100;                  % x轴范围
ym = 100;                  % y轴范围
sink.x = 50;               % 基站x轴 50
sink.y = 50;               % 基站y轴 50
n = 100;                   % 节点总数
p = 0.05;                  % 簇头概率
Rs = 15;                   % 感知半径
Rc = 2*Rs;                 % 通信半径
Eelec = 50*10^(-9);
Efs=10*10^(-12);
Emp=0.0013*10^(-12);
ED=5*10^(-9);
d0 = sqrt(Efs/Emp);
E0 = 0.5;                  % 初始能量
packetLength = 4000;
ctrPacketLength = 100;
rmax = 6000;

figure;
%% 节点随机分布
for i = 1:n
    Node(i).xd = rand(1,1)*xm;
    Node(i).yd = rand(1,1)*ym;   % 随机产生100个点
    Node(i).type = 'N';          % 进行选举簇头前先将所有节点设为普通节点
    Node(i).E = E0;              % 初始能量
    Node(i).CH = 0;              % 保存普通节点的簇头节点,-1代表自己是簇头
    Node(i).d = sqrt((Node(i).xd-sink.x)^2+(Node(i).yd-sink.y)^2);
    Node(i).G = 0;                  % 候选集标志
    Node(i).Nbr = zeros(n, 1);      % 邻居节点集
    Node(i).NumNbr = 0;             % 邻居节点个数
    Node(i).status = 1;             % 节点的状态:1  激活状态;0  休眠状态
    plot(Node(i).xd, Node(i).yd, 'o', sink.x, sink.y, 'p', 'LineWidth', 2);
    hold on;
end
legend('节点', '基站');
xlabel 'x'; ylabel 'y'; title 'WSN分布图';
save data1;
%%%%%%%%%%%%%%%%%NDSCT%%%%%%%%%%%%%%%
alive_ndsct = zeros(rmax, 1);        % 每轮存活节点数
re_ndsct = zeros(rmax, 1);           % 每轮节点总能量
ce_ndsct = zeros(rmax, 1);           % 每轮节点消耗总能量
sleep = zeros(rmax, 1);              % 每轮休眠节点数
for r = 1:rmax
    r
%     figure;
    if mod(r, round(1/p)) == 0
        for i = 1:n
            Node(i).G = 0;
        end
    end
    % 初始化
    for i = 1:n
        if Node(i).E > 0
            Node(i).type = 'N';
            Node(i).CH = 0;
            Node(i).status = 1;
            Node(i).NumNbr = 0;
            alive_ndsct(r) = alive_ndsct(r)+1;
            re_ndsct(r) = re_ndsct(r)+Node(i).E;
        end
    end
    if alive_ndsct(r) == 0
        break;
    end
    % 计算邻居节点
    for i = 1:n
        if Node(i).E > 0
            count = 0;
            for j = 1:n
                if Node(j).E > 0
                    dist = sqrt((Node(i).xd-Node(j).xd)^2+(Node(i).yd-Node(j).yd)^2);
                    if j ~= i && dist < Rs
                        count = count + 1;
                        Node(i).Nbr(count) = j;
                    end
                end
                if j == n
                    Node(i).NumNbr = count;
                end
            end
        end
    end
    %% 簇头选举
    cluster = 0;
    for i = 1:n
        if  Node(i).E > 0
            temp_rand = rand;
            if Node(i).G <= 0 && temp_rand < p/(1-p*mod(r,round(1/p)))*(Node(i).E/E0)
                Node(i).type = 'C';      % 节点类型为簇头
                Node(i).G = round(1/p)-1;
                cluster = cluster + 1;
                % 簇头节点存入C数组
                C(cluster).xd = Node(i).xd;
                C(cluster).yd = Node(i).yd;
                C(cluster).dist = Node(i).d;
                C(cluster).id = i;
%                 X(cluster) = Node(i).xd;
%                 Y(cluster) = Node(i).yd;
%                 plot(Node(i).xd, Node(i).yd, 'r*');
%                 hold on;
                CH = C;
                Node(i).CH = -1;
                % 广播自成为簇头
                distanceBroad = sqrt(xm*xm+ym*ym);
                if distanceBroad > d0
                    Node(i).E = Node(i).E- (Eelec*ctrPacketLength + Emp*ctrPacketLength*distanceBroad^4);
                    ce_ndsct(r) = ce_ndsct(r)+Eelec*ctrPacketLength + Emp*ctrPacketLength*distanceBroad^4;
               else
                    Node(i).E = Node(i).E- (Eelec*ctrPacketLength + Efs*ctrPacketLength*distanceBroad^2);
                    ce_ndsct(r) = ce_ndsct(r)+Eelec*ctrPacketLength + Efs*ctrPacketLength*distanceBroad^2;
                end
                % 簇头自己发送数据包能量消耗
                if Node(i).d > d0
                    Node(i).E = Node(i).E- ((Eelec+ED)*packetLength+Emp*packetLength*Node(i).d^4);
                    ce_ndsct(r) = ce_ndsct(r)+(Eelec+ED)*packetLength+Emp*packetLength*Node(i).d^4;
                else
                    Node(i).E = Node(i).E- ((Eelec+ED)*packetLength+Efs*packetLength*Node(i).d^2);
                    ce_ndsct(r) = ce_ndsct(r)+(Eelec+ED)*packetLength+Efs*packetLength*Node(i).d^2;
                end
            end
        end
    end
    % 判断最近的簇头结点,如何去判断,采用距离矩阵
    for i = 1:n
        if Node(i).type == 'N' && Node(i).E > 0
            if cluster > 0
                Length = zeros(cluster, 1);
                for c = 1:cluster
                    Length(c) = sqrt((Node(i).xd - C(c).xd)^2+(Node(i).yd-C(c).yd)^2);
                end
                [min_dis, min_dis_cluster] = min(Length);    % 找到距离簇头最近的簇成员节点
                % 接收簇头发来的广播的消耗
                Node(i).E = Node(i).E - Eelec*ctrPacketLength;
                ce_ndsct(r) = ce_ndsct(r)+Eelec*ctrPacketLength;
                % 加入这个簇
                if min_dis < d0
                    Node(i).E = Node(i).E-(Eelec*ctrPacketLength+Efs*ctrPacketLength*min_dis^2);
                    ce_ndsct(r) = ce_ndsct(r)+Eelec*ctrPacketLength+Efs*ctrPacketLength*min_dis^2;
                else
                    Node(i).E = Node(i).E-(Eelec*ctrPacketLength+Emp*ctrPacketLength*min_dis^4);
                    ce_ndsct(r) = ce_ndsct(r)+Eelec*ctrPacketLength+Emp*ctrPacketLength*min_dis^4;
                end
                Node(i).CH = C(min_dis_cluster).id;
%                 plot(Node(i).xd, Node(i).yd, 'ko');
%                 hold on;
%                 plot([Node(i).xd; Node(C(min_dis_cluster).id).xd], [Node(i).yd; Node(C(min_dis_cluster).id).yd]);
%                 hold on;
                % 簇头接收簇成员接收加入消息
                 if min_dis > 0
                    Node(C(min_dis_cluster).id).E = Node(C(min_dis_cluster).id).E - Eelec*ctrPacketLength; %接收加入消息
                    ce_ndsct(r) = ce_ndsct(r)+Eelec*ctrPacketLength;
                 end
            end
        end
    end
    %% 判断冗余节点,进行休眠调度
    for i = 1:n
        if Node(i).E > 0 && Node(i).type == 'N'     % 非簇头节点
            if Node(i).NumNbr >= 4          % 邻居节点个数≥4
                if isFullCover(Node, i) == 1
                    Node(i).status = 0;     % 冗余节点,状态调整为休眠状态
                    sleep(r) = sleep(r)+1;
%                     plot(Node(i).xd, Node(i).yd, 'go');
%                     hold on;
                end         
            end
        end
    end
    %% 数据传输
    for i = 1:n
        if Node(i).E > 0 && Node(i).status ~= 0         % 节点存活且状态为激活态
            if Node(i).type == 'N'      % 普通节点
                if cluster > 0   % 簇头节点存在
                    dist = sqrt((Node(i).xd-Node(Node(i).CH).xd)^2+(Node(i).yd-Node(Node(i).CH).yd)^2);
                    % 向簇头发送数据
                    if dist < d0
                        Node(i).E = Node(i).E-(Eelec*packetLength+Efs*packetLength*dist^2);
                        ce_ndsct(r) = ce_ndsct(r)+Eelec*packetLength+Efs*packetLength*dist^2;
                    else
                        Node(i).E = Node(i).E-(Eelec*packetLength+Emp*packetLength*dist^4);
                        ce_ndsct(r) = ce_ndsct(r)+Eelec*packetLength+Emp*packetLength*dist^4;
                    end
                else                    % 无簇头选出
                    % 直接发送数据到基站
                    dist = Node(i).d;
                    if dist < d0
                        Node(i).E = Node(i).E-(Eelec*packetLength+Efs*packetLength*dist^2);
                        ce_ndsct(r) = ce_ndsct(r)+Eelec*packetLength+Efs*packetLength*dist^2;
                    else
                        Node(i).E = Node(i).E-(Eelec*packetLength+Emp*packetLength*dist^4);
                        ce_ndsct(r) = ce_ndsct(r)+Eelec*packetLength+Emp*packetLength*dist^4;
                    end
                end
            end
        end
    end
end
load data1.mat;
%%%%%%%%%%%%%%LEACH%%%%%%%%%%%%%%%
%%
alive_leach = zeros(rmax, 1);        % 每轮存活节点数
re_leach = zeros(rmax, 1);           % 每轮节点总能量
ce_leach = zeros(rmax, 1);           % 每轮节点消耗总能量
for r = 1:rmax
%     figure;
    if mod(r, round(1/p)) == 0
        for i = 1:n
            Node(i).G=0;
        end
    end
    for i = 1:n
        if Node(i).E > 0
            Node(i).type = 'N';
            Node(i).CH = 0;
            alive_leach(r) = alive_leach(r)+1;
            re_leach(r) = re_leach(r)+Node(i).E;
        end
    end
    if alive_leach(r) == 0
        break;
    end
    %% 簇头选举
    cluster = 0;
    for i = 1:n
        if  Node(i).E > 0
            temp_rand = rand;
            if Node(i).G <= 0 && temp_rand < p/(1-p*mod(r,round(1/p)))
                Node(i).type = 'C';      % 节点类型为簇头
                Node(i).G = round(1/p)-1;
                cluster = cluster + 1;
                % 簇头节点存入C数组
                C(cluster).xd = Node(i).xd;
                C(cluster).yd = Node(i).yd;
                C(cluster).dist = Node(i).d;
                C(cluster).id = i;
                X(cluster) = Node(i).xd;
                Y(cluster) = Node(i).yd;
                CH = C;
                Node(i).CH = -1;
                % 广播自成为簇头
                distanceBroad = sqrt(xm*xm+ym*ym);
                if distanceBroad > d0
                    Node(i).E = Node(i).E- (Eelec*ctrPacketLength + Emp*ctrPacketLength*distanceBroad^4);
                    ce_leach(r) = ce_leach(r)+Eelec*ctrPacketLength + Emp*ctrPacketLength*distanceBroad^4;
               else
                    Node(i).E = Node(i).E- (Eelec*ctrPacketLength + Efs*ctrPacketLength*distanceBroad^2);
                    ce_leach(r) = ce_leach(r)+Eelec*ctrPacketLength + Efs*ctrPacketLength*distanceBroad^2;
                end
                % 簇头自己发送数据包能量消耗
                if Node(i).d > d0
                    Node(i).E = Node(i).E- ((Eelec+ED)*packetLength+Emp*packetLength*Node(i).d^4);
                    ce_leach(r) = ce_leach(r)+(Eelec+ED)*packetLength+Emp*packetLength*Node(i).d^4;
                else
                    Node(i).E = Node(i).E- ((Eelec+ED)*packetLength+Efs*packetLength*Node(i).d^2);
                    ce_leach(r) = ce_leach(r)+(Eelec+ED)*packetLength+Efs*packetLength*Node(i).d^2;
                end
            end
        end
    end
    % 判断最近的簇头结点,如何去判断,采用距离矩阵
    for i = 1:n
        if Node(i).type == 'N' && Node(i).E > 0
            if cluster > 0
                Length = zeros(cluster, 1);
                for c = 1:cluster
                    Length(c) = sqrt((Node(i).xd - C(c).xd)^2+(Node(i).yd-C(c).yd)^2);
                end
                [min_dis, min_dis_cluster] = min(Length);    % 找到距离簇头最近的簇成员节点
                % 接收簇头发来的广播的消耗
                Node(i).E = Node(i).E - Eelec*ctrPacketLength;
                ce_leach(r) = ce_leach(r)+Eelec*ctrPacketLength;
                % 加入这个簇,并发送数据给簇头
                if min_dis < d0
                    Node(i).E = Node(i).E-(Eelec*(ctrPacketLength+packetLength)+Efs*(ctrPacketLength+packetLength)*min_dis^2);
                    ce_leach(r) = ce_leach(r)+Eelec*(ctrPacketLength+packetLength)+Efs*(ctrPacketLength+packetLength)*min_dis^2;
                else
                    Node(i).E = Node(i).E-(Eelec*(ctrPacketLength+packetLength)+Emp*(ctrPacketLength+packetLength)*min_dis^4);
                    ce_leach(r) = ce_leach(r)+Eelec*(ctrPacketLength+packetLength)+Emp*(ctrPacketLength+packetLength)*min_dis^4;
                end
                Node(i).CH = C(min_dis_cluster).id;
                % 簇头接收簇成员数据包消耗能量,接收加入消息
                 if min_dis > 0
                    Node(C(min_dis_cluster).id).E = Node(C(min_dis_cluster).id).E - (Eelec+ED)*packetLength; %接受簇成员发来的数据包
                    Node(C(min_dis_cluster).id).E = Node(C(min_dis_cluster).id).E - Eelec*ctrPacketLength; %接收加入消息
                    ce_leach(r) = ce_leach(r)+(Eelec+ED)*packetLength+Eelec*ctrPacketLength;
                end
            else                 % 无簇头选出,直接发送数据包到基站
                if Node(i).d < d0
                    Node(i).E = Node(i).E-(Eelec*packetLength+Efs*packetLength*Node(i).d^2);
                    ce_leach(r) = ce_leach(r)+Eelec*packetLength+Efs*packetLength*Node(i).d^2;
                else
                    Node(i).E = Node(i).E-(Eelec*packetLength+Emp*packetLength*Node(i).d^4);
                    ce_leach(r) = ce_leach(r)+Eelec*packetLength+Emp*packetLength*Node(i).d^4;
                end
            end
        end
%         [vx, vy] = voronoi(X, Y);
%         plot(X, Y, 'r*', vx, vy, 'g-');
%         hold on;
%         voronoi(X, Y);
%         axis([0 xm 0 ym]);
    end
end
%% 绘图显示
figure;
plot(1:rmax, sleep, 'r', 'linewidth', 1);
xlabel '轮数'; ylabel '每轮休眠节点数';
legend('NDSCT');
figure;
plot(1:rmax, alive_ndsct, 'r', 1:rmax, alive_leach, 'g', 'LineWidth', 2);
xlabel '轮数'; ylabel '每轮存活节点数';
legend('NDSCT', 'LEACH');
figure;
plot(1:rmax, re_ndsct, 'r', 1:rmax, re_leach, 'g', 'LineWidth', 2);
xlabel '轮数'; ylabel '每轮剩余总能量';
legend('NDSCT', 'LEACH');
figure;
plot(1:rmax, ce_ndsct, 'r', 1:rmax, ce_leach, 'g', 'LineWidth', 1);
xlabel '轮数'; ylabel '每轮消耗总能量';
legend('NDSCT', 'LEACH');
Copy the code

Iii. References and codes private message bloggers

[1] Zhang LEI. Research on node sleep scheduling algorithm based on clustering topology in wireless sensor networks [D]. 2019.