Class CloudletToVmMappingSolution

java.lang.Object
org.cloudsimplus.heuristics.CloudletToVmMappingSolution
All Implemented Interfaces:
Comparable<HeuristicSolution<Map<Cloudlet,​Vm>>>, HeuristicSolution<Map<Cloudlet,​Vm>>

public class CloudletToVmMappingSolution
extends Object
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.
Since:
CloudSim Plus 1.0
Author:
Manoel Campos da Silva Filho
See Also:
Heuristic
  • Field Details

    • 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.
      See Also:
      Constant Field Values
  • Constructor Details

    • 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
  • Method Details

    • 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
    • getHeuristic

      public Heuristic<HeuristicSolution<Map<Cloudlet,​Vm>>> getHeuristic()
      Specified by:
      getHeuristic in interface HeuristicSolution<Map<Cloudlet,​Vm>>
      Returns:
      the heuristic that generated this solution.
    • getCost

      public double getCost()
      Defines the cost of using this solution. As higher is the cost, worse is a solution. How a solution cost is computed is totally dependent of the heuristic implementation being used to find a solution. It computes the cost of the entire mapping between Vm's and Cloudlets.
      Specified by:
      getCost in interface HeuristicSolution<Map<Cloudlet,​Vm>>
      Returns:
      the solution cost
      See Also:
      HeuristicSolution.getFitness()
    • 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()
    • 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
    • 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;
      Specified by:
      compareTo in interface Comparable<HeuristicSolution<Map<Cloudlet,​Vm>>>
      Parameters:
      solution - the solution to compare this instance to
      Returns:
    • getResult

      public Map<Cloudlet,​Vm> getResult()
      Description copied from interface: HeuristicSolution
      Gets the result of the solution. For instance, if a implementation of this interface aims to provide a mapping between Cloudlets and Vm's, this type would be a Map<Cloudlet, Vm>, that will indicate which Vm will run each Cloudlet. This way, the type T of the solution is totally dependent of the problem being solved by the heuristic implementation.

      The result of solution is generated by a heuristic. Getting an optimal or sub-optimal solution is the final goal of a heuristic.

      Specified by:
      getResult in interface HeuristicSolution<Map<Cloudlet,​Vm>>
      Returns:
      the actual solution, providing the mapping between Cloudlets and Vm's.
    • 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
    • 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 size is at least 2; an unitary List if the map has only 1 entry; or an empty List if there is no entry in the map.
      See Also:
      swapVmsOfTwoMapEntries(List)