-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_env.py
120 lines (95 loc) · 3.03 KB
/
test_env.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from parameters import configs
from environment.env import SPP
from instance_generator import one_instance_gen
import numpy as np
import time
def main():
SEED = 20238
np.random.seed(SEED)
n_jobs = configs.n_jobs
n_devices = configs.n_devices
n_features = len(configs.feature_labels)
times, adj, feat = one_instance_gen(n_jobs,n_devices,configs.cloud_features,configs.DAG_rand_dependencies_factor)
print("HW features: ")
print(configs.feature_labels)
print(feat)
t1 = time.time()
# Environment
env = SPP(number_jobs=n_jobs,number_devices=n_devices,number_features=n_features)
print("Reset environment")
alloc, state, omega, mask = env.reset(times,adj,feat)
print("LBs")
print(env.LBs)
print("Costs")
print(env.Costs)
print("Initial time:")
print(np.sum(env.LBs))
print(env.max_endTime)
print("Initial COST:")
print(np.sum(env.Costs))
print(env.max_endCost)
print("posRewards")
print(env.posRewards)
print("Allocations")
print(alloc)
print("Start All the placements:")
rewards = [- env.initQuality]
print("*"*30)
while True:
print("\tEnv.step: ",env.step_count)
print("*"*30)
ix_job = np.random.choice(len(omega[~mask]))
candidate_task = omega[~mask][ix_job]
print("Candidate_job: ",candidate_task)
# device = env.selectRndDevice()
# device = env.selectBestCostDevice()
# device = env.selectBestLatencyDevice()
device = env.selectCloudDevice()
print('Action:', device)
alloc, (state_t,state_m), reward, done, omega, mask = env.step(candidate_task,device)
rewards.append(reward)
print("Post alloc by task")
print(env.opIDsOnMchs)
# print("post State M")
# print(state_m)
print("post State T")
print(state_t)
# print(featTasks.shape)
# print("post OMEGA\n",omega)
# print("post Mask\n",mask)
# print("post Alloc")
# print(env.allocations)
print('post LBs:\n', env.LBs)
print('post Costs:\n', env.Costs)
print("post reward:\n", reward)
print("post posReward:\n", env.posRewards)
# print("post featuresTasks:\n", state)
# input("Press Enter to continue...") #debug
if env.done():
break
print("DONE")
print("+"*30)
makespan = sum(rewards) - env.posRewards
t2 = time.time()
print("MakeSpan")
print(makespan)
print("LB")
print(env.LBs)
print(np.sum(env.LBs))
print("Cost")
print(env.Costs)
print(np.sum(env.Costs))
# print("time")
# print(t2 - t1)
# # np.save('sol', env.opIDsOnMchs // n_m)
# np.save('jobSequence', env.opIDsOnMchs)
# np.save('testData', data)
print("Allocations by task")
print(env.opIDsOnMchs)
print("Number of steps")
print(env.step_count)
print("Rewards")
print(rewards)
print(sum(rewards)) # equivalent to: -1 * np.sum(env.LBs)
if __name__ == '__main__':
main()