Cloudsim: return confusion

狂风中的少年 提交于 2020-07-10 10:29:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!