Deployment Scenario (Static Sensor-Mobile Anchor)
In this post, we will write a code for Static Sensors and Mobile Anchor deployment scenario. Initially, we will use the simplest mobility model called Random Way-point Mobility Model (RWP). This mobility model generates the random destinations for a mobile anchor. Once, a mobile anchor reached to a destination, it will again moves straight toward the other random destination. This code is the simple one to explain the RWP mobility model.
Deployment Scenario (Static Sensors and Mobile Anchor deployment)
clc
clear all
close all
%% Deployment of the nodes and anchor nodes
N=100; % Total Number of Sensors
MA=1; % Total Number of Mobile Anchors
X=100; % Area length
Y=100; % Area width
R=20; % Transmission radius (m)
[s_x,s_y, points]=create_distribution(N,X,Y);
ma_x=points(:,1);
ma_y=points(:,2);
plot(s_x,s_y,'bo'); % plot the sensor distribution
hold on
plot(ma_x,ma_y,'*m:'); % plot the mobile anchor followed path
grid on
hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Create Distribution Function (Create a new file and paste the below code and saved the file as create_distribution.m)
function[s_x,s_y,points]=create_distribution(N,X,Y)
s_x = rand(1,N)*X; % sensor random distribution on X axis
s_y = rand(1,N)*Y; % sensor random distribution on Y axis
%%%%%%%%%%%% Mobile anchor RWP mobility model%%%%%%%%%%%%%%
d = 10; % distance of generating the random points (interval)
n = 50; % Number of points to generate
points = [rand(1, 2) .* [X Y]]; % points hold all the generated random points.
d2 = d ^ 2;
% Keep adding points until we have n points.
while (size(points, 1) < n)
point = rand(1, 2) .* [X Y]; % Randomly generate a new point
% Calculate squared distances to all other points
dist2 = sum((points - repmat(point, size(points, 1), 1)) .^ 2, 2);
% Only add this point if it is far enough away from all others.
if (all(dist2 > d2))
points = [points; point];
end
end
These code you can get it from my google drive shareable link given below..
Comments
Post a Comment