0

I am working on cloudsim project. So I write the following code this code first calculate the mean and then order ascending the values of ArrayList. So I want to this code return by refrence vmList in types of Vm. Can anyone help me ? What should I to do ? or What is the problem of this code ?

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;
}
Ali Mosavi
  • 23
  • 5

1 Answers1

0

I don't understand your code. First of all get the list of a type instance Vm, calculate the "size" and add in another list. Then you are get the sum of all values and get the mean. After that, you see all size elements, but your "if" will not work. Look it, you verify, but not matters what is the value, you add in vms list. Basicly you will have two equals lists: "vmSize" and "vms". If you want to make something like a line between values above and below the "mean", you need to reformulate your code or do something like this:

ArrayList<Double> vmsBelowMean = new ArrayList<Double>();
ArrayList<Double> vmsAboveMean = new ArrayList<Double>();


for(int i=0; i<vmSize.size(); i++)
{
    if(vmSize.get(i) > mean)
    {
        vmsAboveMean.add(vmSize.get(i));
    }
    else
    {
        vmsBelowMean.add(vmSize.get(i));
    }
}

and then get together this two arrays.

About return, I think if you need to create your final array looking at this.

  • Thanks for your response. Yes you are right and you solve a part of my problem.so and then in this code I am trying to sort ascending vmList and then return.... If is it possible please read this post you will undrestand more.... https://stackoverflow.com/questions/62263216/cloudsim-return-confusion – Ali Mosavi Jun 09 '20 at 08:12
  • this is the document of the above code:" For FFDmean this function calculates mean of VM dimensions in demand vector ⃗⃗ . The larger the mean the larger is the VM size. The size function S for FFDmean is presented in (6) where v represents a VM, i is a dimension and d is the total number of dimensions 1 ≤ i ≤ d) from D. After calculated dimension. How to sort ascending and return back as the following code. – Ali Mosavi Jun 09 '20 at 08:16
  • public static void sortByCpuUtilization(List vmList) { Collections.sort(vmList, new Comparator() { @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); } }); } – Ali Mosavi Jun 09 '20 at 08:18