probabilistic flooding simulation for uniformly distributed nodes

4 views (last 30 days)
Hii... i am working on simulation of random flooding in uniformly distributed wireless sensor networks. i got the simulation for randomly distributed nodes from here : http://www.mathworks.com/matlabcentral/fileexchange/7928-probabilistic-flooding-simulation i have made the following changes in the code to make the node distribution uniform.
clc;
clear all;
rand('state', 5);
numOfNodes = 4; % number of nodes(changes i made is plotting 4*4 nodes)
envSize=1000; % envsizeXenvsize environment
txRange = 500;
global floodProb; % the pre-defined probability to broadcast;
global savedTransmission; % The number of saved re-transmissions;
savedTransmission = 0;
global xLocation; % Array containing the X-coordinations of wireless nodes;
global yLocation; % Array containing the Y-coordinations of wireless nodes;
__ xLocation = [0:envSize/numOfNodes:envSize];%rand(1,numOfNodes) * envSize;
yLocation = [0:envSize/numOfNodes:envSize];_%rand(1,numOfNodes) * envSize; %x,y coords of nodes_
% Generate the adjacent matrix to represent the topology graph of the
% randomly deployed wireless networks;
distMatrix = zeros(numOfNodes,numOfNodes);
for i=1:numOfNodes
for j=1:numOfNodes
distMatrix(i,j)=sqrt((xLocation(i)-xLocation(j))^2 + (yLocation(i)-yLocation(j))^2); %distance between node pairs
end;
end;
% If the Euclidean distance between two nodes is less than the transmission range, there
% exists a link.
global connMatrix;
connMatrix = ( distMatrix < txRange); %binary connectivity matrix
% The broadcast will start from a sink node;
sinkNode = 1; % sink node;
% Array visited[] stores the boolean value if the broadcast has reach the node.
global visited;
visited = zeros(1, numOfNodes);
% Show the topology;
figure(1);
_hold on;
for i = 1:numOfNodes
for j=1:numOfNodes
plot (xLocation(i),yLocation(j),'*');
end;
end;_
%plot(xLocation, yLocation, '.');
%text(xLocation(sinkNode), yLocation(sinkNode), 'sink');
% title(['p = ' num2str(floodProb)]);
% sink node;
hold off;
visited(sinkNode) = 1;
% recursive Depth first search is adopted to traverse the whole graph;
DFS(sinkNode);
savedTransmission
return;
changes that i have made are in assigning values to "xLocation and yLocation " and in "show the topology".
when i run the program it is plotting the nodes but links only to the nodes along y=x axis. it doesn't connect to the other neighbors. please help me out
  2 Comments
Durgaprasad Srinivasa
Durgaprasad Srinivasa on 26 Mar 2020
function [] = DFS(r)
global connMatrix;
global visited;
global xLocation;
global yLocation;
global floodProb;
global savedTransmission;
wait_time = 20000000;
% Get the number of reachable neighbors
neighborNodes = find(connMatrix(r, :) == 1);
% Get the unreached neighbors
neigbborNodes = intersect(neighborNodes, find(visited(:) == 0));
for k = 1:length(neighborNodes),
line([xLocation(r) xLocation(neighborNodes(k))], [yLocation(r) yLocation(neighborNodes(k))]);
end;
drawnow;
for k = 1:length(neighborNodes),
if (visited(neighborNodes(k)) == 0),
visited(neighborNodes(k)) = 1;
for i=1:wait_time j=i; end
floodProb = 9 / length(neighborNodes);
p = rand;
if p <= floodProb,
% broadcast again;
DFS(neighborNodes(k));
else
savedTransmission = savedTransmission + 1;
end;
end;
end;
you have to use this function to connect othernodes. For more information follow this link belowhttps://se.mathworks.com/matlabcentral/fileexchange/7928-probabilistic-flooding-simulation?s_tid=srchtitle

Sign in to comment.

Answers (1)

Durgaprasad Srinivasa
Durgaprasad Srinivasa on 26 Mar 2020

Categories

Find more on Wireless Communications in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!