Search in sources :

Example 11 with TIntIntHashMap

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

Example 12 with TIntIntHashMap

use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.

the class SplittableElementSetTest method testNewVMSet.

@Test
public void testNewVMSet() {
    List<VM> l = new ArrayList<>();
    TIntIntHashMap m = new TIntIntHashMap();
    for (int i = 0; i < 10; i++) {
        l.add(new VM(i));
        m.put(i, i % 2);
    }
    SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, m);
    for (VM v : s.getValues()) {
        Assert.assertTrue(v.id() >= 0 && v.id() < 10);
    }
    Assert.assertEquals(s.size(), l.size());
    Assert.assertEquals(s.getRespectiveIndex(), m);
}
Also used : ArrayList(java.util.ArrayList) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 13 with TIntIntHashMap

use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.

the class SplittableElementSetTest method testGetSubSet.

@Test
public void testGetSubSet() {
    List<VM> l = new ArrayList<>();
    final TIntIntHashMap index = new TIntIntHashMap();
    for (int i = 0; i < 12; i++) {
        l.add(new VM(i));
        index.put(i, i % 3);
    }
    SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
    for (int i : new int[] { 0, 1, 2 }) {
        Set<VM> ss = s.getSubSet(i);
        Assert.assertEquals(ss.size(), 4);
        for (VM v : ss) {
            Assert.assertEquals(index.get(v.id()), i);
        }
    }
    // Unknown set
    Assert.assertTrue(s.getSubSet(-1).isEmpty());
}
Also used : ArrayList(java.util.ArrayList) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 14 with TIntIntHashMap

use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.

the class AmongSplitterTest method testSplittable.

@Test
public void testSplittable() throws SchedulerException {
    List<VM> vms = Arrays.asList(vm1, vm2, vm3);
    Collection<Collection<Node>> parts = new ArrayList<>();
    parts.add(Arrays.asList(n1, n2));
    parts.add(Collections.singletonList(n3));
    parts.add(Collections.singletonList(n4));
    Among single = new Among(vms, parts);
    /*
         N1 v1 v2
         N2 v3
         ---
         N3 v4
         --
         N4 v5
         */
    FixedNodeSetsPartitioning partitionner = new FixedNodeSetsPartitioning(parts);
    partitionner.setPartitions(parts);
    List<Instance> instances = partitionner.split(new DefaultParameters(), new Instance(mo, Collections.emptyList(), new MinMTTR()));
    TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
    TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
    splitter.split(single, new Instance(mo, new MinMTTR()), instances, vmIndex, nodeIndex);
    Among a = (Among) instances.get(0).getSatConstraints().iterator().next();
    Assert.assertEquals(a.getGroupsOfNodes().size(), 1);
    Assert.assertEquals(a.getInvolvedNodes(), Arrays.asList(n1, n2));
    for (Instance i : instances) {
        System.out.println(i.getSatConstraints());
    }
}
Also used : FixedNodeSetsPartitioning(org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Instance(org.btrplace.model.Instance) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Collection(java.util.Collection) Among(org.btrplace.model.constraint.Among) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 15 with TIntIntHashMap

use of gnu.trove.map.hash.TIntIntHashMap in project scheduler by btrplace.

the class GatherSplitterTest method simpleTest.

@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);
    // Only VMs in m0
    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));
    // All the VMs, test the unfeasibility
    Gather among = new Gather(all, false);
    Assert.assertFalse(splitter.split(among, null, instances, vmIndex, new TIntIntHashMap()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Gather(org.btrplace.model.constraint.Gather) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)45 ArrayList (java.util.ArrayList)26 Test (org.testng.annotations.Test)22 Instance (org.btrplace.model.Instance)18 Model (org.btrplace.model.Model)15 MinMTTR (org.btrplace.model.constraint.MinMTTR)15 DefaultModel (org.btrplace.model.DefaultModel)14 HashSet (java.util.HashSet)13 Node (org.btrplace.model.Node)13 VM (org.btrplace.model.VM)13 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 TIntIntMap (gnu.trove.map.TIntIntMap)5 TIntHashSet (gnu.trove.set.hash.TIntHashSet)3 OutputPort (cc.redberry.pipe.OutputPort)2 TIntIntIterator (gnu.trove.iterator.TIntIntIterator)2 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)2 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)2 IOException (java.io.IOException)2 Random (java.util.Random)2 Mapping (org.btrplace.model.Mapping)2