@Test public void simpleTest() { GatherSplitter splitter = new GatherSplitter(); List<Instance> instances = new ArrayList<>(); Model m0 = new DefaultModel(); m0.getMapping().addReadyVM(m0.newVM(1)); Node n1 = m0.newNode(); m0.getMapping().addOnlineNode(n1); m0.getMapping().addRunningVM(m0.newVM(2), n1); Model m1 = new DefaultModel(); Node n2 = m1.newNode(); Node n3 = m1.newNode(); m1.getMapping().addOnlineNode(n2); m1.getMapping().addOnlineNode(n3); m1.getMapping().addReadyVM(m1.newVM(3)); m1.getMapping().addSleepingVM(m1.newVM(4), n2); m1.getMapping().addRunningVM(m1.newVM(5), n3); instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR())); instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR())); Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs()); all.addAll(m1.getMapping().getAllVMs()); TIntIntHashMap vmIndex = Instances.makeVMIndex(instances); Gather single = new Gather(m0.getMapping().getAllVMs()); Assert.assertTrue(splitter.split(single, null, instances, vmIndex, new TIntIntHashMap())); Assert.assertTrue(instances.get(0).getSatConstraints().contains(single)); Assert.assertFalse(instances.get(1).getSatConstraints().contains(single)); Gather among = new Gather(all, false); Assert.assertFalse(splitter.split(among, null, instances, vmIndex, new TIntIntHashMap())); }
@Override public boolean split(Gather cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition(new IterateProcedure<VM>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<VM> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Gather(new ElementSubSet<>(index, idx, from, to), c)); first = false; } return true; } }); }
GatherSplitter implements ConstraintSplitter<Gather> { @Override public boolean split(Gather cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition(new IterateProcedure<VM>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<VM> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Gather(new ElementSubSet<>(index, idx, from, to), c)); first = false; } return true; } }); } }
GatherSplitter implements ConstraintSplitter<Gather> { @Override public boolean split(Gather cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition(new IterateProcedure<VM>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<VM> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Gather(new ElementSubSet<>(index, idx, from, to), c)); first = false; } return true; } }); }  }
GatherSplitter implements ConstraintSplitter<Gather> { @Override public boolean split(Gather cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition(new IterateProcedure<VM>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<VM> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Gather(new ElementSubSet<>(index, idx, from, to), c)); first = false; } return true; } }); }  @Override Class<Gather> getKey(); @Override boolean split(Gather cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition); }
GatherSplitter implements ConstraintSplitter<Gather> { @Override public boolean split(Gather cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition(new IterateProcedure<VM>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<VM> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Gather(new ElementSubSet<>(index, idx, from, to), c)); first = false; } return true; } }); }  @Override Class<Gather> getKey(); @Override boolean split(Gather cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition);  }