问题
This function is my sample function. this function Sort a given list of VMs by descending order of CPU utilization.
public static <T extends Vm> void sortByCpuUtilization(List<T> vmList) {
Collections.sort(vmList, new Comparator<T>() {
@Override
public int compare(T a, T b) throws ClassCastException {
Double aUtilization = a.getTotalUtilizationOfCpuMips(CloudSim.clock());
Double bUtilization = b.getTotalUtilizationOfCpuMips(CloudSim.clock());
return bUtilization.compareTo(aUtilization);
}
});
}
My question is in this section. I write the bellow function. it return an ArrayList. but this is not my purpose I want to return this function like the above function. What should I do ?
Can anyone help me ?
public static <T extends Vm> ArrayList<Double> sortByFFDMean(List<T> vmList) {
double size = 0;
double sum = 0;
ArrayList<Double> vmSize = new ArrayList<Double>();
ArrayList<Double> vms = new ArrayList<Double>();
for(Vm v: vmList)
{
double cpu = v.getTotalUtilizationOfCpuMips(CloudSim.clock());
double ram = v.getTotalUtilizationOfRam(CloudSim.clock());
double bw = v.getTotalUtilizationOfBW(CloudSim.clock());
size = (cpu + ram + bw / 3);
vmSize.add(size);
sum += size;
}
double mean = sum/vmList.size();
for(int i=0; i<vmSize.size(); i++)
{
if(vmSize.get(i) > mean)
{
vms.add(vmSize.get(i));
}
else
{
vms.add(vmSize.get(i));
}
}
Collections.sort(vms, Collections.reverseOrder());
return vms;
}
来源:https://stackoverflow.com/questions/62263216/cloudsim-return-confusion