Cloudsim and Java reference return problem

56 views Asked by At

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;
}
1

There are 1 answers

3
Lucas Diehl On

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.