CloudletToVmMappingSolution implements HeuristicSolution<Map<Cloudlet, Vm>> { protected final boolean swapVmsOfTwoMapEntries(final List<Map.Entry<Cloudlet, Vm>> entries) { if(entries == null || entries.size() != 2 || entries.get(0) == null || entries.get(1) == null) { return false; } final Vm vm0 = entries.get(0).getValue(); final Vm vm1 = entries.get(1).getValue(); entries.get(0).setValue(vm1); entries.get(1).setValue(vm0); return true; } 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 testSwapVmsOfTwoMapEntries() { final int numberOfEntries = 2; final Cloudlet[] cloudlets = new Cloudlet[numberOfEntries]; for(int i = 1; i <= numberOfEntries; i++){ cloudlets[i-1] = CloudletTestUtil.createCloudlet(i, i*1000, i); } final Vm[] vms = createVms(numberOfEntries); final List<Map.Entry<Cloudlet, Vm>> originalEntries = new ArrayList<>(numberOfEntries); final List<Map.Entry<Cloudlet, Vm>> swappedVmsEntries = new ArrayList<>(numberOfEntries); for (int i = 0; i < numberOfEntries; i++) { originalEntries.add(new AbstractMap.SimpleEntry<>(cloudlets[i], vms[i])); final int swappedVmIndex = (i + 1) % numberOfEntries; swappedVmsEntries.add(new AbstractMap.SimpleEntry<>(cloudlets[i], vms[swappedVmIndex])) ; } final CloudletToVmMappingSolution instance = new CloudletToVmMappingSolution(Heuristic.NULL); instance.swapVmsOfTwoMapEntries(originalEntries); final String msg = String.format( "The VMs of the given cloudlets were not swapped. It was expected the cloudlet %d to move to VM %d and cloudlet %d to move to VM %d.", swappedVmsEntries.get(0).getKey().getId(), swappedVmsEntries.get(0).getValue().getId(), swappedVmsEntries.get(1).getKey().getId(), swappedVmsEntries.get(1).getValue().getId()); assertEquals(swappedVmsEntries, originalEntries, msg); }