def Optimize(CPU, CPULR, VMSC, Pvm, N_Pvm): idx = left_idx(CPULR) for i in range(len(CPULR)): CCPU = copy.deepcopy(CPU[idx[i]]) if (CPULR[idx[i]][0] > 0): VMSC = Adjust(VMSC, 0) for j in range(len(CCPU)): TT_list = [] info = utils.SelectVM(CCPU[j], Pvm, N_Pvm) for t in range(len(VMSC)): if (info[1] == VMSC[t][2]): if ((VMSC[t][1] > info[0]) and ((info[0] + CPULR[idx[i]][0]) >= VMSC[t][1])): TT_list.append(VMSC[t]) VMSC.remove(VMSC[t]) break if (len(TT_list) != 0): CPU[idx[i]].remove(CCPU[j]) CPU[idx[i]].append(TT_list[0][0]) if (CPULR[idx[i]][1] > 0): VMSC = Adjust(VMSC, 1) for j in range(len(CCPU)): TT_list = [] info = utils.SelectVM(CCPU[j], Pvm, N_Pvm) for t in range(len(VMSC)): if (info[0] == VMSC[t][1]): if ((VMSC[t][2] > info[1]) and ((info[1] + CPULR[idx[i]][1]) > VMSC[t][2])): TT_list.append(VMSC[t]) VMSC.remove(VMSC[t]) break if (len(TT_list) != 0): CPU[idx[i]].remove(CCPU[j]) CPU[idx[i]].append(TT_list[0][0]) return CPU
def CLRes(CPU0,VMSC,Pvm,N_Pvm,CPU_kernal,CPU_memory): L_k=0 L_m=0 for i in range(len(VMSC)): L_k=L_k+VMSC[i][1] L_m=L_m+VMSC[i][2] R_kernal=0 R_memory=0 CPU00=copy.deepcopy(CPU0) for i in range(len(CPU0)): info=utils.SelectVM(CPU0[i],Pvm,N_Pvm) if((R_kernal+info[0]<L_k)and(R_memory+info[1]<L_m)): R_kernal=R_kernal+info[0] R_memory=R_memory+info[1] CPU00.remove(CPU0[i]) CPU0=CPU00 CPU_limit=[CPU_kernal,CPU_memory] for j in range(len(CPU0)): CPU_limit[0]=CPU_limit[0]-(utils.SelectVM(CPU0[j],Pvm,N_Pvm))[0] CPU_limit[1]=CPU_limit[1]-(utils.SelectVM(CPU0[j],Pvm,N_Pvm))[1] for j in range(len(VMSC)): VMs_info=[VMSC[j][1],VMSC[j][2]] if((CPU_limit[0]>=VMs_info[0])and(CPU_limit[1]>=VMs_info[1])): CPU0.append(VMSC[j][0]) CPU_limit[0]=CPU_limit[0]-VMs_info[0] CPU_limit[1]=CPU_limit[1]-VMs_info[1] return CPU0
def Boxing(N_PCPU, NEPvm, Pvm, N_Pvm, CPU_kernal, CPU_memory): VMs = [] # all Predicted vms for i in range(N_Pvm): for j in range(int(NEPvm[i])): VMs.append(Pvm[i]) lenVMs = len(VMs) # The number of all predicted VMs CPU = [] for i in range(N_PCPU): CPU.append([]) # intialize the cpu list VMs_info = [[0 for i in range(2)] for j in range(lenVMs)] for i in range(lenVMs): VMs_info[i] = utils.SelectVM(VMs[i][0], Pvm, N_Pvm) # get each cpu information index = [0 for i in range(lenVMs)] for j in range(lenVMs): index[j] = VMs_info[j][1] - VMs_info[j][0] idx = utils.argsort(index) # get the index (ascend) temp_vms = [] temp_vminfo = [] for i in range(lenVMs): temp_vms.append(VMs[idx[i]]) temp_vminfo.append(VMs_info[idx[i]]) VMs = temp_vms VMs_info = temp_vminfo # get the sorted array CPU_index = [(CPU_memory - CPU_kernal) for i in range(N_PCPU)] CPU_limit = [[CPU_kernal, CPU_memory] for i in range(N_PCPU)] for j in range(lenVMs): count = 0 idx = utils.argsort(CPU_index) for z in range(N_PCPU): if (CPU_limit[idx[z]][0] >= VMs_info[j][0] and CPU_limit[idx[z]][1] >= VMs_info[j][1]): CPU[idx[z]].append(VMs[j][0]) CPU_limit[idx[z]][0] = CPU_limit[idx[z]][0] - VMs_info[j][0] CPU_limit[idx[z]][1] = CPU_limit[idx[z]][1] - VMs_info[j][1] CPU_index[idx[z]] = CPU_index[ idx[z]] - VMs_info[j][1] + VMs_info[j][0] break else: count = count + 1 if (count == len(CPU)): N_PCPU = N_PCPU + 1 CPU.append([]) CPU_limit.append([CPU_kernal, CPU_memory]) CPU_index.append((CPU_memory - CPU_kernal)) CPU[(N_PCPU - 1)].append(VMs[j][0]) CPU_limit[(N_PCPU - 1)][0] = CPU_limit[(N_PCPU - 1)][0] - VMs_info[j][0] CPU_limit[(N_PCPU - 1)][1] = CPU_limit[(N_PCPU - 1)][1] - VMs_info[j][1] CPU_index[( N_PCPU - 1)] = CPU_index[(N_PCPU - 1)] - VMs_info[j][1] + VMs_info[j][0] return CPU, N_PCPU