-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulation.py
44 lines (36 loc) · 1.56 KB
/
simulation.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
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
from managers.AdvertisementManager import *
from managers.ModeratorManager import *
# simulator
def simulate(adManager: AdvertisementManager, modManager: ModeratorManager, allocator) -> (float, float, int):
timestep = 0
while timestep < len(adManager.advertisementStream) and modManager.getModerators() and not adManager.allDone():
# start of round n
adManager.update()
allocator.allocate(adManager.getUnassignedAds(),
modManager.getModerators())
modManager.work()
timestep += 1
print(timestep)
waitLoss = adManager.getLoss()
inaccuracyLoss = allocator.getInaccuracyLoss()
loss = waitLoss + inaccuracyLoss
utilRate = modManager.getUtilRate()
return loss, utilRate, timestep
def simulateExtended(adManager: AdvertisementManager, modManager: ModeratorManager, allocator) -> (float, float, int, list):
timestep = 0
while timestep < len(adManager.advertisementStream) and modManager.getModerators() and not adManager.allDone():
# start of round n
adManager.update()
allocator.allocate(adManager.getUnassignedAds(),
modManager.getModerators())
modManager.work()
timestep += 1
waitLoss = adManager.getLoss()
inaccuracyLoss = allocator.getInaccuracyLoss()
loss = waitLoss + inaccuracyLoss
utilRate = modManager.getUtilRate()
utilRateList = modManager.getUtilRateList()
return loss, utilRate, timestep, utilRateList