-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuserfunctions.py
More file actions
78 lines (53 loc) · 1.87 KB
/
userfunctions.py
File metadata and controls
78 lines (53 loc) · 1.87 KB
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
from ast import arg
from scipy.stats import truncnorm
import numpy as np
def myfunction(*args):
posarg, posarg2 = args
#print(kwargs)
#rq_rate = kwargs["request_rate"]
print(posarg)
return (posarg + posarg2) /10
def truncated_normal(*args):
lower, upper, mean, stdev = args
a, b = (lower - mean) / stdev, (upper - mean) / stdev
return truncnorm.rvs(a,b, loc= mean, scale=stdev)
def normal(*args):
mean, stdev = args
return np.random.normal(loc=mean,scale=stdev)
def uniform(*args):
lower, upper = args
return np.random.uniform(low=lower,high=upper)
def truncate(utility):
bounds = (140,300)
lower_bound, upper_bound = bounds
if(utility > upper_bound): utility = upper_bound
elif(utility < lower_bound): utility = lower_bound
range = upper_bound - lower_bound
result = float((utility - lower_bound)/range)
return result
def utilitySWIM(arrival_rate, dimmer, avg_response_time, max_servers, servers):
OPT_REVENUE = 1.5
BASIC_REVENUE = 1
SERVER_COST = 10
RT_THRESH = 0.75
ur = arrival_rate * ((1 - dimmer) * BASIC_REVENUE + dimmer * OPT_REVENUE)
uc = SERVER_COST * (max_servers - servers)
urt = 1 - ((avg_response_time-RT_THRESH)/RT_THRESH)
UPPER_RT_THRESHOLD = RT_THRESH * 4
delta_threshold = UPPER_RT_THRESHOLD-RT_THRESH
UrtPosFct = (delta_threshold/RT_THRESH)
urt = None
if(avg_response_time <= UPPER_RT_THRESHOLD):
urt = ((RT_THRESH - avg_response_time)/RT_THRESH)
else:
urt = ((RT_THRESH - UPPER_RT_THRESHOLD)/RT_THRESH)
urt_final = None
if(avg_response_time <= RT_THRESH):
urt_final = urt*UrtPosFct
else:
urt_final = urt
revenue_weight = 0.7
server_weight = 0.3
utility = urt_final*((revenue_weight*ur)+(server_weight*uc))
truncated_reward = truncate(utility)
return truncated_reward