CloudletToVmMappingSolution implements HeuristicSolution<Map<Cloudlet, Vm>> { @Override public int compareTo(final HeuristicSolution solution) { final double diff = this.getCost() - solution.getCost(); if(Math.abs(diff) <= MIN_DIFF) { return 0; } return (diff > 0 ? -1 : 1); } CloudletToVmMappingSolution(final Heuristic heuristic); private  CloudletToVmMappingSolution(final Heuristic heuristic, final Map<Cloudlet, Vm> cloudletVmMap);  CloudletToVmMappingSolution(final CloudletToVmMappingSolution solution); void bindCloudletToVm(final Cloudlet cloudlet, final Vm vm); @Override Heuristic<HeuristicSolution<Map<Cloudlet, Vm>>> getHeuristic(); @Override double getCost(); double getCost(final boolean forceRecompute); double getVmCost(final Map.Entry<Vm, List<Map.Entry<Cloudlet, Vm>>> entry); double getVmCost(final Vm vm, final List<Cloudlet> cloudlets); @Override int compareTo(final HeuristicSolution solution); @Override Map<Cloudlet, Vm> getResult(); static final double MIN_DIFF; }
@Test public void testCompareToWhenInstanceIsGreater() { final int NUMBER_OF_CLOUDLETS = 3; final int PES = 2; final CloudletToVmMappingSolution instance = createSolutionWithOneVmForEachCloudlet(NUMBER_OF_CLOUDLETS, PES); final HeuristicSolution o = createSolutionWithOneVmForEachCloudlet(NUMBER_OF_CLOUDLETS, PES, PES/2); final int expResult = 1; final int result = instance.compareTo(o); final String msg = String.format( "The instance was expected to be greater than the compared object. Instance fitness: %f Compared object fitness: %f", instance.getFitness(), o.getFitness()); assertEquals(expResult, result, msg); }
@Test public void testCompareToWhenInstanceIsEquals() { final int NUMBER_OF_CLOUDLETS = 3; final int PES = 2; final CloudletToVmMappingSolution instance = createSolutionWithOneVmForEachCloudlet(NUMBER_OF_CLOUDLETS, PES, PES+1); final HeuristicSolution o = createSolutionWithOneVmForEachCloudlet(NUMBER_OF_CLOUDLETS, PES, PES+1); final int expResult = 0; final int result = instance.compareTo(o); final String msg = String.format( "The instances should be equals. Instance fitness: %f Compared object fitness: %f", instance.getFitness(), o.getFitness()); assertEquals(expResult, result, msg); }
@Test public void testCompareToWhenInstanceIsLower() { final int NUMBER_OF_CLOUDLETS = 3; final int PES = 2; final CloudletToVmMappingSolution instance = createSolutionWithOneVmForEachCloudlet(NUMBER_OF_CLOUDLETS, PES, PES/2); final HeuristicSolution o = createSolutionWithOneVmForEachCloudlet(NUMBER_OF_CLOUDLETS, PES); final int expResult = -1; final int result = instance.compareTo(o); final String msg = String.format( "The instance was expected to be lower than the compared object. Instance fitness: %.2f Compared object fitness: %.2f", instance.getFitness(), o.getFitness()); assertEquals(expResult, result, msg); }