use of org.btrplace.scheduler.runner.disjoint.model.ElementSubSet in project scheduler by btrplace.
the class SplittableElementSetTest method testGetPartitions.
@Test(dependsOnMethods = "testNewVMSet")
public void testGetPartitions() {
List<VM> l = new ArrayList<>();
final TIntIntHashMap index = new TIntIntHashMap();
for (int i = 0; i < 10; i++) {
l.add(new VM(i));
index.put(i, i % 2);
}
SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
// check each partition contains element having the same partition key.
List<ElementSubSet<VM>> ss = s.getPartitions();
for (ElementSubSet<VM> sub : ss) {
Iterator<VM> ite = sub.iterator();
int partKey = index.get(ite.next().id());
while (ite.hasNext()) {
Assert.assertEquals(index.get(ite.next().id()), partKey);
}
}
Assert.assertEquals(s.size(), 10);
Assert.assertEquals(ss.size(), 2);
}
use of org.btrplace.scheduler.runner.disjoint.model.ElementSubSet in project scheduler by btrplace.
the class AmongSplitter method split.
@Override
public boolean split(final Among cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, final TIntIntHashMap nodePosition) {
final boolean c = cstr.isContinuous();
return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition).forEachPartition((index, idx, from, to) -> {
if (to - from >= 2) {
ElementSubSet<VM> vms = new ElementSubSet<>(index, idx, from, to);
// Get the servers on the partition
// Filter out the other nodes in the original constraint
final Collection<Collection<Node>> subParams = new ArrayList<>();
for (Collection<Node> ns : cstr.getGroupsOfNodes()) {
SplittableElementSet<Node> nodeIndex = SplittableElementSet.newNodeIndex(ns, nodePosition);
Set<Node> s = nodeIndex.getSubSet(idx);
if (s != null && !s.isEmpty()) {
subParams.add(s);
}
}
partitions.get(idx).getSatConstraints().add(new Among(vms, subParams, c));
}
return true;
});
}
use of org.btrplace.scheduler.runner.disjoint.model.ElementSubSet in project scheduler by btrplace.
the class ElementSubSetTest method test.
@Test
public void test() {
Model mo = new DefaultModel();
List<VM> l = new ArrayList<>();
final TIntIntHashMap index = new TIntIntHashMap();
for (int i = 0; i < 10; i++) {
l.add(mo.newVM());
index.put(i, i % 2);
}
SplittableElementSet<VM> si = SplittableElementSet.newVMIndex(l, index);
List<VM> values = si.getValues();
ElementSubSet<VM> p1 = new ElementSubSet<>(si, 0, 0, 5);
// test contains()
Assert.assertTrue(p1.contains(values.get(0)));
Assert.assertFalse(p1.contains(values.get(5)));
// test containsAll()
Assert.assertFalse(p1.containsAll(l));
// test size()
Assert.assertEquals(p1.size(), 5);
Assert.assertFalse(p1.isEmpty());
System.out.println(p1);
// test iterator
for (VM v : p1) {
Assert.assertEquals(v.id() % 2, 0);
}
}
use of org.btrplace.scheduler.runner.disjoint.model.ElementSubSet in project scheduler by btrplace.
the class Bench method makeEdges.
private static List<Collection<Node>> makeEdges(List<Node> l, int switchSize) {
TIntIntHashMap parts = new TIntIntHashMap();
int curPart = 0;
int i = 0;
for (Node n : l) {
i = (i + 1) % switchSize;
if ((i + 1) % switchSize == 0) {
curPart++;
}
parts.put(n.id(), curPart);
}
SplittableElementSet<Node> sp = SplittableElementSet.newNodeIndex(l, parts);
final List<Collection<Node>> splits = new ArrayList<>();
sp.forEachPartition((index, key, from, to) -> splits.add(new ElementSubSet<>(index, key, from, to)));
return splits;
}
Aggregations