m基于matlab的AODV,leach自组网网络平台仿真,对比吞吐量,端到端时延,丢包率,剩余节点个数,节点消耗能量
Posted 51matlab
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了m基于matlab的AODV,leach自组网网络平台仿真,对比吞吐量,端到端时延,丢包率,剩余节点个数,节点消耗能量相关的知识,希望对你有一定的参考价值。
1.算法仿真效果
matlab2022a仿真结果如下:
2.算法涉及理论知识概要
AODV是一种应用于无线网状网络的路由协议。它源节点需要发送数据时才进行路由发现。当没有数据发送请求时并不执行。在路由发现过程中首先检查路由表中是否存在从源节点到目的节点的路由,若存在则直接进行数据转发,若不存在,则广播RREQ分组进行寻找并建立路由。当目的节点收到第一个RREQ分组时,立即回复RREP分组给源节点,当源节点收到RREP分组时,便沿着RREP的路径建立了一条到目的节点的路径,然后通过此路径进行数据的传送。当节点在转发分组失败的时候便广播一个RRER分组,以此来告知源节点路径断开,源节点收到RRER之后将要发送的数据存入缓存,并重新发起路由发现的过程,直到新的路由路径建立起来的时候,才将缓存中的数据依次发送给目的节点。
AODV是一种按需路由协议,根据业务需求建立和维护路由,它是DSDV (Destination—SequencedDistance-Vector)协议和DSR(Dynamic Source Routing) 协议的结合,使用DSDV协议中的目的节点序列号来防止缓存的路由信息过期以及环路的产生,路由建立则是基于DSR协议中所采用的方法,不同点在于AODV采用的是逐跳路由而不是源路由,可以实现ZigBee节点之间动态的、自发的路由,使节点很快实现到目的节点的通信。ZigBee路由算法中使用的AODVjr算法是对AODV算法的精简和改进,但是仍然保持AODV的原始功能。其特点是路由路径最佳,缺点是单个节点需要路由表,整体路由代价高。
AODV路由协议主要可分为初始化、路由的建立及维护、显示、时钟、节点移动模块。总体设计框图所示:
AODV是一种按需路由协议,根据业务需求建立和维护路由,它是DSDV协议和DSR协议的结合。使用DSDV协议中的目的节点序列号来防止缓存的路由信息过期以及环路的产生,路由建立则是基于DSR协议中所采用的方法,不同点在于AODV采用的是逐跳路由而不是源路由。
控制中心主要包括消息收发模块、用户列表(相关节点信息,用户名和IP)、参数设置模块和功能性模块。
1.参数设置模块:可以实现节点个数、仿真场景大小、仿真时间、信道模型、路由协议、节点初始能量等的输入或者选择
2.功能性模块:显示拓扑结构图;计算网络平均吞吐量、平均端到端时延、丢包率、剩余节点个数、节点消耗能量等
参数设置模块,是通过GUI界面进行设置,主要实现可设置网络节点,仿真场景大小,仿真时间,信道模型的选择,路由协议的选择,节点初始能量的设置等参数变量,这些变量,我们均通过GUI界面进行参数的输入。
功能模块,显示拓扑结构图;计算网络平均吞吐量、平均端到端时延、丢包率、剩余节点个数、节点消耗能量等
整个网络的工作机制如下:
通过设置N个网络节点,在设置好大小的场景中,进行随机坐标的分布,并设置整个网络的工作时间,即仿真时间,不同节点之间的信息传递,其信道模型根据设置,选择Free space和 Two-ray ground reflection两种类型的信道,网络工作的MAC协议为IEEE 802.11,而路由协议,则根据选择,设置Leach或者AODV,或AODV改进三种类型。然后,我们根据网络的实际仿真结果,实时的输出六个指标。
3.MATLAB核心程序
STATISTICS.DEAD3(r+1) = Dead_time; countCHs3 = 0; cluster3 = 1; for i = 1:n if Ea > 0 & S3(i).E > 0 & S3(i).G <= 0 if rand<= 0.2 countCHs3 = countCHs3+1; packets_TO_BS3 = packets_TO_BS3+1; PACKETS_TO_BS3(r+1) = packets_TO_BS3; S3(i).type = \'C\'; C3(cluster3).xd = S3(i).xd; C3(cluster3).yd = S3(i).yd; if r > 1 distance = sqrt((S3(i).xd-(S3(n+1).xd) )^2 + (S3(i).yd-(S3(n+1).yd))^2 ); Fs = LBF3t(r); Ps = Ec3(r); Gs = w1*distance+w2*Fs+w3*Ps; else distance = sqrt((S3(i).xd-(S3(n+1).xd) )^2 + (S3(i).yd-(S3(n+1).yd))^2 ); Gs = distance; end C3(cluster3).distance = Gs; C3(cluster3).id = i; X3(cluster3) = S3(i).xd; Y3(cluster3) = S3(i).yd; cluster3 = cluster3+1; %计算簇头发送4000bit数据的能量消耗 if Gs > do S3(i).E = S3(i).E - ((ETX+EDA)*(PACK) + Emp*PACK*(distance*distance*distance*distance)); end if Gs <= do S3(i).E = S3(i).E - ((ETX+EDA)*(PACK) + Efs*PACK*(distance * distance)); end end end end STATISTICS.COUNTCHS3(r+1) = countCHs3; x3 = zeros(1,cluster3-1); y3 = 0; z3 = 0; Drop_rate0 = zeros(1,n); %产生不同的路由路径,用来进行综合分析 PATH = []; Nums = 1:n; nn = n; for js = 1:n/2 tmps = randperm(nn); if js > 1 I1 = find(tmps == tmps1); I2 = find(tmps == tmps2); tmps(I1)=0; tmps(I2)=0; tmps(find(tmps==0)) = []; end SS = tmps(1); DD = tmps(2); %根据原节点和目标节点进行路由跟新 [path,hop] = aodv_path_discovery_new(n,nodes_link,SS,DD,Fload,PLest,BREAK); PATH = [PATH,path]; tmps1 = SS; tmps2 = DD; end for ind=1:length(PATH) i = PATH(ind); if S3(i).type==\'N\' && S3(i).E>0 if cluster3-1 >= 1 min_dis = Inf; min_dis_cluster = 0; for c=1:cluster3-1 if r > 1 distance = sqrt((S3(i).xd-C3(c).xd)^2 + (S3(i).yd-C3(c).yd)^2); Fs = LBF3t(r); Ps = Ec3(r); Gs = w1*distance+w2*Fs+w3*Ps; else distance = sqrt((S3(i).xd-C3(c).xd)^2 + (S3(i).yd-C3(c).yd)^2); Gs = distance; end temp = min(min_dis,Gs); if temp < min_dis min_dis = temp; min_dis_cluster = c; x3(c) = x3(c)+1; end end
基于MATLAB/GUI的自组网仿真平台,对比leach,ADOV协议
目录
一、理论基础
此仿真平台由控制中心和终端节点组成(GUI界面交互)。控制中心可以向节点发送控制命令,不可到达节点可以通过多跳方式到达;节点返回相关信息;通信方式为UDP。
控制中心主要包括消息收发模块、用户列表(相关节点信息,用户名和IP)、参数设置模块和功能性模块。
- 参数设置模块:可以实现节点个数、仿真场景大小、仿真时间、信道模型、路由协议、节点初始能量等的输入或者选择
- 功能性模块:显示拓扑结构图;计算网络平均吞吐量、平均端到端时延、丢包率、剩余节点个数、节点消耗能量等
数据吞吐:
这个指标的计算,通过一段时间N的仿真,然后除以N,得到整个网络的平均吞吐量。
网络能量消耗:
网络能量的计算,即当前时刻的能量为前一时刻的能量减去当前时刻的能量消耗。
在进行网络相关指标计算的时候,需要对每个时刻的网络剩余能量Ei进行判断,如果大于0,则继续循环进行计算,如果小于等于0,则停止计算。
负载均衡度对比:
通过计算网络最大负载,和最小负载,然后得到负载均衡度。
这个指标反映了在实际工作中,网络的负载分布情况。
丢包率:
这在整个网络中,通过发送bit数据包,然后统计丢包率,计算公式如下所示:
即统计每个时刻的丢包的bit数,除以当前时刻总的数据包,获得当前时刻的丢包率。
死亡节点数:
根据网络能耗指标:
二、核心程序
function varargout = tops(varargin)
% TOPS MATLAB code for tops.fig
% TOPS, by itself, creates a new TOPS or raises the existing
% singleton*.
%
% H = TOPS returns the handle to a new TOPS or the handle to
% the existing singleton*.
%
% TOPS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TOPS.M with the given input arguments.
%
% TOPS('Property','Value',...) creates a new TOPS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before tops_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to tops_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help tops
% Last Modified by GUIDE v2.5 05-Jun-2014 20:45:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tops_OpeningFcn, ...
'gui_OutputFcn', @tops_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin1)
gui_State.gui_Callback = str2func(varargin1);
end
if nargout
[varargout1:nargout] = gui_mainfcn(gui_State, varargin:);
else
gui_mainfcn(gui_State, varargin:);
end
% End initialization code - DO NOT EDIT
% --- Executes just before tops is made visible.
function tops_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to tops (see VARARGIN)
% Choose default command line output for tops
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes tops wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = tops_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout1 = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%============================================================================场景初始化<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================场景初始化<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================场景初始化<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================场景初始化<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
parameter;
SEEK = str2num(get(handles.edit7,'String'));
rand('state',SEEK);
SEEK2 = str2num(get(handles.edit8,'String'));
A = str2num(get(handles.edit1,'String'));
nodes_number = str2num(get(handles.edit2,'String'));
R = str2num(get(handles.edit3,'String'));
X = rand(1,nodes_number)*A/2;
Y = rand(1,nodes_number)*A/2;
views = get(handles.checkbox1,'Value');
%节点初始化,这里直接进行编程,不通过GUI界面设置
%节点状态的初始化
%节点状态的初始化
%负载
rand('state',SEEK2);
tmps = 0.7*rand(3,nodes_number);
%假设节点的负载时随机的
% Fload = tmps(1,:);%负载百分比0~1之间
[xs,ys,ds,iscom] = func_dist([X',Y'],nodes_number,R);
for i = 1:nodes_number
dd = ds(i,:);
NEAR = length(find(dd<R));
Fload(i) = 0.4+0.6*NEAR/nodes_number;
end
%剩余能量
PLest = min(2*tmps(2,:),1);%剩余能量百分比0~1之间
%损坏
BREAK = tmps(3,:) >= 0.2;%0表示的损坏的节点,1表示正常的节点
axes(handles.axes1);
cla reset;
plot(X,Y,'b s');
hold on;
xlabel('空间横坐标 x 单位:m');
ylabel('空间纵坐标 y 单位:m');
hold on;
for i = 1:nodes_number
%给节点标注号码
if views == 1
text(X(i)+2, Y(i)+2, num2str(i));
end
for j = 1:nodes_number
distance = sqrt((X(i) - X(j))^2 + (Y(i) - Y(j))^2);
if distance <= R
nodes_link(i, j) = 1;
grid on;
else
nodes_link(i, j) = inf;
end;
end;
end;
%============================================================================路径搜索<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================路径搜索<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================路径搜索<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================路径搜索<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
parameter;
if get(handles.radiobutton1,'value')
SEL1=1;
elseif get(handles.radiobutton2,'value')
SEL1=2;
elseif get(handles.radiobutton3,'value')
SEL1=3;
end
if get(handles.radiobutton4,'value')
SEL2=1;
elseif get(handles.radiobutton5,'value')
SEL2=2;
end
S=str2num(get(handles.edit5,'String'));
D=str2num(get(handles.edit6,'String'));
if S < 1 | S > nodes_number
msgbox('源节点错误,请重新输入');
end
if D < 1 | D > nodes_number
msgbox('目标节点错误,请重新输入');
end
axes(handles.axes1);
cla reset;
plot(X,Y,'b s');
hold on;
xlabel('空间横坐标 x 单位:m');
ylabel('空间纵坐标 y 单位:m');
hold on;
grid on;
for i = 1:nodes_number
%给节点标注号码
if views == 1
text(X(i)+2, Y(i)+2, num2str(i));
end
for j = 1:nodes_number
distance = sqrt((X(i) - X(j))^2 + (Y(i) - Y(j))^2);
if distance <= R
nodes_link(i, j) = 1;
grid on;
else
nodes_link(i, j) = inf;
end;
end;
end;
%%
%LEACH
if SEL1 == 1
[PATHS,hop] = leach_path_discovery(nodes_number,nodes_link,S,D);
l=length(PATHS);
end
%%
%AODV
if SEL1 == 2
[PATHS,hop] = aodv_path_discovery(nodes_number,nodes_link,S,D);
l=length(PATHS);
end
%%
%改进AODV
if SEL1 == 3
[PATHS,hop] = aodv_path_discovery_new(nodes_number,nodes_link,S,D,Fload,PLest,BREAK);
l = length(PATHS);
end
if l==0 & S~=D
fprintf('源节点 %d 到目的节点 %d 的路径为:空!\\n',S,D);
fprintf('\\n');
plot(X(S),Y(S),'rp','markersize',15);
plot(X(D),Y(D),'rp','markersize',15);
elseif l==0 & S==D
fprintf('源节点 %d 与目的节点 %d 为同一节点。\\n',S,D);
fprintf('跳数为 %d 。\\n',hop);
fprintf('\\n')
plot(X(D),Y(D),'rp','markersize',15);
else fprintf('源节点 %d 到目的节点 %d 的路径为:',S,D);
i=2;
fprintf('%d',S);
while i~=l+1
fprintf(' -> %d',PATHS(i));
i=i+1;
end;
fprintf('\\n');
fprintf('跳数为 %d 。\\n',hop);
fprintf('\\n');
end;
if l ~= 0
for i = 1:(l-1)
line([X(PATHS(i)) X(PATHS(i+1))],[Y(PATHS(i)) Y(PATHS(i+1))],'Color','r','LineWidth',1.50);
end;
end;
if SEL1 == 1
save data_save\\path1.mat l S D X Y PATHS
end
if SEL1 == 2
save data_save\\path2.mat l S D X Y PATHS
end
if SEL1 == 3
save data_save\\path3.mat l S D X Y PATHS
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton4
set(handles.radiobutton4,'value',1);
set(handles.radiobutton5,'value',0);
% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton5
set(handles.radiobutton4,'value',0);
set(handles.radiobutton5,'value',1);
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
set(handles.radiobutton1,'value',1);
set(handles.radiobutton2,'value',0);
set(handles.radiobutton3,'value',0);
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
set(handles.radiobutton1,'value',0);
set(handles.radiobutton2,'value',1);
set(handles.radiobutton3,'value',0);
% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.radiobutton1,'value',0);
set(handles.radiobutton2,'value',0);
set(handles.radiobutton3,'value',1);
% Hint: get(hObject,'Value') returns toggle state of radiobutton3
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit7 as text
% str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%============================================================================性能仿真<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================性能仿真<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================性能仿真<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%============================================================================性能仿真<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
parameter;
Times = str2num(get(handles.edit10,'String'));
PACK = str2num(get(handles.edit11,'String'));
if SEL1 == 1
[Throughput,Power,Loads,droprate,death] = func_leach_performance(A,PACK,nodes_number,Times,X,Y,SEL2);
end
if SEL1 == 2
[Throughput,Power,Loads,droprate,death] = func_AODV_performance(A,PACK,nodes_number,Times,X,Y,SEL2);
end
if SEL1 == 3
[Throughput,Power,Loads,droprate,death] = func_advance_AODV_performance(A,PACK,nodes_number,Times,X,Y,SEL2);
end
axes(handles.axes2);
cla reset;
plot(Throughput,'b','linewidth',2);
grid on;
xlabel('x(time)');
ylabel('y(数据吞吐)');
axes(handles.axes3);
cla reset;
plot(Power,'b','linewidth',2);
grid on;
xlabel('x(time)');
ylabel('y(网络能量消耗)');
axes(handles.axes4);
cla reset;
plot(Loads,'b','linewidth',2);
grid on;
xlabel('x(time)');
ylabel('y(负载均衡度对比)');
axes(handles.axes5);
cla reset;
plot(droprate,'b','linewidth',2);
grid on;
xlabel('x(time)');
ylabel('y(丢包率)');
axes(handles.axes6);
cla reset;
plot(death,'b','linewidth',2);
grid on;
xlabel('x(time)');
ylabel('y(死亡节点数)');
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
parameter;
if SEL2 == 1
axes(handles.axes2);
cla reset;
load data_save\\r0_1.mat
plot(Throughput,'b','linewidth',2);
hold on
load data_save\\r1_1.mat
plot(Throughput,'r','linewidth',2);
hold on
load data_save\\r2_1.mat
plot(Throughput,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(数据吞吐)');
axes(handles.axes3);
cla reset;
load data_save\\r0_1.mat
plot(Power,'b','linewidth',2);
hold on
load data_save\\r1_1.mat
plot(Power,'r','linewidth',2);
hold on
load data_save\\r2_1.mat
plot(Power,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(网络能量消耗)');
axes(handles.axes4);
cla reset;
load data_save\\r0_1.mat
plot(Loads,'b','linewidth',2);
hold on
load data_save\\r1_1.mat
plot(Loads,'r','linewidth',2);
hold on
load data_save\\r2_1.mat
plot(Loads,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(负载均衡度对比)');
axes(handles.axes5);
cla reset;
load data_save\\r0_1.mat
plot(droprate,'b','linewidth',2);
hold on
load data_save\\r1_1.mat
plot(droprate,'r','linewidth',2);
hold on
load data_save\\r2_1.mat
plot(droprate,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(丢包率)');
axes(handles.axes6);
cla reset;
load data_save\\r0_1.mat
plot(death,'b','linewidth',2);
hold on
load data_save\\r1_1.mat
plot(death,'r','linewidth',2);
hold on
load data_save\\r2_1.mat
plot(death,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(死亡节点数)');
end
if SEL2 == 2
axes(handles.axes2);
cla reset;
load data_save\\r0_2.mat
plot(Throughput,'b','linewidth',2);
hold on
load data_save\\r1_2.mat
plot(Throughput,'r','linewidth',2);
hold on
load data_save\\r2_2.mat
plot(Throughput,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(数据吞吐)');
axes(handles.axes3);
cla reset;
load data_save\\r0_2.mat
plot(Power,'b','linewidth',2);
hold on
load data_save\\r1_2.mat
plot(Power,'r','linewidth',2);
hold on
load data_save\\r2_2.mat
plot(Power,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(网络能量消耗)');
axes(handles.axes4);
cla reset;
load data_save\\r0_2.mat
plot(Loads,'b','linewidth',2);
hold on
load data_save\\r1_2.mat
plot(Loads,'r','linewidth',2);
hold on
load data_save\\r2_2.mat
plot(Loads,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(负载均衡度对比)');
axes(handles.axes5);
cla reset;
load data_save\\r0_2.mat
plot(droprate,'b','linewidth',2);
hold on
load data_save\\r1_2.mat
plot(droprate,'r','linewidth',2);
hold on
load data_save\\r2_2.mat
plot(droprate,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(丢包率)');
axes(handles.axes6);
cla reset;
load data_save\\r0_2.mat
plot(death,'b','linewidth',2);
hold on
load data_save\\r1_2.mat
plot(death,'r','linewidth',2);
hold on
load data_save\\r2_2.mat
plot(death,'g','linewidth',2);
hold on
legend('leach','AODV','改进AODV');
grid on;
xlabel('x(time)');
ylabel('y(死亡节点数)');
end
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
clear;
close all;
warning off;
function edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit9_Callback(hObject, eventdata, handles)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit9 as text
% str2double(get(hObject,'String')) returns contents of edit9 as a double
% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit10_Callback(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit10 as text
% str2double(get(hObject,'String')) returns contents of edit10 as a double
% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
function edit11_Callback(hObject, eventdata, handles)
% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit11 as text
% str2double(get(hObject,'String')) returns contents of edit11 as a double
% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
三、仿真测试结果
A12-15
以上是关于m基于matlab的AODV,leach自组网网络平台仿真,对比吞吐量,端到端时延,丢包率,剩余节点个数,节点消耗能量的主要内容,如果未能解决你的问题,请参考以下文章
LEACH协议基于matlab无线传感器网络LEACH与DEEC协议含Matlab源码 2187期
LEACH协议基于matlab粒子群算法改进LEACH协议含Matlab源码 2052期
LEACH协议基于matlab粒子群算法改进LEACH协议含Matlab源码 2052期
WSN通信基于matlab粒子群算法改进能量均衡高效WSN LEACH协议含Matlab源码 1562期