当前位置:   article > 正文

计算卸载论文阅读01-理论梳理_计算卸载会议

计算卸载会议

标题:When Learning Joins Edge: Real-time Proportional Computation Offloading via Deep Reinforcement Learning

会议:ICPADS 2019

一、梳理

问题:在任务进行卸载时,往往忽略了任务的特定的卸载比例。

模型:针对上述问题,我们提出了一种创新的强化学习(RL)方法来解决比例计算问题。我们考虑了一种常见的卸载场景,该场景具有时变带宽和异构设备,并且设备不断生成应用程序。对于每个应用程序,客户端必须选择本地或远程执行该应用程序,并确定要卸载的比例。我们将该问题制定为一个长期优化问题,然后提出一种基于RL的算法来解决该问题。基本思想是估计可能决策的收益,其中选择收益最大的决策。我们没有采用原来的深度Q网络(DQN),而是通过添加优先级缓冲机制专家缓冲机制,提出了Advanced DQN(ADQN),分别提高了样本的利用率和克服了冷启动问题。

目的:最小化时延和能耗的权值和(优化参数:用户卸载策略卸载的比例)。

算法:ADQN。

二、模型细节与算法

2.1系统模型

计算卸载主要包含: 本地计算和边缘计算

1、本地计算:用户U_i在时隙t_j时的计算时延(计算时延和排队时延)和能耗为

T_{ij}^{l}=D_{ij}^{l}+t_{q}^{l}=\frac{\omega B_{ij}Q_{y_{ij}}}{f_{ij}^{l}}+t_{q}^{l}

E_{ij}^{l}=e_lB_{ij}Q_{y_{ij}}

其中B_{ij}表示任务大小,Q_{y_{ij}}表示本地计算任务的比例

2、边缘计算:包含时延(上下行传输时延+执行时延+排队时延)和能耗
T_{ij}^{r}=D_{ij}^{r}+t_q^r=\frac{\omega B_{ij}P_{y_{ij}}}{F_{ij}^r}+\frac{B_{ij}P_{y_{ij}}}{r_{ul}^{ij}}+\frac{\omega^s B_{ij}}{r_{dl}^{ij}} + t_q^r

E_{ij}^r=e_r B_{ij}P_{y_{ij}}

其中P_{y_{ij}}表示卸载到边缘服务器的比例,\omega^s表示每单位计算任务处理后得到的结果大小。

3、总的时延与能耗成本

W_{ij}=\lambda \max (T_{ij}^r,T_{ij}^l)+\beta(E_{ij}^r+E_{ij}^l)

2.2优化目标

\min \sum_{t_j=1}^{T}[W_{ij}]

       {\tt s.t.}   f_{x_{ij}}^r \leqslant F_{x_{ij}}^r, f_{x_{ij}}^l \leqslant F_{x_{ij}}^l

                r_{ul}^{ij} \leqslant R_{ul}^i, r_{dl}^{ij} \leqslant R_{dl}^i

                x_{ij} \in {1,2,...,m},y_{ij} \in {1,2,...,n}

2.3 State、Action和Reward

1、状态空间:

状态空间包含:(数据大小、本地CPU频率,local可用计算资源,上行速率,下行速率,ES可用计算资源)

2、动作空间:

动作空间包含:(用户选择ES的策略,任务卸载比例)

3、奖励:

奖励:R=\frac{W_l - W(s,a)}{W_l}

W_l表示本地计算成本,W(s,a)表示部分卸载产生的成本。

2.4代码

计算卸载环境代码:

  1. import math
  2. import copy
  3. import numpy as np
  4. class ENV():
  5. def __init__(self, UEs=3, MECs=7, k=33, lam=0.5):
  6. self.UEs = UEs
  7. self.MECs = MECs
  8. self.k = k
  9. q = np.full((k, 1), 0.)
  10. p = np.linspace(0, 1, k).reshape((k, 1))
  11. # Create Action
  12. for i in range(MECs - 1):
  13. a = np.full((k, 1), float(i + 1))
  14. b = np.linspace(0, 1, k).reshape((k, 1))
  15. q = np.append(q, a, axis=0)
  16. p = np.append(p, b, axis=0) # 231(33 * 7) * 33
  17. self.actions = np.hstack((q, p)) # 231 * 2
  18. self.n_actions = len(self.actions) # 231
  19. self.n_features = 3 + MECs * 3 # 3 + 7 * 3
  20. self.discount = 0.01
  21. # 基本参数
  22. # 频率
  23. self.Hz = 1
  24. self.kHz = 1000 * self.Hz
  25. self.mHz = 1000 * self.kHz
  26. self.GHz = 1000 * self.mHz
  27. self.nor = 10 ** (-7)
  28. self.nor1 = 10 ** 19
  29. # 数据大小
  30. self.bit = 1
  31. self.B = 8 * self.bit
  32. self.KB = 1024 * self.B
  33. self.MB = 1024 * self.KB
  34. # self.task_cpu_cycle = np.random.randint(2 * 10**9, 3* 10**9)
  35. self.UE_f = np.random.randint(1.5 * self.GHz * self.nor, 2 * self.GHz * self.nor) # UE的计算能力
  36. self.MEC_f = np.random.randint(5 * self.GHz * self.nor, 7 * self.GHz * self.nor) # MEC的计算能力
  37. # self.UE_f = 500 * self.mHz # UE的计算能力
  38. # self.MEC_f = np.random.randint(5.2 * self.GHz, 24.3 * self.GHz) # MEC的计算能力
  39. self.tr_energy = 1 # 传输能耗
  40. self.r = 40 * math.log2(1 + (16 * 10)) * self.MB * self.nor # 传输速率
  41. # self.r = 800 # 传输速率
  42. self.ew, self.lw = 10 ** (-26), 3 * 10 ** (-26) # 能耗系数
  43. # self.ew, self.lw = 0.3, 0.15 # 能耗系数
  44. self.et, self.lt = 1, 1
  45. self.local_core_max, self.local_core_min = 1.3 * self.UE_f, 0.7 * self.UE_f
  46. self.server_core_max, self.server_core_min = 1.3 * self.MEC_f, 0.7 * self.MEC_f
  47. self.uplink_max, self.uplink_min = 1.3 * self.r, 0.7 * self.r
  48. self.downlink_max, self.downlink_min = 1.3 * self.r, 0.7 * self.r
  49. self.lam = lam
  50. self.e = 1
  51. def reset(self):
  52. # 初始化环境,状态空间
  53. obs = []
  54. servers_cap = []
  55. new_cap = True
  56. for i in range(self.UEs):
  57. uplink, downlink = [], []
  58. # np.random.seed(np.random.randint(1, 1000))
  59. # task_size = np.random.randint(2 * 10**8 * self.nor, 3 * 10**8 * self.nor) # 任务大小
  60. task_size = np.random.randint(1.5 * self.mHz, 2 * self.mHz) # 任务大小
  61. # self.task_size = self.task_size * self.task_cpu_cycle # 处理一个任务所需要的cpu频率
  62. # task_cpu_cycle = np.random.randint(2 * 10**9 * self.nor, 3 * 10**9 * self.nor)
  63. task_cpu_cycle = np.random.randint(10 ** 3, 10 ** 5)
  64. local_comp = np.random.randint(0.9 * self.UE_f, 1.1 * self.UE_f) # UE的计算能力
  65. for i in range(self.MECs):
  66. up = np.random.randint(0.9 * self.r, 1.1 * self.r)
  67. down = np.random.randint(0.9 * self.r, 1.1 * self.r)
  68. if new_cap:
  69. cap = np.random.randint(0.9 * self.MEC_f, 1.1 * self.MEC_f) # MEC计算能力
  70. servers_cap.append(cap)
  71. uplink.append(up)
  72. downlink.append(down)
  73. observation = np.array([task_size, task_cpu_cycle, local_comp])
  74. observation = np.hstack((observation, servers_cap, uplink, downlink))
  75. obs.append(observation)
  76. new_cap = False
  77. return obs
  78. def choose_action(self, prob):
  79. """
  80. 根据概率选择动作
  81. :param prob:
  82. :return:
  83. """
  84. action_choice = np.linspace(0, 1, self.k)
  85. actions = []
  86. for i in range(self.UEs):
  87. a = np.random.choice(a=(self.MECs * self.k), p=prob[i])
  88. target_server = int(a / self.k)
  89. percen = action_choice[a % self.k]
  90. action = [target_server, percen]
  91. actions.append(action)
  92. return actions
  93. def step(self, observation, actions_prob, is_prob=True, is_compared=True):
  94. if is_prob:
  95. actions = self.choose_action(actions_prob)
  96. else:
  97. actions = actions_prob
  98. new_cap = False
  99. obs_ = []
  100. rew, local, ran, mec = [], [], [], []
  101. dpg_times, local_times, ran_times, mec_times = [], [], [], []
  102. dpg_energys, local_energys, ran_energys, mec_energys = [], [], [], []
  103. total = []
  104. a, b, c, d = 0, 0, 0, 0
  105. for i in range(self.UEs):
  106. if i == self.UEs - 1:
  107. new_cap = True
  108. # 提取信息
  109. task_size, task_cpu_cycle, local_comp, servers_cap, uplink, downlink = \
  110. observation[i][0], observation[i][1], observation[i][2], observation[i][3:3+self.MECs], observation[i][3+self.MECs:3+self.MECs*2], observation[i][3+self.MECs*2:3+self.MECs*3]
  111. action = actions[i]
  112. target_server, percen = int(action[0]), action[1]
  113. # 计算奖励
  114. # 1=======部分卸载==========
  115. # 卸载及回传数据产生的时延和能耗
  116. tr_time = (percen * task_size) / uplink[target_server] + self.discount * (percen * task_size) / downlink[
  117. target_server]
  118. tr_energy = (self.tr_energy * percen * task_size) / uplink[target_server] + self.discount * (
  119. self.tr_energy * percen * task_size) / downlink[target_server]
  120. # 本地计算时延和能耗
  121. comp_local_time = task_cpu_cycle * (1 - percen) / (local_comp)
  122. comp_local_energy = self.lw * task_cpu_cycle * (1 - percen) * local_comp ** 2
  123. # 边缘计算时延和能耗
  124. comp_mec_time = (percen * task_cpu_cycle) / servers_cap[target_server]
  125. comp_mec_energy = self.ew * percen * task_cpu_cycle * servers_cap[target_server] ** 2
  126. # 最大计算时延
  127. comp_time = max(comp_local_time, comp_mec_time)
  128. time_cost = (comp_time + tr_time) * self.et
  129. # 能耗成本
  130. energy_cost = (tr_energy + comp_local_energy + comp_mec_energy) * self.e
  131. # 总成本
  132. total_cost = self.lam * time_cost + (1 - self.lam) * energy_cost
  133. # 2、=======完全本地计算==========
  134. local_only_time = task_cpu_cycle / (local_comp) * self.et
  135. local_only_energy = self.lw * task_cpu_cycle * local_comp ** 2 * self.e
  136. # local_only_energy = task_size * local_comp
  137. local_only = self.lam * local_only_time + (1 - self.lam) * local_only_energy
  138. # 3、=======完全边缘计算==========
  139. mec_only_tr_time = task_size / uplink[target_server] + self.discount * task_size / downlink[target_server]
  140. mec_only_tr_energy = self.tr_energy * task_size / uplink[
  141. target_server] + self.discount * self.tr_energy * task_size / downlink[target_server]
  142. # print("mec_only_tr_time:", mec_only_tr_time)
  143. # print("mec_only_tr_energy:", mec_only_tr_energy)
  144. mec_only_comp_time = task_cpu_cycle / servers_cap[target_server]
  145. mec_only_comp_energy = self.ew * task_cpu_cycle * servers_cap[target_server] ** 2
  146. # mec_only_comp_energy = task_size * servers_cap[target_server]
  147. # print("mec_only_comp_time:", mec_only_comp_time)
  148. # print("mec_only_comp_energy:", mec_only_comp_energy)
  149. mec_only_time_cost = (mec_only_tr_time + mec_only_comp_time) * self.et
  150. mec_only_energy_cost = (mec_only_tr_energy + mec_only_comp_energy) * self.e
  151. mec_only = self.lam * mec_only_time_cost + (1 - self.lam) * mec_only_energy_cost
  152. # 4、=======随机卸载==========
  153. percen_ran = np.random.uniform() # 随机卸载比例
  154. mec_ran = np.random.randint(self.MECs) # 随机选择一个服务器进行卸载
  155. random_tr_time = (percen_ran * task_size) / uplink[mec_ran] + (self.discount * percen_ran * task_size) / \
  156. downlink[mec_ran]
  157. random_tr_energy = (self.tr_energy * percen_ran * task_size) / uplink[mec_ran] + self.discount * (
  158. self.tr_energy * percen_ran * task_size) / downlink[mec_ran]
  159. random_comp_local_time = (1 - percen_ran) * task_cpu_cycle / local_comp
  160. random_comp_local_energy = self.lw * (1 - percen_ran) * task_cpu_cycle * local_comp ** 2
  161. # random_comp_local_energy = (1 - percen_ran) * task_size * local_comp
  162. random_comp_mec_time = percen_ran * task_cpu_cycle / servers_cap[mec_ran]
  163. random_comp_mec_energy = self.ew * percen_ran * task_cpu_cycle * servers_cap[mec_ran] ** 2
  164. # random_comp_mec_energy = percen_ran * task_size * servers_cap[mec_ran]
  165. random_comp_time = max(random_comp_local_time, random_comp_mec_time)
  166. random_time_cost = (random_comp_time + random_tr_time) * self.et
  167. random_energy_cost = (random_tr_energy + random_comp_local_energy + random_comp_mec_energy) * self.e
  168. random_total = self.lam * random_time_cost + (1 - self.lam) * random_energy_cost
  169. random_total_cost2 = random_energy_cost
  170. reward = -total_cost
  171. # 得到下一个observation
  172. x = np.random.uniform()
  173. y = 0.5
  174. if x > y:
  175. local_comp = min(local_comp + np.random.randint(0, 0.2 * self.UE_f), self.local_core_max)
  176. for j in range(self.MECs):
  177. cap = min(servers_cap[j] + np.random.randint(0, 0.3 * self.UE_f), self.server_core_max)
  178. # MEC容量保持一致
  179. if new_cap:
  180. for x in range(self.UEs):
  181. observation[x][2 + j] = cap
  182. downlink[j] = min(downlink[j] + np.random.randint(0, 0.2 * self.r), self.downlink_max)
  183. uplink[j] = min(uplink[j] + np.random.randint(0, 0.2 * self.r), self.uplink_max)
  184. else:
  185. local_comp = max(local_comp + np.random.randint(-0.2 * self.UE_f, 0), self.local_core_min)
  186. for j in range(self.MECs):
  187. # MEC容量保持一致
  188. if new_cap:
  189. cap = max(servers_cap[j] + np.random.randint(0, 0.3 * self.UE_f), self.server_core_max)
  190. for x in range(self.UEs):
  191. observation[x][2 + j] = cap
  192. downlink[j] = max(downlink[j] - np.random.randint(0, 0.2 * self.r), self.downlink_min)
  193. uplink[j] = max(uplink[j] - np.random.randint(0, 0.2 * self.r), self.uplink_min)
  194. task_size = np.random.randint(10, 50)
  195. task_cpu_cycle = np.random.randint(10 ** 3, 10 ** 5) # 处理任务所需要的CPU频率
  196. observation_ = np.array([task_size, task_cpu_cycle, local_comp])
  197. observation_ = np.hstack((observation_, servers_cap, uplink, downlink))
  198. obs_.append(observation_)
  199. rew.append(reward)
  200. local.append(local_only)
  201. mec.append(mec_only)
  202. ran.append(random_total)
  203. dpg_times.append(time_cost)
  204. local_times.append(local_only_time)
  205. mec_times.append(mec_only_time_cost)
  206. ran_times.append(random_time_cost)
  207. dpg_energys.append(energy_cost)
  208. local_energys.append(local_only_energy)
  209. mec_energys.append(mec_only_energy_cost)
  210. ran_energys.append(random_energy_cost)
  211. total.append(total_cost)
  212. if is_compared:
  213. return obs_, rew, local, mec, ran, dpg_times, local_times, mec_times, ran_times, dpg_energys, local_energys, mec_energys, ran_energys, total
  214. else:
  215. return obs_, rew, dpg_times, dpg_energys

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/296036
推荐阅读
相关标签
  

闽ICP备14008679号