def Boxing(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 # Split vms according to M/K VM1=[]; VM2=[]; VM4=[]; for i in range(lenVMs): VMs_info=[VMs[i][1],VMs[i][2]] if (VMs_info[1]/VMs_info[0]==1): VM1.append(VMs[i]) elif(VMs_info[1]/VMs_info[0]==2): VM2.append(VMs[i]) else: VM4.append(VMs[i]) Min=min([len(VM1),len(VM2),len(VM4)]) # maybe zero if (Min==0): Min=1 if(len(VM4)==0): P4=1 Min=min([len(VM1),len(VM2)]) P2=int(math.ceil(len(VM2)/Min)) P1=int(math.ceil(len(VM1)/Min)) elif(len(V2)==0): P2=1 Min=min([len(VM1),len(VM4)]) P4=int(math.ceil(len(VM4)/Min)) P1=int(math.ceil(len(VM1)/Min)) else: P1=1 Min=min([len(VM2),len(VM4)]) P2=int(math.ceil(len(VM2)/Min)) P4=int(math.ceil(len(VM4)/Min)) else: P4=int(math.ceil(len(VM4)/Min)) P2=int(math.ceil(len(VM2)/Min)) P1=int(math.ceil(len(VM1)/Min)) idx4=Cond_Sort(VM4) idx2=Cond_Sort(VM2) idx1=Cond_Sort(VM1) VMs=[] #reset i4=0 i2=0 i1=0 for i in range(Min): for j in range(i4,(i4+P4),1): if(j<len(VM4)): VMs.append(VM4[idx4[j]]) i4=i4+1 for z in range(i2,(i2+P2),1): if(z<len(VM2)): VMs.append(VM2[idx2[z]]) i2=i2+1 for t in range(i1,(i1+P1),1): if(t<len(VM1)): VMs.append(VM1[idx1[t]]) i1=i1+1 CPU=[] CPU.append([]) N_PCPU=0 #default 0 VMSC=copy.deepcopy(VMs) while(1): CPU_limit=[CPU_kernal,CPU_memory] lenVM=len(VMs) for j in range(lenVM): VMs_info=[VMs[j][1],VMs[j][2]] if(CPU_limit[0]>=VMs_info[0] and CPU_limit[1]>=VMs_info[1]): CPU[N_PCPU].append(VMs[j][0]) CPU_limit[0]=CPU_limit[0]-VMs_info[0] CPU_limit[1]=CPU_limit[1]-VMs_info[1] VMSC.remove(VMs[j]) if(utils.SUM_Judge(VMSC,CPU_kernal,CPU_memory)): #CPU[0]=CLRes(CPU[0],VMSC,Pvm,N_Pvm,CPU_kernal,CPU_memory) break else: VMs=copy.deepcopy(VMSC) CPU.append([]) N_PCPU=N_PCPU+1 return CPU,(N_PCPU+1)
def Boxing(NEPvm, Pvm, N_Pvm, CPU_kernel, CPU_memory, condition): VMs = [] # all Predicted vms for i in range(N_Pvm): for j in range(int(NEPvm[i])): VMs.append(Pvm[i]) VMs = First_Delete(VMs, CPU_kernel, CPU_memory, condition) lenVMs = len(VMs) # The number of all predicted VMs # Split vms according to M/K VM1 = [] VM2 = [] VM4 = [] for i in range(lenVMs): VMs_info = [VMs[i][1], VMs[i][2]] if (VMs_info[1] / VMs_info[0] == 1): VM1.append(VMs[i]) elif (VMs_info[1] / VMs_info[0] == 2): VM2.append(VMs[i]) else: VM4.append(VMs[i]) VMs = [] #reset VM4 = Adjust(VM4, 0) VM2 = Adjust(VM2, 0) VM1 = Adjust(VM1, 0) T_VMs = [VM4, VM2, VM1] len4 = len(VM4) len2 = len(VM2) len1 = len(VM1) #maybe exist zero if (len4 == 0): len4 = 100 if (len2 == 0): len2 = 100 if (len1 == 0): len1 = 100 for i in range(lenVMs): TEMP = [(len(T_VMs[0]) / len4), (len(T_VMs[1]) / len2), (len(T_VMs[2]) / len1)] M = TEMP.index(max(TEMP)) if (len(T_VMs[M]) != 0): VMs.append(T_VMs[M][0]) (T_VMs[M]).remove(T_VMs[M][0]) CPU = [] CPU.append([]) CPULR = [] #resorce left N_PCPU = 0 #default 0 VMSC = copy.deepcopy(VMs) while (1): CPU_limit = [CPU_kernel, CPU_memory] lenVM = len(VMs) for j in range(lenVM): VMs_info = [VMs[j][1], VMs[j][2]] if (CPU_limit[0] >= VMs_info[0] and CPU_limit[1] >= VMs_info[1]): CPU[N_PCPU].append(VMs[j][0]) CPU_limit[0] = CPU_limit[0] - VMs_info[0] CPU_limit[1] = CPU_limit[1] - VMs_info[1] VMSC.remove(VMs[j]) CPULR.append(CPU_limit) if (utils.SUM_Judge(VMSC, CPU_kernel, CPU_memory)): CPU = Optimize(CPU, CPULR, VMSC, Pvm, N_Pvm) break else: VMs = copy.deepcopy(VMSC) CPU.append([]) N_PCPU = N_PCPU + 1 return CPU, (N_PCPU + 1)