-
Notifications
You must be signed in to change notification settings - Fork 9
/
provider.py
45 lines (28 loc) · 1.3 KB
/
provider.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
import random
import numpy as np
from scipy.stats import truncnorm
class Provider():
def __init__(self, max_mu, max_provider_bid, time_unit):
self.mean_ = 0.1 + np.around(random.uniform(0, max_mu), decimals = 2)
self.sigma_ = 2*self.mean_
self.bid_ = 0.1 + np.around(random.uniform(0, max_provider_bid), decimals = 2)
self.time_unit = time_unit
#self.submission_time = 0
def prob_distribution(self, task):
x_axis = np.arange(0,task.expiry_+self.time_unit, self.time_unit)
a = task.deadline_
b = task.expiry_
probability = truncnorm.pdf(x_axis, -b, b, loc = a*self.mean_, scale = self.sigma_)
cdf = truncnorm.cdf(x_axis, -b, b, loc = a*self.mean_, scale = self.sigma_)
probability = probability / ((cdf[-1] - cdf[0]))
cdf = (cdf - cdf[0]) / ((cdf[-1] - cdf[0]))
return probability, cdf, x_axis
def submit(self, task):
#if self.submission_time == 0:
probability, cdf, x_axis = self.prob_distribution(task)
denominator = sum(probability)
t_sub = np.random.choice(x_axis, p = probability / denominator)
# self.submission_time = t_sub
#else:
# t_sub = self.submission_time
return t_sub