CloudletToVmMappingSolution

public class CloudletToVmMappingSolution implements HeuristicSolution<Map<Cloudlet, Vm>>

A possible solution for mapping a set of Cloudlets to a set of Vm’s. It represents a solution generated using a Heuristic implementation.

Author:Manoel Campos da Silva Filho

See also: Heuristic

Fields

MIN_DIFF

public static final double MIN_DIFF

When two double values are subtracted to check if they are equal zero, there may be some precision issues. This value is used to check the absolute difference between the two values to avoid that solutions with little decimal difference be considered different one of the other.

Constructors

CloudletToVmMappingSolution

public CloudletToVmMappingSolution(Heuristic heuristic)

Creates a new solution for mapping a set of cloudlets to VMs using a given heuristic implementation.

Parameters:
  • heuristic – the heuristic implementation used to find the solution being created.

CloudletToVmMappingSolution

public CloudletToVmMappingSolution(CloudletToVmMappingSolution solution)

Clones a given solution.

Parameters:
  • solution – the solution to be cloned

Methods

bindCloudletToVm

public void bindCloudletToVm(Cloudlet cloudlet, Vm vm)

Binds a cloudlet to be executed by a given Vm.

Parameters:
  • cloudlet – the cloudlet to be added to a Vm
  • vm – the Vm to assign a cloudlet to

compareTo

public int compareTo(HeuristicSolution solution)

Compares this solution with another given one, based on the solution cost. The current object is considered to be: equal to the given object if they have the same cost; greater than the given object if it has a lower cost; lower than the given object if it has a higher cost;

Parameters:
  • solution – the solution to compare this instance to
Returns:

{@inheritDoc}

getCost

public double getCost()

{@inheritDoc} It computes the cost of the entire mapping between Vm’s and Cloudlets.

Returns:{@inheritDoc}

getCost

public double getCost(boolean forceRecompute)

It computes the costs of the entire mapping between Vm’s and cloudlets.

Parameters:
  • forceRecompute – indicate if the cost has to be recomputed anyway
Returns:

the cost of the entire mapping between Vm’s and cloudlets

See also: .getCost()

getHeuristic

public Heuristic<HeuristicSolution<Map<Cloudlet, Vm>>> getHeuristic()

getRandomMapEntries

protected List<Map.Entry<Cloudlet, Vm>> getRandomMapEntries()

Try to get 2 randomly selected entries from the cloudletVmMap.

Returns:a List with 2 entries from the cloudletVmMap if the map has at least 2 entries, an unitary List if the map has only one entry, or an empty List if there is no entry.

See also: .swapVmsOfTwoMapEntries(List)

getResult

public Map<Cloudlet, Vm> getResult()
Returns:the actual solution, providing the mapping between Cloudlets and Vm’s.

getVmCost

public double getVmCost(Map.Entry<Vm, List<Map.Entry<Cloudlet, Vm>>> entry)

Computes the cost of all Cloudlets hosted by a given Vm. The cost is based on the number of PEs from the VM that will be idle or overloaded.

Parameters:
  • entry – a Map Entry where the key is a VM hosting some Cloudlets and the value is the Cloudlets hosted in this VM.
Returns:

the VM cost to host the Cloudlets

getVmCost

public double getVmCost(Vm vm, List<Cloudlet> cloudlets)

Computes the cost of all Cloudlets hosted by a given Vm. The cost is based on the number of PEs from the VM that will be idle or overloaded.

Parameters:
  • vm – the VM to compute the cost to host some Cloudlets
  • cloudlets – the list of Cloudlets to be hosted by the VM in order to compute the cost
Returns:

the VM cost to host the Cloudlets

swapVmsOfTwoMapEntries

protected final boolean swapVmsOfTwoMapEntries(List<Map.Entry<Cloudlet, Vm>> entries)

Swap the Vm’s of 2 randomly selected cloudlets in the cloudletVmMap in order to provide a neighbor solution. The method change the given Map entries, moving the cloudlet of the first entry to the Vm of the second entry and vice-versa.

Parameters:
  • entries – a List of 2 entries containing Cloudlets to swap their VMs. If the entries don’t have 2 elements, the method will return without performing any change in the entries.
Returns:

true if the VMs of the Cloudlets where swapped, false otherwise

swapVmsOfTwoRandomSelectedMapEntries

boolean swapVmsOfTwoRandomSelectedMapEntries()

Swap the Vm’s of 2 randomly selected cloudlets in the cloudletVmMap in order to provide a neighbor solution. The method change the given Map entries, moving the cloudlet of the first entry to the Vm of the second entry and vice-versa.

Returns:true if the Cloudlet’s VMs where swapped, false otherwise

See also: .swapVmsOfTwoMapEntries(List)