forked from nokia/NCBounds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uniform_ring_stability.py
100 lines (88 loc) · 2.04 KB
/
uniform_ring_stability.py
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
import numpy as np
from numpy import linalg as la
R = 100
def mat_exacte(n, R, u):
r = u*R/n
ρ = r / (R - (n-1) * r)
x = np.zeros(n)
x[0] = ρ
for i in np.arange(1,n):
x[i] = (x[0] * (n-i) * r + r * sum([x[j] for j in np.arange(1,i)])) / (R - r)
return np.array([[x[max(i + 1 - j,0)]for j in np.arange(n-1)] for i in np.arange(n-1)])
N = 100
tabEXACT_u = np.ones(N+1)
tab_n = np.arange(N+1)
u = 1
n = 2
b = True
while b :
r = u*R/n
ρ = r / (R- (n-1)*r)
mat = mat_exacte(n, R, u)
s = max(la.eigvals(mat))
if s < 1:
tabEXACT_u[n] = u
n += 1
else:
u -= 0.0001
if u < 0 or n > N:
b = False
tabSFA_u = np.ones(N+1)
u = 1
n = 2
b = True
while b :
r = u*R/n
ρ = r / (R- (n-1)*r)
mat = ρ * np.ones((n-1,n-1))
for i in np.arange(n-2):
mat[i+1,i] = 1
s = max(la.eigvals(mat))
if s < 1:
tabSFA_u[n] = u
n += 1
else:
u -= 0.001
if u < 0 or n > N:
b = False
tabPMOO_u = np.ones(N+1)
u = 1
n = 2
b = True
while b :
r = u*R/n
ρ = r / (R- (n-1)*r)
mat = ρ * np.ones((n-1,n-1))
s = max(la.eigvals(mat))
if s < 1:
tabPMOO_u[n] = u
n += 1
else:
u -= 0.001
if u < 0 or n > N:
b = False
f = open('./ring_stability.data', 'w')
n = 0
while n<N+1:
f.write("%f\t" % n)
f.write("%f\t" % tabEXACT_u[n])
f.write("%f\t" % tabPMOO_u[n])
f.write("%f\n" % tabSFA_u[n])
n += 1
f.close()
with open('./ring_stability.data') as f:
lines = f.readlines()
n = [float(line.split()[0]) for line in lines]
exact = [float(line.split()[1]) for line in lines]
pmoo = [float(line.split()[2]) for line in lines]
sfa = [float(line.split()[3]) for line in lines]
f.close()
import matplotlib.pyplot as pl
pl.plot(n,sfa, c='r', label='SFA')
pl.plot(n,exact, c='b', label='Exact')
pl.plot(n,pmoo, c='y', label='PMOO')
pl.xlabel('Number of servers')
pl.ylabel('Maximum utilization rate for stability')
pl.legend()
pl.axis([0, 100, 0, 1])
pl.show()