org.cloudsimplus.selectionpolicies.VmSelectionPolicyRandomSelection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudsimplus Show documentation
Show all versions of cloudsimplus Show documentation
CloudSim Plus: A modern, highly extensible and easier-to-use Java 17+ Framework for Modeling and Simulation of Cloud Computing Infrastructures and Services
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudsimplus.selectionpolicies;
import lombok.NonNull;
import org.cloudsimplus.distributions.ContinuousDistribution;
import org.cloudsimplus.distributions.UniformDistr;
import org.cloudsimplus.hosts.Host;
import org.cloudsimplus.vms.Vm;
import java.util.Optional;
/**
* A VM selection policy that randomly select VMs to migrate from a host.
* It uses a uniform Pseudo Random Number Generator (PRNG) as default to select VMs.
*
* If you are using any algorithms, policies or workload included in the power package please cite
* the following paper:
*
*
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 3.0
*/
public class VmSelectionPolicyRandomSelection implements VmSelectionPolicy {
private final ContinuousDistribution rand;
/**
* Creates a PowerVmSelectionPolicyRandomSelection using
* a uniform Pseudo Random Number Generator (PRNG) as default to select VMs to migrate.
*/
public VmSelectionPolicyRandomSelection(){
this(new UniformDistr());
}
/**
* Creates a PowerVmSelectionPolicyRandomSelection using a given
* Pseudo Random Number Generator (PRNG) to select VMs to migrate.
*
* @param rand a Pseudo Random Number Generator (PRNG) to randomly select VMs to migrate.
*/
public VmSelectionPolicyRandomSelection(@NonNull final ContinuousDistribution rand){
super();
this.rand = rand;
}
@Override
public Optional getVmToMigrate(final Host host) {
final var migratableVmList = host.getMigratableVms();
if (migratableVmList.isEmpty()) {
return Optional.empty();
}
final int index = (int)(rand.sample() * migratableVmList.size());
return Optional.of(migratableVmList.get(index));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy