cloudsim-plus-master/cloudsim-plus-master/cloudsim-plus-testbeds/src/main/java/org/cloudsimplus/sla/tasktimecompletion/CloudletTaskTimeCompletionMinimizationExperiment.java
private Vm selectVmForCloudlet(Cloudlet cl) {
        final List<Vm> execVms = cl.getBroker().getVmExecList();

        final Comparator<Vm> sortByFreePesNumber = comparingLong(this::getExpectedNumberOfFreeVmPes);
        final Comparator<Vm> sortByExpectedCloudletCompletionTime = comparingDouble(vm -> getExpectedCloudletCompletionTime(cl, vm));
        execVms.sort(
            sortByExpectedCloudletCompletionTime.thenComparing(sortByFreePesNumber.reversed())
        );
        final Vm mostFreePesVm = execVms.stream().findFirst().orElse(Vm.NULL);

        taskCompletionTimeSlaContract = contractsMap.get(cl.getBroker()).getTaskCompletionTimeMetric().getMaxDimension().getValue();

        return execVms.stream()
            .filter(vm -> getExpectedNumberOfFreeVmPes(vm) >= cl.getNumberOfPes())
            .filter(vm -> getExpectedCloudletCompletionTime(cl, vm) <= taskCompletionTimeSlaContract)
            .findFirst()
            .orElse(mostFreePesVm);
    }
/**
     * Selects a VM to run a Cloudlet which minimizes the Cloudlet completion
     * time.
     *
     * @param cl the Cloudlet to select a VM to
     * @return the selected Vm
     */
Selects a VM to run a Cloudlet which minimizes the Cloudlet completion
time.

@param cl the Cloudlet to select a VM to
@return the selected Vm
Selects a VM to run a Cloudlet which minimizes the Cloudlet completion time . @param cl the Cloudlet to select a VM to @return the selected Vm
private Vm selectVmForCloudlet(Cloudlet cl) {
        final List<Vm> execVms = cl.getBroker().getVmExecList();
        final Comparator<Vm> sortByFreePesNumber = comparingLong(this::getExpectedNumberOfFreeVmPes);
        final Comparator<Vm> sortByExpectedCloudletCompletionTime = comparingDouble(vm -> getExpectedCloudletCompletionTime(cl, vm));
        execVms.sort(
            sortByExpectedCloudletCompletionTime.thenComparing(sortByFreePesNumber.reversed())
        );
        final Vm mostFreePesVm = execVms.stream().findFirst().orElse(Vm.NULL);
        taskCompletionTimeSlaContract = contractsMap.get(cl.getBroker()).getTaskCompletionTimeMetric().getMaxDimension().getValue();
        return execVms.stream()
            .filter(vm -> getExpectedNumberOfFreeVmPes(vm) >= cl.getNumberOfPes())
            .filter(vm -> getExpectedCloudletCompletionTime(cl, vm) <= taskCompletionTimeSlaContract)
            .findFirst()
            .orElse(mostFreePesVm);
    }
private Vm selectVmForCloudlet ( Cloudlet cl ) { final List < Vm > execVms = cl . getBroker ( ) . getVmExecList ( ) ; final Comparator < Vm > sortByFreePesNumber = comparingLong ( this :: getExpectedNumberOfFreeVmPes ) ; final Comparator < Vm > sortByExpectedCloudletCompletionTime = comparingDouble ( vm -> getExpectedCloudletCompletionTime ( cl , vm ) ) ; execVms . sort ( sortByExpectedCloudletCompletionTime . thenComparing ( sortByFreePesNumber . reversed ( ) ) ) ; final Vm mostFreePesVm = execVms . stream ( ) . findFirst ( ) . orElse ( Vm . NULL ) ; taskCompletionTimeSlaContract = contractsMap . get ( cl . getBroker ( ) ) . getTaskCompletionTimeMetric ( ) . getMaxDimension ( ) . getValue ( ) ; return execVms . stream ( ) . filter ( vm -> getExpectedNumberOfFreeVmPes ( vm ) >= cl . getNumberOfPes ( ) ) . filter ( vm -> getExpectedCloudletCompletionTime ( cl , vm ) <= taskCompletionTimeSlaContract ) . findFirst ( ) . orElse ( mostFreePesVm ) ; }
Selects a VM to run a Cloudlet which minimizes the Cloudlet completion
 time.
Selects a VM to run a Cloudlet which minimizes the Cloudlet completion time .