-
Notifications
You must be signed in to change notification settings - Fork 1
/
project.m
109 lines (96 loc) · 1.54 KB
/
project.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
clear
N = 9;
n = 3;
C = 10;
m=100;
xmax = m*C;
V = 0.5;
T = (V+1)*10^4;
Q = cell(1,T+1);
for i=1:T+10
Q{i} = zeros(N,N);
end
x1 = zeros(1,T+1);
x2 = zeros(1,T+1);
x3 = zeros(1,T+1);
W1 = zeros(1,T+1);
W2 = zeros(1,T+1);
W3 = zeros(1,T+1);
links = zeros(N,N);
links(1,4)=1;
links(1,5)=1;
links(1,6)=1;
links(1,7)=1;
links(1,8)=1;
links(1,9)=1;
links(2,4)=1;
links(2,5)=1;
links(2,6)=1;
links(2,7)=1;
links(2,8)=1;
links(2,9)=1;
links(3,4)=1;
links(3,5)=1;
links(3,6)=1;
links(3,7)=1;
links(3,8)=1;
links(3,9)=1;
a1 = zeros(N,N);
a2 = zeros(N,N);
a3 = zeros(N,N);
a1(1,4)=1;
a1(1,7)=1;
a2(2,4)=1;
a2(2,7)=1;
a3(3,4)=1;
a3(3,7)=1;
a2(1,5)=1;
a2(1,8)=0;
a2(2,5)=0;
a2(2,8)=0;
a2(3,5)=0;
a2(3,8)=0;
a3(1,6)=0;
a3(1,9)=0;
a3(2,6)=0;
a3(2,9)=0;
a3(3,6)=0;
a3(3,9)=0;
for t = 1:T
for i = 1:N
for j = 1:N
if links(i,j) == 1
Q{t+1}(i,j) = max(Q{t}(i,j)+a1(i,j)*x1(t)+a2(i,j)*x2(t)+a3(i,j)*x3(t)-C, 0);
end
end
end
W1(t) = sum(sum(Q{t}.*a1));
W2(t) = sum(sum(Q{t}.*a2));
W3(t) = sum(sum(Q{t}.*a3));
x1(t+1) = V/W1(t)-1;
x2(t+1) = V/W2(t)-1;
x3(t+1) = V/W3(t)-1;
if x1(t+1) > xmax
x1(t+1) = xmax;
end
if x1(t+1) < 0
x1(t+1) = 0;
end
if x2(t+1) > xmax
x2(t+1) = xmax;
end
if x2(t+1) < 0
x2(t+1) = 0;
end
if x3(t+1) > xmax
x3(t+1) = xmax;
end
if x3(t+1) < 0
x3(t+1) = 0;
end
end
xbar1 = mean(x1)
xbar2 = mean(x2)
xbar3 = mean(x3)
util = log(1+xbar1)+log(1+xbar2)+log(1+xbar3)
V