Package org.cloudsimplus.heuristics
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 Summary
Fields Modifier and Type Field Description static double
MIN_DIFF
When two double values are subtracted to check if they are equal zero, there may be some precision issues.Fields inherited from interface org.cloudsimplus.heuristics.HeuristicSolution
LOGGER, NULL
-
Constructor Summary
Constructors Constructor Description CloudletToVmMappingSolution(CloudletToVmMappingSolution solution)
Clones a given solution.CloudletToVmMappingSolution(Heuristic heuristic)
Creates a new solution for mapping a set of cloudlets to VMs using a given heuristic implementation. -
Method Summary
Modifier and Type Method Description void
bindCloudletToVm(Cloudlet cloudlet, Vm vm)
Binds a cloudlet to be executed by a given Vm.int
compareTo(HeuristicSolution solution)
Compares this solution with another given one, based on the solution cost.double
getCost()
Defines the cost of using this solution.double
getCost(boolean forceRecompute)
It computes the costs of the entire mapping between Vm's and cloudlets.Heuristic<HeuristicSolution<Map<Cloudlet,Vm>>>
getHeuristic()
protected List<Map.Entry<Cloudlet,Vm>>
getRandomMapEntries()
Try to get 2 randomly selected entries from thecloudletVmMap
.Map<Cloudlet,Vm>
getResult()
Gets the result of the solution.double
getVmCost(Map.Entry<Vm,List<Map.Entry<Cloudlet,Vm>>> entry)
Computes the cost of all Cloudlets hosted by a given Vm.double
getVmCost(Vm vm, List<Cloudlet> cloudlets)
Computes the cost of all Cloudlets hosted by a given Vm.protected boolean
swapVmsOfTwoMapEntries(List<Map.Entry<Cloudlet,Vm>> entries)
Swap the Vm's of 2 randomly selected cloudlets in thecloudletVmMap
in order to provide a neighbor solution.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cloudsimplus.heuristics.HeuristicSolution
getFitness
-
Field Details
-
MIN_DIFF
public static final double MIN_DIFFWhen 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
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
Clones a given solution.- Parameters:
solution
- the solution to be cloned
-
-
Method Details
-
bindCloudletToVm
Binds a cloudlet to be executed by a given Vm.- Parameters:
cloudlet
- the cloudlet to be added to a Vmvm
- the Vm to assign a cloudlet to
-
getHeuristic
- Specified by:
getHeuristic
in interfaceHeuristicSolution<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 interfaceHeuristicSolution<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
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
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 Cloudletscloudlets
- 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
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 interfaceComparable<HeuristicSolution<Map<Cloudlet,Vm>>>
- Parameters:
solution
- the solution to compare this instance to- Returns:
-
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 aMap<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 interfaceHeuristicSolution<Map<Cloudlet,Vm>>
- Returns:
- the actual solution, providing the mapping between Cloudlets and Vm's.
-
swapVmsOfTwoMapEntries
Swap the Vm's of 2 randomly selected cloudlets in thecloudletVmMap
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
Try to get 2 randomly selected entries from thecloudletVmMap
.- 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)
-