-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostLayer
More file actions
42 lines (35 loc) · 1.13 KB
/
Copy pathHostLayer
File metadata and controls
42 lines (35 loc) · 1.13 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
import math
class HostLayer:
def __init__(self, alpha_0=0.007297, h_0=6.626e-34, G_0=6.674e-11, max_capacity=1e15):
self.alpha_0 = alpha_0
self.h_0 = h_0
self.G_0 = G_0
self.max_capacity = max_capacity
self.v_log = 1.0
self.nu_max = 3e18
def append_registry(self, transaction_count):
if transaction_count <= 0:
return
self.v_log += float(transaction_count)
def get_runtime_constants(self):
load_factor = self.v_log / self.max_capacity
if load_factor > 1.0:
load_factor = 1.0
if self.v_log <= 1.0:
c = self.nu_max
else:
c = self.nu_max / (1.0 + self.alpha_0 * math.log(self.v_log))
h = self.h_0 * (1.0 + 0.05 * load_factor)
G = self.G_0 * (1.0 + 0.1 * load_factor)
if c <= 0:
ell_p = float('inf')
else:
ell_p = math.sqrt((h * G) / math.pow(c, 3))
return {
"v_log": self.v_log,
"load_factor": load_factor,
"c": c,
"h": h,
"G": G,
"ell_p": ell_p
}