├── README.md ├── task scheduling.pdf └── task_scheduling.py /README.md: -------------------------------------------------------------------------------- 1 | # Task-Scheduling-under-Mobile-Cloud-Computing-Environment 2 | The python implementations of paper [Energy and Performance-Aware Task Scheduling in a Mobile Cloud Computing Environment](http://www.mpedram.com/Papers/task-sched-MCC-cloud14.pdf) 3 | 4 | # Algorithm Overview 5 | - Step 1: initial scheduling, without considering the energy consumption. 6 | - Step 2: rescheduling to find the optimal one with least energy consumption under time constraint. 7 | 8 | 9 | # Implementation 10 | - We use *class Node* to represent the node variables 11 | - Two test samples are provided in the *main function*. One test samples is the same as the sample givin in the paper. 12 | - Also, please refer **task scheduling.pdf** for more specific details. 13 | 14 | 15 | Note: please refer this project if you want to use the implementation, thanks. 16 | -------------------------------------------------------------------------------- /task scheduling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derekkk/Task-Scheduling-under-Mobile-Cloud-Computing-Environment/58c88d58dab7483d830226475a47b44c64a53fed/task scheduling.pdf -------------------------------------------------------------------------------- /task_scheduling.py: -------------------------------------------------------------------------------- 1 | # File: 2 | # -*- coding: utf-8 -*- 3 | # @Time : 11/29/2018 7:25 PM 4 | # @Author : Derek Hu 5 | from copy import deepcopy 6 | import time 7 | 8 | # define node class 9 | class Node(object): 10 | def __init__(self, id, parents, children, core_speed, cloud_speed): 11 | self.id = id 12 | self.parents = parents # list of Nodes 13 | self.children = children # list of Nodes 14 | self.core_speed = core_speed # list: [9, 7, 5] for core1, core2 and core3 15 | self.cloud_speed = cloud_speed # list [3, 1, 1] cloud speed 16 | self.ft_l = 0 # local finish time, inf at start 17 | self.ft_ws = 0 18 | self.ft_c = 0 19 | self.ft_wr = 0 20 | self.ready_time = -1 # local ready time 21 | self.rt_ws = -1 # cloud ready time 22 | self.rt_c = -1 23 | self.rt_wr = -1 24 | self.is_core = None 25 | self._local_cloud() # compute self.is_core 26 | self._computation_cost() 27 | self.priority_socre = None 28 | self.assignment = -2 # 0, 1, 2, 3 29 | self.start_time = [-1, -1, -1, -1] # start time for core1, core2, core3, cloud 30 | self.is_scheduled = None 31 | 32 | def _local_cloud(self): 33 | """determine if local or cloud, here assume core3 is faster than others""" 34 | t_l_min = self.core_speed[2] 35 | t_c_min = 5 # assume cloud is always 5 36 | if t_l_min <= t_c_min: 37 | self.is_core = True 38 | self.ft_ws = 0 39 | self.ft_c = 0 40 | self.ft_wr = 0 41 | else: 42 | self.is_core = False 43 | self.ft_l = 0 44 | 45 | def _computation_cost(self): 46 | """calculate w_i in section 3""" 47 | self.w_i = 0 48 | if self.is_core == True: 49 | self.w_i = sum(self.core_speed) / len(self.core_speed) 50 | else: 51 | self.w_i = 5 52 | 53 | 54 | def total_T(nodes): 55 | """compute the total time""" 56 | total_t = 0 57 | for node in nodes: 58 | if len(node.children) == 0: 59 | total_t = max(node.ft_l, node.ft_wr) 60 | return total_t 61 | 62 | def total_E(nodes, core_cloud_power=[1, 2, 4, 0.5]): 63 | """compute total energy 64 | core_cloud_power: [1, 2, 4, 0.5] for core1, core2, core3, cloud sending 65 | """ 66 | total_energy = 0 67 | for node in nodes: 68 | if node.is_core == True: 69 | current_node_e = node.core_speed[node.assignment] * core_cloud_power[node.assignment] 70 | total_energy += current_node_e 71 | if node.is_core == False: 72 | current_node_e = node.cloud_speed[0] * core_cloud_power[3] 73 | total_energy += current_node_e 74 | return total_energy 75 | 76 | def primary_assignment(nodes): 77 | """primary assignment, input is a list of nodes""" 78 | # [c1, c2, c3, sending, cloud, receiving] 79 | local_source = [0, 0, 0] 80 | cloud_source = [0, 0, 0] 81 | # core and cloud sequence after assignment 82 | core1_seq = [] 83 | core2_seq = [] 84 | core3_seq = [] 85 | cloud_seq = [] # here we assume cloud cost is same for each node, and the seq of 3 process are always the same 86 | 87 | for i, node in enumerate(nodes): 88 | if node.is_core == True: # local task 89 | if len(node.parents) == 0: 90 | node.ready_time = 0 91 | else: # equation (3) 92 | for p in node.parents: 93 | p_ft = max(p.ft_l, p.ft_wr) 94 | if p_ft > node.ready_time: 95 | node.ready_time = p_ft 96 | 97 | core_1_finishtime = max(local_source[0], node.ready_time) + node.core_speed[0] 98 | core_2_finishtime = max(local_source[1], node.ready_time) + node.core_speed[1] 99 | core_3_finishtime = max(local_source[2], node.ready_time) + node.core_speed[2] 100 | # choose the fastest one 101 | core_assign_id = 0 102 | core_assign_finishtime = core_1_finishtime 103 | if core_assign_finishtime > core_2_finishtime: 104 | core_assign_finishtime = core_2_finishtime 105 | core_assign_id = 1 106 | if core_assign_finishtime > core_3_finishtime: 107 | core_assign_finishtime = core_3_finishtime 108 | core_assign_id = 2 109 | node.assignment = core_assign_id 110 | node.ft_l = core_assign_finishtime 111 | node.start_time[core_assign_id] = max(local_source[core_assign_id], node.ready_time) 112 | # update the ready time of the children nodes 113 | # current_node_ft = max(node.ft_l, node.ft_wr) 114 | # for child_node in node.children: 115 | # if child_node.ready_time < current_node_ft: 116 | # child_node.ready_time = current_node_ft 117 | # local source assignment 118 | local_source[core_assign_id] = node.ft_l 119 | 120 | # add the node to core seq 121 | if node.assignment == 0: 122 | core1_seq.append(node.id) 123 | if node.assignment == 1: 124 | core2_seq.append(node.id) 125 | if node.assignment == 2: 126 | core3_seq.append(node.id) 127 | 128 | print("node id:{}, assigenment:{}, ready time: {}, local start_time: {}". 129 | format(node.id, node.assignment+1, node.ready_time, node.start_time[node.assignment])) 130 | print(local_source) 131 | print("-----------") 132 | 133 | if node.is_core == False: # cloud task 134 | # equation (4) 135 | for p in node.parents: 136 | p_ws = max(p.ft_l, p.ft_ws) 137 | if p_ws > node.rt_ws: 138 | node.rt_ws = p_ws 139 | cloud_ws_finishtime = max(cloud_source[0], node.rt_ws) + node.cloud_speed[0] 140 | node.ft_ws = cloud_ws_finishtime 141 | # (5) 142 | p_max_ft_c = 0 143 | for p in node.parents: 144 | if p.ft_c > p_max_ft_c: 145 | p_max_ft_c = p.ft_c 146 | node.rt_c = max(node.ft_ws, p_max_ft_c) 147 | cloud_c_finishtime = max(cloud_source[1], node.rt_c) + node.cloud_speed[1] 148 | node.ft_c = cloud_c_finishtime 149 | #(6) 150 | node.rt_wr = node.ft_c 151 | cloud_wr_finishtime = max(cloud_source[2], node.rt_wr) + node.cloud_speed[2] 152 | node.ft_wr = cloud_wr_finishtime 153 | node.assignment = 3 # 3 is cloud 154 | node.start_time[3] = max(cloud_source[0], node.rt_ws) # cloud task start time is sending start time 155 | 156 | cloud_source[0] = cloud_ws_finishtime 157 | cloud_source[1] = cloud_c_finishtime 158 | cloud_source[2] = cloud_wr_finishtime 159 | 160 | cloud_seq.append(node.id) 161 | print("node id:{}, assigenment:{}, ws ready time: {}, c ready time: {}, wr ready time: {}, cloud start time: {}". 162 | format(node.id, node.assignment + 1, node.rt_ws, node.rt_c, node.rt_wr, node.start_time[3])) 163 | print(local_source) 164 | print("-----------") 165 | print(cloud_source) 166 | print("total time: ", total_T(nodes)) 167 | print("total energy: ", total_E(nodes, [1, 2, 4, 0.5])) 168 | print([i for i in core1_seq]) 169 | print([i for i in core2_seq]) 170 | print([i for i in core3_seq]) 171 | print([i for i in cloud_seq]) 172 | seq = [core1_seq, core2_seq, core3_seq, cloud_seq] 173 | return seq 174 | 175 | 176 | def new_squence(nodes, tar_id, k, seq): 177 | """ 178 | compute new scheduling seq 179 | :param nodes: node list 180 | :param tar_id: index of target node 181 | :param k: migration location: [0, 1, 2, 3] means: core1, core2, core3, cloud 182 | :param seq: current core sequence: [core1_seq, core2_seq, core3_seq, cloud_seq], each one is a list of node_ids 183 | :return: 184 | """ 185 | node_index = {} #{key-node.id: value-index in nodes} 186 | temp_id = 0 187 | for _node in nodes: 188 | node_index[_node.id] = temp_id 189 | temp_id += 1 190 | if _node.id == tar_id: 191 | node_tar = _node 192 | if node_tar.is_core == True: # calculate tar ready time in (19) 193 | node_tar_rt = node_tar.ready_time 194 | if node_tar.is_core == False: 195 | node_tar_rt = node_tar.rt_ws 196 | seq[node_tar.assignment].remove(node_tar.id) # original core seq 197 | s_new = seq[k] # S_new in (19) 198 | s_new_prim = [] 199 | flag = False 200 | for _node_id in s_new: 201 | _node = nodes[node_index[_node_id]] 202 | if _node.start_time[k] < node_tar_rt: 203 | s_new_prim.append(_node.id) 204 | if _node.start_time[k] >= node_tar_rt and flag == False: 205 | s_new_prim.append(node_tar.id) 206 | flag = True 207 | if _node.start_time[k] >= node_tar_rt and flag == True: 208 | s_new_prim.append(_node.id) 209 | if flag == False: 210 | s_new_prim.append(node_tar.id) 211 | seq[k] = s_new_prim 212 | node_tar.assignment = k 213 | if k == 3: 214 | node_tar.is_core = False 215 | else: 216 | node_tar.is_core = True 217 | 218 | return seq 219 | 220 | 221 | def kernel_algorithm(nodes_new, seq_new): 222 | """ 223 | kernel algorithm 224 | :param nodes_new: node list 225 | :param seq_new: current core sequence: [core1_seq, core2_seq, core3_seq, cloud_seq], each one is a list of nodes 226 | """ 227 | 228 | local_source = [0, 0, 0] 229 | cloud_source = [0, 0, 0] 230 | 231 | ready1 = [-1]*len(nodes_new) # [-1s] at start, ready1[i] is for node.id==i 232 | ready2 = [-1]*len(nodes_new) 233 | ready1[nodes_new[0].id - 1] = 0 # id start from 1 234 | for each_seq in seq_new: 235 | if len(each_seq) > 0: 236 | ready2[each_seq[0] - 1] = 0 237 | # print(ready1, ready2) 238 | 239 | node_index = {} # {key-node.id: value-index in nodes} 240 | temp_id = 0 241 | for _node in nodes_new: 242 | node_index[_node.id] = temp_id 243 | _node.ready_time = -1 # local ready time 244 | _node.rt_ws = -1 # cloud ready time 245 | _node.rt_c = -1 246 | _node.rt_wr = -1 247 | temp_id += 1 248 | 249 | # start the rescheduling task 250 | stack = [] # LIFO stack 251 | stack.append(nodes_new[0]) 252 | 253 | while len(stack) != 0: # not empty 254 | v_i = stack.pop() 255 | v_i.is_scheduled = "kernel_scheduled" # means is scheduled 256 | # first, calculate v_i local ready time 257 | if v_i.is_core == True: # local task 258 | if len(v_i.parents) == 0: 259 | v_i.ready_time = 0 260 | else: # equation (3) 261 | for p in v_i.parents: 262 | p_ft = max(p.ft_l, p.ft_wr) 263 | if p_ft > v_i.ready_time: 264 | v_i.ready_time = p_ft 265 | 266 | # part 2: schedule on the corresponding core 267 | if v_i.assignment == 0: # local core1 268 | v_i.start_time = [-1, -1, -1, -1] 269 | v_i.start_time[0] = max(local_source[0], v_i.ready_time) 270 | v_i.ft_l = v_i.start_time[0] + v_i.core_speed[0] 271 | v_i.ft_ws = -1 272 | v_i.ft_c = -1 273 | v_i.ft_wr = -1 274 | local_source[0] = v_i.ft_l 275 | if v_i.assignment == 1: # local core2 276 | v_i.start_time = [-1, -1, -1, -1] 277 | v_i.start_time[1] = max(local_source[1], v_i.ready_time) 278 | v_i.ft_l = v_i.start_time[1] + v_i.core_speed[1] 279 | v_i.ft_ws = -1 280 | v_i.ft_c = -1 281 | v_i.ft_wr = -1 282 | local_source[1] = v_i.ft_l 283 | if v_i.assignment == 2: # local core3 284 | v_i.start_time = [-1, -1, -1, -1] 285 | v_i.start_time[2] = max(local_source[2], v_i.ready_time) 286 | v_i.ft_l = v_i.start_time[2] + v_i.core_speed[2] 287 | v_i.ft_ws = -1 288 | v_i.ft_c = -1 289 | v_i.ft_wr = -1 290 | local_source[2] = v_i.ft_l 291 | 292 | if v_i.assignment == 3: # cloud 293 | if len(v_i.parents) == 0: # 1. sending 294 | v_i.rt_ws = 0 295 | else: 296 | for p in v_i.parents: 297 | p_ws = max(p.ft_l, p.ft_ws) 298 | if p_ws > v_i.rt_ws: 299 | v_i.rt_ws = p_ws 300 | v_i.ft_ws = max(cloud_source[0], v_i.rt_ws) + v_i.cloud_speed[0] 301 | v_i.start_time = [-1, -1, -1, -1] 302 | v_i.start_time[3] = max(cloud_source[0], v_i.rt_ws) 303 | cloud_source[0] = v_i.ft_ws 304 | 305 | p_max_ft_c = 0 # 2. cloud part 306 | for p in v_i.parents: 307 | if p.ft_c > p_max_ft_c: 308 | p_max_ft_c = p.ft_c 309 | v_i.rt_c = max(v_i.ft_ws, p_max_ft_c) 310 | v_i.ft_c = max(cloud_source[1], v_i.rt_c) + v_i.cloud_speed[1] 311 | cloud_source[1] = v_i.ft_c 312 | 313 | v_i.rt_wr = v_i.ft_c # 3. receiveing part 314 | v_i.ft_wr = max(cloud_source[2], v_i.rt_wr) + v_i.cloud_speed[2] 315 | v_i.ft_l = -1 316 | cloud_source[2] = v_i.ft_wr 317 | 318 | 319 | # if v_i.is_core == True: 320 | # print("node id:{}, assigenment:{}, ready time: {}, local start_time: {}, is_scheduled: {}". 321 | # format(v_i.id, v_i.assignment + 1, v_i.ready_time, v_i.start_time[v_i.assignment], v_i.is_scheduled)) 322 | # print(local_source, cloud_source) 323 | # print("-----------") 324 | # else: 325 | # print( 326 | # "node id:{}, assigenment:{}, ws ready time: {}, c ready time: {}, wr ready time: {}, cloud start time: {}, is_scheduled: {}". 327 | # format(v_i.id, v_i.assignment + 1, v_i.rt_ws, v_i.rt_c,v_i.rt_wr, v_i.start_time[3], v_i.is_scheduled)) 328 | # print(local_source, cloud_source) 329 | # print("-----------") 330 | 331 | 332 | #update ready1 and ready2 333 | corresponding_seq = seq_new[v_i.assignment] # the sequence that current v_i is assigned 334 | 335 | v_i_index = corresponding_seq.index(v_i.id) # position of v_i in seq list 336 | if v_i_index != len(corresponding_seq) - 1: 337 | next_node_id = corresponding_seq[v_i_index + 1] 338 | else: 339 | next_node_id = -1 # current node is the last in the seq 340 | 341 | for _node in nodes_new: 342 | flag = 0 343 | for p in _node.parents: 344 | if p.is_scheduled != "kernel_scheduled": 345 | flag += 1 346 | ready1[_node.id - 1] = flag 347 | if _node.id == next_node_id: 348 | ready2[_node.id-1] = 0 349 | 350 | for _node in nodes_new: 351 | # add node into stack if satisfied 352 | if (ready1[_node.id-1] == 0) and (ready2[_node.id-1] == 0) and (_node.is_scheduled != "kernel_scheduled") and (_node not in stack): 353 | # print("add stack: ", _node.id) 354 | stack.append(_node) 355 | 356 | for node in nodes_new: 357 | node.is_scheduled = None 358 | return nodes_new 359 | 360 | if __name__ == '__main__': 361 | 362 | # node10 = Node(id=10, parents=None, children=[], core_speed=[7, 4, 2], cloud_speed=[3, 1, 1]) 363 | # node9 = Node(id=9, parents=None, children=[node10], core_speed=[5, 3, 2], cloud_speed=[3, 1, 1]) 364 | # node8 = Node(id=8, parents=None, children=[node10], core_speed=[6, 4, 2], cloud_speed=[3, 1, 1]) 365 | # node7 = Node(id=7, parents=None, children=[node10], core_speed=[8, 5, 3], cloud_speed=[3, 1, 1]) 366 | # node6 = Node(id=6, parents=None, children=[node8], core_speed=[7, 6, 4], cloud_speed=[3, 1, 1]) 367 | # node5 = Node(id=5, parents=None, children=[node9], core_speed=[5, 4, 2], cloud_speed=[3, 1, 1]) 368 | # node4 = Node(id=4, parents=None, children=[node8, node9], core_speed=[7, 5, 3], cloud_speed=[3, 1, 1]) 369 | # node3 = Node(id=3, parents=None, children=[node7], core_speed=[6, 5, 4], cloud_speed=[3, 1, 1]) 370 | # node2 = Node(id=2, parents=None, children=[node8, node9], core_speed=[8, 6, 5], cloud_speed=[3, 1, 1]) 371 | # node1 = Node(id=1, parents=None, children=[node2, node3, node4, node5, node6], core_speed=[9, 7, 5], cloud_speed=[3, 1, 1]) 372 | # node1.parents = [] 373 | # node2.parents = [node1] 374 | # node3.parents = [node1] 375 | # node4.parents = [node1] 376 | # node5.parents = [node1] 377 | # node6.parents = [node1] 378 | # node7.parents = [node3] 379 | # node8.parents = [node2, node4, node6] 380 | # node9.parents = [node2, node4, node5] 381 | # node10.parents = [node7, node8, node9] 382 | # 383 | # node2.is_core = False 384 | # node2._computation_cost() 385 | 386 | 387 | #Test 2 388 | node10 = Node(id=10, parents=None, children=[], core_speed=[7, 4, 2], cloud_speed=[3, 1, 1]) 389 | node9 = Node(id=9, parents=None, children=[node10], core_speed=[5, 3, 2], cloud_speed=[3, 1, 1]) 390 | node8 = Node(id=8, parents=None, children=[node10], core_speed=[6, 4, 2], cloud_speed=[3, 1, 1]) 391 | node7 = Node(id=7, parents=None, children=[node10], core_speed=[8, 5, 3], cloud_speed=[3, 1, 1]) 392 | node6 = Node(id=6, parents=None, children=[node8, node9], core_speed=[7, 6, 4], cloud_speed=[3, 1, 1]) 393 | node5 = Node(id=5, parents=None, children=[node7, node8], core_speed=[5, 4, 2], cloud_speed=[3, 1, 1]) 394 | node4 = Node(id=4, parents=None, children=[node6], core_speed=[7, 5, 3], cloud_speed=[3, 1, 1]) 395 | node3 = Node(id=3, parents=None, children=[node5, node6], core_speed=[6, 5, 4], cloud_speed=[3, 1, 1]) 396 | node2 = Node(id=2, parents=None, children=[node5], core_speed=[8, 6, 5], cloud_speed=[3, 1, 1]) 397 | node1 = Node(id=1, parents=None, children=[node2, node3, node4], core_speed=[9, 7, 5], cloud_speed=[3, 1, 1]) 398 | node1.parents = [] 399 | node2.parents = [node1] 400 | node3.parents = [node1] 401 | node4.parents = [node1] 402 | node5.parents = [node2, node3] 403 | node6.parents = [node3, node4] 404 | node7.parents = [node5] 405 | node8.parents = [node5, node6] 406 | node9.parents = [node6] 407 | node10.parents = [node7, node8, node9] 408 | 409 | start = time.clock() 410 | 411 | node1.ready_time = 0 412 | 413 | # calculate Priority Score 414 | node_list = [node10, node9, node8, node7, node6, node5, node4, node3, node2, node1] 415 | for node in node_list: 416 | priority_socre = node.w_i 417 | if len(node.children) == 0: 418 | node.priority_socre = priority_socre 419 | continue 420 | child_score = max([i.priority_socre for i in node.children]) 421 | 422 | node.priority_socre = priority_socre + child_score 423 | 424 | node_list = sorted(node_list, key=lambda node: node.priority_socre, reverse=True) 425 | 426 | print("compute priority order") 427 | for node in node_list: 428 | print(node.id, node.priority_socre) 429 | 430 | sequence = primary_assignment(node_list) 431 | T_init = total_T(node_list) 432 | E_init = total_E(node_list, [1, 2, 4, 0.5]) 433 | print("initial time and energy: ", T_init, E_init) 434 | 435 | ############################################# 436 | # start outer loop 437 | ############################################# 438 | iter_num = 0 439 | while iter_num < 100: 440 | # One outer loop 441 | print("-----" * 20) 442 | print("iter: ", iter_num) 443 | print("-----" * 20) 444 | T_init = total_T(node_list) 445 | E_init = total_E(node_list, [1, 2, 4, 0.5]) 446 | print("initial time and energy: ", T_init, E_init) 447 | migration_choice = [[] for i in range(len(node_list))] 448 | for i in range(len(node_list)): 449 | if node_list[i].assignment == 3: # cloud node 450 | current_row_id = node_list[i].id - 1 451 | current_row_value = [1] * 4 # 4 resources 452 | migration_choice[current_row_id] = current_row_value 453 | else: 454 | current_row_id = node_list[i].id - 1 455 | current_row_value = [0] * 4 # 4 resources 456 | current_row_value[node_list[i].assignment] = 1 457 | migration_choice[current_row_id] = current_row_value 458 | print("migration") 459 | # print(migration_choice) 460 | 461 | T_max_constraint = 27 462 | result_table = [[(-1, -1) for j in range(4)] for i in range(len(node_list))] 463 | # print(result_table) 464 | 465 | for n in range(len(migration_choice)): # the n-th node 466 | nth_row = migration_choice[n] 467 | for k in range(len(nth_row)): # the k-th resource 468 | if nth_row[k] == 1: 469 | continue 470 | seq_copy = deepcopy(sequence) 471 | nodes_copy = deepcopy(node_list) 472 | seq_copy = new_squence(nodes_copy, n+1, k, seq_copy) 473 | kernel_algorithm(nodes_copy, seq_copy) 474 | 475 | current_T = total_T(nodes_copy) 476 | current_E = total_E(nodes_copy) 477 | del nodes_copy 478 | del seq_copy 479 | result_table[n][k] = (current_T, current_E) 480 | 481 | # print("after outer loop: ") 482 | # print(result_table) 483 | 484 | n_best = -1 485 | k_best = -1 486 | T_best = T_init 487 | E_best = E_init 488 | ration_best = -1 489 | print(result_table) 490 | for i in range(len(result_table)): 491 | for j in range(len(result_table[i])): 492 | val = result_table[i][j] 493 | if val == (-1, -1): 494 | continue 495 | if val[0] > 27: 496 | continue 497 | ration = (E_best - val[1]) / abs(val[0] - T_best + 0.00005) 498 | if ration > ration_best: 499 | ration_best = ration 500 | n_best = i 501 | k_best = j 502 | 503 | if n_best == -1 and k_best == -1: 504 | break 505 | n_best += 1 506 | k_best += 1 507 | T_best, E_best = result_table[n_best-1][k_best-1] 508 | print("current migration: task:{}, k: {}, total time: {}, total energy: {}".format(n_best, k_best, T_best, E_best)) 509 | print("update after current outer loop") 510 | sequence = new_squence(node_list, n_best, k_best-1, sequence) 511 | kernel_algorithm(node_list, sequence) 512 | # print("finish time: ", [(node.id, node.start_time, node.ft_wr, node.ft_l, node.assignment) for node in node_list]) 513 | for s in sequence: 514 | print([i for i in s]) 515 | T_current = total_T(node_list) 516 | E_current = total_E(node_list, [1, 2, 4, 0.5]) 517 | E_diff = E_init - E_current 518 | T_diff = abs(T_current - T_init) 519 | iter_num += 1 520 | 521 | print("time and energy: ", T_current, E_current) 522 | if E_diff <= 1: 523 | break 524 | 525 | print("rescheduling finished...") 526 | for node in node_list: 527 | if node.is_core == True: 528 | print("node id:{}, assigenment:{}, ready time: {}, local start_time: {}". 529 | format(node.id, node.assignment + 1, node.ready_time, node.start_time[node.assignment])) 530 | print("-----------") 531 | else: 532 | print( 533 | "node id:{}, assigenment:{}, ws ready time: {}, c ready time: {}, wr ready time: {}, cloud start time: {}". 534 | format(node.id, node.assignment + 1, node.rt_ws, node.rt_c, node.rt_wr, node.start_time[3])) 535 | print("-----------") 536 | 537 | elapsed = (time.clock() - start) 538 | print("Time used:", elapsed) 539 | print("final sequence: ") 540 | for s in sequence: 541 | print([i for i in s]) 542 | # for node in node_list: 543 | # print(node.id, node.ft_l, node.ft_wr) 544 | T_final = total_T(node_list) 545 | E_final = total_E(node_list, [1, 2, 4, 0.5]) 546 | print("final time: {}, final energy: {}".format(T_current, E_current)) 547 | 548 | 549 | 550 | # print("rescheduling") 551 | # seq_copy = deepcopy(sequence) 552 | # nodes_copy = deepcopy(node_list) 553 | # 554 | # seq_copy = new_squence(nodes_copy, 1, 3, seq_copy) 555 | # for s in seq_copy: 556 | # print([i for i in s]) 557 | # 558 | # print("call kernel algorithm") 559 | # kernel_algorithm(nodes_copy, seq_copy) 560 | # for s in seq_copy: 561 | # print([i for i in s]) 562 | # print("time: ", total_T(nodes_copy), total_E(nodes_copy)) 563 | # print("---"*30) 564 | # seq_copy = new_squence(nodes_copy, 3, 3, seq_copy) 565 | # for s in seq_copy: 566 | # print([i for i in s]) 567 | # 568 | # print("call kernel algorithm") 569 | # kernel_algorithm(nodes_copy, seq_copy) 570 | # for s in seq_copy: 571 | # print([i for i in s]) 572 | # print("time: ", total_T(nodes_copy), total_E(nodes_copy)) 573 | # print("---" * 30) 574 | # seq_copy = new_squence(nodes_copy, 6, 3, seq_copy) 575 | # for s in seq_copy: 576 | # print([i for i in s]) 577 | # 578 | # print("call kernel algorithm") 579 | # kernel_algorithm(nodes_copy, seq_copy) 580 | # for s in seq_copy: 581 | # print([i for i in s]) 582 | # print("time: ", total_T(nodes_copy), total_E(nodes_copy)) 583 | 584 | --------------------------------------------------------------------------------