这是我在 Cloudsim 中编写的代码,用于将 VM 调度到合适的主机。我已经延长了VmAllocationPolicyAbstract
课程。但是,当我运行它时,我在控制台中收到以下错误:“在任何可用的数据中心中都没有找到合适的主机。”
package org.cloudbus.cloudsim.allocationpolicies;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.vms.Vm;
import java.awt.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class VmAllocationPolicyMrfs extends VmAllocationPolicyAbstract {
ArrayList<Vm> mylist = new ArrayList<Vm>();
private final Map<String, Host> vm_table = new HashMap<String, Host>();
Host host;
public boolean allocateHostForVm(Vm vm) {
if(this.vm_table.containsKey(vm.getUid())) {
return true;
}
boolean vm_allocated = false;
ArrayList<Vm> myvm = new ArrayList<Vm>();
double dominantcpu = 0.0;
double dominantram = 0.0;
Map<String, Double> dominantcpulist = new HashMap<String, Double>();
Map<String, Double> dominantramlist = new HashMap<String, Double>();
Map<String, Double> requestedCpu = new HashMap<String, Double>();
Map<String, Double> requestedRam = new HashMap<String, Double>();
for(int i = 0; i<=getHostList().size(); i++) {
for(Vm vm1:myvm) {
double cpurequest = vm1.getCurrentRequestedTotalMips();
double ramrequest = vm1.getCurrentRequestedRam();
if (cpurequest<ramrequest && host != null) {
dominantram = ramrequest;
dominantramlist.put(vm1.getUid(),dominantram);
vm_allocated = this.allocateHostForVm(vm1, host);
}
else if(cpurequest>ramrequest) {
dominantcpu = cpurequest;
dominantcpulist.put(vm1.getUid(), dominantcpu);
vm_allocated = this.allocateHostForVm(vm1, host);
}
}
}
return vm_allocated;
}
}
我该如何解决这个问题?