-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDirect_Protocol.m
32 lines (31 loc) · 966 Bytes
/
Direct_Protocol.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function Result=Direct_Protocol(Model,Network)
Iteration=Model.Iteration;
Packet.ToBS=zeros(Iteration,1);
Dead.All=zeros(Iteration,1);
Dead.Normal=zeros(Iteration,1);
Dead.Advance=zeros(Iteration,1);
Networks=[];
%% Main loop
for i=1:Iteration
disp(['It = ' , num2str(i)]);
if(mod(i-1,Model.SaveIteration)==0)
Networks=[Networks,Network];
end
if(mod(i-1, round(1/Model.P) )==0)
Temp=num2cell(zeros(1,length(Network)));
[Network.G]=Temp{:};
[Network.cl]=Temp{:};
end
[Dead.Normal(i),Dead.Advance(i)]=DeadCounter(Network);
Dead.All(i)=Dead.Normal(i)+Dead.Advance(i);
Network=Direct_UsedEnergy(Model,Network);
Packet.ToBS(i)=Model.NodeNumber-Dead.All(i);
end
%% Result
Result.Dead=Dead;
Result.Networks=Networks;
Result.Packet=cumsum(Packet.ToBS);
Dead.All(Dead.All==0)=Inf;
[~,Location]=min(Dead.All);
Result.FirstDead=Location;
end