Search in sources :

Example 31 with TIntIntHashMap

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

the class FixedNodeSetsPartitioning method split.

@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
    Model mo = i.getModel();
    SynchronizedElementBuilder eb = new SynchronizedElementBuilder(mo);
    List<Instance> parts = new ArrayList<>(partitions.size());
    // nb of VMs
    int nbVMs = i.getModel().getMapping().getNbVMs();
    int nbNodes = i.getModel().getMapping().getNbNodes();
    TIntIntHashMap vmPosition = new TIntIntHashMap(nbVMs);
    TIntIntHashMap nodePosition = new TIntIntHashMap(nbNodes);
    int partNumber = 0;
    Set<VM> toLaunch = getVMsToLaunch(i);
    for (Collection<Node> s : partitions) {
        SubModel partModel = new SubModel(mo, eb, s, new HashSet<>(toLaunch.size() / partitions.size()));
        parts.add(new Instance(partModel, new THashSet<>(), i.getOptConstraint()));
        // VM Index
        partModel.getMapping().fillVMIndex(vmPosition, partNumber);
        // Node index
        for (Node n : s) {
            nodePosition.put(n.id(), partNumber);
        }
        partNumber++;
    }
    // Round-robin placement for the VMs to launch
    int p = 0;
    for (VM v : toLaunch) {
        if (!parts.get(p).getModel().getMapping().addReadyVM(v)) {
            throw new SplitException(parts.get(p).getModel(), "Unable to dispatch the VM to launch '" + v + "'");
        }
        vmPosition.put(v.id(), p);
        p = (p + 1) % parts.size();
    }
    // Split the constraints
    for (SatConstraint cstr : i.getSatConstraints()) {
        if (!cstrMapper.split(cstr, i, parts, vmPosition, nodePosition)) {
            throw new SplitException(i.getModel(), "Unable to split " + cstr);
        }
    }
    return parts;
}
Also used : Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList) SatConstraint(org.btrplace.model.constraint.SatConstraint) THashSet(gnu.trove.set.hash.THashSet) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) SynchronizedElementBuilder(org.btrplace.model.SynchronizedElementBuilder)

Example 32 with TIntIntHashMap

use of gnu.trove.map.hash.TIntIntHashMap 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 33 with TIntIntHashMap

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

the class SplittableElementSetTest method testOrdering.

@Test(dependsOnMethods = "testNewVMSet")
public void testOrdering() {
    List<VM> l = new ArrayList<>();
    final TIntIntHashMap index = new TIntIntHashMap();
    Random rnd = new Random();
    for (int i = 0; i < 10; i++) {
        l.add(new VM(i));
        index.put(i, rnd.nextInt(3));
    }
    SplittableElementSet<VM> s = SplittableElementSet.newVMIndex(l, index);
    System.err.println(s);
    List<VM> values = s.getValues();
    for (int i = 0; i < values.size() - 1; i++) {
        Assert.assertTrue(index.get(values.get(i).id()) <= index.get(values.get(i + 1).id()));
    }
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 34 with TIntIntHashMap

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

the class SplittableElementSetTest method testForEachPartition.

@Test(dependsOnMethods = "testNewVMSet")
public void testForEachPartition() {
    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);
    s.forEachPartition((index1, key, from, to) -> {
        Assert.assertEquals(to - from, 5);
        for (int i = from; i < to; i++) {
            Assert.assertEquals(key, index1.getValues().get(i).id() % 2);
        }
        return true;
    });
    // We stop after the first partition
    s.forEachPartition(new IterateProcedure<VM>() {

        final boolean first = true;

        @Override
        public boolean extract(SplittableElementSet<VM> index, int key, int from, int to) {
            Assert.assertTrue(first);
            return false;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Test(org.testng.annotations.Test)

Example 35 with TIntIntHashMap

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

the class SplittableElementSetTest method testNewNodeSet.

@Test
public void testNewNodeSet() {
    List<Node> l = new ArrayList<>();
    TIntIntHashMap m = new TIntIntHashMap();
    for (int i = 0; i < 10; i++) {
        l.add(new Node(i));
        m.put(i, i % 2);
    }
    SplittableElementSet<Node> s = SplittableElementSet.newNodeIndex(l, m);
    for (Node 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)

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