-
Notifications
You must be signed in to change notification settings - Fork 0
/
stakeholder.py
69 lines (51 loc) · 1.77 KB
/
stakeholder.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
"""
Author: DURUII
Created: 2023/12/18
Revised: 2023/12/23
Ref:
1. https://github.com/DURUII/Replica-AUCB/blob/main/arms.py
2. "II. SYSTEM MODEL & PROBLEM" of the paper
"""
import math
import random
class SimpleOption:
c_max = 15
def __init__(self, tasks: list[int]):
self.tasks = tasks
self.cost = 0.0
def __str__(self):
return f"SimpleOption(tasks={self.tasks})"
def __repr__(self):
return self.__str__()
def update_cost(self, f, observed_eps):
self.cost = observed_eps * f(len(self.tasks)) / SimpleOption.c_max
# SimpleOption.c_max = max(self.cost, SimpleOption.c_max)
# SimpleOption.c_min = min(self.cost, SimpleOption.c_min)
return self
class Task:
def __init__(self, weight: float):
self.w = weight
def __str__(self):
return f"Task(weight={self.w})"
def __repr__(self):
return self.__str__()
class Worker:
eps_min = 0.1
def __init__(self, e: float, q: float, options: list[SimpleOption]):
# in original problem, eps (cost parameter) -> prior, fixed value
self.mu_e = e
self.mu_q = q
self.sigma_q = random.uniform(0, min(q / 3, (1 - q) / 3))
self.options = options
# if extended, eps (cost parameter) -> sampled from a distribution
self.sigma_e = random.uniform(0, min(e / 3, (1 - e) / 3))
def draw(self):
""" universally used in algorithm 1 & 2 """
return random.gauss(self.mu_q, self.sigma_q)
def epsilon(self):
""" only used in extended problem setting """
return random.gauss(self.mu_e, self.sigma_e)
def __str__(self):
return f"Worker(e={self.mu_e}, q={self.mu_q}, options={self.options})"
def __repr__(self):
return self.__str__()