-
Notifications
You must be signed in to change notification settings - Fork 1
/
aimd_main.m
73 lines (59 loc) · 2.04 KB
/
aimd_main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function aimd_main(simTime, lambda, nNodes, orphanAge, orphanRate, alpha_AIMD, beta_AIMD)
% create global variable by adding them to Tangle structure
Tangle.nNodes = nNodes;
Tangle.orphanAge = orphanAge;
Tangle.orphanRate = orphanRate;
Tangle.bAvgFilt = (1/10)*ones(10,1);
Tangle.simTime = simTime;
Tangle.q = 1/3;
Tangle.dt = 0.1; % must be inverse of a whole number
Tangle.mu = 0; % rate of malicious arrivals
Tangle.nCW = 1; % store this many past values of CW
Tangle.h = 1;
Tangle.maxDepth = 20;
Tangle.nStartingTips = 1;
Tangle.size = Tangle.nStartingTips;
% create a vector of lambdas if it was given as a constant
if(length(lambda)==1)
Tangle.lambda = lambda*ones(1, simTime/Tangle.dt); % rate of honest arrivals
elseif(length(lambda)==simTime/Tangle.dt)
Tangle.lambda = lambda;
else
error('lambda input is incorrect length');
end
% create the genesis transaction
Tangle = create_genesis(Tangle);
for n = 1:Tangle.nNodes
Tangle.Nodes(n).alpha = 0.1;
Tangle.Nodes(n).beta = 0;
Tangle.Nodes(n).alphaAIMD = alphaAIMD;
Tangle.Nodes(n).betaAIMD = betaAIMD;
end
Results.alphas = zeros(nNodes, simTime);
Results.orphanRate = zeros(nNodes, simTime);
Results.avgOrphanRate = zeros(nNodes, simTime);
Results.nOrphans = zeros(nNodes, simTime);
Results.nTips = zeros(1, simTime/Tangle.dt);
[~, Results] = generate_aimd(Tangle, 1, Results);
%% Plotting of results
% save('Results_basic.mat', 'Results');
close all
IEEEFigure
figure(1)
hold on
c = get(groot,'DefaultAxesColorOrder');
for i = 1:size(Results.alphas,1)
plot(1:size(Results.alphas,2), Results.alphas(i,:), 'Color', c(i,:));
plot([0 size(Results.alphas,2)], [mean(Results.alphas(i,:)) mean(Results.alphas(i,:))], 'Color', c(i,:), 'LineStyle', '--');
end
ylabel('$\alpha$','Interpreter', 'latex');
xlabel('Time(s)');
figure(2)
hold on
c = get(groot,'DefaultAxesColorOrder');
for i = 1:size(Results.alphas,1)
plot(1:Tangle.simTime, Results.avgOrphanRate(i,:), 'Color', c(i,:));
end
ylabel('Orphan Rate (moving average)','Interpreter', 'latex');
xlabel('Time(s)');
end