-
Notifications
You must be signed in to change notification settings - Fork 2
/
dp_simu.m
79 lines (71 loc) · 2.18 KB
/
dp_simu.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
74
75
76
77
78
79
function [simu] = dp_simu(h_set, B_set, num_belief, pi)
% Simulate the optimal policy (partial knowledge)
% Declare global variables
% See aoi_main.m
global K D T
global lambdas channels weights
global simu_indept
% Return the POMDP functions of each end node
[transF, obserF] = sigl_func();
% Set the finite horizon during which the set of belief states changes
T0 = length(h_set(1, 1, :));
belief_index = 1:num_belief(T0);
simu = zeros(1, simu_indept);
parfor si = 1:simu_indept
% Run independent numerical experiments
% Initialize the local age of each end node
z = ones(K, 1);
% Initialize the AoI of each end node at the monitor
h = ones(K, 1) * 2;
% Initialize \mathbb{B}^{t}
B = zeros(K, D);
B(:, 1) = 1;
for t = 1:T
simu(si) = simu(si) + dot(weights, h);
if t < T
% Determine the action
t0 = min(t, T0);
diff_h = sum(abs(h_set(:, :, t0) - h));
diff_B = sum(abs(B_set(:, :, :, t0) - B), [1 2]);
nb = belief_index(diff_h' + squeeze(diff_B) < 1e-12);
action = ones(1, K);
action(pi(nb, t)) = 2;
else
continue
end
% Update the AoI of each end node at the monitor
no = zeros(1, K);
for k = 1:K
if action(k) == 2 && rand() < channels(k)
no(k) = min(D, z(k));
h(k) = z(k) + 1;
else
no(k) = D + 1;
h(k) = h(k) + 1;
end
end
h = min(h, D);
% Update the local age of each end node
for k = 1:K
if rand() < lambdas(k)
z(k) = 1;
else
z(k) = z(k) + 1;
end
end
z = min(z, D);
% Update \mathbb{B}^{t}
for k = 1:K
if action(k) == 2
B(k, :) = B(k, :) .* obserF(:, no(k), k)' * transF(:, :, k);
B(k, :) = B(k, :) / sum(B(k, :));
else
B(k, :) = B(k, :) * transF(:, :, k);
end
end
end
end
% Compute the EWSAoI (simu)
simu = sum(simu) / T / K / simu_indept;
% Print the EWSAoI (simu)
fprintf("dp_simu = %.6f\n", simu);