forked from hongzimao/deeprm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_distribution.py
executable file
·86 lines (56 loc) · 2.52 KB
/
job_distribution.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import numpy as np
class Dist:
def __init__(self, num_res, max_nw_size, job_len):
self.num_res = num_res
self.max_nw_size = max_nw_size
self.job_len = job_len
self.job_small_chance = 0.8
self.job_len_big_lower = job_len * 2 / 3
self.job_len_big_upper = job_len
self.job_len_small_lower = 1
self.job_len_small_upper = job_len / 5
self.dominant_res_lower = max_nw_size / 2
self.dominant_res_upper = max_nw_size
self.other_res_lower = 1
self.other_res_upper = max_nw_size / 5
def normal_dist(self):
# new work duration
nw_len = np.random.randint(1, self.job_len + 1) # same length in every dimension
nw_size = np.zeros(self.num_res)
for i in range(self.num_res):
nw_size[i] = np.random.randint(1, self.max_nw_size + 1)
return nw_len, nw_size
def bi_model_dist(self):
# -- job length --
if np.random.rand() < self.job_small_chance: # small job
nw_len = np.random.randint(self.job_len_small_lower,
self.job_len_small_upper + 1)
else: # big job
nw_len = np.random.randint(self.job_len_big_lower,
self.job_len_big_upper + 1)
nw_size = np.zeros(self.num_res)
# -- job resource request --
dominant_res = np.random.randint(0, self.num_res)
for i in range(self.num_res):
if i == dominant_res:
nw_size[i] = np.random.randint(self.dominant_res_lower,
self.dominant_res_upper + 1)
else:
nw_size[i] = np.random.randint(self.other_res_lower,
self.other_res_upper + 1)
return nw_len, nw_size
def generate_sequence_work(pa, seed=42):
print("job distribution generate sequence work.")
np.random.seed(seed)
simu_len = pa.simu_len * pa.num_ex
nw_dist = pa.dist.bi_model_dist
nw_len_seq = np.zeros(simu_len, dtype=int)
nw_size_seq = np.zeros((simu_len, pa.num_res), dtype=int)
for i in range(simu_len):
if np.random.rand() < pa.new_job_rate: # a new job comes
nw_len_seq[i], nw_size_seq[i, :] = nw_dist()
nw_len_seq = np.reshape(nw_len_seq,
[pa.num_ex, pa.simu_len])
nw_size_seq = np.reshape(nw_size_seq,
[pa.num_ex, pa.simu_len, pa.num_res])
return nw_len_seq, nw_size_seq