@Test public void simpleTest() { SpreadSplitter splitter = new SpreadSplitter(); 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(); m1.getMapping().addReadyVM(m1.newVM(3)); Node n2 = m1.newNode(); Node n3 = m1.newNode(); m1.getMapping().addOnlineNode(n2); m1.getMapping().addOnlineNode(n3); 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 index = Instances.makeVMIndex(instances); Spread spreadSingle = new Spread(m0.getMapping().getAllVMs()); Assert.assertTrue(splitter.split(spreadSingle, null, instances, index, new TIntIntHashMap())); Assert.assertTrue(instances.get(0).getSatConstraints().contains(spreadSingle)); Assert.assertFalse(instances.get(1).getSatConstraints().contains(spreadSingle)); Spread spreadAmong = new Spread(all, false); Assert.assertTrue(splitter.split(spreadAmong, null, instances, index, new TIntIntHashMap())); Assert.assertTrue(instances.get(0).getSatConstraints().contains(new Spread(m0.getMapping().getAllVMs(), false))); Assert.assertTrue(instances.get(1).getSatConstraints().contains(new Spread(m1.getMapping().getAllVMs(), false))); }
@Override public boolean split(final Spread cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition((index, idx, from, to) -> { if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Spread(new ElementSubSet<>(index, idx, from, to), c)); } return true; }); }
SpreadSplitter implements ConstraintSplitter<Spread> { @Override public boolean split(final Spread cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition((index, idx, from, to) -> { if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Spread(new ElementSubSet<>(index, idx, from, to), c)); } return true; }); } }
SpreadSplitter implements ConstraintSplitter<Spread> { @Override public boolean split(final Spread cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition((index, idx, from, to) -> { if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Spread(new ElementSubSet<>(index, idx, from, to), c)); } return true; }); }  }
SpreadSplitter implements ConstraintSplitter<Spread> { @Override public boolean split(final Spread cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition((index, idx, from, to) -> { if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Spread(new ElementSubSet<>(index, idx, from, to), c)); } return true; }); }  @Override Class<Spread> getKey(); @Override boolean split(final Spread cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition); }
SpreadSplitter implements ConstraintSplitter<Spread> { @Override public boolean split(final Spread cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition). forEachPartition((index, idx, from, to) -> { if (to - from >= 2) { partitions.get(idx).getSatConstraints().add(new Spread(new ElementSubSet<>(index, idx, from, to), c)); } return true; }); }  @Override Class<Spread> getKey(); @Override boolean split(final Spread cstr, Instance origin, final List<Instance> partitions, final TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition);  }