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
  • 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 two values. It is used to avoid that solutions with little decimal deviations are considered different from each other.
      See Also:
  • 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 configure the solution being created.
    • CloudletToVmMappingSolution

      public CloudletToVmMappingSolution(Heuristic heuristic, int id)
      Creates a new solution for mapping a set of cloudlets to VMs using a given Heuristic implementation.
      Parameters:
      heuristic - the heuristic implementation used to configure the solution being created.
      id - unique solution id to identify the index of the solution inside the set of all solutions created
    • CloudletToVmMappingSolution

      public CloudletToVmMappingSolution(@NonNull @NonNull CloudletToVmMappingSolution solution, int id)
      Clones a given solution.
      Parameters:
      solution - the solution to be cloned
      id - unique solution id to identify the index of the solution inside the set of all solutions created
  • Method Details

    • bindCloudletToVm

      public void bindCloudletToVm(@NonNull @NonNull Cloudlet cloudlet, @NonNull @NonNull 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
    • getCost

      public double getCost()
      Defines the cost of using this solution. As higher is the cost, the worse a solution is. How a solution cost is computed is totally dependent on the heuristic implementation being used to find a solution. It computes the cost of the entire mapping between VMs and Cloudlets.
      Specified by:
      getCost in interface HeuristicSolution<Map<Cloudlet,Vm>>
      Returns:
      the solution cost
      See Also:
    • getCost

      public double getCost(boolean forceRecompute)
      It computes the costs of the entire mapping between VMs and cloudlets.
      Parameters:
      forceRecompute - indicate if the cost has to be recomputed anyway
      Returns:
      the cost of the entire mapping between VMs and cloudlets
      See Also:
    • 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 to compute the cost
      Returns:
      the VM cost to host the Cloudlets
    • compareTo

      public int compareTo(@NonNull @NonNull 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 an 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 a solution is generated by a heuristic. Getting an optimal or suboptimal 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 VMs of 2 randomly selected cloudlets in the cloudletVmMap in order to provide a neighbor solution.

      The method changes 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; a unitary List if the map has only 1 entry; or an empty List if there is no entry in the map.
      See Also: