@Test public void testSplit() throws SchedulerException { MaxOnlineSplitter splitter = new MaxOnlineSplitter(); Model mo = new DefaultModel(); Node[] ns = new Node[10]; for (int i = 0; i < ns.length; i++) { Node n = mo.newNode(); mo.getMapping().addOnlineNode(n); ns[i] = n; } FixedNodeSetsPartitioning cut = new FixedSizePartitioning(5); Instance origin = new Instance(mo, Collections.emptyList(), new MinMTTR()); List<Instance> instances = cut.split(new DefaultParameters(), origin); TIntIntHashMap vmIndex = Instances.makeVMIndex(instances); TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances); MaxOnline m1 = new MaxOnline(new HashSet<>(Arrays.asList(ns[0], ns[1], ns[2], ns[3], ns[4])), 3); Assert.assertTrue(splitter.split(m1, origin, instances, vmIndex, nodeIndex)); boolean found = false; for (Instance i : instances) { if (i.getSatConstraints().contains(m1)) { if (found) { Assert.fail(m1 + " is already in a partition"); } found = true; } } MaxOnline m2 = new MaxOnline(new HashSet<>(Arrays.asList(ns[0], ns[1], ns[5])), 3); Assert.assertFalse(splitter.split(m2, origin, instances, vmIndex, nodeIndex)); }
@Override public boolean split(MaxOnline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); final int q = cstr.getAmount(); return SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition). forEachPartition(new IterateProcedure<Node>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<Node> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 1) { partitions.get(idx).getSatConstraints().add(new MaxOnline(new ElementSubSet<>(index, idx, from, to), q, c)); first = false; } return true; } }); }
MaxOnlineSplitter implements ConstraintSplitter<MaxOnline> { @Override public boolean split(MaxOnline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); final int q = cstr.getAmount(); return SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition). forEachPartition(new IterateProcedure<Node>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<Node> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 1) { partitions.get(idx).getSatConstraints().add(new MaxOnline(new ElementSubSet<>(index, idx, from, to), q, c)); first = false; } return true; } }); } }
MaxOnlineSplitter implements ConstraintSplitter<MaxOnline> { @Override public boolean split(MaxOnline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); final int q = cstr.getAmount(); return SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition). forEachPartition(new IterateProcedure<Node>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<Node> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 1) { partitions.get(idx).getSatConstraints().add(new MaxOnline(new ElementSubSet<>(index, idx, from, to), q, c)); first = false; } return true; } }); }  }
MaxOnlineSplitter implements ConstraintSplitter<MaxOnline> { @Override public boolean split(MaxOnline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); final int q = cstr.getAmount(); return SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition). forEachPartition(new IterateProcedure<Node>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<Node> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 1) { partitions.get(idx).getSatConstraints().add(new MaxOnline(new ElementSubSet<>(index, idx, from, to), q, c)); first = false; } return true; } }); }  @Override Class<MaxOnline> getKey(); @Override boolean split(MaxOnline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition); }
MaxOnlineSplitter implements ConstraintSplitter<MaxOnline> { @Override public boolean split(MaxOnline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) { final boolean c = cstr.isContinuous(); final int q = cstr.getAmount(); return SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition). forEachPartition(new IterateProcedure<Node>() { private boolean first = true; @Override public boolean extract(SplittableElementSet<Node> index, int idx, int from, int to) { if (!first) { return false; } if (to - from >= 1) { partitions.get(idx).getSatConstraints().add(new MaxOnline(new ElementSubSet<>(index, idx, from, to), q, c)); first = false; } return true; } }); }  @Override Class<MaxOnline> getKey(); @Override boolean split(MaxOnline cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition);  }