-
Notifications
You must be signed in to change notification settings - Fork 6
/
small_network_example.py
103 lines (72 loc) · 3.46 KB
/
small_network_example.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
101
102
103
from NCBounds.ArrivalCurve import ArrivalCurve
from NCBounds.Flow import Flow
from NCBounds.ServiceCurve import ServiceCurve
from NCBounds.Server import Server
from NCBounds.Network import Network, Ring, TwoRings
from NCBounds.FeedForwardAnalyzer import FeedForwardAnalyzer, SFAFeedForwardAnalyzer, ExactFeedForwardAnalyzer
from NCBounds.FixPointAnalyzer import FixPointAnalyzer, SFAFixPointAnalyzer, ExactFixPointAnalyzer, \
GroupFixPointAnalyzer, LinearFixPointAnalyzer
class SmallNetwork(Network):
def __init__(self, u):
super(SmallNetwork, self).__init__([Flow(ArrivalCurve(1, 25 * u), [2, 3, 1]),
Flow(ArrivalCurve(1, 25 * u), [3, 1, 2]),
Flow(ArrivalCurve(1, 25 * u), [1, 0, 2]),
Flow(ArrivalCurve(1, 25 * u), [1, 2, 3])],
[Server(ServiceCurve(100, 1)), Server(ServiceCurve(100, 1)),
Server(ServiceCurve(100, 1)), Server(ServiceCurve(100, 1))])
snk = SmallNetwork(0.5)
print("** The small Network description **")
print(snk)
print("\n ** Transformation into a forest (noy yet with the correct arrival curves)**")
forest_snk = ExactFixPointAnalyzer(snk).nk2forest[0]
print(forest_snk)
print("\n The matrix of xi computed for flow 6 and server 3")
print(ExactFeedForwardAnalyzer(forest_snk).exact_xi([6],3))
print("\n \nComputing the equivalent forest network (with correct arrival curves) and performances")
print("\n\t*SFA method: each flow is decomposed into sub-paths of length 1")
sfa = SFAFixPointAnalyzer(snk)
print(sfa.ff_equiv)
print(sfa.backlog(3, 3))
print("\n\t*Linear-flows method: the network is decomposed into a tree, and an arrival curve is computed for each sub-path")
exact = ExactFixPointAnalyzer(snk)
print(exact.ff_equiv)
print(exact.backlog(3, 3))
print("\n\t*Linear-arc method: the network is decomposed into a tree, and an arrival curve is computed for each arc that has been removed")
group = GroupFixPointAnalyzer(snk)
print(group.ff_equiv)
print(group.backlog(3, 3))
print("\n\t*Linear method: the network is decomposed into a tree, and an arrival curve is computed for each arc that has been removed and each sub-path of the flows")
linear = LinearFixPointAnalyzer(snk)
#print(linear.ff_equiv)
print(linear.backlog(3, 3))
print("\n\nComparing the approaches")
f = open('./small_network.data', 'w')
#f.write("# u\t SFA\t Exact\t Group \t Comby\n")
u=0.01
while u < 1:
snk = SmallNetwork(u)
f.write("%f\t" % u)
f.write("%f\t" % SFAFixPointAnalyzer(snk).backlog(3, 3))
f.write("%f\t" % ExactFixPointAnalyzer(snk).backlog(3, 3))
f.write("%f\t" % GroupFixPointAnalyzer(snk).backlog_bis(3, 3))
f.write("%f\n" % LinearFixPointAnalyzer(snk).backlog(3, 3))
u += 0.01
f.close()
with open('./small_network.data') as f:
lines = f.readlines()
u = [float(line.split()[0]) for line in lines]
sfa = [float(line.split()[1]) for line in lines]
exact = [float(line.split()[2]) for line in lines]
group = [float(line.split()[3]) for line in lines]
combi = [float(line.split()[4]) for line in lines]
f.close()
import matplotlib.pyplot as pl
pl.plot(u,sfa, c='r', label='SFA')
pl.plot(u,exact, c='b', label='Flows')
pl.plot(u,group, c='y', label='Arcs')
pl.plot(u,combi, c='m', label='F+A')
pl.xlabel('Utilization rate')
pl.ylabel('Backlog bound')
pl.legend()
pl.axis([0., 1, 0, 2000])
pl.show()