PROJECT VIDEO
SCENARIO
1- Deploy nodes in the forest.
2- All the nodes in the equal range.
3- All the nodes that are in the one range having a one cluster head they work as a cluster coordinator.
4- Data aggregation happening on that point.
5- In the scenario first we send packet from source to destinatiosink,n when environment having no problem.
6- In the second when the fire happen that time those will detect the fire this node working as a source sent information to destination (base station).
7- Third case when fire destroy the cluster head then election algorithm elect the new cluster head and communicate with other nodes sent information to destination.
MATLAB SOURCE CODE
Instructions to run the code
1- Copy each of below codes in different M files.
2- Place all the files in same folder
3- Use the Excel files from below link and download them into the same folder as the source codes
4- Also note that these codes are not in a particular order. Copy them all and then run the program.
5- Run the “FINAL.m” file
Code 1 – Script M File – FINAL.m
clc clear all close all disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') disp('%%%%%%%%%%% WELCOME TO JUNGLE FIRE DETECTION PROGRAMME %%%%%%%%%%%') disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') hn=input('Please enter the approx number of HEAD NODES (minimum 5): '); % number of head nodes while hn<5 % minimum number of head nodes must be 5 disp('Too few sensors, please enter again') hn=input('Please enter the approx number of HEAD NODES (minimum 5): '); end %hn=30; disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') disp('Placing the sensors') disp('Press enter to continue..') pause figure(1) [x,y,x1,y1,row,col,bp]=placing_sensors(hn); title('Placement of the sensors with networking between the head nodes and base station') hold off disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') disp('Condition of no fire') disp('Press enter to continue..') pause for i=1:2 figure(2) normal_condition(hn) title('Flow of information when there is no fire') hold off pause(0.3) if i==3 break else set(gca,'Color','w') end end disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') disp('Condition of fire') disp('Press enter to continue..') pause figure(3) start_fire=fire_condition(hn); title('Condition of fire increasing through the jungle') hold off disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') disp('Condition of fire detection') disp('Press enter to continue..') pause figure(4) %firedetection2(hn,x,y,x1,y1,row,col) [axis,time,burntnodes,basetime,times,unik]=fire_detection3(hn,bp,x,y,x1,y1,row,col); title('Detecting the fire(scenario 1)') % figure(5) % [axis,time,burntnodes,basetime]=fire_detection(hn,bp,x,y,x1,y1,row,col); % %test_scene(hn) % title('Detecting the fire(scenario 1)') disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%') disp('Graphs') disp('Press enter to continue..') pause % graphs(axis,time,burntnodes,x1,y1,basetime,x,y,times,unik,start_fire)
Code 2 – Function M File – fire_condition.m
function [start_fire]=fire_condition(hn) [x,y,x1,y1,row,col,bp]=placing_sensors(hn); [r c]=size(x); dh=sqrt((x(1,1)-x(1,c))^2 + (y(1,1)-y(1,c))^2); dv=sqrt((x(1,1)-x(r,1))^2 + (y(1,1)-y(r,1))^2); start_fire=[((dh/2)+x(1,1)) ((dv/2)+4)]; plot(start_fire(1),start_fire(2),'ko') div=row/col; if (start_fire(2)-y(1,1))<(start_fire(1)-x(1,1)) ii=1; ij=1; while ii<(start_fire(2)-y(1,1)) || ij<(start_fire(2)-y(1,1)) ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); pause(0.3) ii=ii+1; ij=ii*div; end elseif (start_fire(2)-y(1,1))>(start_fire(1)-x(1,1)) ii=1; ij=1; while ii<(start_fire(1)-x(1,1)) || ij<(start_fire(1)-x(1,1)) ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); pause(0.3) ii=ii+1; ij=ii*div; end end end
Code 3 – Function M File – placing_sensors.m
function [x,y,x1,y1,row,col,bp]=placing_sensors(hn) col=5*ceil(hn/30); %0-30hn=5col, 30-60hn=10col... row=ceil(hn/col); rectangle('Position',[0 ((row*4)+6) 5 4],'Facecolor','r') text(1,((row*4)+8),'BASE') hold on [x y]=meshgrid(linspace(1,(col*4),col),linspace(4,(row*4),row)); plot(x,y,'go','LineWidth',5) axis([-5 ((col*4)+5) 0 ((row*4)+10)]) bp=[5 ((4*row)+6)]; % base station reciever point a=x(1,:); b=y(end,:); for i=1:length(a) plot([a(i) bp(1)],[b(i) bp(2)],'LineWidth',2); end % difference=(row*col)-hn; % if difference~=0 % for i=1:difference % plot(x(1,end-(i-1)) , y(1,end-(i-1)) , 'wo','LineWidth',5) % end % end % clear difference %if mod(hn,col)==0 % network when number of head nodes is a multiple of col [r c]=size(x); a1=x(1,:); b1=x(r,:); c1=y(1,:); d1=y(r,:); a2=x(:,1); b2=x(:,c); c2=y(:,1); d2=y(:,c); for i=1:length(a1) m1=[a1(i) b1(i)]; n1=[c1(i) d1(i)]; plot(m1,n1,'LineWidth',2) end for i=1:length(a2) m2=[a2(i) b2(i)]; n2=[c2(i) d2(i)]; plot(m2,n2,'LineWidth',2) end % else % network when number of head nodes is not a multiple of col % [r c]=size(x); % a1=x(r,:); % b1=x(2,:); % c1=y(r,:); % d1=y(2,:); % % a2=x(r:-1:2,1); % b2=x(r:-1:2,c); % c2=y(r:-1:2,1); % d2=y(r:-1:2,c); % % for i=1:length(a1) % m1=[a1(i) b1(i)]; % n1=[c1(i) d1(i)]; % plot(m1,n1,'LineWidth',2) % end % % for i=1:length(a2) % m2=[a2(i) b2(i)]; % n2=[c2(i) d2(i)]; % plot(m2,n2,'LineWidth',2) % end % % difference=hn-(col*(row-1)); % plot([x(1,1) x(1,difference)],[y(1,1) y(1,difference)],'LineWidth',2) % for i=1:difference % plot([x(1,i) x(2,i)],[y(1,i) y(2,i)],'LineWidth',2); % end % end clear difference r c dh=sqrt((x(1,1)-x(1,2))^2+((y(1,1)-y(1,2))^2)); % horizontal distance between two head nodes dv=sqrt((x(1,1)-x(2,1))^2+((y(1,1)-y(2,1))^2)); % vertical distance between two head nodes [x1 y1]=meshgrid(((x(1,1)-(dh/4)):dh/2:(x(1,end)+(dh/4))),((y(1,1)-(dv/4)):dv/2:(y(end,1)+(dv/2)))); plot(x1,y1,'g*') [r c]=size(x1); difference=(r*c)-(hn*4); % if ~isempty(difference) % d=difference/2; % for i=0:d-1 % plot(x1(1,c-i),y1(1,c-i),'w*') % plot(x1(2,c-i),y1(2,c-i),'w*') % end % end for i=1:row column=col; % if i==1 && mod(hn,col)~=0 % column=hn-((row-1)*col); % end for j=1:column plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]) plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]) plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]) end end end
Code 4 – Function M File – fire_detection3.m
function [axis,time,burntnodes,basetime,times,unik]=fire_detection3(hn,bp,x,y,x1,y1,row,col) %[x,y,x1,y1,row,col,bp]=placing_sensors(hn); %figure(4) [r c]=size(x); [r1 c1]=size(x1); dh=sqrt((x(1,1)-x(1,c))^2 + (y(1,1)-y(1,c))^2); %horizontal distance dv=sqrt((x(1,1)-x(r,1))^2 + (y(1,1)-y(r,1))^2); %vertical distance start_fire=[((dh/2)+x(1,1)) ((dv/2)+4)]; %origin of fire %plot(start_fire(1),start_fire(2),'ko') div=row/col; time=0; %time in sec for the fire to reach at the edge of forest axis=[]; %values of axis of ellipse from the start point to the boundry of forest burntnodes=[]; % number of burnt nodes basetime=[]; times=[]; %time for each ellipse unik=[]; %number of nodes burnt if (start_fire(2)-y(1,1))<(start_fire(1)-x(1,1)) %vertical distance < horizontal distance ii=1; %horizontal axis ij=1; %vertical axis deadnodeset_b=[]; deadnodeset_a=[]; n=0; X1=x; Y1=y; while ii<=(start_fire(2)-y(1,1)) || ij<=(start_fire(2)-y(1,1)) % detect vertical radius first, and then horizontal % subplot(1,2,1) ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset_b=deadnodeset_a; %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset=dead_nodes(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij,div); % to detect and mark the dead nodes deadnodeset_a=deadnodeset; unik_deadnodes=checkdeadnode2(deadnodeset_a,deadnodeset_b); % to delete the dead connections % flowcontrol2(unik_deadnodes,deadnodeset_a,hn,deadnodeset_b) [X,Y]=bully3(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1); X1=X; Y1=Y; %flowinfo1(row,col,hn,x,y,deadnodeset_a,ra) %checkdeadnode1(deadnodeset,x,y,x1,y1,bp) % subplot(1,2,2) % ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % [x,y,x1,y1,row,col,bp]=placing_sensors(hn); % % deadnodeset_b=deadnodeset_a; % %deadnodeset1=dead_nodes1(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij); % to detect and mark the dead nodes % %deadnodeset_a=deadnodeset; % %checkdeadnode(deadnodeset1,x,y,x1,y1,bp) % checkdeadnode(deadnodeset,x,y,x1,y1,bp,unik_deadnodes) pause(0.3) ii=ii+1; ij=ii*div; time=time+1; axis=[axis; ii ij]; [ra ca]=size(deadnodeset); burntnodes=[burntnodes ra]; [raa caa]=size(unik_deadnodes); if ~isequal(raa,0) unik=[unik raa]; times=[times; round(clock)]; end n=n+ii; basetime=[basetime n]; end elseif (start_fire(2)-y(1,1))>(start_fire(1)-x(1,1)) %vertical distance > horizontal distance ii=1; %horizontal axis ij=1; %vertical axis deadnodeset_b=[]; deadnodeset_a=[]; n=0; X1=x; Y1=y; while ii<=(start_fire(1)-x(1,1)) || ij<=(start_fire(1)-x(1,1)) % detect horizontal radius first, and then vertical % subplot(1,2,1) ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset_b=deadnodeset_a; %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset=dead_nodes(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij,div); % to detect and mark the dead nodes deadnodeset_a=deadnodeset; unik_deadnodes=checkdeadnode2(deadnodeset_a,deadnodeset_b); % to delete the dead connections %flowcontrol2(unik_deadnodes,deadnodeset_a,hn,deadnodeset_b) [X,Y]=bully3(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1); X1=X; Y1=Y; % subplot(1,2,2) % ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % [x,y,x1,y1,row,col,bp]=placing_sensors(hn); % % deadnodeset_b=deadnodeset_a; % %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % %deadnodeset1=dead_nodes1(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij); % to detect and mark the dead nodes % %deadnodeset_a=deadnodeset; % % checkdeadnode(deadnodeset1,x,y,x1,y1,bp) % checkdeadnode(deadnodeset,x,y,x1,y1,bp,unik_deadnodes) pause(0.3) ii=ii+1; ij=ii*div; time=time+1; axis=[axis; ii ij]; [ra ca]=size(deadnodeset); burntnodes=[burntnodes ra]; [raa caa]=size(unik_deadnodes); if ~isequal(raa,0) unik=[unik raa]; times=[times; round(clock) ]; end n=n+ii; basetime=[basetime n]; end end end
Code 5 – Function M File –bully3.m
function [X,Y]=bully3(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1) bars=0; %t=0; while bars>=0 subplot(1,2,1) bar(bars) axis([0 3 0 110]) grid on ylabel('Temperature') set(gca,'XTick',[]) bars=bars+randi(10,1,1); %bars=bars+15; subplot(1,2,2) rectangle('Position',[0 ((row*4)+6) 5 4],'Facecolor','r') text(1,((row*4)+8),'BASE') hold on cp=[5 ((row*4)+6)]; % coloring_b(X1,Y1,row,col,x,y,x1,y1) plot(x,y,'go','LineWidth',5) plot(x1,y1,'g*') set(gca,'XTick',[]) set(gca,'YTick',[]) [r c]=size(deadnodeset); for i=1:r plot(deadnodeset(i,1),deadnodeset(i,2),'ko','LineWidth',3) end [ra ca]=size(unik_deadnodes); for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'ro','LineWidth',3) plot([unik_deadnodes(i,1) cp(1)],[unik_deadnodes(i,2) cp(2)],'r') end pause(0.5) for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'yo','LineWidth',3) plot([unik_deadnodes(i,1) cp(1)],[unik_deadnodes(i,2) cp(2)],'y') end pause(0.5) if bars>=90 %bars=1; break end end for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'ko','LineWidth',3) plot([unik_deadnodes(i,1) cp(1)],[unik_deadnodes(i,2) cp(2)],'w') end [r c]=size(X1); for i=1:r for j=1:c if X1(i,j)==x(i,j) && Y1(i,j)==y(i,j) plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))],'w') plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))],'w') plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))],'w') plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))],'w') elseif X1(i,j)~=0 && Y1(i,j)~=0 plot([X1(i,j) x1(((2*i)-1),((2*j)-1))],[Y1(i,j) y1(((2*i)-1),((2*j)-1))],'w') plot([X1(i,j) x1(((2*i)-1),(2*j))],[Y1(i,j) y1(((2*i)-1),(2*j))],'w') plot([X1(i,j) x1((2*i),((2*j)-1))],[Y1(i,j) y1((2*i),((2*j)-1))],'w') plot([X1(i,j) x1((2*i),(2*j))],[Y1(i,j) y1((2*i),(2*j))],'w') end end end [rr cc]=size(x); [r3 c3]=size(deadnodeset); X=x; Y=y; for i=1:rr for j=1:cc for k=1:r3 if x(i,j)==deadnodeset(k,1) && y(i,j)==deadnodeset(k,2) a1=x1(((2*i)-1),((2*j)-1)); a2=y1(((2*i)-1),((2*j)-1)); b1=x1(((2*i)-1),(2*j)); b2=y1(((2*i)-1),(2*j)); c1=x1((2*i),((2*j)-1)); c2=y1((2*i),((2*j)-1)); d1=x1((2*i),(2*j)); d2=y1((2*i),(2*j)); a=[a1 a2]; b=[b1 b2]; c=[c1 c2]; d=[d1 d2]; for l=1:r3 if a(1)==deadnodeset(l,1) && a(2)==deadnodeset(l,2) a=[]; break else X(i,j)=a(1); %a becomes the new head Y(i,j)=a(2); end end if isempty(a) for l=1:r3 if b(1)==deadnodeset(l,1) && b(2)==deadnodeset(l,2) b=[]; break else X(i,j)=b(1); %b becomes the new head Y(i,j)=b(2); end end end if isempty(b) for l=1:r3 if c(1)==deadnodeset(l,1) && c(2)==deadnodeset(l,2) c=[]; break else X(i,j)=c(1); %c becomes the new head Y(i,j)=c(2); end end end if isempty(c) for l=1:r3 if d(1)==deadnodeset(l,1) && d(2)==deadnodeset(l,2) d=[]; break else X(i,j)=d(1); %d becomes the new head Y(i,j)=d(2); end end end if isempty(d) X(i,j)=0; %the whole cluster is burnt Y(i,j)=0; end end end end end % new head nodes obtained (up) for i=1:rr for j=1:cc xyz=0; if x(i,j)==X(i,j) && y(i,j)==Y(i,j) xyz=1; else xyz=0; break end end if xyz==0 break end end if xyz==1 for i=1:row for j=1:col plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]) plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]) plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]) end end end [r c]=size(X); for i=1:r for j=1:c if X(i,j)==x(i,j) && Y(i,j)==y(i,j) plot(X(i,j),Y(i,j),'go','LineWidth',5) for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) abc=plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) %delete(abc) % disp('br') plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) abc=plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) % delete(abc) % disp('br') plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) abc=plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) % delete(abc) % disp('br') plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),(2*j))) && ~isequal(deadnodeset(k,2),y1((2*i),(2*j))) abc=plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]); elseif isequal(deadnodeset(k,1),x1((2*i),(2*j))) && isequal(deadnodeset(k,2),y1((2*i),(2*j))) % delete(abc) % disp('br') plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))],'w') break end end clear k abc elseif X(i,j)~=0 && Y(i,j)~=0 plot(X(i,j),Y(i,j),'go','LineWidth',5) for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) abc=plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) % delete(abc) % disp('br') plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) abc=plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) % delete(abc) % disp('br') plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) abc=plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) % delete(abc) % disp('br') plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),(2*j))) && ~isequal(deadnodeset(k,2),y1((2*i),(2*j))) abc=plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))]); elseif isequal(deadnodeset(k,1),x1((2*i),(2*j))) && isequal(deadnodeset(k,2),y1((2*i),(2*j))) % delete(abc) % disp('br') plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))],'w') break end end end end end [r c]=size(X); for i=1:r for j=1:c if X(i,j)==x(i,j) && Y(i,j)==y(i,j) plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]) plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]) plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]) elseif X(i,j)~=0 && Y(i,j)~=0 plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))]) plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))]) plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))]) end end end %clear rr cc %coloring_w(X1,Y1,row,col,x,y,x1,y1) %coloring_c(X,Y,row,col,x,y,x1,y1) %pause end
Code 6 – Function M File –bully2.m
function [X,Y]=bully2(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1) [rr cc]=size(x); [r3 c3]=size(deadnodeset); X=x; Y=y; for i=1:rr for j=1:cc for k=1:r3 if x(i,j)==deadnodeset(k,1) && y(i,j)==deadnodeset(k,2) a1=x1(((2*i)-1),((2*j)-1)); a2=y1(((2*i)-1),((2*j)-1)); b1=x1(((2*i)-1),(2*j)); b2=y1(((2*i)-1),(2*j)); c1=x1((2*i),((2*j)-1)); c2=y1((2*i),((2*j)-1)); d1=x1((2*i),(2*j)); d2=y1((2*i),(2*j)); a=[a1 a2]; b=[b1 b2]; c=[c1 c2]; d=[d1 d2]; for l=1:r3 if a(1)==deadnodeset(l,1) && a(2)==deadnodeset(l,2) a=[]; break else X(i,j)=a(1); %a becomes the new head Y(i,j)=a(2); end end if isempty(a) for l=1:r3 if b(1)==deadnodeset(l,1) && b(2)==deadnodeset(l,2) b=[]; break else X(i,j)=b(1); %b becomes the new head Y(i,j)=b(2); end end end if isempty(b) for l=1:r3 if c(1)==deadnodeset(l,1) && c(2)==deadnodeset(l,2) c=[]; break else X(i,j)=c(1); %c becomes the new head Y(i,j)=c(2); end end end if isempty(c) for l=1:r3 if d(1)==deadnodeset(l,1) && d(2)==deadnodeset(l,2) d=[]; break else X(i,j)=d(1); %d becomes the new head Y(i,j)=d(2); end end end if isempty(d) X(i,j)=0; %the whole cluster is burnt Y(i,j)=0; end end end end end % new head nodes obtained (up) for i=1:rr for j=1:cc xyz=0; if x(i,j)==X(i,j) && y(i,j)==Y(i,j) xyz=1; else xyz=0; break end end if xyz==0 break end end if xyz==1 for i=1:row for j=1:col plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]) plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]) plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]) end end end [r c]=size(X); for i=1:r for j=1:c if X(i,j)==x(i,j) && Y(i,j)==y(i,j) plot(X(i,j),Y(i,j),'go','LineWidth',5) for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) abc=plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) %delete(abc) % disp('br') plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) abc=plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) % delete(abc) % disp('br') plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) abc=plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) % delete(abc) % disp('br') plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),(2*j))) && ~isequal(deadnodeset(k,2),y1((2*i),(2*j))) abc=plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]); elseif isequal(deadnodeset(k,1),x1((2*i),(2*j))) && isequal(deadnodeset(k,2),y1((2*i),(2*j))) % delete(abc) % disp('br') plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))],'w') break end end clear k abc elseif X(i,j)~=0 && Y(i,j)~=0 plot(X(i,j),Y(i,j),'go','LineWidth',5) for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) abc=plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) % delete(abc) % disp('br') plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) abc=plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) % delete(abc) % disp('br') plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) abc=plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) % delete(abc) % disp('br') plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),(2*j))) && ~isequal(deadnodeset(k,2),y1((2*i),(2*j))) abc=plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))]); elseif isequal(deadnodeset(k,1),x1((2*i),(2*j))) && isequal(deadnodeset(k,2),y1((2*i),(2*j))) % delete(abc) % disp('br') plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))],'w') break end end end end end [r c]=size(X); for i=1:r for j=1:c if X(i,j)==x(i,j) && Y(i,j)==y(i,j) plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]) plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]) plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]) elseif X(i,j)~=0 && Y(i,j)~=0 plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))]) plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))]) plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))]) end end end %pause end
Code 7 – Function M File – firedetection2.m
%function [axis,time,burntnodes,basetime]=firedetection2(hn,bp,x,y,x1,y1,row,col) function firedetection2(hn,x,y,x1,y1,row,col) %[x,y,x1,y1,row,col,bp]=placing_sensors(hn); %figure(4) [r c]=size(x); [r1 c1]=size(x1); dh=sqrt((x(1,1)-x(1,c))^2 + (y(1,1)-y(1,c))^2); %horizontal distance dv=sqrt((x(1,1)-x(r,1))^2 + (y(1,1)-y(r,1))^2); %vertical distance start_fire=[((dh/2)+x(1,1)) ((dv/2)+4)]; %origin of fire %plot(start_fire(1),start_fire(2),'ko') div=row/col; % time=0; %time in sec for the fire to reach at the edge of forest % axis=[]; %values of axis of ellipse from the start point to the boundry of forest % burntnodes=[]; % number of burnt nodes % basetime=[]; if (start_fire(2)-y(1,1))<(start_fire(1)-x(1,1)) %vertical distance < horizontal distance ii=1; %horizontal axis ij=1; %vertical axis deadnodeset_b=[]; deadnodeset_a=[]; % n=0; X1=x; Y1=y; while ii<=(start_fire(2)-y(1,1)) || ij<=(start_fire(2)-y(1,1)) % detect vertical radius first, and then horizontal % subplot(1,2,1) ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset_b=deadnodeset_a; %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset=dead_nodes(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij,div); % to detect and mark the dead nodes deadnodeset_a=deadnodeset; unik_deadnodes=checkdeadnode2(deadnodeset_a,deadnodeset_b); % to delete the dead connections [X,Y]=scene2(deadnodeset,unik_deadnodes,x,y,x1,y1,row,col,X1,Y1,hn); % flowcontrol2(unik_deadnodes,deadnodeset_a,hn,deadnodeset_b) % [X,Y]=bully(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1); X1=X; Y1=Y; %flowinfo1(row,col,hn,x,y,deadnodeset_a,ra) %checkdeadnode1(deadnodeset,x,y,x1,y1,bp) % subplot(1,2,2) % ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % [x,y,x1,y1,row,col,bp]=placing_sensors(hn); % % deadnodeset_b=deadnodeset_a; % %deadnodeset1=dead_nodes1(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij); % to detect and mark the dead nodes % %deadnodeset_a=deadnodeset; % %checkdeadnode(deadnodeset1,x,y,x1,y1,bp) % checkdeadnode(deadnodeset,x,y,x1,y1,bp,unik_deadnodes) pause(0.3) ii=ii+1; ij=ii*div; % time=time+1; % axis=[axis; ii ij]; % [ra ca]=size(deadnodeset); % burntnodes=[burntnodes ra]; % n=n+ii; % basetime=[basetime n]; end elseif (start_fire(2)-y(1,1))>(start_fire(1)-x(1,1)) %vertical distance > horizontal distance ii=1; %horizontal axis ij=1; %vertical axis deadnodeset_b=[]; deadnodeset_a=[]; % n=0; X1=x; Y1=y; while ii<=(start_fire(1)-x(1,1)) || ij<=(start_fire(1)-x(1,1)) % detect horizontal radius first, and then vertical % subplot(1,2,1) ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset_b=deadnodeset_a; %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset=dead_nodes(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij,div); % to detect and mark the dead nodes deadnodeset_a=deadnodeset; unik_deadnodes=checkdeadnode2(deadnodeset_a,deadnodeset_b); % to delete the dead connections [X,Y]=scene2(deadnodeset,unik_deadnodes,x,y,x1,y1,row,col,X1,Y1,hn); % %flowcontrol2(unik_deadnodes,deadnodeset_a,hn,deadnodeset_b) % [X,Y]=bully(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1); X1=X; Y1=Y; % subplot(1,2,2) % ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % [x,y,x1,y1,row,col,bp]=placing_sensors(hn); % % deadnodeset_b=deadnodeset_a; % %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % %deadnodeset1=dead_nodes1(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij); % to detect and mark the dead nodes % %deadnodeset_a=deadnodeset; % % checkdeadnode(deadnodeset1,x,y,x1,y1,bp) % checkdeadnode(deadnodeset,x,y,x1,y1,bp,unik_deadnodes) pause(0.3) ii=ii+1; ij=ii*div; % time=time+1; % axis=[axis; ii ij]; % [ra ca]=size(deadnodeset); % burntnodes=[burntnodes ra]; % n=n+ii; % basetime=[basetime n]; end end end
Code 8 – Function M File –scene2.m
function [X,Y]=scene2(deadnodeset,unik_deadnodes,x,y,x1,y1,row,col,X1,Y1,hn) bars=0; while bars>=0 subplot(1,2,1) bar(bars) axis([0 3 0 110]) grid on ylabel('Temperature') set(gca,'XTick',[]) bars=bars+randi(10,1,1); subplot(1,2,2) rectangle('Position',[0 ((row*4)+6) 5 4],'Facecolor','r') text(1,((row*4)+8),'BASE') hold on cp=[5 ((row*4)+6)]; % connectiong point of the base station plot(x,y,'go','LineWidth',5) plot(x1,y1,'g*') [r c]=size(deadnodeset); for i=1:r plot(deadnodeset(i,1),deadnodeset(i,2),'ko','LineWidth',5) end set(gca,'XTick',[]) set(gca,'YTick',[]) [X,Y]=bully2(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1); [ra ca]=size(unik_deadnodes); for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'ro','LineWidth',3) plot([unik_deadnodes(i,1) cp(1)],[unik_deadnodes(i,2) cp(2)],'c'); end pause(0.5) for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'yo','LineWidth',3) plot([unik_deadnodes(i,1) cp(1)],[unik_deadnodes(i,2) cp(2)],'c'); end pause(0.5) if bars>=90 break end end for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'ko','LineWidth',3) plot([unik_deadnodes(i,1) cp(1)],[unik_deadnodes(i,2) cp(2)],'w') end
Code 9 – Function M File –coloring_b.m
function coloring_b(X,Y,row,col,x,y,x1,y1) %coloring blue [rr cc]=size(X); for i=1:rr a=X(i,:); b=Y(i,:); nn1=[]; nn2=[]; for j=1:length(a) if a(j)==0 nn1=[nn1 j]; end if b(j)==0 nn2=[nn2 j]; end end a(nn1)=[]; b(nn2)=[]; for k=1:length(a)-1 a1=a(k); a2=b(k); b1=a(k+1); b2=b(k+1); plot([a1 b1],[a2 b2],'b','LineWidth',2) %horizontal end %pause(0.3) if ~isequal(i,rr) c=X(i+1,:); d=Y(i+1,:); c(nn1)=[]; d(nn2)=[]; for k=1:length(a) a1=a(k); a2=b(k); b1=c(k); b2=d(k); if ~isequal(b1,0) || ~isequal(b2,0) plot([a1 b1],[a2 b2],'b','LineWidth',2) %vertical end end end if isequal(i,rr) for k=1:length(a) plot([a(k) 5],[b(k) ((row*4)+6)],'b','LineWidth',2) end end end [r c]=size(X); for i=1:r for j=1:c if X(i,j)==x(i,j) && Y(i,j)==y(i,j) plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]) plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]) plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]) elseif X(i,j)~=0 && Y(i,j)~=0 plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))]) plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))]) plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))]) end end end
Code 10 – Function M File – bully.m
function [X,Y]=bully(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1) bars=0; while bars>=0 subplot(1,2,1) bar(bars) axis([0 3 0 110]) grid on ylabel('Temperature') set(gca,'XTick',[]) bars=bars+10; subplot(1,2,2) rectangle('Position',[0 ((row*4)+6) 5 4],'Facecolor','r') text(1,((row*4)+8),'BASE') hold on coloring_b(X1,Y1,row,col,x,y,x1,y1) plot(x,y,'go','LineWidth',5) plot(x1,y1,'g*') set(gca,'XTick',[]) set(gca,'YTick',[]) [r c]=size(deadnodeset); for i=1:r plot(deadnodeset(i,1),deadnodeset(i,2),'ko','LineWidth',3) end [ra ca]=size(unik_deadnodes); for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'ro','LineWidth',3) end pause(0.5) for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'yo','LineWidth',3) end pause(0.5) if bars>=90 %bars=1; break end end for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'ko','LineWidth',3) end [rr cc]=size(x); [r3 c3]=size(deadnodeset); X=x; Y=y; for i=1:rr for j=1:cc for k=1:r3 if x(i,j)==deadnodeset(k,1) && y(i,j)==deadnodeset(k,2) a1=x1(((2*i)-1),((2*j)-1)); a2=y1(((2*i)-1),((2*j)-1)); b1=x1(((2*i)-1),(2*j)); b2=y1(((2*i)-1),(2*j)); c1=x1((2*i),((2*j)-1)); c2=y1((2*i),((2*j)-1)); d1=x1((2*i),(2*j)); d2=y1((2*i),(2*j)); a=[a1 a2]; b=[b1 b2]; c=[c1 c2]; d=[d1 d2]; for l=1:r3 if a(1)==deadnodeset(l,1) && a(2)==deadnodeset(l,2) a=[]; break else X(i,j)=a(1); %a becomes the new head Y(i,j)=a(2); end end if isempty(a) for l=1:r3 if b(1)==deadnodeset(l,1) && b(2)==deadnodeset(l,2) b=[]; break else X(i,j)=b(1); %b becomes the new head Y(i,j)=b(2); end end end if isempty(b) for l=1:r3 if c(1)==deadnodeset(l,1) && c(2)==deadnodeset(l,2) c=[]; break else X(i,j)=c(1); %c becomes the new head Y(i,j)=c(2); end end end if isempty(c) for l=1:r3 if d(1)==deadnodeset(l,1) && d(2)==deadnodeset(l,2) d=[]; break else X(i,j)=d(1); %d becomes the new head Y(i,j)=d(2); end end end if isempty(d) X(i,j)=0; %the whole cluster is burnt Y(i,j)=0; end end end end end % new head nodes obtained (up) for i=1:rr for j=1:cc xyz=0; if x(i,j)==X(i,j) && y(i,j)==Y(i,j) xyz=1; else xyz=0; break end end if xyz==0 break end end if xyz==1 for i=1:row for j=1:col plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]) plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]) plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]) end end end [r c]=size(X); for i=1:r for j=1:c if X(i,j)==x(i,j) && Y(i,j)==y(i,j) plot(X(i,j),Y(i,j),'go','LineWidth',5) for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) abc=plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) %delete(abc) % disp('br') plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) abc=plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) % delete(abc) % disp('br') plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) abc=plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) % delete(abc) % disp('br') plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),(2*j))) && ~isequal(deadnodeset(k,2),y1((2*i),(2*j))) abc=plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]); elseif isequal(deadnodeset(k,1),x1((2*i),(2*j))) && isequal(deadnodeset(k,2),y1((2*i),(2*j))) % delete(abc) % disp('br') plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))],'w') break end end clear k abc elseif X(i,j)~=0 && Y(i,j)~=0 plot(X(i,j),Y(i,j),'go','LineWidth',5) for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) abc=plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),((2*j)-1))) && isequal(deadnodeset(k,2),y1(((2*i)-1),((2*j)-1))) % delete(abc) % disp('br') plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && ~isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) abc=plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))]); elseif isequal(deadnodeset(k,1),x1(((2*i)-1),(2*j))) && isequal(deadnodeset(k,2),y1(((2*i)-1),(2*j))) % delete(abc) % disp('br') plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && ~isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) abc=plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))]); elseif isequal(deadnodeset(k,1),x1((2*i),((2*j)-1))) && isequal(deadnodeset(k,2),y1((2*i),((2*j)-1))) % delete(abc) % disp('br') plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))],'w') break end end clear k abc for k=1:r3 if ~isequal(deadnodeset(k,1),x1((2*i),(2*j))) && ~isequal(deadnodeset(k,2),y1((2*i),(2*j))) abc=plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))]); elseif isequal(deadnodeset(k,1),x1((2*i),(2*j))) && isequal(deadnodeset(k,2),y1((2*i),(2*j))) % delete(abc) % disp('br') plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))],'w') break end end end end end %clear rr cc coloring_w(X1,Y1,row,col,x,y,x1,y1) coloring_c(X,Y,row,col,x,y,x1,y1) %pause end
Code 11 – Function M File – fire_detection.m
function [axis,time,burntnodes,basetime]=fire_detection(hn,bp,x,y,x1,y1,row,col) %[x,y,x1,y1,row,col,bp]=placing_sensors(hn); %figure(4) [r c]=size(x); [r1 c1]=size(x1); dh=sqrt((x(1,1)-x(1,c))^2 + (y(1,1)-y(1,c))^2); %horizontal distance dv=sqrt((x(1,1)-x(r,1))^2 + (y(1,1)-y(r,1))^2); %vertical distance start_fire=[((dh/2)+x(1,1)) ((dv/2)+4)]; %origin of fire %plot(start_fire(1),start_fire(2),'ko') div=row/col; time=0; %time in sec for the fire to reach at the edge of forest axis=[]; %values of axis of ellipse from the start point to the boundry of forest burntnodes=[]; % number of burnt nodes basetime=[]; if (start_fire(2)-y(1,1))<(start_fire(1)-x(1,1)) %vertical distance < horizontal distance ii=1; %horizontal axis ij=1; %vertical axis deadnodeset_b=[]; deadnodeset_a=[]; n=0; X1=x; Y1=y; while ii<=(start_fire(2)-y(1,1)) || ij<=(start_fire(2)-y(1,1)) % detect vertical radius first, and then horizontal % subplot(1,2,1) ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset_b=deadnodeset_a; %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset=dead_nodes(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij,div); % to detect and mark the dead nodes deadnodeset_a=deadnodeset; unik_deadnodes=checkdeadnode2(deadnodeset_a,deadnodeset_b); % to delete the dead connections % flowcontrol2(unik_deadnodes,deadnodeset_a,hn,deadnodeset_b) [X,Y]=bully(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1); X1=X; Y1=Y; %flowinfo1(row,col,hn,x,y,deadnodeset_a,ra) %checkdeadnode1(deadnodeset,x,y,x1,y1,bp) % subplot(1,2,2) % ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % [x,y,x1,y1,row,col,bp]=placing_sensors(hn); % % deadnodeset_b=deadnodeset_a; % %deadnodeset1=dead_nodes1(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij); % to detect and mark the dead nodes % %deadnodeset_a=deadnodeset; % %checkdeadnode(deadnodeset1,x,y,x1,y1,bp) % checkdeadnode(deadnodeset,x,y,x1,y1,bp,unik_deadnodes) pause(0.3) ii=ii+1; ij=ii*div; time=time+1; axis=[axis; ii ij]; [ra ca]=size(deadnodeset); burntnodes=[burntnodes ra]; n=n+ii; basetime=[basetime n]; end elseif (start_fire(2)-y(1,1))>(start_fire(1)-x(1,1)) %vertical distance > horizontal distance ii=1; %horizontal axis ij=1; %vertical axis deadnodeset_b=[]; deadnodeset_a=[]; n=0; X1=x; Y1=y; while ii<=(start_fire(1)-x(1,1)) || ij<=(start_fire(1)-x(1,1)) % detect horizontal radius first, and then vertical % subplot(1,2,1) ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset_b=deadnodeset_a; %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); deadnodeset=dead_nodes(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij,div); % to detect and mark the dead nodes deadnodeset_a=deadnodeset; unik_deadnodes=checkdeadnode2(deadnodeset_a,deadnodeset_b); % to delete the dead connections %flowcontrol2(unik_deadnodes,deadnodeset_a,hn,deadnodeset_b) [X,Y]=bully(deadnodeset,x,y,x1,y1,hn,unik_deadnodes,row,col,X1,Y1); X1=X; Y1=Y; % subplot(1,2,2) % ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % [x,y,x1,y1,row,col,bp]=placing_sensors(hn); % % deadnodeset_b=deadnodeset_a; % %ellipse((ii),(ij),0,start_fire(1),start_fire(2),100); % %deadnodeset1=dead_nodes1(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij); % to detect and mark the dead nodes % %deadnodeset_a=deadnodeset; % % checkdeadnode(deadnodeset1,x,y,x1,y1,bp) % checkdeadnode(deadnodeset,x,y,x1,y1,bp,unik_deadnodes) pause(0.3) ii=ii+1; ij=ii*div; time=time+1; axis=[axis; ii ij]; [ra ca]=size(deadnodeset); burntnodes=[burntnodes ra]; n=n+ii; basetime=[basetime n]; end end end
Code 12 – Function M File – coloring_w.m
function coloring_w(X,Y,row,col,x,y,x1,y1) %coloring blue [rr cc]=size(X); for i=1:rr a=X(i,:); b=Y(i,:); nn1=[]; nn2=[]; for j=1:length(a) if a(j)==0 nn1=[nn1 j]; end if b(j)==0 nn2=[nn2 j]; end end a(nn1)=[]; b(nn2)=[]; for k=1:length(a)-1 a1=a(k); a2=b(k); b1=a(k+1); b2=b(k+1); plot([a1 b1],[a2 b2],'w','LineWidth',2) %horizontal white end %pause(0.3) if ~isequal(i,rr) c=X(i+1,:); d=Y(i+1,:); c(nn1)=[]; d(nn2)=[]; for k=1:length(a) a1=a(k); a2=b(k); b1=c(k); b2=d(k); if ~isequal(b1,0) || ~isequal(b2,0) plot([a1 b1],[a2 b2],'w','LineWidth',2) %vertical white end end end if isequal(i,rr) for k=1:length(a) plot([a(k) 5],[b(k) ((row*4)+6)],'w','LineWidth',2) end end end [r c]=size(X); for i=1:r for j=1:c if X(i,j)==x(i,j) && Y(i,j)==y(i,j) plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))],'w') plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))],'w') plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))],'w') plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))],'w') elseif X(i,j)~=0 && Y(i,j)~=0 plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))],'w') plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))],'w') plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))],'w') plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))],'w') end end end
Code 13 – Function M File – coloring_c.m
function coloring_c(X,Y,row,col,x,y,x1,y1) %coloring blue [rr cc]=size(X); for i=1:rr a=X(i,:); b=Y(i,:); nn1=[]; nn2=[]; for j=1:length(a) if a(j)==0 nn1=[nn1 j]; end if b(j)==0 nn2=[nn2 j]; end end a(nn1)=[]; b(nn2)=[]; for k=1:length(a)-1 a1=a(k); a2=b(k); b1=a(k+1); b2=b(k+1); plot([a1 b1],[a2 b2],'c','LineWidth',2) %horizontal white end pause(0.3) if ~isequal(i,rr) c=X(i+1,:); d=Y(i+1,:); c(nn1)=[]; d(nn2)=[]; for k=1:length(a) a1=a(k); a2=b(k); b1=c(k); b2=d(k); if ~isequal(b1,0) || ~isequal(b2,0) plot([a1 b1],[a2 b2],'c','LineWidth',2) %vertical white end end end pause(0.3) if isequal(i,rr) for k=1:length(a) plot([a(k) 5],[b(k) ((row*4)+6)],'c','LineWidth',2) end end end [r c]=size(X); for i=1:r for j=1:c if X(i,j)==x(i,j) && Y(i,j)==y(i,j) plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))]) plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))]) plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))]) elseif X(i,j)~=0 && Y(i,j)~=0 plot([X(i,j) x1(((2*i)-1),((2*j)-1))],[Y(i,j) y1(((2*i)-1),((2*j)-1))]) plot([X(i,j) x1(((2*i)-1),(2*j))],[Y(i,j) y1(((2*i)-1),(2*j))]) plot([X(i,j) x1((2*i),((2*j)-1))],[Y(i,j) y1((2*i),((2*j)-1))]) plot([X(i,j) x1((2*i),(2*j))],[Y(i,j) y1((2*i),(2*j))]) end end end
Code 14 – Function M File – normal_condition.m
function normal_condition(hn) [x,y,x1,y1,row,col,bp]=placing_sensors(hn); for i=1:row column=col; % if i==1 && mod(hn,col)~=0 % column=hn-((row-1)*col); % end a1=[x(i,1) x(i,column)]; b1=[y(i,1) y(i,column)]; abc=plot(a1,b1,'c','LineWidth',2); pause(0.3) if i==row break end a2=x(i,1:column); b2=y(i,1:column); a3=x(i+1,1:column); b3=y(i+1,1:column); for j=1:length(a2) plot([a2(j) a3(j)],[b2(j) b3(j)],'c','LineWidth',2) end pause(0.3) end a4=x(row,:); b4=y(row,:); for i=1:length(a4) plot([bp(1) a4(i)],[bp(2) b4(i)],'c','LineWidth',2) end end
Code 15 – Function M File –flowcontrol2.m
function flowcontrol2(unik_deadnodes,deadnodeset_a,hn,deadnodeset_b) %pause(0.3) %set(gca,'Color','w') % col=5*ceil(hn/30); %0-30hn=5col, 30-60hn=10col... % row=ceil(hn/col); % % rectangle('Position',[0 ((row*4)+6) 5 4],'Facecolor','r') % text(1,((row*4)+8),'BASE') % hold on % % plot(x,y,'go','LineWidth',5) % plot(x1,y1,'g*') % axis([-5 ((col*4)+5) 0 ((row*4)+10)]) % % bp=[5 ((4*row)+6)]; % base station's reciever point % a=x(1,:); % b=y(end,:); % for i=1:length(a) % plot([a(i) bp(1)],[b(i) bp(2)],'LineWidth',2); % end % % difference=(row*col)-hn; % if difference~=0 % for i=1:difference % plot(x(1,end-(i-1)) , y(1,end-(i-1)) , 'wo','LineWidth',5) % end % end % clear difference [x,y,x1,y1,row,col,bp]=placing_sensors(hn); % fresh=freshnodes(deadnodeset_a,deadnodeset_b); % [ra ca]=size(fresh); % for i=1:ra % plot(fresh(i,1),fresh(i,2),'ro','LineWidth',3) % end % pause(0.3) % for i=1:ra % plot(fresh(i,1),fresh(i,2),'yo','LineWidth',3) % end % pause(0.3) % for i=1:ra % plot(fresh(i,1),fresh(i,2),'ko','LineWidth',3) % end [ra ca]=size(unik_deadnodes); for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'ro','LineWidth',3) end pause(0.5) for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'yo','LineWidth',3) end pause(0.5) for i=1:ra plot(unik_deadnodes(i,1),unik_deadnodes(i,2),'ko','LineWidth',3) end % [r c]=size(unik_deadnodes); % for i=1:r % plot(unik_deadnodes(i,1),unik_deadnodes(1,2),'ko') % end for i=1:row column=col; if i==1 && mod(hn,col)~=0 column=hn-((row-1)*col); end a1=[x(i,1) x(i,column)]; b1=[y(i,1) y(i,column)]; abc=plot(a1,b1,'c','LineWidth',2); % dead=[]; % for j=1:column % for k=1:ra % if x(i,j)==deadnodeset_a(k,1) && y(i,j)==deadnodeset_a(k,2) % dead=[dead; x(i,j) y(i,j)]; % end % end % end % if ~isempty(dead) % plot([dead(1,1) dead(end,1)],[dead(1,2) dead(end,2)],'w','LineWidth',2) % end [r1 c1]=size(x); [r2 c2]=size(x1); [r3 c3]=size(deadnodeset_a); for ii=1:r1 for j=1:c1 for k=1:r3 if x(ii,j)==deadnodeset_a(k,1) && y(ii,j)==deadnodeset_a(k,2) if ii+1<=r1 plot([x(ii,j) x(ii+1,j)],[y(ii,j) y(ii+1,j)],'w','LineWidth',2) end if ii-1>=1 plot([x(ii,j) x(ii-1,j)],[y(ii,j) y(ii-1,j)],'w','LineWidth',2) end if j+1<=c1 plot([x(ii,j) x(ii,j+1)],[y(ii,j) y(ii,j+1)],'w','LineWidth',2) end if j-1>=1 plot([x(ii,j) x(ii,j-1)],[y(ii,j) y(ii,j-1)],'w','LineWidth',2) end if ii==r1 plot([bp(1) x(ii,j)],[bp(2) y(ii,j)],'w','LineWidth',2) end end end end end pause(0.3) if i==row break end a2=x(i,1:column); b2=y(i,1:column); a3=x(i+1,1:column); b3=y(i+1,1:column); for j=1:length(a2) plot([a2(j) a3(j)],[b2(j) b3(j)],'c','LineWidth',2) end pause(0.3) end a4=x(row,:); b4=y(row,:); for i=1:length(a4) plot([bp(1) a4(i)],[bp(2) b4(i)],'c','LineWidth',2) end [r1 c1]=size(deadnodeset_a); for i=1:r1 plot(deadnodeset_a(i,1),deadnodeset_a(i,2),'ko','LineWidth',3) end end
Code 16 – Function M File –ellipse.m
function [x,y] = ellipse(a,b,phi,x0,y0,n) n_dflt = 100; % Default for number of points if nargin < 6, n = n_dflt; end if nargin < 5, y0 = 0; end if nargin < 4, x0 = 0; end if nargin < 3, phi = 0; end if nargin < 2, b = 1; end if nargin < 1, a = 1; end th = linspace(0,2*pi,n+1); x = a*cos(th); y = b*sin(th); c = cos(phi); s = sin(phi); th = x*c-y*s+x0; y = x*s+y*c+y0; x = th; if nargout==0, plot(x,y,'r'); end end
Code 17 – Function M File –checkdeadnode.m
function checkdeadnode(deadnodeset,x,y,x1,y1,bp,unik_deadnodes) [r c]=size(x); [r1 c1]=size(x1); [r2 c2]=size(deadnodeset); % for i=1:r1 % for j=1:c1 % for k=1:r2 % if x1(i,j)==deadnodeset(k,1) && y1(i,j)==deadnodeset(k,2) % plot([x1(i,j) x(ceil(i/2),ceil(j/2))],[y1(i,j) y(ceil(i/2),ceil(j/2))],'w') % %plot(deadnodeset(k,1),deadnodeset(k,2),'ko','LineWidth',3) % %[ra ca]=size(deadnodeset); % % end % end % end % end [rr cc]=size(unik_deadnodes); for ii=1:rr plot(unik_deadnodes(ii,1),unik_deadnodes(ii,2),'ro','LineWidth',3) end pause(0.5) for ii=1:rr plot(unik_deadnodes(ii,1),unik_deadnodes(ii,2),'yo','LineWidth',3) end pause(0.5) for ii=1:rr plot(unik_deadnodes(ii,1),unik_deadnodes(ii,2),'ko','LineWidth',3) end for i=1:r for j=1:c for k=1:r2 if x(i,j)==deadnodeset(k,1) && y(i,j)==deadnodeset(k,2) plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))],'w') plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))],'w') plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))],'w') plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))],'w') if (x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1)) && (y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2)) && (x1((2*i)-1)~=deadnodeset(k,1)) && (y1(((2*i)-1),(2*j))~=deadnodeset(k,2)) && (x1((2*i),((2*j)-1))~=deadnodeset(k,1)) && (y1((2*i),((2*j)-1))~=deadnodeset(k,2)) && (x1((2*i),(2*j))~=deadnodeset(k,1)) && (y1((2*i),(2*j))~=deadnodeset(k,2)) % all four subnodes of the head are out of fire range. %plot(x1(((2*i)-1),((2*j)-1)),y1(((2*i)-1),((2*j)-1)),'go','LineWidth',5) plot([x1(((2*i)-1),((2*j)-1)) x1((2*i)-1)],[y1(((2*i)-1),((2*j)-1)) y1(((2*i)-1),(2*j))],'r') plot([x1(((2*i)-1),((2*j)-1)) x1((2*i),((2*j)-1))],[y1(((2*i)-1),((2*j)-1)) y1((2*i),((2*j)-1))],'r') plot([x1(((2*i)-1),((2*j)-1)) x1((2*i),(2*j))],[y1(((2*i)-1),((2*j)-1)) y1((2*i),(2*j))],'r') % a is head if i+1<=r && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i+1,j)],[y1(((2*i)-1),((2*j)-1)) y(i+1,j)],'b','LineWidth',2) end if i-1>=1 && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i-1,j)],[y1(((2*i)-1),((2*j)-1)) y(i-1,j)],'b','LineWidth',2) end if j+1<=c && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i,j+1)],[y1(((2*i)-1),((2*j)-1)) y(i,j+1)],'b','LineWidth',2) end if j-1>=1 && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i,j-1)],[y1(((2*i)-1),((2*j)-1)) y(i,j-1)],'b','LineWidth',2) end elseif (x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1)) && (y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2)) && (x1((2*i)-1)~=deadnodeset(k,1)) && (y1(((2*i)-1),(2*j))~=deadnodeset(k,2)) && (x1((2*i),((2*j)-1))~=deadnodeset(k,1)) && (y1((2*i),((2*j)-1))~=deadnodeset(k,2)) plot([x1(((2*i)-1),((2*j)-1)) x1((2*i)-1)],[y1(((2*i)-1),((2*j)-1)) y1(((2*i)-1),(2*j))],'r') plot([x1(((2*i)-1),((2*j)-1)) x1((2*i),((2*j)-1))],[y1(((2*i)-1),((2*j)-1)) y1((2*i),((2*j)-1))],'r') % a is head if i+1<=r && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i+1,j)],[y1(((2*i)-1),((2*j)-1)) y(i+1,j)],'b','LineWidth',2) end if i-1>=1 && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i-1,j)],[y1(((2*i)-1),((2*j)-1)) y(i-1,j)],'b','LineWidth',2) end if j+1<=c && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i,j+1)],[y1(((2*i)-1),((2*j)-1)) y(i,j+1)],'b','LineWidth',2) end if j-1>=1 && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i,j-1)],[y1(((2*i)-1),((2*j)-1)) y(i,j-1)],'b','LineWidth',2) end elseif (x1((2*i)-1)~=deadnodeset(k,1)) && (y1(((2*i)-1),(2*j))~=deadnodeset(k,2)) && (x1((2*i),((2*j)-1))~=deadnodeset(k,1)) && (y1((2*i),((2*j)-1))~=deadnodeset(k,2)) && (x1((2*i),(2*j))~=deadnodeset(k,1)) && (y1((2*i),(2*j))~=deadnodeset(k,2)) plot([x1((2*i)-1) x1(2*i)],[y1(((2*i)-1),(2*j)) y1((2*i),((2*j)-1))],'r') plot([x1((2*i)-1) x1((2*i),(2*j))],[y1(((2*i)-1),(2*j)) y1((2*i),(2*j))],'r') %b is head if i+1<=r && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i+1,j)],[y1(((2*i)-1),(2*j)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i-1,j)],[y1(((2*i)-1),(2*j)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i,j+1)],[y1(((2*i)-1),(2*j)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i,j-1)],[y1(((2*i)-1),(2*j)) y(i,j-1)],'b','LineWidth',3) end elseif (x1((2*i),((2*j)-1))~=deadnodeset(k,1)) && (y1((2*i),((2*j)-1))~=deadnodeset(k,2)) && (x1((2*i),(2*j))~=deadnodeset(k,1)) && (y1((2*i),(2*j))~=deadnodeset(k,2)) && (x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1)) && (y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2)) plot([x1((2*i),((2*j)-1)) x1((2*i),(2*j))],[y1((2*i),((2*j)-1)) y1((2*i),(2*j))],'r') plot([x1((2*i),((2*j)-1)) x1(((2*i)-1),((2*j)-1))],[y1((2*i),((2*j)-1)) y1(((2*i)-1),((2*j)-1))],'r') % c is head if i+1<=r && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i+1,j)],[y1((2*i),((2*j)-1)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i-1,j)],[y1((2*i),((2*j)-1)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i,j+1)],[y1((2*i),((2*j)-1)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i,j-1)],[y1((2*i),((2*j)-1)) y(i,j-1)],'b','LineWidth',3) end elseif (x1((2*i),(2*j))~=deadnodeset(k,1)) && (y1((2*i),(2*j))~=deadnodeset(k,2)) && (x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1)) && (y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2)) && (x1((2*i)-1)~=deadnodeset(k,1)) && (y1(((2*i)-1),(2*j))~=deadnodeset(k,2)) plot([x1((2*i),(2*j)) x1(((2*i)-1),((2*j)-1))],[y1((2*i),(2*j)) y1(((2*i)-1),((2*j)-1))],'r') plot([x1((2*i),(2*j)) x1((2*i)-1)],[y1((2*i),(2*j)) y1(((2*i)-1),(2*j))],'r') % d is head if i+1<=r && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i+1,j)],[y1((2*i),(2*j)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i-1,j)],[y1((2*i),(2*j)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i,j+1)],[y1((2*i),(2*j)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i,j-1)],[y1((2*i),(2*j)) y(i,j-1)],'b','LineWidth',3) end elseif (x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1)) && (y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2)) && (x1((2*i)-1)~=deadnodeset(k,1)) && (y1(((2*i)-1),(2*j))~=deadnodeset(k,2)) plot([x1(((2*i)-1),((2*j)-1)) x1((2*i)-1)],[y1(((2*i)-1),((2*j)-1)) y1(((2*i)-1),(2*j))],'r') % a is head if i+1<=r && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i+1,j)],[y1(((2*i)-1),((2*j)-1)) y(i+1,j)],'b','LineWidth',2) end if i-1>=1 && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i-1,j)],[y1(((2*i)-1),((2*j)-1)) y(i-1,j)],'b','LineWidth',2) end if j+1<=c && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i,j+1)],[y1(((2*i)-1),((2*j)-1)) y(i,j+1)],'b','LineWidth',2) end if j-1>=1 && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i,j-1)],[y1(((2*i)-1),((2*j)-1)) y(i,j-1)],'b','LineWidth',2) end elseif (x1((2*i)-1)~=deadnodeset(k,1)) && (y1(((2*i)-1),(2*j))~=deadnodeset(k,2)) && (x1((2*i),((2*j)-1))~=deadnodeset(k,1)) && (y1((2*i),((2*j)-1))~=deadnodeset(k,2)) plot([x1((2*i)-1) x1((2*i),((2*j)-1))],[y1(((2*i)-1),(2*j)) y1((2*i),((2*j)-1))],'r') %b is head if i+1<=r && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i+1,j)],[y1(((2*i)-1),(2*j)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i-1,j)],[y1(((2*i)-1),(2*j)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i,j+1)],[y1(((2*i)-1),(2*j)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i,j-1)],[y1(((2*i)-1),(2*j)) y(i,j-1)],'b','LineWidth',3) end elseif (x1((2*i),((2*j)-1))~=deadnodeset(k,1)) && (y1((2*i),((2*j)-1))~=deadnodeset(k,2)) && (x1((2*i),(2*j))~=deadnodeset(k,1)) && (y1((2*i),(2*j))~=deadnodeset(k,2)) plot([(x1((2*i),((2*j)-1))) x1((2*i),(2*j))],[y1((2*i),((2*j)-1)) y1((2*i),(2*j))],'r') % c is head if i+1<=r && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i+1,j)],[y1((2*i),((2*j)-1)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i-1,j)],[y1((2*i),((2*j)-1)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i,j+1)],[y1((2*i),((2*j)-1)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i,j-1)],[y1((2*i),((2*j)-1)) y(i,j-1)],'b','LineWidth',3) end elseif (x1((2*i),(2*j))~=deadnodeset(k,1)) && (y1((2*i),(2*j))~=deadnodeset(k,2)) && (x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1)) && (y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2)) plot([x1((2*i),(2*j)) x1(((2*i)-1),((2*j)-1))],[y1((2*i),(2*j)) y1(((2*i)-1),((2*j)-1))],'r') % d is head if i+1<=r && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i+1,j)],[y1((2*i),(2*j)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i-1,j)],[y1((2*i),(2*j)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i,j+1)],[y1((2*i),(2*j)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i,j-1)],[y1((2*i),(2*j)) y(i,j-1)],'b','LineWidth',3) end elseif (x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1)) && (y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2)) % a is head if i+1<=r && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i+1,j)],[y1(((2*i)-1),((2*j)-1)) y(i+1,j)],'b','LineWidth',2) end if i-1>=1 && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i-1,j)],[y1(((2*i)-1),((2*j)-1)) y(i-1,j)],'b','LineWidth',2) end if j+1<=c && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i,j+1)],[y1(((2*i)-1),((2*j)-1)) y(i,j+1)],'b','LineWidth',2) end if j-1>=1 && x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2) plot([x1(((2*i)-1),((2*j)-1)) x(i,j-1)],[y1(((2*i)-1),((2*j)-1)) y(i,j-1)],'b','LineWidth',2) end elseif (x1((2*i)-1)~=deadnodeset(k,1)) && (y1(((2*i)-1),(2*j))~=deadnodeset(k,2)) %b is head if i+1<=r && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i+1,j)],[y1(((2*i)-1),(2*j)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i-1,j)],[y1(((2*i)-1),(2*j)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i,j+1)],[y1(((2*i)-1),(2*j)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i)-1)~=deadnodeset(k,1) && y1(((2*i)-1),(2*j))~=deadnodeset(k,2) plot([x1((2*i)-1) x(i,j-1)],[y1(((2*i)-1),(2*j)) y(i,j-1)],'b','LineWidth',3) end elseif (x1((2*i),((2*j)-1))~=deadnodeset(k,1)) && (y1((2*i),((2*j)-1))~=deadnodeset(k,2)) % c is head if i+1<=r && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i+1,j)],[y1((2*i),((2*j)-1)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i-1,j)],[y1((2*i),((2*j)-1)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i,j+1)],[y1((2*i),((2*j)-1)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i),((2*j)-1))~=deadnodeset(k,1) && y1((2*i),((2*j)-1))~=deadnodeset(k,2) plot([x1((2*i),((2*j)-1)) x(i,j-1)],[y1((2*i),((2*j)-1)) y(i,j-1)],'b','LineWidth',3) end elseif (x1((2*i),(2*j))~=deadnodeset(k,1)) && (y1((2*i),(2*j))~=deadnodeset(k,2)) % d is head if i+1<=r && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i+1,j)],[y1((2*i),(2*j)) y(i+1,j)],'b','LineWidth',3) end if i-1>=1 && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i-1,j)],[y1((2*i),(2*j)) y(i-1,j)],'b','LineWidth',3) end if j+1<=c && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i,j+1)],[y1((2*i),(2*j)) y(i,j+1)],'b','LineWidth',3) end if j-1>=1 && x1((2*i),(2*j))~=deadnodeset(k,1) && y1((2*i),(2*j))~=deadnodeset(k,2) plot([x1((2*i),(2*j)) x(i,j-1)],[y1((2*i),(2*j)) y(i,j-1)],'b','LineWidth',3) end % a=(x1(((2*i)-1),((2*j)-1))~=deadnodeset(k,1)) && (y1(((2*i)-1),((2*j)-1))~=deadnodeset(k,2)) % b=(x1((2*i)-1)~=deadnodeset(k,1)) && (y1(((2*i)-1),(2*j))~=deadnodeset(k,2)) % c=(x1((2*i),((2*j)-1))~=deadnodeset(k,1)) && (y1((2*i),((2*j)-1))~=deadnodeset(k,2)) % d=(x1((2*i),(2*j))~=deadnodeset(k,1)) && (y1((2*i),(2*j))~=deadnodeset(k,2)) end if i+1<=r plot([x(i,j) x(i+1,j)],[y(i,j) y(i+1,j)],'w','LineWidth',3) end if i-1>=1 plot([x(i,j) x(i-1,j)],[y(i,j) y(i-1,j)],'w','LineWidth',3) end if j+1<=c plot([x(i,j) x(i,j+1)],[y(i,j) y(i,j+1)],'w','LineWidth',3) end if j-1>=1 plot([x(i,j) x(i,j-1)],[y(i,j) y(i,j-1)],'w','LineWidth',3) end if i==r plot([bp(1) x(i,j)],[bp(2) y(i,j)],'w','LineWidth',2) end plot(deadnodeset(k,1),deadnodeset(k,2),'ko','LineWidth',3) end end end end
Code 18 – Function M File –checkdeadnode2.m
function unik_deadnodes=checkdeadnode2(deadnodeset_a,deadnodeset_b) [ra ca]=size(deadnodeset_a); [rb cb]=size(deadnodeset_b); unik_deadnodes=deadnodeset_a; x=[]; % deadnodeset_a % deadnodeset_b for i=1:ra for j=1:rb if deadnodeset_b(j,1)==deadnodeset_a(i,1) && deadnodeset_b(j,2)==deadnodeset_a(i,2) x=[x i]; end end end unik_deadnodes(x,:)=[]; % is=[]; % for i=1:ra % for j=1:rb % if deadnodeset_b(j,1)==deadnodeset_a(i,1) && deadnodeset_b(j,2)==deadnodeset_a(i,2) % is=[is i]; % end % end % end % %is % if isempty(is) % unik_deadnodes=deadnodeset_a; % else % ind=1; % unik_deadnodes=[]; % for i=1:ra % if i<=length(is) % if i==is(ind) % ind=ind+1; % continue % end % end % unik_deadnodes=[unik_deadnodes; deadnodeset_a(i,1) deadnodeset_a(i,2)]; % end % end % [r1 c1]=size(x); % [r2 c2]=size(x1); % [r3 c3]=size(unik_deadnodes); % % for i=1:r1 % for j=1:c1 % for k=1:r3 % if x(i,j)==unik_deadnodes(k,1) && y(i,j)==unik_deadnodes(k,2) % if i+1<=r1 % plot([x(i,j) x(i+1,j)],[y(i,j) y(i+1,j)],'w','LineWidth',2) % end % if i-1>=1 % plot([x(i,j) x(i-1,j)],[y(i,j) y(i-1,j)],'w','LineWidth',2) % end % if j+1<=c1 % plot([x(i,j) x(i,j+1)],[y(i,j) y(i,j+1)],'w','LineWidth',2) % end % if j-1>=1 % plot([x(i,j) x(i,j-1)],[y(i,j) y(i,j-1)],'w','LineWidth',2) % end % % if i==r1 % plot([bp(1) x(i,j)],[bp(2) y(i,j)],'w','LineWidth',2) % end % end % end % end % end % % for i=1:r2 % for j=1:c2 % for k=1:r3 % if x1(i,j)==unik_deadnodes(k,1) && y1(i,j)==unik_deadnodes(k,2) % plot([x1(i,j) x(ceil(i/2),ceil(j/2))],[y1(i,j) y(ceil(i/2),ceil(j/2))],'w') % end % end % end % end % for i=1:ra % plot(deadnodeset_a(i,1),deadnodeset_a(i,2),'ko','LineWidth',3) % end end
Code 19 – Function M File –dead_nodes.m
function [deadnodeset]=dead_nodes(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij,div) deadnodeset=[]; for i=1:r for j=1:c if (((x(i,j)-start_fire(1))^2)/(ii^2)) + (((y(i,j)-start_fire(2))^2)/(ij^2)) <= 1 deadnodeset=[deadnodeset ; x(i,j) y(i,j)]; end end end for i=1:r1 for j=1:c1 if (((x1(i,j)-start_fire(1))^2)/(ii^2)) + (((y1(i,j)-start_fire(2))^2)/(ij^2)) <= 1 deadnodeset=[deadnodeset ; x1(i,j) y1(i,j)]; end end end % difference=(r*c)-hn; % if difference~=0 % for i=1:difference % plot(x(1,end-(i-1)) , y(1,end-(i-1)) , 'wo','LineWidth',5) % end % end % clear difference % difference=(r1*c1)-(hn*4); % if ~isempty(difference) % d=difference/2; % for i=0:d-1 % plot(x1(1,c1-i),y1(1,c1-i),'wo','LineWidth',5) % plot(x1(2,c1-i),y1(2,c1-i),'wo','LineWidth',5) % end % end end
Code 20 – Function M File –freshnodes.m
function fresh=freshnodes(deadnodeset_a,deadnodeset_b) fresh=[]; fresh2=[]; if isempty(deadnodeset_b) fresh=deadnodeset_a; else [r1 c1]=size(deadnodeset_a); [r2 c2]=size(deadnodeset_b); % for i=1:r1 % for j=1:r2 % if deadnodeset_a(i,1)~=deadnodeset_b(j,1) && deadnodeset_a(i,2)~=deadnodeset_b(j,2) % fresh=[fresh; deadnodeset_a(i,1) deadnodeset_a(i,2)]; % end % end % end end end
Code 21 – Function M File –dead_nodes1.m
function [deadnodeset]=dead_nodes1(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij) deadnodeset=[]; for i=1:r for j=1:c a1=sqrt(((start_fire(1)-x(i,j))^2) + ((start_fire(2)-y(i,j))^2)); if a1<ii || a1<ij deadnodeset=[deadnodeset ; x(i,j) y(i,j)]; plot(x(i,j),y(i,j),'ko','LineWidth',3) end end end for i=1:r1 for j=1:c1 a2=sqrt(((start_fire(1)-x1(i,j))^2) + ((start_fire(2)-y1(i,j))^2)); if a2<ii || a2<ij deadnodeset=[deadnodeset ; x1(i,j) y1(i,j)]; plot(x1(i,j),y1(i,j),'ko','LineWidth',3) end end end difference=(r*c)-hn; if difference~=0 for i=1:difference plot(x(1,end-(i-1)) , y(1,end-(i-1)) , 'wo','LineWidth',5) end end clear difference difference=(r1*c1)-(hn*4); if ~isempty(difference) d=difference/2; for i=0:d-1 plot(x1(1,c1-i),y1(1,c1-i),'wo','LineWidth',5) plot(x1(2,c1-i),y1(2,c1-i),'wo','LineWidth',5) end end end
Code 22 – Function M File –dead_nodes1.m
function [deadnodeset]=dead_nodes1(r,c,r1,c1,start_fire,x,y,x1,y1,hn,ii,ij) deadnodeset=[]; for i=1:r for j=1:c a1=sqrt(((start_fire(1)-x(i,j))^2) + ((start_fire(2)-y(i,j))^2)); if a1<ii || a1<ij deadnodeset=[deadnodeset ; x(i,j) y(i,j)]; plot(x(i,j),y(i,j),'ko','LineWidth',3) end end end for i=1:r1 for j=1:c1 a2=sqrt(((start_fire(1)-x1(i,j))^2) + ((start_fire(2)-y1(i,j))^2)); if a2<ii || a2<ij deadnodeset=[deadnodeset ; x1(i,j) y1(i,j)]; plot(x1(i,j),y1(i,j),'ko','LineWidth',3) end end end difference=(r*c)-hn; if difference~=0 for i=1:difference plot(x(1,end-(i-1)) , y(1,end-(i-1)) , 'wo','LineWidth',5) end end clear difference difference=(r1*c1)-(hn*4); if ~isempty(difference) d=difference/2; for i=0:d-1 plot(x1(1,c1-i),y1(1,c1-i),'wo','LineWidth',5) plot(x1(2,c1-i),y1(2,c1-i),'wo','LineWidth',5) end end end
Code 23 – Function M File –flowinfo1.m
function flowinfo1(row,col,hn,x,y,deadnodeset_a,ra) % flow of info during fire for i=1:row column=col; if i==1 && mod(hn,col)~=0 column=hn-((row-1)*col); end a1=[x(i,1) x(i,column)]; b1=[y(i,1) y(i,column)]; abc=plot(a1,b1,'c','LineWidth',2); blanks=[]; for j=1:col for k=1:ra if deadnodeset_a(k,1)==x(i,j) && deadnodeset_a(k,2)==y(i,j) blanks=[blanks; x(i,j) y(i,j)]; end end end if ~isempty(blanks) plot([blanks(1,1) blanks(end,1)],[blanks(1,2) blanks(end,2)],'w','LineWidth',2) end pause(0.3) if i==row break end a2=x(i,1:column); b2=y(i,1:column); a3=x(i+1,1:column); b3=y(i+1,1:column); for j=1:length(a2) plot([a2(j) a3(j)],[b2(j) b3(j)],'c','LineWidth',2) end pause(0.3) end a4=x(row,:); b4=y(row,:); for i=1:length(a4) plot([bp(1) a4(i)],[bp(2) b4(i)],'c','LineWidth',2) end
Code 24 – Function M File –test_scene.m
function test_scene(hn) [x,y,x1,y1,row,col,bp]=placing_sensors(hn); % stage 1 plot([x(3,3) x(4,3)],[y(3,3) y(4,3)],'w','LineWidth',2) %up plot([x(3,3) x(2,3)],[y(3,3) y(2,3)],'w','LineWidth',2) %down plot([x(3,3) x(3,2)],[y(3,3) y(3,2)],'w','LineWidth',2) %left plot([x(3,3) x(3,4)],[y(3,3) y(3,4)],'w','LineWidth',2) %right plot(x(3,3),y(3,3),'ko','LineWidth',5) plot([x(4,3) x(5,3)],[y(4,3) y(5,3)],'w','LineWidth',2) %up plot([x(4,3) x(3,3)],[y(4,3) y(3,3)],'w','LineWidth',2) %down plot([x(4,3) x(4,2)],[y(4,3) y(4,2)],'w','LineWidth',2) %left plot([x(4,3) x(4,4)],[y(4,3) y(4,4)],'w','LineWidth',2) %right plot(x(4,3),y(4,3),'ko','LineWidth',5) plot(x1(6,5),y1(6,5),'k*') plot(x1(6,6),y1(6,6),'k*') plot([x1(6,5) x(3,3)],[y1(6,5) y(3,3)],'w') plot([x1(6,6) x(3,3)],[y1(6,6) y(3,3)],'w') plot([x1(5,5) x(3,3)],[y1(5,5) y(3,3)],'w') plot([x1(5,6) x(3,3)],[y1(5,6) y(3,3)],'w') plot(x1(7,5),y1(7,5),'k*') plot(x1(7,6),y1(7,6),'k*') plot([x1(7,5) x(4,3)],[y1(7,5) y(4,3)],'w') plot([x1(7,6) x(4,3)],[y1(7,6) y(4,3)],'w') plot([x1(8,5) x(4,3)],[y1(8,5) y(4,3)],'w') plot([x1(8,6) x(4,3)],[y1(8,6) y(4,3)],'w') plot([x1(8,5) x(4,2)],[y1(8,5) y(4,2)],'LineWidth',2) plot([x1(8,5) x(4,4)],[y1(8,5) y(4,4)],'LineWidth',2) plot([x1(8,5) x(5,3)],[y1(8,5) y(5,3)],'LineWidth',2) plot(x1(8,5),y1(8,5),'go','LineWidth',5) plot([x1(8,5) x1(8,6)],[y1(8,5) y1(8,6)]) plot([x1(5,5) x(3,2)],[y1(5,5) y(3,2)],'LineWidth',2) plot([x1(5,5) x(3,4)],[y1(5,5) y(3,4)],'LineWidth',2) plot([x1(5,5) x(2,3)],[y1(5,5) y(2,3)],'LineWidth',2) plot(x1(5,5),y1(5,5),'go','LineWidth',5) plot([x1(5,5) x1(5,6)],[y1(5,5) y1(5,6)])
Code 25 – Function M File – checkdeadnode1.m
function checkdeadnode1(deadnodeset,x,y,x1,y1,bp) [r c]=size(x); [r1 c1]=size(x1); [r2 c2]=size(deadnodeset); for i=1:r1 for j=1:c1 for k=1:r2 if x1(i,j)==deadnodeset(k,1) && y1(i,j)==deadnodeset(k,2) plot([x1(i,j) x(ceil(i/2),ceil(j/2))],[y1(i,j) y(ceil(i/2),ceil(j/2))],'w') plot(deadnodeset(k,1),deadnodeset(k,2),'ko','LineWidth',3) end end end end for i=1:r for j=1:c for k=1:r2 if x(i,j)==deadnodeset(k,1) && y(i,j)==deadnodeset(k,2) plot([x(i,j) x1(((2*i)-1),((2*j)-1))],[y(i,j) y1(((2*i)-1),((2*j)-1))],'w') plot([x(i,j) x1(((2*i)-1),(2*j))],[y(i,j) y1(((2*i)-1),(2*j))],'w') plot([x(i,j) x1((2*i),((2*j)-1))],[y(i,j) y1((2*i),((2*j)-1))],'w') plot([x(i,j) x1((2*i),(2*j))],[y(i,j) y1((2*i),(2*j))],'w') for l=1:r2 if x1(((2*i)-1),((2*j)-1))~=deadnodeset(l,1) && y1(((2*i)-1),((2*j)-1))~=deadnodeset(l,2) % a is not dead and a is head for m=1:r2 if x1((2*i)-1)~=deadnodeset(m,1) && y1(((2*i)-1),(2*j))~=deadnodeset(m,2) %b is not dead plot([x1(((2*i)-1),((2*j)-1)) x1((2*i)-1)],[y1(((2*i)-1),((2*j)-1)) y1(((2*i)-1),(2*j))],'r') %ab end end for m=1:r2 if x1((2*i),((2*j)-1))~=deadnodeset(m,1) && y1((2*i),((2*j)-1))~=deadnodeset(m,2)%c is not dead plot([x1(((2*i)-1),((2*j)-1)) x1((2*i),((2*j)-1))],[y1(((2*i)-1),((2*j)-1)) y1((2*i),((2*j)-1))],'r') %ac end end for m=1:r2 if x1((2*i),(2*j))~=deadnodeset(m,1) && y1((2*i),(2*j))~=deadnodeset(m,2) %d is not dead plot([x1(((2*i)-1),((2*j)-1)) x1((2*i),(2*j))],[y1(((2*i)-1),((2*j)-1)) y1((2*i),(2*j))],'r') %ad end end else %a is dead if x1((2*i)-1)~=deadnodeset(l,1) && y1(((2*i)-1),(2*j))~=deadnodeset(l,2) %b is not dead for m=1:r2 if x1((2*i),((2*j)-1))~=deadnodeset(m,1) && y1((2*i),((2*j)-1))~=deadnodeset(m,2) %c is not dead plot([x1((2*i)-1) x1((2*i),((2*j)-1))],[y1(((2*i)-1),(2*j)) y1((2*i),((2*j)-1))],'r') %bc end end for m=1:r2 if x1((2*i),(2*j))~=deadnodeset(m,1) && y1((2*i),(2*j))~=deadnodeset(m,2) % d is not dead plot([x1((2*i)-1) x1((2*i),(2*j))],[y1(((2*i)-1),(2*j)) y1((2*i),(2*j))],'r') %bd end end else % b is dead if x1((2*i),((2*j)-1))~=deadnodeset(l,1) && y1((2*i),((2*j)-1))~=deadnodeset(l,2)% c is not dead for m=1:r2 if x1((2*i),(2*j))~=deadnodeset(m,1) && y1((2*i),(2*j))~=deadnodeset(m,2) % d is not dead plot([x1((2*i),((2*j)-1)) x1((2*i),(2*j))],[y1((2*i),((2*j)-1)) y1((2*i),(2*j))],'r') %cd end end else % c is dead if x1((2*i),(2*j))~=deadnodeset(l,1) && y1((2*i),(2*j))~=deadnodeset(l,2) %d is not dead end end end end end % a=x1(((2*i)-1),((2*j)-1)) y1(((2*i)-1),((2*j)-1)) % b=x1((2*i)-1) y1(((2*i)-1),(2*j)) % c=x1((2*i),((2*j)-1)) y1((2*i),((2*j)-1)) % d=x1((2*i),(2*j)) y1((2*i),(2*j)) if i+1<=r plot([x(i,j) x(i+1,j)],[y(i,j) y(i+1,j)],'w','LineWidth',3) end if i-1>=1 plot([x(i,j) x(i-1,j)],[y(i,j) y(i-1,j)],'w','LineWidth',3) end if j+1<=c plot([x(i,j) x(i,j+1)],[y(i,j) y(i,j+1)],'w','LineWidth',3) end if j-1>=1 plot([x(i,j) x(i,j-1)],[y(i,j) y(i,j-1)],'w','LineWidth',3) end if i==r plot([bp(1) x(i,j)],[bp(2) y(i,j)],'w','LineWidth',2) end plot(deadnodeset(k,1),deadnodeset(k,2),'ko','LineWidth',3) end end end end
Code 26 – Function M File – graphs.m
function graphs(axis,time,burntnodes,x1,y1,basetime,x,y,times,unik,start_fire) figure(5) subplot(2,2,1) area=[]; for i=1:time a=(axis(i,1))*axis(i,2)*pi; area=[area a]; end plot(1:time,area) title('Area of fire VS Time') xlabel('Time(hr)') ylabel('Area(sq mts)') %figure(6) subplot(2,2,2) plot(1:time,burntnodes,'r*','LineWidth',4) title('Number of nodes burnt VS Time') xlabel('Time(hrs)') ylabel('Number of nodes') %figure(7) subplot(2,2,3) base_distance=200; %distance of base station from the origin of fire (in this case centre of forest) rem_time=[]; for i=1:length(basetime) rem=base_distance-basetime(i); rem_time=[rem_time rem]; end plot(1:time,rem_time) title('Time taken for fire to reach the base station') xlabel('Levels of fire advancement') ylabel('Time taken to reach base') [r1 c1]=size(x); [r2 c2]=size(x1); totalnodes=(r1*c1)+(r2*c2); %figure(8) subplot(2,2,4) pktratio=[]; for i=1:length(burntnodes) pktratio=[pktratio (totalnodes-burntnodes(i))]; end plot(1:time,pktratio) title('Packet Ratio VS Time') xlabel('Time') ylabel('Packet Ratio') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('Press enter to continue..') pause disp('Number of nodes burnt along with time taken for them to burn') disp('Shown in the excel file') %mat={'Nodes burnt at time t' 'Total nodes burnt' 'Year' 'Month' 'Date' 'Hrs' 'Minutes' 'Seconds'}; tot=[]; t=0; for i=1:length(unik) t=t+unik(i); tot=[tot t]; end % unik % tot % times answers=[unik' tot' times]; [num,txt,raw]=xlsread('Timeframe'); [row col]=size(num); blank_mat=[]; for i=1:row blank_mat(i,:)= zeros(1,col); end xlswrite('Timeframe',blank_mat,1,'A3') xlswrite('Timeframe',answers,1,'A3') % answers % mat1=[mat; num2cell(answers)]; % disp(mat1) figure(6) long=sqrt((x1(1,1)-x1(end,end))^2+(y1(1,1)-y1(end,end))^2); %longest distance between 2 sensors short=sqrt((x1(1,1)-x(1,1))^2+(y1(1,1)-y(1,1))^2); %shortest distance between 2 sensors dist=linspace(short,long,10); %distances between the sensors from "short" to "long" e=linspace(90,20,10); %remaining energy levels gap=e(2)-e(1); energy=[]; for i=1:length(e) a=e(i); b=e(i)+gap; x=a + (b-a).*rand(1,1); energy=[energy x]; %declining energy of the nodes as distance between them increases end plot(dist,energy) title('Remaining energy level of deployed nodes') xlabel('Average distance between sensors') ylabel('Remaining energy level (%)') clear long short dist figure(7) long=sqrt((start_fire(1)-x1(1,1))^2+((start_fire(2)-y1(1,1))^2)); %longest distance between the fire start point and a sensor dist1=[]; [r c]=size(x1); for i=1:r for j=1:c d=sqrt((start_fire(1)-x1(i,j))^2+((start_fire(2)-y1(i,j))^2)); dist1=[dist1;i j d]; %distances of start point with all the sub nodes end end dist2=[]; [r c]=size(x); for i=1:r for j=1:c d=sqrt((start_fire(1)-x(i,j))^2+((start_fire(2)-y(i,j))^2)); dist2=[dist2;i j d]; %distances of start point with all the head nodes end end [a,ind1]=sort(dist1(:,3)); [b,ind2]=sort(dist2(:,3)); if a(1)<b(1) i=dist1(ind1(1),1); j=dist1(ind1(1),2); short=sqrt((start_fire(1)-x1(i,j))^2+((start_fire(2)-y1(i,j))^2)); %shortest distance between the start point and a sub node elseif a(1)>b(1) i=dist2(ind1(1),1); j=dist2(ind1(1),2); short=sqrt((start_fire(1)-x(i,j))^2+((start_fire(2)-y(i,j))^2)); %shortest distance between the start point and a head node elseif a(1)==b(1) i=dist2(ind1(1),1); j=dist2(ind1(1),2); short=sqrt((start_fire(1)-x(i,j))^2+((start_fire(2)-y(i,j))^2)); %shortest distance between the start point and a head node end e=linspace(short,long,10); %making partitions from short to long plot(e) title('Time required for the sensor nodes to sense the fire threat from various distances') xlabel('Average distance between fire ignition location and sensor node') ylabel('Time required for the sensor node to sense threat')