forked from linkpark/metarl-offloading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate_opt_solution.py
174 lines (143 loc) · 9.2 KB
/
calculate_opt_solution.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import numpy as np
from env.mec_offloaing_envs.offloading_env import Resources
from env.mec_offloaing_envs.offloading_env import OffloadingEnvironment
from utils import utils
if __name__ == "__main__":
resource_cluster = Resources(mec_process_capable=(10.0 * 1024 * 1024),
mobile_process_capable=(1.0 * 1024 * 1024),
bandwidth_up=7.0, bandwidth_dl=7.0)
env = OffloadingEnvironment(resource_cluster=resource_cluster,
batch_size=100,
graph_number=100,
graph_file_paths=[
"./env/mec_offloaing_envs/data/meta_offloading_20/offload_random20_4/random.20."
],
time_major=False)
env.set_task(0)
print("calculate optimal solution offloading20_4======")
cost, plan = env.calculate_optimal_solution()
target_batch, task_finish_time_batch = env.get_reward_batch_step_by_step(plan,
env.task_graphs_batchs[env.task_id],
env.max_running_time_batchs[env.task_id],
env.min_running_time_batchs[env.task_id])
discounted_reward = []
for reward_path in target_batch:
discounted_reward.append(utils.discount_cumsum(reward_path, 1.0)[0])
print("avg optimal solution: ", np.mean(discounted_reward))
print("avg optimal solution: ", np.mean(task_finish_time_batch))
print("avg optimal solution: ", np.mean(cost))
resource_cluster = Resources(mec_process_capable=(10.0 * 1024 * 1024),
mobile_process_capable=(1.0 * 1024 * 1024),
bandwidth_up=7.0, bandwidth_dl=7.0)
env = OffloadingEnvironment(resource_cluster=resource_cluster,
batch_size=100,
graph_number=100,
graph_file_paths=[
"./env/mec_offloaing_envs/data/meta_offloading_20/offload_random20_8/random.20."
],
time_major=False)
env.set_task(0)
print("calculate optimal solution offloading20_8======")
cost, plan = env.calculate_optimal_solution()
target_batch, task_finish_time_batch = env.get_reward_batch_step_by_step(plan,
env.task_graphs_batchs[env.task_id],
env.max_running_time_batchs[env.task_id],
env.min_running_time_batchs[env.task_id])
discounted_reward = []
for reward_path in target_batch:
discounted_reward.append(utils.discount_cumsum(reward_path, 1.0)[0])
print("avg optimal solution: ", np.mean(discounted_reward))
print("avg optimal solution: ", np.mean(task_finish_time_batch))
print("avg optimal solution: ", np.mean(cost))
resource_cluster = Resources(mec_process_capable=(10.0 * 1024 * 1024),
mobile_process_capable=(1.0 * 1024 * 1024),
bandwidth_up=7.0, bandwidth_dl=7.0)
env = OffloadingEnvironment(resource_cluster=resource_cluster,
batch_size=100,
graph_number=100,
graph_file_paths=[
"./env/mec_offloaing_envs/data/meta_offloading_20/offload_random20_12/random.20."
],
time_major=False)
env.set_task(0)
print("calculate optimal solution offloading20_12======")
cost, plan = env.calculate_optimal_solution()
target_batch, task_finish_time_batch = env.get_reward_batch_step_by_step(plan,
env.task_graphs_batchs[env.task_id],
env.max_running_time_batchs[env.task_id],
env.min_running_time_batchs[env.task_id])
discounted_reward = []
for reward_path in target_batch:
discounted_reward.append(utils.discount_cumsum(reward_path, 1.0)[0])
print("avg optimal solution: ", np.mean(discounted_reward))
print("avg optimal solution: ", np.mean(task_finish_time_batch))
print("avg optimal solution: ", np.mean(cost))
resource_cluster = Resources(mec_process_capable=(10.0 * 1024 * 1024),
mobile_process_capable=(1.0 * 1024 * 1024),
bandwidth_up=7.0, bandwidth_dl=7.0)
env = OffloadingEnvironment(resource_cluster=resource_cluster,
batch_size=100,
graph_number=100,
graph_file_paths=[
"./env/mec_offloaing_envs/data/meta_offloading_20/offload_random20_16/random.20."
],
time_major=False)
env.set_task(0)
print("calculate optimal solution offloading20_16======")
cost, plan = env.calculate_optimal_solution()
target_batch, task_finish_time_batch = env.get_reward_batch_step_by_step(plan,
env.task_graphs_batchs[env.task_id],
env.max_running_time_batchs[env.task_id],
env.min_running_time_batchs[env.task_id])
discounted_reward = []
for reward_path in target_batch:
discounted_reward.append(utils.discount_cumsum(reward_path, 1.0)[0])
print("avg optimal solution: ", np.mean(discounted_reward))
print("avg optimal solution: ", np.mean(task_finish_time_batch))
print("avg optimal solution: ", np.mean(cost))
resource_cluster = Resources(mec_process_capable=(10.0 * 1024 * 1024),
mobile_process_capable=(1.0 * 1024 * 1024),
bandwidth_up=7.0, bandwidth_dl=7.0)
env = OffloadingEnvironment(resource_cluster=resource_cluster,
batch_size=100,
graph_number=100,
graph_file_paths=[
"./env/mec_offloaing_envs/data/meta_offloading_20/offload_random20_20/random.20."
],
time_major=False)
env.set_task(0)
print("calculate optimal solution offloading20_20======")
cost, plan = env.calculate_optimal_solution()
target_batch, task_finish_time_batch = env.get_reward_batch_step_by_step(plan,
env.task_graphs_batchs[env.task_id],
env.max_running_time_batchs[env.task_id],
env.min_running_time_batchs[env.task_id])
discounted_reward = []
for reward_path in target_batch:
discounted_reward.append(utils.discount_cumsum(reward_path, 1.0)[0])
print("avg optimal solution: ", np.mean(discounted_reward))
print("avg optimal solution: ", np.mean(task_finish_time_batch))
print("avg optimal solution: ", np.mean(cost))
resource_cluster = Resources(mec_process_capable=(10.0 * 1024 * 1024),
mobile_process_capable=(1.0 * 1024 * 1024),
bandwidth_up=7.0, bandwidth_dl=7.0)
env = OffloadingEnvironment(resource_cluster=resource_cluster,
batch_size=100,
graph_number=100,
graph_file_paths=[
"./env/mec_offloaing_envs/data/meta_offloading_20/offload_random20_24/random.20."
],
time_major=False)
env.set_task(0)
print("calculate optimal solution offloading20_24======")
cost, plan = env.calculate_optimal_solution()
target_batch, task_finish_time_batch = env.get_reward_batch_step_by_step(plan,
env.task_graphs_batchs[env.task_id],
env.max_running_time_batchs[env.task_id],
env.min_running_time_batchs[env.task_id])
discounted_reward = []
for reward_path in target_batch:
discounted_reward.append(utils.discount_cumsum(reward_path, 1.0)[0])
print("avg optimal solution: ", np.mean(discounted_reward))
print("avg optimal solution: ", np.mean(task_finish_time_batch))
print("avg optimal solution: ", np.mean(cost))