-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.py
65 lines (56 loc) · 2.03 KB
/
runner.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
from monitoring import Monitoring
from simulation import Simulation
from generators import Generator
from applications import Application
from controllers import StaticController
import time
import uuid
class Runner:
def __init__(self, hrz: int, cts: list, window: int, app: Application, genMonitoring = None, name="run"):
self.app = app
self.sla = self.app.sla
self.horizon = hrz
self.controllers = cts
self.window = window
self.simulations = []
self.genMonitoring = genMonitoring
self.name = name
def run(self, gen: Generator):
print("********************* %s ********************\n" % (gen,))
for ct in self.controllers:
ct.setSLA(self.sla)
if self.genMonitoring:
m = self.genMonitoring(self.window, self.sla)
else:
m = Monitoring(self.window, self.sla)
ct.setMonitoring(m)
ct.setGenerator(gen)
a = self.app
#mi serve per far partire i controllori con un punto iniziale feasible
if(not isinstance(ct, StaticController)):
ct.init_cores=max(int(gen.tick(0)*0.01), 1)
self.app.cores=max(int(gen.tick(0)*0.01), 1)
s = Simulation(self.horizon, a, gen, m, ct)
s.run()
self.simulations.append(s)
ct.reset()
a.reset()
# print()
def log(self):
ts = time.time()
id = uuid.uuid1()
f = open(f'sim-{self.name}-{ts}-{str(id)}.log', "w")
for s in self.simulations:
res = s.log()
print(res)
f.write(res)
f.close()
def plot(self):
for s in self.simulations:
s.plot()
def getTotalViolations(self):
print([s.getTotalViolations() for s in self.simulations])
return sum([s.getTotalViolations() for s in self.simulations])
def exportData(self):
for s in self.simulations:
s.exportData()