Search in sources :

Example 1 with ElementSubSet

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);
}
Also used : ElementSubSet(org.btrplace.scheduler.runner.disjoint.model.ElementSubSet) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 2 with ElementSubSet

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;
    });
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ElementSubSet(org.btrplace.scheduler.runner.disjoint.model.ElementSubSet) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Among(org.btrplace.model.constraint.Among)

Example 3 with ElementSubSet

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ElementSubSet(org.btrplace.scheduler.runner.disjoint.model.ElementSubSet) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 4 with ElementSubSet

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;
}
Also used : ElementSubSet(org.btrplace.scheduler.runner.disjoint.model.ElementSubSet) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Aggregations

ElementSubSet (org.btrplace.scheduler.runner.disjoint.model.ElementSubSet)4 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)3 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 Collection (java.util.Collection)1 Node (org.btrplace.model.Node)1 VM (org.btrplace.model.VM)1 Among (org.btrplace.model.constraint.Among)1