[WSN] Research on node energy consumption of WSN routing protocol (shortest path) based on ant colony algorithm (Matlab code implementation)

Welcome to this blog

Advantages of bloggers:Blog content should be as thoughtful and logical as possible for the convenience of readers.

Motto:He who travels a hundred miles is half as good as ninety.

The directory of this article is as follows:

Table of Contents

1 Overview

2 Operation results

3 References

4 Matlab code implementation


1 Overview

[WSN] Research on node energy consumption of routing protocols (shortest paths) based on the ant colony algorithm is a very important topic.

In wireless sensor networks (WSN) without Ant Colony Algorithm (ACO), when using the same routing protocol (shortest path), node energy will continue to be consumed, eventually leading to node death. This is because when sensor nodes transmit data, they often need to pass through multiple relay nodes to reach the destination, and the data forwarding of these relay nodes consumes a large amount of energy. In the absence of the ACO algorithm, nodes in the network do not take into account differences in energy consumption and therefore cannot make targeted routing choices.

In the WSN network where the ACO step is applied, the situation is different. Data is also transmitted through a routing protocol (shortest path), but ACO analyzes the energy consumption of the path being used and makes routing adjustments based on the energy consumption evaluation results. This means that under the guidance of the ACO algorithm, nodes can make corresponding decisions based on energy changes on the routing path. For example, if the energy consumption of a certain path is large, ACO can select other paths with relatively small energy consumption to reduce the energy consumption of nodes.

By introducing the ACO algorithm, nodes in the WSN network can choose routing paths more intelligently, thereby reducing node energy consumption. This will extend the life of the entire network and improve network stability and performance. In addition, the ACO algorithm can also be adjusted and optimized according to the actual situation of the network to better adapt to different application scenarios and changes in node energy consumption.

All in all, by studying the node energy consumption of routing protocols (shortest paths) based on the ant colony algorithm, we can deeply understand the key factors of energy problems in WSN networks and provide effective methods to solve the problem of excessive node energy consumption. The introduction of the ACO algorithm enables nodes to intelligently select routing paths based on energy consumption, thereby optimizing energy distribution, extending network life, and improving network reliability and performance.

2 Running results

Continuously running.

Part of the code:

%% Main configuration values for this simulation

dataset.nodeNo = 9; %Number of nodes
ACOnodeNo = dataset.nodeNo;
dataset.nodePosition(1,:) = [1 50 50]; %(Sender node fixed position)
dataset.nodePosition(2,:) = [2 900 900]; %(Receiver node fixed position)
dataset.NeighborsNo = 5;
dataset.range = 500; %Tolerance distance to became neighbor of one node (Euclidean distance based)
dataset.attenuationFactor = 1.8; %Atenuation factor in freespace - ranges from 1.8 to 4 due environment
dataset.minEnergy = 80; % Mw - Miliwatts (70% energy)
dataset.maxEnergy = 100; % Mw - Miliwatts (Full energy (100%) - 1 mAh charge capacity within 1 Volt energy)
dataset.energyconsumptionperCicle = 0.85;
dataset.energyrecoveryperCicle = 0.2;
dataset.minenergyfactor = 0.18;
dataset.maxenergyfactor = 0.2;
STenergy=inf;
packet=0;
iterationcounter=1;
plotgraphs=1; %Choose 1 for "yes" or 0 for "no" if you want to plot graphs or no (Better performance if no)
reprodutibily = 0; %1 = yes (always generate same random numbers) (0) for no reprodutibility (Different random numbers every code execution);


% Node position sortition
if reprodutibily == 0
    rng('shuffle');
else
    rng('default');
end
for a = 3 : dataset.nodeNo
    
   dataset.nodeId = a;
   garbage.x = randi([1 900]); %Xpos sortition
   garbage.y = randi([1 900]); %Ypos sortition
   dataset.nodePosition(a,:) = [dataset.nodeId garbage.x garbage.y]; %NodeID, X and Y position into nodePosition table
   
end

% Euclidean Distance calc from one node to all others

for i = 1 : dataset.nodeNo
    for j = 1: dataset.nodeNo
        garbage.x1 = dataset.nodePosition(i,2);
        garbage.x2 = dataset.nodePosition(j,2);
        garbage.y1 = dataset.nodePosition(i,3);
        garbage.y2 = dataset.nodePosition(j,3);
        
        dataset.euclidiana(i,j) = sqrt( (garbage.x1 - garbage.x2) ^2 + (garbage.y1 - garbage.y2)^2 );
        
    end
end

% Edges matrix definition due "range" variable value

dataset.weights = lt(dataset.euclidiana,dataset.range);

% Graph construction

G=graph(dataset.weights,'omitselfloops'); %Graph creation based on adjacency matrix (Edges matrix) built above

% Euclidean distance extraction for all existent end-to-end formed by
% "distance tolerance" (range variable value)

%% Main configuration values for this simulation

dataset.nodeNo = 9; %Number of nodes
ACOnodeNo = dataset.nodeNo;
dataset.nodePosition(1,:) = [1 50 50]; %(Sender node fixed position)
dataset.nodePosition(2,:) = [2 900 900]; %(Receiver node fixed position)
dataset.NeighborsNo = 5;
dataset.range = 500; %Tolerance distance to became neighbor of one node (Euclidean distance based)
dataset.attenuationFactor = 1.8; %Atenuation factor in freespace – ranges from 1.8 to 4 due environment
dataset.minEnergy = 80; % Mw – Miliwatts (70% energy)
dataset.maxEnergy = 100; % Mw – Miliwatts (Full energy (100%) – 1 mAh charge capacity within 1 Volt energy)
dataset.energyconsumptionperCicle = 0.85;
dataset.energyrecoveryperCicle = 0.2;
dataset.minenergyfactor = 0.18;
dataset.maxenergyfactor = 0.2;
STenergy=inf;
packet=0;
iterationcounter=1;
plotgraphs=1; %Choose 1 for “yes” or 0 for “no” if you want to plot graphs or no (Better performance if no)
reprodutibily = 0; %1 = yes (always generate same random numbers) (0) for no reprodutibility (Different random numbers every code execution);

% Node position sortition
if reprodutibily == 0
rng(‘shuffle’);
else
rng(‘default’);
end
for a = 3 : dataset.nodeNo

dataset.nodeId = a;
garbage.x = randi([1 900]); %Xpos sortition
garbage.y = randi([1 900]); %Ypos sortition
dataset.nodePosition(a,:) = [dataset.nodeId garbage.x garbage.y]; %NodeID, X and Y position into nodePosition table

end

% Euclidean Distance calc from one node to all others

for i = 1 : dataset.nodeNo
for j = 1: dataset.nodeNo
garbage.x1 = dataset.nodePosition(i,2);
garbage.x2 = dataset.nodePosition(j,2);
garbage.y1 = dataset.nodePosition(i,3);
garbage.y2 = dataset.nodePosition(j,3);

dataset.euclidiana(i,j) = sqrt( (garbage.x1 – garbage.x2) ^2 + (garbage.y1 – garbage.y2)^2 );

end
end

% Edges matrix definition due “range” variable value

dataset.weights = lt(dataset.euclidiana,dataset.range);

% Graph construction

G=graph(dataset.weights,’omitselfloops’); %Graph creation based on adjacency matrix (Edges matrix) built above

% Euclidean distance extraction for all existent end-to-end formed by
% “distance tolerance” (range variable value)

3 References

Some of the content in the article is quoted from the Internet. The source will be indicated or cited as a reference. It is inevitable that there will be some unfinished information. If there is anything inappropriate, please feel free to contact us to delete it.

[1] Liao Minghua, Zhang Hua, Xie Jianquan. WSN energy prediction routing protocol based on ant colony algorithm [J]. Computer Engineering, 2012, 38(3):88-90.DOI:10.3969/j.issn.1000-3428.2012. 03.030.

[1] Mi Yiping. Research on WSN routing algorithm based on improved ant colony algorithm [D]. North China University [2023-09-19]. DOI: CNKI: CDMD: 2.1012.336755.

4 Matlab code implementation

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Algorithm skill tree Home page Overview 53760 people are learning the system